wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / d3dcompiler_43 / reflection.c
blob10558283dd46ae5a11a1f85ae7ec2899bfbc893b
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 * Copyright 2010 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 "initguid.h"
22 #include "d3dcompiler_private.h"
23 #include "d3d10.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
27 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE
29 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6 = 6,
30 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7 = 7,
33 #define D3DCOMPILER_SHADER_TARGET_VERSION_MASK 0xffff
34 #define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK 0xffff0000
36 struct d3dcompiler_shader_signature
38 D3D11_SIGNATURE_PARAMETER_DESC *elements;
39 UINT element_count;
40 char *string_data;
43 struct d3dcompiler_shader_reflection_type
45 ID3D11ShaderReflectionType ID3D11ShaderReflectionType_iface;
46 ID3D10ShaderReflectionType ID3D10ShaderReflectionType_iface;
48 DWORD id;
49 struct wine_rb_entry entry;
51 struct d3dcompiler_shader_reflection *reflection;
53 D3D11_SHADER_TYPE_DESC desc;
54 struct d3dcompiler_shader_reflection_type_member *members;
55 char *name;
58 struct d3dcompiler_shader_reflection_type_member
60 char *name;
61 DWORD offset;
62 struct d3dcompiler_shader_reflection_type *type;
65 struct d3dcompiler_shader_reflection_variable
67 ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface;
68 ID3D10ShaderReflectionVariable ID3D10ShaderReflectionVariable_iface;
70 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffer;
71 struct d3dcompiler_shader_reflection_type *type;
73 char *name;
74 UINT start_offset;
75 UINT size;
76 UINT flags;
77 void *default_value;
80 struct d3dcompiler_shader_reflection_constant_buffer
82 ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface;
83 ID3D10ShaderReflectionConstantBuffer ID3D10ShaderReflectionConstantBuffer_iface;
85 struct d3dcompiler_shader_reflection *reflection;
87 char *name;
88 D3D_CBUFFER_TYPE type;
89 UINT variable_count;
90 UINT size;
91 UINT flags;
93 struct d3dcompiler_shader_reflection_variable *variables;
96 enum D3DCOMPILER_REFLECTION_VERSION
98 D3DCOMPILER_REFLECTION_VERSION_D3D10,
99 D3DCOMPILER_REFLECTION_VERSION_D3D11,
100 D3DCOMPILER_REFLECTION_VERSION_D3D12,
103 /* ID3D11ShaderReflection */
104 struct d3dcompiler_shader_reflection
106 ID3D11ShaderReflection ID3D11ShaderReflection_iface;
107 ID3D10ShaderReflection ID3D10ShaderReflection_iface;
108 LONG refcount;
110 enum D3DCOMPILER_REFLECTION_VERSION interface_version;
112 DWORD target;
113 char *creator;
114 UINT flags;
115 UINT version;
116 UINT bound_resource_count;
117 UINT constant_buffer_count;
119 UINT mov_instruction_count;
120 UINT conversion_instruction_count;
121 UINT instruction_count;
122 UINT emit_instruction_count;
123 D3D_PRIMITIVE_TOPOLOGY gs_output_topology;
124 UINT gs_max_output_vertex_count;
125 D3D_PRIMITIVE input_primitive;
126 UINT cut_instruction_count;
127 UINT dcl_count;
128 UINT static_flow_control_count;
129 UINT float_instruction_count;
130 UINT temp_register_count;
131 UINT int_instruction_count;
132 UINT uint_instruction_count;
133 UINT temp_array_count;
134 UINT array_instruction_count;
135 UINT texture_normal_instructions;
136 UINT texture_load_instructions;
137 UINT texture_comp_instructions;
138 UINT texture_bias_instructions;
139 UINT texture_gradient_instructions;
140 UINT dynamic_flow_control_count;
141 UINT c_control_points;
142 D3D_TESSELLATOR_OUTPUT_PRIMITIVE hs_output_primitive;
143 D3D_TESSELLATOR_PARTITIONING hs_prtitioning;
144 D3D_TESSELLATOR_DOMAIN tessellator_domain;
146 struct d3dcompiler_shader_signature *isgn;
147 struct d3dcompiler_shader_signature *osgn;
148 struct d3dcompiler_shader_signature *pcsg;
149 char *resource_string;
150 D3D12_SHADER_INPUT_BIND_DESC *bound_resources;
151 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers;
152 struct wine_rb_tree types;
155 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset);
157 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl;
158 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl;
159 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl;
161 static const struct ID3D10ShaderReflectionConstantBufferVtbl d3d10_shader_reflection_constant_buffer_vtbl;
162 static const struct ID3D10ShaderReflectionVariableVtbl d3d10_shader_reflection_variable_vtbl;
163 static const struct ID3D10ShaderReflectionTypeVtbl d3d10_shader_reflection_type_vtbl;
165 /* null objects - needed for invalid calls */
166 static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer =
168 {&d3dcompiler_shader_reflection_constant_buffer_vtbl},
169 {&d3d10_shader_reflection_constant_buffer_vtbl}
171 static struct d3dcompiler_shader_reflection_type null_type =
173 {&d3dcompiler_shader_reflection_type_vtbl},
174 {&d3d10_shader_reflection_type_vtbl}
176 static struct d3dcompiler_shader_reflection_variable null_variable =
178 {&d3dcompiler_shader_reflection_variable_vtbl},
179 {&d3d10_shader_reflection_variable_vtbl},
180 &null_constant_buffer,
181 &null_type
184 static BOOL copy_name(const char *ptr, char **name)
186 size_t name_len;
188 if (!ptr) return TRUE;
190 name_len = strlen(ptr) + 1;
191 if (name_len == 1)
193 return TRUE;
196 *name = HeapAlloc(GetProcessHeap(), 0, name_len);
197 if (!*name)
199 ERR("Failed to allocate name memory.\n");
200 return FALSE;
203 memcpy(*name, ptr, name_len);
205 return TRUE;
208 static BOOL copy_value(const char *ptr, void **value, DWORD size)
210 if (!ptr || !size) return TRUE;
212 *value = HeapAlloc(GetProcessHeap(), 0, size);
213 if (!*value)
215 ERR("Failed to allocate value memory.\n");
216 return FALSE;
219 memcpy(*value, ptr, size);
221 return TRUE;
224 static int d3dcompiler_shader_reflection_type_compare(const void *key, const struct wine_rb_entry *entry)
226 const struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3dcompiler_shader_reflection_type, entry);
227 const DWORD *id = key;
229 return *id - t->id;
232 static void free_type_member(struct d3dcompiler_shader_reflection_type_member *member)
234 if (member)
236 HeapFree(GetProcessHeap(), 0, member->name);
240 static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry *entry, void *context)
242 struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
243 unsigned int i;
245 TRACE("reflection type %p.\n", t);
247 if (t->members)
249 for (i = 0; i < t->desc.Members; ++i)
251 free_type_member(&t->members[i]);
253 HeapFree(GetProcessHeap(), 0, t->members);
256 heap_free(t->name);
257 HeapFree(GetProcessHeap(), 0, t);
260 static void free_signature(struct d3dcompiler_shader_signature *sig)
262 TRACE("Free signature %p\n", sig);
264 HeapFree(GetProcessHeap(), 0, sig->elements);
265 HeapFree(GetProcessHeap(), 0, sig->string_data);
268 static void free_variable(struct d3dcompiler_shader_reflection_variable *var)
270 if (var)
272 HeapFree(GetProcessHeap(), 0, var->name);
273 HeapFree(GetProcessHeap(), 0, var->default_value);
277 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer *cb)
279 if (cb->variables)
281 unsigned int i;
283 for (i = 0; i < cb->variable_count; ++i)
285 free_variable(&cb->variables[i]);
287 HeapFree(GetProcessHeap(), 0, cb->variables);
290 HeapFree(GetProcessHeap(), 0, cb->name);
293 static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref)
295 TRACE("Cleanup %p\n", ref);
297 if (ref->isgn)
299 free_signature(ref->isgn);
300 HeapFree(GetProcessHeap(), 0, ref->isgn);
303 if (ref->osgn)
305 free_signature(ref->osgn);
306 HeapFree(GetProcessHeap(), 0, ref->osgn);
309 if (ref->pcsg)
311 free_signature(ref->pcsg);
312 HeapFree(GetProcessHeap(), 0, ref->pcsg);
315 if (ref->constant_buffers)
317 unsigned int i;
319 for (i = 0; i < ref->constant_buffer_count; ++i)
321 free_constant_buffer(&ref->constant_buffers[i]);
325 wine_rb_destroy(&ref->types, d3dcompiler_shader_reflection_type_destroy, NULL);
326 HeapFree(GetProcessHeap(), 0, ref->constant_buffers);
327 HeapFree(GetProcessHeap(), 0, ref->bound_resources);
328 HeapFree(GetProcessHeap(), 0, ref->resource_string);
329 HeapFree(GetProcessHeap(), 0, ref->creator);
332 /* IUnknown methods */
334 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface)
336 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface);
339 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object)
341 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
343 if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
344 || IsEqualGUID(riid, &IID_IUnknown)
345 || (D3D_COMPILER_VERSION >= 47 && IsEqualGUID(riid, &IID_ID3D12ShaderReflection)))
347 IUnknown_AddRef(iface);
348 *object = iface;
349 return S_OK;
352 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
354 *object = NULL;
355 return E_NOINTERFACE;
358 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection *iface)
360 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
361 ULONG refcount = InterlockedIncrement(&This->refcount);
363 TRACE("%p increasing refcount to %u\n", This, refcount);
365 return refcount;
368 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection *iface)
370 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
371 ULONG refcount = InterlockedDecrement(&This->refcount);
373 TRACE("%p decreasing refcount to %u\n", This, refcount);
375 if (!refcount)
377 reflection_cleanup(This);
378 HeapFree(GetProcessHeap(), 0, This);
381 return refcount;
384 /* ID3D11ShaderReflection methods */
386 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc)
388 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
390 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
392 if (!desc)
394 WARN("Invalid argument specified\n");
395 return E_FAIL;
398 desc->Version = This->version;
399 desc->Creator = This->creator;
400 desc->Flags = This->flags;
401 desc->ConstantBuffers = This->constant_buffer_count;
402 desc->BoundResources = This->bound_resource_count;
403 desc->InputParameters = This->isgn ? This->isgn->element_count : 0;
404 desc->OutputParameters = This->osgn ? This->osgn->element_count : 0;
405 desc->InstructionCount = This->instruction_count;
406 desc->TempRegisterCount = This->temp_register_count;
407 desc->TempArrayCount = This->temp_array_count;
408 desc->DefCount = 0;
409 desc->DclCount = This->dcl_count;
410 desc->TextureNormalInstructions = This->texture_normal_instructions;
411 desc->TextureLoadInstructions = This->texture_load_instructions;
412 desc->TextureCompInstructions = This->texture_comp_instructions;
413 desc->TextureBiasInstructions = This->texture_bias_instructions;
414 desc->TextureGradientInstructions = This->texture_gradient_instructions;
415 desc->FloatInstructionCount = This->float_instruction_count;
416 desc->IntInstructionCount = This->int_instruction_count;
417 desc->UintInstructionCount = This->uint_instruction_count;
418 desc->StaticFlowControlCount = This->static_flow_control_count;
419 desc->DynamicFlowControlCount = This->dynamic_flow_control_count;
420 desc->MacroInstructionCount = 0;
421 desc->ArrayInstructionCount = This->array_instruction_count;
422 desc->CutInstructionCount = This->cut_instruction_count;
423 desc->EmitInstructionCount = This->emit_instruction_count;
424 desc->GSOutputTopology = This->gs_output_topology;
425 desc->GSMaxOutputVertexCount = This->gs_max_output_vertex_count;
426 desc->InputPrimitive = This->input_primitive;
427 desc->PatchConstantParameters = This->pcsg ? This->pcsg->element_count : 0;
428 desc->cGSInstanceCount = 0;
429 desc->cControlPoints = This->c_control_points;
430 desc->HSOutputPrimitive = This->hs_output_primitive;
431 desc->HSPartitioning = This->hs_prtitioning;
432 desc->TessellatorDomain = This->tessellator_domain;
433 desc->cBarrierInstructions = 0;
434 desc->cInterlockedInstructions = 0;
435 desc->cTextureStoreInstructions = 0;
437 return S_OK;
440 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByIndex(
441 ID3D11ShaderReflection *iface, UINT index)
443 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
445 TRACE("iface %p, index %u\n", iface, index);
447 if (index >= This->constant_buffer_count)
449 WARN("Invalid argument specified\n");
450 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
453 return &This->constant_buffers[index].ID3D11ShaderReflectionConstantBuffer_iface;
456 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByName(
457 ID3D11ShaderReflection *iface, const char *name)
459 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
460 unsigned int i;
462 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
464 if (!name)
466 WARN("Invalid argument specified\n");
467 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
470 for (i = 0; i < This->constant_buffer_count; ++i)
472 struct d3dcompiler_shader_reflection_constant_buffer *d = &This->constant_buffers[i];
474 if (!strcmp(d->name, name))
476 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d);
477 return &d->ID3D11ShaderReflectionConstantBuffer_iface;
481 WARN("Invalid name specified\n");
483 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
486 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDesc(
487 ID3D11ShaderReflection *iface, UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc)
489 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
491 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
493 if (!desc || index >= reflection->bound_resource_count)
495 WARN("Invalid argument specified\n");
496 return E_INVALIDARG;
499 memcpy(desc, &reflection->bound_resources[index],
500 reflection->interface_version == D3DCOMPILER_REFLECTION_VERSION_D3D12
501 ? sizeof(D3D12_SHADER_INPUT_BIND_DESC) : sizeof(D3D11_SHADER_INPUT_BIND_DESC));
503 return S_OK;
506 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetInputParameterDesc(
507 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
509 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
511 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
513 if (!desc || !reflection->isgn || index >= reflection->isgn->element_count)
515 WARN("Invalid argument specified\n");
516 return E_INVALIDARG;
519 *desc = reflection->isgn->elements[index];
521 return S_OK;
524 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetOutputParameterDesc(
525 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
527 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
529 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
531 if (!desc || !reflection->osgn || index >= reflection->osgn->element_count)
533 WARN("Invalid argument specified\n");
534 return E_INVALIDARG;
537 *desc = reflection->osgn->elements[index];
539 return S_OK;
542 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
543 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
545 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
547 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
549 if (!desc || !reflection->pcsg || index >= reflection->pcsg->element_count)
551 WARN("Invalid argument specified\n");
552 return E_INVALIDARG;
555 *desc = reflection->pcsg->elements[index];
557 return S_OK;
560 static struct ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetVariableByName(
561 ID3D11ShaderReflection *iface, const char *name)
563 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
564 unsigned int i, k;
566 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
568 if (!name)
570 WARN("Invalid name specified\n");
571 return &null_variable.ID3D11ShaderReflectionVariable_iface;
574 for (i = 0; i < This->constant_buffer_count; ++i)
576 struct d3dcompiler_shader_reflection_constant_buffer *cb = &This->constant_buffers[i];
578 for (k = 0; k < cb->variable_count; ++k)
580 struct d3dcompiler_shader_reflection_variable *v = &cb->variables[k];
582 if (!strcmp(v->name, name))
584 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
585 return &v->ID3D11ShaderReflectionVariable_iface;
590 WARN("Invalid name specified\n");
592 return &null_variable.ID3D11ShaderReflectionVariable_iface;
595 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDescByName(
596 ID3D11ShaderReflection *iface, const char *name, D3D11_SHADER_INPUT_BIND_DESC *desc)
598 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
599 unsigned int i;
601 TRACE("iface %p, name %s, desc %p\n", iface, debugstr_a(name), desc);
603 if (!desc || !name)
605 WARN("Invalid argument specified\n");
606 return E_INVALIDARG;
609 for (i = 0; i < reflection->bound_resource_count; ++i)
611 D3D12_SHADER_INPUT_BIND_DESC *d = &reflection->bound_resources[i];
613 if (!strcmp(d->Name, name))
615 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d);
616 memcpy(desc, d, reflection->interface_version == D3DCOMPILER_REFLECTION_VERSION_D3D12
617 ? sizeof(D3D12_SHADER_INPUT_BIND_DESC) : sizeof(D3D11_SHADER_INPUT_BIND_DESC));
618 return S_OK;
622 WARN("Invalid name specified\n");
624 return E_INVALIDARG;
627 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovInstructionCount(
628 ID3D11ShaderReflection *iface)
630 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
632 TRACE("iface %p\n", iface);
634 return This->mov_instruction_count;
637 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovcInstructionCount(
638 ID3D11ShaderReflection *iface)
640 FIXME("iface %p stub!\n", iface);
642 return 0;
645 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConversionInstructionCount(
646 ID3D11ShaderReflection *iface)
648 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
650 TRACE("iface %p\n", iface);
652 return This->conversion_instruction_count;
655 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
656 ID3D11ShaderReflection *iface)
658 FIXME("iface %p stub!\n", iface);
660 return 0;
663 static D3D_PRIMITIVE STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetGSInputPrimitive(
664 ID3D11ShaderReflection *iface)
666 FIXME("iface %p stub!\n", iface);
668 return 0;
671 static BOOL STDMETHODCALLTYPE d3dcompiler_shader_reflection_IsSampleFrequencyShader(
672 ID3D11ShaderReflection *iface)
674 FIXME("iface %p stub!\n", iface);
676 return FALSE;
679 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetNumInterfaceSlots(
680 ID3D11ShaderReflection *iface)
682 FIXME("iface %p stub!\n", iface);
684 return 0;
687 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMinFeatureLevel(
688 ID3D11ShaderReflection *iface, D3D_FEATURE_LEVEL *level)
690 FIXME("iface %p, level %p stub!\n", iface, level);
692 return E_NOTIMPL;
695 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetThreadGroupSize(
696 ID3D11ShaderReflection *iface, UINT *sizex, UINT *sizey, UINT *sizez)
698 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface, sizex, sizey, sizez);
700 return 0;
703 static UINT64 STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetRequiresFlags(
704 ID3D11ShaderReflection *iface)
706 FIXME("iface %p stub!\n", iface);
708 return 0;
711 static const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl =
713 /* IUnknown methods */
714 d3dcompiler_shader_reflection_QueryInterface,
715 d3dcompiler_shader_reflection_AddRef,
716 d3dcompiler_shader_reflection_Release,
717 /* ID3D11ShaderReflection methods */
718 d3dcompiler_shader_reflection_GetDesc,
719 d3dcompiler_shader_reflection_GetConstantBufferByIndex,
720 d3dcompiler_shader_reflection_GetConstantBufferByName,
721 d3dcompiler_shader_reflection_GetResourceBindingDesc,
722 d3dcompiler_shader_reflection_GetInputParameterDesc,
723 d3dcompiler_shader_reflection_GetOutputParameterDesc,
724 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc,
725 d3dcompiler_shader_reflection_GetVariableByName,
726 d3dcompiler_shader_reflection_GetResourceBindingDescByName,
727 d3dcompiler_shader_reflection_GetMovInstructionCount,
728 d3dcompiler_shader_reflection_GetMovcInstructionCount,
729 d3dcompiler_shader_reflection_GetConversionInstructionCount,
730 d3dcompiler_shader_reflection_GetBitwiseInstructionCount,
731 d3dcompiler_shader_reflection_GetGSInputPrimitive,
732 d3dcompiler_shader_reflection_IsSampleFrequencyShader,
733 d3dcompiler_shader_reflection_GetNumInterfaceSlots,
734 d3dcompiler_shader_reflection_GetMinFeatureLevel,
735 d3dcompiler_shader_reflection_GetThreadGroupSize,
736 d3dcompiler_shader_reflection_GetRequiresFlags,
739 /* ID3D11ShaderReflectionConstantBuffer methods */
741 static inline struct d3dcompiler_shader_reflection_constant_buffer *impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer *iface)
743 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_constant_buffer, ID3D11ShaderReflectionConstantBuffer_iface);
746 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetDesc(
747 ID3D11ShaderReflectionConstantBuffer *iface, D3D11_SHADER_BUFFER_DESC *desc)
749 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
751 TRACE("iface %p, desc %p\n", iface, desc);
753 if (This == &null_constant_buffer)
755 WARN("Null constant buffer specified\n");
756 return E_FAIL;
759 if (!desc)
761 WARN("Invalid argument specified\n");
762 return E_FAIL;
765 desc->Name = This->name;
766 desc->Type = This->type;
767 desc->Variables = This->variable_count;
768 desc->Size = This->size;
769 desc->uFlags = This->flags;
771 return S_OK;
774 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
775 ID3D11ShaderReflectionConstantBuffer *iface, UINT index)
777 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
779 TRACE("iface %p, index %u\n", iface, index);
781 if (index >= This->variable_count)
783 WARN("Invalid index specified\n");
784 return &null_variable.ID3D11ShaderReflectionVariable_iface;
787 return &This->variables[index].ID3D11ShaderReflectionVariable_iface;
790 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
791 ID3D11ShaderReflectionConstantBuffer *iface, const char *name)
793 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
794 unsigned int i;
796 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
798 if (!name)
800 WARN("Invalid argument specified\n");
801 return &null_variable.ID3D11ShaderReflectionVariable_iface;
804 for (i = 0; i < This->variable_count; ++i)
806 struct d3dcompiler_shader_reflection_variable *v = &This->variables[i];
808 if (!strcmp(v->name, name))
810 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
811 return &v->ID3D11ShaderReflectionVariable_iface;
815 WARN("Invalid name specified\n");
817 return &null_variable.ID3D11ShaderReflectionVariable_iface;
820 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl =
822 /* ID3D11ShaderReflectionConstantBuffer methods */
823 d3dcompiler_shader_reflection_constant_buffer_GetDesc,
824 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex,
825 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName,
828 /* ID3D11ShaderReflectionVariable methods */
830 static inline struct d3dcompiler_shader_reflection_variable *impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable *iface)
832 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_variable, ID3D11ShaderReflectionVariable_iface);
835 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetDesc(
836 ID3D11ShaderReflectionVariable *iface, D3D11_SHADER_VARIABLE_DESC *desc)
838 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
840 TRACE("iface %p, desc %p\n", iface, desc);
842 if (This == &null_variable)
844 WARN("Null variable specified\n");
845 return E_FAIL;
848 if (!desc)
850 WARN("Invalid argument specified\n");
851 return E_FAIL;
854 desc->Name = This->name;
855 desc->StartOffset = This->start_offset;
856 desc->Size = This->size;
857 desc->uFlags = This->flags;
858 desc->DefaultValue = This->default_value;
860 /* TODO test and set proper values for texture. */
861 desc->StartTexture = 0xffffffff;
862 desc->TextureSize = 0;
863 desc->StartSampler = 0xffffffff;
864 desc->SamplerSize = 0;
866 return S_OK;
869 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetType(
870 ID3D11ShaderReflectionVariable *iface)
872 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
874 TRACE("iface %p\n", iface);
876 return &This->type->ID3D11ShaderReflectionType_iface;
879 static ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetBuffer(
880 ID3D11ShaderReflectionVariable *iface)
882 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
884 TRACE("iface %p\n", iface);
886 return &This->constant_buffer->ID3D11ShaderReflectionConstantBuffer_iface;
889 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
890 ID3D11ShaderReflectionVariable *iface, UINT index)
892 FIXME("iface %p, index %u stub!\n", iface, index);
894 return 0;
897 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl =
899 /* ID3D11ShaderReflectionVariable methods */
900 d3dcompiler_shader_reflection_variable_GetDesc,
901 d3dcompiler_shader_reflection_variable_GetType,
902 d3dcompiler_shader_reflection_variable_GetBuffer,
903 d3dcompiler_shader_reflection_variable_GetInterfaceSlot,
906 /* ID3D11ShaderReflectionType methods */
908 static inline struct d3dcompiler_shader_reflection_type *impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType *iface)
910 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_type, ID3D11ShaderReflectionType_iface);
913 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetDesc(
914 ID3D11ShaderReflectionType *iface, D3D11_SHADER_TYPE_DESC *desc)
916 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
918 TRACE("iface %p, desc %p\n", iface, desc);
920 if (This == &null_type)
922 WARN("Null type specified\n");
923 return E_FAIL;
926 if (!desc)
928 WARN("Invalid argument specified\n");
929 return E_FAIL;
932 *desc = This->desc;
934 return S_OK;
937 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
938 ID3D11ShaderReflectionType *iface, UINT index)
940 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
942 TRACE("iface %p, index %u\n", iface, index);
944 if (index >= This->desc.Members)
946 WARN("Invalid index specified\n");
947 return &null_type.ID3D11ShaderReflectionType_iface;
950 return &This->members[index].type->ID3D11ShaderReflectionType_iface;
953 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByName(
954 ID3D11ShaderReflectionType *iface, const char *name)
956 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
957 unsigned int i;
959 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
961 if (!name)
963 WARN("Invalid argument specified\n");
964 return &null_type.ID3D11ShaderReflectionType_iface;
967 for (i = 0; i < This->desc.Members; ++i)
969 struct d3dcompiler_shader_reflection_type_member *member = &This->members[i];
971 if (!strcmp(member->name, name))
973 TRACE("Returning ID3D11ShaderReflectionType %p.\n", member->type);
974 return &member->type->ID3D11ShaderReflectionType_iface;
978 WARN("Invalid name specified\n");
980 return &null_type.ID3D11ShaderReflectionType_iface;
983 static const char * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeName(
984 ID3D11ShaderReflectionType *iface, UINT index)
986 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
988 TRACE("iface %p, index %u\n", iface, index);
990 if (This == &null_type)
992 WARN("Null type specified\n");
993 return "$Invalid";
996 if (index >= This->desc.Members)
998 WARN("Invalid index specified\n");
999 return NULL;
1002 return This->members[index].name;
1005 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsEqual(
1006 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
1008 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
1010 TRACE("iface %p, type %p\n", iface, type);
1012 if (This == &null_type)
1014 WARN("Null type specified\n");
1015 return E_FAIL;
1018 if (iface == type)
1019 return S_OK;
1021 return S_FALSE;
1024 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetSubType(
1025 ID3D11ShaderReflectionType *iface)
1027 FIXME("iface %p stub!\n", iface);
1029 return NULL;
1032 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetBaseClass(
1033 ID3D11ShaderReflectionType *iface)
1035 FIXME("iface %p stub!\n", iface);
1037 return NULL;
1040 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetNumInterfaces(
1041 ID3D11ShaderReflectionType *iface)
1043 FIXME("iface %p stub!\n", iface);
1045 return 0;
1048 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
1049 ID3D11ShaderReflectionType *iface, UINT index)
1051 FIXME("iface %p, index %u stub!\n", iface, index);
1053 return NULL;
1056 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsOfType(
1057 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
1059 FIXME("iface %p, type %p stub!\n", iface, type);
1061 return E_NOTIMPL;
1064 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_ImplementsInterface(
1065 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *base)
1067 FIXME("iface %p, base %p stub!\n", iface, base);
1069 return E_NOTIMPL;
1072 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl =
1074 /* ID3D11ShaderReflectionType methods */
1075 d3dcompiler_shader_reflection_type_GetDesc,
1076 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex,
1077 d3dcompiler_shader_reflection_type_GetMemberTypeByName,
1078 d3dcompiler_shader_reflection_type_GetMemberTypeName,
1079 d3dcompiler_shader_reflection_type_IsEqual,
1080 d3dcompiler_shader_reflection_type_GetSubType,
1081 d3dcompiler_shader_reflection_type_GetBaseClass,
1082 d3dcompiler_shader_reflection_type_GetNumInterfaces,
1083 d3dcompiler_shader_reflection_type_GetInterfaceByIndex,
1084 d3dcompiler_shader_reflection_type_IsOfType,
1085 d3dcompiler_shader_reflection_type_ImplementsInterface,
1088 static HRESULT d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1090 const char *ptr = data;
1091 DWORD size = data_size >> 2;
1093 TRACE("Size %u\n", size);
1095 read_dword(&ptr, &r->instruction_count);
1096 TRACE("InstructionCount: %u\n", r->instruction_count);
1098 read_dword(&ptr, &r->temp_register_count);
1099 TRACE("TempRegisterCount: %u\n", r->temp_register_count);
1101 skip_dword_unknown(&ptr, 1);
1103 read_dword(&ptr, &r->dcl_count);
1104 TRACE("DclCount: %u\n", r->dcl_count);
1106 read_dword(&ptr, &r->float_instruction_count);
1107 TRACE("FloatInstructionCount: %u\n", r->float_instruction_count);
1109 read_dword(&ptr, &r->int_instruction_count);
1110 TRACE("IntInstructionCount: %u\n", r->int_instruction_count);
1112 read_dword(&ptr, &r->uint_instruction_count);
1113 TRACE("UintInstructionCount: %u\n", r->uint_instruction_count);
1115 read_dword(&ptr, &r->static_flow_control_count);
1116 TRACE("StaticFlowControlCount: %u\n", r->static_flow_control_count);
1118 read_dword(&ptr, &r->dynamic_flow_control_count);
1119 TRACE("DynamicFlowControlCount: %u\n", r->dynamic_flow_control_count);
1121 skip_dword_unknown(&ptr, 1);
1123 read_dword(&ptr, &r->temp_array_count);
1124 TRACE("TempArrayCount: %u\n", r->temp_array_count);
1126 read_dword(&ptr, &r->array_instruction_count);
1127 TRACE("ArrayInstructionCount: %u\n", r->array_instruction_count);
1129 read_dword(&ptr, &r->cut_instruction_count);
1130 TRACE("CutInstructionCount: %u\n", r->cut_instruction_count);
1132 read_dword(&ptr, &r->emit_instruction_count);
1133 TRACE("EmitInstructionCount: %u\n", r->emit_instruction_count);
1135 read_dword(&ptr, &r->texture_normal_instructions);
1136 TRACE("TextureNormalInstructions: %u\n", r->texture_normal_instructions);
1138 read_dword(&ptr, &r->texture_load_instructions);
1139 TRACE("TextureLoadInstructions: %u\n", r->texture_load_instructions);
1141 read_dword(&ptr, &r->texture_comp_instructions);
1142 TRACE("TextureCompInstructions: %u\n", r->texture_comp_instructions);
1144 read_dword(&ptr, &r->texture_bias_instructions);
1145 TRACE("TextureBiasInstructions: %u\n", r->texture_bias_instructions);
1147 read_dword(&ptr, &r->texture_gradient_instructions);
1148 TRACE("TextureGradientInstructions: %u\n", r->texture_gradient_instructions);
1150 read_dword(&ptr, &r->mov_instruction_count);
1151 TRACE("MovInstructionCount: %u\n", r->mov_instruction_count);
1153 skip_dword_unknown(&ptr, 1);
1155 read_dword(&ptr, &r->conversion_instruction_count);
1156 TRACE("ConversionInstructionCount: %u\n", r->conversion_instruction_count);
1158 skip_dword_unknown(&ptr, 1);
1160 read_dword(&ptr, &r->input_primitive);
1161 TRACE("InputPrimitive: %x\n", r->input_primitive);
1163 read_dword(&ptr, &r->gs_output_topology);
1164 TRACE("GSOutputTopology: %x\n", r->gs_output_topology);
1166 read_dword(&ptr, &r->gs_max_output_vertex_count);
1167 TRACE("GSMaxOutputVertexCount: %u\n", r->gs_max_output_vertex_count);
1169 skip_dword_unknown(&ptr, 2);
1171 /* old dx10 stat size */
1172 if (size == 28) return S_OK;
1174 skip_dword_unknown(&ptr, 1);
1176 /* dx10 stat size */
1177 if (size == 29) return S_OK;
1179 skip_dword_unknown(&ptr, 1);
1181 read_dword(&ptr, &r->c_control_points);
1182 TRACE("cControlPoints: %u\n", r->c_control_points);
1184 read_dword(&ptr, &r->hs_output_primitive);
1185 TRACE("HSOutputPrimitive: %x\n", r->hs_output_primitive);
1187 read_dword(&ptr, &r->hs_prtitioning);
1188 TRACE("HSPartitioning: %x\n", r->hs_prtitioning);
1190 read_dword(&ptr, &r->tessellator_domain);
1191 TRACE("TessellatorDomain: %x\n", r->tessellator_domain);
1193 skip_dword_unknown(&ptr, 3);
1195 /* dx11 stat size */
1196 if (size == 37) return S_OK;
1198 FIXME("Unhandled size %u\n", size);
1200 return E_FAIL;
1203 static HRESULT d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection *ref,
1204 struct d3dcompiler_shader_reflection_type_member *member, const char *data, const char **ptr)
1206 DWORD offset;
1208 read_dword(ptr, &offset);
1209 if (!copy_name(data + offset, &member->name))
1211 ERR("Failed to copy name.\n");
1212 return E_OUTOFMEMORY;
1214 TRACE("Member name: %s.\n", debugstr_a(member->name));
1216 read_dword(ptr, &offset);
1217 TRACE("Member type offset: %x\n", offset);
1219 member->type = get_reflection_type(ref, data, offset);
1220 if (!member->type)
1222 ERR("Failed to get member type\n");
1223 HeapFree(GetProcessHeap(), 0, member->name);
1224 return E_FAIL;
1227 read_dword(ptr, &member->offset);
1228 TRACE("Member offset %x\n", member->offset);
1230 return S_OK;
1233 static HRESULT d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type *type, const char *data, DWORD offset)
1235 const char *ptr = data + offset;
1236 DWORD temp;
1237 D3D11_SHADER_TYPE_DESC *desc;
1238 unsigned int i;
1239 struct d3dcompiler_shader_reflection_type_member *members = NULL;
1240 HRESULT hr;
1241 DWORD member_offset;
1243 desc = &type->desc;
1245 read_dword(&ptr, &temp);
1246 desc->Class = temp & 0xffff;
1247 desc->Type = temp >> 16;
1248 TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc->Class),
1249 debug_d3dcompiler_shader_variable_type(desc->Type));
1251 read_dword(&ptr, &temp);
1252 desc->Rows = temp & 0xffff;
1253 desc->Columns = temp >> 16;
1254 TRACE("Rows %u, Columns %u\n", desc->Rows, desc->Columns);
1256 read_dword(&ptr, &temp);
1257 desc->Elements = temp & 0xffff;
1258 desc->Members = temp >> 16;
1259 TRACE("Elements %u, Members %u\n", desc->Elements, desc->Members);
1261 read_dword(&ptr, &member_offset);
1262 TRACE("Member Offset %u\n", member_offset);
1264 if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1265 skip_dword_unknown(&ptr, 4);
1267 if (desc->Members)
1269 const char *ptr2 = data + member_offset;
1271 members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*members) * desc->Members);
1272 if (!members)
1274 ERR("Failed to allocate type memory.\n");
1275 return E_OUTOFMEMORY;
1278 for (i = 0; i < desc->Members; ++i)
1280 hr = d3dcompiler_parse_type_members(type->reflection, &members[i], data, &ptr2);
1281 if (hr != S_OK)
1283 FIXME("Failed to parse type members.\n");
1284 goto err_out;
1289 if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1291 read_dword(&ptr, &offset);
1292 if (!copy_name(data + offset, &type->name))
1294 ERR("Failed to copy name.\n");
1295 heap_free(members);
1296 return E_OUTOFMEMORY;
1298 desc->Name = type->name;
1299 TRACE("Type name: %s.\n", debugstr_a(type->name));
1302 type->members = members;
1304 return S_OK;
1306 err_out:
1307 for (i = 0; i < desc->Members; ++i)
1309 free_type_member(&members[i]);
1311 HeapFree(GetProcessHeap(), 0, members);
1312 return hr;
1315 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset)
1317 struct d3dcompiler_shader_reflection_type *type;
1318 struct wine_rb_entry *entry;
1319 HRESULT hr;
1321 entry = wine_rb_get(&reflection->types, &offset);
1322 if (entry)
1324 TRACE("Returning existing type.\n");
1325 return WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
1328 type = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*type));
1329 if (!type)
1330 return NULL;
1332 type->ID3D11ShaderReflectionType_iface.lpVtbl = &d3dcompiler_shader_reflection_type_vtbl;
1333 type->ID3D10ShaderReflectionType_iface.lpVtbl = &d3d10_shader_reflection_type_vtbl;
1334 type->id = offset;
1335 type->reflection = reflection;
1337 hr = d3dcompiler_parse_type(type, data, offset);
1338 if (FAILED(hr))
1340 ERR("Failed to parse type info, hr %#x.\n", hr);
1341 HeapFree(GetProcessHeap(), 0, type);
1342 return NULL;
1345 if (wine_rb_put(&reflection->types, &offset, &type->entry) == -1)
1347 ERR("Failed to insert type entry.\n");
1348 HeapFree(GetProcessHeap(), 0, type);
1349 return NULL;
1352 return type;
1355 static HRESULT d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer *cb,
1356 const char *data, DWORD data_size, const char *ptr)
1358 struct d3dcompiler_shader_reflection_variable *variables;
1359 unsigned int i;
1360 HRESULT hr;
1362 variables = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb->variable_count * sizeof(*variables));
1363 if (!variables)
1365 ERR("Failed to allocate variables memory.\n");
1366 return E_OUTOFMEMORY;
1369 for (i = 0; i < cb->variable_count; i++)
1371 struct d3dcompiler_shader_reflection_variable *v = &variables[i];
1372 DWORD offset;
1374 v->ID3D11ShaderReflectionVariable_iface.lpVtbl = &d3dcompiler_shader_reflection_variable_vtbl;
1375 v->ID3D10ShaderReflectionVariable_iface.lpVtbl = &d3d10_shader_reflection_variable_vtbl;
1376 v->constant_buffer = cb;
1378 read_dword(&ptr, &offset);
1379 if (!copy_name(data + offset, &v->name))
1381 ERR("Failed to copy name.\n");
1382 hr = E_OUTOFMEMORY;
1383 goto err_out;
1385 TRACE("Variable name: %s.\n", debugstr_a(v->name));
1387 read_dword(&ptr, &v->start_offset);
1388 TRACE("Variable offset: %u\n", v->start_offset);
1390 read_dword(&ptr, &v->size);
1391 TRACE("Variable size: %u\n", v->size);
1393 read_dword(&ptr, &v->flags);
1394 TRACE("Variable flags: %u\n", v->flags);
1396 read_dword(&ptr, &offset);
1397 TRACE("Variable type offset: %x\n", offset);
1398 v->type = get_reflection_type(cb->reflection, data, offset);
1399 if (!v->type)
1401 ERR("Failed to get type.\n");
1402 hr = E_FAIL;
1403 goto err_out;
1406 read_dword(&ptr, &offset);
1407 TRACE("Variable default value offset: %x\n", offset);
1408 if (!copy_value(data + offset, &v->default_value, offset ? v->size : 0))
1410 ERR("Failed to copy name.\n");
1411 hr = E_OUTOFMEMORY;
1412 goto err_out;
1415 if ((cb->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1416 skip_dword_unknown(&ptr, 4);
1419 cb->variables = variables;
1421 return S_OK;
1423 err_out:
1424 for (i = 0; i < cb->variable_count; i++)
1426 free_variable(&variables[i]);
1428 HeapFree(GetProcessHeap(), 0, variables);
1429 return hr;
1432 static HRESULT d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1434 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers = NULL;
1435 DWORD offset, cbuffer_offset, resource_offset, creator_offset;
1436 unsigned int i, string_data_offset, string_data_size;
1437 D3D12_SHADER_INPUT_BIND_DESC *bound_resources = NULL;
1438 char *string_data = NULL, *creator = NULL;
1439 DWORD size = data_size >> 2;
1440 const char *ptr = data;
1441 DWORD target_version;
1442 HRESULT hr;
1444 TRACE("Size %u\n", size);
1446 read_dword(&ptr, &r->constant_buffer_count);
1447 TRACE("Constant buffer count: %u\n", r->constant_buffer_count);
1449 read_dword(&ptr, &cbuffer_offset);
1450 TRACE("Constant buffer offset: %#x\n", cbuffer_offset);
1452 read_dword(&ptr, &r->bound_resource_count);
1453 TRACE("Bound resource count: %u\n", r->bound_resource_count);
1455 read_dword(&ptr, &resource_offset);
1456 TRACE("Bound resource offset: %#x\n", resource_offset);
1458 read_dword(&ptr, &r->target);
1459 TRACE("Target: %#x\n", r->target);
1461 target_version = r->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK;
1463 #if D3D_COMPILER_VERSION < 47
1464 if (target_version >= 0x501)
1466 WARN("Target version %#x is not supported in d3dcompiler %u.\n", target_version, D3D_COMPILER_VERSION);
1467 return E_INVALIDARG;
1469 #endif
1471 read_dword(&ptr, &r->flags);
1472 TRACE("Flags: %u\n", r->flags);
1474 read_dword(&ptr, &creator_offset);
1475 TRACE("Creator at offset %#x.\n", creator_offset);
1477 if (!copy_name(data + creator_offset, &creator))
1479 ERR("Failed to copy name.\n");
1480 return E_OUTOFMEMORY;
1482 TRACE("Creator: %s.\n", debugstr_a(creator));
1484 /* todo: Parse RD11 */
1485 if (target_version >= 0x500)
1487 skip_dword_unknown(&ptr, 8);
1490 if (r->bound_resource_count)
1492 /* 8 for each bind desc */
1493 string_data_offset = resource_offset + r->bound_resource_count * 8 * sizeof(DWORD);
1494 string_data_size = (cbuffer_offset ? cbuffer_offset : creator_offset) - string_data_offset;
1496 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1497 if (!string_data)
1499 ERR("Failed to allocate string data memory.\n");
1500 hr = E_OUTOFMEMORY;
1501 goto err_out;
1503 memcpy(string_data, data + string_data_offset, string_data_size);
1505 bound_resources = HeapAlloc(GetProcessHeap(), 0, r->bound_resource_count * sizeof(*bound_resources));
1506 if (!bound_resources)
1508 ERR("Failed to allocate resources memory.\n");
1509 hr = E_OUTOFMEMORY;
1510 goto err_out;
1513 ptr = data + resource_offset;
1514 for (i = 0; i < r->bound_resource_count; i++)
1516 D3D12_SHADER_INPUT_BIND_DESC *desc = &bound_resources[i];
1518 read_dword(&ptr, &offset);
1519 desc->Name = string_data + (offset - string_data_offset);
1520 TRACE("Input bind Name: %s\n", debugstr_a(desc->Name));
1522 read_dword(&ptr, &desc->Type);
1523 TRACE("Input bind Type: %#x\n", desc->Type);
1525 read_dword(&ptr, &desc->ReturnType);
1526 TRACE("Input bind ReturnType: %#x\n", desc->ReturnType);
1528 read_dword(&ptr, &desc->Dimension);
1529 TRACE("Input bind Dimension: %#x\n", desc->Dimension);
1531 read_dword(&ptr, &desc->NumSamples);
1532 TRACE("Input bind NumSamples: %u\n", desc->NumSamples);
1534 read_dword(&ptr, &desc->BindPoint);
1535 TRACE("Input bind BindPoint: %u\n", desc->BindPoint);
1537 read_dword(&ptr, &desc->BindCount);
1538 TRACE("Input bind BindCount: %u\n", desc->BindCount);
1540 read_dword(&ptr, &desc->uFlags);
1541 TRACE("Input bind uFlags: %u\n", desc->uFlags);
1543 if (target_version >= 0x501)
1545 read_dword(&ptr, &desc->Space);
1546 TRACE("Input bind Space %u.\n", desc->Space);
1547 read_dword(&ptr, &desc->uID);
1548 TRACE("Input bind uID %u.\n", desc->uID);
1550 else
1552 desc->Space = 0;
1553 desc->uID = desc->BindPoint;
1558 if (r->constant_buffer_count)
1560 constant_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, r->constant_buffer_count * sizeof(*constant_buffers));
1561 if (!constant_buffers)
1563 ERR("Failed to allocate constant buffer memory.\n");
1564 hr = E_OUTOFMEMORY;
1565 goto err_out;
1568 ptr = data + cbuffer_offset;
1569 for (i = 0; i < r->constant_buffer_count; i++)
1571 struct d3dcompiler_shader_reflection_constant_buffer *cb = &constant_buffers[i];
1573 cb->ID3D11ShaderReflectionConstantBuffer_iface.lpVtbl = &d3dcompiler_shader_reflection_constant_buffer_vtbl;
1574 cb->ID3D10ShaderReflectionConstantBuffer_iface.lpVtbl = &d3d10_shader_reflection_constant_buffer_vtbl;
1575 cb->reflection = r;
1577 read_dword(&ptr, &offset);
1578 if (!copy_name(data + offset, &cb->name))
1580 ERR("Failed to copy name.\n");
1581 hr = E_OUTOFMEMORY;
1582 goto err_out;
1584 TRACE("Name: %s.\n", debugstr_a(cb->name));
1586 read_dword(&ptr, &cb->variable_count);
1587 TRACE("Variable count: %u\n", cb->variable_count);
1589 read_dword(&ptr, &offset);
1590 TRACE("Variable offset: %x\n", offset);
1592 hr = d3dcompiler_parse_variables(cb, data, data_size, data + offset);
1593 if (hr != S_OK)
1595 FIXME("Failed to parse variables.\n");
1596 goto err_out;
1599 read_dword(&ptr, &cb->size);
1600 TRACE("Cbuffer size: %u\n", cb->size);
1602 read_dword(&ptr, &cb->flags);
1603 TRACE("Cbuffer flags: %u\n", cb->flags);
1605 read_dword(&ptr, &cb->type);
1606 TRACE("Cbuffer type: %#x\n", cb->type);
1610 r->creator = creator;
1611 r->resource_string = string_data;
1612 r->bound_resources = bound_resources;
1613 r->constant_buffers = constant_buffers;
1615 return S_OK;
1617 err_out:
1618 for (i = 0; i < r->constant_buffer_count; ++i)
1620 free_constant_buffer(&constant_buffers[i]);
1622 HeapFree(GetProcessHeap(), 0, constant_buffers);
1623 HeapFree(GetProcessHeap(), 0, bound_resources);
1624 HeapFree(GetProcessHeap(), 0, string_data);
1625 HeapFree(GetProcessHeap(), 0, creator);
1627 return hr;
1630 static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section)
1632 D3D11_SIGNATURE_PARAMETER_DESC *d;
1633 unsigned int string_data_offset;
1634 unsigned int string_data_size;
1635 const char *ptr = section->data;
1636 char *string_data;
1637 unsigned int i;
1638 DWORD count;
1639 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size;
1641 switch (section->tag)
1643 case TAG_OSG5:
1644 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7;
1645 break;
1647 case TAG_ISGN:
1648 case TAG_OSGN:
1649 case TAG_PCSG:
1650 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1651 break;
1653 default:
1654 FIXME("Unhandled section %s!\n", debugstr_an((const char *)&section->tag, 4));
1655 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1656 break;
1659 read_dword(&ptr, &count);
1660 TRACE("%u elements\n", count);
1662 skip_dword_unknown(&ptr, 1);
1664 d = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*d));
1665 if (!d)
1667 ERR("Failed to allocate signature memory.\n");
1668 return E_OUTOFMEMORY;
1671 /* 2 DWORDs for the header, element_size for each element. */
1672 string_data_offset = 2 * sizeof(DWORD) + count * element_size * sizeof(DWORD);
1673 string_data_size = section->data_size - string_data_offset;
1675 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1676 if (!string_data)
1678 ERR("Failed to allocate string data memory.\n");
1679 HeapFree(GetProcessHeap(), 0, d);
1680 return E_OUTOFMEMORY;
1682 memcpy(string_data, section->data + string_data_offset, string_data_size);
1684 for (i = 0; i < count; ++i)
1686 UINT name_offset;
1687 DWORD mask;
1689 #if D3D_COMPILER_VERSION >= 46
1690 /* FIXME */
1691 d[i].MinPrecision = D3D_MIN_PRECISION_DEFAULT;
1692 #endif
1693 if (element_size == D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7)
1695 read_dword(&ptr, &d[i].Stream);
1697 else
1699 d[i].Stream = 0;
1702 read_dword(&ptr, &name_offset);
1703 d[i].SemanticName = string_data + (name_offset - string_data_offset);
1704 read_dword(&ptr, &d[i].SemanticIndex);
1705 read_dword(&ptr, &d[i].SystemValueType);
1706 read_dword(&ptr, &d[i].ComponentType);
1707 read_dword(&ptr, &d[i].Register);
1708 read_dword(&ptr, &mask);
1709 d[i].ReadWriteMask = (mask >> 8) & 0xff;
1710 d[i].Mask = mask & 0xff;
1712 if (!stricmp(d[i].SemanticName, "sv_depth"))
1713 d[i].SystemValueType = D3D_NAME_DEPTH;
1714 else if (!stricmp(d[i].SemanticName, "sv_coverage"))
1715 d[i].SystemValueType = D3D_NAME_COVERAGE;
1716 else if (!stricmp(d[i].SemanticName, "sv_depthgreaterequal"))
1717 d[i].SystemValueType = D3D_NAME_DEPTH_GREATER_EQUAL;
1718 else if (!stricmp(d[i].SemanticName, "sv_depthlessequal"))
1719 d[i].SystemValueType = D3D_NAME_DEPTH_LESS_EQUAL;
1720 else if (!stricmp(d[i].SemanticName, "sv_target"))
1721 d[i].SystemValueType = D3D_NAME_TARGET;
1723 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
1724 "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n",
1725 debugstr_a(d[i].SemanticName), d[i].SemanticIndex, d[i].SystemValueType,
1726 d[i].ComponentType, d[i].Register, d[i].Mask, d[i].ReadWriteMask, d[i].Stream);
1729 s->elements = d;
1730 s->element_count = count;
1731 s->string_data = string_data;
1733 return S_OK;
1736 static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1738 const char *ptr = data;
1740 read_dword(&ptr, &r->version);
1741 TRACE("Shader version: %u\n", r->version);
1743 /* todo: Check if anything else is needed from the shdr or shex blob. */
1745 return S_OK;
1748 static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection,
1749 const void *data, SIZE_T data_size)
1751 struct dxbc src_dxbc;
1752 HRESULT hr;
1753 unsigned int i;
1755 wine_rb_init(&reflection->types, d3dcompiler_shader_reflection_type_compare);
1757 hr = dxbc_parse(data, data_size, &src_dxbc);
1758 if (FAILED(hr))
1760 WARN("Failed to parse reflection\n");
1761 return hr;
1764 for (i = 0; i < src_dxbc.count; ++i)
1766 struct dxbc_section *section = &src_dxbc.sections[i];
1768 switch (section->tag)
1770 case TAG_RDEF:
1771 hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size);
1772 if (FAILED(hr))
1774 WARN("Failed to parse RDEF section.\n");
1775 goto err_out;
1777 break;
1779 case TAG_ISGN:
1780 reflection->isgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->isgn));
1781 if (!reflection->isgn)
1783 ERR("Failed to allocate ISGN memory.\n");
1784 hr = E_OUTOFMEMORY;
1785 goto err_out;
1788 hr = d3dcompiler_parse_signature(reflection->isgn, section);
1789 if (FAILED(hr))
1791 WARN("Failed to parse section ISGN.\n");
1792 goto err_out;
1794 break;
1796 case TAG_OSG5:
1797 case TAG_OSGN:
1798 reflection->osgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->osgn));
1799 if (!reflection->osgn)
1801 ERR("Failed to allocate OSGN memory.\n");
1802 hr = E_OUTOFMEMORY;
1803 goto err_out;
1806 hr = d3dcompiler_parse_signature(reflection->osgn, section);
1807 if (FAILED(hr))
1809 WARN("Failed to parse section OSGN.\n");
1810 goto err_out;
1812 break;
1814 case TAG_PCSG:
1815 reflection->pcsg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->pcsg));
1816 if (!reflection->pcsg)
1818 ERR("Failed to allocate PCSG memory.\n");
1819 hr = E_OUTOFMEMORY;
1820 goto err_out;
1823 hr = d3dcompiler_parse_signature(reflection->pcsg, section);
1824 if (FAILED(hr))
1826 WARN("Failed to parse section PCSG.\n");
1827 goto err_out;
1829 break;
1831 case TAG_SHEX:
1832 case TAG_SHDR:
1833 hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size);
1834 if (FAILED(hr))
1836 WARN("Failed to parse SHDR section.\n");
1837 goto err_out;
1839 break;
1841 case TAG_STAT:
1842 hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size);
1843 if (FAILED(hr))
1845 WARN("Failed to parse section STAT.\n");
1846 goto err_out;
1848 break;
1850 default:
1851 FIXME("Unhandled section %s!\n", debugstr_an((const char *)&section->tag, 4));
1852 break;
1856 dxbc_destroy(&src_dxbc);
1858 return hr;
1860 err_out:
1861 reflection_cleanup(reflection);
1862 dxbc_destroy(&src_dxbc);
1864 return hr;
1867 /* d3d10 reflection methods. */
1868 #if !D3D_COMPILER_VERSION
1869 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D10ShaderReflection(ID3D10ShaderReflection *iface)
1871 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D10ShaderReflection_iface);
1874 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_QueryInterface(ID3D10ShaderReflection *iface,
1875 REFIID riid, void **object)
1877 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1879 if (IsEqualGUID(riid, &IID_ID3D10ShaderReflection) || IsEqualGUID(riid, &IID_IUnknown))
1881 IUnknown_AddRef(iface);
1882 *object = iface;
1883 return S_OK;
1886 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
1888 *object = NULL;
1889 return E_NOINTERFACE;
1892 static ULONG STDMETHODCALLTYPE d3d10_shader_reflection_AddRef(ID3D10ShaderReflection *iface)
1894 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1895 ULONG refcount = InterlockedIncrement(&reflection->refcount);
1897 TRACE("%p increasing refcount to %u.\n", reflection, refcount);
1899 return refcount;
1902 static ULONG STDMETHODCALLTYPE d3d10_shader_reflection_Release(ID3D10ShaderReflection *iface)
1904 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1905 ULONG refcount = InterlockedDecrement(&reflection->refcount);
1907 TRACE("%p decreasing refcount to %u.\n", reflection, refcount);
1909 if (!refcount)
1910 heap_free(reflection);
1912 return refcount;
1915 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetDesc(ID3D10ShaderReflection *iface,
1916 D3D10_SHADER_DESC *desc)
1918 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1920 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
1922 if (!desc)
1924 WARN("Invalid argument specified.\n");
1925 return E_FAIL;
1928 desc->Version = reflection->version;
1929 desc->Creator = reflection->creator;
1930 desc->Flags = reflection->flags;
1931 desc->ConstantBuffers = reflection->constant_buffer_count;
1932 desc->BoundResources = reflection->bound_resource_count;
1933 desc->InputParameters = reflection->isgn ? reflection->isgn->element_count : 0;
1934 desc->OutputParameters = reflection->osgn ? reflection->osgn->element_count : 0;
1935 desc->InstructionCount = reflection->instruction_count;
1936 desc->TempRegisterCount = reflection->temp_register_count;
1937 desc->TempArrayCount = reflection->temp_array_count;
1938 desc->DefCount = 0;
1939 desc->DclCount = reflection->dcl_count;
1940 desc->TextureNormalInstructions = reflection->texture_normal_instructions;
1941 desc->TextureLoadInstructions = reflection->texture_load_instructions;
1942 desc->TextureCompInstructions = reflection->texture_comp_instructions;
1943 desc->TextureBiasInstructions = reflection->texture_bias_instructions;
1944 desc->TextureGradientInstructions = reflection->texture_gradient_instructions;
1945 desc->FloatInstructionCount = reflection->float_instruction_count;
1946 desc->IntInstructionCount = reflection->int_instruction_count;
1947 desc->UintInstructionCount = reflection->uint_instruction_count;
1948 desc->StaticFlowControlCount = reflection->static_flow_control_count;
1949 desc->DynamicFlowControlCount = reflection->dynamic_flow_control_count;
1950 desc->MacroInstructionCount = 0;
1951 desc->ArrayInstructionCount = reflection->array_instruction_count;
1952 desc->CutInstructionCount = reflection->cut_instruction_count;
1953 desc->EmitInstructionCount = reflection->emit_instruction_count;
1954 desc->GSOutputTopology = reflection->gs_output_topology;
1955 desc->GSMaxOutputVertexCount = reflection->gs_max_output_vertex_count;
1957 return S_OK;
1960 static struct ID3D10ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3d10_shader_reflection_GetConstantBufferByIndex(
1961 ID3D10ShaderReflection *iface, UINT index)
1963 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1965 TRACE("iface %p, index %u.\n", iface, index);
1967 if (index >= reflection->constant_buffer_count)
1969 WARN("Invalid argument specified.\n");
1970 return &null_constant_buffer.ID3D10ShaderReflectionConstantBuffer_iface;
1973 return &reflection->constant_buffers[index].ID3D10ShaderReflectionConstantBuffer_iface;
1976 static struct ID3D10ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3d10_shader_reflection_GetConstantBufferByName(
1977 ID3D10ShaderReflection *iface, const char *name)
1979 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1980 unsigned int i;
1982 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
1984 if (!name)
1986 WARN("Invalid argument specified.\n");
1987 return &null_constant_buffer.ID3D10ShaderReflectionConstantBuffer_iface;
1990 for (i = 0; i < reflection->constant_buffer_count; ++i)
1992 struct d3dcompiler_shader_reflection_constant_buffer *d = &reflection->constant_buffers[i];
1994 if (!strcmp(d->name, name))
1996 TRACE("Returning ID3D10ShaderReflectionConstantBuffer %p.\n", d);
1997 return &d->ID3D10ShaderReflectionConstantBuffer_iface;
2001 WARN("Invalid name specified.\n");
2003 return &null_constant_buffer.ID3D10ShaderReflectionConstantBuffer_iface;
2006 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetResourceBindingDesc(ID3D10ShaderReflection *iface,
2007 UINT index, D3D10_SHADER_INPUT_BIND_DESC *desc)
2009 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
2011 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
2013 if (!desc || index >= reflection->bound_resource_count)
2015 WARN("Invalid argument specified.\n");
2016 return E_INVALIDARG;
2019 memcpy(desc, &reflection->bound_resources[index], sizeof(*desc));
2021 return S_OK;
2024 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetInputParameterDesc(ID3D10ShaderReflection *iface,
2025 UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc)
2027 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
2029 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
2031 if (!desc || !reflection->isgn || index >= reflection->isgn->element_count)
2033 WARN("Invalid argument specified.\n");
2034 return E_INVALIDARG;
2037 memcpy(desc, &reflection->isgn->elements[index], sizeof(*desc));
2039 return S_OK;
2042 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetOutputParameterDesc(ID3D10ShaderReflection *iface,
2043 UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc)
2045 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
2047 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
2049 if (!desc || !reflection->osgn || index >= reflection->osgn->element_count)
2051 WARN("Invalid argument specified.\n");
2052 return E_INVALIDARG;
2055 memcpy(desc, &reflection->osgn->elements[index], sizeof(*desc));
2057 return S_OK;
2060 static const struct ID3D10ShaderReflectionVtbl d3d10_shader_reflection_vtbl =
2062 d3d10_shader_reflection_QueryInterface,
2063 d3d10_shader_reflection_AddRef,
2064 d3d10_shader_reflection_Release,
2065 d3d10_shader_reflection_GetDesc,
2066 d3d10_shader_reflection_GetConstantBufferByIndex,
2067 d3d10_shader_reflection_GetConstantBufferByName,
2068 d3d10_shader_reflection_GetResourceBindingDesc,
2069 d3d10_shader_reflection_GetInputParameterDesc,
2070 d3d10_shader_reflection_GetOutputParameterDesc,
2073 static inline struct d3dcompiler_shader_reflection_constant_buffer *impl_from_ID3D10ShaderReflectionConstantBuffer(
2074 ID3D10ShaderReflectionConstantBuffer *iface)
2076 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_constant_buffer,
2077 ID3D10ShaderReflectionConstantBuffer_iface);
2080 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_constant_buffer_GetDesc(
2081 ID3D10ShaderReflectionConstantBuffer *iface, D3D10_SHADER_BUFFER_DESC *desc)
2083 struct d3dcompiler_shader_reflection_constant_buffer *cb = impl_from_ID3D10ShaderReflectionConstantBuffer(iface);
2085 TRACE("iface %p, desc %p.\n", iface, desc);
2087 if (cb == &null_constant_buffer)
2089 WARN("Null constant buffer specified.\n");
2090 return E_FAIL;
2093 if (!desc)
2095 WARN("Invalid argument specified.\n");
2096 return E_FAIL;
2099 desc->Name = cb->name;
2100 desc->Type = cb->type;
2101 desc->Variables = cb->variable_count;
2102 desc->Size = cb->size;
2103 desc->uFlags = cb->flags;
2105 return S_OK;
2108 static ID3D10ShaderReflectionVariable * STDMETHODCALLTYPE d3d10_shader_reflection_constant_buffer_GetVariableByIndex(
2109 ID3D10ShaderReflectionConstantBuffer *iface, UINT index)
2111 struct d3dcompiler_shader_reflection_constant_buffer *cb = impl_from_ID3D10ShaderReflectionConstantBuffer(iface);
2113 TRACE("iface %p, index %u.\n", iface, index);
2115 if (index >= cb->variable_count)
2117 WARN("Invalid index specified.\n");
2118 return &null_variable.ID3D10ShaderReflectionVariable_iface;
2121 return &cb->variables[index].ID3D10ShaderReflectionVariable_iface;
2124 static ID3D10ShaderReflectionVariable * STDMETHODCALLTYPE d3d10_shader_reflection_constant_buffer_GetVariableByName(
2125 ID3D10ShaderReflectionConstantBuffer *iface, const char *name)
2127 struct d3dcompiler_shader_reflection_constant_buffer *cb = impl_from_ID3D10ShaderReflectionConstantBuffer(iface);
2128 unsigned int i;
2130 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
2132 if (!name)
2134 WARN("Invalid argument specified.\n");
2135 return &null_variable.ID3D10ShaderReflectionVariable_iface;
2138 for (i = 0; i < cb->variable_count; ++i)
2140 struct d3dcompiler_shader_reflection_variable *v = &cb->variables[i];
2142 if (!strcmp(v->name, name))
2144 TRACE("Returning ID3D10ShaderReflectionVariable %p.\n", v);
2145 return &v->ID3D10ShaderReflectionVariable_iface;
2149 WARN("Invalid name specified.\n");
2151 return &null_variable.ID3D10ShaderReflectionVariable_iface;
2154 static const struct ID3D10ShaderReflectionConstantBufferVtbl d3d10_shader_reflection_constant_buffer_vtbl =
2156 d3d10_shader_reflection_constant_buffer_GetDesc,
2157 d3d10_shader_reflection_constant_buffer_GetVariableByIndex,
2158 d3d10_shader_reflection_constant_buffer_GetVariableByName,
2161 static inline struct d3dcompiler_shader_reflection_variable *impl_from_ID3D10ShaderReflectionVariable(ID3D10ShaderReflectionVariable *iface)
2163 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_variable, ID3D10ShaderReflectionVariable_iface);
2166 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_variable_GetDesc(ID3D10ShaderReflectionVariable *iface,
2167 D3D10_SHADER_VARIABLE_DESC *desc)
2169 struct d3dcompiler_shader_reflection_variable *var = impl_from_ID3D10ShaderReflectionVariable(iface);
2171 TRACE("iface %p, desc %p.\n", iface, desc);
2173 if (var == &null_variable)
2175 WARN("Null variable specified.\n");
2176 return E_FAIL;
2179 if (!desc)
2181 WARN("Invalid argument specified.\n");
2182 return E_FAIL;
2185 desc->Name = var->name;
2186 desc->StartOffset = var->start_offset;
2187 desc->Size = var->size;
2188 desc->uFlags = var->flags;
2189 desc->DefaultValue = var->default_value;
2191 return S_OK;
2194 static ID3D10ShaderReflectionType * STDMETHODCALLTYPE d3d10_shader_reflection_variable_GetType(
2195 ID3D10ShaderReflectionVariable *iface)
2197 struct d3dcompiler_shader_reflection_variable *var = impl_from_ID3D10ShaderReflectionVariable(iface);
2199 TRACE("iface %p.\n", iface);
2201 return &var->type->ID3D10ShaderReflectionType_iface;
2204 static const struct ID3D10ShaderReflectionVariableVtbl d3d10_shader_reflection_variable_vtbl =
2206 d3d10_shader_reflection_variable_GetDesc,
2207 d3d10_shader_reflection_variable_GetType,
2210 static inline struct d3dcompiler_shader_reflection_type *impl_from_ID3D10ShaderReflectionType(
2211 ID3D10ShaderReflectionType *iface)
2213 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_type, ID3D10ShaderReflectionType_iface);
2216 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_type_GetDesc(ID3D10ShaderReflectionType *iface,
2217 D3D10_SHADER_TYPE_DESC *desc)
2219 struct d3dcompiler_shader_reflection_type *type = impl_from_ID3D10ShaderReflectionType(iface);
2221 TRACE("iface %p, desc %p.\n", iface, desc);
2223 if (type == &null_type)
2225 WARN("Null type specified.\n");
2226 return E_FAIL;
2229 if (!desc)
2231 WARN("Invalid argument specified.\n");
2232 return E_FAIL;
2235 memcpy(desc, &type->desc, sizeof(*desc));
2237 return S_OK;
2240 static ID3D10ShaderReflectionType * STDMETHODCALLTYPE d3d10_shader_reflection_type_GetMemberTypeByIndex(
2241 ID3D10ShaderReflectionType *iface, UINT index)
2243 struct d3dcompiler_shader_reflection_type *type = impl_from_ID3D10ShaderReflectionType(iface);
2245 TRACE("iface %p, index %u.\n", iface, index);
2247 if (index >= type->desc.Members)
2249 WARN("Invalid index specified.\n");
2250 return &null_type.ID3D10ShaderReflectionType_iface;
2253 return &type->members[index].type->ID3D10ShaderReflectionType_iface;
2256 static ID3D10ShaderReflectionType * STDMETHODCALLTYPE d3d10_shader_reflection_type_GetMemberTypeByName(
2257 ID3D10ShaderReflectionType *iface, const char *name)
2259 struct d3dcompiler_shader_reflection_type *type = impl_from_ID3D10ShaderReflectionType(iface);
2260 unsigned int i;
2262 TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
2264 if (!name)
2266 WARN("Invalid argument specified.\n");
2267 return &null_type.ID3D10ShaderReflectionType_iface;
2270 for (i = 0; i < type->desc.Members; ++i)
2272 struct d3dcompiler_shader_reflection_type_member *member = &type->members[i];
2274 if (!strcmp(member->name, name))
2276 TRACE("Returning ID3D10ShaderReflectionType %p.\n", member->type);
2277 return &member->type->ID3D10ShaderReflectionType_iface;
2281 WARN("Invalid name specified.\n");
2283 return &null_type.ID3D10ShaderReflectionType_iface;
2286 static const char * STDMETHODCALLTYPE d3d10_shader_reflection_type_GetMemberTypeName(
2287 ID3D10ShaderReflectionType *iface, UINT index)
2289 struct d3dcompiler_shader_reflection_type *type = impl_from_ID3D10ShaderReflectionType(iface);
2291 TRACE("iface %p, index %u.\n", iface, index);
2293 if (type == &null_type)
2295 WARN("Null type specified.\n");
2296 return "$Invalid";
2299 if (index >= type->desc.Members)
2301 WARN("Invalid index specified.\n");
2302 return NULL;
2305 return type->members[index].name;
2308 static const struct ID3D10ShaderReflectionTypeVtbl d3d10_shader_reflection_type_vtbl =
2310 d3d10_shader_reflection_type_GetDesc,
2311 d3d10_shader_reflection_type_GetMemberTypeByIndex,
2312 d3d10_shader_reflection_type_GetMemberTypeByName,
2313 d3d10_shader_reflection_type_GetMemberTypeName,
2316 HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10ShaderReflection **reflector)
2318 struct d3dcompiler_shader_reflection *object;
2319 HRESULT hr;
2321 TRACE("data %p, data_size %lu, reflector %p.\n", data, data_size, reflector);
2323 if (!(object = heap_alloc_zero(sizeof(*object))))
2325 ERR("Failed to allocate D3D10 shader reflection object memory.\n");
2326 return E_OUTOFMEMORY;
2329 object->ID3D10ShaderReflection_iface.lpVtbl = &d3d10_shader_reflection_vtbl;
2330 object->interface_version = D3DCOMPILER_REFLECTION_VERSION_D3D10;
2331 object->refcount = 1;
2333 hr = d3dcompiler_shader_reflection_init(object, data, data_size);
2334 if (FAILED(hr))
2336 WARN("Failed to initialize shader reflection.\n");
2337 HeapFree(GetProcessHeap(), 0, object);
2338 return hr;
2341 *reflector = &object->ID3D10ShaderReflection_iface;
2343 TRACE("Created ID3D10ShaderReflection %p.\n", object);
2345 return S_OK;
2347 #endif
2349 HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector)
2351 struct d3dcompiler_shader_reflection *object;
2352 HRESULT hr;
2353 const DWORD *temp = data;
2355 TRACE("data %p, data_size %lu, riid %s, blob %p\n", data, data_size, debugstr_guid(riid), reflector);
2357 if (!data || data_size < 32)
2359 WARN("Invalid argument supplied.\n");
2360 return D3DERR_INVALIDCALL;
2363 if (temp[6] != data_size)
2365 WARN("Wrong size supplied.\n");
2366 #if D3D_COMPILER_VERSION >= 46
2367 return D3DERR_INVALIDCALL;
2368 #else
2369 return E_FAIL;
2370 #endif
2373 if (!IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
2374 && (D3D_COMPILER_VERSION < 47 || !IsEqualGUID(riid, &IID_ID3D12ShaderReflection)))
2376 WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid), debugstr_guid(&IID_ID3D11ShaderReflection));
2377 #if D3D_COMPILER_VERSION >= 46
2378 return E_INVALIDARG;
2379 #else
2380 return E_NOINTERFACE;
2381 #endif
2384 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2385 if (!object)
2386 return E_OUTOFMEMORY;
2388 object->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl;
2389 object->refcount = 1;
2390 object->interface_version = IsEqualGUID(riid, &IID_ID3D12ShaderReflection)
2391 ? D3DCOMPILER_REFLECTION_VERSION_D3D12 : D3DCOMPILER_REFLECTION_VERSION_D3D11;
2393 hr = d3dcompiler_shader_reflection_init(object, data, data_size);
2394 if (FAILED(hr))
2396 WARN("Failed to initialize shader reflection\n");
2397 HeapFree(GetProcessHeap(), 0, object);
2398 return hr;
2401 *reflector = object;
2403 TRACE("Created ID3D11ShaderReflection %p\n", object);
2405 return S_OK;