d3dx9: Use the original bytecode in D3DXGetShaderSamplers() instead of using a constant table.

This commit is contained in:
Rico Schüller 2011-09-16 08:38:24 +02:00 committed by Alexandre Julliard
parent c4db72f50e
commit 7cfdaedd3e
2 changed files with 67 additions and 47 deletions

View File

@ -1273,50 +1273,40 @@ HRESULT WINAPI D3DXGetShaderConstantTable(CONST DWORD* byte_code,
HRESULT WINAPI D3DXGetShaderSamplers(CONST DWORD *byte_code, LPCSTR *samplers, UINT *count) HRESULT WINAPI D3DXGetShaderSamplers(CONST DWORD *byte_code, LPCSTR *samplers, UINT *count)
{ {
HRESULT hr; HRESULT hr;
LPD3DXCONSTANTTABLE constant_table = NULL;
D3DXCONSTANTTABLE_DESC constant_table_desc;
UINT i, sampler_count = 0; UINT i, sampler_count = 0;
UINT size;
LPCSTR data;
const D3DXSHADER_CONSTANTTABLE *ctab_header;
const D3DXSHADER_CONSTANTINFO *constant_info;
TRACE("byte_code %p, samplers %p, count %p\n", byte_code, samplers, count); TRACE("byte_code %p, samplers %p, count %p\n", byte_code, samplers, count);
if (count) *count = 0; if (count) *count = 0;
hr = D3DXGetShaderConstantTable(byte_code, &constant_table); hr = D3DXFindShaderComment(byte_code, MAKEFOURCC('C','T','A','B'), (LPCVOID *)&data, &size);
if (hr != D3D_OK) if (hr != D3D_OK) return D3D_OK;
if (size < sizeof(D3DXSHADER_CONSTANTTABLE)) return D3D_OK;
ctab_header = (const D3DXSHADER_CONSTANTTABLE *)data;
if (ctab_header->Size != sizeof(*ctab_header)) return D3D_OK;
constant_info = (D3DXSHADER_CONSTANTINFO *)(data + ctab_header->ConstantInfo);
for (i = 0; i < ctab_header->Constants; i++)
{ {
WARN("Failed to get constant table\n"); const D3DXSHADER_TYPEINFO *type;
/* no samplers found, all is fine */ TRACE("name = %s\n", data + constant_info[i].Name);
return D3D_OK;
}
hr = ID3DXConstantTable_GetDesc(constant_table, &constant_table_desc); type = (D3DXSHADER_TYPEINFO *)(data + constant_info[i].TypeInfo);
if (hr != D3D_OK)
{
WARN("Failed to get constant table desc\n");
goto err_out;
}
for (i = 0; i < constant_table_desc.Constants; ++i) if (type->Type == D3DXPT_SAMPLER
{ || type->Type == D3DXPT_SAMPLER1D
D3DXHANDLE handle = ID3DXConstantTable_GetConstant(constant_table, NULL, i); || type->Type == D3DXPT_SAMPLER2D
D3DXCONSTANT_DESC constant_desc; || type->Type == D3DXPT_SAMPLER3D
UINT size; || type->Type == D3DXPT_SAMPLERCUBE)
hr = ID3DXConstantTable_GetConstantDesc(constant_table, handle, &constant_desc, &size);
if (hr != D3D_OK)
{ {
WARN("Failed to get constant desc\n"); if (samplers) samplers[sampler_count] = data + constant_info[i].Name;
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; ++sampler_count;
} }
@ -1324,10 +1314,7 @@ HRESULT WINAPI D3DXGetShaderSamplers(CONST DWORD *byte_code, LPCSTR *samplers, U
TRACE("Found %u samplers\n", sampler_count); TRACE("Found %u samplers\n", sampler_count);
err_out:
if (count) *count = sampler_count; if (count) *count = sampler_count;
if (constant_table) ID3DXConstantTable_Release(constant_table);
return hr; return D3D_OK;
} }

View File

@ -768,6 +768,7 @@ static const DWORD get_shader_samplers_blob[] =
static void test_get_shader_samplers(void) static void test_get_shader_samplers(void)
{ {
LPCSTR samplers[16] = {NULL}; /* maximum number of sampler registers v/ps 3.0 = 16 */ LPCSTR samplers[16] = {NULL}; /* maximum number of sampler registers v/ps 3.0 = 16 */
LPCSTR sampler_orig;
UINT count = 2; UINT count = 2;
HRESULT hr; HRESULT hr;
@ -785,11 +786,22 @@ static void test_get_shader_samplers(void)
hr = D3DXGetShaderSamplers(get_shader_samplers_blob, samplers, NULL); hr = D3DXGetShaderSamplers(get_shader_samplers_blob, samplers, NULL);
ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK); 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"); /* check that sampler points to shader blob */
ok(!strcmp(samplers[1], "s1D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[1], "s1D"); sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x2E];
ok(!strcmp(samplers[2], "s2D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[2], "s2D"); ok(sampler_orig == samplers[0], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[0], sampler_orig);
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"); sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x33];
ok(sampler_orig == samplers[1], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[1], sampler_orig);
sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x38];
ok(sampler_orig == samplers[2], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[2], sampler_orig);
sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x3D];
ok(sampler_orig == samplers[3], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[3], sampler_orig);
sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x42];
ok(sampler_orig == samplers[4], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[4], sampler_orig);
ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy"); ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy");
/* reset samplers */ /* reset samplers */
@ -804,12 +816,33 @@ static void test_get_shader_samplers(void)
ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK); 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(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"); /* check that sampler points to shader blob */
ok(!strcmp(samplers[1], "s1D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[1], "s1D"); sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x2E];
ok(!strcmp(samplers[2], "s2D"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[2], "s2D"); ok(sampler_orig == samplers[0], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[0], sampler_orig);
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"); sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x33];
ok(sampler_orig == samplers[1], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[1], sampler_orig);
sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x38];
ok(sampler_orig == samplers[2], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[2], sampler_orig);
sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x3D];
ok(sampler_orig == samplers[3], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[3], sampler_orig);
sampler_orig = (LPCSTR)&get_shader_samplers_blob[0x42];
ok(sampler_orig == samplers[4], "D3DXGetShaderSamplers failed, got %p, expected %p\n", samplers[4], sampler_orig);
ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy"); ok(!strcmp(samplers[5], "dummy"), "D3DXGetShaderSamplers failed, got \"%s\", expected \"%s\"\n", samplers[5], "dummy");
/* check without ctab */
hr = D3DXGetShaderSamplers(simple_vs, samplers, &count);
ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
ok(count == 0, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 0);
/* check invalid ctab */
hr = D3DXGetShaderSamplers(shader_with_invalid_ctab, samplers, &count);
ok(hr == D3D_OK, "D3DXGetShaderSamplers failed, got %x, expected %x\n", hr, D3D_OK);
ok(count == 0, "D3DXGetShaderSamplers failed, got %u, expected %u\n", count, 0);
} }
START_TEST(shader) START_TEST(shader)