[PATCH vkd3d 2/8] tests: Specify the default vertex shader in the shader runner frontend.
Zebediah Figura
zfigura at codeweavers.com
Mon Mar 21 20:42:15 CDT 2022
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
tests/shader_runner.c | 10 +++++++
tests/shader_runner_d3d11.c | 54 ++++++++++++++++---------------------
tests/shader_runner_d3d12.c | 16 +++++------
3 files changed, 39 insertions(+), 41 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c
index 033fee0a6..a2aecf9f9 100644
--- a/tests/shader_runner.c
+++ b/tests/shader_runner.c
@@ -290,6 +290,16 @@ static void parse_test_directive(struct shader_runner *runner, const char *line)
{
if (match_string(line, "draw quad", &line))
{
+ static const char vs_source[] =
+ "void main(uint id : SV_VertexID, out float4 position : SV_Position)\n"
+ "{\n"
+ " float2 coords = float2((id << 1) & 2, id & 2);\n"
+ " position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);\n"
+ "}";
+
+ if (!runner->vs_source)
+ runner->vs_source = strdup(vs_source);
+
runner->ops->draw_quad(runner);
}
else if (match_string(line, "probe all rgba", &line))
diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c
index fb73f80e9..f40494446 100644
--- a/tests/shader_runner_d3d11.c
+++ b/tests/shader_runner_d3d11.c
@@ -61,8 +61,6 @@ struct d3d11_shader_runner
ID3D11Texture2D *rt;
ID3D11RenderTargetView *rtv;
ID3D11DeviceContext *immediate_context;
-
- ID3D11VertexShader *vs;
};
static struct d3d11_shader_runner *d3d11_shader_runner(struct shader_runner *r)
@@ -74,11 +72,22 @@ static bool enable_debug_layer;
static bool use_warp_adapter;
static unsigned int use_adapter_idx;
-static ID3D10Blob *compile_shader(const char *source, const char *profile)
+static ID3D10Blob *compile_shader(const char *source, const char *type, enum shader_model shader_model)
{
ID3D10Blob *blob = NULL, *errors = NULL;
+ char profile[7];
HRESULT hr;
+ static const char *const shader_models[] =
+ {
+ [SHADER_MODEL_2_0] = "4_0",
+ [SHADER_MODEL_4_0] = "4_0",
+ [SHADER_MODEL_4_1] = "4_1",
+ [SHADER_MODEL_5_0] = "5_0",
+ [SHADER_MODEL_5_1] = "5_1",
+ };
+
+ sprintf(profile, "%s_%s", type, shader_models[shader_model]);
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, 0, 0, &blob, &errors);
ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr);
if (errors)
@@ -323,9 +332,6 @@ static void destroy_test_context(struct d3d11_shader_runner *runner)
{
ULONG ref;
- if (runner->vs)
- ID3D11VertexShader_Release(runner->vs);
-
ID3D11DeviceContext_Release(runner->immediate_context);
ID3D11RenderTargetView_Release(runner->rtv);
ID3D11Texture2D_Release(runner->rt);
@@ -405,43 +411,28 @@ static void d3d11_runner_destroy_texture(struct shader_runner *r, struct texture
static void d3d11_runner_draw_quad(struct shader_runner *r)
{
- static const char vs_source[] =
- "void main(uint id : SV_VertexID, out float4 position : SV_Position)\n"
- "{\n"
- " float2 coords = float2((id << 1) & 2, id & 2);\n"
- " position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);\n"
- "}";
-
struct d3d11_shader_runner *runner = d3d11_shader_runner(r);
ID3D11Device *device = runner->device;
+ ID3D10Blob *vs_code, *ps_code;
ID3D11Buffer *cb = NULL;
+ ID3D11VertexShader *vs;
ID3D11PixelShader *ps;
- ID3D10Blob *ps_code;
unsigned int i;
HRESULT hr;
- static const char *const ps_profiles[] =
- {
- [SHADER_MODEL_2_0] = "ps_4_0",
- [SHADER_MODEL_4_0] = "ps_4_0",
- [SHADER_MODEL_4_1] = "ps_4_1",
- [SHADER_MODEL_5_0] = "ps_5_0",
- [SHADER_MODEL_5_1] = "ps_5_1",
- };
-
- if (!(ps_code = compile_shader(runner->r.ps_source, ps_profiles[runner->r.minimum_shader_model])))
+ if (!(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model)))
return;
- if (!runner->vs)
+ if (!(ps_code = compile_shader(runner->r.ps_source, "ps", runner->r.minimum_shader_model)))
{
- ID3D10Blob *vs_code = compile_shader(runner->r.vs_source ? runner->r.vs_source : vs_source, "vs_4_0");
-
- hr = ID3D11Device_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code),
- ID3D10Blob_GetBufferSize(vs_code), NULL, &runner->vs);
- ok(hr == S_OK, "Failed to create vertex shader, hr %#lx.\n", hr);
ID3D10Blob_Release(vs_code);
+ return;
}
+ hr = ID3D11Device_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code),
+ ID3D10Blob_GetBufferSize(vs_code), NULL, &vs);
+ ok(hr == S_OK, "Failed to create vertex shader, hr %#lx.\n", hr);
+
hr = ID3D11Device_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(ps_code),
ID3D10Blob_GetBufferSize(ps_code), NULL, &ps);
ok(hr == S_OK, "Failed to create pixel shader, hr %#lx.\n", hr);
@@ -482,12 +473,13 @@ static void d3d11_runner_draw_quad(struct shader_runner *r)
}
ID3D11DeviceContext_IASetPrimitiveTopology(runner->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- ID3D11DeviceContext_VSSetShader(runner->immediate_context, runner->vs, NULL, 0);
+ ID3D11DeviceContext_VSSetShader(runner->immediate_context, vs, NULL, 0);
ID3D11DeviceContext_PSSetShader(runner->immediate_context, ps, NULL, 0);
ID3D11DeviceContext_Draw(runner->immediate_context, 3, 0);
ID3D11PixelShader_Release(ps);
+ ID3D11VertexShader_Release(vs);
if (cb)
ID3D11Buffer_Release(cb);
}
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c
index e124922fa..befa7f2f5 100644
--- a/tests/shader_runner_d3d12.c
+++ b/tests/shader_runner_d3d12.c
@@ -133,8 +133,8 @@ static void d3d12_runner_draw_quad(struct shader_runner *r)
ID3D12CommandQueue *queue = test_context->queue;
D3D12_STATIC_SAMPLER_DESC static_samplers[1];
ID3D12Device *device = test_context->device;
- ID3D10Blob *vs_code = NULL, *ps_code;
static const float clear_color[4];
+ ID3D10Blob *vs_code, *ps_code;
D3D12_SHADER_BYTECODE vs, ps;
unsigned int uniform_index;
ID3D12PipelineState *pso;
@@ -144,7 +144,7 @@ static void d3d12_runner_draw_quad(struct shader_runner *r)
if (!(ps_code = compile_shader(runner->r.ps_source, "ps", runner->r.minimum_shader_model)))
return;
- if (runner->r.vs_source && !(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model)))
+ if (!(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model)))
{
ID3D10Blob_Release(ps_code);
return;
@@ -209,17 +209,13 @@ static void d3d12_runner_draw_quad(struct shader_runner *r)
hr = create_root_signature(device, &root_signature_desc, &test_context->root_signature);
ok(hr == S_OK, "Failed to create root signature, hr %#x.\n", hr);
- if (vs_code)
- {
- vs.pShaderBytecode = ID3D10Blob_GetBufferPointer(vs_code);
- vs.BytecodeLength = ID3D10Blob_GetBufferSize(vs_code);
- }
+ vs.pShaderBytecode = ID3D10Blob_GetBufferPointer(vs_code);
+ vs.BytecodeLength = ID3D10Blob_GetBufferSize(vs_code);
ps.pShaderBytecode = ID3D10Blob_GetBufferPointer(ps_code);
ps.BytecodeLength = ID3D10Blob_GetBufferSize(ps_code);
pso = create_pipeline_state(device, test_context->root_signature,
- test_context->render_target_desc.Format, vs_code ? &vs : NULL, &ps, NULL);
- if (vs_code)
- ID3D10Blob_Release(vs_code);
+ test_context->render_target_desc.Format, &vs, &ps, NULL);
+ ID3D10Blob_Release(vs_code);
ID3D10Blob_Release(ps_code);
if (!pso)
return;
--
2.35.1
More information about the wine-devel
mailing list