tests: Test I/O index ranges not intersecting a signature element for a given register.

Since this test depend on the specific code generated by the
native d3dcompiler we add the possibility to specify a "raw"
shader using a hex format. When the shader assembler is finally
available they should be replaced with assembly code.
This commit is contained in:
Giovanni Mascellani
2025-01-13 22:34:23 +01:00
committed by Henri Verbeet
parent 84a59fe4c0
commit 8887501042
Notes: Henri Verbeet 2025-02-19 18:01:43 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Francisco Casas (@fcasas)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1332
5 changed files with 297 additions and 16 deletions

View File

@@ -1643,13 +1643,58 @@ static HRESULT dxc_compiler_compile_shader(void *dxc_compiler, const char *profi
return hr;
}
static ID3D10Blob *parse_hex(const char *source)
{
size_t len = strlen(source), i, pos = 0;
unsigned char *ptr, value = 0;
bool even = false;
ID3D10Blob *blob;
ptr = malloc(len / 2);
for (i = 0; i < len; ++i)
{
char c = source[i];
if (isspace(c))
continue;
if ('0' <= c && c <= '9')
value = 16 * value + (c - '0');
else if ('a' <= c && c <= 'f')
value = 16 * value + (c - 'a' + 10);
else if ('A' <= c && c <= 'F')
value = 16 * value + (c - 'A' + 10);
else
fatal_error("Invalid hex character '%c'\n", c);
if (even)
{
ptr[pos++] = value;
value = 0;
}
even = !even;
}
if (even)
fatal_error("Odd number of hex characters.\n");
D3DCreateBlob(pos, &blob);
if (pos)
memcpy(ID3D10Blob_GetBufferPointer(blob), ptr, pos);
free(ptr);
return blob;
}
ID3D10Blob *compile_hlsl(const struct shader_runner *runner, enum shader_type type)
{
const char *source = runner->shader_source[type];
unsigned int options = runner->compile_options;
ID3D10Blob *blob = NULL, *errors = NULL;
HRESULT hr = S_OK;
char profile[7];
HRESULT hr;
static const char *const shader_models[] =
{
@@ -1672,16 +1717,45 @@ ID3D10Blob *compile_hlsl(const struct shader_runner *runner, enum shader_type ty
sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->minimum_shader_model]);
if (runner->minimum_shader_model >= SHADER_MODEL_6_0)
switch (runner->shader_format[type])
{
assert(runner->dxc_compiler);
hr = dxc_compiler_compile_shader(runner->dxc_compiler, profile, options,
runner->require_shader_caps[SHADER_CAP_NATIVE_16_BIT], source, &blob);
}
else
{
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, options, 0, &blob, &errors);
case SOURCE_FORMAT_HLSL:
if (runner->minimum_shader_model >= SHADER_MODEL_6_0)
{
assert(runner->dxc_compiler);
hr = dxc_compiler_compile_shader(runner->dxc_compiler, profile, options,
runner->require_shader_caps[SHADER_CAP_NATIVE_16_BIT], source, &blob);
}
else
{
hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, options, 0, &blob, &errors);
}
break;
case SOURCE_FORMAT_D3DBC_HEX:
if (runner->maximum_shader_model >= SHADER_MODEL_4_0)
fatal_error("Cannot use d3dbc-hex with maximum shader model %#x.\n", runner->maximum_shader_model);
blob = parse_hex(source);
hr = S_OK;
break;
case SOURCE_FORMAT_DXBC_TPF_HEX:
if (runner->minimum_shader_model < SHADER_MODEL_4_0)
fatal_error("Cannot use dxbc-tpf-hex with minimum shader model %#x.\n", runner->minimum_shader_model);
if (runner->maximum_shader_model >= SHADER_MODEL_6_0)
fatal_error("Cannot use dxbc-tpf-hex with maximum shader model %#x.\n", runner->maximum_shader_model);
blob = parse_hex(source);
hr = S_OK;
break;
case SOURCE_FORMAT_DXBC_DXIL_HEX:
if (runner->minimum_shader_model < SHADER_MODEL_6_0)
fatal_error("Cannot use dxbc-dxil-hex with minimum shader model %#x.\n", runner->minimum_shader_model);
blob = parse_hex(source);
hr = S_OK;
break;
}
if (hr != S_OK)
{
todo_if (runner->is_todo)
@@ -1725,6 +1799,17 @@ static void compile_shader(struct shader_runner *runner, const char *source,
[SHADER_MODEL_5_0] = "5_0",
};
switch (runner->shader_format[type])
{
case SOURCE_FORMAT_HLSL:
break;
case SOURCE_FORMAT_D3DBC_HEX:
case SOURCE_FORMAT_DXBC_TPF_HEX:
case SOURCE_FORMAT_DXBC_DXIL_HEX:
return;
}
/* We can let this go through D3DCompile() with the invalid shader model
* string, but it returns a unique error code. Just skip it. */
if (model < SHADER_MODEL_4_0 && type != SHADER_TYPE_VS && type != SHADER_TYPE_PS && type != SHADER_TYPE_FX)
@@ -1775,7 +1860,8 @@ static void compile_shader(struct shader_runner *runner, const char *source,
}
}
static void read_shader_directive(struct shader_runner *runner, const char *line, const char *src)
static void read_shader_directive(struct shader_runner *runner, const char *line,
const char *src, enum shader_type shader_type)
{
for (unsigned int i = SHADER_MODEL_MIN; i <= SHADER_MODEL_MAX; ++i)
{
@@ -1783,6 +1869,8 @@ static void read_shader_directive(struct shader_runner *runner, const char *line
runner->hlsl_todo[i] = false;
}
runner->shader_format[shader_type] = SOURCE_FORMAT_HLSL;
while (*src && *src != ']')
{
uint32_t model_mask;
@@ -1815,6 +1903,18 @@ static void read_shader_directive(struct shader_runner *runner, const char *line
runner->hlsl_hrs[i] = E_NOTIMPL;
}
}
else if (match_string(src, "d3dbc-hex", &src))
{
runner->shader_format[shader_type] = SOURCE_FORMAT_D3DBC_HEX;
}
else if (match_string(src, "dxbc-tpf-hex", &src))
{
runner->shader_format[shader_type] = SOURCE_FORMAT_DXBC_TPF_HEX;
}
else if (match_string(src, "dxbc-dxil-hex", &src))
{
runner->shader_format[shader_type] = SOURCE_FORMAT_DXBC_DXIL_HEX;
}
else
{
fatal_error("Malformed line '%s'.\n", line);
@@ -2340,7 +2440,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_c
}
if (state == STATE_SHADER)
read_shader_directive(runner, line_buffer, line);
read_shader_directive(runner, line_buffer, line, shader_type);
}
else if (line[0] != '%' && line[0] != '\n')
{