mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
tests/shader_runner: Centralize the compile_hlsl() helper in shader_runner.c.
This commit is contained in:
parent
591ae5e18e
commit
b3eee0a323
Notes:
Henri Verbeet
2024-10-28 18:11:45 +01:00
Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1216
@ -1445,7 +1445,7 @@ static HRESULT d3d10_blob_from_vkd3d_shader_code(const struct vkd3d_shader_code
|
|||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT dxc_compiler_compile_shader(void *dxc_compiler, enum shader_type type,
|
static HRESULT dxc_compiler_compile_shader(void *dxc_compiler, enum shader_type type,
|
||||||
unsigned int compile_options, const char *hlsl, ID3D10Blob **blob_out)
|
unsigned int compile_options, const char *hlsl, ID3D10Blob **blob_out)
|
||||||
{
|
{
|
||||||
struct vkd3d_shader_code blob;
|
struct vkd3d_shader_code blob;
|
||||||
@ -1472,6 +1472,49 @@ HRESULT dxc_compiler_compile_shader(void *dxc_compiler, enum shader_type type,
|
|||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ID3D10Blob *compile_hlsl(const struct shader_runner *runner, enum shader_type type)
|
||||||
|
{
|
||||||
|
const char *source = runner->shader_source[type];
|
||||||
|
ID3D10Blob *blob = NULL, *errors = NULL;
|
||||||
|
char profile[7];
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
static const char *const shader_models[] =
|
||||||
|
{
|
||||||
|
[SHADER_MODEL_2_0] = "2_0",
|
||||||
|
[SHADER_MODEL_3_0] = "3_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",
|
||||||
|
[SHADER_MODEL_6_0] = "6_0",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (runner->minimum_shader_model >= SHADER_MODEL_6_0)
|
||||||
|
{
|
||||||
|
assert(runner->dxc_compiler);
|
||||||
|
hr = dxc_compiler_compile_shader(runner->dxc_compiler, type, runner->compile_options, source, &blob);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->minimum_shader_model]);
|
||||||
|
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main",
|
||||||
|
profile, runner->compile_options, 0, &blob, &errors);
|
||||||
|
}
|
||||||
|
if (hr != S_OK)
|
||||||
|
{
|
||||||
|
todo_if (runner->is_todo)
|
||||||
|
ok(false, "Failed to compile shader, hr %#x.\n", hr);
|
||||||
|
}
|
||||||
|
if (errors)
|
||||||
|
{
|
||||||
|
if (vkd3d_test_state.debug_level)
|
||||||
|
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
||||||
|
ID3D10Blob_Release(errors);
|
||||||
|
}
|
||||||
|
return blob;
|
||||||
|
}
|
||||||
|
|
||||||
static void compile_shader(struct shader_runner *runner, const char *source, size_t len,
|
static void compile_shader(struct shader_runner *runner, const char *source, size_t len,
|
||||||
enum shader_type type, HRESULT expect)
|
enum shader_type type, HRESULT expect)
|
||||||
{
|
{
|
||||||
|
@ -244,8 +244,7 @@ void fatal_error(const char *format, ...) VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2)
|
|||||||
|
|
||||||
unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot);
|
unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot);
|
||||||
void init_resource(struct resource *resource, const struct resource_params *params);
|
void init_resource(struct resource *resource, const struct resource_params *params);
|
||||||
HRESULT dxc_compiler_compile_shader(void *dxc_compiler, enum shader_type type,
|
ID3D10Blob *compile_hlsl(const struct shader_runner *runner, enum shader_type type);
|
||||||
unsigned int compile_options, const char *hlsl, ID3D10Blob **blob_out);
|
|
||||||
struct sampler *shader_runner_get_sampler(struct shader_runner *runner, unsigned int slot);
|
struct sampler *shader_runner_get_sampler(struct shader_runner *runner, unsigned int slot);
|
||||||
struct resource *shader_runner_get_resource(struct shader_runner *runner, enum resource_type type, unsigned int slot);
|
struct resource *shader_runner_get_resource(struct shader_runner *runner, enum resource_type type, unsigned int slot);
|
||||||
|
|
||||||
|
@ -75,35 +75,6 @@ static struct d3d11_shader_runner *d3d11_shader_runner(struct shader_runner *r)
|
|||||||
return CONTAINING_RECORD(r, struct d3d11_shader_runner, r);
|
return CONTAINING_RECORD(r, struct d3d11_shader_runner, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID3D10Blob *compile_shader(const struct d3d11_shader_runner *runner, enum shader_type type)
|
|
||||||
{
|
|
||||||
const char *source = runner->r.shader_source[type];
|
|
||||||
ID3D10Blob *blob = NULL, *errors = NULL;
|
|
||||||
char profile[7];
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
static const char *const shader_models[] =
|
|
||||||
{
|
|
||||||
[SHADER_MODEL_2_0] = "4_0",
|
|
||||||
[SHADER_MODEL_3_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", shader_type_string(type), shader_models[runner->r.minimum_shader_model]);
|
|
||||||
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, runner->r.compile_options, 0, &blob, &errors);
|
|
||||||
ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr);
|
|
||||||
if (errors)
|
|
||||||
{
|
|
||||||
if (vkd3d_test_state.debug_level)
|
|
||||||
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
|
||||||
ID3D10Blob_Release(errors);
|
|
||||||
}
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
static IDXGIAdapter *create_adapter(void)
|
static IDXGIAdapter *create_adapter(void)
|
||||||
{
|
{
|
||||||
IDXGIFactory4 *factory4;
|
IDXGIFactory4 *factory4;
|
||||||
@ -614,7 +585,7 @@ static bool d3d11_runner_dispatch(struct shader_runner *r, unsigned int x, unsig
|
|||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!(cs_code = compile_shader(runner, SHADER_TYPE_CS)))
|
if (!(cs_code = compile_hlsl(&runner->r, SHADER_TYPE_CS)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
hr = ID3D11Device_CreateComputeShader(device, ID3D10Blob_GetBufferPointer(cs_code),
|
hr = ID3D11Device_CreateComputeShader(device, ID3D10Blob_GetBufferPointer(cs_code),
|
||||||
@ -715,23 +686,23 @@ static bool d3d11_runner_draw(struct shader_runner *r,
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
vs_code = compile_shader(runner, SHADER_TYPE_VS);
|
vs_code = compile_hlsl(&runner->r, SHADER_TYPE_VS);
|
||||||
ps_code = compile_shader(runner, SHADER_TYPE_PS);
|
ps_code = compile_hlsl(&runner->r, SHADER_TYPE_PS);
|
||||||
succeeded = vs_code && ps_code;
|
succeeded = vs_code && ps_code;
|
||||||
|
|
||||||
if (runner->r.shader_source[SHADER_TYPE_HS])
|
if (runner->r.shader_source[SHADER_TYPE_HS])
|
||||||
{
|
{
|
||||||
hs_code = compile_shader(runner, SHADER_TYPE_HS);
|
hs_code = compile_hlsl(&runner->r, SHADER_TYPE_HS);
|
||||||
succeeded = succeeded && hs_code;
|
succeeded = succeeded && hs_code;
|
||||||
}
|
}
|
||||||
if (runner->r.shader_source[SHADER_TYPE_DS])
|
if (runner->r.shader_source[SHADER_TYPE_DS])
|
||||||
{
|
{
|
||||||
ds_code = compile_shader(runner, SHADER_TYPE_DS);
|
ds_code = compile_hlsl(&runner->r, SHADER_TYPE_DS);
|
||||||
succeeded = succeeded && ds_code;
|
succeeded = succeeded && ds_code;
|
||||||
}
|
}
|
||||||
if (runner->r.shader_source[SHADER_TYPE_GS])
|
if (runner->r.shader_source[SHADER_TYPE_GS])
|
||||||
{
|
{
|
||||||
gs_code = compile_shader(runner, SHADER_TYPE_GS);
|
gs_code = compile_hlsl(&runner->r, SHADER_TYPE_GS);
|
||||||
succeeded = succeeded && gs_code;
|
succeeded = succeeded && gs_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,45 +63,6 @@ static struct d3d12_shader_runner *d3d12_shader_runner(struct shader_runner *r)
|
|||||||
return CONTAINING_RECORD(r, struct d3d12_shader_runner, r);
|
return CONTAINING_RECORD(r, struct d3d12_shader_runner, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, enum shader_type type)
|
|
||||||
{
|
|
||||||
const char *source = runner->r.shader_source[type];
|
|
||||||
ID3D10Blob *blob = NULL, *errors = NULL;
|
|
||||||
char profile[7];
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
static const char *const shader_models[] =
|
|
||||||
{
|
|
||||||
[SHADER_MODEL_2_0] = "4_0",
|
|
||||||
[SHADER_MODEL_3_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",
|
|
||||||
[SHADER_MODEL_6_0] = "6_0",
|
|
||||||
};
|
|
||||||
|
|
||||||
if (runner->r.minimum_shader_model >= SHADER_MODEL_6_0)
|
|
||||||
{
|
|
||||||
assert(runner->r.dxc_compiler);
|
|
||||||
hr = dxc_compiler_compile_shader(runner->r.dxc_compiler, type, runner->r.compile_options, source, &blob);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->r.minimum_shader_model]);
|
|
||||||
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main",
|
|
||||||
profile, runner->r.compile_options, 0, &blob, &errors);
|
|
||||||
}
|
|
||||||
ok(FAILED(hr) == !blob, "Got unexpected hr %#x, blob %p.\n", hr, blob);
|
|
||||||
if (errors)
|
|
||||||
{
|
|
||||||
if (vkd3d_test_state.debug_level)
|
|
||||||
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
|
||||||
ID3D10Blob_Release(errors);
|
|
||||||
}
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MAX_RESOURCE_DESCRIPTORS (MAX_RESOURCES * 2)
|
#define MAX_RESOURCE_DESCRIPTORS (MAX_RESOURCES * 2)
|
||||||
|
|
||||||
static struct resource *d3d12_runner_create_resource(struct shader_runner *r, const struct resource_params *params)
|
static struct resource *d3d12_runner_create_resource(struct shader_runner *r, const struct resource_params *params)
|
||||||
@ -395,7 +356,7 @@ static bool d3d12_runner_dispatch(struct shader_runner *r, unsigned int x, unsig
|
|||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
cs_code = compile_shader(runner, SHADER_TYPE_CS);
|
cs_code = compile_hlsl(&runner->r, SHADER_TYPE_CS);
|
||||||
todo_if(runner->r.is_todo && runner->r.minimum_shader_model < SHADER_MODEL_6_0) ok(cs_code, "Failed to compile shader.\n");
|
todo_if(runner->r.is_todo && runner->r.minimum_shader_model < SHADER_MODEL_6_0) ok(cs_code, "Failed to compile shader.\n");
|
||||||
if (!cs_code)
|
if (!cs_code)
|
||||||
return false;
|
return false;
|
||||||
@ -789,23 +750,23 @@ static bool d3d12_runner_draw(struct shader_runner *r,
|
|||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
ps_code = compile_shader(runner, SHADER_TYPE_PS);
|
ps_code = compile_hlsl(&runner->r, SHADER_TYPE_PS);
|
||||||
vs_code = compile_shader(runner, SHADER_TYPE_VS);
|
vs_code = compile_hlsl(&runner->r, SHADER_TYPE_VS);
|
||||||
succeeded = ps_code && vs_code;
|
succeeded = ps_code && vs_code;
|
||||||
|
|
||||||
if (runner->r.shader_source[SHADER_TYPE_HS])
|
if (runner->r.shader_source[SHADER_TYPE_HS])
|
||||||
{
|
{
|
||||||
hs_code = compile_shader(runner, SHADER_TYPE_HS);
|
hs_code = compile_hlsl(&runner->r, SHADER_TYPE_HS);
|
||||||
succeeded = succeeded && hs_code;
|
succeeded = succeeded && hs_code;
|
||||||
}
|
}
|
||||||
if (runner->r.shader_source[SHADER_TYPE_DS])
|
if (runner->r.shader_source[SHADER_TYPE_DS])
|
||||||
{
|
{
|
||||||
ds_code = compile_shader(runner, SHADER_TYPE_DS);
|
ds_code = compile_hlsl(&runner->r, SHADER_TYPE_DS);
|
||||||
succeeded = succeeded && ds_code;
|
succeeded = succeeded && ds_code;
|
||||||
}
|
}
|
||||||
if (runner->r.shader_source[SHADER_TYPE_GS])
|
if (runner->r.shader_source[SHADER_TYPE_GS])
|
||||||
{
|
{
|
||||||
gs_code = compile_shader(runner, SHADER_TYPE_GS);
|
gs_code = compile_hlsl(&runner->r, SHADER_TYPE_GS);
|
||||||
succeeded = succeeded && gs_code;
|
succeeded = succeeded && gs_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,31 +57,6 @@ static struct d3d9_shader_runner *d3d9_shader_runner(struct shader_runner *r)
|
|||||||
|
|
||||||
static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT sdk_version);
|
static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT sdk_version);
|
||||||
|
|
||||||
static ID3D10Blob *compile_shader(const struct d3d9_shader_runner *runner, enum shader_type type)
|
|
||||||
{
|
|
||||||
const char *source = runner->r.shader_source[type];
|
|
||||||
ID3D10Blob *blob = NULL, *errors = NULL;
|
|
||||||
char profile[7];
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
static const char *const shader_models[] =
|
|
||||||
{
|
|
||||||
[SHADER_MODEL_2_0] = "2_0",
|
|
||||||
[SHADER_MODEL_3_0] = "3_0",
|
|
||||||
};
|
|
||||||
|
|
||||||
sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->r.minimum_shader_model]);
|
|
||||||
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, runner->r.compile_options, 0, &blob, &errors);
|
|
||||||
ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr);
|
|
||||||
if (errors)
|
|
||||||
{
|
|
||||||
if (vkd3d_test_state.debug_level)
|
|
||||||
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
|
||||||
ID3D10Blob_Release(errors);
|
|
||||||
}
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_adapter_info(void)
|
static void init_adapter_info(void)
|
||||||
{
|
{
|
||||||
D3DADAPTER_IDENTIFIER9 identifier;
|
D3DADAPTER_IDENTIFIER9 identifier;
|
||||||
@ -362,10 +337,10 @@ static bool d3d9_runner_draw(struct shader_runner *r,
|
|||||||
if (instance_count > 1)
|
if (instance_count > 1)
|
||||||
fatal_error("Unhandled instance count %u.\n", instance_count);
|
fatal_error("Unhandled instance count %u.\n", instance_count);
|
||||||
|
|
||||||
if (!(vs_code = compile_shader(runner, SHADER_TYPE_VS)))
|
if (!(vs_code = compile_hlsl(&runner->r, SHADER_TYPE_VS)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(ps_code = compile_shader(runner, SHADER_TYPE_PS)))
|
if (!(ps_code = compile_hlsl(&runner->r, SHADER_TYPE_PS)))
|
||||||
{
|
{
|
||||||
ID3D10Blob_Release(vs_code);
|
ID3D10Blob_Release(vs_code);
|
||||||
return false;
|
return false;
|
||||||
|
@ -533,32 +533,6 @@ static void gl_runner_destroy_resource(struct shader_runner *r, struct resource
|
|||||||
free(resource);
|
free(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID3DBlob *compile_hlsl(const struct shader_runner *runner, enum shader_type type)
|
|
||||||
{
|
|
||||||
const char *source = runner->shader_source[type];
|
|
||||||
ID3DBlob *blob = NULL, *errors = NULL;
|
|
||||||
char profile[7];
|
|
||||||
|
|
||||||
static const char *const shader_models[] =
|
|
||||||
{
|
|
||||||
[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", shader_type_string(type), shader_models[runner->minimum_shader_model]);
|
|
||||||
D3DCompile(source, strlen(source), NULL, NULL, NULL, "main",
|
|
||||||
profile, runner->compile_options, 0, &blob, &errors);
|
|
||||||
if (errors)
|
|
||||||
{
|
|
||||||
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
|
||||||
ID3D10Blob_Release(errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool compile_shader(struct gl_runner *runner, ID3DBlob *blob, struct vkd3d_shader_code *out)
|
static bool compile_shader(struct gl_runner *runner, ID3DBlob *blob, struct vkd3d_shader_code *out)
|
||||||
{
|
{
|
||||||
struct vkd3d_shader_spirv_target_info spirv_info = {.type = VKD3D_SHADER_STRUCTURE_TYPE_SPIRV_TARGET_INFO};
|
struct vkd3d_shader_spirv_target_info spirv_info = {.type = VKD3D_SHADER_STRUCTURE_TYPE_SPIRV_TARGET_INFO};
|
||||||
|
Loading…
Reference in New Issue
Block a user