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 BOOL copy_name(const char *ptr, char **name)
38 if (!ptr) return TRUE;
40 name_len = strlen(ptr) + 1;
46 *name = HeapAlloc(GetProcessHeap(), 0, name_len);
49 ERR("Failed to allocate name memory.\n");
53 memcpy(*name, ptr, name_len);
58 static void free_signature(struct d3dcompiler_shader_signature *sig)
60 TRACE("Free signature %p\n", sig);
62 HeapFree(GetProcessHeap(), 0, sig->elements);
63 HeapFree(GetProcessHeap(), 0, sig->string_data);
66 static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref)
68 TRACE("Cleanup %p\n", ref);
72 free_signature(ref->isgn);
73 HeapFree(GetProcessHeap(), 0, ref->isgn);
78 free_signature(ref->osgn);
79 HeapFree(GetProcessHeap(), 0, ref->osgn);
84 free_signature(ref->pcsg);
85 HeapFree(GetProcessHeap(), 0, ref->pcsg);
88 HeapFree(GetProcessHeap(), 0, ref->bound_resources);
89 HeapFree(GetProcessHeap(), 0, ref->resource_string);
90 HeapFree(GetProcessHeap(), 0, ref->creator);
93 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface)
95 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface);
98 /* IUnknown methods */
100 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object)
102 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
104 if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
105 || IsEqualGUID(riid, &IID_IUnknown))
107 IUnknown_AddRef(iface);
112 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
115 return E_NOINTERFACE;
118 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection *iface)
120 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
121 ULONG refcount = InterlockedIncrement(&This->refcount);
123 TRACE("%p increasing refcount to %u\n", This, refcount);
128 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection *iface)
130 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
131 ULONG refcount = InterlockedDecrement(&This->refcount);
133 TRACE("%p decreasing refcount to %u\n", This, refcount);
137 reflection_cleanup(This);
138 HeapFree(GetProcessHeap(), 0, This);
144 /* ID3D11ShaderReflection methods */
146 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc)
148 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
150 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
154 WARN("Invalid argument specified\n");
158 desc->Version = This->version;
159 desc->Creator = This->creator;
160 desc->Flags = This->flags;
161 desc->ConstantBuffers = This->constant_buffer_count;
162 desc->BoundResources = This->bound_resource_count;
163 desc->InputParameters = This->isgn ? This->isgn->element_count : 0;
164 desc->OutputParameters = This->osgn ? This->osgn->element_count : 0;
165 desc->InstructionCount = This->instruction_count;
166 desc->TempRegisterCount = This->temp_register_count;
167 desc->TempArrayCount = This->temp_array_count;
169 desc->DclCount = This->dcl_count;
170 desc->TextureNormalInstructions = This->texture_normal_instructions;
171 desc->TextureLoadInstructions = This->texture_load_instructions;
172 desc->TextureCompInstructions = This->texture_comp_instructions;
173 desc->TextureBiasInstructions = This->texture_bias_instructions;
174 desc->TextureGradientInstructions = This->texture_gradient_instructions;
175 desc->FloatInstructionCount = This->float_instruction_count;
176 desc->IntInstructionCount = This->int_instruction_count;
177 desc->UintInstructionCount = This->uint_instruction_count;
178 desc->StaticFlowControlCount = This->static_flow_control_count;
179 desc->DynamicFlowControlCount = This->dynamic_flow_control_count;
180 desc->MacroInstructionCount = 0;
181 desc->ArrayInstructionCount = This->array_instruction_count;
182 desc->CutInstructionCount = This->cut_instruction_count;
183 desc->EmitInstructionCount = This->emit_instruction_count;
184 desc->GSOutputTopology = This->gs_output_topology;
185 desc->GSMaxOutputVertexCount = This->gs_max_output_vertex_count;
186 desc->InputPrimitive = This->input_primitive;
187 desc->PatchConstantParameters = This->pcsg ? This->pcsg->element_count : 0;
188 desc->cGSInstanceCount = 0;
189 desc->cControlPoints = This->c_control_points;
190 desc->HSOutputPrimitive = This->hs_output_primitive;
191 desc->HSPartitioning = This->hs_prtitioning;
192 desc->TessellatorDomain = This->tessellator_domain;
193 desc->cBarrierInstructions = 0;
194 desc->cInterlockedInstructions = 0;
195 desc->cTextureStoreInstructions = 0;
200 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByIndex(
201 ID3D11ShaderReflection *iface, UINT index)
203 FIXME("iface %p, index %u stub!\n", iface, index);
208 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByName(
209 ID3D11ShaderReflection *iface, LPCSTR name)
211 FIXME("iface %p, name \"%s\" stub!\n", iface, name);
216 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDesc(
217 ID3D11ShaderReflection *iface, UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc)
219 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
221 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
223 if (!desc || index >= This->bound_resource_count)
225 WARN("Invalid argument specified\n");
229 *desc = This->bound_resources[index];
234 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetInputParameterDesc(
235 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
237 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
239 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
241 if (!desc || !This->isgn || index >= This->isgn->element_count)
243 WARN("Invalid argument specified\n");
247 *desc = This->isgn->elements[index];
252 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetOutputParameterDesc(
253 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
255 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
257 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
259 if (!desc || !This->osgn || index >= This->osgn->element_count)
261 WARN("Invalid argument specified\n");
265 *desc = This->osgn->elements[index];
270 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
271 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
273 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
275 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
277 if (!desc || !This->pcsg || index >= This->pcsg->element_count)
279 WARN("Invalid argument specified\n");
283 *desc = This->pcsg->elements[index];
288 static struct ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetVariableByName(
289 ID3D11ShaderReflection *iface, LPCSTR name)
291 FIXME("iface %p, name %s stub!\n", iface, name);
296 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDescByName(
297 ID3D11ShaderReflection *iface, LPCSTR name, D3D11_SHADER_INPUT_BIND_DESC *desc)
299 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
302 TRACE("iface %p, name %s, desc %p\n", iface, debugstr_a(name), desc);
306 WARN("Invalid argument specified\n");
310 for (i = 0; i < This->bound_resource_count; ++i)
312 D3D11_SHADER_INPUT_BIND_DESC *d = &This->bound_resources[i];
314 if (!strcmp(d->Name, name))
316 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d);
322 WARN("Invalid name specified\n");
327 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovInstructionCount(
328 ID3D11ShaderReflection *iface)
330 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
332 TRACE("iface %p\n", iface);
334 return This->mov_instruction_count;
337 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovcInstructionCount(
338 ID3D11ShaderReflection *iface)
340 FIXME("iface %p stub!\n", iface);
345 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConversionInstructionCount(
346 ID3D11ShaderReflection *iface)
348 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
350 TRACE("iface %p\n", iface);
352 return This->conversion_instruction_count;
355 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
356 ID3D11ShaderReflection *iface)
358 FIXME("iface %p stub!\n", iface);
363 static D3D_PRIMITIVE STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetGSInputPrimitive(
364 ID3D11ShaderReflection *iface)
366 FIXME("iface %p stub!\n", iface);
371 static BOOL STDMETHODCALLTYPE d3dcompiler_shader_reflection_IsSampleFrequencyShader(
372 ID3D11ShaderReflection *iface)
374 FIXME("iface %p stub!\n", iface);
379 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetNumInterfaceSlots(
380 ID3D11ShaderReflection *iface)
382 FIXME("iface %p stub!\n", iface);
387 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMinFeatureLevel(
388 ID3D11ShaderReflection *iface, D3D_FEATURE_LEVEL *level)
390 FIXME("iface %p, level %p stub!\n", iface, level);
395 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetThreadGroupSize(
396 ID3D11ShaderReflection *iface, UINT *sizex, UINT *sizey, UINT *sizez)
398 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface, sizex, sizey, sizez);
403 const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl =
405 /* IUnknown methods */
406 d3dcompiler_shader_reflection_QueryInterface,
407 d3dcompiler_shader_reflection_AddRef,
408 d3dcompiler_shader_reflection_Release,
409 /* ID3D11ShaderReflection methods */
410 d3dcompiler_shader_reflection_GetDesc,
411 d3dcompiler_shader_reflection_GetConstantBufferByIndex,
412 d3dcompiler_shader_reflection_GetConstantBufferByName,
413 d3dcompiler_shader_reflection_GetResourceBindingDesc,
414 d3dcompiler_shader_reflection_GetInputParameterDesc,
415 d3dcompiler_shader_reflection_GetOutputParameterDesc,
416 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc,
417 d3dcompiler_shader_reflection_GetVariableByName,
418 d3dcompiler_shader_reflection_GetResourceBindingDescByName,
419 d3dcompiler_shader_reflection_GetMovInstructionCount,
420 d3dcompiler_shader_reflection_GetMovcInstructionCount,
421 d3dcompiler_shader_reflection_GetConversionInstructionCount,
422 d3dcompiler_shader_reflection_GetBitwiseInstructionCount,
423 d3dcompiler_shader_reflection_GetGSInputPrimitive,
424 d3dcompiler_shader_reflection_IsSampleFrequencyShader,
425 d3dcompiler_shader_reflection_GetNumInterfaceSlots,
426 d3dcompiler_shader_reflection_GetMinFeatureLevel,
427 d3dcompiler_shader_reflection_GetThreadGroupSize,
430 static HRESULT d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
432 const char *ptr = data;
433 DWORD size = data_size >> 2;
435 TRACE("Size %u\n", size);
437 read_dword(&ptr, &r->instruction_count);
438 TRACE("InstructionCount: %u\n", r->instruction_count);
440 read_dword(&ptr, &r->temp_register_count);
441 TRACE("TempRegisterCount: %u\n", r->temp_register_count);
443 skip_dword_unknown(&ptr, 1);
445 read_dword(&ptr, &r->dcl_count);
446 TRACE("DclCount: %u\n", r->dcl_count);
448 read_dword(&ptr, &r->float_instruction_count);
449 TRACE("FloatInstructionCount: %u\n", r->float_instruction_count);
451 read_dword(&ptr, &r->int_instruction_count);
452 TRACE("IntInstructionCount: %u\n", r->int_instruction_count);
454 read_dword(&ptr, &r->uint_instruction_count);
455 TRACE("UintInstructionCount: %u\n", r->uint_instruction_count);
457 read_dword(&ptr, &r->static_flow_control_count);
458 TRACE("StaticFlowControlCount: %u\n", r->static_flow_control_count);
460 read_dword(&ptr, &r->dynamic_flow_control_count);
461 TRACE("DynamicFlowControlCount: %u\n", r->dynamic_flow_control_count);
463 skip_dword_unknown(&ptr, 1);
465 read_dword(&ptr, &r->temp_array_count);
466 TRACE("TempArrayCount: %u\n", r->temp_array_count);
468 read_dword(&ptr, &r->array_instruction_count);
469 TRACE("ArrayInstructionCount: %u\n", r->array_instruction_count);
471 read_dword(&ptr, &r->cut_instruction_count);
472 TRACE("CutInstructionCount: %u\n", r->cut_instruction_count);
474 read_dword(&ptr, &r->emit_instruction_count);
475 TRACE("EmitInstructionCount: %u\n", r->emit_instruction_count);
477 read_dword(&ptr, &r->texture_normal_instructions);
478 TRACE("TextureNormalInstructions: %u\n", r->texture_normal_instructions);
480 read_dword(&ptr, &r->texture_load_instructions);
481 TRACE("TextureLoadInstructions: %u\n", r->texture_load_instructions);
483 read_dword(&ptr, &r->texture_comp_instructions);
484 TRACE("TextureCompInstructions: %u\n", r->texture_comp_instructions);
486 read_dword(&ptr, &r->texture_bias_instructions);
487 TRACE("TextureBiasInstructions: %u\n", r->texture_bias_instructions);
489 read_dword(&ptr, &r->texture_gradient_instructions);
490 TRACE("TextureGradientInstructions: %u\n", r->texture_gradient_instructions);
492 read_dword(&ptr, &r->mov_instruction_count);
493 TRACE("MovInstructionCount: %u\n", r->mov_instruction_count);
495 skip_dword_unknown(&ptr, 1);
497 read_dword(&ptr, &r->conversion_instruction_count);
498 TRACE("ConversionInstructionCount: %u\n", r->conversion_instruction_count);
500 skip_dword_unknown(&ptr, 1);
502 read_dword(&ptr, &r->input_primitive);
503 TRACE("InputPrimitive: %x\n", r->input_primitive);
505 read_dword(&ptr, &r->gs_output_topology);
506 TRACE("GSOutputTopology: %x\n", r->gs_output_topology);
508 read_dword(&ptr, &r->gs_max_output_vertex_count);
509 TRACE("GSMaxOutputVertexCount: %u\n", r->gs_max_output_vertex_count);
511 skip_dword_unknown(&ptr, 3);
514 if (size == 29) return S_OK;
516 skip_dword_unknown(&ptr, 1);
518 read_dword(&ptr, &r->c_control_points);
519 TRACE("cControlPoints: %u\n", r->c_control_points);
521 read_dword(&ptr, &r->hs_output_primitive);
522 TRACE("HSOutputPrimitive: %x\n", r->hs_output_primitive);
524 read_dword(&ptr, &r->hs_prtitioning);
525 TRACE("HSPartitioning: %x\n", r->hs_prtitioning);
527 read_dword(&ptr, &r->tessellator_domain);
528 TRACE("TessellatorDomain: %x\n", r->tessellator_domain);
530 skip_dword_unknown(&ptr, 3);
533 if (size == 37) return S_OK;
535 FIXME("Unhandled size %u\n", size);
540 static HRESULT d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
542 const char *ptr = data;
543 DWORD size = data_size >> 2;
544 DWORD offset, cbuffer_offset, resource_offset, creator_offset;
546 unsigned int string_data_offset;
547 unsigned int string_data_size;
548 char *string_data = NULL, *creator = NULL;
549 D3D11_SHADER_INPUT_BIND_DESC *bound_resources = NULL;
552 TRACE("Size %u\n", size);
554 read_dword(&ptr, &r->constant_buffer_count);
555 TRACE("Constant buffer count: %u\n", r->constant_buffer_count);
557 read_dword(&ptr, &cbuffer_offset);
558 TRACE("Constant buffer offset: %#x\n", cbuffer_offset);
560 read_dword(&ptr, &r->bound_resource_count);
561 TRACE("Bound resource count: %u\n", r->bound_resource_count);
563 read_dword(&ptr, &resource_offset);
564 TRACE("Bound resource offset: %#x\n", resource_offset);
566 read_dword(&ptr, &r->target);
567 TRACE("Target: %#x\n", r->target);
569 read_dword(&ptr, &r->flags);
570 TRACE("Flags: %u\n", r->flags);
572 read_dword(&ptr, &creator_offset);
573 TRACE("Creator at offset %#x.\n", creator_offset);
575 if (!copy_name(data + creator_offset, &creator))
577 ERR("Failed to copy name.\n");
578 return E_OUTOFMEMORY;
580 TRACE("Creator: %s.\n", debugstr_a(creator));
582 /* todo: Parse RD11 */
583 if ((r->target & 0x0000ffff) >= 0x500)
585 skip_dword_unknown(&ptr, 8);
588 if (r->bound_resource_count)
590 /* 8 for each bind desc */
591 string_data_offset = resource_offset + r->bound_resource_count * 8 * sizeof(DWORD);
592 string_data_size = (cbuffer_offset ? cbuffer_offset : creator_offset) - string_data_offset;
594 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
597 ERR("Failed to allocate string data memory.\n");
601 memcpy(string_data, data + string_data_offset, string_data_size);
603 bound_resources = HeapAlloc(GetProcessHeap(), 0, r->bound_resource_count * sizeof(*bound_resources));
604 if (!bound_resources)
606 ERR("Failed to allocate resources memory.\n");
611 ptr = data + resource_offset;
612 for (i = 0; i < r->bound_resource_count; i++)
614 D3D11_SHADER_INPUT_BIND_DESC *desc = &bound_resources[i];
616 read_dword(&ptr, &offset);
617 desc->Name = string_data + (offset - string_data_offset);
618 TRACE("Input bind Name: %s\n", debugstr_a(desc->Name));
620 read_dword(&ptr, &desc->Type);
621 TRACE("Input bind Type: %#x\n", desc->Type);
623 read_dword(&ptr, &desc->ReturnType);
624 TRACE("Input bind ReturnType: %#x\n", desc->ReturnType);
626 read_dword(&ptr, &desc->Dimension);
627 TRACE("Input bind Dimension: %#x\n", desc->Dimension);
629 read_dword(&ptr, &desc->NumSamples);
630 TRACE("Input bind NumSamples: %u\n", desc->NumSamples);
632 read_dword(&ptr, &desc->BindPoint);
633 TRACE("Input bind BindPoint: %u\n", desc->BindPoint);
635 read_dword(&ptr, &desc->BindCount);
636 TRACE("Input bind BindCount: %u\n", desc->BindCount);
638 read_dword(&ptr, &desc->uFlags);
639 TRACE("Input bind uFlags: %u\n", desc->uFlags);
643 /* todo: Parse Constant buffers */
645 r->creator = creator;
646 r->resource_string = string_data;
647 r->bound_resources = bound_resources;
652 HeapFree(GetProcessHeap(), 0, bound_resources);
653 HeapFree(GetProcessHeap(), 0, string_data);
654 HeapFree(GetProcessHeap(), 0, creator);
659 HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section)
661 D3D11_SIGNATURE_PARAMETER_DESC *d;
662 unsigned int string_data_offset;
663 unsigned int string_data_size;
664 const char *ptr = section->data;
668 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size;
670 switch (section->tag)
673 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7;
679 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
683 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4));
684 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
688 read_dword(&ptr, &count);
689 TRACE("%u elements\n", count);
691 skip_dword_unknown(&ptr, 1);
693 d = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*d));
696 ERR("Failed to allocate signature memory.\n");
697 return E_OUTOFMEMORY;
700 /* 2 DWORDs for the header, element_size for each element. */
701 string_data_offset = 2 * sizeof(DWORD) + count * element_size * sizeof(DWORD);
702 string_data_size = section->data_size - string_data_offset;
704 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
707 ERR("Failed to allocate string data memory.\n");
708 HeapFree(GetProcessHeap(), 0, d);
709 return E_OUTOFMEMORY;
711 memcpy(string_data, section->data + string_data_offset, string_data_size);
713 for (i = 0; i < count; ++i)
718 if (element_size == D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7)
720 read_dword(&ptr, &d[i].Stream);
727 read_dword(&ptr, &name_offset);
728 d[i].SemanticName = string_data + (name_offset - string_data_offset);
729 read_dword(&ptr, &d[i].SemanticIndex);
730 read_dword(&ptr, &d[i].SystemValueType);
731 read_dword(&ptr, &d[i].ComponentType);
732 read_dword(&ptr, &d[i].Register);
733 read_dword(&ptr, &mask);
734 d[i].ReadWriteMask = (mask >> 8) & 0xff;
735 d[i].Mask = mask & 0xff;
737 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
738 "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n",
739 debugstr_a(d[i].SemanticName), d[i].SemanticIndex, d[i].SystemValueType,
740 d[i].ComponentType, d[i].Register, d[i].Mask, d[i].ReadWriteMask, d[i].Stream);
744 s->element_count = count;
745 s->string_data = string_data;
750 static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
752 const char *ptr = data;
754 read_dword(&ptr, &r->version);
755 TRACE("Shader version: %u\n", r->version);
757 /* todo: Check if anything else is needed from the shdr or shex blob. */
762 HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection,
763 const void *data, SIZE_T data_size)
765 struct dxbc src_dxbc;
769 reflection->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl;
770 reflection->refcount = 1;
772 hr = dxbc_parse(data, data_size, &src_dxbc);
775 WARN("Failed to parse reflection\n");
779 for (i = 0; i < src_dxbc.count; ++i)
781 struct dxbc_section *section = &src_dxbc.sections[i];
783 switch (section->tag)
786 hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size);
789 WARN("Failed to parse section STAT.\n");
796 hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size);
799 WARN("Failed to parse SHDR section.\n");
805 hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size);
808 WARN("Failed to parse RDEF section.\n");
814 reflection->isgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->isgn));
815 if (!reflection->isgn)
817 ERR("Failed to allocate ISGN memory.\n");
822 hr = d3dcompiler_parse_signature(reflection->isgn, section);
825 WARN("Failed to parse section ISGN.\n");
832 reflection->osgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->osgn));
833 if (!reflection->osgn)
835 ERR("Failed to allocate OSGN memory.\n");
840 hr = d3dcompiler_parse_signature(reflection->osgn, section);
843 WARN("Failed to parse section OSGN.\n");
849 reflection->pcsg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->pcsg));
850 if (!reflection->pcsg)
852 ERR("Failed to allocate PCSG memory.\n");
857 hr = d3dcompiler_parse_signature(reflection->pcsg, section);
860 WARN("Failed to parse section PCSG.\n");
866 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4));
871 dxbc_destroy(&src_dxbc);
876 reflection_cleanup(reflection);
877 dxbc_destroy(&src_dxbc);