From c42ee0339a8aa6069712059ccc6b3e72d10e9d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rico=20Sch=C3=BCller?= Date: Fri, 15 Jul 2011 10:52:36 +0200 Subject: [PATCH] d3dx9: Implement D3DXGetShaderSamplers(). --- dlls/d3dx9_36/d3dx9_36.spec | 2 +- dlls/d3dx9_36/shader.c | 62 +++++++++++++++++++ dlls/d3dx9_36/tests/shader.c | 111 +++++++++++++++++++++++++++++++++++ include/d3dx9shader.h | 1 + 4 files changed, 175 insertions(+), 1 deletion(-) diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec index 19c38c17bd8..c530d84fa0b 100644 --- a/dlls/d3dx9_36/d3dx9_36.spec +++ b/dlls/d3dx9_36/d3dx9_36.spec @@ -161,7 +161,7 @@ @ stdcall D3DXGetShaderConstantTableEx(ptr long ptr) @ stub D3DXGetShaderInputSemantics(ptr ptr ptr) @ stub D3DXGetShaderOutputSemantics(ptr ptr ptr) -@ stub D3DXGetShaderSamplers(ptr ptr ptr) +@ stdcall D3DXGetShaderSamplers(ptr ptr ptr) @ stdcall D3DXGetShaderSize(ptr) @ stdcall D3DXGetShaderVersion(ptr) @ stdcall D3DXGetVertexShaderProfile(ptr) diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c index 6a67f043371..000b41db438 100644 --- a/dlls/d3dx9_36/shader.c +++ b/dlls/d3dx9_36/shader.c @@ -1278,3 +1278,65 @@ HRESULT WINAPI D3DXGetShaderConstantTable(CONST DWORD* byte_code, return D3DXGetShaderConstantTableEx(byte_code, 0, constant_table); } + +HRESULT WINAPI D3DXGetShaderSamplers(CONST DWORD *byte_code, LPCSTR *samplers, UINT *count) +{ + HRESULT hr; + LPD3DXCONSTANTTABLE constant_table = NULL; + D3DXCONSTANTTABLE_DESC constant_table_desc; + UINT i, sampler_count = 0; + + TRACE("byte_code %p, samplers %p, count %p\n", byte_code, samplers, count); + + if (count) *count = 0; + + hr = D3DXGetShaderConstantTable(byte_code, &constant_table); + if (hr != D3D_OK) + { + WARN("Failed to get constant table\n"); + + /* no samplers found, all is fine */ + return D3D_OK; + } + + hr = ID3DXConstantTable_GetDesc(constant_table, &constant_table_desc); + if (hr != D3D_OK) + { + WARN("Failed to get constant table desc\n"); + goto err_out; + } + + for (i = 0; i < constant_table_desc.Constants; ++i) + { + D3DXHANDLE handle = ID3DXConstantTable_GetConstant(constant_table, NULL, i); + D3DXCONSTANT_DESC constant_desc; + UINT size; + + hr = ID3DXConstantTable_GetConstantDesc(constant_table, handle, &constant_desc, &size); + if (hr != D3D_OK) + { + WARN("Failed to get constant desc\n"); + goto err_out; + } + + if (constant_desc.Type == D3DXPT_SAMPLER + || constant_desc.Type == D3DXPT_SAMPLER1D + || constant_desc.Type == D3DXPT_SAMPLER2D + || constant_desc.Type == D3DXPT_SAMPLER3D + || constant_desc.Type == D3DXPT_SAMPLERCUBE) + { + if (samplers) samplers[sampler_count] = constant_desc.Name; + + ++sampler_count; + } + } + + TRACE("Found %u samplers\n", sampler_count); + +err_out: + + if (count) *count = sampler_count; + if (constant_table) ID3DXConstantTable_Release(constant_table); + + return hr; +} diff --git a/dlls/d3dx9_36/tests/shader.c b/dlls/d3dx9_36/tests/shader.c index 1d6f0da3411..0a1b8bf223e 100644 --- a/dlls/d3dx9_36/tests/shader.c +++ b/dlls/d3dx9_36/tests/shader.c @@ -702,6 +702,116 @@ static void test_get_sampler_index(void) ok(refcnt == 0, "The ID3DXConstantTable reference count was %u, should be 0\n", refcnt); } +/* + * fxc.exe /Tps_3_0 + */ +#if 0 +sampler s; +sampler1D s1D; +sampler2D s2D; +sampler3D s3D; +samplerCUBE scube; +float4 init; +float4 main(float3 tex : TEXCOORD0) : COLOR +{ + float4 tmp = init; + tmp = tmp + tex1D(s1D, tex.x); + tmp = tmp + tex1D(s1D, tex.y); + tmp = tmp + tex3D(s3D, tex.xyz); + tmp = tmp + tex1D(s, tex.x); + tmp = tmp + tex2D(s2D, tex.xy); + tmp = tmp + texCUBE(scube, tex.xyz); + return tmp; +} +#endif +static const DWORD get_shader_samplers_blob[] = +{ + 0xffff0300, /* ps_3_0 */ + 0x0054fffe, FCC_CTAB, /* CTAB comment */ + 0x0000001c, 0x0000011b, 0xffff0300, 0x00000006, 0x0000001c, 0x00000100, /* Header */ + 0x00000114, + 0x00000094, 0x00000002, 0x00000001, 0x0000009c, 0x00000000, /* Constant 1 desc (init) */ + 0x000000ac, 0x00040003, 0x00000001, 0x000000b0, 0x00000000, /* Constant 2 desc (s) */ + 0x000000c0, 0x00000003, 0x00000001, 0x000000c4, 0x00000000, /* Constant 3 desc (s1D) */ + 0x000000d4, 0x00010003, 0x00000001, 0x000000d8, 0x00000000, /* Constant 4 desc (s2D) */ + 0x000000e8, 0x00030003, 0x00000001, 0x000000ec, 0x00000000, /* Constant 5 desc (s3D) */ + 0x000000fc, 0x00020003, 0x00000001, 0x00000104, 0x00000000, /* Constant 6 desc (scube) */ + 0x74696e69, 0xababab00, /* Constant 1 name */ + 0x00030001, 0x00040001, 0x00000001, 0x00000000, /* Constant 1 type desc */ + 0xabab0073, /* Constant 2 name */ + 0x000c0004, 0x00010001, 0x00000001, 0x00000000, /* Constant 2 type desc */ + 0x00443173, /* Constant 3 name */ + 0x000b0004, 0x00010001, 0x00000001, 0x00000000, /* Constant 3 type desc */ + 0x00443273, /* Constant 4 name */ + 0x000c0004, 0x00010001, 0x00000001, 0x00000000, /* Constant 4 type desc */ + 0x00443373, /* Constant 5 name */ + 0x000d0004, 0x00010001, 0x00000001, 0x00000000, /* Constant 5 type desc */ + 0x62756373, 0xabab0065, /* Constant 6 name */ + 0x000e0004, 0x00010001, 0x00000001, 0x00000000, /* Constant 6 type desc */ + 0x335f7370, 0x4d00305f, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, /* Target/Creator name string */ + 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072, 0x392e3932, + 0x332e3235, 0x00313131, + 0x0200001f, 0x80000005, 0x90070000, 0x0200001f, 0x90000000, 0xa00f0800, /* shader */ + 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, 0x98000000, 0xa00f0802, + 0x0200001f, 0xa0000000, 0xa00f0803, 0x0200001f, 0x90000000, 0xa00f0804, + 0x03000042, 0x800f0000, 0x90e40000, 0xa0e40800, 0x03000002, 0x800f0000, + 0x80e40000, 0xa0e40000, 0x03000042, 0x800f0001, 0x90550000, 0xa0e40800, + 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x03000042, 0x800f0001, + 0x90e40000, 0xa0e40803, 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, + 0x03000042, 0x800f0001, 0x90e40000, 0xa0e40804, 0x03000002, 0x800f0000, + 0x80e40000, 0x80e40001, 0x03000042, 0x800f0001, 0x90e40000, 0xa0e40801, + 0x03000002, 0x800f0000, 0x80e40000, 0x80e40001, 0x03000042, 0x800f0001, + 0x90e40000, 0xa0e40802, 0x03000002, 0x800f0800, 0x80e40000, 0x80e40001, + 0x0000ffff, /* END */ +}; + +static void test_get_shader_samplers(void) +{ + LPCSTR samplers[16] = {NULL}; /* maximum number of sampler registers v/ps 3.0 = 16 */ + UINT count = 2; + HRESULT hr; + +#if 0 + /* crashes if bytecode is NULL */ + hr = D3DXGetShaderSamplers(NULL, NULL, &count); + ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK); +#endif + + hr = D3DXGetShaderSamplers(get_shader_samplers_blob, NULL, NULL); + ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK); + + samplers[5] = "dummy"; + + hr = D3DXGetShaderSamplers(get_shader_samplers_blob, samplers, NULL); + ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK); + + ok(!strcmp(samplers[0], "s"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[0], "s"); + ok(!strcmp(samplers[1], "s1D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[1], "s1D"); + ok(!strcmp(samplers[2], "s2D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[2], "s2D"); + ok(!strcmp(samplers[3], "s3D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[3], "s3D"); + ok(!strcmp(samplers[4], "scube"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[4], "scube"); + ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy"); + + /* reset samplers */ + memset(samplers, 0, sizeof(samplers)); + samplers[5] = "dummy"; + + hr = D3DXGetShaderSamplers(get_shader_samplers_blob, NULL, &count); + ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK); + ok(count == 5, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 5); + + hr = D3DXGetShaderSamplers(get_shader_samplers_blob, samplers, &count); + ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK); + ok(count == 5, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 5); + + ok(!strcmp(samplers[0], "s"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[0], "s"); + ok(!strcmp(samplers[1], "s1D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[1], "s1D"); + ok(!strcmp(samplers[2], "s2D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[2], "s2D"); + ok(!strcmp(samplers[3], "s3D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[3], "s3D"); + ok(!strcmp(samplers[4], "scube"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[4], "scube"); + ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy"); +} + START_TEST(shader) { test_get_shader_size(); @@ -711,4 +821,5 @@ START_TEST(shader) test_constant_tables(); test_setting_constants(); test_get_sampler_index(); + test_get_shader_samplers(); } diff --git a/include/d3dx9shader.h b/include/d3dx9shader.h index b5380a3a4a7..3d6ce98014c 100644 --- a/include/d3dx9shader.h +++ b/include/d3dx9shader.h @@ -257,6 +257,7 @@ UINT WINAPI D3DXGetShaderSize(const DWORD *byte_code); DWORD WINAPI D3DXGetShaderVersion(const DWORD *byte_code); LPCSTR WINAPI D3DXGetVertexShaderProfile(LPDIRECT3DDEVICE9 device); HRESULT WINAPI D3DXFindShaderComment(CONST DWORD* byte_code, DWORD fourcc, LPCVOID* data, UINT* size); +HRESULT WINAPI D3DXGetShaderSamplers(CONST DWORD *byte_code, LPCSTR *samplers, UINT *count); HRESULT WINAPI D3DXAssembleShaderFromFileA(LPCSTR filename, CONST D3DXMACRO* defines,