d3d10: Return the read value from read_dword().
[wine.git] / dlls / d3d10 / effect.c
blob4759dea5ee94faa9dd04eb1646eae083b4bd844e
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 * Copyright 2009 Rico Schüller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "d3d10_private.h"
23 #include <float.h>
24 #include <stdint.h>
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
28 #define MAKE_TAG(ch0, ch1, ch2, ch3) \
29 ((DWORD)(ch0) | ((DWORD)(ch1) << 8) | \
30 ((DWORD)(ch2) << 16) | ((DWORD)(ch3) << 24 ))
31 #define TAG_DXBC MAKE_TAG('D', 'X', 'B', 'C')
32 #define TAG_FX10 MAKE_TAG('F', 'X', '1', '0')
33 #define TAG_FXLC MAKE_TAG('F', 'X', 'L', 'C')
34 #define TAG_CLI4 MAKE_TAG('C', 'L', 'I', '4')
35 #define TAG_CTAB MAKE_TAG('C', 'T', 'A', 'B')
37 #define D3D10_FX10_TYPE_COLUMN_SHIFT 11
38 #define D3D10_FX10_TYPE_COLUMN_MASK (0x7 << D3D10_FX10_TYPE_COLUMN_SHIFT)
40 #define D3D10_FX10_TYPE_ROW_SHIFT 8
41 #define D3D10_FX10_TYPE_ROW_MASK (0x7 << D3D10_FX10_TYPE_ROW_SHIFT)
43 #define D3D10_FX10_TYPE_BASETYPE_SHIFT 3
44 #define D3D10_FX10_TYPE_BASETYPE_MASK (0x1f << D3D10_FX10_TYPE_BASETYPE_SHIFT)
46 #define D3D10_FX10_TYPE_CLASS_SHIFT 0
47 #define D3D10_FX10_TYPE_CLASS_MASK (0x7 << D3D10_FX10_TYPE_CLASS_SHIFT)
49 #define D3D10_FX10_TYPE_MATRIX_COLUMN_MAJOR_MASK 0x4000
51 static inline struct d3d10_effect *impl_from_ID3D10EffectPool(ID3D10EffectPool *iface)
53 return CONTAINING_RECORD(iface, struct d3d10_effect, ID3D10EffectPool_iface);
56 const struct ID3D10EffectPoolVtbl d3d10_effect_pool_vtbl;
57 static inline struct d3d10_effect *unsafe_impl_from_ID3D10EffectPool(ID3D10EffectPool *iface)
59 if (!iface || iface->lpVtbl != &d3d10_effect_pool_vtbl)
60 return NULL;
61 return CONTAINING_RECORD(iface, struct d3d10_effect, ID3D10EffectPool_iface);
64 static const struct ID3D10EffectVtbl d3d10_effect_pool_effect_vtbl;
65 static void d3d10_effect_variable_destroy(struct d3d10_effect_variable *v);
67 static const struct ID3D10EffectTechniqueVtbl d3d10_effect_technique_vtbl;
68 static const struct ID3D10EffectPassVtbl d3d10_effect_pass_vtbl;
69 static const struct ID3D10EffectVariableVtbl d3d10_effect_variable_vtbl;
70 static const struct ID3D10EffectConstantBufferVtbl d3d10_effect_constant_buffer_vtbl;
71 static const struct ID3D10EffectScalarVariableVtbl d3d10_effect_scalar_variable_vtbl;
72 static const struct ID3D10EffectVectorVariableVtbl d3d10_effect_vector_variable_vtbl;
73 static const struct ID3D10EffectMatrixVariableVtbl d3d10_effect_matrix_variable_vtbl;
74 static const struct ID3D10EffectStringVariableVtbl d3d10_effect_string_variable_vtbl;
75 static const struct ID3D10EffectShaderResourceVariableVtbl d3d10_effect_shader_resource_variable_vtbl;
76 static const struct ID3D10EffectRenderTargetViewVariableVtbl d3d10_effect_render_target_view_variable_vtbl;
77 static const struct ID3D10EffectDepthStencilViewVariableVtbl d3d10_effect_depth_stencil_view_variable_vtbl;
78 static const struct ID3D10EffectShaderVariableVtbl d3d10_effect_shader_variable_vtbl;
79 static const struct ID3D10EffectBlendVariableVtbl d3d10_effect_blend_variable_vtbl;
80 static const struct ID3D10EffectDepthStencilVariableVtbl d3d10_effect_depth_stencil_variable_vtbl;
81 static const struct ID3D10EffectRasterizerVariableVtbl d3d10_effect_rasterizer_variable_vtbl;
82 static const struct ID3D10EffectSamplerVariableVtbl d3d10_effect_sampler_variable_vtbl;
83 static const struct ID3D10EffectTypeVtbl d3d10_effect_type_vtbl;
85 /* null objects - needed for invalid calls */
86 static struct d3d10_effect_technique null_technique = {{&d3d10_effect_technique_vtbl}};
87 static struct d3d10_effect_pass null_pass = {{&d3d10_effect_pass_vtbl}};
88 static struct d3d10_effect_type null_type = {{&d3d10_effect_type_vtbl}};
89 static struct d3d10_effect_variable null_local_buffer = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_constant_buffer_vtbl},
90 &null_local_buffer, &null_type};
91 static struct d3d10_effect_variable null_variable = {{&d3d10_effect_variable_vtbl},
92 &null_local_buffer, &null_type};
93 static struct d3d10_effect_variable null_scalar_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_scalar_variable_vtbl},
94 &null_local_buffer, &null_type};
95 static struct d3d10_effect_variable null_vector_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_vector_variable_vtbl},
96 &null_local_buffer, &null_type};
97 static struct d3d10_effect_variable null_matrix_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_matrix_variable_vtbl},
98 &null_local_buffer, &null_type};
99 static struct d3d10_effect_variable null_string_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_string_variable_vtbl},
100 &null_local_buffer, &null_type};
101 static struct d3d10_effect_variable null_render_target_view_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_render_target_view_variable_vtbl},
102 &null_local_buffer, &null_type};
103 static struct d3d10_effect_variable null_depth_stencil_view_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_depth_stencil_view_variable_vtbl},
104 &null_local_buffer, &null_type};
105 static struct d3d10_effect_variable null_shader_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_variable_vtbl},
106 &null_local_buffer, &null_type};
107 static struct d3d10_effect_variable null_blend_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_blend_variable_vtbl},
108 &null_local_buffer, &null_type};
109 static struct d3d10_effect_variable null_depth_stencil_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_depth_stencil_variable_vtbl},
110 &null_local_buffer, &null_type};
111 static struct d3d10_effect_variable null_rasterizer_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_rasterizer_variable_vtbl},
112 &null_local_buffer, &null_type};
113 static struct d3d10_effect_variable null_sampler_variable = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_sampler_variable_vtbl},
114 &null_local_buffer, &null_type};
116 static ID3D10ShaderResourceView *null_srvs[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
118 static struct d3d10_effect_variable null_shader_resource_variable =
120 .ID3D10EffectVariable_iface.lpVtbl = (ID3D10EffectVariableVtbl *)&d3d10_effect_shader_resource_variable_vtbl,
121 .buffer = &null_local_buffer,
122 .type = &null_type,
123 .u.resource.srv = null_srvs,
126 /* anonymous_shader_type and anonymous_shader */
127 static char anonymous_name[] = "$Anonymous";
128 static char anonymous_vertexshader_name[] = "vertexshader";
129 static char anonymous_pixelshader_name[] = "pixelshader";
130 static char anonymous_geometryshader_name[] = "geometryshader";
131 static struct d3d10_effect_type anonymous_vs_type = {{&d3d10_effect_type_vtbl},
132 anonymous_vertexshader_name, D3D10_SVT_VERTEXSHADER, D3D10_SVC_OBJECT};
133 static struct d3d10_effect_type anonymous_ps_type = {{&d3d10_effect_type_vtbl},
134 anonymous_pixelshader_name, D3D10_SVT_PIXELSHADER, D3D10_SVC_OBJECT};
135 static struct d3d10_effect_type anonymous_gs_type = {{&d3d10_effect_type_vtbl},
136 anonymous_geometryshader_name, D3D10_SVT_GEOMETRYSHADER, D3D10_SVC_OBJECT};
137 static struct d3d10_effect_variable anonymous_vs = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_variable_vtbl},
138 &null_local_buffer, &anonymous_vs_type, anonymous_name};
139 static struct d3d10_effect_variable anonymous_ps = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_variable_vtbl},
140 &null_local_buffer, &anonymous_ps_type, anonymous_name};
141 static struct d3d10_effect_variable anonymous_gs = {{(const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_variable_vtbl},
142 &null_local_buffer, &anonymous_gs_type, anonymous_name};
144 static struct d3d10_effect_type *get_fx10_type(struct d3d10_effect *effect,
145 const char *data, size_t data_size, DWORD offset);
147 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectVariable(ID3D10EffectVariable *iface)
149 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
152 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectShaderVariable(ID3D10EffectShaderVariable *iface)
154 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
157 static struct d3d10_effect_variable * d3d10_array_get_element(struct d3d10_effect_variable *v,
158 unsigned int index)
160 if (!v->type->element_count) return v;
161 return &v->elements[index];
164 static struct d3d10_effect_variable * d3d10_get_state_variable(struct d3d10_effect_variable *v,
165 unsigned int index, const struct d3d10_effect_var_array *array)
167 v = d3d10_array_get_element(v, 0);
169 if (v->u.state.index + index >= array->count)
171 WARN("Invalid index %u.\n", index);
172 return NULL;
175 return array->v[v->u.state.index + index];
178 enum d3d10_effect_container_type
180 D3D10_C_NONE,
181 D3D10_C_PASS,
182 D3D10_C_RASTERIZER,
183 D3D10_C_DEPTHSTENCIL,
184 D3D10_C_BLEND,
185 D3D10_C_SAMPLER,
188 static enum d3d10_effect_container_type get_var_container_type(const struct d3d10_effect_variable *v)
190 switch (v->type->basetype)
192 case D3D10_SVT_DEPTHSTENCIL: return D3D10_C_DEPTHSTENCIL;
193 case D3D10_SVT_BLEND: return D3D10_C_BLEND;
194 case D3D10_SVT_RASTERIZER: return D3D10_C_RASTERIZER;
195 case D3D10_SVT_SAMPLER: return D3D10_C_SAMPLER;
196 default: return D3D10_C_NONE;
200 struct preshader_instr
202 unsigned int comp_count : 16;
203 unsigned int reserved : 4;
204 unsigned int opcode : 11;
205 unsigned int scalar : 1;
208 typedef void (*pres_op_func)(float **args, unsigned int n, const struct preshader_instr *instr);
210 static void pres_ftou(float **args, unsigned int n, const struct preshader_instr *instr)
212 float *retval = args[1];
213 unsigned int i;
215 for (i = 0; i < instr->comp_count; ++i)
217 unsigned int u = args[0][i];
218 retval[i] = *(float *)&u;
222 static void pres_add(float **args, unsigned int n, const struct preshader_instr *instr)
224 float *retval = args[2];
225 unsigned int i;
227 for (i = 0; i < instr->comp_count; ++i)
228 retval[i] = args[0][instr->scalar ? 0 : i] + args[1][i];
231 struct preshader_op_info
233 int opcode;
234 char name[8];
235 pres_op_func func;
238 static const struct preshader_op_info preshader_ops[] =
240 { 0x133, "ftou", pres_ftou },
241 { 0x204, "add", pres_add },
244 static int __cdecl preshader_op_compare(const void *a, const void *b)
246 int opcode = *(int *)a;
247 const struct preshader_op_info *op_info = b;
248 return opcode - op_info->opcode;
251 static const struct preshader_op_info * d3d10_effect_get_op_info(int opcode)
253 return bsearch(&opcode, preshader_ops, ARRAY_SIZE(preshader_ops), sizeof(*preshader_ops),
254 preshader_op_compare);
257 struct d3d10_ctab_var
259 struct d3d10_effect_variable *v;
260 unsigned int offset;
261 unsigned int length;
264 struct d3d10_reg_table
266 union
268 float *f;
269 DWORD *dword;
271 unsigned int count;
274 enum d3d10_reg_table_type
276 D3D10_REG_TABLE_CONSTANTS = 1,
277 D3D10_REG_TABLE_CB = 2,
278 D3D10_REG_TABLE_RESULT = 4,
279 D3D10_REG_TABLE_TEMP = 7,
280 D3D10_REG_TABLE_COUNT,
283 struct d3d10_effect_preshader
285 struct d3d10_reg_table reg_tables[D3D10_REG_TABLE_COUNT];
286 ID3D10Blob *code;
288 struct d3d10_ctab_var *vars;
289 unsigned int vars_count;
292 struct d3d10_preshader_parse_context
294 struct d3d10_effect_preshader *preshader;
295 struct d3d10_effect *effect;
296 unsigned int table_sizes[D3D10_REG_TABLE_COUNT];
299 struct d3d10_effect_prop_dependency
301 unsigned int id;
302 unsigned int idx;
303 unsigned int operation;
304 union
306 struct
308 struct d3d10_effect_variable *v;
309 unsigned int offset;
310 } var;
311 struct
313 struct d3d10_effect_variable *v;
314 struct d3d10_effect_preshader index;
315 } index_expr;
316 struct
318 struct d3d10_effect_preshader value;
319 } value_expr;
323 static HRESULT d3d10_reg_table_allocate(struct d3d10_reg_table *table, unsigned int count)
325 if (!(table->f = heap_calloc(count, sizeof(*table->f))))
326 return E_OUTOFMEMORY;
327 table->count = count;
328 return S_OK;
331 static void d3d10_effect_preshader_clear(struct d3d10_effect_preshader *p)
333 unsigned int i;
335 for (i = 0; i < ARRAY_SIZE(p->reg_tables); ++i)
336 heap_free(p->reg_tables[i].f);
337 if (p->code)
338 ID3D10Blob_Release(p->code);
339 heap_free(p->vars);
340 memset(p, 0, sizeof(*p));
343 static float * d3d10_effect_preshader_get_reg_ptr(const struct d3d10_effect_preshader *p,
344 enum d3d10_reg_table_type regt, unsigned int offset)
346 switch (regt)
348 case D3D10_REG_TABLE_CONSTANTS:
349 case D3D10_REG_TABLE_CB:
350 case D3D10_REG_TABLE_RESULT:
351 case D3D10_REG_TABLE_TEMP:
352 return p->reg_tables[regt].f + offset;
353 default:
354 return NULL;
358 static HRESULT d3d10_effect_preshader_eval(struct d3d10_effect_preshader *p)
360 unsigned int i, j, regt, offset, instr_count, arg_count;
361 const DWORD *ip = ID3D10Blob_GetBufferPointer(p->code);
362 struct preshader_instr ins;
363 float *dst, *args[4];
365 dst = d3d10_effect_preshader_get_reg_ptr(p, D3D10_REG_TABLE_RESULT, 0);
366 memset(dst, 0, sizeof(float) * p->reg_tables[D3D10_REG_TABLE_RESULT].count);
368 /* Update constant buffer */
369 dst = d3d10_effect_preshader_get_reg_ptr(p, D3D10_REG_TABLE_CB, 0);
370 for (i = 0; i < p->vars_count; ++i)
372 struct d3d10_ctab_var *v = &p->vars[i];
373 memcpy(dst + v->offset, v->v->buffer->u.buffer.local_buffer + v->v->buffer_offset,
374 v->length * sizeof(*dst));
377 instr_count = *ip++;
379 for (i = 0; i < instr_count; ++i)
381 *(DWORD *)&ins = *ip++;
382 arg_count = 1 + *ip++;
384 if (arg_count > ARRAY_SIZE(args))
386 FIXME("Unexpected argument count %u.\n", arg_count);
387 return E_FAIL;
390 /* Arguments are followed by the return value. */
391 for (j = 0; j < arg_count; ++j)
393 ip++; /* TODO: argument register flags are currently ignored */
394 regt = *ip++;
395 offset = *ip++;
397 args[j] = d3d10_effect_preshader_get_reg_ptr(p, regt, offset);
400 d3d10_effect_get_op_info(ins.opcode)->func(args, arg_count, &ins);
403 return S_OK;
406 static void d3d10_effect_clear_prop_dependencies(struct d3d10_effect_prop_dependencies *d)
408 unsigned int i;
410 for (i = 0; i < d->count; ++i)
412 struct d3d10_effect_prop_dependency *dep = &d->entries[i];
413 switch (dep->operation)
415 case D3D10_EOO_INDEX_EXPRESSION:
416 d3d10_effect_preshader_clear(&dep->index_expr.index);
417 break;
418 case D3D10_EOO_VALUE_EXPRESSION:
419 d3d10_effect_preshader_clear(&dep->value_expr.value);
420 break;
423 heap_free(d->entries);
424 memset(d, 0, sizeof(*d));
427 struct d3d10_effect_state_property_info
429 UINT id;
430 const char *name;
431 D3D_SHADER_VARIABLE_TYPE type;
432 UINT size;
433 UINT count;
434 enum d3d10_effect_container_type container_type;
435 LONG offset;
436 LONG index_offset;
439 static const struct d3d10_effect_state_property_info property_infos[] =
441 {0x00, "Pass.RasterizerState", D3D10_SVT_RASTERIZER, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, rasterizer) },
442 {0x01, "Pass.DepthStencilState", D3D10_SVT_DEPTHSTENCIL, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, depth_stencil) },
443 {0x02, "Pass.BlendState", D3D10_SVT_BLEND, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, blend) },
444 {0x03, "Pass.RenderTargets", D3D10_SVT_RENDERTARGETVIEW, 1, 8, D3D10_C_PASS, ~0u },
445 {0x04, "Pass.DepthStencilView", D3D10_SVT_DEPTHSTENCILVIEW, 1, 1, D3D10_C_PASS, ~0u },
446 {0x05, "Pass.Unknown5", D3D10_SVT_VOID, 0, 0, D3D10_C_PASS, ~0u },
447 {0x06, "Pass.VertexShader", D3D10_SVT_VERTEXSHADER, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, vs.shader),
448 FIELD_OFFSET(struct d3d10_effect_pass, vs.index) },
449 {0x07, "Pass.PixelShader", D3D10_SVT_PIXELSHADER, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, ps.shader),
450 FIELD_OFFSET(struct d3d10_effect_pass, ps.index) },
451 {0x08, "Pass.GeometryShader", D3D10_SVT_GEOMETRYSHADER, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, gs.shader),
452 FIELD_OFFSET(struct d3d10_effect_pass, gs.index) },
453 {0x09, "Pass.StencilRef", D3D10_SVT_UINT, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, stencil_ref) },
454 {0x0a, "Pass.BlendFactor", D3D10_SVT_FLOAT, 4, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, blend_factor) },
455 {0x0b, "Pass.SampleMask", D3D10_SVT_UINT, 1, 1, D3D10_C_PASS, FIELD_OFFSET(struct d3d10_effect_pass, sample_mask) },
457 {0x0c, "RasterizerState.FillMode", D3D10_SVT_INT, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, FillMode) },
458 {0x0d, "RasterizerState.CullMode", D3D10_SVT_INT, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, CullMode) },
459 {0x0e, "RasterizerState.FrontCounterClockwise", D3D10_SVT_BOOL, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, FrontCounterClockwise) },
460 {0x0f, "RasterizerState.DepthBias", D3D10_SVT_INT, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, DepthBias) },
461 {0x10, "RasterizerState.DepthBiasClamp", D3D10_SVT_FLOAT, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, DepthBiasClamp) },
462 {0x11, "RasterizerState.SlopeScaledDepthBias", D3D10_SVT_FLOAT, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, SlopeScaledDepthBias) },
463 {0x12, "RasterizerState.DepthClipEnable", D3D10_SVT_BOOL, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, DepthClipEnable) },
464 {0x13, "RasterizerState.ScissorEnable", D3D10_SVT_BOOL, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, ScissorEnable) },
465 {0x14, "RasterizerState.MultisampleEnable", D3D10_SVT_BOOL, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, MultisampleEnable) },
466 {0x15, "RasterizerState.AntialiasedLineEnable", D3D10_SVT_BOOL, 1, 1, D3D10_C_RASTERIZER, FIELD_OFFSET(D3D10_RASTERIZER_DESC, AntialiasedLineEnable) },
468 {0x16, "DepthStencilState.DepthEnable", D3D10_SVT_BOOL, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, DepthEnable) },
469 {0x17, "DepthStencilState.DepthWriteMask", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, DepthWriteMask) },
470 {0x18, "DepthStencilState.DepthFunc", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, DepthFunc) },
471 {0x19, "DepthStencilState.StencilEnable", D3D10_SVT_BOOL, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, StencilEnable) },
472 {0x1a, "DepthStencilState.StencilReadMask", D3D10_SVT_UINT8, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, StencilReadMask) },
473 {0x1b, "DepthStencilState.StencilWriteMask", D3D10_SVT_UINT8, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, StencilWriteMask) },
474 {0x1c, "DepthStencilState.FrontFaceStencilFail", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, FrontFace.StencilFailOp) },
475 {0x1d, "DepthStencilState.FrontFaceStencilDepthFail", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, FrontFace.StencilDepthFailOp)},
476 {0x1e, "DepthStencilState.FrontFaceStencilPass", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, FrontFace.StencilPassOp) },
477 {0x1f, "DepthStencilState.FrontFaceStencilFunc", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, FrontFace.StencilFunc) },
478 {0x20, "DepthStencilState.BackFaceStencilFail", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, BackFace.StencilFailOp) },
479 {0x21, "DepthStencilState.BackFaceStencilDepthFail", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, BackFace.StencilDepthFailOp) },
480 {0x22, "DepthStencilState.BackFaceStencilPass", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, BackFace.StencilPassOp) },
481 {0x23, "DepthStencilState.BackFaceStencilFunc", D3D10_SVT_INT, 1, 1, D3D10_C_DEPTHSTENCIL, FIELD_OFFSET(D3D10_DEPTH_STENCIL_DESC, BackFace.StencilFunc) },
483 {0x24, "BlendState.AlphaToCoverageEnable", D3D10_SVT_BOOL, 1, 1, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, AlphaToCoverageEnable) },
484 {0x25, "BlendState.BlendEnable", D3D10_SVT_BOOL, 1, 8, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, BlendEnable) },
485 {0x26, "BlendState.SrcBlend", D3D10_SVT_INT, 1, 1, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, SrcBlend) },
486 {0x27, "BlendState.DestBlend", D3D10_SVT_INT, 1, 1, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, DestBlend) },
487 {0x28, "BlendState.BlendOp", D3D10_SVT_INT, 1, 1, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, BlendOp) },
488 {0x29, "BlendState.SrcBlendAlpha", D3D10_SVT_INT, 1, 1, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, SrcBlendAlpha) },
489 {0x2a, "BlendState.DestBlendAlpha", D3D10_SVT_INT, 1, 1, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, DestBlendAlpha) },
490 {0x2b, "BlendState.BlendOpAlpha", D3D10_SVT_INT, 1, 1, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, BlendOpAlpha) },
491 {0x2c, "BlendState.RenderTargetWriteMask", D3D10_SVT_UINT8, 1, 8, D3D10_C_BLEND, FIELD_OFFSET(D3D10_BLEND_DESC, RenderTargetWriteMask) },
493 {0x2d, "SamplerState.Filter", D3D10_SVT_INT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.Filter) },
494 {0x2e, "SamplerState.AddressU", D3D10_SVT_INT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.AddressU) },
495 {0x2f, "SamplerState.AddressV", D3D10_SVT_INT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.AddressV) },
496 {0x30, "SamplerState.AddressW", D3D10_SVT_INT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.AddressW) },
497 {0x31, "SamplerState.MipLODBias", D3D10_SVT_FLOAT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.MipLODBias) },
498 {0x32, "SamplerState.MaxAnisotropy", D3D10_SVT_UINT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.MaxAnisotropy) },
499 {0x33, "SamplerState.ComparisonFunc", D3D10_SVT_INT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.ComparisonFunc) },
500 {0x34, "SamplerState.BorderColor", D3D10_SVT_FLOAT, 4, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.BorderColor) },
501 {0x35, "SamplerState.MinLOD", D3D10_SVT_FLOAT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.MinLOD) },
502 {0x36, "SamplerState.MaxLOD", D3D10_SVT_FLOAT, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, desc.MaxLOD) },
503 {0x37, "SamplerState.Texture", D3D10_SVT_TEXTURE, 1, 1, D3D10_C_SAMPLER, FIELD_OFFSET(struct d3d10_effect_sampler_desc, texture) },
506 static const D3D10_RASTERIZER_DESC default_rasterizer_desc =
508 D3D10_FILL_SOLID,
509 D3D10_CULL_BACK,
510 FALSE,
512 0.0f,
513 0.0f,
514 TRUE,
515 FALSE,
516 FALSE,
517 FALSE,
520 static const D3D10_DEPTH_STENCIL_DESC default_depth_stencil_desc =
522 TRUE,
523 D3D10_DEPTH_WRITE_MASK_ALL,
524 D3D10_COMPARISON_LESS,
525 FALSE,
526 D3D10_DEFAULT_STENCIL_READ_MASK,
527 D3D10_DEFAULT_STENCIL_WRITE_MASK,
528 {D3D10_STENCIL_OP_KEEP, D3D10_STENCIL_OP_KEEP, D3D10_STENCIL_OP_KEEP, D3D10_COMPARISON_ALWAYS},
529 {D3D10_STENCIL_OP_KEEP, D3D10_STENCIL_OP_KEEP, D3D10_STENCIL_OP_KEEP, D3D10_COMPARISON_ALWAYS},
532 static const D3D10_BLEND_DESC default_blend_desc =
534 FALSE,
535 {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
536 D3D10_BLEND_SRC_ALPHA,
537 D3D10_BLEND_INV_SRC_ALPHA,
538 D3D10_BLEND_OP_ADD,
539 D3D10_BLEND_SRC_ALPHA,
540 D3D10_BLEND_INV_SRC_ALPHA,
541 D3D10_BLEND_OP_ADD,
542 {0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf},
545 static const D3D10_SAMPLER_DESC default_sampler_desc =
547 D3D10_FILTER_MIN_MAG_MIP_POINT,
548 D3D10_TEXTURE_ADDRESS_WRAP,
549 D3D10_TEXTURE_ADDRESS_WRAP,
550 D3D10_TEXTURE_ADDRESS_WRAP,
551 0.0f,
553 D3D10_COMPARISON_NEVER,
554 {0.0f, 0.0f, 0.0f, 0.0f},
555 0.0f,
556 FLT_MAX,
559 struct d3d10_effect_state_storage_info
561 D3D_SHADER_VARIABLE_TYPE id;
562 SIZE_T size;
563 const void *default_state;
566 static const struct d3d10_effect_state_storage_info d3d10_effect_state_storage_info[] =
568 {D3D10_SVT_RASTERIZER, sizeof(default_rasterizer_desc), &default_rasterizer_desc },
569 {D3D10_SVT_DEPTHSTENCIL, sizeof(default_depth_stencil_desc), &default_depth_stencil_desc},
570 {D3D10_SVT_BLEND, sizeof(default_blend_desc), &default_blend_desc },
571 {D3D10_SVT_SAMPLER, sizeof(default_sampler_desc), &default_sampler_desc },
574 #define WINE_D3D10_TO_STR(x) case x: return #x
576 static const char *debug_d3d10_shader_variable_class(D3D10_SHADER_VARIABLE_CLASS c)
578 switch (c)
580 WINE_D3D10_TO_STR(D3D10_SVC_SCALAR);
581 WINE_D3D10_TO_STR(D3D10_SVC_VECTOR);
582 WINE_D3D10_TO_STR(D3D10_SVC_MATRIX_ROWS);
583 WINE_D3D10_TO_STR(D3D10_SVC_MATRIX_COLUMNS);
584 WINE_D3D10_TO_STR(D3D10_SVC_OBJECT);
585 WINE_D3D10_TO_STR(D3D10_SVC_STRUCT);
586 default:
587 FIXME("Unrecognised D3D10_SHADER_VARIABLE_CLASS %#x.\n", c);
588 return "unrecognised";
592 static const char *debug_d3d10_shader_variable_type(D3D10_SHADER_VARIABLE_TYPE t)
594 switch (t)
596 WINE_D3D10_TO_STR(D3D10_SVT_VOID);
597 WINE_D3D10_TO_STR(D3D10_SVT_BOOL);
598 WINE_D3D10_TO_STR(D3D10_SVT_INT);
599 WINE_D3D10_TO_STR(D3D10_SVT_FLOAT);
600 WINE_D3D10_TO_STR(D3D10_SVT_STRING);
601 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE);
602 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE1D);
603 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2D);
604 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE3D);
605 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURECUBE);
606 WINE_D3D10_TO_STR(D3D10_SVT_SAMPLER);
607 WINE_D3D10_TO_STR(D3D10_SVT_PIXELSHADER);
608 WINE_D3D10_TO_STR(D3D10_SVT_VERTEXSHADER);
609 WINE_D3D10_TO_STR(D3D10_SVT_UINT);
610 WINE_D3D10_TO_STR(D3D10_SVT_UINT8);
611 WINE_D3D10_TO_STR(D3D10_SVT_GEOMETRYSHADER);
612 WINE_D3D10_TO_STR(D3D10_SVT_RASTERIZER);
613 WINE_D3D10_TO_STR(D3D10_SVT_DEPTHSTENCIL);
614 WINE_D3D10_TO_STR(D3D10_SVT_BLEND);
615 WINE_D3D10_TO_STR(D3D10_SVT_BUFFER);
616 WINE_D3D10_TO_STR(D3D10_SVT_CBUFFER);
617 WINE_D3D10_TO_STR(D3D10_SVT_TBUFFER);
618 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE1DARRAY);
619 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DARRAY);
620 WINE_D3D10_TO_STR(D3D10_SVT_RENDERTARGETVIEW);
621 WINE_D3D10_TO_STR(D3D10_SVT_DEPTHSTENCILVIEW);
622 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DMS);
623 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURE2DMSARRAY);
624 WINE_D3D10_TO_STR(D3D10_SVT_TEXTURECUBEARRAY);
625 default:
626 FIXME("Unrecognised D3D10_SHADER_VARIABLE_TYPE %#x.\n", t);
627 return "unrecognised";
631 #undef WINE_D3D10_TO_STR
633 static HRESULT d3d10_effect_variable_get_raw_value(struct d3d10_effect_variable *v,
634 void *data, unsigned int offset, unsigned int count)
636 BOOL is_buffer;
638 is_buffer = v->type->basetype == D3D10_SVT_CBUFFER || v->type->basetype == D3D10_SVT_TBUFFER;
640 if (v->type->type_class == D3D10_SVC_OBJECT && !is_buffer)
642 WARN("Not supported on object variables of type %s.\n",
643 debug_d3d10_shader_variable_type(v->type->basetype));
644 return D3DERR_INVALIDCALL;
647 if (!is_buffer)
649 offset += v->buffer_offset;
650 v = v->buffer;
653 memcpy(data, v->u.buffer.local_buffer + offset, count);
655 return S_OK;
658 static BOOL read_float_value(uint32_t value, D3D_SHADER_VARIABLE_TYPE in_type,
659 float *out_data, unsigned int out_idx)
661 switch (in_type)
663 case D3D10_SVT_FLOAT:
664 out_data[out_idx] = *(float *)&value;
665 return TRUE;
667 case D3D10_SVT_INT:
668 out_data[out_idx] = (INT)value;
669 return TRUE;
671 case D3D10_SVT_UINT:
672 out_data[out_idx] = value;
673 return TRUE;
675 default:
676 FIXME("Unhandled in_type %#x.\n", in_type);
677 return FALSE;
681 static BOOL read_int32_value(uint32_t value, D3D_SHADER_VARIABLE_TYPE in_type,
682 int *out_data, unsigned int out_idx)
684 switch (in_type)
686 case D3D10_SVT_FLOAT:
687 out_data[out_idx] = *(float *)&value;
688 return TRUE;
690 case D3D10_SVT_INT:
691 case D3D10_SVT_UINT:
692 case D3D10_SVT_BOOL:
693 out_data[out_idx] = value;
694 return TRUE;
696 default:
697 FIXME("Unhandled in_type %#x.\n", in_type);
698 return FALSE;
702 static BOOL read_int8_value(uint32_t value, D3D_SHADER_VARIABLE_TYPE in_type,
703 INT8 *out_data, unsigned int out_idx)
705 switch (in_type)
707 case D3D10_SVT_INT:
708 case D3D10_SVT_UINT:
709 out_data[out_idx] = value;
710 return TRUE;
712 default:
713 FIXME("Unhandled in_type %#x.\n", in_type);
714 return FALSE;
718 static BOOL d3d10_effect_read_numeric_value(uint32_t value, D3D_SHADER_VARIABLE_TYPE in_type,
719 D3D_SHADER_VARIABLE_TYPE out_type, void *out_data, unsigned int out_idx)
721 switch (out_type)
723 case D3D10_SVT_FLOAT:
724 return read_float_value(value, in_type, out_data, out_idx);
725 case D3D10_SVT_INT:
726 case D3D10_SVT_UINT:
727 case D3D10_SVT_BOOL:
728 return read_int32_value(value, in_type, out_data, out_idx);
729 case D3D10_SVT_UINT8:
730 return read_int8_value(value, in_type, out_data, out_idx);
731 default:
732 FIXME("Unsupported property type %u.\n", out_type);
733 return FALSE;
737 static void d3d10_effect_update_dependent_props(struct d3d10_effect_prop_dependencies *deps,
738 void *container)
740 const struct d3d10_effect_state_property_info *property_info;
741 struct d3d10_effect_prop_dependency *d;
742 unsigned int i, j, count, variable_idx;
743 struct d3d10_effect_variable *v;
744 unsigned int *dst_index;
745 uint32_t value;
746 HRESULT hr;
747 void *dst;
749 for (i = 0; i < deps->count; ++i)
751 d = &deps->entries[i];
753 property_info = &property_infos[d->id];
755 dst = (char *)container + property_info->offset;
756 dst_index = (unsigned int *)((char *)container + property_info->index_offset);
758 switch (d->operation)
760 case D3D10_EOO_VAR:
761 case D3D10_EOO_CONST_INDEX:
763 v = d->var.v;
765 count = v->type->type_class == D3D10_SVC_VECTOR ? 4 : 1;
767 for (j = 0; j < count; ++j)
769 d3d10_effect_variable_get_raw_value(v, &value, d->var.offset + j * sizeof(value), sizeof(value));
770 d3d10_effect_read_numeric_value(value, v->type->basetype, property_info->type, dst, j);
773 break;
775 case D3D10_EOO_INDEX_EXPRESSION:
777 v = d->index_expr.v;
779 if (FAILED(hr = d3d10_effect_preshader_eval(&d->index_expr.index)))
781 WARN("Failed to evaluate index expression, hr %#x.\n", hr);
782 return;
785 variable_idx = *d->index_expr.index.reg_tables[D3D10_REG_TABLE_RESULT].dword;
787 if (variable_idx >= v->type->element_count)
789 WARN("Expression evaluated to invalid index value %u, array %s of size %u.\n",
790 variable_idx, debugstr_a(v->name), v->type->element_count);
791 variable_idx = 0;
794 /* Ignoring destination index here, there are no object typed array properties. */
795 switch (property_info->type)
797 case D3D10_SVT_VERTEXSHADER:
798 case D3D10_SVT_PIXELSHADER:
799 case D3D10_SVT_GEOMETRYSHADER:
800 *(void **)dst = v;
801 *dst_index = variable_idx;
802 break;
803 default:
804 *(void **)dst = &v->elements[variable_idx];
806 break;
808 default:
809 FIXME("Unsupported property update for %u.\n", d->operation);
814 static BOOL d3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
816 SIZE_T max_capacity, new_capacity;
817 void *new_elements;
819 if (count <= *capacity)
820 return TRUE;
822 max_capacity = ~(SIZE_T)0 / size;
823 if (count > max_capacity)
824 return FALSE;
826 new_capacity = max(1, *capacity);
827 while (new_capacity < count && new_capacity <= max_capacity / 2)
828 new_capacity *= 2;
829 if (new_capacity < count)
830 new_capacity = count;
832 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
833 return FALSE;
835 *elements = new_elements;
836 *capacity = new_capacity;
837 return TRUE;
840 static inline DWORD read_dword(const char **ptr)
842 DWORD d;
844 memcpy(&d, *ptr, sizeof(d));
845 *ptr += sizeof(d);
847 return d;
850 static BOOL require_space(size_t offset, size_t count, size_t size, size_t data_size)
852 return !count || (data_size - offset) / count >= size;
855 static void skip_dword_unknown(const char *location, const char **ptr, unsigned int count)
857 unsigned int i;
858 DWORD d;
860 FIXME("Skipping %u unknown DWORDs (%s):\n", count, location);
861 for (i = 0; i < count; ++i)
863 d = read_dword(ptr);
864 FIXME("\t0x%08x\n", d);
868 static HRESULT parse_dxbc(const char *data, SIZE_T data_size,
869 HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx)
871 const char *ptr = data;
872 HRESULT hr = S_OK;
873 DWORD chunk_count;
874 DWORD total_size;
875 unsigned int i;
876 DWORD version;
877 DWORD tag;
879 if (!data)
881 WARN("No data supplied.\n");
882 return E_FAIL;
885 tag = read_dword(&ptr);
886 TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));
888 if (tag != TAG_DXBC)
890 WARN("Wrong tag.\n");
891 return E_FAIL;
894 skip_dword_unknown("DXBC checksum", &ptr, 4);
896 version = read_dword(&ptr);
897 TRACE("version: %#x.\n", version);
898 if (version != 0x00000001)
900 WARN("Got unexpected DXBC version %#x.\n", version);
901 return E_FAIL;
904 total_size = read_dword(&ptr);
905 TRACE("total size: %#x\n", total_size);
907 if (data_size != total_size)
909 WARN("Wrong size supplied.\n");
910 return E_FAIL;
913 chunk_count = read_dword(&ptr);
914 TRACE("chunk count: %#x\n", chunk_count);
916 for (i = 0; i < chunk_count; ++i)
918 DWORD chunk_tag, chunk_size;
919 const char *chunk_ptr;
920 DWORD chunk_offset;
922 chunk_offset = read_dword(&ptr);
923 TRACE("chunk %u at offset %#x\n", i, chunk_offset);
925 if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size))
927 WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size);
928 return E_FAIL;
931 chunk_ptr = data + chunk_offset;
933 chunk_tag = read_dword(&chunk_ptr);
934 chunk_size = read_dword(&chunk_ptr);
936 if (!require_space(chunk_ptr - data, 1, chunk_size, data_size))
938 WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n",
939 chunk_size, data_size, chunk_offset);
940 return E_FAIL;
943 if (FAILED(hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx)))
944 break;
947 return hr;
950 static BOOL fx10_get_string(const char *data, size_t data_size, DWORD offset, const char **s, size_t *l)
952 size_t len, max_len;
954 if (offset >= data_size)
956 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
957 return FALSE;
960 max_len = data_size - offset;
961 if (!(len = strnlen(data + offset, max_len)))
963 *s = NULL;
964 *l = 0;
965 return TRUE;
968 if (len == max_len)
969 return FALSE;
971 *s = data + offset;
972 *l = ++len;
974 return TRUE;
977 static BOOL fx10_copy_string(const char *data, size_t data_size, DWORD offset, char **s)
979 const char *p;
980 size_t len;
982 if (!fx10_get_string(data, data_size, offset, &p, &len))
983 return FALSE;
985 if (!p)
987 *s = NULL;
988 return TRUE;
991 if (!(*s = heap_alloc(len)))
993 ERR("Failed to allocate string memory.\n");
994 return FALSE;
997 memcpy(*s, p, len);
999 return TRUE;
1002 static BOOL copy_name(const char *ptr, char **name)
1004 size_t name_len;
1006 if (!ptr) return TRUE;
1008 name_len = strlen(ptr) + 1;
1009 if (name_len == 1)
1011 return TRUE;
1014 if (!(*name = heap_alloc(name_len)))
1016 ERR("Failed to allocate name memory.\n");
1017 return FALSE;
1020 memcpy(*name, ptr, name_len);
1022 return TRUE;
1025 static struct d3d10_effect_variable * d3d10_effect_get_buffer_by_name(struct d3d10_effect *effect,
1026 const char *name)
1028 unsigned int i;
1030 for (i = 0; i < effect->local_buffer_count; ++i)
1032 struct d3d10_effect_variable *l = &effect->local_buffers[i];
1033 if (l->name && !strcmp(l->name, name))
1034 return l;
1037 return effect->pool ? d3d10_effect_get_buffer_by_name(effect->pool, name) : NULL;
1040 static struct d3d10_effect_variable * d3d10_effect_get_variable_by_name(
1041 const struct d3d10_effect *effect, const char *name)
1043 struct d3d10_effect_variable *v;
1044 unsigned int i, j;
1046 for (i = 0; i < effect->local_buffer_count; ++i)
1048 for (j = 0; j < effect->local_buffers[i].type->member_count; ++j)
1050 v = &effect->local_buffers[i].members[j];
1051 if (v->name && !strcmp(v->name, name))
1052 return v;
1056 for (i = 0; i < effect->local_variable_count; ++i)
1058 struct d3d10_effect_variable *v = &effect->local_variables[i];
1059 if (v->name && !strcmp(v->name, name))
1060 return v;
1063 return effect->pool ? d3d10_effect_get_variable_by_name(effect->pool, name) : NULL;
1066 static HRESULT get_fx10_shader_resources(struct d3d10_effect_variable *v)
1068 struct d3d10_effect_shader_variable *sv = &v->u.shader;
1069 struct d3d10_effect_shader_resource *sr;
1070 D3D10_SHADER_INPUT_BIND_DESC bind_desc;
1071 D3D10_SHADER_DESC desc;
1072 unsigned int i;
1074 sv->reflection->lpVtbl->GetDesc(sv->reflection, &desc);
1075 sv->resource_count = desc.BoundResources;
1077 if (!(sv->resources = heap_calloc(sv->resource_count, sizeof(*sv->resources))))
1079 ERR("Failed to allocate shader resource binding information memory.\n");
1080 return E_OUTOFMEMORY;
1083 for (i = 0; i < desc.BoundResources; ++i)
1085 sv->reflection->lpVtbl->GetResourceBindingDesc(sv->reflection, i, &bind_desc);
1086 sr = &sv->resources[i];
1088 sr->in_type = bind_desc.Type;
1089 sr->bind_point = bind_desc.BindPoint;
1090 sr->bind_count = bind_desc.BindCount;
1092 switch (bind_desc.Type)
1094 case D3D10_SIT_CBUFFER:
1095 case D3D10_SIT_TBUFFER:
1096 if (sr->bind_count != 1)
1098 WARN("Unexpected bind count %u for a buffer %s.\n", bind_desc.BindCount,
1099 debugstr_a(bind_desc.Name));
1100 return E_UNEXPECTED;
1102 sr->variable = d3d10_effect_get_buffer_by_name(v->effect, bind_desc.Name);
1103 break;
1105 case D3D10_SIT_SAMPLER:
1106 case D3D10_SIT_TEXTURE:
1107 sr->variable = d3d10_effect_get_variable_by_name(v->effect, bind_desc.Name);
1108 break;
1110 default:
1111 break;
1114 if (!sr->variable)
1116 WARN("Failed to find shader resource.\n");
1117 return E_FAIL;
1121 return S_OK;
1124 struct d3d10_effect_so_decl
1126 D3D10_SO_DECLARATION_ENTRY *entries;
1127 SIZE_T capacity;
1128 SIZE_T count;
1129 unsigned int stride;
1130 char *decl;
1133 static void d3d10_effect_cleanup_so_decl(struct d3d10_effect_so_decl *so_decl)
1135 heap_free(so_decl->entries);
1136 heap_free(so_decl->decl);
1137 memset(so_decl, 0, sizeof(*so_decl));
1140 static HRESULT d3d10_effect_parse_stream_output_declaration(const char *decl,
1141 struct d3d10_effect_so_decl *so_decl)
1143 static const char * xyzw = "xyzw";
1144 static const char * rgba = "rgba";
1145 char *p, *ptr, *end, *next, *mask, *m, *slot;
1146 unsigned int len = strlen(decl);
1147 D3D10_SO_DECLARATION_ENTRY e;
1149 memset(so_decl, 0, sizeof(*so_decl));
1151 if (!(so_decl->decl = heap_alloc(len + 1)))
1152 return E_OUTOFMEMORY;
1153 memcpy(so_decl->decl, decl, len + 1);
1155 p = so_decl->decl;
1157 while (p && *p)
1159 memset(&e, 0, sizeof(e));
1161 end = strchr(p, ';');
1162 next = end ? end + 1 : p + strlen(p);
1164 len = next - p;
1165 if (end) len--;
1167 /* Remove leading and trailing spaces. */
1168 while (len && isspace(*p)) { len--; p++; }
1169 while (len && isspace(p[len - 1])) len--;
1171 p[len] = 0;
1173 /* Output slot */
1174 if ((slot = strchr(p, ':')))
1176 *slot = 0;
1178 ptr = p;
1179 while (*ptr)
1181 if (!isdigit(*ptr))
1183 WARN("Invalid output slot %s.\n", debugstr_a(p));
1184 goto failed;
1186 ptr++;
1189 e.OutputSlot = atoi(p);
1190 p = slot + 1;
1193 /* Mask */
1194 if ((mask = strchr(p, '.')))
1196 *mask = 0; mask++;
1198 if ((m = strstr(xyzw, mask)))
1199 e.StartComponent = m - xyzw;
1200 else if ((m = strstr(rgba, mask)))
1201 e.StartComponent = m - rgba;
1202 else
1204 WARN("Invalid component mask %s.\n", debugstr_a(mask));
1205 goto failed;
1208 e.ComponentCount = strlen(mask);
1210 else
1212 e.StartComponent = 0;
1213 e.ComponentCount = 4;
1216 /* Semantic index and name */
1217 len = strlen(p);
1218 while (isdigit(p[len - 1]))
1219 len--;
1221 if (p[len])
1223 e.SemanticIndex = atoi(&p[len]);
1224 p[len] = 0;
1227 e.SemanticName = stricmp(p, "$SKIP") ? p : NULL;
1229 if (!d3d_array_reserve((void **)&so_decl->entries, &so_decl->capacity, so_decl->count + 1,
1230 sizeof(*so_decl->entries)))
1231 goto failed;
1233 so_decl->entries[so_decl->count++] = e;
1235 if (e.OutputSlot == 0)
1236 so_decl->stride += e.ComponentCount * sizeof(float);
1238 p = next;
1241 return S_OK;
1243 failed:
1244 d3d10_effect_cleanup_so_decl(so_decl);
1246 return E_FAIL;
1249 static HRESULT parse_fx10_shader(const char *data, size_t data_size, DWORD offset, struct d3d10_effect_variable *v)
1251 ID3D10Device *device = v->effect->device;
1252 DWORD dxbc_size;
1253 const char *ptr;
1254 HRESULT hr;
1256 if (v->effect->shaders.current >= v->effect->shaders.count)
1258 WARN("Invalid effect? Used shader current(%u) >= used shader count(%u)\n",
1259 v->effect->shaders.current, v->effect->shaders.count);
1260 return E_FAIL;
1263 v->effect->shaders.v[v->effect->shaders.current++] = v;
1265 if (offset >= data_size || !require_space(offset, 1, sizeof(dxbc_size), data_size))
1267 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
1268 return E_FAIL;
1271 ptr = data + offset;
1272 dxbc_size = read_dword(&ptr);
1273 TRACE("dxbc size: %#x\n", dxbc_size);
1275 if (!require_space(ptr - data, 1, dxbc_size, data_size))
1277 WARN("Invalid dxbc size %#x (data size %#lx, offset %#x).\n", offset, (long)data_size, offset);
1278 return E_FAIL;
1281 /* We got a shader VertexShader vs = NULL, so it is fine to skip this. */
1282 if (!dxbc_size) return S_OK;
1284 if (FAILED(hr = D3D10ReflectShader(ptr, dxbc_size, &v->u.shader.reflection)))
1285 return hr;
1287 D3DGetInputSignatureBlob(ptr, dxbc_size, &v->u.shader.input_signature);
1289 if (FAILED(hr = D3DCreateBlob(dxbc_size, &v->u.shader.bytecode)))
1290 return hr;
1292 memcpy(ID3D10Blob_GetBufferPointer(v->u.shader.bytecode), ptr, dxbc_size);
1294 if (FAILED(hr = get_fx10_shader_resources(v)))
1295 return hr;
1297 switch (v->type->basetype)
1299 case D3D10_SVT_VERTEXSHADER:
1300 hr = ID3D10Device_CreateVertexShader(device, ptr, dxbc_size, &v->u.shader.shader.vs);
1301 break;
1303 case D3D10_SVT_PIXELSHADER:
1304 hr = ID3D10Device_CreatePixelShader(device, ptr, dxbc_size, &v->u.shader.shader.ps);
1305 break;
1307 case D3D10_SVT_GEOMETRYSHADER:
1308 if (v->u.shader.stream_output_declaration)
1310 struct d3d10_effect_so_decl so_decl;
1312 if (FAILED(hr = d3d10_effect_parse_stream_output_declaration(v->u.shader.stream_output_declaration, &so_decl)))
1314 WARN("Failed to parse stream output declaration, hr %#x.\n", hr);
1315 break;
1318 hr = ID3D10Device_CreateGeometryShaderWithStreamOutput(device, ptr, dxbc_size,
1319 so_decl.entries, so_decl.count, so_decl.stride, &v->u.shader.shader.gs);
1321 d3d10_effect_cleanup_so_decl(&so_decl);
1323 else
1324 hr = ID3D10Device_CreateGeometryShader(device, ptr, dxbc_size, &v->u.shader.shader.gs);
1325 break;
1327 default:
1328 ERR("This should not happen!\n");
1329 return E_FAIL;
1332 return hr;
1335 static D3D10_SHADER_VARIABLE_CLASS d3d10_variable_class(DWORD c, BOOL is_column_major)
1337 switch (c)
1339 case 1: return D3D10_SVC_SCALAR;
1340 case 2: return D3D10_SVC_VECTOR;
1341 case 3: if (is_column_major) return D3D10_SVC_MATRIX_COLUMNS;
1342 else return D3D10_SVC_MATRIX_ROWS;
1343 default:
1344 FIXME("Unknown variable class %#x.\n", c);
1345 return 0;
1349 static D3D10_SHADER_VARIABLE_TYPE d3d10_variable_type(DWORD t, BOOL is_object,
1350 unsigned int *flags)
1352 *flags = 0;
1354 if(is_object)
1356 switch (t)
1358 case 1: return D3D10_SVT_STRING;
1359 case 2: return D3D10_SVT_BLEND;
1360 case 3: return D3D10_SVT_DEPTHSTENCIL;
1361 case 4: return D3D10_SVT_RASTERIZER;
1362 case 5: return D3D10_SVT_PIXELSHADER;
1363 case 6: return D3D10_SVT_VERTEXSHADER;
1364 case 7: return D3D10_SVT_GEOMETRYSHADER;
1365 case 8:
1366 *flags = D3D10_EOT_FLAG_GS_SO;
1367 return D3D10_SVT_GEOMETRYSHADER;
1369 case 9: return D3D10_SVT_TEXTURE;
1370 case 10: return D3D10_SVT_TEXTURE1D;
1371 case 11: return D3D10_SVT_TEXTURE1DARRAY;
1372 case 12: return D3D10_SVT_TEXTURE2D;
1373 case 13: return D3D10_SVT_TEXTURE2DARRAY;
1374 case 14: return D3D10_SVT_TEXTURE2DMS;
1375 case 15: return D3D10_SVT_TEXTURE2DMSARRAY;
1376 case 16: return D3D10_SVT_TEXTURE3D;
1377 case 17: return D3D10_SVT_TEXTURECUBE;
1379 case 19: return D3D10_SVT_RENDERTARGETVIEW;
1380 case 20: return D3D10_SVT_DEPTHSTENCILVIEW;
1381 case 21: return D3D10_SVT_SAMPLER;
1382 case 22: return D3D10_SVT_BUFFER;
1383 default:
1384 FIXME("Unknown variable type %#x.\n", t);
1385 return D3D10_SVT_VOID;
1388 else
1390 switch (t)
1392 case 1: return D3D10_SVT_FLOAT;
1393 case 2: return D3D10_SVT_INT;
1394 case 3: return D3D10_SVT_UINT;
1395 case 4: return D3D10_SVT_BOOL;
1396 default:
1397 FIXME("Unknown variable type %#x.\n", t);
1398 return D3D10_SVT_VOID;
1403 static HRESULT parse_fx10_type(const char *data, size_t data_size, DWORD offset, struct d3d10_effect_type *t)
1405 DWORD typeinfo, type_flags, type_kind;
1406 const char *ptr;
1407 unsigned int i;
1409 if (offset >= data_size || !require_space(offset, 6, sizeof(DWORD), data_size))
1411 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
1412 return E_FAIL;
1415 ptr = data + offset;
1416 offset = read_dword(&ptr);
1417 TRACE("Type name at offset %#x.\n", offset);
1419 if (!fx10_copy_string(data, data_size, offset, &t->name))
1421 ERR("Failed to copy name.\n");
1422 return E_OUTOFMEMORY;
1424 TRACE("Type name: %s.\n", debugstr_a(t->name));
1426 type_kind = read_dword(&ptr);
1427 TRACE("Kind: %u.\n", type_kind);
1429 t->element_count = read_dword(&ptr);
1430 TRACE("Element count: %u.\n", t->element_count);
1432 t->size_unpacked = read_dword(&ptr);
1433 TRACE("Unpacked size: %#x.\n", t->size_unpacked);
1435 t->stride = read_dword(&ptr);
1436 TRACE("Stride: %#x.\n", t->stride);
1438 t->size_packed = read_dword(&ptr);
1439 TRACE("Packed size %#x.\n", t->size_packed);
1441 switch (type_kind)
1443 case 1:
1444 TRACE("Type is numeric.\n");
1446 if (!require_space(ptr - data, 1, sizeof(typeinfo), data_size))
1448 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
1449 return E_FAIL;
1452 typeinfo = read_dword(&ptr);
1453 t->member_count = 0;
1454 t->column_count = (typeinfo & D3D10_FX10_TYPE_COLUMN_MASK) >> D3D10_FX10_TYPE_COLUMN_SHIFT;
1455 t->row_count = (typeinfo & D3D10_FX10_TYPE_ROW_MASK) >> D3D10_FX10_TYPE_ROW_SHIFT;
1456 t->basetype = d3d10_variable_type((typeinfo & D3D10_FX10_TYPE_BASETYPE_MASK) >> D3D10_FX10_TYPE_BASETYPE_SHIFT, FALSE, &type_flags);
1457 t->type_class = d3d10_variable_class((typeinfo & D3D10_FX10_TYPE_CLASS_MASK) >> D3D10_FX10_TYPE_CLASS_SHIFT, typeinfo & D3D10_FX10_TYPE_MATRIX_COLUMN_MAJOR_MASK);
1459 TRACE("Type description: %#x.\n", typeinfo);
1460 TRACE("\tcolumns: %u.\n", t->column_count);
1461 TRACE("\trows: %u.\n", t->row_count);
1462 TRACE("\tbasetype: %s.\n", debug_d3d10_shader_variable_type(t->basetype));
1463 TRACE("\tclass: %s.\n", debug_d3d10_shader_variable_class(t->type_class));
1464 TRACE("\tunknown bits: %#x.\n", typeinfo & ~(D3D10_FX10_TYPE_COLUMN_MASK | D3D10_FX10_TYPE_ROW_MASK
1465 | D3D10_FX10_TYPE_BASETYPE_MASK | D3D10_FX10_TYPE_CLASS_MASK | D3D10_FX10_TYPE_MATRIX_COLUMN_MAJOR_MASK));
1466 break;
1468 case 2:
1469 TRACE("Type is an object.\n");
1471 if (!require_space(ptr - data, 1, sizeof(typeinfo), data_size))
1473 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
1474 return E_FAIL;
1477 typeinfo = read_dword(&ptr);
1478 t->member_count = 0;
1479 t->column_count = 0;
1480 t->row_count = 0;
1481 t->basetype = d3d10_variable_type(typeinfo, TRUE, &type_flags);
1482 t->type_class = D3D10_SVC_OBJECT;
1483 t->flags = type_flags;
1485 TRACE("Type description: %#x.\n", typeinfo);
1486 TRACE("\tbasetype: %s.\n", debug_d3d10_shader_variable_type(t->basetype));
1487 TRACE("\tclass: %s.\n", debug_d3d10_shader_variable_class(t->type_class));
1488 TRACE("\tflags: %#x.\n", t->flags);
1489 break;
1491 case 3:
1492 TRACE("Type is a structure.\n");
1494 if (!require_space(ptr - data, 1, sizeof(t->member_count), data_size))
1496 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
1497 return E_FAIL;
1500 t->member_count = read_dword(&ptr);
1501 TRACE("Member count: %u.\n", t->member_count);
1503 t->column_count = 0;
1504 t->row_count = 0;
1505 t->basetype = 0;
1506 t->type_class = D3D10_SVC_STRUCT;
1508 if (!(t->members = heap_calloc(t->member_count, sizeof(*t->members))))
1510 ERR("Failed to allocate members memory.\n");
1511 return E_OUTOFMEMORY;
1514 if (!require_space(ptr - data, t->member_count, 4 * sizeof(DWORD), data_size))
1516 WARN("Invalid member count %#x (data size %#lx, offset %#x).\n",
1517 t->member_count, (long)data_size, offset);
1518 return E_FAIL;
1521 for (i = 0; i < t->member_count; ++i)
1523 struct d3d10_effect_type_member *typem = &t->members[i];
1525 offset = read_dword(&ptr);
1526 TRACE("Member name at offset %#x.\n", offset);
1528 if (!fx10_copy_string(data, data_size, offset, &typem->name))
1530 ERR("Failed to copy name.\n");
1531 return E_OUTOFMEMORY;
1533 TRACE("Member name: %s.\n", debugstr_a(typem->name));
1535 offset = read_dword(&ptr);
1536 TRACE("Member semantic at offset %#x.\n", offset);
1538 if (!fx10_copy_string(data, data_size, offset, &typem->semantic))
1540 ERR("Failed to copy semantic.\n");
1541 return E_OUTOFMEMORY;
1543 TRACE("Member semantic: %s.\n", debugstr_a(typem->semantic));
1545 typem->buffer_offset = read_dword(&ptr);
1546 TRACE("Member offset in struct: %#x.\n", typem->buffer_offset);
1548 offset = read_dword(&ptr);
1549 TRACE("Member type info at offset %#x.\n", offset);
1551 if (!(typem->type = get_fx10_type(t->effect, data, data_size, offset)))
1553 ERR("Failed to get variable type.\n");
1554 return E_FAIL;
1557 break;
1559 default:
1560 FIXME("Unhandled type kind %#x.\n", type_kind);
1561 return E_FAIL;
1564 if (t->element_count)
1566 TRACE("Elementtype for type at offset: %#x\n", t->id);
1568 /* allocate elementtype - we need only one, because all elements have the same type */
1569 if (!(t->elementtype = heap_alloc_zero(sizeof(*t->elementtype))))
1571 ERR("Failed to allocate members memory.\n");
1572 return E_OUTOFMEMORY;
1575 /* create a copy of the original type with some minor changes */
1576 t->elementtype->ID3D10EffectType_iface.lpVtbl = &d3d10_effect_type_vtbl;
1577 t->elementtype->effect = t->effect;
1579 if (!copy_name(t->name, &t->elementtype->name))
1581 ERR("Failed to copy name.\n");
1582 return E_OUTOFMEMORY;
1584 TRACE("\tType name: %s.\n", debugstr_a(t->elementtype->name));
1586 t->elementtype->element_count = 0;
1587 TRACE("\tElement count: %u.\n", t->elementtype->element_count);
1590 * Not sure if this calculation is 100% correct, but a test
1591 * shows that these values work.
1593 t->elementtype->size_unpacked = t->size_packed / t->element_count;
1594 TRACE("\tUnpacked size: %#x.\n", t->elementtype->size_unpacked);
1596 t->elementtype->stride = t->stride;
1597 TRACE("\tStride: %#x.\n", t->elementtype->stride);
1599 t->elementtype->size_packed = t->size_packed / t->element_count;
1600 TRACE("\tPacked size: %#x.\n", t->elementtype->size_packed);
1602 t->elementtype->member_count = t->member_count;
1603 TRACE("\tMember count: %u.\n", t->elementtype->member_count);
1605 t->elementtype->column_count = t->column_count;
1606 TRACE("\tColumns: %u.\n", t->elementtype->column_count);
1608 t->elementtype->row_count = t->row_count;
1609 TRACE("\tRows: %u.\n", t->elementtype->row_count);
1611 t->elementtype->basetype = t->basetype;
1612 TRACE("\tBasetype: %s.\n", debug_d3d10_shader_variable_type(t->elementtype->basetype));
1614 t->elementtype->type_class = t->type_class;
1615 TRACE("\tClass: %s.\n", debug_d3d10_shader_variable_class(t->elementtype->type_class));
1617 t->elementtype->members = t->members;
1620 return S_OK;
1623 static struct d3d10_effect_type *get_fx10_type(struct d3d10_effect *effect,
1624 const char *data, size_t data_size, DWORD offset)
1626 struct d3d10_effect_type *type;
1627 struct wine_rb_entry *entry;
1628 HRESULT hr;
1630 entry = wine_rb_get(&effect->types, &offset);
1631 if (entry)
1633 TRACE("Returning existing type.\n");
1634 return WINE_RB_ENTRY_VALUE(entry, struct d3d10_effect_type, entry);
1637 if (!(type = heap_alloc_zero(sizeof(*type))))
1639 ERR("Failed to allocate type memory.\n");
1640 return NULL;
1643 type->ID3D10EffectType_iface.lpVtbl = &d3d10_effect_type_vtbl;
1644 type->id = offset;
1645 type->effect = effect;
1646 if (FAILED(hr = parse_fx10_type(data, data_size, offset, type)))
1648 ERR("Failed to parse type info, hr %#x.\n", hr);
1649 heap_free(type);
1650 return NULL;
1653 if (wine_rb_put(&effect->types, &offset, &type->entry) == -1)
1655 ERR("Failed to insert type entry.\n");
1656 heap_free(type);
1657 return NULL;
1660 return type;
1663 static void set_variable_vtbl(struct d3d10_effect_variable *v)
1665 const ID3D10EffectVariableVtbl **vtbl = &v->ID3D10EffectVariable_iface.lpVtbl;
1667 switch (v->type->type_class)
1669 case D3D10_SVC_SCALAR:
1670 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_scalar_variable_vtbl;
1671 break;
1673 case D3D10_SVC_VECTOR:
1674 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_vector_variable_vtbl;
1675 break;
1677 case D3D10_SVC_MATRIX_ROWS:
1678 case D3D10_SVC_MATRIX_COLUMNS:
1679 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_matrix_variable_vtbl;
1680 break;
1682 case D3D10_SVC_STRUCT:
1683 *vtbl = &d3d10_effect_variable_vtbl;
1684 break;
1686 case D3D10_SVC_OBJECT:
1687 switch(v->type->basetype)
1689 case D3D10_SVT_STRING:
1690 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_string_variable_vtbl;
1691 break;
1693 case D3D10_SVT_TEXTURE:
1694 case D3D10_SVT_TEXTURE1D:
1695 case D3D10_SVT_TEXTURE1DARRAY:
1696 case D3D10_SVT_TEXTURE2D:
1697 case D3D10_SVT_TEXTURE2DARRAY:
1698 case D3D10_SVT_TEXTURE2DMS:
1699 case D3D10_SVT_TEXTURE2DMSARRAY:
1700 case D3D10_SVT_TEXTURE3D:
1701 case D3D10_SVT_TEXTURECUBE:
1702 case D3D10_SVT_BUFFER: /* Either resource or constant buffer. */
1703 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_resource_variable_vtbl;
1704 break;
1706 case D3D10_SVT_RENDERTARGETVIEW:
1707 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_render_target_view_variable_vtbl;
1708 break;
1710 case D3D10_SVT_DEPTHSTENCILVIEW:
1711 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_depth_stencil_view_variable_vtbl;
1712 break;
1714 case D3D10_SVT_DEPTHSTENCIL:
1715 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_depth_stencil_variable_vtbl;
1716 break;
1718 case D3D10_SVT_VERTEXSHADER:
1719 case D3D10_SVT_GEOMETRYSHADER:
1720 case D3D10_SVT_PIXELSHADER:
1721 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_variable_vtbl;
1722 break;
1724 case D3D10_SVT_BLEND:
1725 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_blend_variable_vtbl;
1726 break;
1728 case D3D10_SVT_RASTERIZER:
1729 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_rasterizer_variable_vtbl;
1730 break;
1732 case D3D10_SVT_SAMPLER:
1733 *vtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_sampler_variable_vtbl;
1734 break;
1736 default:
1737 FIXME("Unhandled basetype %s.\n", debug_d3d10_shader_variable_type(v->type->basetype));
1738 *vtbl = &d3d10_effect_variable_vtbl;
1739 break;
1741 break;
1743 default:
1744 FIXME("Unhandled type class %s.\n", debug_d3d10_shader_variable_class(v->type->type_class));
1745 *vtbl = &d3d10_effect_variable_vtbl;
1746 break;
1750 static HRESULT copy_variableinfo_from_type(struct d3d10_effect_variable *v)
1752 unsigned int i;
1753 HRESULT hr;
1755 if (v->type->member_count)
1757 if (!(v->members = heap_calloc(v->type->member_count, sizeof(*v->members))))
1759 ERR("Failed to allocate members memory.\n");
1760 return E_OUTOFMEMORY;
1763 for (i = 0; i < v->type->member_count; ++i)
1765 struct d3d10_effect_variable *var = &v->members[i];
1766 struct d3d10_effect_type_member *typem = &v->type->members[i];
1768 var->buffer = v->buffer;
1769 var->effect = v->effect;
1770 var->type = typem->type;
1771 set_variable_vtbl(var);
1773 if (!copy_name(typem->name, &var->name))
1775 ERR("Failed to copy name.\n");
1776 return E_OUTOFMEMORY;
1778 TRACE("Variable name: %s.\n", debugstr_a(var->name));
1780 if (!copy_name(typem->semantic, &var->semantic))
1782 ERR("Failed to copy name.\n");
1783 return E_OUTOFMEMORY;
1785 TRACE("Variable semantic: %s.\n", debugstr_a(var->semantic));
1787 var->buffer_offset = v->buffer_offset + typem->buffer_offset;
1788 TRACE("Variable buffer offset: %u.\n", var->buffer_offset);
1790 hr = copy_variableinfo_from_type(var);
1791 if (FAILED(hr)) return hr;
1795 if (v->type->element_count)
1797 unsigned int bufferoffset = v->buffer_offset;
1799 if (!(v->elements = heap_calloc(v->type->element_count, sizeof(*v->elements))))
1801 ERR("Failed to allocate elements memory.\n");
1802 return E_OUTOFMEMORY;
1805 for (i = 0; i < v->type->element_count; ++i)
1807 struct d3d10_effect_variable *var = &v->elements[i];
1809 var->buffer = v->buffer;
1810 var->effect = v->effect;
1811 var->type = v->type->elementtype;
1812 set_variable_vtbl(var);
1814 if (!copy_name(v->name, &var->name))
1816 ERR("Failed to copy name.\n");
1817 return E_OUTOFMEMORY;
1819 TRACE("Variable name: %s.\n", debugstr_a(var->name));
1821 if (!copy_name(v->semantic, &var->semantic))
1823 ERR("Failed to copy name.\n");
1824 return E_OUTOFMEMORY;
1826 TRACE("Variable semantic: %s.\n", debugstr_a(var->semantic));
1828 if (i != 0)
1830 bufferoffset += v->type->stride;
1832 var->buffer_offset = bufferoffset;
1833 TRACE("Variable buffer offset: %u.\n", var->buffer_offset);
1835 hr = copy_variableinfo_from_type(var);
1836 if (FAILED(hr)) return hr;
1840 return S_OK;
1843 static HRESULT parse_fx10_variable_head(const char *data, size_t data_size,
1844 const char **ptr, struct d3d10_effect_variable *v)
1846 DWORD offset;
1848 offset = read_dword(ptr);
1849 TRACE("Variable name at offset %#x.\n", offset);
1851 if (!fx10_copy_string(data, data_size, offset, &v->name))
1853 ERR("Failed to copy name.\n");
1854 return E_OUTOFMEMORY;
1856 TRACE("Variable name: %s.\n", debugstr_a(v->name));
1858 offset = read_dword(ptr);
1859 TRACE("Variable type info at offset %#x.\n", offset);
1861 if (!(v->type = get_fx10_type(v->effect, data, data_size, offset)))
1863 ERR("Failed to get variable type.\n");
1864 return E_FAIL;
1866 set_variable_vtbl(v);
1868 v->explicit_bind_point = ~0u;
1870 if (v->effect->flags & D3D10_EFFECT_IS_POOL)
1871 v->flag |= D3D10_EFFECT_VARIABLE_POOLED;
1873 return copy_variableinfo_from_type(v);
1876 static HRESULT parse_fx10_annotation(const char *data, size_t data_size,
1877 const char **ptr, struct d3d10_effect_variable *a)
1879 DWORD offset;
1880 HRESULT hr;
1882 if (FAILED(hr = parse_fx10_variable_head(data, data_size, ptr, a)))
1883 return hr;
1885 offset = read_dword(ptr);
1886 TRACE("Annotation value is at offset %#x.\n", offset);
1888 switch (a->type->basetype)
1890 case D3D10_SVT_STRING:
1891 if (!fx10_copy_string(data, data_size, offset, (char **)&a->u.buffer.local_buffer))
1893 ERR("Failed to copy name.\n");
1894 return E_OUTOFMEMORY;
1896 break;
1898 default:
1899 FIXME("Unhandled object type %#x.\n", a->type->basetype);
1902 /* mark the variable as annotation */
1903 a->flag |= D3D10_EFFECT_VARIABLE_ANNOTATION;
1905 return S_OK;
1908 static HRESULT parse_fx10_annotations(const char *data, size_t data_size, const char **ptr,
1909 struct d3d10_effect *effect, struct d3d10_effect_annotations *annotations)
1911 unsigned int i;
1912 HRESULT hr;
1914 if (!(annotations->elements = heap_calloc(annotations->count, sizeof(*annotations->elements))))
1916 ERR("Failed to allocate annotations memory.\n");
1917 return E_OUTOFMEMORY;
1920 for (i = 0; i < annotations->count; ++i)
1922 struct d3d10_effect_variable *a = &annotations->elements[i];
1924 a->effect = effect;
1925 a->buffer = &null_local_buffer;
1927 if (FAILED(hr = parse_fx10_annotation(data, data_size, ptr, a)))
1928 return hr;
1931 return hr;
1934 static HRESULT parse_fx10_anonymous_shader(struct d3d10_effect *e, D3D_SHADER_VARIABLE_TYPE basetype,
1935 struct d3d10_effect_anonymous_shader *s)
1937 struct d3d10_effect_variable *v = &s->shader;
1938 struct d3d10_effect_type *t = &s->type;
1939 const char *name = NULL;
1941 switch (basetype)
1943 case D3D10_SVT_VERTEXSHADER:
1944 name = "vertexshader";
1945 break;
1947 case D3D10_SVT_PIXELSHADER:
1948 name = "pixelshader";
1949 break;
1951 case D3D10_SVT_GEOMETRYSHADER:
1952 name = "geometryshader";
1953 break;
1955 default:
1956 WARN("Unhandled shader type %#x.\n", basetype);
1957 return E_FAIL;
1959 t->basetype = basetype;
1961 if (!copy_name(name, &t->name))
1963 ERR("Failed to copy name.\n");
1964 return E_OUTOFMEMORY;
1966 TRACE("Type name: %s.\n", debugstr_a(t->name));
1968 t->type_class = D3D10_SVC_OBJECT;
1970 t->ID3D10EffectType_iface.lpVtbl = &d3d10_effect_type_vtbl;
1972 v->type = t;
1973 v->effect = e;
1974 v->u.shader.isinline = 1;
1975 set_variable_vtbl(v);
1977 if (!copy_name("$Anonymous", &v->name))
1979 ERR("Failed to copy semantic.\n");
1980 return E_OUTOFMEMORY;
1982 TRACE("Variable name: %s.\n", debugstr_a(v->name));
1984 return S_OK;
1987 static const struct d3d10_effect_state_storage_info *get_storage_info(D3D_SHADER_VARIABLE_TYPE id)
1989 unsigned int i;
1991 for (i = 0; i < ARRAY_SIZE(d3d10_effect_state_storage_info); ++i)
1993 if (d3d10_effect_state_storage_info[i].id == id)
1994 return &d3d10_effect_state_storage_info[i];
1997 return NULL;
2000 static BOOL read_value_list(const char *data, size_t data_size, uint32_t offset,
2001 D3D_SHADER_VARIABLE_TYPE out_type, unsigned int out_base, unsigned int out_size,
2002 void *out_data)
2004 D3D_SHADER_VARIABLE_TYPE in_type;
2005 unsigned int i, type_flags;
2006 uint32_t t, value, count;
2007 const char *ptr;
2009 if (offset >= data_size || !require_space(offset, 1, sizeof(count), data_size))
2011 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
2012 return FALSE;
2015 ptr = data + offset;
2016 count = read_dword(&ptr);
2017 if (count != out_size)
2018 return FALSE;
2020 if (!require_space(ptr - data, count, 2 * sizeof(DWORD), data_size))
2022 WARN("Invalid value count %#x (offset %#x, data size %#lx).\n", count, offset, (long)data_size);
2023 return FALSE;
2026 TRACE("%u values:\n", count);
2027 for (i = 0; i < count; ++i)
2029 unsigned int out_idx = out_base * out_size + i;
2031 t = read_dword(&ptr);
2032 value = read_dword(&ptr);
2034 in_type = d3d10_variable_type(t, FALSE, &type_flags);
2035 TRACE("\t%s: %#x.\n", debug_d3d10_shader_variable_type(in_type), value);
2037 switch (out_type)
2039 case D3D10_SVT_FLOAT:
2040 case D3D10_SVT_INT:
2041 case D3D10_SVT_UINT:
2042 case D3D10_SVT_UINT8:
2043 case D3D10_SVT_BOOL:
2044 if (!d3d10_effect_read_numeric_value(value, in_type, out_type, out_data, out_idx))
2045 return FALSE;
2046 break;
2048 case D3D10_SVT_VERTEXSHADER:
2049 *(void **)out_data = &anonymous_vs;
2050 break;
2052 case D3D10_SVT_PIXELSHADER:
2053 *(void **)out_data = &anonymous_ps;
2054 break;
2056 case D3D10_SVT_GEOMETRYSHADER:
2057 *(void **)out_data = &anonymous_gs;
2058 break;
2060 case D3D10_SVT_TEXTURE:
2061 *(void **)out_data = &null_shader_resource_variable;
2062 break;
2064 case D3D10_SVT_DEPTHSTENCIL:
2065 *(void **)out_data = &null_depth_stencil_variable;
2066 break;
2068 case D3D10_SVT_BLEND:
2069 *(void **)out_data = &null_blend_variable;
2070 break;
2072 default:
2073 FIXME("Unhandled out_type %#x.\n", out_type);
2074 return FALSE;
2078 return TRUE;
2081 static BOOL is_object_property(const struct d3d10_effect_state_property_info *property_info)
2083 switch (property_info->type)
2085 case D3D10_SVT_RASTERIZER:
2086 case D3D10_SVT_DEPTHSTENCIL:
2087 case D3D10_SVT_BLEND:
2088 case D3D10_SVT_RENDERTARGETVIEW:
2089 case D3D10_SVT_DEPTHSTENCILVIEW:
2090 case D3D10_SVT_VERTEXSHADER:
2091 case D3D10_SVT_PIXELSHADER:
2092 case D3D10_SVT_GEOMETRYSHADER:
2093 case D3D10_SVT_TEXTURE:
2094 return TRUE;
2095 default:
2096 return FALSE;
2100 static BOOL is_object_property_type_matching(const struct d3d10_effect_state_property_info *property_info,
2101 const struct d3d10_effect_variable *v)
2103 if (property_info->type == v->type->basetype) return TRUE;
2105 switch (v->type->basetype)
2107 case D3D10_SVT_TEXTURE1D:
2108 case D3D10_SVT_TEXTURE1DARRAY:
2109 case D3D10_SVT_TEXTURE2D:
2110 case D3D10_SVT_TEXTURE2DARRAY:
2111 case D3D10_SVT_TEXTURE2DMS:
2112 case D3D10_SVT_TEXTURE2DMSARRAY:
2113 case D3D10_SVT_TEXTURE3D:
2114 case D3D10_SVT_TEXTURECUBE:
2115 if (property_info->type == D3D10_SVT_TEXTURE) return TRUE;
2116 /* fallthrough */
2117 default:
2118 return FALSE;
2122 static HRESULT parse_fx10_preshader_instr(struct d3d10_preshader_parse_context *context,
2123 unsigned int *offset, const char **ptr, unsigned int data_size)
2125 const struct preshader_op_info *op_info;
2126 unsigned int i, param_count, size;
2127 struct preshader_instr ins;
2128 uint32_t input_count;
2130 if (!require_space(*offset, 2, sizeof(uint32_t), data_size))
2132 WARN("Malformed FXLC table, size %u.\n", data_size);
2133 return E_FAIL;
2136 *(uint32_t *)&ins = read_dword(ptr);
2137 input_count = read_dword(ptr);
2138 *offset += 2 * sizeof(uint32_t);
2140 if (!(op_info = d3d10_effect_get_op_info(ins.opcode)))
2142 FIXME("Unrecognized opcode %#x.\n", ins.opcode);
2143 return E_FAIL;
2146 TRACE("Opcode %#x (%s), input count %u.\n", ins.opcode, op_info->name, input_count);
2148 /* Inputs + one output */
2149 param_count = input_count + 1;
2151 if (!require_space(*offset, 3 * param_count, sizeof(uint32_t), data_size))
2153 WARN("Malformed FXLC table, opcode %#x.\n", ins.opcode);
2154 return E_FAIL;
2156 *offset += 3 * param_count * sizeof(uint32_t);
2158 for (i = 0; i < param_count; ++i)
2160 uint32_t flags, regt, param_offset;
2162 flags = read_dword(ptr);
2163 if (flags)
2165 FIXME("Arguments flags are not supported %#x.\n", flags);
2166 return E_UNEXPECTED;
2169 regt = read_dword(ptr);
2170 param_offset = read_dword(ptr);
2172 switch (regt)
2174 case D3D10_REG_TABLE_CONSTANTS:
2175 case D3D10_REG_TABLE_CB:
2176 case D3D10_REG_TABLE_RESULT:
2177 case D3D10_REG_TABLE_TEMP:
2178 size = param_offset + (ins.scalar && i == 0 ? 1 : ins.comp_count);
2179 context->table_sizes[regt] = max(context->table_sizes[regt], size);
2180 break;
2181 default:
2182 FIXME("Unexpected register table index %u.\n", regt);
2183 break;
2187 return S_OK;
2190 static HRESULT parse_fx10_fxlc(void *ctx, const char *data, unsigned int data_size)
2192 struct d3d10_preshader_parse_context *context = ctx;
2193 struct d3d10_effect_preshader *p = context->preshader;
2194 unsigned int i, offset = 4;
2195 uint32_t ins_count;
2196 const char *ptr;
2197 HRESULT hr;
2199 if (data_size % sizeof(uint32_t))
2201 WARN("FXLC size misaligned %u.\n", data_size);
2202 return E_FAIL;
2205 if (FAILED(hr = D3DCreateBlob(data_size, &p->code)))
2206 return hr;
2207 memcpy(ID3D10Blob_GetBufferPointer(p->code), data, data_size);
2209 ptr = data;
2210 ins_count = read_dword(&ptr);
2211 TRACE("%u instructions.\n", ins_count);
2213 for (i = 0; i < ins_count; ++i)
2215 if (FAILED(hr = parse_fx10_preshader_instr(context, &offset, &ptr, data_size)))
2217 WARN("Failed to parse instruction %u.\n", i);
2218 return hr;
2222 if (FAILED(hr = d3d10_reg_table_allocate(&p->reg_tables[D3D10_REG_TABLE_RESULT],
2223 context->table_sizes[D3D10_REG_TABLE_RESULT]))) return hr;
2224 if (FAILED(hr = d3d10_reg_table_allocate(&p->reg_tables[D3D10_REG_TABLE_TEMP],
2225 context->table_sizes[D3D10_REG_TABLE_TEMP]))) return hr;
2227 return S_OK;
2230 static HRESULT parse_fx10_cli4(void *ctx, const char *data, unsigned int data_size)
2232 struct d3d10_preshader_parse_context *context = ctx;
2233 struct d3d10_effect_preshader *p = context->preshader;
2234 struct d3d10_reg_table *table = &p->reg_tables[D3D10_REG_TABLE_CONSTANTS];
2235 const char *ptr = data;
2236 uint32_t count;
2237 HRESULT hr;
2239 if (data_size < sizeof(DWORD))
2241 WARN("Invalid CLI4 chunk size %u.\n", data_size);
2242 return E_FAIL;
2245 count = read_dword(&ptr);
2247 TRACE("%u literal constants.\n", count);
2249 if (!require_space(4, count, sizeof(float), data_size))
2251 WARN("Invalid constant table size %u.\n", data_size);
2252 return E_FAIL;
2255 if (FAILED(hr = d3d10_reg_table_allocate(table, count)))
2256 return hr;
2258 memcpy(table->f, ptr, table->count * sizeof(*table->f));
2260 return S_OK;
2263 static HRESULT parse_fx10_ctab(void *ctx, const char *data, unsigned int data_size)
2265 struct d3d10_preshader_parse_context *context = ctx;
2266 struct d3d10_effect_preshader *p = context->preshader;
2267 struct ctab_header
2269 DWORD size;
2270 DWORD creator;
2271 DWORD version;
2272 DWORD constants;
2273 DWORD constantinfo;
2274 DWORD flags;
2275 DWORD target;
2276 } header;
2277 struct ctab_const_info
2279 DWORD name;
2280 WORD register_set;
2281 WORD register_index;
2282 WORD register_count;
2283 WORD reserved;
2284 DWORD typeinfo;
2285 DWORD default_value;
2286 } *info;
2287 unsigned int i, cb_reg_count = 0;
2288 const char *ptr = data;
2289 const char *name;
2290 size_t name_len;
2291 HRESULT hr;
2293 if (data_size < sizeof(header))
2295 WARN("Invalid constant table size %u.\n", data_size);
2296 return E_FAIL;
2299 header.size = read_dword(&ptr);
2300 header.creator = read_dword(&ptr);
2301 header.version = read_dword(&ptr);
2302 header.constants = read_dword(&ptr);
2303 header.constantinfo = read_dword(&ptr);
2304 header.flags = read_dword(&ptr);
2305 header.target = read_dword(&ptr);
2307 if (!require_space(header.constantinfo, header.constants, sizeof(*info), data_size))
2309 WARN("Invalid constant info section offset %#x.\n", header.constantinfo);
2310 return E_FAIL;
2313 p->vars_count = header.constants;
2315 TRACE("Variable count %u.\n", p->vars_count);
2317 if (!(p->vars = heap_calloc(p->vars_count, sizeof(*p->vars))))
2318 return E_OUTOFMEMORY;
2320 info = (struct ctab_const_info *)(data + header.constantinfo);
2321 for (i = 0; i < p->vars_count; ++i, ++info)
2323 if (!fx10_get_string(data, data_size, info->name, &name, &name_len))
2324 return E_FAIL;
2326 if (!(p->vars[i].v = d3d10_effect_get_variable_by_name(context->effect, name)))
2328 WARN("Couldn't find variable %s.\n", debugstr_a(name));
2329 return E_FAIL;
2332 /* 4 components per register */
2333 p->vars[i].offset = info->register_index * 4;
2334 p->vars[i].length = info->register_count * 4;
2336 cb_reg_count = max(cb_reg_count, info->register_index + info->register_count);
2339 /* Allocate contiguous "constant buffer" for all referenced variables. */
2340 if (FAILED(hr = d3d10_reg_table_allocate(&p->reg_tables[D3D10_REG_TABLE_CB], cb_reg_count * 4)))
2342 WARN("Failed to allocate variables buffer.\n");
2343 return hr;
2346 return S_OK;
2349 static HRESULT fxlvm_chunk_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
2351 TRACE("Chunk tag: %s, size: %u.\n", debugstr_an((const char *)&tag, 4), data_size);
2353 switch (tag)
2355 case TAG_FXLC:
2356 return parse_fx10_fxlc(ctx, data, data_size);
2358 case TAG_CLI4:
2359 return parse_fx10_cli4(ctx, data, data_size);
2361 case TAG_CTAB:
2362 return parse_fx10_ctab(ctx, data, data_size);
2364 default:
2365 FIXME("Unhandled chunk %s.\n", debugstr_an((const char *)&tag, 4));
2366 return S_OK;
2370 static HRESULT parse_fx10_preshader(const char *data, size_t data_size,
2371 struct d3d10_effect *effect, struct d3d10_effect_preshader *preshader)
2373 struct d3d10_preshader_parse_context context;
2374 HRESULT hr;
2376 memset(preshader, 0, sizeof(*preshader));
2377 memset(&context, 0, sizeof(context));
2378 context.preshader = preshader;
2379 context.effect = effect;
2381 if (FAILED(hr = parse_dxbc(data, data_size, fxlvm_chunk_handler, &context))) return hr;
2383 /* Constant buffer and literal constants are preallocated, validate here that expression
2384 has no invalid accesses for those. */
2386 if (context.table_sizes[D3D10_REG_TABLE_CONSTANTS] >
2387 preshader->reg_tables[D3D10_REG_TABLE_CONSTANTS].count)
2389 WARN("Expression references out of bounds literal constant.\n");
2390 return E_FAIL;
2393 if (context.table_sizes[D3D10_REG_TABLE_CB] > preshader->reg_tables[D3D10_REG_TABLE_CB].count)
2395 WARN("Expression references out of bounds variable.\n");
2396 return E_FAIL;
2399 return S_OK;
2402 static HRESULT d3d10_effect_add_prop_dependency(struct d3d10_effect_prop_dependencies *d,
2403 const struct d3d10_effect_prop_dependency *dep)
2405 if (!d3d_array_reserve((void **)&d->entries, &d->capacity, d->count + 1, sizeof(*d->entries)))
2406 return E_OUTOFMEMORY;
2408 d->entries[d->count++] = *dep;
2410 return S_OK;
2413 static HRESULT parse_fx10_property_assignment(const char *data, size_t data_size,
2414 const char **ptr, enum d3d10_effect_container_type container_type,
2415 struct d3d10_effect *effect, void *container, struct d3d10_effect_prop_dependencies *d)
2417 uint32_t id, idx, variable_idx, operation, value_offset, sodecl_offset;
2418 const struct d3d10_effect_state_property_info *property_info;
2419 struct d3d10_effect_prop_dependency dep;
2420 struct d3d10_effect_variable *variable;
2421 uint32_t code_offset, blob_size;
2422 const char *data_ptr, *name;
2423 unsigned int *dst_index;
2424 size_t name_len;
2425 HRESULT hr;
2426 void *dst;
2428 id = read_dword(ptr);
2429 idx = read_dword(ptr);
2430 operation = read_dword(ptr);
2431 value_offset = read_dword(ptr);
2433 if (id >= ARRAY_SIZE(property_infos))
2435 FIXME("Unknown property id %#x.\n", id);
2436 return E_FAIL;
2438 property_info = &property_infos[id];
2440 TRACE("Property %s[%#x] = value list @ offset %#x.\n", property_info->name, idx, value_offset);
2442 if (property_info->container_type != container_type)
2444 ERR("Invalid container type %#x for property %#x.\n", container_type, id);
2445 return E_FAIL;
2448 if (idx >= property_info->count)
2450 ERR("Invalid index %#x for property %#x.\n", idx, id);
2451 return E_FAIL;
2454 if (property_info->offset == ~0u)
2456 ERR("Unsupported property %#x.\n", id);
2457 return E_NOTIMPL;
2460 dst = (char *)container + property_info->offset;
2461 dst_index = (unsigned int *)((char *)container + property_info->index_offset);
2463 switch (operation)
2465 case D3D10_EOO_CONST:
2467 /* Constant values output directly to backing store. */
2468 if (!read_value_list(data, data_size, value_offset, property_info->type, idx,
2469 property_info->size, dst))
2471 ERR("Failed to read values for property %#x.\n", id);
2472 return E_FAIL;
2474 break;
2476 case D3D10_EOO_VAR:
2478 /* Variable. */
2479 if (!fx10_get_string(data, data_size, value_offset, &name, &name_len))
2481 WARN("Failed to get variable name.\n");
2482 return E_FAIL;
2484 TRACE("Variable name %s.\n", debugstr_a(name));
2486 if (!(variable = d3d10_effect_get_variable_by_name(effect, name)))
2488 WARN("Couldn't find variable %s.\n", debugstr_a(name));
2489 return E_FAIL;
2492 if (is_object_property(property_info))
2494 if (variable->type->element_count)
2496 WARN("Unexpected array variable value %s.\n", debugstr_a(name));
2497 return E_FAIL;
2500 if (!is_object_property_type_matching(property_info, variable))
2502 WARN("Object type mismatch. Variable type %#x, property type %#x.\n",
2503 variable->type->basetype, property_info->type);
2504 return E_FAIL;
2507 ((void **)dst)[idx] = variable;
2509 else
2511 if (property_info->size * sizeof(float) > variable->type->size_unpacked)
2513 WARN("Mismatching variable size %u, property size %u.\n",
2514 variable->type->size_unpacked, property_info->size);
2515 return E_FAIL;
2518 dep.id = id;
2519 dep.idx = idx;
2520 dep.operation = operation;
2521 dep.var.v = variable;
2522 dep.var.offset = 0;
2524 return d3d10_effect_add_prop_dependency(d, &dep);
2527 break;
2529 case D3D10_EOO_CONST_INDEX:
2531 /* Array variable, constant index. */
2532 if (value_offset >= data_size || !require_space(value_offset, 2, sizeof(DWORD), data_size))
2534 WARN("Invalid offset %#x (data size %#lx).\n", value_offset, (long)data_size);
2535 return E_FAIL;
2537 data_ptr = data + value_offset;
2538 value_offset = read_dword(&data_ptr);
2539 variable_idx = read_dword(&data_ptr);
2541 if (!fx10_get_string(data, data_size, value_offset, &name, &name_len))
2543 WARN("Failed to get variable name.\n");
2544 return E_FAIL;
2547 TRACE("Variable name %s[%s%u].\n", debugstr_a(name), is_object_property(property_info) ?
2548 "" : "offset ", variable_idx);
2550 if (!(variable = d3d10_effect_get_variable_by_name(effect, name)))
2552 WARN("Couldn't find variable %s.\n", debugstr_a(name));
2553 return E_FAIL;
2556 if (is_object_property(property_info))
2558 if (!variable->type->element_count || variable_idx >= variable->type->element_count)
2560 WARN("Invalid array size %u.\n", variable->type->element_count);
2561 return E_FAIL;
2564 if (!is_object_property_type_matching(property_info, variable))
2566 WARN("Object type mismatch. Variable type %#x, property type %#x.\n",
2567 variable->type->basetype, property_info->type);
2568 return E_FAIL;
2571 /* Shader variables are special, they are referenced via array, with index stored separately. */
2572 switch (property_info->type)
2574 case D3D10_SVT_VERTEXSHADER:
2575 case D3D10_SVT_PIXELSHADER:
2576 case D3D10_SVT_GEOMETRYSHADER:
2577 ((void **)dst)[idx] = variable;
2578 *dst_index = variable_idx;
2579 break;
2580 default:
2581 ((void **)dst)[idx] = &variable->elements[variable_idx];
2584 else
2586 unsigned int offset = variable_idx * sizeof(float);
2588 if (offset >= variable->type->size_unpacked ||
2589 variable->type->size_unpacked - offset < property_info->size * sizeof(float))
2591 WARN("Invalid numeric variable data offset %u.\n", variable_idx);
2592 return E_FAIL;
2595 dep.id = id;
2596 dep.idx = idx;
2597 dep.operation = operation;
2598 dep.var.v = variable;
2599 dep.var.offset = offset;
2601 return d3d10_effect_add_prop_dependency(d, &dep);
2604 break;
2606 case D3D10_EOO_INDEX_EXPRESSION:
2608 /* Variable, and an expression for its index. */
2609 if (value_offset >= data_size || !require_space(value_offset, 2, sizeof(DWORD), data_size))
2611 WARN("Invalid offset %#x (data size %#lx).\n", value_offset, (long)data_size);
2612 return E_FAIL;
2615 data_ptr = data + value_offset;
2616 value_offset = read_dword(&data_ptr);
2617 code_offset = read_dword(&data_ptr);
2619 if (!fx10_get_string(data, data_size, value_offset, &name, &name_len))
2621 WARN("Failed to get variable name.\n");
2622 return E_FAIL;
2625 TRACE("Variable name %s[<expr>].\n", debugstr_a(name));
2627 if (!(variable = d3d10_effect_get_variable_by_name(effect, name)))
2629 WARN("Couldn't find variable %s.\n", debugstr_a(name));
2630 return E_FAIL;
2633 if (!variable->type->element_count)
2635 WARN("Expected array variable.\n");
2636 return E_FAIL;
2639 if (!is_object_property(property_info))
2641 WARN("Expected object type property used with indexed expression.\n");
2642 return E_FAIL;
2645 if (code_offset >= data_size || !require_space(code_offset, 1, sizeof(DWORD), data_size))
2647 WARN("Invalid offset %#x (data size %#lx).\n", value_offset, (long)data_size);
2648 return E_FAIL;
2651 data_ptr = data + code_offset;
2652 blob_size = read_dword(&data_ptr);
2654 if (!require_space(code_offset, 1, sizeof(uint32_t) + blob_size, data_size))
2656 WARN("Invalid offset %#x (data size %#lx).\n", code_offset, (long)data_size);
2657 return E_FAIL;
2660 dep.id = id;
2661 dep.idx = idx;
2662 dep.operation = operation;
2663 dep.index_expr.v = variable;
2664 if (FAILED(hr = parse_fx10_preshader(data_ptr, blob_size, effect, &dep.index_expr.index)))
2666 WARN("Failed to parse preshader, hr %#x.\n", hr);
2667 return hr;
2670 return d3d10_effect_add_prop_dependency(d, &dep);
2672 case D3D10_EOO_VALUE_EXPRESSION:
2674 if (value_offset >= data_size || !require_space(value_offset, 1, sizeof(uint32_t), data_size))
2676 WARN("Invalid offset %#x (data size %#lx).\n", value_offset, (long)data_size);
2677 return E_FAIL;
2680 data_ptr = data + value_offset;
2681 blob_size = read_dword(&data_ptr);
2683 if (!require_space(value_offset, 1, sizeof(uint32_t) + blob_size, data_size))
2685 WARN("Invalid offset %#x (data size %#lx).\n", value_offset, (long)data_size);
2686 return E_FAIL;
2689 dep.id = id;
2690 dep.idx = idx;
2691 dep.operation = operation;
2692 if (FAILED(hr = parse_fx10_preshader(data_ptr, blob_size, effect, &dep.value_expr.value)))
2694 WARN("Failed to parse preshader, hr %#x.\n", hr);
2695 return hr;
2698 return d3d10_effect_add_prop_dependency(d, &dep);
2700 case D3D10_EOO_ANONYMOUS_SHADER:
2702 /* Anonymous shader */
2703 if (effect->anonymous_shader_current >= effect->anonymous_shader_count)
2705 ERR("Anonymous shader count is wrong!\n");
2706 return E_FAIL;
2709 if (value_offset >= data_size || !require_space(value_offset, 2, sizeof(DWORD), data_size))
2711 WARN("Invalid offset %#x (data size %#lx).\n", value_offset, (long)data_size);
2712 return E_FAIL;
2714 data_ptr = data + value_offset;
2715 value_offset = read_dword(&data_ptr);
2716 sodecl_offset = read_dword(&data_ptr);
2718 TRACE("Effect object starts at offset %#x.\n", value_offset);
2720 if (FAILED(hr = parse_fx10_anonymous_shader(effect, property_info->type,
2721 &effect->anonymous_shaders[effect->anonymous_shader_current])))
2722 return hr;
2724 variable = &effect->anonymous_shaders[effect->anonymous_shader_current].shader;
2725 ++effect->anonymous_shader_current;
2727 if (sodecl_offset)
2729 TRACE("Anonymous shader stream output declaration at offset %#x.\n", sodecl_offset);
2730 if (!fx10_copy_string(data, data_size, sodecl_offset,
2731 &variable->u.shader.stream_output_declaration))
2733 ERR("Failed to copy stream output declaration.\n");
2734 return E_FAIL;
2737 TRACE("Stream output declaration: %s.\n", debugstr_a(variable->u.shader.stream_output_declaration));
2740 switch (property_info->type)
2742 case D3D10_SVT_VERTEXSHADER:
2743 case D3D10_SVT_PIXELSHADER:
2744 case D3D10_SVT_GEOMETRYSHADER:
2745 if (FAILED(hr = parse_fx10_shader(data, data_size, value_offset, variable)))
2746 return hr;
2747 break;
2749 default:
2750 WARN("Unexpected shader type %#x.\n", property_info->type);
2751 return E_FAIL;
2754 ((void **)dst)[idx] = variable;
2756 break;
2758 default:
2759 FIXME("Unhandled operation %#x.\n", operation);
2760 return E_FAIL;
2763 return S_OK;
2766 static HRESULT parse_fx10_pass(const char *data, size_t data_size,
2767 const char **ptr, struct d3d10_effect_pass *p)
2769 DWORD offset, object_count;
2770 unsigned int i;
2771 HRESULT hr;
2773 offset = read_dword(ptr);
2774 TRACE("Pass name at offset %#x.\n", offset);
2776 if (!fx10_copy_string(data, data_size, offset, &p->name))
2778 ERR("Failed to copy name.\n");
2779 return E_OUTOFMEMORY;
2781 TRACE("Pass name: %s.\n", debugstr_a(p->name));
2783 object_count = read_dword(ptr);
2784 TRACE("Pass has %u effect objects.\n", object_count);
2786 p->annotations.count = read_dword(ptr);
2787 TRACE("Pass has %u annotations.\n", p->annotations.count);
2789 if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, p->technique->effect,
2790 &p->annotations)))
2792 ERR("Failed to parse pass annotations, hr %#x.\n", hr);
2793 return hr;
2796 p->vs.shader = &null_shader_variable;
2797 p->ps.shader = &null_shader_variable;
2798 p->gs.shader = &null_shader_variable;
2800 for (i = 0; i < object_count; ++i)
2802 if (FAILED(hr = parse_fx10_property_assignment(data, data_size, ptr,
2803 D3D10_C_PASS, p->technique->effect, p, &p->dependencies)))
2805 WARN("Failed to parse pass assignment %u, hr %#x.\n", i, hr);
2806 return hr;
2810 return hr;
2813 static HRESULT parse_fx10_technique(const char *data, size_t data_size,
2814 const char **ptr, struct d3d10_effect_technique *t)
2816 unsigned int i;
2817 DWORD offset;
2818 HRESULT hr;
2820 offset = read_dword(ptr);
2821 TRACE("Technique name at offset %#x.\n", offset);
2823 if (!fx10_copy_string(data, data_size, offset, &t->name))
2825 ERR("Failed to copy name.\n");
2826 return E_OUTOFMEMORY;
2828 TRACE("Technique name: %s.\n", debugstr_a(t->name));
2830 t->pass_count = read_dword(ptr);
2831 TRACE("Technique has %u passes\n", t->pass_count);
2833 t->annotations.count = read_dword(ptr);
2834 TRACE("Technique has %u annotations.\n", t->annotations.count);
2836 if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, t->effect,
2837 &t->annotations)))
2839 ERR("Failed to parse technique annotations, hr %#x.\n", hr);
2840 return hr;
2843 if (!(t->passes = heap_calloc(t->pass_count, sizeof(*t->passes))))
2845 ERR("Failed to allocate passes memory\n");
2846 return E_OUTOFMEMORY;
2849 for (i = 0; i < t->pass_count; ++i)
2851 struct d3d10_effect_pass *p = &t->passes[i];
2853 p->ID3D10EffectPass_iface.lpVtbl = &d3d10_effect_pass_vtbl;
2854 p->technique = t;
2856 if (FAILED(hr = parse_fx10_pass(data, data_size, ptr, p)))
2857 return hr;
2860 return S_OK;
2863 static void parse_fx10_set_default_numeric_value(const char **ptr, struct d3d10_effect_variable *v)
2865 float *dst = (float *)(v->buffer->u.buffer.local_buffer + v->buffer_offset), *src;
2866 BOOL col_major = v->type->type_class == D3D10_SVC_MATRIX_COLUMNS;
2867 unsigned int col_count = v->type->column_count, col;
2868 unsigned int row_count = v->type->row_count, row;
2870 src = (float *)*ptr;
2872 if (col_major)
2874 for (col = 0; col < col_count; ++col)
2876 for (row = 0; row < row_count; ++row)
2877 dst[row] = src[row * col_count + col];
2878 dst += 4;
2881 else
2883 for (row = 0; row < row_count; ++row)
2885 memcpy(dst, src, col_count * sizeof(float));
2886 src += col_count;
2887 dst += 4;
2891 *ptr += col_count * row_count * sizeof(float);
2894 static void parse_fx10_default_value(const char **ptr, struct d3d10_effect_variable *var)
2896 unsigned int element_count = max(var->type->element_count, 1), i, m;
2897 struct d3d10_effect_variable *v;
2899 for (i = 0; i < element_count; ++i)
2901 v = d3d10_array_get_element(var, i);
2903 switch (v->type->type_class)
2905 case D3D10_SVC_STRUCT:
2906 for (m = 0; m < v->type->member_count; ++m)
2907 parse_fx10_default_value(ptr, &v->members[m]);
2908 break;
2909 case D3D10_SVC_SCALAR:
2910 case D3D10_SVC_VECTOR:
2911 case D3D10_SVC_MATRIX_COLUMNS:
2912 case D3D10_SVC_MATRIX_ROWS:
2913 parse_fx10_set_default_numeric_value(ptr, v);
2914 break;
2915 default:
2916 FIXME("Unexpected initial value for type %#x.\n", v->type->basetype);
2917 return;
2922 static void d3d10_effect_variable_update_buffer_offsets(struct d3d10_effect_variable *v,
2923 unsigned int offset)
2925 unsigned int i;
2927 for (i = 0; i < v->type->member_count; ++i)
2928 d3d10_effect_variable_update_buffer_offsets(&v->members[i], offset);
2930 for (i = 0; i < v->type->element_count; ++i)
2931 d3d10_effect_variable_update_buffer_offsets(&v->elements[i], offset);
2933 v->buffer_offset += offset;
2936 static HRESULT parse_fx10_numeric_variable(const char *data, size_t data_size,
2937 const char **ptr, BOOL local, struct d3d10_effect_variable *v)
2939 uint32_t offset, flags, default_value_offset, buffer_offset;
2940 const char *data_ptr;
2941 HRESULT hr;
2943 if (FAILED(hr = parse_fx10_variable_head(data, data_size, ptr, v)))
2944 return hr;
2946 offset = read_dword(ptr);
2947 TRACE("Variable semantic at offset %#x.\n", offset);
2949 if (!fx10_copy_string(data, data_size, offset, &v->semantic))
2951 ERR("Failed to copy semantic.\n");
2952 return E_OUTOFMEMORY;
2954 TRACE("Variable semantic: %s.\n", debugstr_a(v->semantic));
2956 buffer_offset = read_dword(ptr);
2957 TRACE("Variable offset in buffer: %#x.\n", buffer_offset);
2959 default_value_offset = read_dword(ptr);
2960 TRACE("Variable default value offset: %#x.\n", default_value_offset);
2962 flags = read_dword(ptr);
2963 TRACE("Variable flags: %#x.\n", flags);
2965 v->flag |= flags;
2967 /* At this point storage offsets for members and array elements are relative to containing
2968 variable. Update them by moving to correct offset within a buffer. */
2969 d3d10_effect_variable_update_buffer_offsets(v, buffer_offset);
2971 if (local)
2973 if (default_value_offset)
2975 if (!require_space(default_value_offset, 1, v->type->size_packed, data_size))
2977 WARN("Invalid default value offset %#x, variable packed size %u.\n", default_value_offset,
2978 v->type->size_packed);
2979 return E_FAIL;
2982 data_ptr = data + default_value_offset;
2983 parse_fx10_default_value(&data_ptr, v);
2986 v->annotations.count = read_dword(ptr);
2987 TRACE("Variable has %u annotations.\n", v->annotations.count);
2989 if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, v->effect,
2990 &v->annotations)))
2992 ERR("Failed to parse variable annotations, hr %#x.\n", hr);
2993 return hr;
2997 if (v->flag & D3D10_EFFECT_VARIABLE_EXPLICIT_BIND_POINT)
2998 v->explicit_bind_point = v->buffer_offset;
3000 return S_OK;
3003 static HRESULT create_state_object(struct d3d10_effect_variable *v)
3005 ID3D10Device *device = v->effect->device;
3006 HRESULT hr;
3008 switch (v->type->basetype)
3010 case D3D10_SVT_DEPTHSTENCIL:
3011 if (FAILED(hr = ID3D10Device_CreateDepthStencilState(device,
3012 &v->u.state.desc.depth_stencil, &v->u.state.object.depth_stencil)))
3013 return hr;
3014 break;
3016 case D3D10_SVT_BLEND:
3017 if (FAILED(hr = ID3D10Device_CreateBlendState(device,
3018 &v->u.state.desc.blend, &v->u.state.object.blend)))
3019 return hr;
3020 break;
3022 case D3D10_SVT_RASTERIZER:
3023 if (FAILED(hr = ID3D10Device_CreateRasterizerState(device,
3024 &v->u.state.desc.rasterizer, &v->u.state.object.rasterizer)))
3025 return hr;
3026 break;
3028 case D3D10_SVT_SAMPLER:
3029 if (FAILED(hr = ID3D10Device_CreateSamplerState(device,
3030 &v->u.state.desc.sampler.desc, &v->u.state.object.sampler)))
3031 return hr;
3032 break;
3034 default:
3035 ERR("Unhandled variable type %s.\n", debug_d3d10_shader_variable_type(v->type->basetype));
3036 return E_FAIL;
3039 return S_OK;
3042 static HRESULT parse_fx10_object_variable(const char *data, size_t data_size,
3043 const char **ptr, BOOL shared_type_desc, struct d3d10_effect_variable *v)
3045 struct d3d10_effect_var_array *vars;
3046 struct d3d10_effect_variable *var;
3047 unsigned int i, j, element_count;
3048 HRESULT hr;
3049 DWORD offset;
3051 if (FAILED(hr = parse_fx10_variable_head(data, data_size, ptr, v)))
3052 return hr;
3054 offset = read_dword(ptr);
3055 TRACE("Variable semantic at offset %#x.\n", offset);
3057 if (!fx10_copy_string(data, data_size, offset, &v->semantic))
3059 ERR("Failed to copy semantic.\n");
3060 return E_OUTOFMEMORY;
3062 TRACE("Variable semantic: %s.\n", debugstr_a(v->semantic));
3064 v->explicit_bind_point = read_dword(ptr);
3065 TRACE("Variable explicit bind point %#x.\n", v->explicit_bind_point);
3067 /* Shared variable description contains only type information. */
3068 if (shared_type_desc) return S_OK;
3070 element_count = max(v->type->element_count, 1);
3072 switch (v->type->basetype)
3074 case D3D10_SVT_TEXTURE:
3075 case D3D10_SVT_TEXTURE1D:
3076 case D3D10_SVT_TEXTURE1DARRAY:
3077 case D3D10_SVT_TEXTURE2D:
3078 case D3D10_SVT_TEXTURE2DARRAY:
3079 case D3D10_SVT_TEXTURE2DMS:
3080 case D3D10_SVT_TEXTURE2DMSARRAY:
3081 case D3D10_SVT_TEXTURE3D:
3082 case D3D10_SVT_TEXTURECUBE:
3083 if (!(v->u.resource.srv = heap_calloc(element_count, sizeof(*v->u.resource.srv))))
3085 ERR("Failed to allocate shader resource view array memory.\n");
3086 return E_OUTOFMEMORY;
3088 v->u.resource.parent = TRUE;
3090 if (v->elements)
3092 for (i = 0; i < v->type->element_count; ++i)
3094 v->elements[i].u.resource.srv = &v->u.resource.srv[i];
3095 v->elements[i].u.resource.parent = FALSE;
3098 break;
3100 case D3D10_SVT_RENDERTARGETVIEW:
3101 case D3D10_SVT_DEPTHSTENCILVIEW:
3102 case D3D10_SVT_BUFFER:
3103 TRACE("SVT could not have elements.\n");
3104 break;
3106 case D3D10_SVT_VERTEXSHADER:
3107 case D3D10_SVT_PIXELSHADER:
3108 case D3D10_SVT_GEOMETRYSHADER:
3109 TRACE("Shader type is %s\n", debug_d3d10_shader_variable_type(v->type->basetype));
3110 for (i = 0; i < element_count; ++i)
3112 DWORD shader_offset, sodecl_offset;
3114 var = d3d10_array_get_element(v, i);
3116 shader_offset = read_dword(ptr);
3117 TRACE("Shader offset: %#x.\n", shader_offset);
3119 if (v->type->flags & D3D10_EOT_FLAG_GS_SO)
3121 sodecl_offset = read_dword(ptr);
3122 TRACE("Stream output declaration at offset %#x.\n", sodecl_offset);
3124 if (!fx10_copy_string(data, data_size, sodecl_offset,
3125 &var->u.shader.stream_output_declaration))
3127 ERR("Failed to copy stream output declaration.\n");
3128 return E_OUTOFMEMORY;
3131 TRACE("Stream output declaration: %s.\n", debugstr_a(var->u.shader.stream_output_declaration));
3134 if (FAILED(hr = parse_fx10_shader(data, data_size, shader_offset, var)))
3135 return hr;
3137 break;
3139 case D3D10_SVT_DEPTHSTENCIL:
3140 case D3D10_SVT_BLEND:
3141 case D3D10_SVT_RASTERIZER:
3142 case D3D10_SVT_SAMPLER:
3144 const struct d3d10_effect_state_storage_info *storage_info;
3146 if (!(storage_info = get_storage_info(v->type->basetype)))
3148 FIXME("Failed to get backing store info for type %s.\n",
3149 debug_d3d10_shader_variable_type(v->type->basetype));
3150 return E_FAIL;
3153 if (storage_info->size > sizeof(v->u.state.desc))
3155 ERR("Invalid storage size %#lx.\n", storage_info->size);
3156 return E_FAIL;
3159 switch (v->type->basetype)
3161 case D3D10_SVT_DEPTHSTENCIL:
3162 vars = &v->effect->ds_states;
3163 break;
3164 case D3D10_SVT_BLEND:
3165 vars = &v->effect->blend_states;
3166 break;
3167 case D3D10_SVT_RASTERIZER:
3168 vars = &v->effect->rs_states;
3169 break;
3170 case D3D10_SVT_SAMPLER:
3171 vars = &v->effect->samplers;
3172 break;
3173 default:
3177 for (i = 0; i < element_count; ++i)
3179 unsigned int prop_count;
3181 var = d3d10_array_get_element(v, i);
3183 if (vars->current >= vars->count)
3185 WARN("Wrong variable array size for %#x.\n", v->type->basetype);
3186 return E_FAIL;
3188 var->u.state.index = vars->current;
3189 vars->v[vars->current++] = var;
3191 prop_count = read_dword(ptr);
3192 TRACE("State object property count: %#x.\n", prop_count);
3194 memcpy(&var->u.state.desc, storage_info->default_state, storage_info->size);
3196 for (j = 0; j < prop_count; ++j)
3198 if (FAILED(hr = parse_fx10_property_assignment(data, data_size, ptr,
3199 get_var_container_type(var), var->effect, &var->u.state.desc,
3200 &var->u.state.dependencies)))
3202 ERR("Failed to read property list.\n");
3203 return hr;
3207 if (FAILED(hr = create_state_object(var)))
3208 return hr;
3211 break;
3213 default:
3214 FIXME("Unhandled case %s.\n", debug_d3d10_shader_variable_type(v->type->basetype));
3215 return E_FAIL;
3218 v->annotations.count = read_dword(ptr);
3219 TRACE("Variable has %u annotations.\n", v->annotations.count);
3221 if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, v->effect,
3222 &v->annotations)))
3224 ERR("Failed to parse variable annotations, hr %#x.\n", hr);
3225 return hr;
3228 return S_OK;
3231 static HRESULT create_buffer_object(struct d3d10_effect_variable *v)
3233 D3D10_BUFFER_DESC buffer_desc;
3234 D3D10_SUBRESOURCE_DATA subresource_data;
3235 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc;
3236 ID3D10Device *device = v->effect->device;
3237 HRESULT hr;
3239 buffer_desc.ByteWidth = v->data_size;
3240 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
3241 buffer_desc.CPUAccessFlags = 0;
3242 buffer_desc.MiscFlags = 0;
3243 if (v->type->basetype == D3D10_SVT_CBUFFER)
3244 buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
3245 else
3246 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
3248 subresource_data.pSysMem = v->u.buffer.local_buffer;
3249 subresource_data.SysMemPitch = 0;
3250 subresource_data.SysMemSlicePitch = 0;
3252 if (FAILED(hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &subresource_data, &v->u.buffer.buffer)))
3253 return hr;
3255 if (v->type->basetype == D3D10_SVT_TBUFFER)
3257 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
3258 srv_desc.ViewDimension = D3D_SRV_DIMENSION_BUFFER;
3259 srv_desc.Buffer.ElementOffset = 0;
3260 srv_desc.Buffer.ElementWidth = v->type->size_unpacked / 16;
3261 if (v->type->size_unpacked % 16)
3262 WARN("Unexpected texture buffer size not a multiple of 16.\n");
3264 if (FAILED(hr = ID3D10Device_CreateShaderResourceView(device, (ID3D10Resource *)v->u.buffer.buffer,
3265 &srv_desc, &v->u.buffer.resource_view)))
3266 return hr;
3268 else
3269 v->u.buffer.resource_view = NULL;
3271 return S_OK;
3274 static HRESULT parse_fx10_buffer(const char *data, size_t data_size, const char **ptr,
3275 BOOL local, struct d3d10_effect_variable *l)
3277 const char *prefix = local ? "Local" : "Shared";
3278 unsigned int i;
3279 DWORD offset;
3280 D3D10_CBUFFER_TYPE d3d10_cbuffer_type;
3281 HRESULT hr;
3282 unsigned int stride = 0;
3284 /* Generate our own type, it isn't in the fx blob. */
3285 if (!(l->type = heap_alloc_zero(sizeof(*l->type))))
3287 ERR("Failed to allocate local buffer type memory.\n");
3288 return E_OUTOFMEMORY;
3290 l->type->ID3D10EffectType_iface.lpVtbl = &d3d10_effect_type_vtbl;
3291 l->type->type_class = D3D10_SVC_OBJECT;
3292 l->type->effect = l->effect;
3294 offset = read_dword(ptr);
3295 TRACE("%s buffer name at offset %#x.\n", prefix, offset);
3297 if (!fx10_copy_string(data, data_size, offset, &l->name))
3299 ERR("Failed to copy name.\n");
3300 return E_OUTOFMEMORY;
3302 TRACE("%s buffer name: %s.\n", prefix, debugstr_a(l->name));
3304 l->data_size = read_dword(ptr);
3305 TRACE("%s buffer data size: %#x.\n", prefix, l->data_size);
3307 d3d10_cbuffer_type = read_dword(ptr);
3308 TRACE("%s buffer type: %#x.\n", prefix, d3d10_cbuffer_type);
3310 switch(d3d10_cbuffer_type)
3312 case D3D10_CT_CBUFFER:
3313 l->type->basetype = D3D10_SVT_CBUFFER;
3314 if (!copy_name("cbuffer", &l->type->name))
3316 ERR("Failed to copy name.\n");
3317 return E_OUTOFMEMORY;
3319 break;
3321 case D3D10_CT_TBUFFER:
3322 l->type->basetype = D3D10_SVT_TBUFFER;
3323 if (!copy_name("tbuffer", &l->type->name))
3325 ERR("Failed to copy name.\n");
3326 return E_OUTOFMEMORY;
3328 break;
3330 default:
3331 ERR("Unexpected D3D10_CBUFFER_TYPE %#x!\n", d3d10_cbuffer_type);
3332 return E_FAIL;
3335 l->type->member_count = read_dword(ptr);
3336 TRACE("%s buffer member count: %#x.\n", prefix, l->type->member_count);
3338 l->explicit_bind_point = read_dword(ptr);
3339 TRACE("%s buffer explicit bind point: %#x.\n", prefix, l->explicit_bind_point);
3341 if (l->effect->flags & D3D10_EFFECT_IS_POOL)
3342 l->flag |= D3D10_EFFECT_VARIABLE_POOLED;
3344 if (local)
3346 l->annotations.count = read_dword(ptr);
3347 TRACE("Local buffer has %u annotations.\n", l->annotations.count);
3349 if (FAILED(hr = parse_fx10_annotations(data, data_size, ptr, l->effect,
3350 &l->annotations)))
3352 ERR("Failed to parse buffer annotations, hr %#x.\n", hr);
3353 return hr;
3357 if (!(l->members = heap_calloc(l->type->member_count, sizeof(*l->members))))
3359 ERR("Failed to allocate members memory.\n");
3360 return E_OUTOFMEMORY;
3363 if (!(l->type->members = heap_calloc(l->type->member_count, sizeof(*l->type->members))))
3365 ERR("Failed to allocate type members memory.\n");
3366 return E_OUTOFMEMORY;
3369 if (local && !(l->u.buffer.local_buffer = heap_alloc_zero(l->data_size)))
3371 ERR("Failed to allocate local constant buffer memory.\n");
3372 return E_OUTOFMEMORY;
3375 for (i = 0; i < l->type->member_count; ++i)
3377 struct d3d10_effect_variable *v = &l->members[i];
3378 struct d3d10_effect_type_member *typem = &l->type->members[i];
3380 v->buffer = l;
3381 v->effect = l->effect;
3383 if (FAILED(hr = parse_fx10_numeric_variable(data, data_size, ptr, local, v)))
3384 return hr;
3387 * Copy the values from the variable type to the constant buffers type
3388 * members structure, because it is our own generated type.
3390 typem->type = v->type;
3392 if (!copy_name(v->name, &typem->name))
3394 ERR("Failed to copy name.\n");
3395 return E_OUTOFMEMORY;
3397 TRACE("Variable name: %s.\n", debugstr_a(typem->name));
3399 if (!copy_name(v->semantic, &typem->semantic))
3401 ERR("Failed to copy name.\n");
3402 return E_OUTOFMEMORY;
3404 TRACE("Variable semantic: %s.\n", debugstr_a(typem->semantic));
3406 typem->buffer_offset = v->buffer_offset;
3407 TRACE("Variable buffer offset: %u.\n", typem->buffer_offset);
3409 l->type->size_packed += v->type->size_packed;
3412 * For the complete constantbuffer the size_unpacked = stride,
3413 * the stride is calculated like this:
3415 * 1) if the constant buffer variables are packed with packoffset
3416 * - stride = the highest used constant
3417 * - the complete stride has to be a multiple of 0x10
3419 * 2) if the constant buffer variables are NOT packed with packoffset
3420 * - sum of unpacked size for all variables which fit in a 0x10 part
3421 * - if the size exceeds a 0x10 part, the rest of the old part is skipped
3422 * and a new part is started
3423 * - if the variable is a struct it is always used a new part
3424 * - the complete stride has to be a multiple of 0x10
3426 * e.g.:
3427 * 0x4, 0x4, 0x4, 0x8, 0x4, 0x14, 0x4
3428 * part 0x10 0x10 0x20 -> 0x40
3430 if (v->flag & D3D10_EFFECT_VARIABLE_EXPLICIT_BIND_POINT)
3432 if ((v->type->size_unpacked + v->buffer_offset) > stride)
3434 stride = v->type->size_unpacked + v->buffer_offset;
3437 else
3439 if (v->type->type_class == D3D10_SVC_STRUCT)
3441 stride = (stride + 0xf) & ~0xf;
3444 if ( ((stride & 0xf) + v->type->size_unpacked) > 0x10)
3446 stride = (stride + 0xf) & ~0xf;
3449 stride += v->type->size_unpacked;
3452 l->type->stride = l->type->size_unpacked = (stride + 0xf) & ~0xf;
3454 TRACE("%s constant buffer:\n", prefix);
3455 TRACE("\tType name: %s.\n", debugstr_a(l->type->name));
3456 TRACE("\tElement count: %u.\n", l->type->element_count);
3457 TRACE("\tMember count: %u.\n", l->type->member_count);
3458 TRACE("\tUnpacked size: %#x.\n", l->type->size_unpacked);
3459 TRACE("\tStride: %#x.\n", l->type->stride);
3460 TRACE("\tPacked size %#x.\n", l->type->size_packed);
3461 TRACE("\tBasetype: %s.\n", debug_d3d10_shader_variable_type(l->type->basetype));
3462 TRACE("\tTypeclass: %s.\n", debug_d3d10_shader_variable_class(l->type->type_class));
3464 if (local && l->data_size)
3466 if (FAILED(hr = create_buffer_object(l)))
3468 WARN("Failed to create a buffer object, hr %#x.\n", hr);
3469 return hr;
3473 if (l->explicit_bind_point != ~0u)
3474 l->flag |= D3D10_EFFECT_VARIABLE_EXPLICIT_BIND_POINT;
3476 return S_OK;
3479 static void d3d10_effect_type_member_destroy(struct d3d10_effect_type_member *typem)
3481 TRACE("effect type member %p.\n", typem);
3483 /* Do not release typem->type, it will be covered by d3d10_effect_type_destroy(). */
3484 heap_free(typem->semantic);
3485 heap_free(typem->name);
3488 static void d3d10_effect_type_destroy(struct wine_rb_entry *entry, void *context)
3490 struct d3d10_effect_type *t = WINE_RB_ENTRY_VALUE(entry, struct d3d10_effect_type, entry);
3492 TRACE("effect type %p.\n", t);
3494 if (t->elementtype)
3496 heap_free(t->elementtype->name);
3497 heap_free(t->elementtype);
3500 if (t->members)
3502 unsigned int i;
3504 for (i = 0; i < t->member_count; ++i)
3506 d3d10_effect_type_member_destroy(&t->members[i]);
3508 heap_free(t->members);
3511 heap_free(t->name);
3512 heap_free(t);
3515 static BOOL d3d10_effect_types_match(const struct d3d10_effect_type *t1,
3516 const struct d3d10_effect_type *t2)
3518 unsigned int i;
3520 if (strcmp(t1->name, t2->name)) return FALSE;
3521 if (t1->basetype != t2->basetype) return FALSE;
3522 if (t1->type_class != t2->type_class) return FALSE;
3523 if (t1->element_count != t2->element_count) return FALSE;
3524 if (t1->element_count) return d3d10_effect_types_match(t1->elementtype, t2->elementtype);
3525 if (t1->member_count != t2->member_count) return FALSE;
3526 if (t1->column_count != t2->column_count) return FALSE;
3527 if (t1->row_count != t2->row_count) return FALSE;
3529 for (i = 0; i < t1->member_count; ++i)
3531 if (strcmp(t1->members[i].name, t2->members[i].name)) return FALSE;
3532 if (t1->members[i].buffer_offset != t2->members[i].buffer_offset) return FALSE;
3533 if (!d3d10_effect_types_match(t1->members[i].type, t2->members[i].type)) return FALSE;
3536 return TRUE;
3539 static HRESULT d3d10_effect_validate_shared_variable(const struct d3d10_effect *effect,
3540 const struct d3d10_effect_variable *v)
3542 struct d3d10_effect_variable *sv;
3544 switch (v->type->basetype)
3546 case D3D10_SVT_CBUFFER:
3547 case D3D10_SVT_TBUFFER:
3548 sv = d3d10_effect_get_buffer_by_name(effect->pool, v->name);
3549 break;
3550 default:
3551 sv = d3d10_effect_get_variable_by_name(effect->pool, v->name);
3554 if (!sv)
3556 WARN("Variable %s wasn't found in the pool.\n", debugstr_a(v->name));
3557 return E_INVALIDARG;
3560 if (!d3d10_effect_types_match(sv->type, v->type))
3562 WARN("Variable %s type does not match pool type.\n", debugstr_a(v->name));
3563 return E_INVALIDARG;
3566 return S_OK;
3569 static HRESULT parse_fx10_body(struct d3d10_effect *e, const char *data, DWORD data_size)
3571 const char *ptr;
3572 unsigned int i;
3573 HRESULT hr;
3575 if (e->index_offset >= data_size)
3577 WARN("Invalid index offset %#x (data size %#x).\n", e->index_offset, data_size);
3578 return E_FAIL;
3580 ptr = data + e->index_offset;
3582 if (!(e->local_buffers = heap_calloc(e->local_buffer_count, sizeof(*e->local_buffers))))
3584 ERR("Failed to allocate local buffer memory.\n");
3585 return E_OUTOFMEMORY;
3588 if (!(e->local_variables = heap_calloc(e->local_variable_count, sizeof(*e->local_variables))))
3590 ERR("Failed to allocate local variable memory.\n");
3591 return E_OUTOFMEMORY;
3594 if (!(e->anonymous_shaders = heap_calloc(e->anonymous_shader_count, sizeof(*e->anonymous_shaders))))
3596 ERR("Failed to allocate anonymous shaders memory\n");
3597 return E_OUTOFMEMORY;
3600 if (!(e->shaders.v = heap_calloc(e->shaders.count, sizeof(*e->shaders.v))))
3602 ERR("Failed to allocate used shaders memory\n");
3603 return E_OUTOFMEMORY;
3606 if (!(e->samplers.v = heap_calloc(e->samplers.count, sizeof(*e->samplers.v))))
3608 ERR("Failed to allocate samplers array.\n");
3609 return E_OUTOFMEMORY;
3612 if (!(e->blend_states.v = heap_calloc(e->blend_states.count, sizeof(*e->blend_states.v))))
3614 ERR("Failed to allocate blend states array.\n");
3615 return E_OUTOFMEMORY;
3618 if (!(e->ds_states.v = heap_calloc(e->ds_states.count, sizeof(*e->ds_states.v))))
3620 ERR("Failed to allocate depth stencil states array.\n");
3621 return E_OUTOFMEMORY;
3624 if (!(e->rs_states.v = heap_calloc(e->rs_states.count, sizeof(*e->rs_states.v))))
3626 ERR("Failed to allocate rasterizer states array.\n");
3627 return E_OUTOFMEMORY;
3630 if (!(e->techniques = heap_calloc(e->technique_count, sizeof(*e->techniques))))
3632 ERR("Failed to allocate techniques memory\n");
3633 return E_OUTOFMEMORY;
3636 for (i = 0; i < e->local_buffer_count; ++i)
3638 struct d3d10_effect_variable *l = &e->local_buffers[i];
3639 l->ID3D10EffectVariable_iface.lpVtbl = (const ID3D10EffectVariableVtbl *)&d3d10_effect_constant_buffer_vtbl;
3640 l->effect = e;
3641 l->buffer = &null_local_buffer;
3643 if (FAILED(hr = parse_fx10_buffer(data, data_size, &ptr, TRUE, l)))
3644 return hr;
3647 for (i = 0; i < e->local_variable_count; ++i)
3649 struct d3d10_effect_variable *v = &e->local_variables[i];
3651 v->effect = e;
3652 v->ID3D10EffectVariable_iface.lpVtbl = &d3d10_effect_variable_vtbl;
3653 v->buffer = &null_local_buffer;
3655 if (FAILED(hr = parse_fx10_object_variable(data, data_size, &ptr, FALSE, v)))
3656 return hr;
3659 for (i = 0; i < e->shared_buffer_count; ++i)
3661 struct d3d10_effect_variable b = {{ 0 }};
3663 b.effect = e;
3665 if (FAILED(hr = parse_fx10_buffer(data, data_size, &ptr, FALSE, &b)))
3667 d3d10_effect_variable_destroy(&b);
3668 return hr;
3671 hr = d3d10_effect_validate_shared_variable(e, &b);
3672 d3d10_effect_variable_destroy(&b);
3673 if (FAILED(hr)) return hr;
3676 for (i = 0; i < e->shared_object_count; ++i)
3678 struct d3d10_effect_variable o = {{ 0 }};
3680 o.effect = e;
3682 if (FAILED(hr = parse_fx10_object_variable(data, data_size, &ptr, TRUE, &o)))
3684 d3d10_effect_variable_destroy(&o);
3685 return hr;
3688 hr = d3d10_effect_validate_shared_variable(e, &o);
3689 d3d10_effect_variable_destroy(&o);
3690 if (FAILED(hr)) return hr;
3693 for (i = 0; i < e->technique_count; ++i)
3695 struct d3d10_effect_technique *t = &e->techniques[i];
3697 t->ID3D10EffectTechnique_iface.lpVtbl = &d3d10_effect_technique_vtbl;
3698 t->effect = e;
3700 if (FAILED(hr = parse_fx10_technique(data, data_size, &ptr, t)))
3701 return hr;
3704 return S_OK;
3707 static HRESULT parse_fx10(struct d3d10_effect *e, const char *data, DWORD data_size)
3709 const char *ptr = data;
3710 DWORD unused;
3712 if (!require_space(0, 19, sizeof(DWORD), data_size))
3714 WARN("Invalid data size %#x.\n", data_size);
3715 return E_INVALIDARG;
3718 /* Compiled target version (e.g. fx_4_0=0xfeff1001, fx_4_1=0xfeff1011). */
3719 e->version = read_dword(&ptr);
3720 TRACE("Target: %#x\n", e->version);
3722 e->local_buffer_count = read_dword(&ptr);
3723 TRACE("Local buffer count: %u.\n", e->local_buffer_count);
3725 e->variable_count = read_dword(&ptr);
3726 TRACE("Variable count: %u\n", e->variable_count);
3728 e->local_variable_count = read_dword(&ptr);
3729 TRACE("Object count: %u\n", e->local_variable_count);
3731 e->shared_buffer_count = read_dword(&ptr);
3732 TRACE("Pool buffer count: %u\n", e->shared_buffer_count);
3734 unused = read_dword(&ptr);
3735 TRACE("Pool variable count: %u\n", unused);
3737 e->shared_object_count = read_dword(&ptr);
3738 TRACE("Pool objects count: %u\n", e->shared_object_count);
3740 e->technique_count = read_dword(&ptr);
3741 TRACE("Technique count: %u\n", e->technique_count);
3743 e->index_offset = read_dword(&ptr);
3744 TRACE("Index offset: %#x\n", e->index_offset);
3746 unused = read_dword(&ptr);
3747 TRACE("String count: %u\n", unused);
3749 e->texture_count = read_dword(&ptr);
3750 TRACE("Texture count: %u\n", e->texture_count);
3752 e->ds_states.count = read_dword(&ptr);
3753 TRACE("Depthstencilstate count: %u\n", e->ds_states.count);
3755 e->blend_states.count = read_dword(&ptr);
3756 TRACE("Blendstate count: %u\n", e->blend_states.count);
3758 e->rs_states.count = read_dword(&ptr);
3759 TRACE("Rasterizerstate count: %u\n", e->rs_states.count);
3761 e->samplers.count = read_dword(&ptr);
3762 TRACE("Samplerstate count: %u\n", e->samplers.count);
3764 e->rtvs.count = read_dword(&ptr);
3765 TRACE("Rendertargetview count: %u\n", e->rtvs.count);
3767 e->dsvs.count = read_dword(&ptr);
3768 TRACE("Depthstencilview count: %u\n", e->dsvs.count);
3770 e->shaders.count = read_dword(&ptr);
3771 TRACE("Used shader count: %u\n", e->shaders.count);
3773 e->anonymous_shader_count = read_dword(&ptr);
3774 TRACE("Anonymous shader count: %u\n", e->anonymous_shader_count);
3776 if (!e->pool && (e->shared_object_count || e->shared_buffer_count))
3778 WARN("Effect requires a pool to load.\n");
3779 return E_FAIL;
3782 return parse_fx10_body(e, ptr, data_size - (ptr - data));
3785 static HRESULT fx10_chunk_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
3787 struct d3d10_effect *e = ctx;
3789 TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));
3791 TRACE("chunk size: %#x\n", data_size);
3793 switch(tag)
3795 case TAG_FX10:
3796 return parse_fx10(e, data, data_size);
3798 default:
3799 FIXME("Unhandled chunk %s.\n", debugstr_an((const char *)&tag, 4));
3800 return S_OK;
3804 HRESULT d3d10_effect_parse(struct d3d10_effect *This, const void *data, SIZE_T data_size)
3806 return parse_dxbc(data, data_size, fx10_chunk_handler, This);
3809 static void d3d10_effect_shader_variable_destroy(struct d3d10_effect_shader_variable *s,
3810 D3D10_SHADER_VARIABLE_TYPE type)
3812 if (s->reflection)
3813 s->reflection->lpVtbl->Release(s->reflection);
3814 if (s->input_signature)
3815 ID3D10Blob_Release(s->input_signature);
3816 if (s->bytecode)
3817 ID3D10Blob_Release(s->bytecode);
3819 switch (type)
3821 case D3D10_SVT_VERTEXSHADER:
3822 case D3D10_SVT_PIXELSHADER:
3823 case D3D10_SVT_GEOMETRYSHADER:
3824 if (s->shader.object)
3825 IUnknown_Release(s->shader.object);
3826 break;
3828 default:
3829 FIXME("Unhandled shader type %s.\n", debug_d3d10_shader_variable_type(type));
3830 break;
3833 if (s->resource_count)
3834 heap_free(s->resources);
3837 static void d3d10_effect_annotations_destroy(struct d3d10_effect_annotations *a)
3839 unsigned int i;
3841 if (!a->elements) return;
3843 for (i = 0; i < a->count; ++i)
3844 d3d10_effect_variable_destroy(&a->elements[i]);
3845 heap_free(a->elements);
3846 a->elements = NULL;
3847 a->count = 0;
3850 static void d3d10_effect_variable_destroy(struct d3d10_effect_variable *v)
3852 unsigned int i, elem_count;
3854 TRACE("variable %p.\n", v);
3856 heap_free(v->name);
3857 heap_free(v->semantic);
3858 d3d10_effect_annotations_destroy(&v->annotations);
3860 if (v->members)
3862 for (i = 0; i < v->type->member_count; ++i)
3864 d3d10_effect_variable_destroy(&v->members[i]);
3866 heap_free(v->members);
3869 if (v->elements)
3871 for (i = 0; i < v->type->element_count; ++i)
3873 d3d10_effect_variable_destroy(&v->elements[i]);
3875 heap_free(v->elements);
3878 if (v->type)
3880 switch (v->type->basetype)
3882 case D3D10_SVT_VERTEXSHADER:
3883 case D3D10_SVT_PIXELSHADER:
3884 case D3D10_SVT_GEOMETRYSHADER:
3885 d3d10_effect_shader_variable_destroy(&v->u.shader, v->type->basetype);
3886 break;
3888 case D3D10_SVT_DEPTHSTENCIL:
3889 case D3D10_SVT_BLEND:
3890 case D3D10_SVT_RASTERIZER:
3891 case D3D10_SVT_SAMPLER:
3892 if (v->u.state.object.object)
3893 IUnknown_Release(v->u.state.object.object);
3894 d3d10_effect_clear_prop_dependencies(&v->u.state.dependencies);
3895 break;
3897 case D3D10_SVT_TEXTURE1D:
3898 case D3D10_SVT_TEXTURE1DARRAY:
3899 case D3D10_SVT_TEXTURE2D:
3900 case D3D10_SVT_TEXTURE2DARRAY:
3901 case D3D10_SVT_TEXTURE2DMS:
3902 case D3D10_SVT_TEXTURE2DMSARRAY:
3903 case D3D10_SVT_TEXTURE3D:
3904 case D3D10_SVT_TEXTURECUBE:
3905 if (!v->u.resource.parent)
3906 break;
3908 if (!v->type->element_count)
3909 elem_count = 1;
3910 else
3911 elem_count = v->type->element_count;
3913 for (i = 0; i < elem_count; ++i)
3915 if (v->u.resource.srv[i])
3916 ID3D10ShaderResourceView_Release(v->u.resource.srv[i]);
3919 heap_free(v->u.resource.srv);
3920 break;
3922 case D3D10_SVT_STRING:
3923 heap_free(v->u.buffer.local_buffer);
3924 break;
3926 default:
3927 break;
3932 static void d3d10_effect_pass_destroy(struct d3d10_effect_pass *p)
3934 TRACE("pass %p\n", p);
3936 heap_free(p->name);
3937 d3d10_effect_annotations_destroy(&p->annotations);
3938 d3d10_effect_clear_prop_dependencies(&p->dependencies);
3941 static void d3d10_effect_technique_destroy(struct d3d10_effect_technique *t)
3943 unsigned int i;
3945 TRACE("technique %p\n", t);
3947 heap_free(t->name);
3948 if (t->passes)
3950 for (i = 0; i < t->pass_count; ++i)
3952 d3d10_effect_pass_destroy(&t->passes[i]);
3954 heap_free(t->passes);
3957 d3d10_effect_annotations_destroy(&t->annotations);
3960 static void d3d10_effect_local_buffer_destroy(struct d3d10_effect_variable *l)
3962 unsigned int i;
3964 TRACE("local buffer %p.\n", l);
3966 heap_free(l->name);
3967 if (l->members)
3969 for (i = 0; i < l->type->member_count; ++i)
3971 d3d10_effect_variable_destroy(&l->members[i]);
3973 heap_free(l->members);
3976 if (l->type)
3977 d3d10_effect_type_destroy(&l->type->entry, NULL);
3979 d3d10_effect_annotations_destroy(&l->annotations);
3980 heap_free(l->u.buffer.local_buffer);
3982 if (l->u.buffer.buffer)
3983 ID3D10Buffer_Release(l->u.buffer.buffer);
3984 if (l->u.buffer.resource_view)
3985 ID3D10ShaderResourceView_Release(l->u.buffer.resource_view);
3988 /* IUnknown methods */
3990 static inline struct d3d10_effect *impl_from_ID3D10Effect(ID3D10Effect *iface)
3992 return CONTAINING_RECORD(iface, struct d3d10_effect, ID3D10Effect_iface);
3995 static HRESULT STDMETHODCALLTYPE d3d10_effect_QueryInterface(ID3D10Effect *iface, REFIID riid, void **object)
3997 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
3999 if (IsEqualGUID(riid, &IID_ID3D10Effect)
4000 || IsEqualGUID(riid, &IID_IUnknown))
4002 IUnknown_AddRef(iface);
4003 *object = iface;
4004 return S_OK;
4007 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
4009 *object = NULL;
4010 return E_NOINTERFACE;
4013 static ULONG STDMETHODCALLTYPE d3d10_effect_AddRef(ID3D10Effect *iface)
4015 struct d3d10_effect *This = impl_from_ID3D10Effect(iface);
4016 ULONG refcount = InterlockedIncrement(&This->refcount);
4018 TRACE("%p increasing refcount to %u\n", This, refcount);
4020 return refcount;
4023 static ULONG STDMETHODCALLTYPE d3d10_effect_Release(ID3D10Effect *iface)
4025 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4026 ULONG refcount = InterlockedDecrement(&effect->refcount);
4028 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
4030 if (!refcount)
4032 unsigned int i;
4034 if (effect->techniques)
4036 for (i = 0; i < effect->technique_count; ++i)
4038 d3d10_effect_technique_destroy(&effect->techniques[i]);
4040 heap_free(effect->techniques);
4043 if (effect->local_variables)
4045 for (i = 0; i < effect->local_variable_count; ++i)
4047 d3d10_effect_variable_destroy(&effect->local_variables[i]);
4049 heap_free(effect->local_variables);
4052 if (effect->local_buffers)
4054 for (i = 0; i < effect->local_buffer_count; ++i)
4056 d3d10_effect_local_buffer_destroy(&effect->local_buffers[i]);
4058 heap_free(effect->local_buffers);
4061 if (effect->anonymous_shaders)
4063 for (i = 0; i < effect->anonymous_shader_count; ++i)
4065 d3d10_effect_variable_destroy(&effect->anonymous_shaders[i].shader);
4066 heap_free(effect->anonymous_shaders[i].type.name);
4068 heap_free(effect->anonymous_shaders);
4071 heap_free(effect->shaders.v);
4072 heap_free(effect->samplers.v);
4073 heap_free(effect->rtvs.v);
4074 heap_free(effect->dsvs.v);
4075 heap_free(effect->blend_states.v);
4076 heap_free(effect->ds_states.v);
4077 heap_free(effect->rs_states.v);
4079 wine_rb_destroy(&effect->types, d3d10_effect_type_destroy, NULL);
4081 if (effect->pool)
4082 IUnknown_Release(&effect->pool->ID3D10Effect_iface);
4083 ID3D10Device_Release(effect->device);
4084 heap_free(effect);
4087 return refcount;
4090 /* ID3D10Effect methods */
4092 static BOOL STDMETHODCALLTYPE d3d10_effect_IsValid(ID3D10Effect *iface)
4094 FIXME("iface %p stub!\n", iface);
4096 return FALSE;
4099 static BOOL STDMETHODCALLTYPE d3d10_effect_IsPool(ID3D10Effect *iface)
4101 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4103 TRACE("iface %p.\n", iface);
4105 return effect->ID3D10Effect_iface.lpVtbl == &d3d10_effect_pool_effect_vtbl;
4108 static HRESULT STDMETHODCALLTYPE d3d10_effect_GetDevice(ID3D10Effect *iface, ID3D10Device **device)
4110 struct d3d10_effect *This = impl_from_ID3D10Effect(iface);
4112 TRACE("iface %p, device %p\n", iface, device);
4114 ID3D10Device_AddRef(This->device);
4115 *device = This->device;
4117 return S_OK;
4120 static void d3d10_effect_get_desc(const struct d3d10_effect *effect, D3D10_EFFECT_DESC *desc)
4122 unsigned int i;
4124 desc->IsChildEffect = !!effect->pool;
4125 desc->ConstantBuffers = effect->local_buffer_count;
4126 desc->SharedConstantBuffers = 0;
4127 desc->GlobalVariables = effect->local_variable_count;
4128 for (i = 0; i < effect->local_buffer_count; ++i)
4130 desc->GlobalVariables += effect->local_buffers[i].type->member_count;
4132 desc->SharedGlobalVariables = 0;
4133 desc->Techniques = effect->technique_count;
4136 static HRESULT STDMETHODCALLTYPE d3d10_effect_GetDesc(ID3D10Effect *iface, D3D10_EFFECT_DESC *desc)
4138 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4139 D3D10_EFFECT_DESC pool_desc = { 0 };
4141 TRACE("iface %p, desc %p.\n", iface, desc);
4143 if (!desc)
4144 return E_INVALIDARG;
4146 if (effect->pool)
4147 d3d10_effect_get_desc(effect->pool, &pool_desc);
4149 d3d10_effect_get_desc(effect, desc);
4151 desc->SharedConstantBuffers = pool_desc.ConstantBuffers;
4152 desc->SharedGlobalVariables = pool_desc.GlobalVariables;
4154 return S_OK;
4157 static struct d3d10_effect_variable * d3d10_effect_get_buffer_by_index(struct d3d10_effect *effect,
4158 unsigned int index)
4160 if (index < effect->local_buffer_count)
4161 return &effect->local_buffers[index];
4162 index -= effect->local_buffer_count;
4164 return effect->pool ? d3d10_effect_get_buffer_by_index(effect->pool, index) : NULL;
4167 static BOOL is_var_shared(const struct d3d10_effect_variable *v)
4169 return !!(v->flag & D3D10_EFFECT_VARIABLE_POOLED);
4172 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_GetConstantBufferByIndex(ID3D10Effect *iface,
4173 UINT index)
4175 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4176 struct d3d10_effect_variable *v;
4178 TRACE("iface %p, index %u\n", iface, index);
4180 if ((v = d3d10_effect_get_buffer_by_index(effect, index)))
4182 TRACE("Returning %sbuffer %p, name %s.\n", is_var_shared(v) ? "shared " : "", v,
4183 debugstr_a(v->name));
4184 return (ID3D10EffectConstantBuffer *)&v->ID3D10EffectVariable_iface;
4187 WARN("Invalid index specified\n");
4189 return (ID3D10EffectConstantBuffer *)&null_local_buffer.ID3D10EffectVariable_iface;
4192 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_GetConstantBufferByName(ID3D10Effect *iface,
4193 const char *name)
4195 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4196 struct d3d10_effect_variable *v;
4198 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4200 if ((v = d3d10_effect_get_buffer_by_name(effect, name)))
4202 TRACE("Returning %sbuffer %p.\n", is_var_shared(v) ? "shared " : "", v);
4203 return (ID3D10EffectConstantBuffer *)&v->ID3D10EffectVariable_iface;
4206 WARN("Invalid name specified\n");
4208 return (ID3D10EffectConstantBuffer *)&null_local_buffer.ID3D10EffectVariable_iface;
4211 static struct d3d10_effect_variable * d3d10_effect_get_variable_by_index(
4212 const struct d3d10_effect *effect, unsigned int index)
4214 unsigned int i;
4216 for (i = 0; i < effect->local_buffer_count; ++i)
4218 struct d3d10_effect_variable *v = &effect->local_buffers[i];
4219 if (index < v->type->member_count)
4220 return &v->members[index];
4221 index -= v->type->member_count;
4224 if (index < effect->local_variable_count)
4225 return &effect->local_variables[index];
4226 index -= effect->local_variable_count;
4228 return effect->pool ? d3d10_effect_get_variable_by_index(effect->pool, index) : NULL;
4231 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_GetVariableByIndex(ID3D10Effect *iface, UINT index)
4233 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4234 struct d3d10_effect_variable *v;
4236 TRACE("iface %p, index %u\n", iface, index);
4238 if ((v = d3d10_effect_get_variable_by_index(effect, index)))
4240 TRACE("Returning %svariable %s.\n", is_var_shared(v) ? "shared " : "", debugstr_a(v->name));
4241 return &v->ID3D10EffectVariable_iface;
4244 WARN("Invalid index specified\n");
4246 return &null_variable.ID3D10EffectVariable_iface;
4249 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_GetVariableByName(ID3D10Effect *iface,
4250 const char *name)
4252 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4253 struct d3d10_effect_variable *v;
4255 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4257 if (!name)
4259 WARN("Invalid name specified\n");
4260 return &null_variable.ID3D10EffectVariable_iface;
4263 if ((v = d3d10_effect_get_variable_by_name(effect, name)))
4265 TRACE("Returning %svariable %p.\n", is_var_shared(v) ? "shared " : "", v);
4266 return &v->ID3D10EffectVariable_iface;
4269 WARN("Invalid name specified\n");
4271 return &null_variable.ID3D10EffectVariable_iface;
4274 static struct d3d10_effect_variable * d3d10_effect_get_variable_by_semantic(
4275 const struct d3d10_effect *effect, const char *semantic)
4277 unsigned int i;
4279 for (i = 0; i < effect->local_buffer_count; ++i)
4281 struct d3d10_effect_variable *l = &effect->local_buffers[i];
4282 unsigned int j;
4284 for (j = 0; j < l->type->member_count; ++j)
4286 struct d3d10_effect_variable *v = &l->members[j];
4288 if (v->semantic && !stricmp(v->semantic, semantic))
4289 return v;
4293 for (i = 0; i < effect->local_variable_count; ++i)
4295 struct d3d10_effect_variable *v = &effect->local_variables[i];
4297 if (v->semantic && !stricmp(v->semantic, semantic))
4298 return v;
4301 return effect->pool ? d3d10_effect_get_variable_by_semantic(effect->pool, semantic) : NULL;
4304 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_GetVariableBySemantic(ID3D10Effect *iface,
4305 const char *semantic)
4307 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4308 struct d3d10_effect_variable *v;
4310 TRACE("iface %p, semantic %s\n", iface, debugstr_a(semantic));
4312 if (!semantic)
4314 WARN("Invalid semantic specified\n");
4315 return &null_variable.ID3D10EffectVariable_iface;
4318 if ((v = d3d10_effect_get_variable_by_semantic(effect, semantic)))
4320 TRACE("Returning %svariable %s.\n", is_var_shared(v) ? "shared " : "", debugstr_a(v->name));
4321 return &v->ID3D10EffectVariable_iface;
4324 WARN("Invalid semantic specified\n");
4326 return &null_variable.ID3D10EffectVariable_iface;
4329 static struct ID3D10EffectTechnique * STDMETHODCALLTYPE d3d10_effect_GetTechniqueByIndex(ID3D10Effect *iface,
4330 UINT index)
4332 struct d3d10_effect *This = impl_from_ID3D10Effect(iface);
4333 struct d3d10_effect_technique *t;
4335 TRACE("iface %p, index %u\n", iface, index);
4337 if (index >= This->technique_count)
4339 WARN("Invalid index specified\n");
4340 return &null_technique.ID3D10EffectTechnique_iface;
4343 t = &This->techniques[index];
4345 TRACE("Returning technique %p, %s.\n", t, debugstr_a(t->name));
4347 return &t->ID3D10EffectTechnique_iface;
4350 static struct ID3D10EffectTechnique * STDMETHODCALLTYPE d3d10_effect_GetTechniqueByName(ID3D10Effect *iface,
4351 const char *name)
4353 struct d3d10_effect *This = impl_from_ID3D10Effect(iface);
4354 unsigned int i;
4356 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4358 if (!name)
4360 WARN("Invalid name specified\n");
4361 return &null_technique.ID3D10EffectTechnique_iface;
4364 for (i = 0; i < This->technique_count; ++i)
4366 struct d3d10_effect_technique *t = &This->techniques[i];
4367 if (t->name && !strcmp(t->name, name))
4369 TRACE("Returning technique %p\n", t);
4370 return &t->ID3D10EffectTechnique_iface;
4374 WARN("Invalid name specified\n");
4376 return &null_technique.ID3D10EffectTechnique_iface;
4379 static HRESULT STDMETHODCALLTYPE d3d10_effect_Optimize(ID3D10Effect *iface)
4381 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4382 struct d3d10_effect_variable *v;
4383 unsigned int i, j;
4385 FIXME("iface %p semi-stub!\n", iface);
4387 if (effect->flags & D3D10_EFFECT_OPTIMIZED)
4388 return S_OK;
4390 for (i = 0; i < effect->shaders.count; ++i)
4392 v = effect->shaders.v[i];
4394 if (v->u.shader.reflection)
4396 v->u.shader.reflection->lpVtbl->Release(v->u.shader.reflection);
4397 v->u.shader.reflection = NULL;
4399 if (v->u.shader.bytecode)
4401 ID3D10Blob_Release(v->u.shader.bytecode);
4402 v->u.shader.bytecode = NULL;
4404 heap_free(v->u.shader.stream_output_declaration);
4405 v->u.shader.stream_output_declaration = NULL;
4408 for (i = 0; i < effect->technique_count; ++i)
4410 for (j = 0; j < effect->techniques[i].pass_count; ++j)
4412 heap_free(effect->techniques[i].passes[j].name);
4413 effect->techniques[i].passes[j].name = NULL;
4416 heap_free(effect->techniques[i].name);
4417 effect->techniques[i].name = NULL;
4420 effect->flags |= D3D10_EFFECT_OPTIMIZED;
4422 return S_OK;
4425 static BOOL STDMETHODCALLTYPE d3d10_effect_IsOptimized(ID3D10Effect *iface)
4427 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
4429 TRACE("iface %p.\n", iface);
4431 return !!(effect->flags & D3D10_EFFECT_OPTIMIZED);
4434 static const struct ID3D10EffectVtbl d3d10_effect_vtbl =
4436 /* IUnknown methods */
4437 d3d10_effect_QueryInterface,
4438 d3d10_effect_AddRef,
4439 d3d10_effect_Release,
4440 /* ID3D10Effect methods */
4441 d3d10_effect_IsValid,
4442 d3d10_effect_IsPool,
4443 d3d10_effect_GetDevice,
4444 d3d10_effect_GetDesc,
4445 d3d10_effect_GetConstantBufferByIndex,
4446 d3d10_effect_GetConstantBufferByName,
4447 d3d10_effect_GetVariableByIndex,
4448 d3d10_effect_GetVariableByName,
4449 d3d10_effect_GetVariableBySemantic,
4450 d3d10_effect_GetTechniqueByIndex,
4451 d3d10_effect_GetTechniqueByName,
4452 d3d10_effect_Optimize,
4453 d3d10_effect_IsOptimized,
4456 /* ID3D10EffectTechnique methods */
4458 static inline struct d3d10_effect_technique *impl_from_ID3D10EffectTechnique(ID3D10EffectTechnique *iface)
4460 return CONTAINING_RECORD(iface, struct d3d10_effect_technique, ID3D10EffectTechnique_iface);
4463 static BOOL STDMETHODCALLTYPE d3d10_effect_technique_IsValid(ID3D10EffectTechnique *iface)
4465 struct d3d10_effect_technique *This = impl_from_ID3D10EffectTechnique(iface);
4467 TRACE("iface %p\n", iface);
4469 return This != &null_technique;
4472 static HRESULT STDMETHODCALLTYPE d3d10_effect_technique_GetDesc(ID3D10EffectTechnique *iface,
4473 D3D10_TECHNIQUE_DESC *desc)
4475 struct d3d10_effect_technique *tech = impl_from_ID3D10EffectTechnique(iface);
4477 TRACE("iface %p, desc %p\n", iface, desc);
4479 if (tech == &null_technique)
4481 WARN("Null technique specified\n");
4482 return E_FAIL;
4485 if (!desc)
4487 WARN("Invalid argument specified\n");
4488 return E_INVALIDARG;
4491 desc->Name = tech->name;
4492 desc->Passes = tech->pass_count;
4493 desc->Annotations = tech->annotations.count;
4495 return S_OK;
4498 static ID3D10EffectVariable * d3d10_annotation_get_by_index(const struct d3d10_effect_annotations *annotations,
4499 unsigned int index)
4501 struct d3d10_effect_variable *a;
4503 if (index >= annotations->count)
4505 WARN("Invalid index specified\n");
4506 return &null_variable.ID3D10EffectVariable_iface;
4509 a = &annotations->elements[index];
4511 TRACE("Returning annotation %p, name %s.\n", a, debugstr_a(a->name));
4513 return &a->ID3D10EffectVariable_iface;
4516 static ID3D10EffectVariable * d3d10_annotation_get_by_name(const struct d3d10_effect_annotations *annotations,
4517 const char *name)
4519 unsigned int i;
4521 for (i = 0; i < annotations->count; ++i)
4523 struct d3d10_effect_variable *a = &annotations->elements[i];
4524 if (a->name && !strcmp(a->name, name))
4526 TRACE("Returning annotation %p.\n", a);
4527 return &a->ID3D10EffectVariable_iface;
4531 WARN("Invalid name specified.\n");
4533 return &null_variable.ID3D10EffectVariable_iface;
4536 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_technique_GetAnnotationByIndex(
4537 ID3D10EffectTechnique *iface, UINT index)
4539 struct d3d10_effect_technique *tech = impl_from_ID3D10EffectTechnique(iface);
4541 TRACE("iface %p, index %u\n", iface, index);
4543 return d3d10_annotation_get_by_index(&tech->annotations, index);
4546 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_technique_GetAnnotationByName(
4547 ID3D10EffectTechnique *iface, const char *name)
4549 struct d3d10_effect_technique *tech = impl_from_ID3D10EffectTechnique(iface);
4551 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4553 return d3d10_annotation_get_by_name(&tech->annotations, name);
4556 static struct ID3D10EffectPass * STDMETHODCALLTYPE d3d10_effect_technique_GetPassByIndex(ID3D10EffectTechnique *iface,
4557 UINT index)
4559 struct d3d10_effect_technique *This = impl_from_ID3D10EffectTechnique(iface);
4560 struct d3d10_effect_pass *p;
4562 TRACE("iface %p, index %u\n", iface, index);
4564 if (index >= This->pass_count)
4566 WARN("Invalid index specified\n");
4567 return &null_pass.ID3D10EffectPass_iface;
4570 p = &This->passes[index];
4572 TRACE("Returning pass %p, %s.\n", p, debugstr_a(p->name));
4574 return &p->ID3D10EffectPass_iface;
4577 static struct ID3D10EffectPass * STDMETHODCALLTYPE d3d10_effect_technique_GetPassByName(ID3D10EffectTechnique *iface,
4578 const char *name)
4580 struct d3d10_effect_technique *This = impl_from_ID3D10EffectTechnique(iface);
4581 unsigned int i;
4583 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4585 /* Do not check for name==NULL, W7/DX10 crashes in that case. */
4587 for (i = 0; i < This->pass_count; ++i)
4589 struct d3d10_effect_pass *p = &This->passes[i];
4590 if (p->name && !strcmp(p->name, name))
4592 TRACE("Returning pass %p\n", p);
4593 return &p->ID3D10EffectPass_iface;
4597 WARN("Invalid name specified\n");
4599 return &null_pass.ID3D10EffectPass_iface;
4602 static HRESULT STDMETHODCALLTYPE d3d10_effect_technique_ComputeStateBlockMask(ID3D10EffectTechnique *iface,
4603 D3D10_STATE_BLOCK_MASK *mask)
4605 FIXME("iface %p,mask %p stub!\n", iface, mask);
4607 return E_NOTIMPL;
4610 static const struct ID3D10EffectTechniqueVtbl d3d10_effect_technique_vtbl =
4612 /* ID3D10EffectTechnique methods */
4613 d3d10_effect_technique_IsValid,
4614 d3d10_effect_technique_GetDesc,
4615 d3d10_effect_technique_GetAnnotationByIndex,
4616 d3d10_effect_technique_GetAnnotationByName,
4617 d3d10_effect_technique_GetPassByIndex,
4618 d3d10_effect_technique_GetPassByName,
4619 d3d10_effect_technique_ComputeStateBlockMask,
4622 /* ID3D10EffectPass methods */
4624 static inline struct d3d10_effect_pass *impl_from_ID3D10EffectPass(ID3D10EffectPass *iface)
4626 return CONTAINING_RECORD(iface, struct d3d10_effect_pass, ID3D10EffectPass_iface);
4629 static BOOL STDMETHODCALLTYPE d3d10_effect_pass_IsValid(ID3D10EffectPass *iface)
4631 struct d3d10_effect_pass *This = impl_from_ID3D10EffectPass(iface);
4633 TRACE("iface %p\n", iface);
4635 return This != &null_pass;
4638 static HRESULT STDMETHODCALLTYPE d3d10_effect_pass_GetDesc(ID3D10EffectPass *iface,
4639 D3D10_PASS_DESC *desc)
4641 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4642 struct d3d10_effect_variable *vs;
4643 ID3D10Blob *input_signature;
4645 TRACE("iface %p, desc %p.\n", iface, desc);
4647 if (pass == &null_pass)
4649 WARN("Null pass specified\n");
4650 return E_FAIL;
4653 if (!desc)
4655 WARN("Invalid argument specified\n");
4656 return E_INVALIDARG;
4659 d3d10_effect_update_dependent_props(&pass->dependencies, pass);
4661 vs = d3d10_array_get_element(pass->vs.shader, pass->vs.index);
4662 input_signature = vs->u.shader.input_signature;
4664 desc->Name = pass->name;
4665 desc->Annotations = pass->annotations.count;
4666 if (input_signature)
4668 desc->pIAInputSignature = ID3D10Blob_GetBufferPointer(input_signature);
4669 desc->IAInputSignatureSize = ID3D10Blob_GetBufferSize(input_signature);
4671 else
4673 desc->pIAInputSignature = NULL;
4674 desc->IAInputSignatureSize = 0;
4676 desc->StencilRef = pass->stencil_ref;
4677 desc->SampleMask = pass->sample_mask;
4678 memcpy(desc->BlendFactor, pass->blend_factor, 4 * sizeof(float));
4680 return S_OK;
4683 static HRESULT STDMETHODCALLTYPE d3d10_effect_pass_GetVertexShaderDesc(ID3D10EffectPass *iface,
4684 D3D10_PASS_SHADER_DESC *desc)
4686 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4688 TRACE("iface %p, desc %p.\n", iface, desc);
4690 if (pass == &null_pass)
4692 WARN("Null pass specified.\n");
4693 return E_FAIL;
4696 if (!desc)
4698 WARN("Invalid argument specified.\n");
4699 return E_INVALIDARG;
4702 d3d10_effect_update_dependent_props(&pass->dependencies, pass);
4704 desc->pShaderVariable = (ID3D10EffectShaderVariable *)&pass->vs.shader->ID3D10EffectVariable_iface;
4705 desc->ShaderIndex = pass->vs.index;
4707 return S_OK;
4710 static HRESULT STDMETHODCALLTYPE d3d10_effect_pass_GetGeometryShaderDesc(ID3D10EffectPass *iface,
4711 D3D10_PASS_SHADER_DESC *desc)
4713 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4715 TRACE("iface %p, desc %p.\n", iface, desc);
4717 if (pass == &null_pass)
4719 WARN("Null pass specified.\n");
4720 return E_FAIL;
4723 if (!desc)
4725 WARN("Invalid argument specified.\n");
4726 return E_INVALIDARG;
4729 d3d10_effect_update_dependent_props(&pass->dependencies, pass);
4731 desc->pShaderVariable = (ID3D10EffectShaderVariable *)&pass->gs.shader->ID3D10EffectVariable_iface;
4732 desc->ShaderIndex = pass->gs.index;
4734 return S_OK;
4737 static HRESULT STDMETHODCALLTYPE d3d10_effect_pass_GetPixelShaderDesc(ID3D10EffectPass *iface,
4738 D3D10_PASS_SHADER_DESC *desc)
4740 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4742 TRACE("iface %p, desc %p.\n", iface, desc);
4744 if (pass == &null_pass)
4746 WARN("Null pass specified.\n");
4747 return E_FAIL;
4750 if (!desc)
4752 WARN("Invalid argument specified.\n");
4753 return E_INVALIDARG;
4756 d3d10_effect_update_dependent_props(&pass->dependencies, pass);
4758 desc->pShaderVariable = (ID3D10EffectShaderVariable *)&pass->ps.shader->ID3D10EffectVariable_iface;
4759 desc->ShaderIndex = pass->ps.index;
4761 return S_OK;
4764 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_pass_GetAnnotationByIndex(ID3D10EffectPass *iface,
4765 UINT index)
4767 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4769 TRACE("iface %p, index %u\n", iface, index);
4771 return d3d10_annotation_get_by_index(&pass->annotations, index);
4774 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_pass_GetAnnotationByName(ID3D10EffectPass *iface,
4775 const char *name)
4777 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4779 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
4781 return d3d10_annotation_get_by_name(&pass->annotations, name);
4784 static void update_buffer(ID3D10Device *device, struct d3d10_effect_variable *v)
4786 struct d3d10_effect_buffer_variable *b = &v->u.buffer;
4788 if (!b->changed)
4789 return;
4791 ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)b->buffer, 0, NULL,
4792 b->local_buffer, v->data_size, 0);
4794 b->changed = FALSE;
4797 static void set_sampler(ID3D10Device *device, D3D10_SHADER_VARIABLE_TYPE shader_type,
4798 struct d3d10_effect_variable *v, unsigned int bind_point)
4800 switch (shader_type)
4802 case D3D10_SVT_VERTEXSHADER:
4803 ID3D10Device_VSSetSamplers(device, bind_point, 1, &v->u.state.object.sampler);
4804 break;
4806 case D3D10_SVT_PIXELSHADER:
4807 ID3D10Device_PSSetSamplers(device, bind_point, 1, &v->u.state.object.sampler);
4808 break;
4810 case D3D10_SVT_GEOMETRYSHADER:
4811 ID3D10Device_GSSetSamplers(device, bind_point, 1, &v->u.state.object.sampler);
4812 break;
4814 default:
4815 WARN("Incorrect shader type to bind sampler.\n");
4816 break;
4820 static void apply_shader_resources(ID3D10Device *device, struct d3d10_effect_variable *v)
4822 struct d3d10_effect_shader_variable *sv = &v->u.shader;
4823 struct d3d10_effect_shader_resource *sr;
4824 struct d3d10_effect_variable *rsrc_v;
4825 ID3D10ShaderResourceView **srv;
4826 unsigned int i, j;
4828 for (i = 0; i < sv->resource_count; ++i)
4830 sr = &sv->resources[i];
4831 rsrc_v = sr->variable;
4833 switch (sr->in_type)
4835 case D3D10_SIT_CBUFFER:
4836 update_buffer(device, rsrc_v);
4837 switch (v->type->basetype)
4839 case D3D10_SVT_VERTEXSHADER:
4840 ID3D10Device_VSSetConstantBuffers(device, sr->bind_point, 1,
4841 &rsrc_v->u.buffer.buffer);
4842 break;
4844 case D3D10_SVT_PIXELSHADER:
4845 ID3D10Device_PSSetConstantBuffers(device, sr->bind_point, 1,
4846 &rsrc_v->u.buffer.buffer);
4847 break;
4849 case D3D10_SVT_GEOMETRYSHADER:
4850 ID3D10Device_GSSetConstantBuffers(device, sr->bind_point, 1,
4851 &rsrc_v->u.buffer.buffer);
4852 break;
4854 default:
4855 WARN("Incorrect shader type to bind constant buffer.\n");
4856 break;
4858 break;
4860 case D3D10_SIT_TEXTURE:
4862 if (rsrc_v->type->basetype == D3D10_SVT_SAMPLER)
4864 TRACE("Using texture associated with sampler %s.\n", debugstr_a(rsrc_v->name));
4865 rsrc_v = rsrc_v->u.state.desc.sampler.texture;
4868 /* fallthrough */
4869 case D3D10_SIT_TBUFFER:
4871 if (sr->in_type == D3D10_SIT_TBUFFER)
4873 update_buffer(device, rsrc_v);
4874 srv = &rsrc_v->u.buffer.resource_view;
4876 else
4877 srv = rsrc_v->u.resource.srv;
4879 switch (v->type->basetype)
4881 case D3D10_SVT_VERTEXSHADER:
4882 ID3D10Device_VSSetShaderResources(device, sr->bind_point, sr->bind_count, srv);
4883 break;
4885 case D3D10_SVT_PIXELSHADER:
4886 ID3D10Device_PSSetShaderResources(device, sr->bind_point, sr->bind_count, srv);
4887 break;
4889 case D3D10_SVT_GEOMETRYSHADER:
4890 ID3D10Device_GSSetShaderResources(device, sr->bind_point, sr->bind_count, srv);
4891 break;
4893 default:
4894 WARN("Incorrect shader type to bind shader resource view.\n");
4895 break;
4897 break;
4899 case D3D10_SIT_SAMPLER:
4900 if (!rsrc_v->type->element_count)
4902 set_sampler(device, v->type->basetype, rsrc_v, sr->bind_point);
4903 break;
4906 for (j = 0; j < sr->bind_count; ++j)
4907 set_sampler(device, v->type->basetype, &rsrc_v->elements[j], sr->bind_point + j);
4908 break;
4910 default:
4911 WARN("Unhandled shader resource %#x.\n", sr->in_type);
4912 break;
4917 static void d3d10_effect_pass_set_shader(struct d3d10_effect_pass *pass,
4918 const struct d3d10_effect_pass_shader_desc *shader_desc)
4920 ID3D10Device *device = pass->technique->effect->device;
4921 struct d3d10_effect_variable *v;
4923 v = d3d10_array_get_element(shader_desc->shader, shader_desc->index);
4925 switch (v->type->basetype)
4927 case D3D10_SVT_VERTEXSHADER:
4928 ID3D10Device_VSSetShader(device, v->u.shader.shader.vs);
4929 break;
4930 case D3D10_SVT_PIXELSHADER:
4931 ID3D10Device_PSSetShader(device, v->u.shader.shader.ps);
4932 break;
4933 case D3D10_SVT_GEOMETRYSHADER:
4934 ID3D10Device_GSSetShader(device, v->u.shader.shader.gs);
4935 break;
4936 default:
4937 WARN("Unexpected shader type %u.\n", v->type->basetype);
4940 apply_shader_resources(device, v);
4943 static HRESULT STDMETHODCALLTYPE d3d10_effect_pass_Apply(ID3D10EffectPass *iface, UINT flags)
4945 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4946 ID3D10Device *device = pass->technique->effect->device;
4948 TRACE("iface %p, flags %#x\n", iface, flags);
4950 if (flags) FIXME("Ignoring flags (%#x)\n", flags);
4952 d3d10_effect_update_dependent_props(&pass->dependencies, pass);
4954 if (pass->vs.shader != &null_shader_variable)
4955 d3d10_effect_pass_set_shader(pass, &pass->vs);
4956 if (pass->gs.shader != &null_shader_variable)
4957 d3d10_effect_pass_set_shader(pass, &pass->gs);
4958 if (pass->ps.shader != &null_shader_variable)
4959 d3d10_effect_pass_set_shader(pass, &pass->ps);
4960 if (pass->rasterizer)
4961 ID3D10Device_RSSetState(device, pass->rasterizer->u.state.object.rasterizer);
4962 if (pass->depth_stencil)
4963 ID3D10Device_OMSetDepthStencilState(device, pass->depth_stencil->u.state.object.depth_stencil,
4964 pass->stencil_ref);
4965 if (pass->blend)
4966 ID3D10Device_OMSetBlendState(device, pass->blend->u.state.object.blend,
4967 pass->blend_factor, pass->sample_mask);
4969 return S_OK;
4972 static HRESULT STDMETHODCALLTYPE d3d10_effect_pass_ComputeStateBlockMask(ID3D10EffectPass *iface,
4973 D3D10_STATE_BLOCK_MASK *mask)
4975 struct d3d10_effect_pass *pass = impl_from_ID3D10EffectPass(iface);
4977 FIXME("iface %p, mask %p semi-stub!\n", iface, mask);
4979 if (pass->vs.shader != &null_shader_variable)
4980 D3D10StateBlockMaskEnableCapture(mask, D3D10_DST_VS, 0, 1);
4981 if (pass->ps.shader != &null_shader_variable)
4982 D3D10StateBlockMaskEnableCapture(mask, D3D10_DST_PS, 0, 1);
4983 if (pass->gs.shader != &null_shader_variable)
4984 D3D10StateBlockMaskEnableCapture(mask, D3D10_DST_GS, 0, 1);
4985 if (pass->rasterizer)
4986 D3D10StateBlockMaskEnableCapture(mask, D3D10_DST_RS_RASTERIZER_STATE, 0, 1);
4987 if (pass->depth_stencil)
4988 D3D10StateBlockMaskEnableCapture(mask, D3D10_DST_OM_DEPTH_STENCIL_STATE, 0, 1);
4989 if (pass->blend)
4990 D3D10StateBlockMaskEnableCapture(mask, D3D10_DST_OM_BLEND_STATE, 0, 1);
4992 return S_OK;
4995 static const struct ID3D10EffectPassVtbl d3d10_effect_pass_vtbl =
4997 /* ID3D10EffectPass methods */
4998 d3d10_effect_pass_IsValid,
4999 d3d10_effect_pass_GetDesc,
5000 d3d10_effect_pass_GetVertexShaderDesc,
5001 d3d10_effect_pass_GetGeometryShaderDesc,
5002 d3d10_effect_pass_GetPixelShaderDesc,
5003 d3d10_effect_pass_GetAnnotationByIndex,
5004 d3d10_effect_pass_GetAnnotationByName,
5005 d3d10_effect_pass_Apply,
5006 d3d10_effect_pass_ComputeStateBlockMask,
5009 /* ID3D10EffectVariable methods */
5011 static BOOL STDMETHODCALLTYPE d3d10_effect_variable_IsValid(ID3D10EffectVariable *iface)
5013 TRACE("iface %p\n", iface);
5015 return impl_from_ID3D10EffectVariable(iface) != &null_variable;
5018 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_variable_GetType(ID3D10EffectVariable *iface)
5020 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5022 TRACE("iface %p\n", iface);
5024 return &This->type->ID3D10EffectType_iface;
5027 static HRESULT STDMETHODCALLTYPE d3d10_effect_variable_GetDesc(ID3D10EffectVariable *iface,
5028 D3D10_EFFECT_VARIABLE_DESC *desc)
5030 struct d3d10_effect_variable *v = impl_from_ID3D10EffectVariable(iface);
5032 TRACE("iface %p, desc %p\n", iface, desc);
5034 if (!iface->lpVtbl->IsValid(iface))
5036 WARN("Null variable specified\n");
5037 return E_FAIL;
5040 if (!desc)
5042 WARN("Invalid argument specified\n");
5043 return E_INVALIDARG;
5046 /* FIXME: This isn't correct. Anonymous shaders let desc->ExplicitBindPoint untouched, but normal shaders set it! */
5047 memset(desc, 0, sizeof(*desc));
5048 desc->Name = v->name;
5049 desc->Semantic = v->semantic;
5050 desc->Flags = v->flag;
5051 desc->Annotations = v->annotations.count;
5052 desc->BufferOffset = v->buffer_offset;
5054 if (v->flag & D3D10_EFFECT_VARIABLE_EXPLICIT_BIND_POINT)
5055 desc->ExplicitBindPoint = v->explicit_bind_point;
5057 return S_OK;
5060 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_variable_GetAnnotationByIndex(
5061 ID3D10EffectVariable *iface, UINT index)
5063 struct d3d10_effect_variable *var = impl_from_ID3D10EffectVariable(iface);
5065 TRACE("iface %p, index %u\n", iface, index);
5067 return d3d10_annotation_get_by_index(&var->annotations, index);
5070 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_variable_GetAnnotationByName(
5071 ID3D10EffectVariable *iface, const char *name)
5073 struct d3d10_effect_variable *var = impl_from_ID3D10EffectVariable(iface);
5075 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
5077 return d3d10_annotation_get_by_name(&var->annotations, name);
5080 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_variable_GetMemberByIndex(
5081 ID3D10EffectVariable *iface, UINT index)
5083 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5084 struct d3d10_effect_variable *m;
5086 TRACE("iface %p, index %u\n", iface, index);
5088 if (index >= This->type->member_count)
5090 WARN("Invalid index specified\n");
5091 return &null_variable.ID3D10EffectVariable_iface;
5094 m = &This->members[index];
5096 TRACE("Returning member %p, %s\n", m, debugstr_a(m->name));
5098 return &m->ID3D10EffectVariable_iface;
5101 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_variable_GetMemberByName(
5102 ID3D10EffectVariable *iface, const char *name)
5104 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5105 unsigned int i;
5107 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
5109 if (!name)
5111 WARN("Invalid name specified\n");
5112 return &null_variable.ID3D10EffectVariable_iface;
5115 for (i = 0; i < This->type->member_count; ++i)
5117 struct d3d10_effect_variable *m = &This->members[i];
5119 if (m->name && !strcmp(m->name, name))
5121 TRACE("Returning member %p\n", m);
5122 return &m->ID3D10EffectVariable_iface;
5126 WARN("Invalid name specified\n");
5128 return &null_variable.ID3D10EffectVariable_iface;
5131 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_variable_GetMemberBySemantic(
5132 ID3D10EffectVariable *iface, const char *semantic)
5134 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5135 unsigned int i;
5137 TRACE("iface %p, semantic %s.\n", iface, debugstr_a(semantic));
5139 if (!semantic)
5141 WARN("Invalid semantic specified\n");
5142 return &null_variable.ID3D10EffectVariable_iface;
5145 for (i = 0; i < This->type->member_count; ++i)
5147 struct d3d10_effect_variable *m = &This->members[i];
5149 if (m->semantic && !stricmp(m->semantic, semantic))
5151 TRACE("Returning member %p\n", m);
5152 return &m->ID3D10EffectVariable_iface;
5156 WARN("Invalid semantic specified\n");
5158 return &null_variable.ID3D10EffectVariable_iface;
5161 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_variable_GetElement(
5162 ID3D10EffectVariable *iface, UINT index)
5164 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5165 struct d3d10_effect_variable *v;
5167 TRACE("iface %p, index %u\n", iface, index);
5169 if (index >= This->type->element_count)
5171 WARN("Invalid index specified\n");
5172 return &null_variable.ID3D10EffectVariable_iface;
5175 v = &This->elements[index];
5177 TRACE("Returning element %p, %s\n", v, debugstr_a(v->name));
5179 return &v->ID3D10EffectVariable_iface;
5182 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_variable_GetParentConstantBuffer(
5183 ID3D10EffectVariable *iface)
5185 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5187 TRACE("iface %p\n", iface);
5189 return (ID3D10EffectConstantBuffer *)&This->buffer->ID3D10EffectVariable_iface;
5192 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsScalar(
5193 ID3D10EffectVariable *iface)
5195 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5197 TRACE("iface %p\n", iface);
5199 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_scalar_variable_vtbl)
5200 return (ID3D10EffectScalarVariable *)&This->ID3D10EffectVariable_iface;
5202 return (ID3D10EffectScalarVariable *)&null_scalar_variable.ID3D10EffectVariable_iface;
5205 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsVector(
5206 ID3D10EffectVariable *iface)
5208 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5210 TRACE("iface %p\n", iface);
5212 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_vector_variable_vtbl)
5213 return (ID3D10EffectVectorVariable *)&This->ID3D10EffectVariable_iface;
5215 return (ID3D10EffectVectorVariable *)&null_vector_variable.ID3D10EffectVariable_iface;
5218 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsMatrix(
5219 ID3D10EffectVariable *iface)
5221 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5223 TRACE("iface %p\n", iface);
5225 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_matrix_variable_vtbl)
5226 return (ID3D10EffectMatrixVariable *)&This->ID3D10EffectVariable_iface;
5228 return (ID3D10EffectMatrixVariable *)&null_matrix_variable.ID3D10EffectVariable_iface;
5231 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsString(
5232 ID3D10EffectVariable *iface)
5234 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5236 TRACE("iface %p\n", iface);
5238 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_string_variable_vtbl)
5239 return (ID3D10EffectStringVariable *)&This->ID3D10EffectVariable_iface;
5241 return (ID3D10EffectStringVariable *)&null_string_variable.ID3D10EffectVariable_iface;
5244 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsShaderResource(
5245 ID3D10EffectVariable *iface)
5247 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5249 TRACE("iface %p\n", iface);
5251 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_resource_variable_vtbl)
5252 return (ID3D10EffectShaderResourceVariable *)&This->ID3D10EffectVariable_iface;
5254 return (ID3D10EffectShaderResourceVariable *)&null_shader_resource_variable.ID3D10EffectVariable_iface;
5257 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsRenderTargetView(
5258 ID3D10EffectVariable *iface)
5260 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5262 TRACE("iface %p\n", iface);
5264 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_render_target_view_variable_vtbl)
5265 return (ID3D10EffectRenderTargetViewVariable *)&This->ID3D10EffectVariable_iface;
5267 return (ID3D10EffectRenderTargetViewVariable *)&null_render_target_view_variable.ID3D10EffectVariable_iface;
5270 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsDepthStencilView(
5271 ID3D10EffectVariable *iface)
5273 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5275 TRACE("iface %p\n", iface);
5277 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_depth_stencil_view_variable_vtbl)
5278 return (ID3D10EffectDepthStencilViewVariable *)&This->ID3D10EffectVariable_iface;
5280 return (ID3D10EffectDepthStencilViewVariable *)&null_depth_stencil_view_variable.ID3D10EffectVariable_iface;
5283 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_variable_AsConstantBuffer(
5284 ID3D10EffectVariable *iface)
5286 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5288 TRACE("iface %p\n", iface);
5290 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_constant_buffer_vtbl)
5291 return (ID3D10EffectConstantBuffer *)&This->ID3D10EffectVariable_iface;
5293 return (ID3D10EffectConstantBuffer *)&null_local_buffer.ID3D10EffectVariable_iface;
5296 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsShader(
5297 ID3D10EffectVariable *iface)
5299 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5301 TRACE("iface %p\n", iface);
5303 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_shader_variable_vtbl)
5304 return (ID3D10EffectShaderVariable *)&This->ID3D10EffectVariable_iface;
5306 return (ID3D10EffectShaderVariable *)&null_shader_variable.ID3D10EffectVariable_iface;
5309 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsBlend(ID3D10EffectVariable *iface)
5311 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5313 TRACE("iface %p\n", iface);
5315 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_blend_variable_vtbl)
5316 return (ID3D10EffectBlendVariable *)&This->ID3D10EffectVariable_iface;
5318 return (ID3D10EffectBlendVariable *)&null_blend_variable.ID3D10EffectVariable_iface;
5321 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsDepthStencil(
5322 ID3D10EffectVariable *iface)
5324 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5326 TRACE("iface %p\n", iface);
5328 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_depth_stencil_variable_vtbl)
5329 return (ID3D10EffectDepthStencilVariable *)&This->ID3D10EffectVariable_iface;
5331 return (ID3D10EffectDepthStencilVariable *)&null_depth_stencil_variable.ID3D10EffectVariable_iface;
5334 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsRasterizer(
5335 ID3D10EffectVariable *iface)
5337 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5339 TRACE("iface %p\n", iface);
5341 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_rasterizer_variable_vtbl)
5342 return (ID3D10EffectRasterizerVariable *)&This->ID3D10EffectVariable_iface;
5344 return (ID3D10EffectRasterizerVariable *)&null_rasterizer_variable.ID3D10EffectVariable_iface;
5347 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_variable_AsSampler(
5348 ID3D10EffectVariable *iface)
5350 struct d3d10_effect_variable *This = impl_from_ID3D10EffectVariable(iface);
5352 TRACE("iface %p\n", iface);
5354 if (This->ID3D10EffectVariable_iface.lpVtbl == (const ID3D10EffectVariableVtbl *)&d3d10_effect_sampler_variable_vtbl)
5355 return (ID3D10EffectSamplerVariable *)&This->ID3D10EffectVariable_iface;
5357 return (ID3D10EffectSamplerVariable *)&null_sampler_variable.ID3D10EffectVariable_iface;
5360 static HRESULT STDMETHODCALLTYPE d3d10_effect_variable_SetRawValue(ID3D10EffectVariable *iface,
5361 void *data, UINT offset, UINT count)
5363 struct d3d10_effect_variable *v = impl_from_ID3D10EffectVariable(iface);
5364 BOOL is_buffer;
5366 TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count);
5368 if (!iface->lpVtbl->IsValid(iface))
5370 WARN("Invalid variable.\n");
5371 return E_FAIL;
5374 is_buffer = v->type->basetype == D3D10_SVT_CBUFFER || v->type->basetype == D3D10_SVT_TBUFFER;
5376 if (v->type->type_class == D3D10_SVC_OBJECT && !is_buffer)
5378 WARN("Not supported on object variables of type %s.\n",
5379 debug_d3d10_shader_variable_type(v->type->basetype));
5380 return D3DERR_INVALIDCALL;
5383 if (!is_buffer)
5385 offset += v->buffer_offset;
5386 v = v->buffer;
5389 memcpy(v->u.buffer.local_buffer + offset, data, count);
5390 v->u.buffer.changed = TRUE;
5392 return S_OK;
5395 static HRESULT STDMETHODCALLTYPE d3d10_effect_variable_GetRawValue(ID3D10EffectVariable *iface,
5396 void *data, UINT offset, UINT count)
5398 struct d3d10_effect_variable *v = impl_from_ID3D10EffectVariable(iface);
5400 TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count);
5402 if (!iface->lpVtbl->IsValid(iface))
5404 WARN("Invalid variable.\n");
5405 return E_FAIL;
5408 return d3d10_effect_variable_get_raw_value(v, data, offset, count);
5411 static const struct ID3D10EffectVariableVtbl d3d10_effect_variable_vtbl =
5413 /* ID3D10EffectVariable methods */
5414 d3d10_effect_variable_IsValid,
5415 d3d10_effect_variable_GetType,
5416 d3d10_effect_variable_GetDesc,
5417 d3d10_effect_variable_GetAnnotationByIndex,
5418 d3d10_effect_variable_GetAnnotationByName,
5419 d3d10_effect_variable_GetMemberByIndex,
5420 d3d10_effect_variable_GetMemberByName,
5421 d3d10_effect_variable_GetMemberBySemantic,
5422 d3d10_effect_variable_GetElement,
5423 d3d10_effect_variable_GetParentConstantBuffer,
5424 d3d10_effect_variable_AsScalar,
5425 d3d10_effect_variable_AsVector,
5426 d3d10_effect_variable_AsMatrix,
5427 d3d10_effect_variable_AsString,
5428 d3d10_effect_variable_AsShaderResource,
5429 d3d10_effect_variable_AsRenderTargetView,
5430 d3d10_effect_variable_AsDepthStencilView,
5431 d3d10_effect_variable_AsConstantBuffer,
5432 d3d10_effect_variable_AsShader,
5433 d3d10_effect_variable_AsBlend,
5434 d3d10_effect_variable_AsDepthStencil,
5435 d3d10_effect_variable_AsRasterizer,
5436 d3d10_effect_variable_AsSampler,
5437 d3d10_effect_variable_SetRawValue,
5438 d3d10_effect_variable_GetRawValue,
5441 /* ID3D10EffectVariable methods */
5442 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectConstantBuffer(ID3D10EffectConstantBuffer *iface)
5444 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
5447 static BOOL STDMETHODCALLTYPE d3d10_effect_constant_buffer_IsValid(ID3D10EffectConstantBuffer *iface)
5449 struct d3d10_effect_variable *v = impl_from_ID3D10EffectConstantBuffer(iface);
5451 TRACE("iface %p.\n", iface);
5453 return v != &null_local_buffer;
5456 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetType(ID3D10EffectConstantBuffer *iface)
5458 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
5461 static HRESULT STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetDesc(ID3D10EffectConstantBuffer *iface,
5462 D3D10_EFFECT_VARIABLE_DESC *desc)
5464 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
5467 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetAnnotationByIndex(
5468 ID3D10EffectConstantBuffer *iface, UINT index)
5470 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
5473 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetAnnotationByName(
5474 ID3D10EffectConstantBuffer *iface, const char *name)
5476 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
5479 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetMemberByIndex(
5480 ID3D10EffectConstantBuffer *iface, UINT index)
5482 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
5485 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetMemberByName(
5486 ID3D10EffectConstantBuffer *iface, const char *name)
5488 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
5491 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetMemberBySemantic(
5492 ID3D10EffectConstantBuffer *iface, const char *semantic)
5494 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
5497 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetElement(
5498 ID3D10EffectConstantBuffer *iface, UINT index)
5500 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
5503 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetParentConstantBuffer(
5504 ID3D10EffectConstantBuffer *iface)
5506 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
5509 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsScalar(
5510 ID3D10EffectConstantBuffer *iface)
5512 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
5515 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsVector(
5516 ID3D10EffectConstantBuffer *iface)
5518 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
5521 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsMatrix(
5522 ID3D10EffectConstantBuffer *iface)
5524 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
5527 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsString(
5528 ID3D10EffectConstantBuffer *iface)
5530 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
5533 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsShaderResource(
5534 ID3D10EffectConstantBuffer *iface)
5536 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
5539 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsRenderTargetView(
5540 ID3D10EffectConstantBuffer *iface)
5542 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
5545 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsDepthStencilView(
5546 ID3D10EffectConstantBuffer *iface)
5548 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
5551 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsConstantBuffer(
5552 ID3D10EffectConstantBuffer *iface)
5554 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
5557 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsShader(
5558 ID3D10EffectConstantBuffer *iface)
5560 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
5563 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsBlend(ID3D10EffectConstantBuffer *iface)
5565 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
5568 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsDepthStencil(
5569 ID3D10EffectConstantBuffer *iface)
5571 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
5574 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsRasterizer(
5575 ID3D10EffectConstantBuffer *iface)
5577 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
5580 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_constant_buffer_AsSampler(
5581 ID3D10EffectConstantBuffer *iface)
5583 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
5586 static HRESULT STDMETHODCALLTYPE d3d10_effect_constant_buffer_SetRawValue(ID3D10EffectConstantBuffer *iface,
5587 void *data, UINT offset, UINT count)
5589 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
5592 static HRESULT STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetRawValue(ID3D10EffectConstantBuffer *iface,
5593 void *data, UINT offset, UINT count)
5595 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
5598 /* ID3D10EffectConstantBuffer methods */
5599 static HRESULT STDMETHODCALLTYPE d3d10_effect_constant_buffer_SetConstantBuffer(ID3D10EffectConstantBuffer *iface,
5600 ID3D10Buffer *buffer)
5602 FIXME("iface %p, buffer %p stub!\n", iface, buffer);
5604 return E_NOTIMPL;
5607 static HRESULT STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetConstantBuffer(ID3D10EffectConstantBuffer *iface,
5608 ID3D10Buffer **buffer)
5610 struct d3d10_effect_variable *v = impl_from_ID3D10EffectConstantBuffer(iface);
5612 TRACE("iface %p, buffer %p.\n", iface, buffer);
5614 if (!iface->lpVtbl->IsValid(iface))
5616 WARN("Null variable specified.\n");
5617 return E_FAIL;
5620 if (v->type->basetype != D3D10_SVT_CBUFFER)
5622 WARN("Wrong variable type %s.\n", debug_d3d10_shader_variable_type(v->type->basetype));
5623 return D3DERR_INVALIDCALL;
5626 *buffer = v->u.buffer.buffer;
5627 ID3D10Buffer_AddRef(*buffer);
5629 return S_OK;
5632 static HRESULT STDMETHODCALLTYPE d3d10_effect_constant_buffer_SetTextureBuffer(ID3D10EffectConstantBuffer *iface,
5633 ID3D10ShaderResourceView *view)
5635 FIXME("iface %p, view %p stub!\n", iface, view);
5637 return E_NOTIMPL;
5640 static HRESULT STDMETHODCALLTYPE d3d10_effect_constant_buffer_GetTextureBuffer(ID3D10EffectConstantBuffer *iface,
5641 ID3D10ShaderResourceView **view)
5643 struct d3d10_effect_variable *v = impl_from_ID3D10EffectConstantBuffer(iface);
5645 FIXME("iface %p, view %p stub!\n", iface, view);
5647 if (!iface->lpVtbl->IsValid(iface))
5649 WARN("Null variable specified.\n");
5650 return E_FAIL;
5653 if (v->type->basetype != D3D10_SVT_TBUFFER)
5655 WARN("Wrong variable type %s.\n", debug_d3d10_shader_variable_type(v->type->basetype));
5656 return D3DERR_INVALIDCALL;
5659 return E_NOTIMPL;
5662 static const struct ID3D10EffectConstantBufferVtbl d3d10_effect_constant_buffer_vtbl =
5664 /* ID3D10EffectVariable methods */
5665 d3d10_effect_constant_buffer_IsValid,
5666 d3d10_effect_constant_buffer_GetType,
5667 d3d10_effect_constant_buffer_GetDesc,
5668 d3d10_effect_constant_buffer_GetAnnotationByIndex,
5669 d3d10_effect_constant_buffer_GetAnnotationByName,
5670 d3d10_effect_constant_buffer_GetMemberByIndex,
5671 d3d10_effect_constant_buffer_GetMemberByName,
5672 d3d10_effect_constant_buffer_GetMemberBySemantic,
5673 d3d10_effect_constant_buffer_GetElement,
5674 d3d10_effect_constant_buffer_GetParentConstantBuffer,
5675 d3d10_effect_constant_buffer_AsScalar,
5676 d3d10_effect_constant_buffer_AsVector,
5677 d3d10_effect_constant_buffer_AsMatrix,
5678 d3d10_effect_constant_buffer_AsString,
5679 d3d10_effect_constant_buffer_AsShaderResource,
5680 d3d10_effect_constant_buffer_AsRenderTargetView,
5681 d3d10_effect_constant_buffer_AsDepthStencilView,
5682 d3d10_effect_constant_buffer_AsConstantBuffer,
5683 d3d10_effect_constant_buffer_AsShader,
5684 d3d10_effect_constant_buffer_AsBlend,
5685 d3d10_effect_constant_buffer_AsDepthStencil,
5686 d3d10_effect_constant_buffer_AsRasterizer,
5687 d3d10_effect_constant_buffer_AsSampler,
5688 d3d10_effect_constant_buffer_SetRawValue,
5689 d3d10_effect_constant_buffer_GetRawValue,
5690 /* ID3D10EffectConstantBuffer methods */
5691 d3d10_effect_constant_buffer_SetConstantBuffer,
5692 d3d10_effect_constant_buffer_GetConstantBuffer,
5693 d3d10_effect_constant_buffer_SetTextureBuffer,
5694 d3d10_effect_constant_buffer_GetTextureBuffer,
5698 static BOOL get_value_as_bool(void *src_data, D3D10_SHADER_VARIABLE_TYPE src_type)
5700 switch (src_type)
5702 case D3D10_SVT_FLOAT:
5703 case D3D10_SVT_INT:
5704 case D3D10_SVT_UINT:
5705 case D3D10_SVT_BOOL:
5706 if (*(DWORD *)src_data)
5707 return -1;
5708 break;
5710 default:
5711 break;
5714 return 0;
5717 static int get_value_as_int(void *src_data, D3D10_SHADER_VARIABLE_TYPE src_type)
5719 switch (src_type)
5721 case D3D10_SVT_FLOAT:
5722 return (int)(*(float *)src_data);
5724 case D3D10_SVT_INT:
5725 case D3D10_SVT_UINT:
5726 return *(int *)src_data;
5728 case D3D10_SVT_BOOL:
5729 return get_value_as_bool(src_data, src_type);
5731 default:
5732 return 0;
5736 static float get_value_as_float(void *src_data, D3D10_SHADER_VARIABLE_TYPE src_type)
5738 switch (src_type)
5740 case D3D10_SVT_FLOAT:
5741 return *(float *)src_data;
5743 case D3D10_SVT_INT:
5744 case D3D10_SVT_UINT:
5745 return (float)(*(int *)src_data);
5747 case D3D10_SVT_BOOL:
5748 return (float)get_value_as_bool(src_data, src_type);
5750 default:
5751 return 0.0f;
5755 static void get_vector_as_type(BYTE *dst_data, D3D_SHADER_VARIABLE_TYPE dst_type,
5756 BYTE *src_data, D3D_SHADER_VARIABLE_TYPE src_type, unsigned int count)
5758 DWORD *src_data_dword = (DWORD *)src_data;
5759 DWORD *dst_data_dword = (DWORD *)dst_data;
5760 unsigned int i;
5762 for (i = 0; i < count; ++i, ++dst_data_dword, ++src_data_dword)
5764 if (dst_type == src_type)
5765 *dst_data_dword = *src_data_dword;
5766 else
5768 switch (dst_type)
5770 case D3D10_SVT_FLOAT:
5771 *(float *)dst_data_dword = get_value_as_float(src_data_dword, src_type);
5772 break;
5774 case D3D10_SVT_INT:
5775 case D3D10_SVT_UINT:
5776 *(int *)dst_data_dword = get_value_as_int(src_data_dword, src_type);
5777 break;
5779 case D3D10_SVT_BOOL:
5780 *(BOOL *)dst_data_dword = get_value_as_bool(src_data_dword, src_type);
5781 break;
5783 default:
5784 *dst_data_dword = 0;
5785 break;
5791 static void write_variable_to_buffer(struct d3d10_effect_variable *variable, void *src,
5792 D3D_SHADER_VARIABLE_TYPE src_type)
5794 BYTE *dst = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
5795 D3D_SHADER_VARIABLE_TYPE dst_type = variable->type->basetype;
5797 get_vector_as_type(dst, dst_type, src, src_type, variable->type->column_count);
5799 variable->buffer->u.buffer.changed = TRUE;
5802 static void write_variable_array_to_buffer(struct d3d10_effect_variable *variable, void *src,
5803 D3D_SHADER_VARIABLE_TYPE src_type, unsigned int offset, unsigned int count)
5805 BYTE *dst = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
5806 D3D_SHADER_VARIABLE_TYPE dst_type = variable->type->basetype;
5807 unsigned int element_size, i;
5808 BYTE *cur_element = src;
5810 if (!variable->type->element_count)
5812 write_variable_to_buffer(variable, src, src_type);
5813 return;
5816 if (offset >= variable->type->element_count)
5818 WARN("Offset %u larger than element count %u, ignoring.\n", offset, variable->type->element_count);
5819 return;
5822 if (count > variable->type->element_count - offset)
5824 WARN("Offset %u, count %u overruns the variable (element count %u), fixing up.\n",
5825 offset, count, variable->type->element_count);
5826 count = variable->type->element_count - offset;
5829 element_size = variable->type->elementtype->size_packed;
5830 dst += variable->type->stride * offset;
5832 for (i = 0; i < count; ++i)
5834 get_vector_as_type(dst, dst_type, cur_element, src_type, variable->type->column_count);
5836 cur_element += element_size;
5837 dst += variable->type->stride;
5840 variable->buffer->u.buffer.changed = TRUE;
5843 static void read_variable_from_buffer(struct d3d10_effect_variable *variable, void *dst,
5844 D3D_SHADER_VARIABLE_TYPE dst_type)
5846 BYTE *src = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
5847 D3D_SHADER_VARIABLE_TYPE src_type = variable->type->basetype;
5849 get_vector_as_type(dst, dst_type, src, src_type, variable->type->column_count);
5852 static void read_variable_array_from_buffer(struct d3d10_effect_variable *variable, void *dst,
5853 D3D_SHADER_VARIABLE_TYPE dst_type, unsigned int offset, unsigned int count)
5855 BYTE *src = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
5856 D3D_SHADER_VARIABLE_TYPE src_type = variable->type->basetype;
5857 unsigned int element_size, i;
5858 BYTE *cur_element = dst;
5860 if (!variable->type->element_count)
5862 read_variable_from_buffer(variable, dst, dst_type);
5863 return;
5866 if (offset >= variable->type->element_count)
5868 WARN("Offset %u larger than element count %u, ignoring.\n", offset, variable->type->element_count);
5869 return;
5872 if (count > variable->type->element_count - offset)
5874 WARN("Offset %u, count %u overruns the variable (element count %u), fixing up.\n",
5875 offset, count, variable->type->element_count);
5876 count = variable->type->element_count - offset;
5879 element_size = variable->type->elementtype->size_packed;
5880 src += variable->type->stride * offset;
5882 for (i = 0; i < count; ++i)
5884 get_vector_as_type(cur_element, dst_type, src, src_type, variable->type->column_count);
5886 cur_element += element_size;
5887 src += variable->type->stride;
5891 /* ID3D10EffectVariable methods */
5893 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectScalarVariable(ID3D10EffectScalarVariable *iface)
5895 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
5898 static BOOL STDMETHODCALLTYPE d3d10_effect_scalar_variable_IsValid(ID3D10EffectScalarVariable *iface)
5900 struct d3d10_effect_variable *v = impl_from_ID3D10EffectScalarVariable(iface);
5902 TRACE("iface %p\n", iface);
5904 return v != &null_scalar_variable;
5907 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetType(
5908 ID3D10EffectScalarVariable *iface)
5910 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
5913 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetDesc(ID3D10EffectScalarVariable *iface,
5914 D3D10_EFFECT_VARIABLE_DESC *desc)
5916 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
5919 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetAnnotationByIndex(
5920 ID3D10EffectScalarVariable *iface, UINT index)
5922 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
5925 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetAnnotationByName(
5926 ID3D10EffectScalarVariable *iface, const char *name)
5928 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
5931 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetMemberByIndex(
5932 ID3D10EffectScalarVariable *iface, UINT index)
5934 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
5937 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetMemberByName(
5938 ID3D10EffectScalarVariable *iface, const char *name)
5940 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
5943 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetMemberBySemantic(
5944 ID3D10EffectScalarVariable *iface, const char *semantic)
5946 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
5949 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetElement(
5950 ID3D10EffectScalarVariable *iface, UINT index)
5952 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
5955 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetParentConstantBuffer(
5956 ID3D10EffectScalarVariable *iface)
5958 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
5961 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsScalar(
5962 ID3D10EffectScalarVariable *iface)
5964 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
5967 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsVector(
5968 ID3D10EffectScalarVariable *iface)
5970 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
5973 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsMatrix(
5974 ID3D10EffectScalarVariable *iface)
5976 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
5979 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsString(
5980 ID3D10EffectScalarVariable *iface)
5982 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
5985 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsShaderResource(
5986 ID3D10EffectScalarVariable *iface)
5988 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
5991 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsRenderTargetView(
5992 ID3D10EffectScalarVariable *iface)
5994 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
5997 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsDepthStencilView(
5998 ID3D10EffectScalarVariable *iface)
6000 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
6003 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsConstantBuffer(
6004 ID3D10EffectScalarVariable *iface)
6006 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
6009 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsShader(
6010 ID3D10EffectScalarVariable *iface)
6012 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
6015 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsBlend(
6016 ID3D10EffectScalarVariable *iface)
6018 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
6021 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsDepthStencil(
6022 ID3D10EffectScalarVariable *iface)
6024 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
6027 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsRasterizer(
6028 ID3D10EffectScalarVariable *iface)
6030 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
6033 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_scalar_variable_AsSampler(
6034 ID3D10EffectScalarVariable *iface)
6036 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
6039 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_SetRawValue(ID3D10EffectScalarVariable *iface,
6040 void *data, UINT offset, UINT count)
6042 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
6045 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetRawValue(ID3D10EffectScalarVariable *iface,
6046 void *data, UINT offset, UINT count)
6048 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
6051 /* ID3D10EffectScalarVariable methods */
6053 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_SetFloat(ID3D10EffectScalarVariable *iface,
6054 float value)
6056 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6058 TRACE("iface %p, value %.8e.\n", iface, value);
6059 write_variable_to_buffer(effect_var, &value, D3D10_SVT_FLOAT);
6061 return S_OK;
6064 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetFloat(ID3D10EffectScalarVariable *iface,
6065 float *value)
6067 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6069 TRACE("iface %p, value %p.\n", iface, value);
6070 read_variable_from_buffer(effect_var, value, D3D10_SVT_FLOAT);
6072 return S_OK;
6075 /* Tests show that offset is ignored for scalar variables. */
6076 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_SetFloatArray(ID3D10EffectScalarVariable *iface,
6077 float *values, UINT offset, UINT count)
6079 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6081 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6082 write_variable_array_to_buffer(effect_var, values, D3D10_SVT_FLOAT, 0, count);
6084 return S_OK;
6087 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetFloatArray(ID3D10EffectScalarVariable *iface,
6088 float *values, UINT offset, UINT count)
6090 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6092 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6093 read_variable_array_from_buffer(effect_var, values, D3D10_SVT_FLOAT, 0, count);
6095 return S_OK;
6098 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_SetInt(ID3D10EffectScalarVariable *iface,
6099 int value)
6101 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6103 TRACE("iface %p, value %d.\n", iface, value);
6104 write_variable_to_buffer(effect_var, &value, D3D10_SVT_INT);
6106 return S_OK;
6109 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetInt(ID3D10EffectScalarVariable *iface,
6110 int *value)
6112 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6114 TRACE("iface %p, value %p.\n", iface, value);
6115 read_variable_from_buffer(effect_var, value, D3D10_SVT_INT);
6117 return S_OK;
6120 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_SetIntArray(ID3D10EffectScalarVariable *iface,
6121 int *values, UINT offset, UINT count)
6123 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6125 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6126 write_variable_array_to_buffer(effect_var, values, D3D10_SVT_INT, 0, count);
6128 return S_OK;
6131 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetIntArray(ID3D10EffectScalarVariable *iface,
6132 int *values, UINT offset, UINT count)
6134 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6136 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6137 read_variable_array_from_buffer(effect_var, values, D3D10_SVT_INT, 0, count);
6139 return S_OK;
6142 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_SetBool(ID3D10EffectScalarVariable *iface,
6143 BOOL value)
6145 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6147 TRACE("iface %p, value %d.\n", iface, value);
6148 write_variable_to_buffer(effect_var, &value, D3D10_SVT_BOOL);
6150 return S_OK;
6153 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetBool(ID3D10EffectScalarVariable *iface,
6154 BOOL *value)
6156 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6158 TRACE("iface %p, value %p.\n", iface, value);
6159 read_variable_from_buffer(effect_var, value, D3D10_SVT_BOOL);
6161 return S_OK;
6164 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_SetBoolArray(ID3D10EffectScalarVariable *iface,
6165 BOOL *values, UINT offset, UINT count)
6167 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6169 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6170 write_variable_array_to_buffer(effect_var, values, D3D10_SVT_BOOL, 0, count);
6172 return S_OK;
6175 static HRESULT STDMETHODCALLTYPE d3d10_effect_scalar_variable_GetBoolArray(ID3D10EffectScalarVariable *iface,
6176 BOOL *values, UINT offset, UINT count)
6178 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectScalarVariable(iface);
6180 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6181 read_variable_array_from_buffer(effect_var, values, D3D10_SVT_BOOL, 0, count);
6183 return S_OK;
6186 static const struct ID3D10EffectScalarVariableVtbl d3d10_effect_scalar_variable_vtbl =
6188 /* ID3D10EffectVariable methods */
6189 d3d10_effect_scalar_variable_IsValid,
6190 d3d10_effect_scalar_variable_GetType,
6191 d3d10_effect_scalar_variable_GetDesc,
6192 d3d10_effect_scalar_variable_GetAnnotationByIndex,
6193 d3d10_effect_scalar_variable_GetAnnotationByName,
6194 d3d10_effect_scalar_variable_GetMemberByIndex,
6195 d3d10_effect_scalar_variable_GetMemberByName,
6196 d3d10_effect_scalar_variable_GetMemberBySemantic,
6197 d3d10_effect_scalar_variable_GetElement,
6198 d3d10_effect_scalar_variable_GetParentConstantBuffer,
6199 d3d10_effect_scalar_variable_AsScalar,
6200 d3d10_effect_scalar_variable_AsVector,
6201 d3d10_effect_scalar_variable_AsMatrix,
6202 d3d10_effect_scalar_variable_AsString,
6203 d3d10_effect_scalar_variable_AsShaderResource,
6204 d3d10_effect_scalar_variable_AsRenderTargetView,
6205 d3d10_effect_scalar_variable_AsDepthStencilView,
6206 d3d10_effect_scalar_variable_AsConstantBuffer,
6207 d3d10_effect_scalar_variable_AsShader,
6208 d3d10_effect_scalar_variable_AsBlend,
6209 d3d10_effect_scalar_variable_AsDepthStencil,
6210 d3d10_effect_scalar_variable_AsRasterizer,
6211 d3d10_effect_scalar_variable_AsSampler,
6212 d3d10_effect_scalar_variable_SetRawValue,
6213 d3d10_effect_scalar_variable_GetRawValue,
6214 /* ID3D10EffectScalarVariable methods */
6215 d3d10_effect_scalar_variable_SetFloat,
6216 d3d10_effect_scalar_variable_GetFloat,
6217 d3d10_effect_scalar_variable_SetFloatArray,
6218 d3d10_effect_scalar_variable_GetFloatArray,
6219 d3d10_effect_scalar_variable_SetInt,
6220 d3d10_effect_scalar_variable_GetInt,
6221 d3d10_effect_scalar_variable_SetIntArray,
6222 d3d10_effect_scalar_variable_GetIntArray,
6223 d3d10_effect_scalar_variable_SetBool,
6224 d3d10_effect_scalar_variable_GetBool,
6225 d3d10_effect_scalar_variable_SetBoolArray,
6226 d3d10_effect_scalar_variable_GetBoolArray,
6229 /* ID3D10EffectVariable methods */
6231 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectVectorVariable(ID3D10EffectVectorVariable *iface)
6233 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
6236 static BOOL STDMETHODCALLTYPE d3d10_effect_vector_variable_IsValid(ID3D10EffectVectorVariable *iface)
6238 struct d3d10_effect_variable *v = impl_from_ID3D10EffectVectorVariable(iface);
6240 TRACE("iface %p\n", iface);
6242 return v != &null_vector_variable;
6245 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetType(
6246 ID3D10EffectVectorVariable *iface)
6248 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
6251 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetDesc(ID3D10EffectVectorVariable *iface,
6252 D3D10_EFFECT_VARIABLE_DESC *desc)
6254 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
6257 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetAnnotationByIndex(
6258 ID3D10EffectVectorVariable *iface, UINT index)
6260 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
6263 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetAnnotationByName(
6264 ID3D10EffectVectorVariable *iface, const char *name)
6266 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
6269 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetMemberByIndex(
6270 ID3D10EffectVectorVariable *iface, UINT index)
6272 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
6275 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetMemberByName(
6276 ID3D10EffectVectorVariable *iface, const char *name)
6278 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
6281 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetMemberBySemantic(
6282 ID3D10EffectVectorVariable *iface, const char *semantic)
6284 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
6287 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetElement(
6288 ID3D10EffectVectorVariable *iface, UINT index)
6290 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
6293 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_vector_variable_GetParentConstantBuffer(
6294 ID3D10EffectVectorVariable *iface)
6296 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
6299 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsScalar(
6300 ID3D10EffectVectorVariable *iface)
6302 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
6305 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsVector(
6306 ID3D10EffectVectorVariable *iface)
6308 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
6311 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsMatrix(
6312 ID3D10EffectVectorVariable *iface)
6314 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
6317 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsString(
6318 ID3D10EffectVectorVariable *iface)
6320 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
6323 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsShaderResource(
6324 ID3D10EffectVectorVariable *iface)
6326 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
6329 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsRenderTargetView(
6330 ID3D10EffectVectorVariable *iface)
6332 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
6335 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsDepthStencilView(
6336 ID3D10EffectVectorVariable *iface)
6338 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
6341 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsConstantBuffer(
6342 ID3D10EffectVectorVariable *iface)
6344 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
6347 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsShader(
6348 ID3D10EffectVectorVariable *iface)
6350 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
6353 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsBlend(
6354 ID3D10EffectVectorVariable *iface)
6356 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
6359 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsDepthStencil(
6360 ID3D10EffectVectorVariable *iface)
6362 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
6365 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsRasterizer(
6366 ID3D10EffectVectorVariable *iface)
6368 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
6371 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_vector_variable_AsSampler(
6372 ID3D10EffectVectorVariable *iface)
6374 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
6377 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_SetRawValue(ID3D10EffectVectorVariable *iface,
6378 void *data, UINT offset, UINT count)
6380 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
6383 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetRawValue(ID3D10EffectVectorVariable *iface,
6384 void *data, UINT offset, UINT count)
6386 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
6389 /* ID3D10EffectVectorVariable methods */
6391 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_SetBoolVector(ID3D10EffectVectorVariable *iface,
6392 BOOL *value)
6394 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6396 TRACE("iface %p, value %p.\n", iface, value);
6397 write_variable_to_buffer(effect_var, value, D3D10_SVT_BOOL);
6399 return S_OK;
6402 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_SetIntVector(ID3D10EffectVectorVariable *iface,
6403 int *value)
6405 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6407 TRACE("iface %p, value %p.\n", iface, value);
6408 write_variable_to_buffer(effect_var, value, D3D10_SVT_INT);
6410 return S_OK;
6413 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_SetFloatVector(ID3D10EffectVectorVariable *iface,
6414 float *value)
6416 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6418 TRACE("iface %p, value %p.\n", iface, value);
6419 write_variable_to_buffer(effect_var, value, D3D10_SVT_FLOAT);
6421 return S_OK;
6424 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetBoolVector(ID3D10EffectVectorVariable *iface,
6425 BOOL *value)
6427 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6429 TRACE("iface %p, value %p.\n", iface, value);
6430 read_variable_from_buffer(effect_var, value, D3D10_SVT_BOOL);
6432 return S_OK;
6435 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetIntVector(ID3D10EffectVectorVariable *iface,
6436 int *value)
6438 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6440 TRACE("iface %p, value %p.\n", iface, value);
6441 read_variable_from_buffer(effect_var, value, D3D10_SVT_INT);
6443 return S_OK;
6446 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetFloatVector(ID3D10EffectVectorVariable *iface,
6447 float *value)
6449 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6451 TRACE("iface %p, value %p.\n", iface, value);
6452 read_variable_from_buffer(effect_var, value, D3D10_SVT_FLOAT);
6454 return S_OK;
6457 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_SetBoolVectorArray(ID3D10EffectVectorVariable *iface,
6458 BOOL *values, UINT offset, UINT count)
6460 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6462 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6463 write_variable_array_to_buffer(effect_var, values, D3D10_SVT_BOOL, offset, count);
6465 return S_OK;
6468 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_SetIntVectorArray(ID3D10EffectVectorVariable *iface,
6469 int *values, UINT offset, UINT count)
6471 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6473 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6474 write_variable_array_to_buffer(effect_var, values, D3D10_SVT_INT, offset, count);
6476 return S_OK;
6479 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_SetFloatVectorArray(ID3D10EffectVectorVariable *iface,
6480 float *values, UINT offset, UINT count)
6482 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6484 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6485 write_variable_array_to_buffer(effect_var, values, D3D10_SVT_FLOAT, offset, count);
6487 return S_OK;
6490 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetBoolVectorArray(ID3D10EffectVectorVariable *iface,
6491 BOOL *values, UINT offset, UINT count)
6493 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6495 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6496 read_variable_array_from_buffer(effect_var, values, D3D10_SVT_BOOL, offset, count);
6498 return S_OK;
6501 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetIntVectorArray(ID3D10EffectVectorVariable *iface,
6502 int *values, UINT offset, UINT count)
6504 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6506 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6507 read_variable_array_from_buffer(effect_var, values, D3D10_SVT_INT, offset, count);
6509 return S_OK;
6512 static HRESULT STDMETHODCALLTYPE d3d10_effect_vector_variable_GetFloatVectorArray(ID3D10EffectVectorVariable *iface,
6513 float *values, UINT offset, UINT count)
6515 struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVectorVariable(iface);
6517 TRACE("iface %p, values %p, offset %u, count %u.\n", iface, values, offset, count);
6518 read_variable_array_from_buffer(effect_var, values, D3D10_SVT_FLOAT, offset, count);
6520 return S_OK;
6523 static const struct ID3D10EffectVectorVariableVtbl d3d10_effect_vector_variable_vtbl =
6525 /* ID3D10EffectVariable methods */
6526 d3d10_effect_vector_variable_IsValid,
6527 d3d10_effect_vector_variable_GetType,
6528 d3d10_effect_vector_variable_GetDesc,
6529 d3d10_effect_vector_variable_GetAnnotationByIndex,
6530 d3d10_effect_vector_variable_GetAnnotationByName,
6531 d3d10_effect_vector_variable_GetMemberByIndex,
6532 d3d10_effect_vector_variable_GetMemberByName,
6533 d3d10_effect_vector_variable_GetMemberBySemantic,
6534 d3d10_effect_vector_variable_GetElement,
6535 d3d10_effect_vector_variable_GetParentConstantBuffer,
6536 d3d10_effect_vector_variable_AsScalar,
6537 d3d10_effect_vector_variable_AsVector,
6538 d3d10_effect_vector_variable_AsMatrix,
6539 d3d10_effect_vector_variable_AsString,
6540 d3d10_effect_vector_variable_AsShaderResource,
6541 d3d10_effect_vector_variable_AsRenderTargetView,
6542 d3d10_effect_vector_variable_AsDepthStencilView,
6543 d3d10_effect_vector_variable_AsConstantBuffer,
6544 d3d10_effect_vector_variable_AsShader,
6545 d3d10_effect_vector_variable_AsBlend,
6546 d3d10_effect_vector_variable_AsDepthStencil,
6547 d3d10_effect_vector_variable_AsRasterizer,
6548 d3d10_effect_vector_variable_AsSampler,
6549 d3d10_effect_vector_variable_SetRawValue,
6550 d3d10_effect_vector_variable_GetRawValue,
6551 /* ID3D10EffectVectorVariable methods */
6552 d3d10_effect_vector_variable_SetBoolVector,
6553 d3d10_effect_vector_variable_SetIntVector,
6554 d3d10_effect_vector_variable_SetFloatVector,
6555 d3d10_effect_vector_variable_GetBoolVector,
6556 d3d10_effect_vector_variable_GetIntVector,
6557 d3d10_effect_vector_variable_GetFloatVector,
6558 d3d10_effect_vector_variable_SetBoolVectorArray,
6559 d3d10_effect_vector_variable_SetIntVectorArray,
6560 d3d10_effect_vector_variable_SetFloatVectorArray,
6561 d3d10_effect_vector_variable_GetBoolVectorArray,
6562 d3d10_effect_vector_variable_GetIntVectorArray,
6563 d3d10_effect_vector_variable_GetFloatVectorArray,
6566 static void write_matrix_to_buffer(struct d3d10_effect_variable *variable, void *dst_void,
6567 struct d3d10_matrix *src, BOOL transpose)
6569 unsigned int col_count = !transpose ? variable->type->column_count : variable->type->row_count;
6570 unsigned int row_count = !transpose ? variable->type->row_count : variable->type->column_count;
6571 BOOL major = variable->type->type_class == D3D10_SVC_MATRIX_COLUMNS;
6572 float *dst = dst_void;
6573 unsigned int row, col;
6575 if (transpose)
6576 major = !major;
6578 if (major)
6580 for (col = 0; col < col_count; ++col)
6582 for (row = 0; row < row_count; ++row)
6583 dst[(col * 4) + row] = src->m[row][col];
6586 else
6588 for (row = 0; row < row_count; ++row)
6590 for (col = 0; col < col_count; ++col)
6591 dst[(row * 4) + col] = src->m[row][col];
6596 static void write_matrix_variable_to_buffer(struct d3d10_effect_variable *variable, void *src_data, BOOL transpose)
6598 BYTE *dst = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
6600 write_matrix_to_buffer(variable, dst, src_data, transpose);
6602 variable->buffer->u.buffer.changed = TRUE;
6605 static void write_matrix_variable_array_to_buffer(struct d3d10_effect_variable *variable, void *src_data,
6606 unsigned int offset, unsigned int count, BOOL transpose)
6608 BYTE *dst = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
6609 struct d3d10_matrix *src = src_data;
6610 unsigned int i;
6612 if (!variable->type->element_count)
6614 write_matrix_variable_to_buffer(variable, src_data, transpose);
6615 return;
6618 if (offset >= variable->type->element_count)
6620 WARN("Offset %u larger than element count %u, ignoring.\n", offset, variable->type->element_count);
6621 return;
6624 if (count > variable->type->element_count - offset)
6626 WARN("Offset %u, count %u overruns the variable (element count %u), fixing up.\n",
6627 offset, count, variable->type->element_count);
6628 count = variable->type->element_count - offset;
6631 if (offset)
6632 dst += variable->type->stride * offset;
6634 for (i = 0; i < count; ++i)
6636 write_matrix_to_buffer(variable, dst, &src[i], transpose);
6638 dst += variable->type->stride;
6641 variable->buffer->u.buffer.changed = TRUE;
6644 static void read_matrix_from_buffer(struct d3d10_effect_variable *variable, void *src_void,
6645 struct d3d10_matrix *dst, BOOL transpose)
6647 unsigned int col_count = !transpose ? variable->type->column_count : variable->type->row_count;
6648 unsigned int row_count = !transpose ? variable->type->row_count : variable->type->column_count;
6649 BOOL major = variable->type->type_class == D3D10_SVC_MATRIX_COLUMNS;
6650 float *src = src_void;
6651 unsigned int row, col;
6653 if (transpose)
6654 major = !major;
6656 if (major)
6658 for (col = 0; col < col_count; ++col)
6660 for (row = 0; row < row_count; ++row)
6661 dst->m[row][col] = src[(col * 4) + row];
6664 else
6666 for (row = 0; row < row_count; ++row)
6668 for (col = 0; col < col_count; ++col)
6669 dst->m[row][col] = src[(row * 4) + col];
6674 static void read_matrix_variable_from_buffer(struct d3d10_effect_variable *variable, void *dst, BOOL transpose)
6676 BYTE *src = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
6678 read_matrix_from_buffer(variable, src, dst, transpose);
6681 static void read_matrix_variable_array_from_buffer(struct d3d10_effect_variable *variable, void *dst_data, UINT offset,
6682 UINT count, BOOL transpose)
6684 BYTE *src = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
6685 struct d3d10_matrix *dst = dst_data;
6686 unsigned int i;
6688 if (!variable->type->element_count)
6690 read_matrix_variable_from_buffer(variable, dst_data, transpose);
6691 return;
6694 if (offset >= variable->type->element_count)
6696 WARN("Offset %u larger than element count %u, ignoring.\n", offset, variable->type->element_count);
6697 return;
6700 if (count > variable->type->element_count - offset)
6702 WARN("Offset %u, count %u overruns the variable (element count %u), fixing up.\n",
6703 offset, count, variable->type->element_count);
6704 count = variable->type->element_count - offset;
6707 if (offset)
6708 src += variable->type->stride * offset;
6710 for (i = 0; i < count; ++i)
6712 read_matrix_from_buffer(variable, src, &dst[i], transpose);
6714 src += variable->type->stride;
6718 /* ID3D10EffectVariable methods */
6720 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectMatrixVariable(ID3D10EffectMatrixVariable *iface)
6722 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
6725 static BOOL STDMETHODCALLTYPE d3d10_effect_matrix_variable_IsValid(ID3D10EffectMatrixVariable *iface)
6727 struct d3d10_effect_variable *v = impl_from_ID3D10EffectMatrixVariable(iface);
6729 TRACE("iface %p\n", iface);
6731 return v != &null_matrix_variable;
6734 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetType(
6735 ID3D10EffectMatrixVariable *iface)
6737 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
6740 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetDesc(ID3D10EffectMatrixVariable *iface,
6741 D3D10_EFFECT_VARIABLE_DESC *desc)
6743 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
6746 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetAnnotationByIndex(
6747 ID3D10EffectMatrixVariable *iface, UINT index)
6749 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
6752 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetAnnotationByName(
6753 ID3D10EffectMatrixVariable *iface, const char *name)
6755 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
6758 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMemberByIndex(
6759 ID3D10EffectMatrixVariable *iface, UINT index)
6761 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
6764 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMemberByName(
6765 ID3D10EffectMatrixVariable *iface, const char *name)
6767 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
6770 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMemberBySemantic(
6771 ID3D10EffectMatrixVariable *iface, const char *semantic)
6773 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
6776 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetElement(
6777 ID3D10EffectMatrixVariable *iface, UINT index)
6779 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
6782 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetParentConstantBuffer(
6783 ID3D10EffectMatrixVariable *iface)
6785 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
6788 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsScalar(
6789 ID3D10EffectMatrixVariable *iface)
6791 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
6794 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsVector(
6795 ID3D10EffectMatrixVariable *iface)
6797 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
6800 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsMatrix(
6801 ID3D10EffectMatrixVariable *iface)
6803 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
6806 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsString(
6807 ID3D10EffectMatrixVariable *iface)
6809 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
6812 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsShaderResource(
6813 ID3D10EffectMatrixVariable *iface)
6815 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
6818 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsRenderTargetView(
6819 ID3D10EffectMatrixVariable *iface)
6821 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
6824 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsDepthStencilView(
6825 ID3D10EffectMatrixVariable *iface)
6827 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
6830 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsConstantBuffer(
6831 ID3D10EffectMatrixVariable *iface)
6833 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
6836 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsShader(
6837 ID3D10EffectMatrixVariable *iface)
6839 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
6842 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsBlend(
6843 ID3D10EffectMatrixVariable *iface)
6845 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
6848 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsDepthStencil(
6849 ID3D10EffectMatrixVariable *iface)
6851 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
6854 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsRasterizer(
6855 ID3D10EffectMatrixVariable *iface)
6857 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
6860 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_matrix_variable_AsSampler(
6861 ID3D10EffectMatrixVariable *iface)
6863 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
6866 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetRawValue(ID3D10EffectMatrixVariable *iface,
6867 void *data, UINT offset, UINT count)
6869 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
6872 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetRawValue(ID3D10EffectMatrixVariable *iface,
6873 void *data, UINT offset, UINT count)
6875 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
6878 /* ID3D10EffectMatrixVariable methods */
6880 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrix(ID3D10EffectMatrixVariable *iface,
6881 float *data)
6883 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6885 TRACE("iface %p, data %p.\n", iface, data);
6886 write_matrix_variable_to_buffer(var, data, FALSE);
6888 return S_OK;
6891 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrix(ID3D10EffectMatrixVariable *iface,
6892 float *data)
6894 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6896 TRACE("iface %p, data %p.\n", iface, data);
6897 read_matrix_variable_from_buffer(var, data, FALSE);
6899 return S_OK;
6902 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixArray(ID3D10EffectMatrixVariable *iface,
6903 float *data, UINT offset, UINT count)
6905 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6907 TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count);
6908 write_matrix_variable_array_to_buffer(var, data, offset, count, FALSE);
6910 return S_OK;
6913 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixArray(ID3D10EffectMatrixVariable *iface,
6914 float *data, UINT offset, UINT count)
6916 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6918 TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count);
6919 read_matrix_variable_array_from_buffer(var, data, offset, count, FALSE);
6921 return S_OK;
6924 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTranspose(ID3D10EffectMatrixVariable *iface,
6925 float *data)
6927 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6929 TRACE("iface %p, data %p.\n", iface, data);
6930 write_matrix_variable_to_buffer(var, data, TRUE);
6932 return S_OK;
6935 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTranspose(ID3D10EffectMatrixVariable *iface,
6936 float *data)
6938 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6940 TRACE("iface %p, data %p.\n", iface, data);
6941 read_matrix_variable_from_buffer(var, data, TRUE);
6943 return S_OK;
6946 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTransposeArray(ID3D10EffectMatrixVariable *iface,
6947 float *data, UINT offset, UINT count)
6949 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6951 TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count);
6952 write_matrix_variable_array_to_buffer(var, data, offset, count, TRUE);
6954 return S_OK;
6957 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTransposeArray(ID3D10EffectMatrixVariable *iface,
6958 float *data, UINT offset, UINT count)
6960 struct d3d10_effect_variable *var = impl_from_ID3D10EffectMatrixVariable(iface);
6962 TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count);
6963 read_matrix_variable_array_from_buffer(var, data, offset, count, TRUE);
6965 return S_OK;
6969 static const struct ID3D10EffectMatrixVariableVtbl d3d10_effect_matrix_variable_vtbl =
6971 /* ID3D10EffectVariable methods */
6972 d3d10_effect_matrix_variable_IsValid,
6973 d3d10_effect_matrix_variable_GetType,
6974 d3d10_effect_matrix_variable_GetDesc,
6975 d3d10_effect_matrix_variable_GetAnnotationByIndex,
6976 d3d10_effect_matrix_variable_GetAnnotationByName,
6977 d3d10_effect_matrix_variable_GetMemberByIndex,
6978 d3d10_effect_matrix_variable_GetMemberByName,
6979 d3d10_effect_matrix_variable_GetMemberBySemantic,
6980 d3d10_effect_matrix_variable_GetElement,
6981 d3d10_effect_matrix_variable_GetParentConstantBuffer,
6982 d3d10_effect_matrix_variable_AsScalar,
6983 d3d10_effect_matrix_variable_AsVector,
6984 d3d10_effect_matrix_variable_AsMatrix,
6985 d3d10_effect_matrix_variable_AsString,
6986 d3d10_effect_matrix_variable_AsShaderResource,
6987 d3d10_effect_matrix_variable_AsRenderTargetView,
6988 d3d10_effect_matrix_variable_AsDepthStencilView,
6989 d3d10_effect_matrix_variable_AsConstantBuffer,
6990 d3d10_effect_matrix_variable_AsShader,
6991 d3d10_effect_matrix_variable_AsBlend,
6992 d3d10_effect_matrix_variable_AsDepthStencil,
6993 d3d10_effect_matrix_variable_AsRasterizer,
6994 d3d10_effect_matrix_variable_AsSampler,
6995 d3d10_effect_matrix_variable_SetRawValue,
6996 d3d10_effect_matrix_variable_GetRawValue,
6997 /* ID3D10EffectMatrixVariable methods */
6998 d3d10_effect_matrix_variable_SetMatrix,
6999 d3d10_effect_matrix_variable_GetMatrix,
7000 d3d10_effect_matrix_variable_SetMatrixArray,
7001 d3d10_effect_matrix_variable_GetMatrixArray,
7002 d3d10_effect_matrix_variable_SetMatrixTranspose,
7003 d3d10_effect_matrix_variable_GetMatrixTranspose,
7004 d3d10_effect_matrix_variable_SetMatrixTransposeArray,
7005 d3d10_effect_matrix_variable_GetMatrixTransposeArray,
7008 /* ID3D10EffectVariable methods */
7010 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectStringVariable(ID3D10EffectStringVariable *iface)
7012 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
7015 static BOOL STDMETHODCALLTYPE d3d10_effect_string_variable_IsValid(ID3D10EffectStringVariable *iface)
7017 struct d3d10_effect_variable *v = impl_from_ID3D10EffectStringVariable(iface);
7019 TRACE("iface %p\n", iface);
7021 return v != &null_string_variable;
7024 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_string_variable_GetType(
7025 ID3D10EffectStringVariable *iface)
7027 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
7030 static HRESULT STDMETHODCALLTYPE d3d10_effect_string_variable_GetDesc(ID3D10EffectStringVariable *iface,
7031 D3D10_EFFECT_VARIABLE_DESC *desc)
7033 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
7036 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_GetAnnotationByIndex(
7037 ID3D10EffectStringVariable *iface, UINT index)
7039 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
7042 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_GetAnnotationByName(
7043 ID3D10EffectStringVariable *iface, const char *name)
7045 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
7048 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_GetMemberByIndex(
7049 ID3D10EffectStringVariable *iface, UINT index)
7051 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
7054 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_GetMemberByName(
7055 ID3D10EffectStringVariable *iface, const char *name)
7057 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
7060 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_GetMemberBySemantic(
7061 ID3D10EffectStringVariable *iface, const char *semantic)
7063 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
7066 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_GetElement(
7067 ID3D10EffectStringVariable *iface, UINT index)
7069 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
7072 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_string_variable_GetParentConstantBuffer(
7073 ID3D10EffectStringVariable *iface)
7075 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
7078 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsScalar(
7079 ID3D10EffectStringVariable *iface)
7081 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
7084 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsVector(
7085 ID3D10EffectStringVariable *iface)
7087 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
7090 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsMatrix(
7091 ID3D10EffectStringVariable *iface)
7093 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
7096 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsString(
7097 ID3D10EffectStringVariable *iface)
7099 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
7102 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsShaderResource(
7103 ID3D10EffectStringVariable *iface)
7105 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
7108 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsRenderTargetView(
7109 ID3D10EffectStringVariable *iface)
7111 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
7114 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsDepthStencilView(
7115 ID3D10EffectStringVariable *iface)
7117 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
7120 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_string_variable_AsConstantBuffer(
7121 ID3D10EffectStringVariable *iface)
7123 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
7126 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsShader(
7127 ID3D10EffectStringVariable *iface)
7129 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
7132 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsBlend(
7133 ID3D10EffectStringVariable *iface)
7135 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
7138 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsDepthStencil(
7139 ID3D10EffectStringVariable *iface)
7141 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
7144 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsRasterizer(
7145 ID3D10EffectStringVariable *iface)
7147 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
7150 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_string_variable_AsSampler(
7151 ID3D10EffectStringVariable *iface)
7153 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
7156 static HRESULT STDMETHODCALLTYPE d3d10_effect_string_variable_SetRawValue(ID3D10EffectStringVariable *iface,
7157 void *data, UINT offset, UINT count)
7159 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7162 static HRESULT STDMETHODCALLTYPE d3d10_effect_string_variable_GetRawValue(ID3D10EffectStringVariable *iface,
7163 void *data, UINT offset, UINT count)
7165 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7168 /* ID3D10EffectStringVariable methods */
7170 static HRESULT STDMETHODCALLTYPE d3d10_effect_string_variable_GetString(ID3D10EffectStringVariable *iface,
7171 const char **str)
7173 struct d3d10_effect_variable *var = impl_from_ID3D10EffectStringVariable(iface);
7174 char *value = (char *)var->u.buffer.local_buffer;
7176 TRACE("iface %p, str %p.\n", iface, str);
7178 if (!value)
7179 return E_FAIL;
7181 if (!str)
7182 return E_INVALIDARG;
7184 *str = value;
7186 return S_OK;
7189 static HRESULT STDMETHODCALLTYPE d3d10_effect_string_variable_GetStringArray(ID3D10EffectStringVariable *iface,
7190 const char **strs, UINT offset, UINT count)
7192 FIXME("iface %p, strs %p, offset %u, count %u stub!\n", iface, strs, offset, count);
7194 return E_NOTIMPL;
7198 static const struct ID3D10EffectStringVariableVtbl d3d10_effect_string_variable_vtbl =
7200 /* ID3D10EffectVariable methods */
7201 d3d10_effect_string_variable_IsValid,
7202 d3d10_effect_string_variable_GetType,
7203 d3d10_effect_string_variable_GetDesc,
7204 d3d10_effect_string_variable_GetAnnotationByIndex,
7205 d3d10_effect_string_variable_GetAnnotationByName,
7206 d3d10_effect_string_variable_GetMemberByIndex,
7207 d3d10_effect_string_variable_GetMemberByName,
7208 d3d10_effect_string_variable_GetMemberBySemantic,
7209 d3d10_effect_string_variable_GetElement,
7210 d3d10_effect_string_variable_GetParentConstantBuffer,
7211 d3d10_effect_string_variable_AsScalar,
7212 d3d10_effect_string_variable_AsVector,
7213 d3d10_effect_string_variable_AsMatrix,
7214 d3d10_effect_string_variable_AsString,
7215 d3d10_effect_string_variable_AsShaderResource,
7216 d3d10_effect_string_variable_AsRenderTargetView,
7217 d3d10_effect_string_variable_AsDepthStencilView,
7218 d3d10_effect_string_variable_AsConstantBuffer,
7219 d3d10_effect_string_variable_AsShader,
7220 d3d10_effect_string_variable_AsBlend,
7221 d3d10_effect_string_variable_AsDepthStencil,
7222 d3d10_effect_string_variable_AsRasterizer,
7223 d3d10_effect_string_variable_AsSampler,
7224 d3d10_effect_string_variable_SetRawValue,
7225 d3d10_effect_string_variable_GetRawValue,
7226 /* ID3D10EffectStringVariable methods */
7227 d3d10_effect_string_variable_GetString,
7228 d3d10_effect_string_variable_GetStringArray,
7231 static void set_shader_resource_variable(ID3D10ShaderResourceView **src, ID3D10ShaderResourceView **dst)
7233 if (*dst == *src)
7234 return;
7236 if (*src)
7237 ID3D10ShaderResourceView_AddRef(*src);
7238 if (*dst)
7239 ID3D10ShaderResourceView_Release(*dst);
7241 *dst = *src;
7244 /* ID3D10EffectVariable methods */
7246 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectShaderResourceVariable(
7247 ID3D10EffectShaderResourceVariable *iface)
7249 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
7252 static BOOL STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_IsValid(ID3D10EffectShaderResourceVariable *iface)
7254 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderResourceVariable(iface);
7256 TRACE("iface %p.\n", iface);
7258 return v != &null_shader_resource_variable;
7261 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetType(
7262 ID3D10EffectShaderResourceVariable *iface)
7264 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
7267 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetDesc(
7268 ID3D10EffectShaderResourceVariable *iface, D3D10_EFFECT_VARIABLE_DESC *desc)
7270 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
7273 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetAnnotationByIndex(
7274 ID3D10EffectShaderResourceVariable *iface, UINT index)
7276 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
7279 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetAnnotationByName(
7280 ID3D10EffectShaderResourceVariable *iface, const char *name)
7282 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
7285 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetMemberByIndex(
7286 ID3D10EffectShaderResourceVariable *iface, UINT index)
7288 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
7291 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetMemberByName(
7292 ID3D10EffectShaderResourceVariable *iface, const char *name)
7294 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
7297 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetMemberBySemantic(
7298 ID3D10EffectShaderResourceVariable *iface, const char *semantic)
7300 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
7303 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetElement(
7304 ID3D10EffectShaderResourceVariable *iface, UINT index)
7306 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
7309 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetParentConstantBuffer(
7310 ID3D10EffectShaderResourceVariable *iface)
7312 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
7315 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsScalar(
7316 ID3D10EffectShaderResourceVariable *iface)
7318 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
7321 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsVector(
7322 ID3D10EffectShaderResourceVariable *iface)
7324 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
7327 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsMatrix(
7328 ID3D10EffectShaderResourceVariable *iface)
7330 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
7333 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsString(
7334 ID3D10EffectShaderResourceVariable *iface)
7336 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
7339 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsShaderResource(
7340 ID3D10EffectShaderResourceVariable *iface)
7342 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
7345 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsRenderTargetView(
7346 ID3D10EffectShaderResourceVariable *iface)
7348 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
7351 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsDepthStencilView(
7352 ID3D10EffectShaderResourceVariable *iface)
7354 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
7357 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsConstantBuffer(
7358 ID3D10EffectShaderResourceVariable *iface)
7360 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
7363 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsShader(
7364 ID3D10EffectShaderResourceVariable *iface)
7366 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
7369 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsBlend(
7370 ID3D10EffectShaderResourceVariable *iface)
7372 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
7375 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsDepthStencil(
7376 ID3D10EffectShaderResourceVariable *iface)
7378 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
7381 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsRasterizer(
7382 ID3D10EffectShaderResourceVariable *iface)
7384 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
7387 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_AsSampler(
7388 ID3D10EffectShaderResourceVariable *iface)
7390 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
7393 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_SetRawValue(
7394 ID3D10EffectShaderResourceVariable *iface, void *data, UINT offset, UINT count)
7396 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7399 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetRawValue(
7400 ID3D10EffectShaderResourceVariable *iface, void *data, UINT offset, UINT count)
7402 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7405 /* ID3D10EffectShaderResourceVariable methods */
7407 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_SetResource(
7408 ID3D10EffectShaderResourceVariable *iface, ID3D10ShaderResourceView *resource)
7410 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderResourceVariable(iface);
7412 TRACE("iface %p, resource %p.\n", iface, resource);
7414 if (!d3d10_effect_shader_resource_variable_IsValid(iface))
7415 return E_FAIL;
7417 set_shader_resource_variable(&resource, v->u.resource.srv);
7419 return S_OK;
7422 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetResource(
7423 ID3D10EffectShaderResourceVariable *iface, ID3D10ShaderResourceView **resource)
7425 FIXME("iface %p, resource %p stub!\n", iface, resource);
7427 return E_NOTIMPL;
7430 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_SetResourceArray(
7431 ID3D10EffectShaderResourceVariable *iface, ID3D10ShaderResourceView **resources, UINT offset, UINT count)
7433 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderResourceVariable(iface);
7434 ID3D10ShaderResourceView **rsrc_view;
7435 unsigned int i;
7437 TRACE("iface %p, resources %p, offset %u, count %u.\n", iface, resources, offset, count);
7439 if (!v->type->element_count)
7440 return d3d10_effect_shader_resource_variable_SetResource(iface, *resources);
7442 if (offset >= v->type->element_count)
7444 WARN("Offset %u larger than element count %u, ignoring.\n", offset, v->type->element_count);
7445 return S_OK;
7448 if (count > v->type->element_count - offset)
7450 WARN("Offset %u, count %u overruns the variable (element count %u), fixing up.\n",
7451 offset, count, v->type->element_count);
7452 count = v->type->element_count - offset;
7455 rsrc_view = &v->u.resource.srv[offset];
7456 for (i = 0; i < count; ++i)
7457 set_shader_resource_variable(&resources[i], &rsrc_view[i]);
7459 return S_OK;
7462 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_resource_variable_GetResourceArray(
7463 ID3D10EffectShaderResourceVariable *iface, ID3D10ShaderResourceView **resources, UINT offset, UINT count)
7465 FIXME("iface %p, resources %p, offset %u, count %u stub!\n", iface, resources, offset, count);
7467 return E_NOTIMPL;
7471 static const struct ID3D10EffectShaderResourceVariableVtbl d3d10_effect_shader_resource_variable_vtbl =
7473 /* ID3D10EffectVariable methods */
7474 d3d10_effect_shader_resource_variable_IsValid,
7475 d3d10_effect_shader_resource_variable_GetType,
7476 d3d10_effect_shader_resource_variable_GetDesc,
7477 d3d10_effect_shader_resource_variable_GetAnnotationByIndex,
7478 d3d10_effect_shader_resource_variable_GetAnnotationByName,
7479 d3d10_effect_shader_resource_variable_GetMemberByIndex,
7480 d3d10_effect_shader_resource_variable_GetMemberByName,
7481 d3d10_effect_shader_resource_variable_GetMemberBySemantic,
7482 d3d10_effect_shader_resource_variable_GetElement,
7483 d3d10_effect_shader_resource_variable_GetParentConstantBuffer,
7484 d3d10_effect_shader_resource_variable_AsScalar,
7485 d3d10_effect_shader_resource_variable_AsVector,
7486 d3d10_effect_shader_resource_variable_AsMatrix,
7487 d3d10_effect_shader_resource_variable_AsString,
7488 d3d10_effect_shader_resource_variable_AsShaderResource,
7489 d3d10_effect_shader_resource_variable_AsRenderTargetView,
7490 d3d10_effect_shader_resource_variable_AsDepthStencilView,
7491 d3d10_effect_shader_resource_variable_AsConstantBuffer,
7492 d3d10_effect_shader_resource_variable_AsShader,
7493 d3d10_effect_shader_resource_variable_AsBlend,
7494 d3d10_effect_shader_resource_variable_AsDepthStencil,
7495 d3d10_effect_shader_resource_variable_AsRasterizer,
7496 d3d10_effect_shader_resource_variable_AsSampler,
7497 d3d10_effect_shader_resource_variable_SetRawValue,
7498 d3d10_effect_shader_resource_variable_GetRawValue,
7499 /* ID3D10EffectShaderResourceVariable methods */
7500 d3d10_effect_shader_resource_variable_SetResource,
7501 d3d10_effect_shader_resource_variable_GetResource,
7502 d3d10_effect_shader_resource_variable_SetResourceArray,
7503 d3d10_effect_shader_resource_variable_GetResourceArray,
7506 /* ID3D10EffectVariable methods */
7508 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectRenderTargetViewVariable(
7509 ID3D10EffectRenderTargetViewVariable *iface)
7511 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
7514 static BOOL STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_IsValid(
7515 ID3D10EffectRenderTargetViewVariable *iface)
7517 struct d3d10_effect_variable *v = impl_from_ID3D10EffectRenderTargetViewVariable(iface);
7519 TRACE("iface %p\n", iface);
7521 return v != &null_render_target_view_variable;
7524 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetType(
7525 ID3D10EffectRenderTargetViewVariable *iface)
7527 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
7530 static HRESULT STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetDesc(
7531 ID3D10EffectRenderTargetViewVariable *iface, D3D10_EFFECT_VARIABLE_DESC *desc)
7533 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
7536 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetAnnotationByIndex(
7537 ID3D10EffectRenderTargetViewVariable *iface, UINT index)
7539 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
7542 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetAnnotationByName(
7543 ID3D10EffectRenderTargetViewVariable *iface, const char *name)
7545 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
7548 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetMemberByIndex(
7549 ID3D10EffectRenderTargetViewVariable *iface, UINT index)
7551 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
7554 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetMemberByName(
7555 ID3D10EffectRenderTargetViewVariable *iface, const char *name)
7557 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
7560 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetMemberBySemantic(
7561 ID3D10EffectRenderTargetViewVariable *iface, const char *semantic)
7563 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
7566 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetElement(
7567 ID3D10EffectRenderTargetViewVariable *iface, UINT index)
7569 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
7572 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetParentConstantBuffer(
7573 ID3D10EffectRenderTargetViewVariable *iface)
7575 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
7578 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsScalar(
7579 ID3D10EffectRenderTargetViewVariable *iface)
7581 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
7584 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsVector(
7585 ID3D10EffectRenderTargetViewVariable *iface)
7587 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
7590 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsMatrix(
7591 ID3D10EffectRenderTargetViewVariable *iface)
7593 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
7596 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsString(
7597 ID3D10EffectRenderTargetViewVariable *iface)
7599 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
7602 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsShaderResource(
7603 ID3D10EffectRenderTargetViewVariable *iface)
7605 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
7608 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsRenderTargetView(
7609 ID3D10EffectRenderTargetViewVariable *iface)
7611 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
7614 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsDepthStencilView(
7615 ID3D10EffectRenderTargetViewVariable *iface)
7617 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
7620 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsConstantBuffer(
7621 ID3D10EffectRenderTargetViewVariable *iface)
7623 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
7626 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsShader(
7627 ID3D10EffectRenderTargetViewVariable *iface)
7629 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
7632 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsBlend(
7633 ID3D10EffectRenderTargetViewVariable *iface)
7635 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
7638 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsDepthStencil(
7639 ID3D10EffectRenderTargetViewVariable *iface)
7641 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
7644 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsRasterizer(
7645 ID3D10EffectRenderTargetViewVariable *iface)
7647 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
7650 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_AsSampler(
7651 ID3D10EffectRenderTargetViewVariable *iface)
7653 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
7656 static HRESULT STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_SetRawValue(
7657 ID3D10EffectRenderTargetViewVariable *iface, void *data, UINT offset, UINT count)
7659 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7662 static HRESULT STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetRawValue(
7663 ID3D10EffectRenderTargetViewVariable *iface, void *data, UINT offset, UINT count)
7665 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7668 /* ID3D10EffectRenderTargetViewVariable methods */
7670 static HRESULT STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_SetRenderTarget(
7671 ID3D10EffectRenderTargetViewVariable *iface, ID3D10RenderTargetView *view)
7673 FIXME("iface %p, view %p stub!\n", iface, view);
7675 return E_NOTIMPL;
7678 static HRESULT STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetRenderTarget(
7679 ID3D10EffectRenderTargetViewVariable *iface, ID3D10RenderTargetView **view)
7681 FIXME("iface %p, view %p stub!\n", iface, view);
7683 return E_NOTIMPL;
7686 static HRESULT STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_SetRenderTargetArray(
7687 ID3D10EffectRenderTargetViewVariable *iface, ID3D10RenderTargetView **views, UINT offset, UINT count)
7689 FIXME("iface %p, views %p, offset %u, count %u stub!\n", iface, views, offset, count);
7691 return E_NOTIMPL;
7694 static HRESULT STDMETHODCALLTYPE d3d10_effect_render_target_view_variable_GetRenderTargetArray(
7695 ID3D10EffectRenderTargetViewVariable *iface, ID3D10RenderTargetView **views, UINT offset, UINT count)
7697 FIXME("iface %p, views %p, offset %u, count %u stub!\n", iface, views, offset, count);
7699 return E_NOTIMPL;
7703 static const struct ID3D10EffectRenderTargetViewVariableVtbl d3d10_effect_render_target_view_variable_vtbl =
7705 /* ID3D10EffectVariable methods */
7706 d3d10_effect_render_target_view_variable_IsValid,
7707 d3d10_effect_render_target_view_variable_GetType,
7708 d3d10_effect_render_target_view_variable_GetDesc,
7709 d3d10_effect_render_target_view_variable_GetAnnotationByIndex,
7710 d3d10_effect_render_target_view_variable_GetAnnotationByName,
7711 d3d10_effect_render_target_view_variable_GetMemberByIndex,
7712 d3d10_effect_render_target_view_variable_GetMemberByName,
7713 d3d10_effect_render_target_view_variable_GetMemberBySemantic,
7714 d3d10_effect_render_target_view_variable_GetElement,
7715 d3d10_effect_render_target_view_variable_GetParentConstantBuffer,
7716 d3d10_effect_render_target_view_variable_AsScalar,
7717 d3d10_effect_render_target_view_variable_AsVector,
7718 d3d10_effect_render_target_view_variable_AsMatrix,
7719 d3d10_effect_render_target_view_variable_AsString,
7720 d3d10_effect_render_target_view_variable_AsShaderResource,
7721 d3d10_effect_render_target_view_variable_AsRenderTargetView,
7722 d3d10_effect_render_target_view_variable_AsDepthStencilView,
7723 d3d10_effect_render_target_view_variable_AsConstantBuffer,
7724 d3d10_effect_render_target_view_variable_AsShader,
7725 d3d10_effect_render_target_view_variable_AsBlend,
7726 d3d10_effect_render_target_view_variable_AsDepthStencil,
7727 d3d10_effect_render_target_view_variable_AsRasterizer,
7728 d3d10_effect_render_target_view_variable_AsSampler,
7729 d3d10_effect_render_target_view_variable_SetRawValue,
7730 d3d10_effect_render_target_view_variable_GetRawValue,
7731 /* ID3D10EffectRenderTargetViewVariable methods */
7732 d3d10_effect_render_target_view_variable_SetRenderTarget,
7733 d3d10_effect_render_target_view_variable_GetRenderTarget,
7734 d3d10_effect_render_target_view_variable_SetRenderTargetArray,
7735 d3d10_effect_render_target_view_variable_GetRenderTargetArray,
7738 /* ID3D10EffectVariable methods */
7740 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectDepthStencilViewVariable(
7741 ID3D10EffectDepthStencilViewVariable *iface)
7743 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
7746 static BOOL STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_IsValid(
7747 ID3D10EffectDepthStencilViewVariable *iface)
7749 struct d3d10_effect_variable *v = impl_from_ID3D10EffectDepthStencilViewVariable(iface);
7751 TRACE("iface %p\n", iface);
7753 return v != &null_depth_stencil_view_variable;
7756 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetType(
7757 ID3D10EffectDepthStencilViewVariable *iface)
7759 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
7762 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetDesc(
7763 ID3D10EffectDepthStencilViewVariable *iface, D3D10_EFFECT_VARIABLE_DESC *desc)
7765 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
7768 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetAnnotationByIndex(
7769 ID3D10EffectDepthStencilViewVariable *iface, UINT index)
7771 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
7774 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetAnnotationByName(
7775 ID3D10EffectDepthStencilViewVariable *iface, const char *name)
7777 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
7780 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetMemberByIndex(
7781 ID3D10EffectDepthStencilViewVariable *iface, UINT index)
7783 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
7786 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetMemberByName(
7787 ID3D10EffectDepthStencilViewVariable *iface, const char *name)
7789 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
7792 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetMemberBySemantic(
7793 ID3D10EffectDepthStencilViewVariable *iface, const char *semantic)
7795 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
7798 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetElement(
7799 ID3D10EffectDepthStencilViewVariable *iface, UINT index)
7801 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
7804 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetParentConstantBuffer(
7805 ID3D10EffectDepthStencilViewVariable *iface)
7807 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
7810 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsScalar(
7811 ID3D10EffectDepthStencilViewVariable *iface)
7813 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
7816 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsVector(
7817 ID3D10EffectDepthStencilViewVariable *iface)
7819 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
7822 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsMatrix(
7823 ID3D10EffectDepthStencilViewVariable *iface)
7825 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
7828 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsString(
7829 ID3D10EffectDepthStencilViewVariable *iface)
7831 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
7834 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsShaderResource(
7835 ID3D10EffectDepthStencilViewVariable *iface)
7837 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
7840 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsRenderTargetView(
7841 ID3D10EffectDepthStencilViewVariable *iface)
7843 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
7846 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsDepthStencilView(
7847 ID3D10EffectDepthStencilViewVariable *iface)
7849 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
7852 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsConstantBuffer(
7853 ID3D10EffectDepthStencilViewVariable *iface)
7855 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
7858 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsShader(
7859 ID3D10EffectDepthStencilViewVariable *iface)
7861 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
7864 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsBlend(
7865 ID3D10EffectDepthStencilViewVariable *iface)
7867 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
7870 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsDepthStencil(
7871 ID3D10EffectDepthStencilViewVariable *iface)
7873 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
7876 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsRasterizer(
7877 ID3D10EffectDepthStencilViewVariable *iface)
7879 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
7882 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_AsSampler(
7883 ID3D10EffectDepthStencilViewVariable *iface)
7885 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
7888 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_SetRawValue(
7889 ID3D10EffectDepthStencilViewVariable *iface, void *data, UINT offset, UINT count)
7891 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7894 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetRawValue(
7895 ID3D10EffectDepthStencilViewVariable *iface, void *data, UINT offset, UINT count)
7897 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
7900 /* ID3D10EffectDepthStencilViewVariable methods */
7902 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_SetDepthStencil(
7903 ID3D10EffectDepthStencilViewVariable *iface, ID3D10DepthStencilView *view)
7905 FIXME("iface %p, view %p stub!\n", iface, view);
7907 return E_NOTIMPL;
7910 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetDepthStencil(
7911 ID3D10EffectDepthStencilViewVariable *iface, ID3D10DepthStencilView **view)
7913 FIXME("iface %p, view %p stub!\n", iface, view);
7915 return E_NOTIMPL;
7918 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_SetDepthStencilArray(
7919 ID3D10EffectDepthStencilViewVariable *iface, ID3D10DepthStencilView **views, UINT offset, UINT count)
7921 FIXME("iface %p, views %p, offset %u, count %u stub!\n", iface, views, offset, count);
7923 return E_NOTIMPL;
7926 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_view_variable_GetDepthStencilArray(
7927 ID3D10EffectDepthStencilViewVariable *iface, ID3D10DepthStencilView **views, UINT offset, UINT count)
7929 FIXME("iface %p, views %p, offset %u, count %u stub!\n", iface, views, offset, count);
7931 return E_NOTIMPL;
7935 static const struct ID3D10EffectDepthStencilViewVariableVtbl d3d10_effect_depth_stencil_view_variable_vtbl =
7937 /* ID3D10EffectVariable methods */
7938 d3d10_effect_depth_stencil_view_variable_IsValid,
7939 d3d10_effect_depth_stencil_view_variable_GetType,
7940 d3d10_effect_depth_stencil_view_variable_GetDesc,
7941 d3d10_effect_depth_stencil_view_variable_GetAnnotationByIndex,
7942 d3d10_effect_depth_stencil_view_variable_GetAnnotationByName,
7943 d3d10_effect_depth_stencil_view_variable_GetMemberByIndex,
7944 d3d10_effect_depth_stencil_view_variable_GetMemberByName,
7945 d3d10_effect_depth_stencil_view_variable_GetMemberBySemantic,
7946 d3d10_effect_depth_stencil_view_variable_GetElement,
7947 d3d10_effect_depth_stencil_view_variable_GetParentConstantBuffer,
7948 d3d10_effect_depth_stencil_view_variable_AsScalar,
7949 d3d10_effect_depth_stencil_view_variable_AsVector,
7950 d3d10_effect_depth_stencil_view_variable_AsMatrix,
7951 d3d10_effect_depth_stencil_view_variable_AsString,
7952 d3d10_effect_depth_stencil_view_variable_AsShaderResource,
7953 d3d10_effect_depth_stencil_view_variable_AsRenderTargetView,
7954 d3d10_effect_depth_stencil_view_variable_AsDepthStencilView,
7955 d3d10_effect_depth_stencil_view_variable_AsConstantBuffer,
7956 d3d10_effect_depth_stencil_view_variable_AsShader,
7957 d3d10_effect_depth_stencil_view_variable_AsBlend,
7958 d3d10_effect_depth_stencil_view_variable_AsDepthStencil,
7959 d3d10_effect_depth_stencil_view_variable_AsRasterizer,
7960 d3d10_effect_depth_stencil_view_variable_AsSampler,
7961 d3d10_effect_depth_stencil_view_variable_SetRawValue,
7962 d3d10_effect_depth_stencil_view_variable_GetRawValue,
7963 /* ID3D10EffectDepthStencilViewVariable methods */
7964 d3d10_effect_depth_stencil_view_variable_SetDepthStencil,
7965 d3d10_effect_depth_stencil_view_variable_GetDepthStencil,
7966 d3d10_effect_depth_stencil_view_variable_SetDepthStencilArray,
7967 d3d10_effect_depth_stencil_view_variable_GetDepthStencilArray,
7970 /* ID3D10EffectVariable methods */
7972 static BOOL STDMETHODCALLTYPE d3d10_effect_shader_variable_IsValid(ID3D10EffectShaderVariable *iface)
7974 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderVariable(iface);
7976 TRACE("iface %p\n", iface);
7978 return v != &null_shader_variable;
7981 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetType(
7982 ID3D10EffectShaderVariable *iface)
7984 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
7987 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetDesc(ID3D10EffectShaderVariable *iface,
7988 D3D10_EFFECT_VARIABLE_DESC *desc)
7990 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
7993 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetAnnotationByIndex(
7994 ID3D10EffectShaderVariable *iface, UINT index)
7996 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
7999 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetAnnotationByName(
8000 ID3D10EffectShaderVariable *iface, const char *name)
8002 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
8005 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetMemberByIndex(
8006 ID3D10EffectShaderVariable *iface, UINT index)
8008 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
8011 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetMemberByName(
8012 ID3D10EffectShaderVariable *iface, const char *name)
8014 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
8017 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetMemberBySemantic(
8018 ID3D10EffectShaderVariable *iface, const char *semantic)
8020 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
8023 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetElement(
8024 ID3D10EffectShaderVariable *iface, UINT index)
8026 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
8029 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_shader_variable_GetParentConstantBuffer(
8030 ID3D10EffectShaderVariable *iface)
8032 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
8035 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsScalar(
8036 ID3D10EffectShaderVariable *iface)
8038 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
8041 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsVector(
8042 ID3D10EffectShaderVariable *iface)
8044 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
8047 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsMatrix(
8048 ID3D10EffectShaderVariable *iface)
8050 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
8053 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsString(
8054 ID3D10EffectShaderVariable *iface)
8056 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
8059 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsShaderResource(
8060 ID3D10EffectShaderVariable *iface)
8062 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
8065 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsRenderTargetView(
8066 ID3D10EffectShaderVariable *iface)
8068 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
8071 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsDepthStencilView(
8072 ID3D10EffectShaderVariable *iface)
8074 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
8077 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsConstantBuffer(
8078 ID3D10EffectShaderVariable *iface)
8080 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
8083 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsShader(
8084 ID3D10EffectShaderVariable *iface)
8086 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
8089 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsBlend(
8090 ID3D10EffectShaderVariable *iface)
8092 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
8095 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsDepthStencil(
8096 ID3D10EffectShaderVariable *iface)
8098 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
8101 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsRasterizer(
8102 ID3D10EffectShaderVariable *iface)
8104 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
8107 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_shader_variable_AsSampler(
8108 ID3D10EffectShaderVariable *iface)
8110 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
8113 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_SetRawValue(
8114 ID3D10EffectShaderVariable *iface, void *data, UINT offset, UINT count)
8116 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
8119 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetRawValue(
8120 ID3D10EffectShaderVariable *iface, void *data, UINT offset, UINT count)
8122 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
8125 /* ID3D10EffectShaderVariable methods */
8127 static HRESULT d3d10_get_shader_variable(struct d3d10_effect_variable *v, UINT shader_index,
8128 struct d3d10_effect_shader_variable **s, D3D10_SHADER_VARIABLE_TYPE *basetype)
8130 unsigned int i;
8132 v = d3d10_array_get_element(v, 0);
8134 if (!shader_index)
8136 *s = &v->u.shader;
8137 if (basetype) *basetype = v->type->basetype;
8138 return S_OK;
8141 /* Index is used as an offset from this variable. */
8143 for (i = 0; i < v->effect->shaders.count; ++i)
8145 if (v == v->effect->shaders.v[i]) break;
8148 if (i + shader_index >= v->effect->shaders.count)
8150 WARN("Invalid shader index %u.\n", shader_index);
8151 return E_FAIL;
8154 *s = &v->effect->shaders.v[i + shader_index]->u.shader;
8155 if (basetype) *basetype = v->effect->shaders.v[i + shader_index]->type->basetype;
8157 return S_OK;
8160 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetShaderDesc(
8161 ID3D10EffectShaderVariable *iface, UINT index, D3D10_EFFECT_SHADER_DESC *desc)
8163 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderVariable(iface);
8164 struct d3d10_effect_shader_variable *s;
8165 D3D10_SHADER_DESC shader_desc;
8166 HRESULT hr;
8168 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
8170 if (FAILED(hr = d3d10_get_shader_variable(v, index, &s, NULL)))
8171 return hr;
8173 memset(desc, 0, sizeof(*desc));
8174 if (s->input_signature)
8175 desc->pInputSignature = ID3D10Blob_GetBufferPointer(s->input_signature);
8176 desc->SODecl = s->stream_output_declaration;
8177 desc->IsInline = s->isinline;
8178 if (s->bytecode)
8180 desc->pBytecode = ID3D10Blob_GetBufferPointer(s->bytecode);
8181 desc->BytecodeLength = ID3D10Blob_GetBufferSize(s->bytecode);
8183 if (s->reflection)
8185 if (SUCCEEDED(hr = s->reflection->lpVtbl->GetDesc(s->reflection, &shader_desc)))
8187 desc->NumInputSignatureEntries = shader_desc.InputParameters;
8188 desc->NumOutputSignatureEntries = shader_desc.OutputParameters;
8192 return hr;
8195 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetVertexShader(
8196 ID3D10EffectShaderVariable *iface, UINT index, ID3D10VertexShader **shader)
8198 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderVariable(iface);
8199 struct d3d10_effect_shader_variable *s;
8200 D3D10_SHADER_VARIABLE_TYPE basetype;
8201 HRESULT hr;
8203 TRACE("iface %p, index %u, shader %p.\n", iface, index, shader);
8205 *shader = NULL;
8207 if (FAILED(hr = d3d10_get_shader_variable(v, index, &s, &basetype)))
8208 return hr;
8210 if (basetype != D3D10_SVT_VERTEXSHADER)
8212 WARN("Shader is not a vertex shader.\n");
8213 return D3DERR_INVALIDCALL;
8216 if ((*shader = s->shader.vs))
8217 ID3D10VertexShader_AddRef(*shader);
8219 return S_OK;
8222 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetGeometryShader(
8223 ID3D10EffectShaderVariable *iface, UINT index, ID3D10GeometryShader **shader)
8225 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderVariable(iface);
8226 struct d3d10_effect_shader_variable *s;
8227 D3D10_SHADER_VARIABLE_TYPE basetype;
8228 HRESULT hr;
8230 TRACE("iface %p, index %u, shader %p.\n", iface, index, shader);
8232 *shader = NULL;
8234 if (FAILED(hr = d3d10_get_shader_variable(v, index, &s, &basetype)))
8235 return hr;
8237 if (basetype != D3D10_SVT_GEOMETRYSHADER)
8239 WARN("Shader is not a geometry shader.\n");
8240 return D3DERR_INVALIDCALL;
8243 if ((*shader = s->shader.gs))
8244 ID3D10GeometryShader_AddRef(*shader);
8246 return S_OK;
8249 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetPixelShader(
8250 ID3D10EffectShaderVariable *iface, UINT index, ID3D10PixelShader **shader)
8252 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderVariable(iface);
8253 struct d3d10_effect_shader_variable *s;
8254 D3D10_SHADER_VARIABLE_TYPE basetype;
8255 HRESULT hr;
8257 TRACE("iface %p, index %u, shader %p.\n", iface, index, shader);
8259 *shader = NULL;
8261 if (FAILED(hr = d3d10_get_shader_variable(v, index, &s, &basetype)))
8262 return hr;
8264 if (basetype != D3D10_SVT_PIXELSHADER)
8266 WARN("Shader is not a pixel shader.\n");
8267 return D3DERR_INVALIDCALL;
8270 if ((*shader = s->shader.ps))
8271 ID3D10PixelShader_AddRef(*shader);
8273 return S_OK;
8276 static HRESULT d3d10_get_shader_variable_signature(struct d3d10_effect_variable *v,
8277 UINT shader_index, UINT element_index, BOOL output, D3D10_SIGNATURE_PARAMETER_DESC *desc)
8279 struct d3d10_effect_shader_variable *s;
8280 HRESULT hr;
8282 if (FAILED(hr = d3d10_get_shader_variable(v, shader_index, &s, NULL)))
8283 return hr;
8285 if (!s->reflection)
8286 return D3DERR_INVALIDCALL;
8288 if (output)
8289 return s->reflection->lpVtbl->GetOutputParameterDesc(s->reflection, element_index, desc);
8290 else
8291 return s->reflection->lpVtbl->GetInputParameterDesc(s->reflection, element_index, desc);
8294 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetInputSignatureElementDesc(
8295 ID3D10EffectShaderVariable *iface, UINT shader_index, UINT element_index,
8296 D3D10_SIGNATURE_PARAMETER_DESC *desc)
8298 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderVariable(iface);
8300 TRACE("iface %p, shader_index %u, element_index %u, desc %p\n",
8301 iface, shader_index, element_index, desc);
8303 if (!iface->lpVtbl->IsValid(iface))
8305 WARN("Null variable specified\n");
8306 return E_FAIL;
8309 return d3d10_get_shader_variable_signature(v, shader_index, element_index, FALSE, desc);
8312 static HRESULT STDMETHODCALLTYPE d3d10_effect_shader_variable_GetOutputSignatureElementDesc(
8313 ID3D10EffectShaderVariable *iface, UINT shader_index, UINT element_index,
8314 D3D10_SIGNATURE_PARAMETER_DESC *desc)
8316 struct d3d10_effect_variable *v = impl_from_ID3D10EffectShaderVariable(iface);
8318 TRACE("iface %p, shader_index %u, element_index %u, desc %p\n",
8319 iface, shader_index, element_index, desc);
8321 if (!iface->lpVtbl->IsValid(iface))
8323 WARN("Null variable specified\n");
8324 return E_FAIL;
8327 return d3d10_get_shader_variable_signature(v, shader_index, element_index, TRUE, desc);
8331 static const struct ID3D10EffectShaderVariableVtbl d3d10_effect_shader_variable_vtbl =
8333 /* ID3D10EffectVariable methods */
8334 d3d10_effect_shader_variable_IsValid,
8335 d3d10_effect_shader_variable_GetType,
8336 d3d10_effect_shader_variable_GetDesc,
8337 d3d10_effect_shader_variable_GetAnnotationByIndex,
8338 d3d10_effect_shader_variable_GetAnnotationByName,
8339 d3d10_effect_shader_variable_GetMemberByIndex,
8340 d3d10_effect_shader_variable_GetMemberByName,
8341 d3d10_effect_shader_variable_GetMemberBySemantic,
8342 d3d10_effect_shader_variable_GetElement,
8343 d3d10_effect_shader_variable_GetParentConstantBuffer,
8344 d3d10_effect_shader_variable_AsScalar,
8345 d3d10_effect_shader_variable_AsVector,
8346 d3d10_effect_shader_variable_AsMatrix,
8347 d3d10_effect_shader_variable_AsString,
8348 d3d10_effect_shader_variable_AsShaderResource,
8349 d3d10_effect_shader_variable_AsRenderTargetView,
8350 d3d10_effect_shader_variable_AsDepthStencilView,
8351 d3d10_effect_shader_variable_AsConstantBuffer,
8352 d3d10_effect_shader_variable_AsShader,
8353 d3d10_effect_shader_variable_AsBlend,
8354 d3d10_effect_shader_variable_AsDepthStencil,
8355 d3d10_effect_shader_variable_AsRasterizer,
8356 d3d10_effect_shader_variable_AsSampler,
8357 d3d10_effect_shader_variable_SetRawValue,
8358 d3d10_effect_shader_variable_GetRawValue,
8359 /* ID3D10EffectShaderVariable methods */
8360 d3d10_effect_shader_variable_GetShaderDesc,
8361 d3d10_effect_shader_variable_GetVertexShader,
8362 d3d10_effect_shader_variable_GetGeometryShader,
8363 d3d10_effect_shader_variable_GetPixelShader,
8364 d3d10_effect_shader_variable_GetInputSignatureElementDesc,
8365 d3d10_effect_shader_variable_GetOutputSignatureElementDesc,
8368 /* ID3D10EffectVariable methods */
8370 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectBlendVariable(
8371 ID3D10EffectBlendVariable *iface)
8373 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
8376 static BOOL STDMETHODCALLTYPE d3d10_effect_blend_variable_IsValid(ID3D10EffectBlendVariable *iface)
8378 struct d3d10_effect_variable *v = impl_from_ID3D10EffectBlendVariable(iface);
8380 TRACE("iface %p\n", iface);
8382 return v != &null_blend_variable;
8385 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetType(
8386 ID3D10EffectBlendVariable *iface)
8388 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
8391 static HRESULT STDMETHODCALLTYPE d3d10_effect_blend_variable_GetDesc(ID3D10EffectBlendVariable *iface,
8392 D3D10_EFFECT_VARIABLE_DESC *desc)
8394 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
8397 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetAnnotationByIndex(
8398 ID3D10EffectBlendVariable *iface, UINT index)
8400 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
8403 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetAnnotationByName(
8404 ID3D10EffectBlendVariable *iface, const char *name)
8406 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
8409 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetMemberByIndex(
8410 ID3D10EffectBlendVariable *iface, UINT index)
8412 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
8415 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetMemberByName(
8416 ID3D10EffectBlendVariable *iface, const char *name)
8418 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
8421 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetMemberBySemantic(
8422 ID3D10EffectBlendVariable *iface, const char *semantic)
8424 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
8427 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetElement(
8428 ID3D10EffectBlendVariable *iface, UINT index)
8430 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
8433 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_blend_variable_GetParentConstantBuffer(
8434 ID3D10EffectBlendVariable *iface)
8436 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
8439 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsScalar(
8440 ID3D10EffectBlendVariable *iface)
8442 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
8445 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsVector(
8446 ID3D10EffectBlendVariable *iface)
8448 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
8451 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsMatrix(
8452 ID3D10EffectBlendVariable *iface)
8454 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
8457 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsString(
8458 ID3D10EffectBlendVariable *iface)
8460 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
8463 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsShaderResource(
8464 ID3D10EffectBlendVariable *iface)
8466 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
8469 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsRenderTargetView(
8470 ID3D10EffectBlendVariable *iface)
8472 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
8475 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsDepthStencilView(
8476 ID3D10EffectBlendVariable *iface)
8478 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
8481 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsConstantBuffer(
8482 ID3D10EffectBlendVariable *iface)
8484 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
8487 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsShader(
8488 ID3D10EffectBlendVariable *iface)
8490 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
8493 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsBlend(
8494 ID3D10EffectBlendVariable *iface)
8496 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
8499 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsDepthStencil(
8500 ID3D10EffectBlendVariable *iface)
8502 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
8505 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsRasterizer(
8506 ID3D10EffectBlendVariable *iface)
8508 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
8511 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_blend_variable_AsSampler(
8512 ID3D10EffectBlendVariable *iface)
8514 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
8517 static HRESULT STDMETHODCALLTYPE d3d10_effect_blend_variable_SetRawValue(ID3D10EffectBlendVariable *iface,
8518 void *data, UINT offset, UINT count)
8520 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
8523 static HRESULT STDMETHODCALLTYPE d3d10_effect_blend_variable_GetRawValue(ID3D10EffectBlendVariable *iface,
8524 void *data, UINT offset, UINT count)
8526 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
8529 /* ID3D10EffectBlendVariable methods */
8531 static HRESULT STDMETHODCALLTYPE d3d10_effect_blend_variable_GetBlendState(ID3D10EffectBlendVariable *iface,
8532 UINT index, ID3D10BlendState **blend_state)
8534 struct d3d10_effect_variable *v = impl_from_ID3D10EffectBlendVariable(iface);
8536 TRACE("iface %p, index %u, blend_state %p.\n", iface, index, blend_state);
8538 if (!iface->lpVtbl->IsValid(iface))
8540 WARN("Invalid variable.\n");
8541 return E_FAIL;
8544 if (!(v = d3d10_get_state_variable(v, index, &v->effect->blend_states)))
8545 return E_FAIL;
8547 if ((*blend_state = v->u.state.object.blend))
8548 ID3D10BlendState_AddRef(*blend_state);
8550 return S_OK;
8553 static HRESULT STDMETHODCALLTYPE d3d10_effect_blend_variable_GetBackingStore(ID3D10EffectBlendVariable *iface,
8554 UINT index, D3D10_BLEND_DESC *desc)
8556 struct d3d10_effect_variable *v = impl_from_ID3D10EffectBlendVariable(iface);
8558 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
8560 if (!iface->lpVtbl->IsValid(iface))
8562 WARN("Invalid variable.\n");
8563 return E_FAIL;
8566 if (!(v = d3d10_get_state_variable(v, index, &v->effect->blend_states)))
8567 return E_FAIL;
8569 *desc = v->u.state.desc.blend;
8571 return S_OK;
8574 static const struct ID3D10EffectBlendVariableVtbl d3d10_effect_blend_variable_vtbl =
8576 /* ID3D10EffectVariable methods */
8577 d3d10_effect_blend_variable_IsValid,
8578 d3d10_effect_blend_variable_GetType,
8579 d3d10_effect_blend_variable_GetDesc,
8580 d3d10_effect_blend_variable_GetAnnotationByIndex,
8581 d3d10_effect_blend_variable_GetAnnotationByName,
8582 d3d10_effect_blend_variable_GetMemberByIndex,
8583 d3d10_effect_blend_variable_GetMemberByName,
8584 d3d10_effect_blend_variable_GetMemberBySemantic,
8585 d3d10_effect_blend_variable_GetElement,
8586 d3d10_effect_blend_variable_GetParentConstantBuffer,
8587 d3d10_effect_blend_variable_AsScalar,
8588 d3d10_effect_blend_variable_AsVector,
8589 d3d10_effect_blend_variable_AsMatrix,
8590 d3d10_effect_blend_variable_AsString,
8591 d3d10_effect_blend_variable_AsShaderResource,
8592 d3d10_effect_blend_variable_AsRenderTargetView,
8593 d3d10_effect_blend_variable_AsDepthStencilView,
8594 d3d10_effect_blend_variable_AsConstantBuffer,
8595 d3d10_effect_blend_variable_AsShader,
8596 d3d10_effect_blend_variable_AsBlend,
8597 d3d10_effect_blend_variable_AsDepthStencil,
8598 d3d10_effect_blend_variable_AsRasterizer,
8599 d3d10_effect_blend_variable_AsSampler,
8600 d3d10_effect_blend_variable_SetRawValue,
8601 d3d10_effect_blend_variable_GetRawValue,
8602 /* ID3D10EffectBlendVariable methods */
8603 d3d10_effect_blend_variable_GetBlendState,
8604 d3d10_effect_blend_variable_GetBackingStore,
8607 /* ID3D10EffectVariable methods */
8609 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectDepthStencilVariable(
8610 ID3D10EffectDepthStencilVariable *iface)
8612 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
8615 static BOOL STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_IsValid(ID3D10EffectDepthStencilVariable *iface)
8617 struct d3d10_effect_variable *v = impl_from_ID3D10EffectDepthStencilVariable(iface);
8619 TRACE("iface %p\n", iface);
8621 return v != &null_depth_stencil_variable;
8624 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetType(
8625 ID3D10EffectDepthStencilVariable *iface)
8627 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
8630 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetDesc(ID3D10EffectDepthStencilVariable *iface,
8631 D3D10_EFFECT_VARIABLE_DESC *desc)
8633 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
8636 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetAnnotationByIndex(
8637 ID3D10EffectDepthStencilVariable *iface, UINT index)
8639 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
8642 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetAnnotationByName(
8643 ID3D10EffectDepthStencilVariable *iface, const char *name)
8645 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
8648 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetMemberByIndex(
8649 ID3D10EffectDepthStencilVariable *iface, UINT index)
8651 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
8654 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetMemberByName(
8655 ID3D10EffectDepthStencilVariable *iface, const char *name)
8657 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
8660 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetMemberBySemantic(
8661 ID3D10EffectDepthStencilVariable *iface, const char *semantic)
8663 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
8666 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetElement(
8667 ID3D10EffectDepthStencilVariable *iface, UINT index)
8669 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
8672 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetParentConstantBuffer(
8673 ID3D10EffectDepthStencilVariable *iface)
8675 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
8678 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsScalar(
8679 ID3D10EffectDepthStencilVariable *iface)
8681 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
8684 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsVector(
8685 ID3D10EffectDepthStencilVariable *iface)
8687 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
8690 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsMatrix(
8691 ID3D10EffectDepthStencilVariable *iface)
8693 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
8696 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsString(
8697 ID3D10EffectDepthStencilVariable *iface)
8699 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
8702 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsShaderResource(
8703 ID3D10EffectDepthStencilVariable *iface)
8705 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
8708 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsRenderTargetView(
8709 ID3D10EffectDepthStencilVariable *iface)
8711 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
8714 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsDepthStencilView(
8715 ID3D10EffectDepthStencilVariable *iface)
8717 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
8720 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsConstantBuffer(
8721 ID3D10EffectDepthStencilVariable *iface)
8723 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
8726 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsShader(
8727 ID3D10EffectDepthStencilVariable *iface)
8729 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
8732 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsBlend(
8733 ID3D10EffectDepthStencilVariable *iface)
8735 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
8738 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsDepthStencil(
8739 ID3D10EffectDepthStencilVariable *iface)
8741 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
8744 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsRasterizer(
8745 ID3D10EffectDepthStencilVariable *iface)
8747 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
8750 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_AsSampler(
8751 ID3D10EffectDepthStencilVariable *iface)
8753 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
8756 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_SetRawValue(ID3D10EffectDepthStencilVariable *iface,
8757 void *data, UINT offset, UINT count)
8759 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
8762 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetRawValue(ID3D10EffectDepthStencilVariable *iface,
8763 void *data, UINT offset, UINT count)
8765 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
8768 /* ID3D10EffectDepthStencilVariable methods */
8770 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetDepthStencilState(ID3D10EffectDepthStencilVariable *iface,
8771 UINT index, ID3D10DepthStencilState **depth_stencil_state)
8773 struct d3d10_effect_variable *v = impl_from_ID3D10EffectDepthStencilVariable(iface);
8775 TRACE("iface %p, index %u, depth_stencil_state %p.\n", iface, index, depth_stencil_state);
8777 if (!iface->lpVtbl->IsValid(iface))
8779 WARN("Invalid variable.\n");
8780 return E_FAIL;
8783 if (!(v = d3d10_get_state_variable(v, index, &v->effect->ds_states)))
8784 return E_FAIL;
8786 if ((*depth_stencil_state = v->u.state.object.depth_stencil))
8787 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
8789 return S_OK;
8792 static HRESULT STDMETHODCALLTYPE d3d10_effect_depth_stencil_variable_GetBackingStore(ID3D10EffectDepthStencilVariable *iface,
8793 UINT index, D3D10_DEPTH_STENCIL_DESC *desc)
8795 struct d3d10_effect_variable *v = impl_from_ID3D10EffectDepthStencilVariable(iface);
8797 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
8799 if (!iface->lpVtbl->IsValid(iface))
8801 WARN("Invalid variable.\n");
8802 return E_FAIL;
8805 if (!(v = d3d10_get_state_variable(v, index, &v->effect->ds_states)))
8806 return E_FAIL;
8808 *desc = v->u.state.desc.depth_stencil;
8810 return S_OK;
8813 static const struct ID3D10EffectDepthStencilVariableVtbl d3d10_effect_depth_stencil_variable_vtbl =
8815 /* ID3D10EffectVariable methods */
8816 d3d10_effect_depth_stencil_variable_IsValid,
8817 d3d10_effect_depth_stencil_variable_GetType,
8818 d3d10_effect_depth_stencil_variable_GetDesc,
8819 d3d10_effect_depth_stencil_variable_GetAnnotationByIndex,
8820 d3d10_effect_depth_stencil_variable_GetAnnotationByName,
8821 d3d10_effect_depth_stencil_variable_GetMemberByIndex,
8822 d3d10_effect_depth_stencil_variable_GetMemberByName,
8823 d3d10_effect_depth_stencil_variable_GetMemberBySemantic,
8824 d3d10_effect_depth_stencil_variable_GetElement,
8825 d3d10_effect_depth_stencil_variable_GetParentConstantBuffer,
8826 d3d10_effect_depth_stencil_variable_AsScalar,
8827 d3d10_effect_depth_stencil_variable_AsVector,
8828 d3d10_effect_depth_stencil_variable_AsMatrix,
8829 d3d10_effect_depth_stencil_variable_AsString,
8830 d3d10_effect_depth_stencil_variable_AsShaderResource,
8831 d3d10_effect_depth_stencil_variable_AsRenderTargetView,
8832 d3d10_effect_depth_stencil_variable_AsDepthStencilView,
8833 d3d10_effect_depth_stencil_variable_AsConstantBuffer,
8834 d3d10_effect_depth_stencil_variable_AsShader,
8835 d3d10_effect_depth_stencil_variable_AsBlend,
8836 d3d10_effect_depth_stencil_variable_AsDepthStencil,
8837 d3d10_effect_depth_stencil_variable_AsRasterizer,
8838 d3d10_effect_depth_stencil_variable_AsSampler,
8839 d3d10_effect_depth_stencil_variable_SetRawValue,
8840 d3d10_effect_depth_stencil_variable_GetRawValue,
8841 /* ID3D10EffectDepthStencilVariable methods */
8842 d3d10_effect_depth_stencil_variable_GetDepthStencilState,
8843 d3d10_effect_depth_stencil_variable_GetBackingStore,
8846 /* ID3D10EffectVariable methods */
8848 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectRasterizerVariable(
8849 ID3D10EffectRasterizerVariable *iface)
8851 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
8854 static BOOL STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_IsValid(ID3D10EffectRasterizerVariable *iface)
8856 struct d3d10_effect_variable *v = impl_from_ID3D10EffectRasterizerVariable(iface);
8858 TRACE("iface %p\n", iface);
8860 return v != &null_rasterizer_variable;
8863 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetType(
8864 ID3D10EffectRasterizerVariable *iface)
8866 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
8869 static HRESULT STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetDesc(ID3D10EffectRasterizerVariable *iface,
8870 D3D10_EFFECT_VARIABLE_DESC *desc)
8872 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
8875 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetAnnotationByIndex(
8876 ID3D10EffectRasterizerVariable *iface, UINT index)
8878 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
8881 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetAnnotationByName(
8882 ID3D10EffectRasterizerVariable *iface, const char *name)
8884 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
8887 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetMemberByIndex(
8888 ID3D10EffectRasterizerVariable *iface, UINT index)
8890 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
8893 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetMemberByName(
8894 ID3D10EffectRasterizerVariable *iface, const char *name)
8896 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
8899 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetMemberBySemantic(
8900 ID3D10EffectRasterizerVariable *iface, const char *semantic)
8902 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
8905 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetElement(
8906 ID3D10EffectRasterizerVariable *iface, UINT index)
8908 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
8911 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetParentConstantBuffer(
8912 ID3D10EffectRasterizerVariable *iface)
8914 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
8917 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsScalar(
8918 ID3D10EffectRasterizerVariable *iface)
8920 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
8923 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsVector(
8924 ID3D10EffectRasterizerVariable *iface)
8926 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
8929 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsMatrix(
8930 ID3D10EffectRasterizerVariable *iface)
8932 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
8935 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsString(
8936 ID3D10EffectRasterizerVariable *iface)
8938 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
8941 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsShaderResource(
8942 ID3D10EffectRasterizerVariable *iface)
8944 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
8947 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsRenderTargetView(
8948 ID3D10EffectRasterizerVariable *iface)
8950 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
8953 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsDepthStencilView(
8954 ID3D10EffectRasterizerVariable *iface)
8956 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
8959 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsConstantBuffer(
8960 ID3D10EffectRasterizerVariable *iface)
8962 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
8965 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsShader(
8966 ID3D10EffectRasterizerVariable *iface)
8968 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
8971 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsBlend(
8972 ID3D10EffectRasterizerVariable *iface)
8974 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
8977 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsDepthStencil(
8978 ID3D10EffectRasterizerVariable *iface)
8980 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
8983 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsRasterizer(
8984 ID3D10EffectRasterizerVariable *iface)
8986 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
8989 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_AsSampler(
8990 ID3D10EffectRasterizerVariable *iface)
8992 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
8995 static HRESULT STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_SetRawValue(ID3D10EffectRasterizerVariable *iface,
8996 void *data, UINT offset, UINT count)
8998 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
9001 static HRESULT STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetRawValue(ID3D10EffectRasterizerVariable *iface,
9002 void *data, UINT offset, UINT count)
9004 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
9007 /* ID3D10EffectRasterizerVariable methods */
9009 static HRESULT STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetRasterizerState(ID3D10EffectRasterizerVariable *iface,
9010 UINT index, ID3D10RasterizerState **rasterizer_state)
9012 struct d3d10_effect_variable *v = impl_from_ID3D10EffectRasterizerVariable(iface);
9014 TRACE("iface %p, index %u, rasterizer_state %p.\n", iface, index, rasterizer_state);
9016 if (!iface->lpVtbl->IsValid(iface))
9018 WARN("Invalid variable.\n");
9019 return E_FAIL;
9022 if (!(v = d3d10_get_state_variable(v, index, &v->effect->rs_states)))
9023 return E_FAIL;
9025 if ((*rasterizer_state = v->u.state.object.rasterizer))
9026 ID3D10RasterizerState_AddRef(*rasterizer_state);
9028 return S_OK;
9031 static HRESULT STDMETHODCALLTYPE d3d10_effect_rasterizer_variable_GetBackingStore(ID3D10EffectRasterizerVariable *iface,
9032 UINT index, D3D10_RASTERIZER_DESC *desc)
9034 struct d3d10_effect_variable *v = impl_from_ID3D10EffectRasterizerVariable(iface);
9036 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
9038 if (!iface->lpVtbl->IsValid(iface))
9040 WARN("Invalid variable.\n");
9041 return E_FAIL;
9044 if (!(v = d3d10_get_state_variable(v, index, &v->effect->rs_states)))
9045 return E_FAIL;
9047 *desc = v->u.state.desc.rasterizer;
9049 return S_OK;
9052 static const struct ID3D10EffectRasterizerVariableVtbl d3d10_effect_rasterizer_variable_vtbl =
9054 /* ID3D10EffectVariable methods */
9055 d3d10_effect_rasterizer_variable_IsValid,
9056 d3d10_effect_rasterizer_variable_GetType,
9057 d3d10_effect_rasterizer_variable_GetDesc,
9058 d3d10_effect_rasterizer_variable_GetAnnotationByIndex,
9059 d3d10_effect_rasterizer_variable_GetAnnotationByName,
9060 d3d10_effect_rasterizer_variable_GetMemberByIndex,
9061 d3d10_effect_rasterizer_variable_GetMemberByName,
9062 d3d10_effect_rasterizer_variable_GetMemberBySemantic,
9063 d3d10_effect_rasterizer_variable_GetElement,
9064 d3d10_effect_rasterizer_variable_GetParentConstantBuffer,
9065 d3d10_effect_rasterizer_variable_AsScalar,
9066 d3d10_effect_rasterizer_variable_AsVector,
9067 d3d10_effect_rasterizer_variable_AsMatrix,
9068 d3d10_effect_rasterizer_variable_AsString,
9069 d3d10_effect_rasterizer_variable_AsShaderResource,
9070 d3d10_effect_rasterizer_variable_AsRenderTargetView,
9071 d3d10_effect_rasterizer_variable_AsDepthStencilView,
9072 d3d10_effect_rasterizer_variable_AsConstantBuffer,
9073 d3d10_effect_rasterizer_variable_AsShader,
9074 d3d10_effect_rasterizer_variable_AsBlend,
9075 d3d10_effect_rasterizer_variable_AsDepthStencil,
9076 d3d10_effect_rasterizer_variable_AsRasterizer,
9077 d3d10_effect_rasterizer_variable_AsSampler,
9078 d3d10_effect_rasterizer_variable_SetRawValue,
9079 d3d10_effect_rasterizer_variable_GetRawValue,
9080 /* ID3D10EffectRasterizerVariable methods */
9081 d3d10_effect_rasterizer_variable_GetRasterizerState,
9082 d3d10_effect_rasterizer_variable_GetBackingStore,
9085 /* ID3D10EffectVariable methods */
9087 static inline struct d3d10_effect_variable *impl_from_ID3D10EffectSamplerVariable(
9088 ID3D10EffectSamplerVariable *iface)
9090 return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface);
9093 static BOOL STDMETHODCALLTYPE d3d10_effect_sampler_variable_IsValid(ID3D10EffectSamplerVariable *iface)
9095 struct d3d10_effect_variable *v = impl_from_ID3D10EffectSamplerVariable(iface);
9097 TRACE("iface %p\n", iface);
9099 return v != &null_sampler_variable;
9102 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetType(
9103 ID3D10EffectSamplerVariable *iface)
9105 return d3d10_effect_variable_GetType((ID3D10EffectVariable *)iface);
9108 static HRESULT STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetDesc(ID3D10EffectSamplerVariable *iface,
9109 D3D10_EFFECT_VARIABLE_DESC *desc)
9111 return d3d10_effect_variable_GetDesc((ID3D10EffectVariable *)iface, desc);
9114 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetAnnotationByIndex(
9115 ID3D10EffectSamplerVariable *iface, UINT index)
9117 return d3d10_effect_variable_GetAnnotationByIndex((ID3D10EffectVariable *)iface, index);
9120 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetAnnotationByName(
9121 ID3D10EffectSamplerVariable *iface, const char *name)
9123 return d3d10_effect_variable_GetAnnotationByName((ID3D10EffectVariable *)iface, name);
9126 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetMemberByIndex(
9127 ID3D10EffectSamplerVariable *iface, UINT index)
9129 return d3d10_effect_variable_GetMemberByIndex((ID3D10EffectVariable *)iface, index);
9132 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetMemberByName(
9133 ID3D10EffectSamplerVariable *iface, const char *name)
9135 return d3d10_effect_variable_GetMemberByName((ID3D10EffectVariable *)iface, name);
9138 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetMemberBySemantic(
9139 ID3D10EffectSamplerVariable *iface, const char *semantic)
9141 return d3d10_effect_variable_GetMemberBySemantic((ID3D10EffectVariable *)iface, semantic);
9144 static struct ID3D10EffectVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetElement(
9145 ID3D10EffectSamplerVariable *iface, UINT index)
9147 return d3d10_effect_variable_GetElement((ID3D10EffectVariable *)iface, index);
9150 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetParentConstantBuffer(
9151 ID3D10EffectSamplerVariable *iface)
9153 return d3d10_effect_variable_GetParentConstantBuffer((ID3D10EffectVariable *)iface);
9156 static struct ID3D10EffectScalarVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsScalar(
9157 ID3D10EffectSamplerVariable *iface)
9159 return d3d10_effect_variable_AsScalar((ID3D10EffectVariable *)iface);
9162 static struct ID3D10EffectVectorVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsVector(
9163 ID3D10EffectSamplerVariable *iface)
9165 return d3d10_effect_variable_AsVector((ID3D10EffectVariable *)iface);
9168 static struct ID3D10EffectMatrixVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsMatrix(
9169 ID3D10EffectSamplerVariable *iface)
9171 return d3d10_effect_variable_AsMatrix((ID3D10EffectVariable *)iface);
9174 static struct ID3D10EffectStringVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsString(
9175 ID3D10EffectSamplerVariable *iface)
9177 return d3d10_effect_variable_AsString((ID3D10EffectVariable *)iface);
9180 static struct ID3D10EffectShaderResourceVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsShaderResource(
9181 ID3D10EffectSamplerVariable *iface)
9183 return d3d10_effect_variable_AsShaderResource((ID3D10EffectVariable *)iface);
9186 static struct ID3D10EffectRenderTargetViewVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsRenderTargetView(
9187 ID3D10EffectSamplerVariable *iface)
9189 return d3d10_effect_variable_AsRenderTargetView((ID3D10EffectVariable *)iface);
9192 static struct ID3D10EffectDepthStencilViewVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsDepthStencilView(
9193 ID3D10EffectSamplerVariable *iface)
9195 return d3d10_effect_variable_AsDepthStencilView((ID3D10EffectVariable *)iface);
9198 static struct ID3D10EffectConstantBuffer * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsConstantBuffer(
9199 ID3D10EffectSamplerVariable *iface)
9201 return d3d10_effect_variable_AsConstantBuffer((ID3D10EffectVariable *)iface);
9204 static struct ID3D10EffectShaderVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsShader(
9205 ID3D10EffectSamplerVariable *iface)
9207 return d3d10_effect_variable_AsShader((ID3D10EffectVariable *)iface);
9210 static struct ID3D10EffectBlendVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsBlend(
9211 ID3D10EffectSamplerVariable *iface)
9213 return d3d10_effect_variable_AsBlend((ID3D10EffectVariable *)iface);
9216 static struct ID3D10EffectDepthStencilVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsDepthStencil(
9217 ID3D10EffectSamplerVariable *iface)
9219 return d3d10_effect_variable_AsDepthStencil((ID3D10EffectVariable *)iface);
9222 static struct ID3D10EffectRasterizerVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsRasterizer(
9223 ID3D10EffectSamplerVariable *iface)
9225 return d3d10_effect_variable_AsRasterizer((ID3D10EffectVariable *)iface);
9228 static struct ID3D10EffectSamplerVariable * STDMETHODCALLTYPE d3d10_effect_sampler_variable_AsSampler(
9229 ID3D10EffectSamplerVariable *iface)
9231 return d3d10_effect_variable_AsSampler((ID3D10EffectVariable *)iface);
9234 static HRESULT STDMETHODCALLTYPE d3d10_effect_sampler_variable_SetRawValue(ID3D10EffectSamplerVariable *iface,
9235 void *data, UINT offset, UINT count)
9237 return d3d10_effect_variable_SetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
9240 static HRESULT STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetRawValue(ID3D10EffectSamplerVariable *iface,
9241 void *data, UINT offset, UINT count)
9243 return d3d10_effect_variable_GetRawValue((ID3D10EffectVariable *)iface, data, offset, count);
9246 /* ID3D10EffectSamplerVariable methods */
9248 static HRESULT STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetSampler(ID3D10EffectSamplerVariable *iface,
9249 UINT index, ID3D10SamplerState **sampler)
9251 struct d3d10_effect_variable *v = impl_from_ID3D10EffectSamplerVariable(iface);
9253 TRACE("iface %p, index %u, sampler %p.\n", iface, index, sampler);
9255 if (!iface->lpVtbl->IsValid(iface))
9257 WARN("Invalid variable.\n");
9258 return E_FAIL;
9261 if (!(v = d3d10_get_state_variable(v, index, &v->effect->samplers)))
9262 return E_FAIL;
9264 if ((*sampler = v->u.state.object.sampler))
9265 ID3D10SamplerState_AddRef(*sampler);
9267 return S_OK;
9270 static HRESULT STDMETHODCALLTYPE d3d10_effect_sampler_variable_GetBackingStore(ID3D10EffectSamplerVariable *iface,
9271 UINT index, D3D10_SAMPLER_DESC *desc)
9273 struct d3d10_effect_variable *v = impl_from_ID3D10EffectSamplerVariable(iface);
9275 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
9277 if (!iface->lpVtbl->IsValid(iface))
9279 WARN("Invalid variable.\n");
9280 return E_FAIL;
9283 if (!(v = d3d10_get_state_variable(v, index, &v->effect->samplers)))
9284 return E_FAIL;
9286 *desc = v->u.state.desc.sampler.desc;
9288 return S_OK;
9291 static const struct ID3D10EffectSamplerVariableVtbl d3d10_effect_sampler_variable_vtbl =
9293 /* ID3D10EffectVariable methods */
9294 d3d10_effect_sampler_variable_IsValid,
9295 d3d10_effect_sampler_variable_GetType,
9296 d3d10_effect_sampler_variable_GetDesc,
9297 d3d10_effect_sampler_variable_GetAnnotationByIndex,
9298 d3d10_effect_sampler_variable_GetAnnotationByName,
9299 d3d10_effect_sampler_variable_GetMemberByIndex,
9300 d3d10_effect_sampler_variable_GetMemberByName,
9301 d3d10_effect_sampler_variable_GetMemberBySemantic,
9302 d3d10_effect_sampler_variable_GetElement,
9303 d3d10_effect_sampler_variable_GetParentConstantBuffer,
9304 d3d10_effect_sampler_variable_AsScalar,
9305 d3d10_effect_sampler_variable_AsVector,
9306 d3d10_effect_sampler_variable_AsMatrix,
9307 d3d10_effect_sampler_variable_AsString,
9308 d3d10_effect_sampler_variable_AsShaderResource,
9309 d3d10_effect_sampler_variable_AsRenderTargetView,
9310 d3d10_effect_sampler_variable_AsDepthStencilView,
9311 d3d10_effect_sampler_variable_AsConstantBuffer,
9312 d3d10_effect_sampler_variable_AsShader,
9313 d3d10_effect_sampler_variable_AsBlend,
9314 d3d10_effect_sampler_variable_AsDepthStencil,
9315 d3d10_effect_sampler_variable_AsRasterizer,
9316 d3d10_effect_sampler_variable_AsSampler,
9317 d3d10_effect_sampler_variable_SetRawValue,
9318 d3d10_effect_sampler_variable_GetRawValue,
9319 /* ID3D10EffectSamplerVariable methods */
9320 d3d10_effect_sampler_variable_GetSampler,
9321 d3d10_effect_sampler_variable_GetBackingStore,
9324 /* ID3D10EffectType methods */
9326 static inline struct d3d10_effect_type *impl_from_ID3D10EffectType(ID3D10EffectType *iface)
9328 return CONTAINING_RECORD(iface, struct d3d10_effect_type, ID3D10EffectType_iface);
9331 static BOOL STDMETHODCALLTYPE d3d10_effect_type_IsValid(ID3D10EffectType *iface)
9333 struct d3d10_effect_type *This = impl_from_ID3D10EffectType(iface);
9335 TRACE("iface %p\n", iface);
9337 return This != &null_type;
9340 static HRESULT STDMETHODCALLTYPE d3d10_effect_type_GetDesc(ID3D10EffectType *iface, D3D10_EFFECT_TYPE_DESC *desc)
9342 struct d3d10_effect_type *This = impl_from_ID3D10EffectType(iface);
9344 TRACE("iface %p, desc %p\n", iface, desc);
9346 if (This == &null_type)
9348 WARN("Null type specified\n");
9349 return E_FAIL;
9352 if (!desc)
9354 WARN("Invalid argument specified\n");
9355 return E_INVALIDARG;
9358 desc->TypeName = This->name;
9359 desc->Class = This->type_class;
9360 desc->Type = This->basetype;
9361 desc->Elements = This->element_count;
9362 desc->Members = This->member_count;
9363 desc->Rows = This->row_count;
9364 desc->Columns = This->column_count;
9365 desc->PackedSize = This->size_packed;
9366 desc->UnpackedSize = This->size_unpacked;
9367 desc->Stride = This->stride;
9369 return S_OK;
9372 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_type_GetMemberTypeByIndex(ID3D10EffectType *iface,
9373 UINT index)
9375 struct d3d10_effect_type *This = impl_from_ID3D10EffectType(iface);
9376 struct d3d10_effect_type *t;
9378 TRACE("iface %p, index %u\n", iface, index);
9380 if (index >= This->member_count)
9382 WARN("Invalid index specified\n");
9383 return &null_type.ID3D10EffectType_iface;
9386 t = (&This->members[index])->type;
9388 TRACE("Returning member %p, %s\n", t, debugstr_a(t->name));
9390 return &t->ID3D10EffectType_iface;
9393 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_type_GetMemberTypeByName(ID3D10EffectType *iface,
9394 const char *name)
9396 struct d3d10_effect_type *This = impl_from_ID3D10EffectType(iface);
9397 unsigned int i;
9399 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
9401 if (!name)
9403 WARN("Invalid name specified\n");
9404 return &null_type.ID3D10EffectType_iface;
9407 for (i = 0; i < This->member_count; ++i)
9409 struct d3d10_effect_type_member *typem = &This->members[i];
9411 if (typem->name && !strcmp(typem->name, name))
9413 TRACE("Returning type %p.\n", typem->type);
9414 return &typem->type->ID3D10EffectType_iface;
9418 WARN("Invalid name specified\n");
9420 return &null_type.ID3D10EffectType_iface;
9423 static struct ID3D10EffectType * STDMETHODCALLTYPE d3d10_effect_type_GetMemberTypeBySemantic(ID3D10EffectType *iface,
9424 const char *semantic)
9426 struct d3d10_effect_type *This = impl_from_ID3D10EffectType(iface);
9427 unsigned int i;
9429 TRACE("iface %p, semantic %s\n", iface, debugstr_a(semantic));
9431 if (!semantic)
9433 WARN("Invalid semantic specified\n");
9434 return &null_type.ID3D10EffectType_iface;
9437 for (i = 0; i < This->member_count; ++i)
9439 struct d3d10_effect_type_member *typem = &This->members[i];
9441 if (typem->semantic && !stricmp(typem->semantic, semantic))
9443 TRACE("Returning type %p.\n", typem->type);
9444 return &typem->type->ID3D10EffectType_iface;
9448 WARN("Invalid semantic specified\n");
9450 return &null_type.ID3D10EffectType_iface;
9453 static const char * STDMETHODCALLTYPE d3d10_effect_type_GetMemberName(ID3D10EffectType *iface, UINT index)
9455 struct d3d10_effect_type *This = impl_from_ID3D10EffectType(iface);
9456 struct d3d10_effect_type_member *typem;
9458 TRACE("iface %p, index %u\n", iface, index);
9460 if (index >= This->member_count)
9462 WARN("Invalid index specified\n");
9463 return NULL;
9466 typem = &This->members[index];
9468 TRACE("Returning name %s\n", debugstr_a(typem->name));
9470 return typem->name;
9473 static const char * STDMETHODCALLTYPE d3d10_effect_type_GetMemberSemantic(ID3D10EffectType *iface, UINT index)
9475 struct d3d10_effect_type *This = impl_from_ID3D10EffectType(iface);
9476 struct d3d10_effect_type_member *typem;
9478 TRACE("iface %p, index %u\n", iface, index);
9480 if (index >= This->member_count)
9482 WARN("Invalid index specified\n");
9483 return NULL;
9486 typem = &This->members[index];
9488 TRACE("Returning semantic %s\n", debugstr_a(typem->semantic));
9490 return typem->semantic;
9493 static const struct ID3D10EffectTypeVtbl d3d10_effect_type_vtbl =
9495 /* ID3D10EffectType */
9496 d3d10_effect_type_IsValid,
9497 d3d10_effect_type_GetDesc,
9498 d3d10_effect_type_GetMemberTypeByIndex,
9499 d3d10_effect_type_GetMemberTypeByName,
9500 d3d10_effect_type_GetMemberTypeBySemantic,
9501 d3d10_effect_type_GetMemberName,
9502 d3d10_effect_type_GetMemberSemantic,
9505 static HRESULT STDMETHODCALLTYPE d3d10_effect_pool_QueryInterface(ID3D10EffectPool *iface,
9506 REFIID riid, void **object)
9508 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
9510 if (IsEqualGUID(riid, &IID_ID3D10EffectPool) ||
9511 IsEqualGUID(riid, &IID_IUnknown))
9513 IUnknown_AddRef(iface);
9514 *object = iface;
9515 return S_OK;
9518 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
9520 *object = NULL;
9521 return E_NOINTERFACE;
9524 static ULONG STDMETHODCALLTYPE d3d10_effect_pool_AddRef(ID3D10EffectPool *iface)
9526 struct d3d10_effect *effect = impl_from_ID3D10EffectPool(iface);
9527 return d3d10_effect_AddRef(&effect->ID3D10Effect_iface);
9530 static ULONG STDMETHODCALLTYPE d3d10_effect_pool_Release(ID3D10EffectPool *iface)
9532 struct d3d10_effect *effect = impl_from_ID3D10EffectPool(iface);
9533 return d3d10_effect_Release(&effect->ID3D10Effect_iface);
9536 static ID3D10Effect * STDMETHODCALLTYPE d3d10_effect_pool_AsEffect(ID3D10EffectPool *iface)
9538 struct d3d10_effect *effect = impl_from_ID3D10EffectPool(iface);
9540 TRACE("%p.\n", iface);
9542 return &effect->ID3D10Effect_iface;
9545 const struct ID3D10EffectPoolVtbl d3d10_effect_pool_vtbl =
9547 /* IUnknown methods */
9548 d3d10_effect_pool_QueryInterface,
9549 d3d10_effect_pool_AddRef,
9550 d3d10_effect_pool_Release,
9551 /* ID3D10EffectPool methods */
9552 d3d10_effect_pool_AsEffect,
9556 static int d3d10_effect_type_compare(const void *key, const struct wine_rb_entry *entry)
9558 const struct d3d10_effect_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3d10_effect_type, entry);
9559 const DWORD *id = key;
9561 return *id - t->id;
9564 static HRESULT d3d10_create_effect(void *data, SIZE_T data_size, ID3D10Device *device,
9565 struct d3d10_effect *pool, unsigned int flags, struct d3d10_effect **effect)
9567 struct d3d10_effect *object;
9568 HRESULT hr;
9570 if (!(object = heap_alloc_zero(sizeof(*object))))
9571 return E_OUTOFMEMORY;
9573 wine_rb_init(&object->types, d3d10_effect_type_compare);
9574 object->ID3D10Effect_iface.lpVtbl = flags & D3D10_EFFECT_IS_POOL ?
9575 &d3d10_effect_pool_effect_vtbl : &d3d10_effect_vtbl;
9576 object->ID3D10EffectPool_iface.lpVtbl = &d3d10_effect_pool_vtbl;
9577 object->refcount = 1;
9578 ID3D10Device_AddRef(device);
9579 object->device = device;
9580 object->pool = pool;
9581 object->flags = flags;
9582 if (pool) IUnknown_AddRef(&pool->ID3D10Effect_iface);
9584 hr = d3d10_effect_parse(object, data, data_size);
9585 if (FAILED(hr))
9587 ERR("Failed to parse effect\n");
9588 IUnknown_Release(&object->ID3D10Effect_iface);
9589 return hr;
9592 *effect = object;
9594 return S_OK;
9597 HRESULT WINAPI D3D10CreateEffectFromMemory(void *data, SIZE_T data_size, UINT flags,
9598 ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3D10Effect **effect)
9600 struct d3d10_effect *object, *pool = NULL;
9601 HRESULT hr;
9603 TRACE("data %p, data_size %lu, flags %#x, device %p, effect_pool %p, effect %p.\n",
9604 data, data_size, flags, device, effect_pool, effect);
9606 if (!(flags & D3D10_EFFECT_COMPILE_CHILD_EFFECT) != !effect_pool)
9607 return E_INVALIDARG;
9609 if (effect_pool && !(pool = unsafe_impl_from_ID3D10EffectPool(effect_pool)))
9611 WARN("External pool implementations are not supported.\n");
9612 return E_INVALIDARG;
9615 if (FAILED(hr = d3d10_create_effect(data, data_size, device, pool, 0, &object)))
9617 WARN("Failed to create an effect, hr %#x.\n", hr);
9618 return hr;
9621 *effect = &object->ID3D10Effect_iface;
9623 TRACE("Created effect %p\n", object);
9625 return hr;
9628 static HRESULT STDMETHODCALLTYPE d3d10_effect_pool_effect_QueryInterface(ID3D10Effect *iface,
9629 REFIID riid, void **object)
9631 struct d3d10_effect *effect = impl_from_ID3D10Effect(iface);
9633 TRACE("iface %p, riid %s, obj %p.\n", iface, debugstr_guid(riid), object);
9635 return IUnknown_QueryInterface(&effect->ID3D10EffectPool_iface, riid, object);
9638 static const struct ID3D10EffectVtbl d3d10_effect_pool_effect_vtbl =
9640 /* IUnknown methods */
9641 d3d10_effect_pool_effect_QueryInterface,
9642 d3d10_effect_AddRef,
9643 d3d10_effect_Release,
9644 /* ID3D10Effect methods */
9645 d3d10_effect_IsValid,
9646 d3d10_effect_IsPool,
9647 d3d10_effect_GetDevice,
9648 d3d10_effect_GetDesc,
9649 d3d10_effect_GetConstantBufferByIndex,
9650 d3d10_effect_GetConstantBufferByName,
9651 d3d10_effect_GetVariableByIndex,
9652 d3d10_effect_GetVariableByName,
9653 d3d10_effect_GetVariableBySemantic,
9654 d3d10_effect_GetTechniqueByIndex,
9655 d3d10_effect_GetTechniqueByName,
9656 d3d10_effect_Optimize,
9657 d3d10_effect_IsOptimized,
9660 HRESULT WINAPI D3D10CreateEffectPoolFromMemory(void *data, SIZE_T data_size, UINT fx_flags,
9661 ID3D10Device *device, ID3D10EffectPool **effect_pool)
9663 struct d3d10_effect *object;
9664 HRESULT hr;
9666 TRACE("data %p, data_size %lu, fx_flags %#x, device %p, effect_pool %p.\n",
9667 data, data_size, fx_flags, device, effect_pool);
9669 if (FAILED(hr = d3d10_create_effect(data, data_size, device, NULL,
9670 D3D10_EFFECT_IS_POOL, &object)))
9672 WARN("Failed to create an effect, hr %#x.\n", hr);
9673 return hr;
9676 *effect_pool = &object->ID3D10EffectPool_iface;
9678 TRACE("Created effect pool %p.\n", object);
9680 return hr;