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
22 #include "wine/port.h"
24 #include "d3dcompiler_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
28 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE
30 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6 = 6,
31 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7 = 7,
34 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset);
36 const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl;
37 const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl;
38 const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl;
40 /* null objects - needed for invalid calls */
41 static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer = {{&d3dcompiler_shader_reflection_constant_buffer_vtbl}};
42 static struct d3dcompiler_shader_reflection_type null_type = {{&d3dcompiler_shader_reflection_type_vtbl}};
43 static struct d3dcompiler_shader_reflection_variable null_variable = {{&d3dcompiler_shader_reflection_variable_vtbl},
44 &null_constant_buffer, &null_type};
46 static BOOL copy_name(const char *ptr, char **name)
50 if (!ptr) return TRUE;
52 name_len = strlen(ptr) + 1;
58 *name = HeapAlloc(GetProcessHeap(), 0, name_len);
61 ERR("Failed to allocate name memory.\n");
65 memcpy(*name, ptr, name_len);
70 static BOOL copy_value(const char *ptr, void **value, DWORD size)
72 if (!ptr || !size) return TRUE;
74 *value = HeapAlloc(GetProcessHeap(), 0, size);
77 ERR("Failed to allocate vlaue memory.\n");
81 memcpy(*value, ptr, size);
86 static void *d3dcompiler_rb_alloc(size_t size)
88 return HeapAlloc(GetProcessHeap(), 0, size);
91 static void *d3dcompiler_rb_realloc(void *ptr, size_t size)
93 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
96 static void d3dcompiler_rb_free(void *ptr)
98 HeapFree(GetProcessHeap(), 0, ptr);
101 static int d3dcompiler_shader_reflection_type_compare(const void *key, const struct wine_rb_entry *entry)
103 const struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3dcompiler_shader_reflection_type, entry);
104 const DWORD *id = key;
109 static void free_type_member(struct d3dcompiler_shader_reflection_type_member *member)
113 HeapFree(GetProcessHeap(), 0, member->name);
117 static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry *entry, void *context)
119 struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
122 TRACE("reflection type %p.\n", t);
126 for (i = 0; i < t->desc.Members; ++i)
128 free_type_member(&t->members[i]);
132 HeapFree(GetProcessHeap(), 0, t);
135 static const struct wine_rb_functions d3dcompiler_shader_reflection_type_rb_functions =
137 d3dcompiler_rb_alloc,
138 d3dcompiler_rb_realloc,
140 d3dcompiler_shader_reflection_type_compare,
143 static void free_signature(struct d3dcompiler_shader_signature *sig)
145 TRACE("Free signature %p\n", sig);
147 HeapFree(GetProcessHeap(), 0, sig->elements);
148 HeapFree(GetProcessHeap(), 0, sig->string_data);
151 static void free_variable(struct d3dcompiler_shader_reflection_variable *var)
155 HeapFree(GetProcessHeap(), 0, var->name);
156 HeapFree(GetProcessHeap(), 0, var->default_value);
160 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer *cb)
166 for (i = 0; i < cb->variable_count; ++i)
168 free_variable(&cb->variables[i]);
170 HeapFree(GetProcessHeap(), 0, cb->variables);
173 HeapFree(GetProcessHeap(), 0, cb->name);
176 static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref)
178 TRACE("Cleanup %p\n", ref);
182 free_signature(ref->isgn);
183 HeapFree(GetProcessHeap(), 0, ref->isgn);
188 free_signature(ref->osgn);
189 HeapFree(GetProcessHeap(), 0, ref->osgn);
194 free_signature(ref->pcsg);
195 HeapFree(GetProcessHeap(), 0, ref->pcsg);
198 if (ref->constant_buffers)
202 for (i = 0; i < ref->constant_buffer_count; ++i)
204 free_constant_buffer(&ref->constant_buffers[i]);
208 wine_rb_destroy(&ref->types, d3dcompiler_shader_reflection_type_destroy, NULL);
209 HeapFree(GetProcessHeap(), 0, ref->constant_buffers);
210 HeapFree(GetProcessHeap(), 0, ref->bound_resources);
211 HeapFree(GetProcessHeap(), 0, ref->resource_string);
212 HeapFree(GetProcessHeap(), 0, ref->creator);
215 /* IUnknown methods */
217 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface)
219 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface);
222 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object)
224 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
226 if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
227 || IsEqualGUID(riid, &IID_IUnknown))
229 IUnknown_AddRef(iface);
234 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
237 return E_NOINTERFACE;
240 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection *iface)
242 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
243 ULONG refcount = InterlockedIncrement(&This->refcount);
245 TRACE("%p increasing refcount to %u\n", This, refcount);
250 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection *iface)
252 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
253 ULONG refcount = InterlockedDecrement(&This->refcount);
255 TRACE("%p decreasing refcount to %u\n", This, refcount);
259 reflection_cleanup(This);
260 HeapFree(GetProcessHeap(), 0, This);
266 /* ID3D11ShaderReflection methods */
268 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc)
270 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
272 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
276 WARN("Invalid argument specified\n");
280 desc->Version = This->version;
281 desc->Creator = This->creator;
282 desc->Flags = This->flags;
283 desc->ConstantBuffers = This->constant_buffer_count;
284 desc->BoundResources = This->bound_resource_count;
285 desc->InputParameters = This->isgn ? This->isgn->element_count : 0;
286 desc->OutputParameters = This->osgn ? This->osgn->element_count : 0;
287 desc->InstructionCount = This->instruction_count;
288 desc->TempRegisterCount = This->temp_register_count;
289 desc->TempArrayCount = This->temp_array_count;
291 desc->DclCount = This->dcl_count;
292 desc->TextureNormalInstructions = This->texture_normal_instructions;
293 desc->TextureLoadInstructions = This->texture_load_instructions;
294 desc->TextureCompInstructions = This->texture_comp_instructions;
295 desc->TextureBiasInstructions = This->texture_bias_instructions;
296 desc->TextureGradientInstructions = This->texture_gradient_instructions;
297 desc->FloatInstructionCount = This->float_instruction_count;
298 desc->IntInstructionCount = This->int_instruction_count;
299 desc->UintInstructionCount = This->uint_instruction_count;
300 desc->StaticFlowControlCount = This->static_flow_control_count;
301 desc->DynamicFlowControlCount = This->dynamic_flow_control_count;
302 desc->MacroInstructionCount = 0;
303 desc->ArrayInstructionCount = This->array_instruction_count;
304 desc->CutInstructionCount = This->cut_instruction_count;
305 desc->EmitInstructionCount = This->emit_instruction_count;
306 desc->GSOutputTopology = This->gs_output_topology;
307 desc->GSMaxOutputVertexCount = This->gs_max_output_vertex_count;
308 desc->InputPrimitive = This->input_primitive;
309 desc->PatchConstantParameters = This->pcsg ? This->pcsg->element_count : 0;
310 desc->cGSInstanceCount = 0;
311 desc->cControlPoints = This->c_control_points;
312 desc->HSOutputPrimitive = This->hs_output_primitive;
313 desc->HSPartitioning = This->hs_prtitioning;
314 desc->TessellatorDomain = This->tessellator_domain;
315 desc->cBarrierInstructions = 0;
316 desc->cInterlockedInstructions = 0;
317 desc->cTextureStoreInstructions = 0;
322 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByIndex(
323 ID3D11ShaderReflection *iface, UINT index)
325 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
327 TRACE("iface %p, index %u\n", iface, index);
329 if (index >= This->constant_buffer_count)
331 WARN("Invalid argument specified\n");
332 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
335 return &This->constant_buffers[index].ID3D11ShaderReflectionConstantBuffer_iface;
338 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByName(
339 ID3D11ShaderReflection *iface, LPCSTR name)
341 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
344 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
348 WARN("Invalid argument specified\n");
349 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
352 for (i = 0; i < This->constant_buffer_count; ++i)
354 struct d3dcompiler_shader_reflection_constant_buffer *d = &This->constant_buffers[i];
356 if (!strcmp(d->name, name))
358 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d);
359 return &d->ID3D11ShaderReflectionConstantBuffer_iface;
363 WARN("Invalid name specified\n");
365 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
368 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDesc(
369 ID3D11ShaderReflection *iface, UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc)
371 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
373 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
375 if (!desc || index >= This->bound_resource_count)
377 WARN("Invalid argument specified\n");
381 *desc = This->bound_resources[index];
386 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetInputParameterDesc(
387 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
389 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
391 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
393 if (!desc || !This->isgn || index >= This->isgn->element_count)
395 WARN("Invalid argument specified\n");
399 *desc = This->isgn->elements[index];
404 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetOutputParameterDesc(
405 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
407 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
409 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
411 if (!desc || !This->osgn || index >= This->osgn->element_count)
413 WARN("Invalid argument specified\n");
417 *desc = This->osgn->elements[index];
422 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
423 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
425 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
427 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
429 if (!desc || !This->pcsg || index >= This->pcsg->element_count)
431 WARN("Invalid argument specified\n");
435 *desc = This->pcsg->elements[index];
440 static struct ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetVariableByName(
441 ID3D11ShaderReflection *iface, LPCSTR name)
443 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
446 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
450 WARN("Invalid name specified\n");
451 return &null_variable.ID3D11ShaderReflectionVariable_iface;
454 for (i = 0; i < This->constant_buffer_count; ++i)
456 struct d3dcompiler_shader_reflection_constant_buffer *cb = &This->constant_buffers[i];
458 for (k = 0; k < cb->variable_count; ++k)
460 struct d3dcompiler_shader_reflection_variable *v = &cb->variables[k];
462 if (!strcmp(v->name, name))
464 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
465 return &v->ID3D11ShaderReflectionVariable_iface;
470 WARN("Invalid name specified\n");
472 return &null_variable.ID3D11ShaderReflectionVariable_iface;
475 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDescByName(
476 ID3D11ShaderReflection *iface, LPCSTR name, D3D11_SHADER_INPUT_BIND_DESC *desc)
478 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
481 TRACE("iface %p, name %s, desc %p\n", iface, debugstr_a(name), desc);
485 WARN("Invalid argument specified\n");
489 for (i = 0; i < This->bound_resource_count; ++i)
491 D3D11_SHADER_INPUT_BIND_DESC *d = &This->bound_resources[i];
493 if (!strcmp(d->Name, name))
495 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d);
501 WARN("Invalid name specified\n");
506 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovInstructionCount(
507 ID3D11ShaderReflection *iface)
509 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
511 TRACE("iface %p\n", iface);
513 return This->mov_instruction_count;
516 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovcInstructionCount(
517 ID3D11ShaderReflection *iface)
519 FIXME("iface %p stub!\n", iface);
524 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConversionInstructionCount(
525 ID3D11ShaderReflection *iface)
527 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
529 TRACE("iface %p\n", iface);
531 return This->conversion_instruction_count;
534 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
535 ID3D11ShaderReflection *iface)
537 FIXME("iface %p stub!\n", iface);
542 static D3D_PRIMITIVE STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetGSInputPrimitive(
543 ID3D11ShaderReflection *iface)
545 FIXME("iface %p stub!\n", iface);
550 static BOOL STDMETHODCALLTYPE d3dcompiler_shader_reflection_IsSampleFrequencyShader(
551 ID3D11ShaderReflection *iface)
553 FIXME("iface %p stub!\n", iface);
558 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetNumInterfaceSlots(
559 ID3D11ShaderReflection *iface)
561 FIXME("iface %p stub!\n", iface);
566 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMinFeatureLevel(
567 ID3D11ShaderReflection *iface, D3D_FEATURE_LEVEL *level)
569 FIXME("iface %p, level %p stub!\n", iface, level);
574 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetThreadGroupSize(
575 ID3D11ShaderReflection *iface, UINT *sizex, UINT *sizey, UINT *sizez)
577 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface, sizex, sizey, sizez);
582 const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl =
584 /* IUnknown methods */
585 d3dcompiler_shader_reflection_QueryInterface,
586 d3dcompiler_shader_reflection_AddRef,
587 d3dcompiler_shader_reflection_Release,
588 /* ID3D11ShaderReflection methods */
589 d3dcompiler_shader_reflection_GetDesc,
590 d3dcompiler_shader_reflection_GetConstantBufferByIndex,
591 d3dcompiler_shader_reflection_GetConstantBufferByName,
592 d3dcompiler_shader_reflection_GetResourceBindingDesc,
593 d3dcompiler_shader_reflection_GetInputParameterDesc,
594 d3dcompiler_shader_reflection_GetOutputParameterDesc,
595 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc,
596 d3dcompiler_shader_reflection_GetVariableByName,
597 d3dcompiler_shader_reflection_GetResourceBindingDescByName,
598 d3dcompiler_shader_reflection_GetMovInstructionCount,
599 d3dcompiler_shader_reflection_GetMovcInstructionCount,
600 d3dcompiler_shader_reflection_GetConversionInstructionCount,
601 d3dcompiler_shader_reflection_GetBitwiseInstructionCount,
602 d3dcompiler_shader_reflection_GetGSInputPrimitive,
603 d3dcompiler_shader_reflection_IsSampleFrequencyShader,
604 d3dcompiler_shader_reflection_GetNumInterfaceSlots,
605 d3dcompiler_shader_reflection_GetMinFeatureLevel,
606 d3dcompiler_shader_reflection_GetThreadGroupSize,
609 /* ID3D11ShaderReflectionConstantBuffer methods */
611 static inline struct d3dcompiler_shader_reflection_constant_buffer *impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer *iface)
613 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_constant_buffer, ID3D11ShaderReflectionConstantBuffer_iface);
616 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetDesc(
617 ID3D11ShaderReflectionConstantBuffer *iface, D3D11_SHADER_BUFFER_DESC *desc)
619 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
621 TRACE("iface %p, desc %p\n", iface, desc);
623 if (This == &null_constant_buffer)
625 WARN("Null constant buffer specified\n");
631 WARN("Invalid argument specified\n");
635 desc->Name = This->name;
636 desc->Type = This->type;
637 desc->Variables = This->variable_count;
638 desc->Size = This->size;
639 desc->uFlags = This->flags;
644 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
645 ID3D11ShaderReflectionConstantBuffer *iface, UINT index)
647 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
649 TRACE("iface %p, index %u\n", iface, index);
651 if (index >= This->variable_count)
653 WARN("Invalid index specified\n");
654 return &null_variable.ID3D11ShaderReflectionVariable_iface;
657 return &This->variables[index].ID3D11ShaderReflectionVariable_iface;
660 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
661 ID3D11ShaderReflectionConstantBuffer *iface, LPCSTR name)
663 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
666 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
670 WARN("Invalid argument specified\n");
671 return &null_variable.ID3D11ShaderReflectionVariable_iface;
674 for (i = 0; i < This->variable_count; ++i)
676 struct d3dcompiler_shader_reflection_variable *v = &This->variables[i];
678 if (!strcmp(v->name, name))
680 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
681 return &v->ID3D11ShaderReflectionVariable_iface;
685 WARN("Invalid name specified\n");
687 return &null_variable.ID3D11ShaderReflectionVariable_iface;
690 const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl =
692 /* ID3D11ShaderReflectionConstantBuffer methods */
693 d3dcompiler_shader_reflection_constant_buffer_GetDesc,
694 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex,
695 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName,
698 /* ID3D11ShaderReflectionVariable methods */
700 static inline struct d3dcompiler_shader_reflection_variable *impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable *iface)
702 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_variable, ID3D11ShaderReflectionVariable_iface);
705 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetDesc(
706 ID3D11ShaderReflectionVariable *iface, D3D11_SHADER_VARIABLE_DESC *desc)
708 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
710 TRACE("iface %p, desc %p\n", iface, desc);
712 if (This == &null_variable)
714 WARN("Null variable specified\n");
720 WARN("Invalid argument specified\n");
724 desc->Name = This->name;
725 desc->StartOffset = This->start_offset;
726 desc->Size = This->size;
727 desc->uFlags = This->flags;
728 desc->DefaultValue = This->default_value;
733 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetType(
734 ID3D11ShaderReflectionVariable *iface)
736 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
738 TRACE("iface %p\n", iface);
740 return &This->type->ID3D11ShaderReflectionType_iface;
743 static ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetBuffer(
744 ID3D11ShaderReflectionVariable *iface)
746 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
748 TRACE("iface %p\n", iface);
750 return &This->constant_buffer->ID3D11ShaderReflectionConstantBuffer_iface;
753 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
754 ID3D11ShaderReflectionVariable *iface, UINT index)
756 FIXME("iface %p, index %u stub!\n", iface, index);
761 const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl =
763 /* ID3D11ShaderReflectionVariable methods */
764 d3dcompiler_shader_reflection_variable_GetDesc,
765 d3dcompiler_shader_reflection_variable_GetType,
766 d3dcompiler_shader_reflection_variable_GetBuffer,
767 d3dcompiler_shader_reflection_variable_GetInterfaceSlot,
770 /* ID3D11ShaderReflectionType methods */
772 static inline struct d3dcompiler_shader_reflection_type *impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType *iface)
774 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_type, ID3D11ShaderReflectionType_iface);
777 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetDesc(
778 ID3D11ShaderReflectionType *iface, D3D11_SHADER_TYPE_DESC *desc)
780 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
782 TRACE("iface %p, desc %p\n", iface, desc);
784 if (This == &null_type)
786 WARN("Null type specified\n");
792 WARN("Invalid argument specified\n");
801 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
802 ID3D11ShaderReflectionType *iface, UINT index)
804 FIXME("iface %p, index %u stub!\n", iface, index);
809 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByName(
810 ID3D11ShaderReflectionType *iface, LPCSTR name)
812 FIXME("iface %p, name %s stub!\n", iface, name);
817 static LPCSTR STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeName(
818 ID3D11ShaderReflectionType *iface, UINT index)
820 FIXME("iface %p, index %u stub!\n", iface, index);
825 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsEqual(
826 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
828 FIXME("iface %p, type %p stub!\n", iface, type);
833 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetSubType(
834 ID3D11ShaderReflectionType *iface)
836 FIXME("iface %p stub!\n", iface);
841 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetBaseClass(
842 ID3D11ShaderReflectionType *iface)
844 FIXME("iface %p stub!\n", iface);
849 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetNumInterfaces(
850 ID3D11ShaderReflectionType *iface)
852 FIXME("iface %p stub!\n", iface);
857 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
858 ID3D11ShaderReflectionType *iface, UINT index)
860 FIXME("iface %p, index %u stub!\n", iface, index);
865 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsOfType(
866 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
868 FIXME("iface %p, type %p stub!\n", iface, type);
873 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_ImplementsInterface(
874 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *base)
876 FIXME("iface %p, base %p stub!\n", iface, base);
881 const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl =
883 /* ID3D11ShaderReflectionType methods */
884 d3dcompiler_shader_reflection_type_GetDesc,
885 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex,
886 d3dcompiler_shader_reflection_type_GetMemberTypeByName,
887 d3dcompiler_shader_reflection_type_GetMemberTypeName,
888 d3dcompiler_shader_reflection_type_IsEqual,
889 d3dcompiler_shader_reflection_type_GetSubType,
890 d3dcompiler_shader_reflection_type_GetBaseClass,
891 d3dcompiler_shader_reflection_type_GetNumInterfaces,
892 d3dcompiler_shader_reflection_type_GetInterfaceByIndex,
893 d3dcompiler_shader_reflection_type_IsOfType,
894 d3dcompiler_shader_reflection_type_ImplementsInterface,
897 static HRESULT d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
899 const char *ptr = data;
900 DWORD size = data_size >> 2;
902 TRACE("Size %u\n", size);
904 read_dword(&ptr, &r->instruction_count);
905 TRACE("InstructionCount: %u\n", r->instruction_count);
907 read_dword(&ptr, &r->temp_register_count);
908 TRACE("TempRegisterCount: %u\n", r->temp_register_count);
910 skip_dword_unknown(&ptr, 1);
912 read_dword(&ptr, &r->dcl_count);
913 TRACE("DclCount: %u\n", r->dcl_count);
915 read_dword(&ptr, &r->float_instruction_count);
916 TRACE("FloatInstructionCount: %u\n", r->float_instruction_count);
918 read_dword(&ptr, &r->int_instruction_count);
919 TRACE("IntInstructionCount: %u\n", r->int_instruction_count);
921 read_dword(&ptr, &r->uint_instruction_count);
922 TRACE("UintInstructionCount: %u\n", r->uint_instruction_count);
924 read_dword(&ptr, &r->static_flow_control_count);
925 TRACE("StaticFlowControlCount: %u\n", r->static_flow_control_count);
927 read_dword(&ptr, &r->dynamic_flow_control_count);
928 TRACE("DynamicFlowControlCount: %u\n", r->dynamic_flow_control_count);
930 skip_dword_unknown(&ptr, 1);
932 read_dword(&ptr, &r->temp_array_count);
933 TRACE("TempArrayCount: %u\n", r->temp_array_count);
935 read_dword(&ptr, &r->array_instruction_count);
936 TRACE("ArrayInstructionCount: %u\n", r->array_instruction_count);
938 read_dword(&ptr, &r->cut_instruction_count);
939 TRACE("CutInstructionCount: %u\n", r->cut_instruction_count);
941 read_dword(&ptr, &r->emit_instruction_count);
942 TRACE("EmitInstructionCount: %u\n", r->emit_instruction_count);
944 read_dword(&ptr, &r->texture_normal_instructions);
945 TRACE("TextureNormalInstructions: %u\n", r->texture_normal_instructions);
947 read_dword(&ptr, &r->texture_load_instructions);
948 TRACE("TextureLoadInstructions: %u\n", r->texture_load_instructions);
950 read_dword(&ptr, &r->texture_comp_instructions);
951 TRACE("TextureCompInstructions: %u\n", r->texture_comp_instructions);
953 read_dword(&ptr, &r->texture_bias_instructions);
954 TRACE("TextureBiasInstructions: %u\n", r->texture_bias_instructions);
956 read_dword(&ptr, &r->texture_gradient_instructions);
957 TRACE("TextureGradientInstructions: %u\n", r->texture_gradient_instructions);
959 read_dword(&ptr, &r->mov_instruction_count);
960 TRACE("MovInstructionCount: %u\n", r->mov_instruction_count);
962 skip_dword_unknown(&ptr, 1);
964 read_dword(&ptr, &r->conversion_instruction_count);
965 TRACE("ConversionInstructionCount: %u\n", r->conversion_instruction_count);
967 skip_dword_unknown(&ptr, 1);
969 read_dword(&ptr, &r->input_primitive);
970 TRACE("InputPrimitive: %x\n", r->input_primitive);
972 read_dword(&ptr, &r->gs_output_topology);
973 TRACE("GSOutputTopology: %x\n", r->gs_output_topology);
975 read_dword(&ptr, &r->gs_max_output_vertex_count);
976 TRACE("GSMaxOutputVertexCount: %u\n", r->gs_max_output_vertex_count);
978 skip_dword_unknown(&ptr, 3);
981 if (size == 29) return S_OK;
983 skip_dword_unknown(&ptr, 1);
985 read_dword(&ptr, &r->c_control_points);
986 TRACE("cControlPoints: %u\n", r->c_control_points);
988 read_dword(&ptr, &r->hs_output_primitive);
989 TRACE("HSOutputPrimitive: %x\n", r->hs_output_primitive);
991 read_dword(&ptr, &r->hs_prtitioning);
992 TRACE("HSPartitioning: %x\n", r->hs_prtitioning);
994 read_dword(&ptr, &r->tessellator_domain);
995 TRACE("TessellatorDomain: %x\n", r->tessellator_domain);
997 skip_dword_unknown(&ptr, 3);
1000 if (size == 37) return S_OK;
1002 FIXME("Unhandled size %u\n", size);
1007 static HRESULT d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection *ref,
1008 struct d3dcompiler_shader_reflection_type_member *member, const char *data, const char **ptr)
1012 read_dword(ptr, &offset);
1013 if (!copy_name(data + offset, &member->name))
1015 ERR("Failed to copy name.\n");
1016 return E_OUTOFMEMORY;
1018 TRACE("Member name: %s.\n", debugstr_a(member->name));
1020 read_dword(ptr, &offset);
1021 TRACE("Member type offset: %x\n", offset);
1023 member->type = get_reflection_type(ref, data, offset);
1026 ERR("Failed to get member type\n");
1027 HeapFree(GetProcessHeap(), 0, member->name);
1031 read_dword(ptr, &member->offset);
1032 TRACE("Member offset %x\n", member->offset);
1037 static HRESULT d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type *type, const char *data, DWORD offset)
1039 const char *ptr = data + offset;
1041 D3D11_SHADER_TYPE_DESC *desc;
1043 struct d3dcompiler_shader_reflection_type_member *members;
1045 DWORD member_offset;
1049 read_dword(&ptr, &temp);
1050 desc->Class = temp & 0xffff;
1051 desc->Type = temp >> 16;
1052 TRACE("Class %x, Type %x\n", desc->Class, desc->Type);
1054 read_dword(&ptr, &temp);
1055 desc->Rows = temp & 0xffff;
1056 desc->Columns = temp >> 16;
1057 TRACE("Rows %u, Columns %u\n", desc->Rows, desc->Columns);
1059 read_dword(&ptr, &temp);
1060 desc->Elements = temp & 0xffff;
1061 desc->Members = temp >> 16;
1062 TRACE("Elements %u, Members %u\n", desc->Elements, desc->Members);
1064 read_dword(&ptr, &member_offset);
1065 TRACE("Member Offset %u\n", member_offset);
1067 if ((type->reflection->target & 0xffff) >= 0x500)
1068 skip_dword_unknown(&ptr, 4);
1072 const char *ptr2 = data + member_offset;
1074 members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*members));
1077 ERR("Failed to allocate type memory.\n");
1078 return E_OUTOFMEMORY;
1081 for (i = 0; i < desc->Members; ++i)
1083 hr = d3dcompiler_parse_type_members(type->reflection, &members[i], data, &ptr2);
1086 FIXME("Failed to parse type members.");
1092 type->members = members;
1097 for (i = 0; i < desc->Members; ++i)
1099 free_type_member(&members[i]);
1101 HeapFree(GetProcessHeap(), 0, members);
1105 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset)
1107 struct d3dcompiler_shader_reflection_type *type;
1108 struct wine_rb_entry *entry;
1111 entry = wine_rb_get(&reflection->types, &offset);
1114 TRACE("Returning existing type.\n");
1115 return WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
1118 type = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*type));
1121 ERR("Failed to allocate type memory.\n");
1125 type->ID3D11ShaderReflectionType_iface.lpVtbl = &d3dcompiler_shader_reflection_type_vtbl;
1127 type->reflection = reflection;
1129 hr = d3dcompiler_parse_type(type, data, offset);
1132 ERR("Failed to parse type info, hr %#x.\n", hr);
1133 HeapFree(GetProcessHeap(), 0, type);
1137 if (wine_rb_put(&reflection->types, &offset, &type->entry) == -1)
1139 ERR("Failed to insert type entry.\n");
1140 HeapFree(GetProcessHeap(), 0, type);
1147 static HRESULT d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer *cb,
1148 const char *data, DWORD data_size, const char *ptr)
1150 struct d3dcompiler_shader_reflection_variable *variables;
1154 variables = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb->variable_count * sizeof(*variables));
1157 ERR("Failed to allocate variables memory.\n");
1158 return E_OUTOFMEMORY;
1161 for (i = 0; i < cb->variable_count; i++)
1163 struct d3dcompiler_shader_reflection_variable *v = &variables[i];
1166 v->ID3D11ShaderReflectionVariable_iface.lpVtbl = &d3dcompiler_shader_reflection_variable_vtbl;
1167 v->constant_buffer = cb;
1169 read_dword(&ptr, &offset);
1170 if (!copy_name(data + offset, &v->name))
1172 ERR("Failed to copy name.\n");
1176 TRACE("Variable name: %s.\n", debugstr_a(v->name));
1178 read_dword(&ptr, &v->start_offset);
1179 TRACE("Variable offset: %u\n", v->start_offset);
1181 read_dword(&ptr, &v->size);
1182 TRACE("Variable size: %u\n", v->size);
1184 read_dword(&ptr, &v->flags);
1185 TRACE("Variable flags: %u\n", v->flags);
1187 read_dword(&ptr, &offset);
1188 TRACE("Variable type offset: %x\n", offset);
1189 v->type = get_reflection_type(cb->reflection, data, offset);
1192 ERR("Failed to get type.\n");
1197 read_dword(&ptr, &offset);
1198 TRACE("Variable default value offset: %x\n", offset);
1199 if (!copy_value(data + offset, &v->default_value, offset ? v->size : 0))
1201 ERR("Failed to copy name.\n");
1206 if ((cb->reflection->target & 0xffff) >= 0x500)
1207 skip_dword_unknown(&ptr, 4);
1210 cb->variables = variables;
1215 for (i = 0; i < cb->variable_count; i++)
1217 free_variable(&variables[i]);
1219 HeapFree(GetProcessHeap(), 0, variables);
1223 static HRESULT d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1225 const char *ptr = data;
1226 DWORD size = data_size >> 2;
1227 DWORD offset, cbuffer_offset, resource_offset, creator_offset;
1228 unsigned int i, string_data_offset, string_data_size;
1229 char *string_data = NULL, *creator = NULL;
1230 D3D11_SHADER_INPUT_BIND_DESC *bound_resources = NULL;
1231 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers = NULL;
1234 TRACE("Size %u\n", size);
1236 read_dword(&ptr, &r->constant_buffer_count);
1237 TRACE("Constant buffer count: %u\n", r->constant_buffer_count);
1239 read_dword(&ptr, &cbuffer_offset);
1240 TRACE("Constant buffer offset: %#x\n", cbuffer_offset);
1242 read_dword(&ptr, &r->bound_resource_count);
1243 TRACE("Bound resource count: %u\n", r->bound_resource_count);
1245 read_dword(&ptr, &resource_offset);
1246 TRACE("Bound resource offset: %#x\n", resource_offset);
1248 read_dword(&ptr, &r->target);
1249 TRACE("Target: %#x\n", r->target);
1251 read_dword(&ptr, &r->flags);
1252 TRACE("Flags: %u\n", r->flags);
1254 read_dword(&ptr, &creator_offset);
1255 TRACE("Creator at offset %#x.\n", creator_offset);
1257 if (!copy_name(data + creator_offset, &creator))
1259 ERR("Failed to copy name.\n");
1260 return E_OUTOFMEMORY;
1262 TRACE("Creator: %s.\n", debugstr_a(creator));
1264 /* todo: Parse RD11 */
1265 if ((r->target & 0x0000ffff) >= 0x500)
1267 skip_dword_unknown(&ptr, 8);
1270 if (r->bound_resource_count)
1272 /* 8 for each bind desc */
1273 string_data_offset = resource_offset + r->bound_resource_count * 8 * sizeof(DWORD);
1274 string_data_size = (cbuffer_offset ? cbuffer_offset : creator_offset) - string_data_offset;
1276 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1279 ERR("Failed to allocate string data memory.\n");
1283 memcpy(string_data, data + string_data_offset, string_data_size);
1285 bound_resources = HeapAlloc(GetProcessHeap(), 0, r->bound_resource_count * sizeof(*bound_resources));
1286 if (!bound_resources)
1288 ERR("Failed to allocate resources memory.\n");
1293 ptr = data + resource_offset;
1294 for (i = 0; i < r->bound_resource_count; i++)
1296 D3D11_SHADER_INPUT_BIND_DESC *desc = &bound_resources[i];
1298 read_dword(&ptr, &offset);
1299 desc->Name = string_data + (offset - string_data_offset);
1300 TRACE("Input bind Name: %s\n", debugstr_a(desc->Name));
1302 read_dword(&ptr, &desc->Type);
1303 TRACE("Input bind Type: %#x\n", desc->Type);
1305 read_dword(&ptr, &desc->ReturnType);
1306 TRACE("Input bind ReturnType: %#x\n", desc->ReturnType);
1308 read_dword(&ptr, &desc->Dimension);
1309 TRACE("Input bind Dimension: %#x\n", desc->Dimension);
1311 read_dword(&ptr, &desc->NumSamples);
1312 TRACE("Input bind NumSamples: %u\n", desc->NumSamples);
1314 read_dword(&ptr, &desc->BindPoint);
1315 TRACE("Input bind BindPoint: %u\n", desc->BindPoint);
1317 read_dword(&ptr, &desc->BindCount);
1318 TRACE("Input bind BindCount: %u\n", desc->BindCount);
1320 read_dword(&ptr, &desc->uFlags);
1321 TRACE("Input bind uFlags: %u\n", desc->uFlags);
1325 if (r->constant_buffer_count)
1327 constant_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, r->constant_buffer_count * sizeof(*constant_buffers));
1328 if (!constant_buffers)
1330 ERR("Failed to allocate constant buffer memory.\n");
1335 ptr = data + cbuffer_offset;
1336 for (i = 0; i < r->constant_buffer_count; i++)
1338 struct d3dcompiler_shader_reflection_constant_buffer *cb = &constant_buffers[i];
1340 cb->ID3D11ShaderReflectionConstantBuffer_iface.lpVtbl = &d3dcompiler_shader_reflection_constant_buffer_vtbl;
1343 read_dword(&ptr, &offset);
1344 if (!copy_name(data + offset, &cb->name))
1346 ERR("Failed to copy name.\n");
1350 TRACE("Name: %s.\n", debugstr_a(cb->name));
1352 read_dword(&ptr, &cb->variable_count);
1353 TRACE("Variable count: %u\n", cb->variable_count);
1355 read_dword(&ptr, &offset);
1356 TRACE("Variable offset: %x\n", offset);
1358 hr = d3dcompiler_parse_variables(cb, data, data_size, data + offset);
1361 FIXME("Failed to parse variables.");
1365 read_dword(&ptr, &cb->size);
1366 TRACE("Cbuffer size: %u\n", cb->size);
1368 read_dword(&ptr, &cb->flags);
1369 TRACE("Cbuffer flags: %u\n", cb->flags);
1371 read_dword(&ptr, &cb->type);
1372 TRACE("Cbuffer type: %#x\n", cb->type);
1376 r->creator = creator;
1377 r->resource_string = string_data;
1378 r->bound_resources = bound_resources;
1379 r->constant_buffers = constant_buffers;
1384 for (i = 0; i < r->constant_buffer_count; ++i)
1386 free_constant_buffer(&constant_buffers[i]);
1388 HeapFree(GetProcessHeap(), 0, constant_buffers);
1389 HeapFree(GetProcessHeap(), 0, bound_resources);
1390 HeapFree(GetProcessHeap(), 0, string_data);
1391 HeapFree(GetProcessHeap(), 0, creator);
1396 static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section, DWORD target)
1398 D3D11_SIGNATURE_PARAMETER_DESC *d;
1399 unsigned int string_data_offset;
1400 unsigned int string_data_size;
1401 const char *ptr = section->data;
1405 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size;
1407 switch (section->tag)
1410 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7;
1416 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1420 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4));
1421 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1425 read_dword(&ptr, &count);
1426 TRACE("%u elements\n", count);
1428 skip_dword_unknown(&ptr, 1);
1430 d = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*d));
1433 ERR("Failed to allocate signature memory.\n");
1434 return E_OUTOFMEMORY;
1437 /* 2 DWORDs for the header, element_size for each element. */
1438 string_data_offset = 2 * sizeof(DWORD) + count * element_size * sizeof(DWORD);
1439 string_data_size = section->data_size - string_data_offset;
1441 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1444 ERR("Failed to allocate string data memory.\n");
1445 HeapFree(GetProcessHeap(), 0, d);
1446 return E_OUTOFMEMORY;
1448 memcpy(string_data, section->data + string_data_offset, string_data_size);
1450 for (i = 0; i < count; ++i)
1455 if (element_size == D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7)
1457 read_dword(&ptr, &d[i].Stream);
1464 read_dword(&ptr, &name_offset);
1465 d[i].SemanticName = string_data + (name_offset - string_data_offset);
1466 read_dword(&ptr, &d[i].SemanticIndex);
1467 read_dword(&ptr, &d[i].SystemValueType);
1468 read_dword(&ptr, &d[i].ComponentType);
1469 read_dword(&ptr, &d[i].Register);
1470 read_dword(&ptr, &mask);
1471 d[i].ReadWriteMask = (mask >> 8) & 0xff;
1472 d[i].Mask = mask & 0xff;
1474 /* pixel shaders have a special handling for SystemValueType in the output signature */
1475 if (((target & 0xffff0000) == 0xffff0000) && (section->tag == TAG_OSG5 || section->tag == TAG_OSGN))
1477 TRACE("Pixelshader output signature fixup.\n");
1479 if (d[i].Register == 0xffffffff)
1481 if (!strcasecmp(d[i].SemanticName, "sv_depth")) d[i].SystemValueType = D3D_NAME_DEPTH;
1482 if (!strcasecmp(d[i].SemanticName, "sv_coverage")) d[i].SystemValueType = D3D_NAME_COVERAGE;
1483 if (!strcasecmp(d[i].SemanticName, "sv_depthgreaterequal")) d[i].SystemValueType = D3D_NAME_DEPTH_GREATER_EQUAL;
1484 if (!strcasecmp(d[i].SemanticName, "sv_depthlessequal")) d[i].SystemValueType = D3D_NAME_DEPTH_LESS_EQUAL;
1488 d[i].SystemValueType = D3D_NAME_TARGET;
1492 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
1493 "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n",
1494 debugstr_a(d[i].SemanticName), d[i].SemanticIndex, d[i].SystemValueType,
1495 d[i].ComponentType, d[i].Register, d[i].Mask, d[i].ReadWriteMask, d[i].Stream);
1499 s->element_count = count;
1500 s->string_data = string_data;
1505 static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1507 const char *ptr = data;
1509 read_dword(&ptr, &r->version);
1510 TRACE("Shader version: %u\n", r->version);
1512 /* todo: Check if anything else is needed from the shdr or shex blob. */
1517 HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection,
1518 const void *data, SIZE_T data_size)
1520 struct dxbc src_dxbc;
1524 reflection->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl;
1525 reflection->refcount = 1;
1527 if (wine_rb_init(&reflection->types, &d3dcompiler_shader_reflection_type_rb_functions) == -1)
1529 ERR("Failed to initialize type rbtree.\n");
1533 hr = dxbc_parse(data, data_size, &src_dxbc);
1536 WARN("Failed to parse reflection\n");
1540 for (i = 0; i < src_dxbc.count; ++i)
1542 struct dxbc_section *section = &src_dxbc.sections[i];
1544 switch (section->tag)
1547 hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size);
1550 WARN("Failed to parse RDEF section.\n");
1556 reflection->isgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->isgn));
1557 if (!reflection->isgn)
1559 ERR("Failed to allocate ISGN memory.\n");
1564 hr = d3dcompiler_parse_signature(reflection->isgn, section, reflection->target);
1567 WARN("Failed to parse section ISGN.\n");
1574 reflection->osgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->osgn));
1575 if (!reflection->osgn)
1577 ERR("Failed to allocate OSGN memory.\n");
1582 hr = d3dcompiler_parse_signature(reflection->osgn, section, reflection->target);
1585 WARN("Failed to parse section OSGN.\n");
1591 reflection->pcsg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->pcsg));
1592 if (!reflection->pcsg)
1594 ERR("Failed to allocate PCSG memory.\n");
1599 hr = d3dcompiler_parse_signature(reflection->pcsg, section, reflection->target);
1602 WARN("Failed to parse section PCSG.\n");
1609 hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size);
1612 WARN("Failed to parse SHDR section.\n");
1618 hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size);
1621 WARN("Failed to parse section STAT.\n");
1627 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4));
1632 dxbc_destroy(&src_dxbc);
1637 reflection_cleanup(reflection);
1638 dxbc_destroy(&src_dxbc);