Signed-off-by: Paul Gofman pgofman@codeweavers.com --- v2: - fix reflection test in d3d10. v3: - show in test that QueryInterface between ID3D11.../ID3D12ShaderReflection returns the same interface pointer.
dlls/d3dcompiler_43/reflection.c | 280 +++++++++++++++++++++++-- dlls/d3dcompiler_43/tests/reflection.c | 61 ++++++ 2 files changed, 318 insertions(+), 23 deletions(-)
diff --git a/dlls/d3dcompiler_43/reflection.c b/dlls/d3dcompiler_43/reflection.c index 9a1e869f0a5..420af0aff9a 100644 --- a/dlls/d3dcompiler_43/reflection.c +++ b/dlls/d3dcompiler_43/reflection.c @@ -96,6 +96,7 @@ struct d3dcompiler_shader_reflection_constant_buffer /* ID3D11ShaderReflection */ struct d3dcompiler_shader_reflection { + ID3D12ShaderReflection ID3D12ShaderReflection_iface; ID3D11ShaderReflection ID3D11ShaderReflection_iface; ID3D10ShaderReflection ID3D10ShaderReflection_iface; LONG refcount; @@ -320,34 +321,18 @@ static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref) HeapFree(GetProcessHeap(), 0, ref->creator); }
-/* IUnknown methods */ - static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface) { return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface); }
-static HRESULT STDMETHODCALLTYPE d3d11_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object) +static inline struct d3dcompiler_shader_reflection *impl_from_ID3D12ShaderReflection(ID3D12ShaderReflection *iface) { - TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); - - if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection) - || IsEqualGUID(riid, &IID_IUnknown)) - { - IUnknown_AddRef(iface); - *object = iface; - return S_OK; - } - - WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); - - *object = NULL; - return E_NOINTERFACE; + return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D12ShaderReflection_iface); }
-static ULONG STDMETHODCALLTYPE d3d11_shader_reflection_AddRef(ID3D11ShaderReflection *iface) +static ULONG d3dcompiler_shader_reflection_AddRef(struct d3dcompiler_shader_reflection *reflection) { - struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface); ULONG refcount = InterlockedIncrement(&reflection->refcount);
TRACE("%p increasing refcount to %u.\n", reflection, refcount); @@ -355,9 +340,8 @@ static ULONG STDMETHODCALLTYPE d3d11_shader_reflection_AddRef(ID3D11ShaderReflec return refcount; }
-static ULONG STDMETHODCALLTYPE d3d11_shader_reflection_Release(ID3D11ShaderReflection *iface) +static ULONG d3dcompiler_shader_reflection_Release(struct d3dcompiler_shader_reflection *reflection) { - struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface); ULONG refcount = InterlockedDecrement(&reflection->refcount);
TRACE("%p decreasing refcount to %u.\n", reflection, refcount); @@ -371,6 +355,59 @@ static ULONG STDMETHODCALLTYPE d3d11_shader_reflection_Release(ID3D11ShaderRefle return refcount; }
+static HRESULT d3dcompiler_shader_reflection_QueryInterface(struct d3dcompiler_shader_reflection *reflection, + REFIID riid, void **object, IUnknown *iface) +{ + if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection)) + { + d3dcompiler_shader_reflection_AddRef(reflection); + *object = &reflection->ID3D11ShaderReflection_iface; + return S_OK; + } + +#if D3D_COMPILER_VERSION >= 47 + if (IsEqualGUID(riid, &IID_ID3D12ShaderReflection)) + { + d3dcompiler_shader_reflection_AddRef(reflection); + *object = &reflection->ID3D12ShaderReflection_iface; + return S_OK; + } +#endif + + if (IsEqualGUID(riid, &IID_IUnknown)) + { + d3dcompiler_shader_reflection_AddRef(reflection); + *object = iface; + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid)); + + *object = NULL; + return E_NOINTERFACE; +} + +/* IUnknown methods */ + +static HRESULT STDMETHODCALLTYPE d3d11_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, + REFIID riid, void **object) +{ + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + return d3dcompiler_shader_reflection_QueryInterface(impl_from_ID3D11ShaderReflection(iface), + riid, object, (IUnknown *)iface); +} + +static ULONG STDMETHODCALLTYPE d3d11_shader_reflection_AddRef(ID3D11ShaderReflection *iface) +{ + return d3dcompiler_shader_reflection_AddRef(impl_from_ID3D11ShaderReflection(iface)); +} + +static ULONG STDMETHODCALLTYPE d3d11_shader_reflection_Release(ID3D11ShaderReflection *iface) +{ + return d3dcompiler_shader_reflection_Release(impl_from_ID3D11ShaderReflection(iface)); +} + /* ID3D11ShaderReflection methods */
static HRESULT STDMETHODCALLTYPE d3d11_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc) @@ -2333,6 +2370,200 @@ HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10Shad } #endif
+static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_QueryInterface(ID3D12ShaderReflection *iface, + REFIID riid, void **object) +{ + TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object); + + return d3dcompiler_shader_reflection_QueryInterface(impl_from_ID3D12ShaderReflection(iface), + riid, object, (IUnknown *)iface); +} + +static ULONG STDMETHODCALLTYPE d3d12_shader_reflection_AddRef(ID3D12ShaderReflection *iface) +{ + return d3dcompiler_shader_reflection_AddRef(impl_from_ID3D12ShaderReflection(iface)); +} + +static ULONG STDMETHODCALLTYPE d3d12_shader_reflection_Release(ID3D12ShaderReflection *iface) +{ + return d3dcompiler_shader_reflection_Release(impl_from_ID3D12ShaderReflection(iface)); +} + +static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_GetDesc(ID3D12ShaderReflection *iface, D3D12_SHADER_DESC *desc) +{ + FIXME("iface %p, desc %p stub.\n", iface, desc); + + return E_NOTIMPL; +} + +static struct ID3D12ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3d12_shader_reflection_GetConstantBufferByIndex + (ID3D12ShaderReflection *iface, UINT index) +{ + FIXME("iface %p, index %u stub.\n", iface, index); + + return NULL; +} + +static struct ID3D12ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3d12_shader_reflection_GetConstantBufferByName + (ID3D12ShaderReflection *iface, const char *name) +{ + FIXME("iface %p, name %s stub.\n", iface, debugstr_a(name)); + + return NULL; +} + +static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_GetResourceBindingDesc(ID3D12ShaderReflection *iface, + UINT index, D3D12_SHADER_INPUT_BIND_DESC *desc) +{ + FIXME("iface %p, index %u, desc %p stub.\n", iface, index, desc); + + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_GetInputParameterDesc(ID3D12ShaderReflection *iface, + UINT index, D3D12_SIGNATURE_PARAMETER_DESC *desc) +{ + FIXME("iface %p, index %u, desc %p stub.\n", iface, index, desc); + + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_GetOutputParameterDesc(ID3D12ShaderReflection *iface, + UINT index, D3D12_SIGNATURE_PARAMETER_DESC *desc) +{ + FIXME("iface %p, index %u, desc %p stub.\n", iface, index, desc); + + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_GetPatchConstantParameterDesc(ID3D12ShaderReflection *iface, + UINT index, D3D12_SIGNATURE_PARAMETER_DESC *desc) +{ + FIXME("iface %p, index %u, desc %p stub.\n", iface, index, desc); + + return E_NOTIMPL; +} + +static struct ID3D12ShaderReflectionVariable * STDMETHODCALLTYPE d3d12_shader_reflection_GetVariableByName + (ID3D12ShaderReflection *iface, const char *name) +{ + FIXME("iface %p, name %s stub.\n", iface, debugstr_a(name)); + + return NULL; +} + +static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_GetResourceBindingDescByName(ID3D12ShaderReflection *iface, + const char *name, D3D12_SHADER_INPUT_BIND_DESC *desc) +{ + FIXME("iface %p, name %s, desc %p stub.\n", iface, debugstr_a(name), desc); + + return E_NOTIMPL; +} + +static UINT STDMETHODCALLTYPE d3d12_shader_reflection_GetMovInstructionCount(ID3D12ShaderReflection *iface) +{ + struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D12ShaderReflection(iface); + + TRACE("iface %p.\n", iface); + + return reflection->mov_instruction_count; +} + +static UINT STDMETHODCALLTYPE d3d12_shader_reflection_GetMovcInstructionCount(ID3D12ShaderReflection *iface) +{ + FIXME("iface %p stub.\n", iface); + + return 0; +} + +static UINT STDMETHODCALLTYPE d3d12_shader_reflection_GetConversionInstructionCount(ID3D12ShaderReflection *iface) +{ + struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D12ShaderReflection(iface); + + TRACE("iface %p.\n", iface); + + return reflection->conversion_instruction_count; +} + +static UINT STDMETHODCALLTYPE d3d12_shader_reflection_GetBitwiseInstructionCount(ID3D12ShaderReflection *iface) +{ + FIXME("iface %p stub.\n", iface); + + return 0; +} + +static D3D_PRIMITIVE STDMETHODCALLTYPE d3d12_shader_reflection_GetGSInputPrimitive(ID3D12ShaderReflection *iface) +{ + FIXME("iface %p stub.\n", iface); + + return 0; +} + +static BOOL STDMETHODCALLTYPE d3d12_shader_reflection_IsSampleFrequencyShader(ID3D12ShaderReflection *iface) +{ + FIXME("iface %p stub.\n", iface); + + return FALSE; +} + +static UINT STDMETHODCALLTYPE d3d12_shader_reflection_GetNumInterfaceSlots(ID3D12ShaderReflection *iface) +{ + FIXME("iface %p stub.\n", iface); + + return 0; +} + +static HRESULT STDMETHODCALLTYPE d3d12_shader_reflection_GetMinFeatureLevel(ID3D12ShaderReflection *iface, + D3D_FEATURE_LEVEL *level) +{ + FIXME("iface %p, level %p stub.\n", iface, level); + + return E_NOTIMPL; +} + +static UINT STDMETHODCALLTYPE d3d12_shader_reflection_GetThreadGroupSize(ID3D12ShaderReflection *iface, + UINT *sizex, UINT *sizey, UINT *sizez) +{ + FIXME("iface %p, sizex %p, sizey %p, sizez %p stub.\n", iface, sizex, sizey, sizez); + + return 0; +} + +static UINT64 STDMETHODCALLTYPE d3d12_shader_reflection_GetRequiresFlags(ID3D12ShaderReflection *iface) +{ + FIXME("iface %p stub.\n", iface); + + return 0; +} + +static const struct ID3D12ShaderReflectionVtbl d3d12_shader_reflection_vtbl = +{ + /* IUnknown methods */ + d3d12_shader_reflection_QueryInterface, + d3d12_shader_reflection_AddRef, + d3d12_shader_reflection_Release, + /* ID3D12ShaderReflection methods */ + d3d12_shader_reflection_GetDesc, + d3d12_shader_reflection_GetConstantBufferByIndex, + d3d12_shader_reflection_GetConstantBufferByName, + d3d12_shader_reflection_GetResourceBindingDesc, + d3d12_shader_reflection_GetInputParameterDesc, + d3d12_shader_reflection_GetOutputParameterDesc, + d3d12_shader_reflection_GetPatchConstantParameterDesc, + d3d12_shader_reflection_GetVariableByName, + d3d12_shader_reflection_GetResourceBindingDescByName, + d3d12_shader_reflection_GetMovInstructionCount, + d3d12_shader_reflection_GetMovcInstructionCount, + d3d12_shader_reflection_GetConversionInstructionCount, + d3d12_shader_reflection_GetBitwiseInstructionCount, + d3d12_shader_reflection_GetGSInputPrimitive, + d3d12_shader_reflection_IsSampleFrequencyShader, + d3d12_shader_reflection_GetNumInterfaceSlots, + d3d12_shader_reflection_GetMinFeatureLevel, + d3d12_shader_reflection_GetThreadGroupSize, + d3d12_shader_reflection_GetRequiresFlags, +}; + HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector) { struct d3dcompiler_shader_reflection *object; @@ -2357,7 +2588,8 @@ HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void #endif }
- if (!IsEqualGUID(riid, &IID_ID3D11ShaderReflection)) + if (!IsEqualGUID(riid, &IID_ID3D11ShaderReflection) + && (D3D_COMPILER_VERSION < 47 || !IsEqualGUID(riid, &IID_ID3D12ShaderReflection))) { WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid), debugstr_guid(&IID_ID3D11ShaderReflection)); #if D3D_COMPILER_VERSION >= 46 @@ -2372,6 +2604,7 @@ HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void return E_OUTOFMEMORY;
object->ID3D11ShaderReflection_iface.lpVtbl = &d3d11_shader_reflection_vtbl; + object->ID3D12ShaderReflection_iface.lpVtbl = &d3d12_shader_reflection_vtbl; object->refcount = 1;
hr = d3dcompiler_shader_reflection_init(object, data, data_size); @@ -2382,7 +2615,8 @@ HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void return hr; }
- *reflector = object; + *reflector = IsEqualGUID(riid, &IID_ID3D12ShaderReflection) ? (void **)&object->ID3D12ShaderReflection_iface + : (void **)&object->ID3D11ShaderReflection_iface;
TRACE("Created ID3D11ShaderReflection %p\n", object);
diff --git a/dlls/d3dcompiler_43/tests/reflection.c b/dlls/d3dcompiler_43/tests/reflection.c index 617003a97b7..18ff93e305f 100644 --- a/dlls/d3dcompiler_43/tests/reflection.c +++ b/dlls/d3dcompiler_43/tests/reflection.c @@ -157,6 +157,66 @@ static void test_reflection_references(void) } #endif
+#if D3D_COMPILER_VERSION +static void test_reflection_interfaces(void) +{ + ID3D12ShaderReflection *ref12 = NULL; + ID3D11ShaderReflection *ref11; + HRESULT hr, expected_hr; + IUnknown *iface, *iunk; + ULONG count; + + expected_hr = D3D_COMPILER_VERSION < 46 ? E_NOINTERFACE : D3D_COMPILER_VERSION == 46 ? E_INVALIDARG : S_OK; + hr = call_reflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D12ShaderReflection, (void **)&ref12); + /* Broken with older d3dcompiler_47. */ + ok(hr == expected_hr || broken(expected_hr == S_OK && hr == E_NOINTERFACE), "Got unexpected hr %#x.\n", hr); + + if (hr != S_OK) + return; + + hr = call_reflect(test_reflection_blob, test_reflection_blob[6], &IID_ID3D11ShaderReflection, (void **)&ref11); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + + hr = ref12->lpVtbl->QueryInterface(ref12, &IID_ID3D11ShaderReflection, (void **)&iface); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + todo_wine ok(iface == (void *)ref12, "Got unexpected interfaces %p, %p.\n", iface, ref12); + hr = iface->lpVtbl->QueryInterface(iface, &IID_IUnknown, (void **)&iunk); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + ok(iface == iunk, "Got unexpected iface %p.\n", iface); + iface->lpVtbl->Release(iunk); + iface->lpVtbl->Release(iface); + + hr = ref12->lpVtbl->QueryInterface(ref12, &IID_IUnknown, (void **)&iface); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + ok(iface == (IUnknown *)ref12, "Got unexpected iface %p.\n", iface); + iface->lpVtbl->Release(iface); + + hr = ref11->lpVtbl->QueryInterface(ref11, &IID_ID3D12ShaderReflection, (void **)&iface); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + todo_wine ok(iface == (void *)ref11, "Got unexpected interfaces %p, %p.\n", iface, ref11); + hr = iface->lpVtbl->QueryInterface(iface, &IID_IUnknown, (void **)&iunk); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + ok(iface == iunk, "Got unexpected iface %p.\n", iface); + iface->lpVtbl->Release(iunk); + iface->lpVtbl->Release(iface); + + hr = ref11->lpVtbl->QueryInterface(ref11, &IID_IUnknown, (void **)&iface); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + ok(iface == (IUnknown *)ref11, "Got unexpected iface %p.\n", iface); + iface->lpVtbl->Release(iface); + + hr = ref11->lpVtbl->QueryInterface(ref11, &IID_ID3D10ShaderReflection, (void **)&iface); + ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr); + hr = ref12->lpVtbl->QueryInterface(ref12, &IID_ID3D10ShaderReflection, (void **)&iface); + ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr); + + count = ref12->lpVtbl->Release(ref12); + ok(!count, "Got unexpected ref count %u.\n", count); + count = ref11->lpVtbl->Release(ref11); + ok(!count, "Got unexpected ref count %u.\n", count); +} +#endif + /* * fxc.exe /E VS /Tvs_4_1 /Fx */ @@ -1861,6 +1921,7 @@ START_TEST(reflection)
#if D3D_COMPILER_VERSION test_reflection_references(); + test_reflection_interfaces(); #endif test_reflection_desc_vs(); test_reflection_desc_ps();