d3dcompiler/tests: Add tests for semantics.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
37d8d163e3
commit
3e89cbc5af
|
@ -42,13 +42,14 @@ struct vec4
|
|||
float x, y, z, w;
|
||||
};
|
||||
|
||||
#define compile_shader(a, b) compile_shader_(__LINE__, a, b)
|
||||
static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const char *target)
|
||||
#define compile_shader(a, b) compile_shader_(__LINE__, a, b, 0)
|
||||
#define compile_shader_flags(a, b, c) compile_shader_(__LINE__, a, b, c)
|
||||
static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const char *target, UINT flags)
|
||||
{
|
||||
ID3D10Blob *blob = NULL, *errors = NULL;
|
||||
HRESULT hr;
|
||||
|
||||
hr = ppD3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors);
|
||||
hr = ppD3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, flags, 0, &blob, &errors);
|
||||
ok_(__FILE__, line)(hr == S_OK, "Failed to compile shader, hr %#x.\n", hr);
|
||||
if (errors)
|
||||
{
|
||||
|
@ -287,7 +288,7 @@ static void draw_quad_(unsigned int line, struct test_context *context, ID3D10Bl
|
|||
|
||||
if (!context->vs)
|
||||
{
|
||||
ID3D10Blob *vs_code = compile_shader_(line, vs_source, "vs_4_0");
|
||||
ID3D10Blob *vs_code = compile_shader_(line, vs_source, "vs_4_0", 0);
|
||||
|
||||
hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
|
||||
ID3D10Blob_GetBufferPointer(vs_code), ID3D10Blob_GetBufferSize(vs_code), &context->input_layout);
|
||||
|
@ -734,6 +735,238 @@ static void test_reflection(void)
|
|||
ok(!refcount, "Got unexpected refcount %u.\n", refcount);
|
||||
}
|
||||
|
||||
static void check_parameter_desc(const char *prefix, const D3D11_SIGNATURE_PARAMETER_DESC *desc,
|
||||
const D3D11_SIGNATURE_PARAMETER_DESC *expect)
|
||||
{
|
||||
ok(!strcmp(desc->SemanticName, expect->SemanticName), "%s: got name %s.\n", prefix, debugstr_a(desc->SemanticName));
|
||||
ok(desc->SemanticIndex == expect->SemanticIndex, "%s: got index %u.\n", prefix, desc->SemanticIndex);
|
||||
ok(desc->Register == expect->Register, "%s: got register %u.\n", prefix, desc->Register);
|
||||
ok(desc->SystemValueType == expect->SystemValueType, "%s: got sysval %u.\n", prefix, desc->SystemValueType);
|
||||
ok(desc->ComponentType == expect->ComponentType, "%s: got data type %u.\n", prefix, desc->ComponentType);
|
||||
ok(desc->Mask == expect->Mask, "%s: got mask %#x.\n", prefix, desc->Mask);
|
||||
todo_wine_if(desc->ReadWriteMask != expect->ReadWriteMask)
|
||||
ok(desc->ReadWriteMask == expect->ReadWriteMask, "%s: got used mask %#x.\n", prefix, desc->ReadWriteMask);
|
||||
ok(desc->Stream == expect->Stream, "%s: got stream %u.\n", prefix, desc->Stream);
|
||||
}
|
||||
|
||||
static void test_semantic_reflection(void)
|
||||
{
|
||||
D3D11_SIGNATURE_PARAMETER_DESC desc;
|
||||
ID3D11ShaderReflection *reflection;
|
||||
D3D11_SHADER_DESC shader_desc;
|
||||
ID3D10Blob *code = NULL;
|
||||
unsigned int i, j;
|
||||
char prefix[40];
|
||||
ULONG refcount;
|
||||
HRESULT hr;
|
||||
|
||||
static const char vs1_source[] =
|
||||
"void main(\n"
|
||||
" in float4 a : apple,\n"
|
||||
" out float4 b : banana2,\n"
|
||||
" inout float4 c : color,\n"
|
||||
" inout float4 d : depth,\n"
|
||||
" inout float4 e : sv_position,\n"
|
||||
" in uint3 f : fruit,\n"
|
||||
" inout bool2 g : grape,\n"
|
||||
" in int h : honeydew)\n"
|
||||
"{\n"
|
||||
" b.yw = a.xz;\n"
|
||||
"}";
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC vs1_inputs[] =
|
||||
{
|
||||
{"apple", 0, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0x5},
|
||||
{"color", 0, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
{"depth", 0, 2, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
{"sv_position", 0, 3, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
{"fruit", 0, 4, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_UINT32, 0x7},
|
||||
{"grape", 0, 5, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_UINT32, 0x3, 0x3},
|
||||
{"honeydew", 0, 6, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_SINT32, 0x1},
|
||||
};
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC vs1_outputs[] =
|
||||
{
|
||||
{"banana", 2, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0x5},
|
||||
{"color", 0, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
{"depth", 0, 2, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
{"sv_position", 0, 3, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
{"grape", 0, 4, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_UINT32, 0x3, 0xc},
|
||||
};
|
||||
|
||||
static const char vs2_source[] =
|
||||
"void main(inout float4 pos : position)\n"
|
||||
"{\n"
|
||||
"}";
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC vs2_inputs[] =
|
||||
{
|
||||
{"position", 0, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
};
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC vs2_outputs[] =
|
||||
{
|
||||
{"position", 0, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
};
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC vs2_legacy_outputs[] =
|
||||
{
|
||||
{"SV_Position", 0, 0, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
};
|
||||
|
||||
static const char ps1_source[] =
|
||||
"void main(\n"
|
||||
" in float2 a : apple,\n"
|
||||
" out float4 b : sv_target2,\n"
|
||||
" out float c : sv_depth,\n"
|
||||
" in float4 d : position,\n"
|
||||
" in float4 e : sv_position)\n"
|
||||
"{\n"
|
||||
" b = d;\n"
|
||||
" c = 0;\n"
|
||||
"}";
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC ps1_inputs[] =
|
||||
{
|
||||
{"apple", 0, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0x3},
|
||||
{"position", 0, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
{"sv_position", 0, 2, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
};
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC ps1_outputs[] =
|
||||
{
|
||||
{"sv_target", 2, 2, D3D_NAME_TARGET, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
{"sv_depth", 0, ~0u, D3D_NAME_DEPTH, D3D_REGISTER_COMPONENT_FLOAT32, 0x1, 0xe},
|
||||
};
|
||||
|
||||
static const char ps2_source[] =
|
||||
"void main(\n"
|
||||
" inout float4 a : color2,\n"
|
||||
" inout float b : depth,\n"
|
||||
" in float4 c : position)\n"
|
||||
"{\n"
|
||||
"}";
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC ps2_inputs[] =
|
||||
{
|
||||
{"color", 2, 0, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
{"depth", 0, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0x1, 0x1},
|
||||
{"SV_Position", 0, 2, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
};
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC ps2_outputs[] =
|
||||
{
|
||||
{"SV_Target", 2, 2, D3D_NAME_TARGET, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
{"SV_Depth", 0, ~0u, D3D_NAME_DEPTH, D3D_REGISTER_COMPONENT_FLOAT32, 0x1, 0xe},
|
||||
};
|
||||
|
||||
static const char cs1_source[] =
|
||||
"[numthreads(1, 1, 1)]\n"
|
||||
"void main(in uint a : sv_dispatchthreadid)\n"
|
||||
"{\n"
|
||||
"}";
|
||||
|
||||
static const char gs1_source[] =
|
||||
"struct input\n"
|
||||
"{\n"
|
||||
" float4 a : sv_position;\n"
|
||||
" float4 b : apple2;\n"
|
||||
"};\n"
|
||||
"struct vertex\n"
|
||||
"{\n"
|
||||
" float4 a : sv_position;\n"
|
||||
" float4 b : apple2;\n"
|
||||
" uint c : sv_primitiveid;\n"
|
||||
"};\n"
|
||||
"[maxvertexcount(1)]\n"
|
||||
"void main(\n"
|
||||
" point input i[1],\n"
|
||||
" inout PointStream<vertex> o,\n"
|
||||
" uint a : sv_primitiveid)\n"
|
||||
"{\n"
|
||||
" struct vertex v;\n"
|
||||
" v.a = i[0].a;\n"
|
||||
" v.b = i[0].b;\n"
|
||||
" v.c = a;\n"
|
||||
" o.Append(v);\n"
|
||||
"}";
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC gs1_inputs[] =
|
||||
{
|
||||
{"sv_position", 0, 0, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
{"apple", 2, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf, 0xf},
|
||||
{"sv_primitiveid", 0, ~0u, D3D_NAME_PRIMITIVE_ID, D3D_REGISTER_COMPONENT_UINT32, 0x1, 0x1},
|
||||
};
|
||||
|
||||
static const D3D11_SIGNATURE_PARAMETER_DESC gs1_outputs[] =
|
||||
{
|
||||
{"sv_position", 0, 0, D3D_NAME_POSITION, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
{"apple", 2, 1, D3D_NAME_UNDEFINED, D3D_REGISTER_COMPONENT_FLOAT32, 0xf},
|
||||
{"sv_primitiveid", 0, 2, D3D_NAME_PRIMITIVE_ID, D3D_REGISTER_COMPONENT_UINT32, 0x1, 0xe},
|
||||
};
|
||||
|
||||
static const struct
|
||||
{
|
||||
const char *source;
|
||||
const char *target;
|
||||
BOOL legacy;
|
||||
const D3D11_SIGNATURE_PARAMETER_DESC *inputs;
|
||||
unsigned int input_count;
|
||||
const D3D11_SIGNATURE_PARAMETER_DESC *outputs;
|
||||
unsigned int output_count;
|
||||
}
|
||||
tests[] =
|
||||
{
|
||||
{vs1_source, "vs_4_0", FALSE, vs1_inputs, ARRAY_SIZE(vs1_inputs), vs1_outputs, ARRAY_SIZE(vs1_outputs)},
|
||||
{vs1_source, "vs_4_0", TRUE, vs1_inputs, ARRAY_SIZE(vs1_inputs), vs1_outputs, ARRAY_SIZE(vs1_outputs)},
|
||||
{vs2_source, "vs_4_0", FALSE, vs2_inputs, ARRAY_SIZE(vs2_inputs), vs2_outputs, ARRAY_SIZE(vs2_outputs)},
|
||||
{vs2_source, "vs_4_0", TRUE, vs2_inputs, ARRAY_SIZE(vs2_inputs), vs2_legacy_outputs, ARRAY_SIZE(vs2_legacy_outputs)},
|
||||
{ps1_source, "ps_4_0", FALSE, ps1_inputs, ARRAY_SIZE(ps1_inputs), ps1_outputs, ARRAY_SIZE(ps1_outputs)},
|
||||
{ps2_source, "ps_4_0", TRUE, ps2_inputs, ARRAY_SIZE(ps2_inputs), ps2_outputs, ARRAY_SIZE(ps2_outputs)},
|
||||
{cs1_source, "cs_4_0", FALSE, NULL, 0, NULL, 0},
|
||||
{gs1_source, "gs_4_0", FALSE, gs1_inputs, ARRAY_SIZE(gs1_inputs), gs1_outputs, ARRAY_SIZE(gs1_outputs)},
|
||||
};
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(tests); ++i)
|
||||
{
|
||||
todo_wine code = compile_shader_flags(tests[i].source, tests[i].target,
|
||||
tests[i].legacy ? D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY : 0);
|
||||
if (!code)
|
||||
continue;
|
||||
|
||||
hr = pD3DReflect(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code),
|
||||
&IID_ID3D11ShaderReflection, (void **)&reflection);
|
||||
ok(hr == S_OK, "Test %u: got hr %#x.\n", i, hr);
|
||||
|
||||
hr = reflection->lpVtbl->GetDesc(reflection, &shader_desc);
|
||||
ok(hr == S_OK, "Test %u: got hr %#x.\n", i, hr);
|
||||
todo_wine ok(shader_desc.InputParameters == tests[i].input_count,
|
||||
"Test %u: got %u input parameters.\n", i, shader_desc.InputParameters);
|
||||
todo_wine ok(shader_desc.OutputParameters == tests[i].output_count,
|
||||
"Test %u: got %u output parameters.\n", i, shader_desc.OutputParameters);
|
||||
|
||||
for (j = 0; j < shader_desc.InputParameters; ++j)
|
||||
{
|
||||
hr = reflection->lpVtbl->GetInputParameterDesc(reflection, j, &desc);
|
||||
ok(hr == S_OK, "Test %u, %u: got hr %#x.\n", i, j, hr);
|
||||
sprintf(prefix, "Test %u, input %u", i, j);
|
||||
check_parameter_desc(prefix, &desc, &tests[i].inputs[j]);
|
||||
}
|
||||
|
||||
for (j = 0; j < shader_desc.OutputParameters; ++j)
|
||||
{
|
||||
hr = reflection->lpVtbl->GetOutputParameterDesc(reflection, j, &desc);
|
||||
ok(hr == S_OK, "Test %u, %u: got hr %#x.\n", i, j, hr);
|
||||
sprintf(prefix, "Test %u, output %u", i, j);
|
||||
check_parameter_desc(prefix, &desc, &tests[i].outputs[j]);
|
||||
}
|
||||
|
||||
ID3D10Blob_Release(code);
|
||||
refcount = reflection->lpVtbl->Release(reflection);
|
||||
ok(!refcount, "Got unexpected refcount %u.\n", refcount);
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL load_d3dcompiler(void)
|
||||
{
|
||||
HMODULE module;
|
||||
|
@ -760,6 +993,7 @@ START_TEST(hlsl_d3d11)
|
|||
}
|
||||
|
||||
test_reflection();
|
||||
test_semantic_reflection();
|
||||
|
||||
if (!(mod = LoadLibraryA("d3d11.dll")))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue