gdiplus: Add GdipGetPenCompoundCount implementation.
[wine.git] / dlls / d3dcompiler_43 / reflection.c
blob0fa0dc168396883eb4e01b9d35dab519dd9786ce
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 #if !D3D_COMPILER_VERSION
26 #define ID3D11ShaderReflection ID3D10ShaderReflection
27 #define ID3D11ShaderReflectionVtbl ID3D10ShaderReflectionVtbl
28 #define ID3D11ShaderReflectionConstantBuffer ID3D10ShaderReflectionConstantBuffer
29 #define ID3D11ShaderReflectionConstantBufferVtbl ID3D10ShaderReflectionConstantBufferVtbl
30 #define ID3D11ShaderReflectionType ID3D10ShaderReflectionType
31 #define ID3D11ShaderReflectionTypeVtbl ID3D10ShaderReflectionTypeVtbl
32 #define ID3D11ShaderReflectionVariable ID3D10ShaderReflectionVariable
33 #define ID3D11ShaderReflectionVariableVtbl ID3D10ShaderReflectionVariableVtbl
34 #define IID_ID3D11ShaderReflection IID_ID3D10ShaderReflection
35 #define D3D11_SHADER_BUFFER_DESC D3D10_SHADER_BUFFER_DESC
36 #define D3D11_SHADER_DESC D3D10_SHADER_DESC
37 #define D3D11_SHADER_INPUT_BIND_DESC D3D10_SHADER_INPUT_BIND_DESC
38 #define D3D11_SHADER_TYPE_DESC D3D10_SHADER_TYPE_DESC
39 #define D3D11_SHADER_VARIABLE_DESC D3D10_SHADER_VARIABLE_DESC
40 #define D3D11_SIGNATURE_PARAMETER_DESC D3D10_SIGNATURE_PARAMETER_DESC
41 #endif
43 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
45 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE
47 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6 = 6,
48 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7 = 7,
51 #define D3DCOMPILER_SHADER_TARGET_VERSION_MASK 0xffff
52 #define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK 0xffff0000
53 #define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_SHIFT 16
55 #define D3DCOMPILER_SHDR_SHADER_TYPE_CS 0x4353
57 enum d3dcompiler_shader_type
59 D3DCOMPILER_SHADER_TYPE_CS = 5,
62 struct d3dcompiler_shader_signature
64 D3D11_SIGNATURE_PARAMETER_DESC *elements;
65 unsigned int element_count;
66 char *string_data;
69 struct d3dcompiler_shader_reflection_type
71 ID3D11ShaderReflectionType ID3D11ShaderReflectionType_iface;
73 uint32_t id;
74 struct wine_rb_entry entry;
76 struct d3dcompiler_shader_reflection *reflection;
78 D3D11_SHADER_TYPE_DESC desc;
79 struct d3dcompiler_shader_reflection_type_member *members;
80 char *name;
83 struct d3dcompiler_shader_reflection_type_member
85 char *name;
86 uint32_t offset;
87 struct d3dcompiler_shader_reflection_type *type;
90 struct d3dcompiler_shader_reflection_variable
92 ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface;
94 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffer;
95 struct d3dcompiler_shader_reflection_type *type;
97 char *name;
98 UINT start_offset;
99 UINT size;
100 UINT flags;
101 void *default_value;
104 struct d3dcompiler_shader_reflection_constant_buffer
106 ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface;
108 struct d3dcompiler_shader_reflection *reflection;
110 char *name;
111 D3D_CBUFFER_TYPE type;
112 UINT variable_count;
113 UINT size;
114 UINT flags;
116 struct d3dcompiler_shader_reflection_variable *variables;
119 enum D3DCOMPILER_REFLECTION_VERSION
121 D3DCOMPILER_REFLECTION_VERSION_D3D10,
122 D3DCOMPILER_REFLECTION_VERSION_D3D11,
123 D3DCOMPILER_REFLECTION_VERSION_D3D12,
126 /* ID3D11ShaderReflection */
127 struct d3dcompiler_shader_reflection
129 ID3D11ShaderReflection ID3D11ShaderReflection_iface;
130 LONG refcount;
132 enum D3DCOMPILER_REFLECTION_VERSION interface_version;
134 uint32_t target;
135 char *creator;
136 UINT flags;
137 UINT version;
138 UINT bound_resource_count;
139 UINT constant_buffer_count;
141 UINT mov_instruction_count;
142 UINT conversion_instruction_count;
143 UINT instruction_count;
144 UINT emit_instruction_count;
145 D3D_PRIMITIVE_TOPOLOGY gs_output_topology;
146 UINT gs_max_output_vertex_count;
147 D3D_PRIMITIVE input_primitive;
148 UINT cut_instruction_count;
149 UINT def_count;
150 UINT dcl_count;
151 UINT static_flow_control_count;
152 UINT float_instruction_count;
153 UINT temp_register_count;
154 UINT int_instruction_count;
155 UINT uint_instruction_count;
156 UINT temp_array_count;
157 UINT array_instruction_count;
158 UINT texture_normal_instructions;
159 UINT texture_load_instructions;
160 UINT texture_comp_instructions;
161 UINT texture_bias_instructions;
162 UINT texture_gradient_instructions;
163 UINT dynamic_flow_control_count;
164 UINT macro_instruction_count;
165 UINT c_control_points;
166 D3D_TESSELLATOR_OUTPUT_PRIMITIVE hs_output_primitive;
167 D3D_TESSELLATOR_PARTITIONING hs_partitioning;
168 D3D_TESSELLATOR_DOMAIN tessellator_domain;
169 UINT thread_group_size_x;
170 UINT thread_group_size_y;
171 UINT thread_group_size_z;
173 struct d3dcompiler_shader_signature *isgn;
174 struct d3dcompiler_shader_signature *osgn;
175 struct d3dcompiler_shader_signature *pcsg;
176 char *resource_string;
177 D3D12_SHADER_INPUT_BIND_DESC *bound_resources;
178 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers;
179 struct wine_rb_tree types;
182 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, uint32_t offset);
184 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl;
185 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl;
186 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl;
188 /* null objects - needed for invalid calls */
189 static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer =
191 {&d3dcompiler_shader_reflection_constant_buffer_vtbl},
193 static struct d3dcompiler_shader_reflection_type null_type =
195 {&d3dcompiler_shader_reflection_type_vtbl},
197 static struct d3dcompiler_shader_reflection_variable null_variable =
199 {&d3dcompiler_shader_reflection_variable_vtbl},
200 &null_constant_buffer,
201 &null_type
204 static BOOL copy_name(const char *ptr, char **name)
206 size_t name_len;
208 if (!ptr) return TRUE;
210 name_len = strlen(ptr) + 1;
211 if (name_len == 1)
213 return TRUE;
216 *name = HeapAlloc(GetProcessHeap(), 0, name_len);
217 if (!*name)
219 ERR("Failed to allocate name memory.\n");
220 return FALSE;
223 memcpy(*name, ptr, name_len);
225 return TRUE;
228 static BOOL copy_value(const char *ptr, void **value, uint32_t size)
230 if (!ptr || !size) return TRUE;
232 *value = HeapAlloc(GetProcessHeap(), 0, size);
233 if (!*value)
235 ERR("Failed to allocate value memory.\n");
236 return FALSE;
239 memcpy(*value, ptr, size);
241 return TRUE;
244 static int d3dcompiler_shader_reflection_type_compare(const void *key, const struct wine_rb_entry *entry)
246 const struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3dcompiler_shader_reflection_type, entry);
247 const uint32_t *id = key;
249 return *id - t->id;
252 static void free_type_member(struct d3dcompiler_shader_reflection_type_member *member)
254 if (member)
256 HeapFree(GetProcessHeap(), 0, member->name);
260 static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry *entry, void *context)
262 struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
263 unsigned int i;
265 TRACE("reflection type %p.\n", t);
267 if (t->members)
269 for (i = 0; i < t->desc.Members; ++i)
271 free_type_member(&t->members[i]);
273 HeapFree(GetProcessHeap(), 0, t->members);
276 heap_free(t->name);
277 HeapFree(GetProcessHeap(), 0, t);
280 static void free_signature(struct d3dcompiler_shader_signature *sig)
282 TRACE("Free signature %p\n", sig);
284 HeapFree(GetProcessHeap(), 0, sig->elements);
285 HeapFree(GetProcessHeap(), 0, sig->string_data);
288 static void free_variable(struct d3dcompiler_shader_reflection_variable *var)
290 if (var)
292 HeapFree(GetProcessHeap(), 0, var->name);
293 HeapFree(GetProcessHeap(), 0, var->default_value);
297 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer *cb)
299 if (cb->variables)
301 unsigned int i;
303 for (i = 0; i < cb->variable_count; ++i)
305 free_variable(&cb->variables[i]);
307 HeapFree(GetProcessHeap(), 0, cb->variables);
310 HeapFree(GetProcessHeap(), 0, cb->name);
313 static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref)
315 TRACE("Cleanup %p\n", ref);
317 if (ref->isgn)
319 free_signature(ref->isgn);
320 HeapFree(GetProcessHeap(), 0, ref->isgn);
323 if (ref->osgn)
325 free_signature(ref->osgn);
326 HeapFree(GetProcessHeap(), 0, ref->osgn);
329 if (ref->pcsg)
331 free_signature(ref->pcsg);
332 HeapFree(GetProcessHeap(), 0, ref->pcsg);
335 if (ref->constant_buffers)
337 unsigned int i;
339 for (i = 0; i < ref->constant_buffer_count; ++i)
341 free_constant_buffer(&ref->constant_buffers[i]);
345 wine_rb_destroy(&ref->types, d3dcompiler_shader_reflection_type_destroy, NULL);
346 HeapFree(GetProcessHeap(), 0, ref->constant_buffers);
347 HeapFree(GetProcessHeap(), 0, ref->bound_resources);
348 HeapFree(GetProcessHeap(), 0, ref->resource_string);
349 HeapFree(GetProcessHeap(), 0, ref->creator);
352 /* IUnknown methods */
354 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface)
356 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface);
359 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object)
361 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
363 if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
364 || IsEqualGUID(riid, &IID_IUnknown)
365 || (D3D_COMPILER_VERSION >= 47 && IsEqualGUID(riid, &IID_ID3D12ShaderReflection)))
367 IUnknown_AddRef(iface);
368 *object = iface;
369 return S_OK;
372 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
374 *object = NULL;
375 return E_NOINTERFACE;
378 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection *iface)
380 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
381 ULONG refcount = InterlockedIncrement(&This->refcount);
383 TRACE("%p increasing refcount to %lu.\n", This, refcount);
385 return refcount;
388 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection *iface)
390 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
391 ULONG refcount = InterlockedDecrement(&This->refcount);
393 TRACE("%p decreasing refcount to %lu.\n", This, refcount);
395 if (!refcount)
397 reflection_cleanup(This);
398 HeapFree(GetProcessHeap(), 0, This);
401 return refcount;
404 /* ID3D11ShaderReflection methods */
406 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc)
408 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
410 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
412 if (!desc)
414 WARN("Invalid argument specified\n");
415 return E_FAIL;
418 desc->Version = reflection->version;
419 desc->Creator = reflection->creator;
420 desc->Flags = reflection->flags;
421 desc->ConstantBuffers = reflection->constant_buffer_count;
422 desc->BoundResources = reflection->bound_resource_count;
423 desc->InputParameters = reflection->isgn ? reflection->isgn->element_count : 0;
424 desc->OutputParameters = reflection->osgn ? reflection->osgn->element_count : 0;
425 desc->InstructionCount = reflection->instruction_count;
426 desc->TempRegisterCount = reflection->temp_register_count;
427 desc->TempArrayCount = reflection->temp_array_count;
428 desc->DefCount = reflection->def_count;
429 desc->DclCount = reflection->dcl_count;
430 desc->TextureNormalInstructions = reflection->texture_normal_instructions;
431 desc->TextureLoadInstructions = reflection->texture_load_instructions;
432 desc->TextureCompInstructions = reflection->texture_comp_instructions;
433 desc->TextureBiasInstructions = reflection->texture_bias_instructions;
434 desc->TextureGradientInstructions = reflection->texture_gradient_instructions;
435 desc->FloatInstructionCount = reflection->float_instruction_count;
436 desc->IntInstructionCount = reflection->int_instruction_count;
437 desc->UintInstructionCount = reflection->uint_instruction_count;
438 desc->StaticFlowControlCount = reflection->static_flow_control_count;
439 desc->DynamicFlowControlCount = reflection->dynamic_flow_control_count;
440 desc->MacroInstructionCount = reflection->macro_instruction_count;
441 desc->ArrayInstructionCount = reflection->array_instruction_count;
442 desc->CutInstructionCount = reflection->cut_instruction_count;
443 desc->EmitInstructionCount = reflection->emit_instruction_count;
444 desc->GSOutputTopology = reflection->gs_output_topology;
445 desc->GSMaxOutputVertexCount = reflection->gs_max_output_vertex_count;
446 #if D3D_COMPILER_VERSION
447 desc->InputPrimitive = reflection->input_primitive;
448 desc->PatchConstantParameters = reflection->pcsg ? reflection->pcsg->element_count : 0;
449 desc->cGSInstanceCount = 0;
450 desc->cControlPoints = reflection->c_control_points;
451 desc->HSOutputPrimitive = reflection->hs_output_primitive;
452 desc->HSPartitioning = reflection->hs_partitioning;
453 desc->TessellatorDomain = reflection->tessellator_domain;
454 desc->cBarrierInstructions = 0;
455 desc->cInterlockedInstructions = 0;
456 desc->cTextureStoreInstructions = 0;
457 #endif
459 return S_OK;
462 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByIndex(
463 ID3D11ShaderReflection *iface, UINT index)
465 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
467 TRACE("iface %p, index %u\n", iface, index);
469 if (index >= This->constant_buffer_count)
471 WARN("Invalid argument specified\n");
472 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
475 return &This->constant_buffers[index].ID3D11ShaderReflectionConstantBuffer_iface;
478 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByName(
479 ID3D11ShaderReflection *iface, const char *name)
481 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
482 unsigned int i;
484 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
486 if (!name)
488 WARN("Invalid argument specified\n");
489 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
492 for (i = 0; i < This->constant_buffer_count; ++i)
494 struct d3dcompiler_shader_reflection_constant_buffer *d = &This->constant_buffers[i];
496 if (!strcmp(d->name, name))
498 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d);
499 return &d->ID3D11ShaderReflectionConstantBuffer_iface;
503 WARN("Invalid name specified\n");
505 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
508 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDesc(
509 ID3D11ShaderReflection *iface, UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc)
511 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
513 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
515 if (!desc || index >= reflection->bound_resource_count)
517 WARN("Invalid argument specified\n");
518 return E_INVALIDARG;
521 memcpy(desc, &reflection->bound_resources[index],
522 reflection->interface_version == D3DCOMPILER_REFLECTION_VERSION_D3D12
523 ? sizeof(D3D12_SHADER_INPUT_BIND_DESC) : sizeof(D3D11_SHADER_INPUT_BIND_DESC));
525 return S_OK;
528 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetInputParameterDesc(
529 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
531 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
533 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
535 if (!desc || !reflection->isgn || index >= reflection->isgn->element_count)
537 WARN("Invalid argument specified\n");
538 return E_INVALIDARG;
541 *desc = reflection->isgn->elements[index];
543 return S_OK;
546 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetOutputParameterDesc(
547 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
549 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
551 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
553 if (!desc || !reflection->osgn || index >= reflection->osgn->element_count)
555 WARN("Invalid argument specified\n");
556 return E_INVALIDARG;
559 *desc = reflection->osgn->elements[index];
561 return S_OK;
564 #if D3D_COMPILER_VERSION
565 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
566 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
568 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
570 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
572 if (!desc || !reflection->pcsg || index >= reflection->pcsg->element_count)
574 WARN("Invalid argument specified\n");
575 return E_INVALIDARG;
578 *desc = reflection->pcsg->elements[index];
580 return S_OK;
583 static struct ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetVariableByName(
584 ID3D11ShaderReflection *iface, const char *name)
586 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
587 unsigned int i, k;
589 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
591 if (!name)
593 WARN("Invalid name specified\n");
594 return &null_variable.ID3D11ShaderReflectionVariable_iface;
597 for (i = 0; i < This->constant_buffer_count; ++i)
599 struct d3dcompiler_shader_reflection_constant_buffer *cb = &This->constant_buffers[i];
601 for (k = 0; k < cb->variable_count; ++k)
603 struct d3dcompiler_shader_reflection_variable *v = &cb->variables[k];
605 if (!strcmp(v->name, name))
607 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
608 return &v->ID3D11ShaderReflectionVariable_iface;
613 WARN("Invalid name specified\n");
615 return &null_variable.ID3D11ShaderReflectionVariable_iface;
618 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDescByName(
619 ID3D11ShaderReflection *iface, const char *name, D3D11_SHADER_INPUT_BIND_DESC *desc)
621 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
622 unsigned int i;
624 TRACE("iface %p, name %s, desc %p\n", iface, debugstr_a(name), desc);
626 if (!desc || !name)
628 WARN("Invalid argument specified\n");
629 return E_INVALIDARG;
632 for (i = 0; i < reflection->bound_resource_count; ++i)
634 D3D12_SHADER_INPUT_BIND_DESC *d = &reflection->bound_resources[i];
636 if (!strcmp(d->Name, name))
638 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d);
639 memcpy(desc, d, reflection->interface_version == D3DCOMPILER_REFLECTION_VERSION_D3D12
640 ? sizeof(D3D12_SHADER_INPUT_BIND_DESC) : sizeof(D3D11_SHADER_INPUT_BIND_DESC));
641 return S_OK;
645 WARN("Invalid name specified\n");
647 return E_INVALIDARG;
650 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovInstructionCount(
651 ID3D11ShaderReflection *iface)
653 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
655 TRACE("iface %p\n", iface);
657 return This->mov_instruction_count;
660 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovcInstructionCount(
661 ID3D11ShaderReflection *iface)
663 FIXME("iface %p stub!\n", iface);
665 return 0;
668 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConversionInstructionCount(
669 ID3D11ShaderReflection *iface)
671 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
673 TRACE("iface %p\n", iface);
675 return This->conversion_instruction_count;
678 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
679 ID3D11ShaderReflection *iface)
681 FIXME("iface %p stub!\n", iface);
683 return 0;
686 static D3D_PRIMITIVE STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetGSInputPrimitive(
687 ID3D11ShaderReflection *iface)
689 FIXME("iface %p stub!\n", iface);
691 return 0;
694 static BOOL STDMETHODCALLTYPE d3dcompiler_shader_reflection_IsSampleFrequencyShader(
695 ID3D11ShaderReflection *iface)
697 FIXME("iface %p stub!\n", iface);
699 return FALSE;
702 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetNumInterfaceSlots(
703 ID3D11ShaderReflection *iface)
705 FIXME("iface %p stub!\n", iface);
707 return 0;
710 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMinFeatureLevel(
711 ID3D11ShaderReflection *iface, D3D_FEATURE_LEVEL *level)
713 FIXME("iface %p, level %p stub!\n", iface, level);
715 return E_NOTIMPL;
718 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetThreadGroupSize(
719 ID3D11ShaderReflection *iface, UINT *sizex, UINT *sizey, UINT *sizez)
721 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
723 TRACE("iface %p, sizex %p, sizey %p, sizez %p.\n", iface, sizex, sizey, sizez);
725 if (!sizex || !sizey || !sizez)
727 WARN("Invalid argument specified.\n");
728 return E_INVALIDARG;
731 *sizex = reflection->thread_group_size_x;
732 *sizey = reflection->thread_group_size_y;
733 *sizez = reflection->thread_group_size_z;
735 return *sizex * *sizey * *sizez;
738 static UINT64 STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetRequiresFlags(
739 ID3D11ShaderReflection *iface)
741 FIXME("iface %p stub!\n", iface);
743 return 0;
745 #endif
747 static const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl =
749 /* IUnknown methods */
750 d3dcompiler_shader_reflection_QueryInterface,
751 d3dcompiler_shader_reflection_AddRef,
752 d3dcompiler_shader_reflection_Release,
753 /* ID3D11ShaderReflection methods */
754 d3dcompiler_shader_reflection_GetDesc,
755 d3dcompiler_shader_reflection_GetConstantBufferByIndex,
756 d3dcompiler_shader_reflection_GetConstantBufferByName,
757 d3dcompiler_shader_reflection_GetResourceBindingDesc,
758 d3dcompiler_shader_reflection_GetInputParameterDesc,
759 d3dcompiler_shader_reflection_GetOutputParameterDesc,
760 #if D3D_COMPILER_VERSION
761 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc,
762 d3dcompiler_shader_reflection_GetVariableByName,
763 d3dcompiler_shader_reflection_GetResourceBindingDescByName,
764 d3dcompiler_shader_reflection_GetMovInstructionCount,
765 d3dcompiler_shader_reflection_GetMovcInstructionCount,
766 d3dcompiler_shader_reflection_GetConversionInstructionCount,
767 d3dcompiler_shader_reflection_GetBitwiseInstructionCount,
768 d3dcompiler_shader_reflection_GetGSInputPrimitive,
769 d3dcompiler_shader_reflection_IsSampleFrequencyShader,
770 d3dcompiler_shader_reflection_GetNumInterfaceSlots,
771 d3dcompiler_shader_reflection_GetMinFeatureLevel,
772 d3dcompiler_shader_reflection_GetThreadGroupSize,
773 d3dcompiler_shader_reflection_GetRequiresFlags,
774 #endif
777 /* ID3D11ShaderReflectionConstantBuffer methods */
779 static inline struct d3dcompiler_shader_reflection_constant_buffer *impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer *iface)
781 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_constant_buffer, ID3D11ShaderReflectionConstantBuffer_iface);
784 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetDesc(
785 ID3D11ShaderReflectionConstantBuffer *iface, D3D11_SHADER_BUFFER_DESC *desc)
787 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
789 TRACE("iface %p, desc %p\n", iface, desc);
791 if (This == &null_constant_buffer)
793 WARN("Null constant buffer specified\n");
794 return E_FAIL;
797 if (!desc)
799 WARN("Invalid argument specified\n");
800 return E_FAIL;
803 desc->Name = This->name;
804 desc->Type = This->type;
805 desc->Variables = This->variable_count;
806 desc->Size = This->size;
807 desc->uFlags = This->flags;
809 return S_OK;
812 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
813 ID3D11ShaderReflectionConstantBuffer *iface, UINT index)
815 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
817 TRACE("iface %p, index %u\n", iface, index);
819 if (index >= This->variable_count)
821 WARN("Invalid index specified\n");
822 return &null_variable.ID3D11ShaderReflectionVariable_iface;
825 return &This->variables[index].ID3D11ShaderReflectionVariable_iface;
828 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
829 ID3D11ShaderReflectionConstantBuffer *iface, const char *name)
831 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
832 unsigned int i;
834 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
836 if (!name)
838 WARN("Invalid argument specified\n");
839 return &null_variable.ID3D11ShaderReflectionVariable_iface;
842 for (i = 0; i < This->variable_count; ++i)
844 struct d3dcompiler_shader_reflection_variable *v = &This->variables[i];
846 if (!strcmp(v->name, name))
848 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
849 return &v->ID3D11ShaderReflectionVariable_iface;
853 WARN("Invalid name specified\n");
855 return &null_variable.ID3D11ShaderReflectionVariable_iface;
858 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl =
860 /* ID3D11ShaderReflectionConstantBuffer methods */
861 d3dcompiler_shader_reflection_constant_buffer_GetDesc,
862 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex,
863 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName,
866 /* ID3D11ShaderReflectionVariable methods */
868 static inline struct d3dcompiler_shader_reflection_variable *impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable *iface)
870 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_variable, ID3D11ShaderReflectionVariable_iface);
873 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetDesc(
874 ID3D11ShaderReflectionVariable *iface, D3D11_SHADER_VARIABLE_DESC *desc)
876 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
878 TRACE("iface %p, desc %p\n", iface, desc);
880 if (This == &null_variable)
882 WARN("Null variable specified\n");
883 return E_FAIL;
886 if (!desc)
888 WARN("Invalid argument specified\n");
889 return E_FAIL;
892 desc->Name = This->name;
893 desc->StartOffset = This->start_offset;
894 desc->Size = This->size;
895 desc->uFlags = This->flags;
896 desc->DefaultValue = This->default_value;
898 #if D3D_COMPILER_VERSION
899 /* TODO test and set proper values for texture. */
900 desc->StartTexture = 0xffffffff;
901 desc->TextureSize = 0;
902 desc->StartSampler = 0xffffffff;
903 desc->SamplerSize = 0;
904 #endif
906 return S_OK;
909 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetType(
910 ID3D11ShaderReflectionVariable *iface)
912 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
914 TRACE("iface %p\n", iface);
916 return &This->type->ID3D11ShaderReflectionType_iface;
919 #if D3D_COMPILER_VERSION
920 static ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetBuffer(
921 ID3D11ShaderReflectionVariable *iface)
923 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
925 TRACE("iface %p\n", iface);
927 return &This->constant_buffer->ID3D11ShaderReflectionConstantBuffer_iface;
930 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
931 ID3D11ShaderReflectionVariable *iface, UINT index)
933 FIXME("iface %p, index %u stub!\n", iface, index);
935 return 0;
937 #endif
939 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl =
941 /* ID3D11ShaderReflectionVariable methods */
942 d3dcompiler_shader_reflection_variable_GetDesc,
943 d3dcompiler_shader_reflection_variable_GetType,
944 #if D3D_COMPILER_VERSION
945 d3dcompiler_shader_reflection_variable_GetBuffer,
946 d3dcompiler_shader_reflection_variable_GetInterfaceSlot,
947 #endif
950 /* ID3D11ShaderReflectionType methods */
952 static inline struct d3dcompiler_shader_reflection_type *impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType *iface)
954 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_type, ID3D11ShaderReflectionType_iface);
957 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetDesc(
958 ID3D11ShaderReflectionType *iface, D3D11_SHADER_TYPE_DESC *desc)
960 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
962 TRACE("iface %p, desc %p\n", iface, desc);
964 if (This == &null_type)
966 WARN("Null type specified\n");
967 return E_FAIL;
970 if (!desc)
972 WARN("Invalid argument specified\n");
973 return E_FAIL;
976 *desc = This->desc;
978 return S_OK;
981 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
982 ID3D11ShaderReflectionType *iface, UINT index)
984 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
986 TRACE("iface %p, index %u\n", iface, index);
988 if (index >= This->desc.Members)
990 WARN("Invalid index specified\n");
991 return &null_type.ID3D11ShaderReflectionType_iface;
994 return &This->members[index].type->ID3D11ShaderReflectionType_iface;
997 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByName(
998 ID3D11ShaderReflectionType *iface, const char *name)
1000 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
1001 unsigned int i;
1003 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
1005 if (!name)
1007 WARN("Invalid argument specified\n");
1008 return &null_type.ID3D11ShaderReflectionType_iface;
1011 for (i = 0; i < This->desc.Members; ++i)
1013 struct d3dcompiler_shader_reflection_type_member *member = &This->members[i];
1015 if (!strcmp(member->name, name))
1017 TRACE("Returning ID3D11ShaderReflectionType %p.\n", member->type);
1018 return &member->type->ID3D11ShaderReflectionType_iface;
1022 WARN("Invalid name specified\n");
1024 return &null_type.ID3D11ShaderReflectionType_iface;
1027 static const char * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeName(
1028 ID3D11ShaderReflectionType *iface, UINT index)
1030 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
1032 TRACE("iface %p, index %u\n", iface, index);
1034 if (This == &null_type)
1036 WARN("Null type specified\n");
1037 return "$Invalid";
1040 if (index >= This->desc.Members)
1042 WARN("Invalid index specified\n");
1043 return NULL;
1046 return This->members[index].name;
1049 #if D3D_COMPILER_VERSION
1050 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsEqual(
1051 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
1053 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
1055 TRACE("iface %p, type %p\n", iface, type);
1057 if (This == &null_type)
1059 WARN("Null type specified\n");
1060 return E_FAIL;
1063 if (iface == type)
1064 return S_OK;
1066 return S_FALSE;
1069 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetSubType(
1070 ID3D11ShaderReflectionType *iface)
1072 FIXME("iface %p stub!\n", iface);
1074 return NULL;
1077 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetBaseClass(
1078 ID3D11ShaderReflectionType *iface)
1080 FIXME("iface %p stub!\n", iface);
1082 return NULL;
1085 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetNumInterfaces(
1086 ID3D11ShaderReflectionType *iface)
1088 FIXME("iface %p stub!\n", iface);
1090 return 0;
1093 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
1094 ID3D11ShaderReflectionType *iface, UINT index)
1096 FIXME("iface %p, index %u stub!\n", iface, index);
1098 return NULL;
1101 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsOfType(
1102 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
1104 FIXME("iface %p, type %p stub!\n", iface, type);
1106 return E_NOTIMPL;
1109 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_ImplementsInterface(
1110 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *base)
1112 FIXME("iface %p, base %p stub!\n", iface, base);
1114 return E_NOTIMPL;
1116 #endif
1118 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl =
1120 /* ID3D11ShaderReflectionType methods */
1121 d3dcompiler_shader_reflection_type_GetDesc,
1122 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex,
1123 d3dcompiler_shader_reflection_type_GetMemberTypeByName,
1124 d3dcompiler_shader_reflection_type_GetMemberTypeName,
1125 #if D3D_COMPILER_VERSION
1126 d3dcompiler_shader_reflection_type_IsEqual,
1127 d3dcompiler_shader_reflection_type_GetSubType,
1128 d3dcompiler_shader_reflection_type_GetBaseClass,
1129 d3dcompiler_shader_reflection_type_GetNumInterfaces,
1130 d3dcompiler_shader_reflection_type_GetInterfaceByIndex,
1131 d3dcompiler_shader_reflection_type_IsOfType,
1132 d3dcompiler_shader_reflection_type_ImplementsInterface,
1133 #endif
1136 static HRESULT d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection *r, const char *data, size_t data_size)
1138 const char *ptr = data;
1139 size_t size = data_size >> 2;
1141 TRACE("Size %Iu.\n", size);
1143 r->instruction_count = read_u32(&ptr);
1144 TRACE("InstructionCount: %u.\n", r->instruction_count);
1146 r->temp_register_count = read_u32(&ptr);
1147 TRACE("TempRegisterCount: %u.\n", r->temp_register_count);
1149 r->def_count = read_u32(&ptr);
1150 TRACE("DefCount: %u.\n", r->def_count);
1152 r->dcl_count = read_u32(&ptr);
1153 TRACE("DclCount: %u.\n", r->dcl_count);
1155 r->float_instruction_count = read_u32(&ptr);
1156 TRACE("FloatInstructionCount: %u.\n", r->float_instruction_count);
1158 r->int_instruction_count = read_u32(&ptr);
1159 TRACE("IntInstructionCount: %u.\n", r->int_instruction_count);
1161 r->uint_instruction_count = read_u32(&ptr);
1162 TRACE("UintInstructionCount: %u.\n", r->uint_instruction_count);
1164 r->static_flow_control_count = read_u32(&ptr);
1165 TRACE("StaticFlowControlCount: %u.\n", r->static_flow_control_count);
1167 r->dynamic_flow_control_count = read_u32(&ptr);
1168 TRACE("DynamicFlowControlCount: %u.\n", r->dynamic_flow_control_count);
1170 r->macro_instruction_count = read_u32(&ptr);
1171 TRACE("MacroInstructionCount: %u.\n", r->macro_instruction_count);
1173 r->temp_array_count = read_u32(&ptr);
1174 TRACE("TempArrayCount: %u.\n", r->temp_array_count);
1176 r->array_instruction_count = read_u32(&ptr);
1177 TRACE("ArrayInstructionCount: %u.\n", r->array_instruction_count);
1179 r->cut_instruction_count = read_u32(&ptr);
1180 TRACE("CutInstructionCount: %u.\n", r->cut_instruction_count);
1182 r->emit_instruction_count = read_u32(&ptr);
1183 TRACE("EmitInstructionCount: %u.\n", r->emit_instruction_count);
1185 r->texture_normal_instructions = read_u32(&ptr);
1186 TRACE("TextureNormalInstructions: %u.\n", r->texture_normal_instructions);
1188 r->texture_load_instructions = read_u32(&ptr);
1189 TRACE("TextureLoadInstructions: %u.\n", r->texture_load_instructions);
1191 r->texture_comp_instructions = read_u32(&ptr);
1192 TRACE("TextureCompInstructions: %u.\n", r->texture_comp_instructions);
1194 r->texture_bias_instructions = read_u32(&ptr);
1195 TRACE("TextureBiasInstructions: %u.\n", r->texture_bias_instructions);
1197 r->texture_gradient_instructions = read_u32(&ptr);
1198 TRACE("TextureGradientInstructions: %u.\n", r->texture_gradient_instructions);
1200 r->mov_instruction_count = read_u32(&ptr);
1201 TRACE("MovInstructionCount: %u.\n", r->mov_instruction_count);
1203 skip_u32_unknown(&ptr, 1);
1205 r->conversion_instruction_count = read_u32(&ptr);
1206 TRACE("ConversionInstructionCount: %u.\n", r->conversion_instruction_count);
1208 skip_u32_unknown(&ptr, 1);
1210 r->input_primitive = read_u32(&ptr);
1211 TRACE("InputPrimitive: %x.\n", r->input_primitive);
1213 r->gs_output_topology = read_u32(&ptr);
1214 TRACE("GSOutputTopology: %x.\n", r->gs_output_topology);
1216 r->gs_max_output_vertex_count = read_u32(&ptr);
1217 TRACE("GSMaxOutputVertexCount: %u.\n", r->gs_max_output_vertex_count);
1219 skip_u32_unknown(&ptr, 2);
1221 /* old dx10 stat size */
1222 if (size == 28) return S_OK;
1224 skip_u32_unknown(&ptr, 1);
1226 /* dx10 stat size */
1227 if (size == 29) return S_OK;
1229 skip_u32_unknown(&ptr, 1);
1231 r->c_control_points = read_u32(&ptr);
1232 TRACE("cControlPoints: %u.\n", r->c_control_points);
1234 r->hs_output_primitive = read_u32(&ptr);
1235 TRACE("HSOutputPrimitive: %x.\n", r->hs_output_primitive);
1237 r->hs_partitioning = read_u32(&ptr);
1238 TRACE("HSPartitioning: %x.\n", r->hs_partitioning);
1240 r->tessellator_domain = read_u32(&ptr);
1241 TRACE("TessellatorDomain: %x.\n", r->tessellator_domain);
1243 skip_u32_unknown(&ptr, 3);
1245 /* dx11 stat size */
1246 if (size == 37) return S_OK;
1248 FIXME("Unhandled size %Iu.\n", size);
1250 return E_FAIL;
1253 static HRESULT d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection *ref,
1254 struct d3dcompiler_shader_reflection_type_member *member, const char *data, const char **ptr)
1256 uint32_t offset;
1258 offset = read_u32(ptr);
1259 if (!copy_name(data + offset, &member->name))
1261 ERR("Failed to copy name.\n");
1262 return E_OUTOFMEMORY;
1264 TRACE("Member name: %s.\n", debugstr_a(member->name));
1266 offset = read_u32(ptr);
1267 TRACE("Member type offset: %x.\n", offset);
1269 member->type = get_reflection_type(ref, data, offset);
1270 if (!member->type)
1272 ERR("Failed to get member type\n");
1273 HeapFree(GetProcessHeap(), 0, member->name);
1274 return E_FAIL;
1277 member->offset = read_u32(ptr);
1278 TRACE("Member offset %x.\n", member->offset);
1280 return S_OK;
1283 static HRESULT d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type *type, const char *data, uint32_t offset)
1285 const char *ptr = data + offset;
1286 uint32_t temp;
1287 D3D11_SHADER_TYPE_DESC *desc;
1288 unsigned int i;
1289 struct d3dcompiler_shader_reflection_type_member *members = NULL;
1290 HRESULT hr;
1291 uint32_t member_offset;
1293 desc = &type->desc;
1295 temp = read_u32(&ptr);
1296 desc->Class = temp & 0xffff;
1297 desc->Type = temp >> 16;
1298 TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc->Class),
1299 debug_d3dcompiler_shader_variable_type(desc->Type));
1301 temp = read_u32(&ptr);
1302 desc->Rows = temp & 0xffff;
1303 desc->Columns = temp >> 16;
1304 TRACE("Rows %u, Columns %u\n", desc->Rows, desc->Columns);
1306 temp = read_u32(&ptr);
1307 desc->Elements = temp & 0xffff;
1308 desc->Members = temp >> 16;
1309 TRACE("Elements %u, Members %u\n", desc->Elements, desc->Members);
1311 member_offset = read_u32(&ptr);
1312 TRACE("Member Offset %u.\n", member_offset);
1314 if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1315 skip_u32_unknown(&ptr, 4);
1317 if (desc->Members)
1319 const char *ptr2 = data + member_offset;
1321 members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*members) * desc->Members);
1322 if (!members)
1324 ERR("Failed to allocate type memory.\n");
1325 return E_OUTOFMEMORY;
1328 for (i = 0; i < desc->Members; ++i)
1330 hr = d3dcompiler_parse_type_members(type->reflection, &members[i], data, &ptr2);
1331 if (hr != S_OK)
1333 FIXME("Failed to parse type members.\n");
1334 goto err_out;
1339 #if D3D_COMPILER_VERSION
1340 if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1342 offset = read_u32(&ptr);
1343 if (!copy_name(data + offset, &type->name))
1345 ERR("Failed to copy name.\n");
1346 heap_free(members);
1347 return E_OUTOFMEMORY;
1349 desc->Name = type->name;
1350 TRACE("Type name: %s.\n", debugstr_a(type->name));
1352 #endif
1354 type->members = members;
1356 return S_OK;
1358 err_out:
1359 for (i = 0; i < desc->Members; ++i)
1361 free_type_member(&members[i]);
1363 HeapFree(GetProcessHeap(), 0, members);
1364 return hr;
1367 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, uint32_t offset)
1369 struct d3dcompiler_shader_reflection_type *type;
1370 struct wine_rb_entry *entry;
1371 HRESULT hr;
1373 entry = wine_rb_get(&reflection->types, &offset);
1374 if (entry)
1376 TRACE("Returning existing type.\n");
1377 return WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
1380 type = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*type));
1381 if (!type)
1382 return NULL;
1384 type->ID3D11ShaderReflectionType_iface.lpVtbl = &d3dcompiler_shader_reflection_type_vtbl;
1385 type->id = offset;
1386 type->reflection = reflection;
1388 hr = d3dcompiler_parse_type(type, data, offset);
1389 if (FAILED(hr))
1391 ERR("Failed to parse type info, hr %#lx.\n", hr);
1392 HeapFree(GetProcessHeap(), 0, type);
1393 return NULL;
1396 if (wine_rb_put(&reflection->types, &offset, &type->entry) == -1)
1398 ERR("Failed to insert type entry.\n");
1399 HeapFree(GetProcessHeap(), 0, type);
1400 return NULL;
1403 return type;
1406 static HRESULT d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer *cb,
1407 const char *data, size_t data_size, const char *ptr)
1409 struct d3dcompiler_shader_reflection_variable *variables;
1410 unsigned int i;
1411 HRESULT hr;
1413 variables = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb->variable_count * sizeof(*variables));
1414 if (!variables)
1416 ERR("Failed to allocate variables memory.\n");
1417 return E_OUTOFMEMORY;
1420 for (i = 0; i < cb->variable_count; i++)
1422 struct d3dcompiler_shader_reflection_variable *v = &variables[i];
1423 uint32_t offset;
1425 v->ID3D11ShaderReflectionVariable_iface.lpVtbl = &d3dcompiler_shader_reflection_variable_vtbl;
1426 v->constant_buffer = cb;
1428 offset = read_u32(&ptr);
1429 if (!copy_name(data + offset, &v->name))
1431 ERR("Failed to copy name.\n");
1432 hr = E_OUTOFMEMORY;
1433 goto err_out;
1435 TRACE("Variable name: %s.\n", debugstr_a(v->name));
1437 v->start_offset = read_u32(&ptr);
1438 TRACE("Variable offset: %u\n", v->start_offset);
1440 v->size = read_u32(&ptr);
1441 TRACE("Variable size: %u\n", v->size);
1443 v->flags = read_u32(&ptr);
1444 TRACE("Variable flags: %u\n", v->flags);
1446 offset = read_u32(&ptr);
1447 TRACE("Variable type offset: %x.\n", offset);
1448 v->type = get_reflection_type(cb->reflection, data, offset);
1449 if (!v->type)
1451 ERR("Failed to get type.\n");
1452 hr = E_FAIL;
1453 goto err_out;
1456 offset = read_u32(&ptr);
1457 TRACE("Variable default value offset: %x.\n", offset);
1458 if (!copy_value(data + offset, &v->default_value, offset ? v->size : 0))
1460 ERR("Failed to copy name.\n");
1461 hr = E_OUTOFMEMORY;
1462 goto err_out;
1465 if ((cb->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1466 skip_u32_unknown(&ptr, 4);
1469 cb->variables = variables;
1471 return S_OK;
1473 err_out:
1474 for (i = 0; i < cb->variable_count; i++)
1476 free_variable(&variables[i]);
1478 HeapFree(GetProcessHeap(), 0, variables);
1479 return hr;
1482 static HRESULT d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection *r, const char *data, size_t data_size)
1484 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers = NULL;
1485 uint32_t offset, cbuffer_offset, resource_offset, creator_offset;
1486 unsigned int i, string_data_offset, string_data_size;
1487 D3D12_SHADER_INPUT_BIND_DESC *bound_resources = NULL;
1488 char *string_data = NULL, *creator = NULL;
1489 size_t size = data_size >> 2;
1490 uint32_t target_version;
1491 const char *ptr = data;
1492 #if D3D_COMPILER_VERSION < 47
1493 uint32_t shader_type;
1494 #endif
1495 HRESULT hr;
1497 TRACE("Size %Iu.\n", size);
1499 r->constant_buffer_count = read_u32(&ptr);
1500 TRACE("Constant buffer count: %u.\n", r->constant_buffer_count);
1502 cbuffer_offset = read_u32(&ptr);
1503 TRACE("Constant buffer offset: %#x.\n", cbuffer_offset);
1505 r->bound_resource_count = read_u32(&ptr);
1506 TRACE("Bound resource count: %u.\n", r->bound_resource_count);
1508 resource_offset = read_u32(&ptr);
1509 TRACE("Bound resource offset: %#x.\n", resource_offset);
1511 r->target = read_u32(&ptr);
1512 TRACE("Target: %#x.\n", r->target);
1514 target_version = r->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK;
1515 #if D3D_COMPILER_VERSION < 47
1516 shader_type = (r->target & D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK)
1517 >> D3DCOMPILER_SHADER_TARGET_SHADERTYPE_SHIFT;
1518 if ((target_version >= 0x501 && shader_type != D3DCOMPILER_SHDR_SHADER_TYPE_CS)
1519 || (!D3D_COMPILER_VERSION && shader_type == D3DCOMPILER_SHDR_SHADER_TYPE_CS))
1521 WARN("Target version %#x is not supported in d3dcompiler %u.\n", target_version, D3D_COMPILER_VERSION);
1522 return E_INVALIDARG;
1524 #endif
1526 r->flags = read_u32(&ptr);
1527 TRACE("Flags: %u.\n", r->flags);
1529 creator_offset = read_u32(&ptr);
1530 TRACE("Creator at offset %#x.\n", creator_offset);
1532 if (!copy_name(data + creator_offset, &creator))
1534 ERR("Failed to copy name.\n");
1535 return E_OUTOFMEMORY;
1537 TRACE("Creator: %s.\n", debugstr_a(creator));
1539 /* todo: Parse RD11 */
1540 if (target_version >= 0x500)
1542 skip_u32_unknown(&ptr, 8);
1545 if (r->bound_resource_count)
1547 /* 8 for each bind desc */
1548 string_data_offset = resource_offset + r->bound_resource_count * 8 * sizeof(uint32_t);
1549 string_data_size = (cbuffer_offset ? cbuffer_offset : creator_offset) - string_data_offset;
1551 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1552 if (!string_data)
1554 ERR("Failed to allocate string data memory.\n");
1555 hr = E_OUTOFMEMORY;
1556 goto err_out;
1558 memcpy(string_data, data + string_data_offset, string_data_size);
1560 bound_resources = HeapAlloc(GetProcessHeap(), 0, r->bound_resource_count * sizeof(*bound_resources));
1561 if (!bound_resources)
1563 ERR("Failed to allocate resources memory.\n");
1564 hr = E_OUTOFMEMORY;
1565 goto err_out;
1568 ptr = data + resource_offset;
1569 for (i = 0; i < r->bound_resource_count; i++)
1571 D3D12_SHADER_INPUT_BIND_DESC *desc = &bound_resources[i];
1573 offset = read_u32(&ptr);
1574 desc->Name = string_data + (offset - string_data_offset);
1575 TRACE("Input bind Name: %s.\n", debugstr_a(desc->Name));
1577 desc->Type = read_u32(&ptr);
1578 TRACE("Input bind Type: %#x.\n", desc->Type);
1580 desc->ReturnType = read_u32(&ptr);
1581 TRACE("Input bind ReturnType: %#x.\n", desc->ReturnType);
1583 desc->Dimension = read_u32(&ptr);
1584 TRACE("Input bind Dimension: %#x.\n", desc->Dimension);
1586 desc->NumSamples = read_u32(&ptr);
1587 TRACE("Input bind NumSamples: %u.\n", desc->NumSamples);
1589 desc->BindPoint = read_u32(&ptr);
1590 TRACE("Input bind BindPoint: %u.\n", desc->BindPoint);
1592 desc->BindCount = read_u32(&ptr);
1593 TRACE("Input bind BindCount: %u.\n", desc->BindCount);
1595 desc->uFlags = read_u32(&ptr);
1596 TRACE("Input bind uFlags: %u.\n", desc->uFlags);
1598 if (target_version >= 0x501)
1600 desc->Space = read_u32(&ptr);
1601 TRACE("Input bind Space %u.\n", desc->Space);
1602 desc->uID = read_u32(&ptr);
1603 TRACE("Input bind uID %u.\n", desc->uID);
1605 else
1607 desc->Space = 0;
1608 desc->uID = desc->BindPoint;
1613 if (r->constant_buffer_count)
1615 constant_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, r->constant_buffer_count * sizeof(*constant_buffers));
1616 if (!constant_buffers)
1618 ERR("Failed to allocate constant buffer memory.\n");
1619 hr = E_OUTOFMEMORY;
1620 goto err_out;
1623 ptr = data + cbuffer_offset;
1624 for (i = 0; i < r->constant_buffer_count; i++)
1626 struct d3dcompiler_shader_reflection_constant_buffer *cb = &constant_buffers[i];
1628 cb->ID3D11ShaderReflectionConstantBuffer_iface.lpVtbl = &d3dcompiler_shader_reflection_constant_buffer_vtbl;
1629 cb->reflection = r;
1631 offset = read_u32(&ptr);
1632 if (!copy_name(data + offset, &cb->name))
1634 ERR("Failed to copy name.\n");
1635 hr = E_OUTOFMEMORY;
1636 goto err_out;
1638 TRACE("Name: %s.\n", debugstr_a(cb->name));
1640 cb->variable_count = read_u32(&ptr);
1641 TRACE("Variable count: %u.\n", cb->variable_count);
1643 offset = read_u32(&ptr);
1644 TRACE("Variable offset: %x.\n", offset);
1646 hr = d3dcompiler_parse_variables(cb, data, data_size, data + offset);
1647 if (hr != S_OK)
1649 FIXME("Failed to parse variables.\n");
1650 goto err_out;
1653 cb->size = read_u32(&ptr);
1654 TRACE("Cbuffer size: %u.\n", cb->size);
1656 cb->flags = read_u32(&ptr);
1657 TRACE("Cbuffer flags: %u.\n", cb->flags);
1659 cb->type = read_u32(&ptr);
1660 TRACE("Cbuffer type: %#x.\n", cb->type);
1664 r->creator = creator;
1665 r->resource_string = string_data;
1666 r->bound_resources = bound_resources;
1667 r->constant_buffers = constant_buffers;
1669 return S_OK;
1671 err_out:
1672 for (i = 0; i < r->constant_buffer_count; ++i)
1674 free_constant_buffer(&constant_buffers[i]);
1676 HeapFree(GetProcessHeap(), 0, constant_buffers);
1677 HeapFree(GetProcessHeap(), 0, bound_resources);
1678 HeapFree(GetProcessHeap(), 0, string_data);
1679 HeapFree(GetProcessHeap(), 0, creator);
1681 return hr;
1684 static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section)
1686 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size;
1687 D3D11_SIGNATURE_PARAMETER_DESC *d;
1688 unsigned int string_data_offset;
1689 const char *ptr = section->data;
1690 unsigned int string_data_size;
1691 unsigned int i, count;
1692 char *string_data;
1694 switch (section->tag)
1696 case TAG_OSG5:
1697 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7;
1698 break;
1700 case TAG_ISGN:
1701 case TAG_OSGN:
1702 case TAG_PCSG:
1703 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1704 break;
1706 default:
1707 FIXME("Unhandled section %s!\n", debugstr_an((const char *)&section->tag, 4));
1708 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1709 break;
1712 count = read_u32(&ptr);
1713 TRACE("%u elements\n", count);
1715 skip_u32_unknown(&ptr, 1);
1717 d = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*d));
1718 if (!d)
1720 ERR("Failed to allocate signature memory.\n");
1721 return E_OUTOFMEMORY;
1724 /* 2 u32s for the header, element_size for each element. */
1725 string_data_offset = 2 * sizeof(uint32_t) + count * element_size * sizeof(uint32_t);
1726 string_data_size = section->data_size - string_data_offset;
1728 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1729 if (!string_data)
1731 ERR("Failed to allocate string data memory.\n");
1732 HeapFree(GetProcessHeap(), 0, d);
1733 return E_OUTOFMEMORY;
1735 memcpy(string_data, section->data + string_data_offset, string_data_size);
1737 for (i = 0; i < count; ++i)
1739 uint32_t name_offset, mask;
1741 #if D3D_COMPILER_VERSION >= 46
1742 /* FIXME */
1743 d[i].MinPrecision = D3D_MIN_PRECISION_DEFAULT;
1744 #endif
1745 #if D3D_COMPILER_VERSION
1746 if (element_size == D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7)
1748 d[i].Stream = read_u32(&ptr);
1750 else
1752 d[i].Stream = 0;
1754 #endif
1756 name_offset = read_u32(&ptr);
1757 d[i].SemanticName = string_data + (name_offset - string_data_offset);
1758 d[i].SemanticIndex = read_u32(&ptr);
1759 d[i].SystemValueType = read_u32(&ptr);
1760 d[i].ComponentType = read_u32(&ptr);
1761 d[i].Register = read_u32(&ptr);
1762 mask = read_u32(&ptr);
1763 d[i].ReadWriteMask = (mask >> 8) & 0xff;
1764 d[i].Mask = mask & 0xff;
1766 if (!stricmp(d[i].SemanticName, "sv_depth"))
1767 d[i].SystemValueType = D3D_NAME_DEPTH;
1768 else if (!stricmp(d[i].SemanticName, "sv_coverage"))
1769 d[i].SystemValueType = D3D_NAME_COVERAGE;
1770 else if (!stricmp(d[i].SemanticName, "sv_depthgreaterequal"))
1771 d[i].SystemValueType = D3D_NAME_DEPTH_GREATER_EQUAL;
1772 else if (!stricmp(d[i].SemanticName, "sv_depthlessequal"))
1773 d[i].SystemValueType = D3D_NAME_DEPTH_LESS_EQUAL;
1774 else if (!stricmp(d[i].SemanticName, "sv_target"))
1775 d[i].SystemValueType = D3D_NAME_TARGET;
1778 s->elements = d;
1779 s->element_count = count;
1780 s->string_data = string_data;
1782 return S_OK;
1785 #define SM4_OPCODE_MASK 0xff
1786 #define SM4_INSTRUCTION_LENGTH_SHIFT 24
1787 #define SM4_INSTRUCTION_LENGTH_MASK (0x1fu << SM4_INSTRUCTION_LENGTH_SHIFT)
1789 enum sm4_opcode
1791 SM5_OP_DCL_THREAD_GROUP = 0x9b,
1794 static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, const char *data, size_t data_size)
1796 uint32_t opcode_token, opcode;
1797 uint32_t size, shader_type;
1798 const char *ptr = data;
1799 const uint32_t *u_ptr;
1800 unsigned int len;
1802 r->version = read_u32(&ptr);
1803 TRACE("Shader version: %u\n", r->version);
1805 shader_type = (r->version & D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK)
1806 >> D3DCOMPILER_SHADER_TARGET_SHADERTYPE_SHIFT;
1808 if (shader_type != D3DCOMPILER_SHADER_TYPE_CS)
1810 /* TODO: Check if anything else is needed from the SHDR or SHEX blob. */
1811 return S_OK;
1814 size = read_u32(&ptr);
1815 TRACE("size %u.\n", size);
1816 if (size * sizeof(uint32_t) != data_size || size < 2)
1818 WARN("Invalid size %u.\n", size);
1819 return E_FAIL;
1821 size -= 2;
1822 u_ptr = (uint32_t *)ptr;
1823 while (size)
1825 opcode_token = *u_ptr;
1826 opcode = opcode_token & SM4_OPCODE_MASK;
1827 len = (opcode_token & SM4_INSTRUCTION_LENGTH_MASK) >> SM4_INSTRUCTION_LENGTH_SHIFT;
1828 if (!len)
1830 if (size < 2)
1832 WARN("End of byte-code, failed to read length token.\n");
1833 return E_FAIL;
1835 len = u_ptr[1];
1837 if (!len || size < len)
1839 WARN("Invalid instruction length %u, size %u.\n", len, size);
1840 return E_FAIL;
1842 if (opcode == SM5_OP_DCL_THREAD_GROUP)
1844 if (len != 4)
1846 WARN("Invalid dcl_thread_group opcode length %u.\n", len);
1847 return E_FAIL;
1849 r->thread_group_size_x = u_ptr[1];
1850 r->thread_group_size_y = u_ptr[2];
1851 r->thread_group_size_z = u_ptr[3];
1852 TRACE("Found dcl_thread_group %u, %u, %u.\n",
1853 r->thread_group_size_x, r->thread_group_size_y, r->thread_group_size_z);
1855 size -= len;
1856 u_ptr += len;
1858 return S_OK;
1861 static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection,
1862 const void *data, SIZE_T data_size)
1864 struct dxbc src_dxbc;
1865 HRESULT hr;
1866 unsigned int i;
1868 wine_rb_init(&reflection->types, d3dcompiler_shader_reflection_type_compare);
1870 hr = dxbc_parse(data, data_size, &src_dxbc);
1871 if (FAILED(hr))
1873 WARN("Failed to parse reflection\n");
1874 return hr;
1877 for (i = 0; i < src_dxbc.count; ++i)
1879 struct dxbc_section *section = &src_dxbc.sections[i];
1881 switch (section->tag)
1883 case TAG_RDEF:
1884 hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size);
1885 if (FAILED(hr))
1887 WARN("Failed to parse RDEF section.\n");
1888 goto err_out;
1890 break;
1892 case TAG_ISGN:
1893 reflection->isgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->isgn));
1894 if (!reflection->isgn)
1896 ERR("Failed to allocate ISGN memory.\n");
1897 hr = E_OUTOFMEMORY;
1898 goto err_out;
1901 hr = d3dcompiler_parse_signature(reflection->isgn, section);
1902 if (FAILED(hr))
1904 WARN("Failed to parse section ISGN.\n");
1905 goto err_out;
1907 break;
1909 case TAG_OSG5:
1910 case TAG_OSGN:
1911 reflection->osgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->osgn));
1912 if (!reflection->osgn)
1914 ERR("Failed to allocate OSGN memory.\n");
1915 hr = E_OUTOFMEMORY;
1916 goto err_out;
1919 hr = d3dcompiler_parse_signature(reflection->osgn, section);
1920 if (FAILED(hr))
1922 WARN("Failed to parse section OSGN.\n");
1923 goto err_out;
1925 break;
1927 case TAG_PCSG:
1928 reflection->pcsg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->pcsg));
1929 if (!reflection->pcsg)
1931 ERR("Failed to allocate PCSG memory.\n");
1932 hr = E_OUTOFMEMORY;
1933 goto err_out;
1936 hr = d3dcompiler_parse_signature(reflection->pcsg, section);
1937 if (FAILED(hr))
1939 WARN("Failed to parse section PCSG.\n");
1940 goto err_out;
1942 break;
1944 case TAG_SHEX:
1945 case TAG_SHDR:
1946 hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size);
1947 if (FAILED(hr))
1949 WARN("Failed to parse SHDR section.\n");
1950 goto err_out;
1952 break;
1954 case TAG_STAT:
1955 hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size);
1956 if (FAILED(hr))
1958 WARN("Failed to parse section STAT.\n");
1959 goto err_out;
1961 break;
1963 default:
1964 FIXME("Unhandled section %s!\n", debugstr_an((const char *)&section->tag, 4));
1965 break;
1969 dxbc_destroy(&src_dxbc);
1971 return hr;
1973 err_out:
1974 reflection_cleanup(reflection);
1975 dxbc_destroy(&src_dxbc);
1977 return hr;
1980 /* d3d10 reflection methods. */
1981 #if !D3D_COMPILER_VERSION
1982 HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10ShaderReflection **reflector)
1984 struct d3dcompiler_shader_reflection *object;
1985 HRESULT hr;
1987 TRACE("data %p, data_size %Iu, reflector %p.\n", data, data_size, reflector);
1989 if (!(object = heap_alloc_zero(sizeof(*object))))
1991 ERR("Failed to allocate D3D10 shader reflection object memory.\n");
1992 return E_OUTOFMEMORY;
1995 object->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl;
1996 object->interface_version = D3DCOMPILER_REFLECTION_VERSION_D3D10;
1997 object->refcount = 1;
1999 hr = d3dcompiler_shader_reflection_init(object, data, data_size);
2000 if (FAILED(hr))
2002 WARN("Failed to initialize shader reflection.\n");
2003 HeapFree(GetProcessHeap(), 0, object);
2004 return hr;
2007 *reflector = (ID3D10ShaderReflection *)&object->ID3D11ShaderReflection_iface;
2009 TRACE("Created ID3D10ShaderReflection %p.\n", object);
2011 return S_OK;
2013 #else
2014 HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector)
2016 struct d3dcompiler_shader_reflection *object;
2017 const uint32_t *temp = data;
2018 HRESULT hr;
2020 TRACE("data %p, data_size %Iu, riid %s, blob %p.\n", data, data_size, debugstr_guid(riid), reflector);
2022 if (!data || data_size < 32)
2024 WARN("Invalid argument supplied.\n");
2025 return D3DERR_INVALIDCALL;
2028 if (temp[6] != data_size)
2030 WARN("Wrong size supplied.\n");
2031 #if D3D_COMPILER_VERSION >= 46
2032 return D3DERR_INVALIDCALL;
2033 #else
2034 return E_FAIL;
2035 #endif
2038 if (!IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
2039 && (D3D_COMPILER_VERSION < 47 || !IsEqualGUID(riid, &IID_ID3D12ShaderReflection)))
2041 WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid), debugstr_guid(&IID_ID3D11ShaderReflection));
2042 #if D3D_COMPILER_VERSION >= 46
2043 return E_INVALIDARG;
2044 #else
2045 return E_NOINTERFACE;
2046 #endif
2049 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2050 if (!object)
2051 return E_OUTOFMEMORY;
2053 object->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl;
2054 object->refcount = 1;
2055 object->interface_version = IsEqualGUID(riid, &IID_ID3D12ShaderReflection)
2056 ? D3DCOMPILER_REFLECTION_VERSION_D3D12 : D3DCOMPILER_REFLECTION_VERSION_D3D11;
2058 hr = d3dcompiler_shader_reflection_init(object, data, data_size);
2059 if (FAILED(hr))
2061 WARN("Failed to initialize shader reflection\n");
2062 HeapFree(GetProcessHeap(), 0, object);
2063 return hr;
2066 *reflector = object;
2067 TRACE("Created ID3D11ShaderReflection %p\n", object);
2069 return S_OK;
2071 #endif