2020-09-30 19:01:18 -07:00
|
|
|
/*
|
2022-01-26 17:40:27 -08:00
|
|
|
* Copyright 2020-2021 Zebediah Figura for CodeWeavers
|
2020-09-30 19:01:18 -07:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This application contains code derived from piglit, the license for which
|
|
|
|
* follows:
|
|
|
|
*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2022-01-26 17:40:28 -08:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
# define _HRESULT_DEFINED
|
|
|
|
typedef int HRESULT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define CONST_VTABLE
|
|
|
|
#include "config.h"
|
|
|
|
#include <ctype.h>
|
2020-09-30 19:01:18 -07:00
|
|
|
#include <errno.h>
|
2022-01-26 17:40:28 -08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2022-03-21 18:42:16 -07:00
|
|
|
#include <string.h>
|
2022-01-26 17:40:28 -08:00
|
|
|
#include "vkd3d_windows.h"
|
|
|
|
#include "vkd3d_d3dcommon.h"
|
|
|
|
#include "vkd3d_d3dcompiler.h"
|
|
|
|
#include "vkd3d_test.h"
|
|
|
|
#include "shader_runner.h"
|
2023-09-14 02:29:24 -07:00
|
|
|
#include "dxcompiler.h"
|
2020-09-30 19:01:18 -07:00
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
struct test_options test_options = {0};
|
|
|
|
|
2024-02-19 08:01:00 -08:00
|
|
|
#ifdef VKD3D_CROSSTEST
|
|
|
|
static const char HLSL_COMPILER[] = "d3dcompiler47.dll";
|
|
|
|
#else
|
|
|
|
static const char HLSL_COMPILER[] = "vkd3d-shader";
|
|
|
|
#endif
|
|
|
|
static const char *const model_strings[] =
|
|
|
|
{
|
|
|
|
[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",
|
|
|
|
};
|
|
|
|
|
2022-03-12 13:02:15 -08:00
|
|
|
void fatal_error(const char *format, ...)
|
2021-11-05 11:35:50 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:01:18 -07:00
|
|
|
enum parse_state
|
|
|
|
{
|
|
|
|
STATE_NONE,
|
2022-03-21 18:42:16 -07:00
|
|
|
STATE_INPUT_LAYOUT,
|
2020-11-21 15:23:45 -08:00
|
|
|
STATE_PREPROC,
|
2020-11-23 22:29:57 -08:00
|
|
|
STATE_PREPROC_INVALID,
|
2022-01-26 06:35:33 -08:00
|
|
|
STATE_REQUIRE,
|
2022-06-08 16:18:35 -07:00
|
|
|
STATE_RESOURCE,
|
2021-11-05 11:35:49 -07:00
|
|
|
STATE_SAMPLER,
|
2021-08-13 14:37:31 -07:00
|
|
|
STATE_SHADER_COMPUTE,
|
2022-10-30 15:21:12 -07:00
|
|
|
STATE_SHADER_COMPUTE_TODO,
|
2020-09-30 19:01:18 -07:00
|
|
|
STATE_SHADER_PIXEL,
|
2022-10-30 15:21:12 -07:00
|
|
|
STATE_SHADER_PIXEL_TODO,
|
2022-03-21 18:42:14 -07:00
|
|
|
STATE_SHADER_VERTEX,
|
2023-04-04 16:23:26 -07:00
|
|
|
STATE_SHADER_VERTEX_TODO,
|
2023-10-12 03:51:19 -07:00
|
|
|
STATE_SHADER_EFFECT,
|
|
|
|
STATE_SHADER_EFFECT_TODO,
|
2020-09-30 19:01:18 -07:00
|
|
|
STATE_TEST,
|
|
|
|
};
|
|
|
|
|
2023-11-10 13:37:40 -08:00
|
|
|
static bool check_qualifier_args_conjunction(const char *line,
|
|
|
|
const char **const rest, enum shader_model sm)
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
2023-11-10 13:37:40 -08:00
|
|
|
bool holds = true;
|
|
|
|
unsigned int i;
|
2020-09-30 19:01:18 -07:00
|
|
|
|
2023-11-10 13:37:40 -08:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
enum shader_model sm_min, sm_max;
|
|
|
|
}
|
|
|
|
valid_args[] =
|
|
|
|
{
|
|
|
|
{"sm>=4", SHADER_MODEL_4_0, SHADER_MODEL_6_0},
|
|
|
|
{"sm>=6", SHADER_MODEL_6_0, SHADER_MODEL_6_0},
|
|
|
|
{"sm<4", SHADER_MODEL_2_0, SHADER_MODEL_4_0 - 1},
|
|
|
|
{"sm<6", SHADER_MODEL_2_0, SHADER_MODEL_6_0 - 1},
|
|
|
|
};
|
2022-03-21 18:42:16 -07:00
|
|
|
|
2023-11-10 13:37:40 -08:00
|
|
|
while (*line != ')' && *line != '|')
|
|
|
|
{
|
|
|
|
bool match = false;
|
|
|
|
|
|
|
|
while (isspace(*line))
|
|
|
|
++line;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(valid_args); ++i)
|
|
|
|
{
|
|
|
|
const char *option_text = valid_args[i].text;
|
|
|
|
|
|
|
|
if (!strncmp(line, option_text, strlen(option_text)))
|
|
|
|
{
|
|
|
|
line += strlen(option_text);
|
|
|
|
if (sm < valid_args[i].sm_min)
|
|
|
|
holds = false;
|
|
|
|
if (sm > valid_args[i].sm_max)
|
|
|
|
holds = false;
|
|
|
|
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (isspace(*line))
|
|
|
|
++line;
|
|
|
|
|
|
|
|
if (match && *line == '&')
|
|
|
|
{
|
|
|
|
++line;
|
|
|
|
}
|
|
|
|
else if (*line != ')' && *line != '|')
|
|
|
|
{
|
|
|
|
fatal_error("Invalid qualifier argument '%s'.\n", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(*line == ')' || *line == '|');
|
2020-09-30 19:01:18 -07:00
|
|
|
if (rest)
|
2023-11-10 13:37:40 -08:00
|
|
|
*rest = line;
|
|
|
|
|
|
|
|
return holds;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_qualifier_args(const char *line, const char **const rest, enum shader_model sm)
|
|
|
|
{
|
|
|
|
bool first = true;
|
|
|
|
bool holds = false;
|
|
|
|
|
|
|
|
assert(*line == '(');
|
|
|
|
++line;
|
|
|
|
|
|
|
|
while (*line != ')')
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
2023-11-10 13:37:40 -08:00
|
|
|
if (!first && *line == '|')
|
|
|
|
++line;
|
|
|
|
first = false;
|
|
|
|
|
|
|
|
holds = check_qualifier_args_conjunction(line, &line, sm) || holds;
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
2023-11-10 13:37:40 -08:00
|
|
|
|
|
|
|
assert(*line == ')');
|
|
|
|
if (rest)
|
|
|
|
*rest = line + 1;
|
|
|
|
|
|
|
|
return holds;
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
|
|
|
|
2023-11-10 13:37:40 -08:00
|
|
|
static bool match_string_generic(const char *line, const char *token, const char **const rest,
|
|
|
|
bool exclude_bracket, bool allow_qualifier_args, enum shader_model sm)
|
2023-09-14 02:18:58 -07:00
|
|
|
{
|
|
|
|
size_t len = strlen(token);
|
2023-11-10 13:37:40 -08:00
|
|
|
bool holds = true;
|
2023-09-14 02:18:58 -07:00
|
|
|
|
2023-11-10 13:37:40 -08:00
|
|
|
while (isspace(*line) || (exclude_bracket && *line == ']'))
|
2023-09-14 02:18:58 -07:00
|
|
|
++line;
|
|
|
|
|
2023-11-10 13:37:40 -08:00
|
|
|
if (strncmp(line, token, len) || !(isspace(line[len]) || line[len] == '('
|
|
|
|
|| (exclude_bracket && line[len] == ']')))
|
2023-09-14 02:18:58 -07:00
|
|
|
return false;
|
2023-11-10 13:37:40 -08:00
|
|
|
line += len;
|
|
|
|
|
|
|
|
if (allow_qualifier_args && *line == '(')
|
|
|
|
holds = check_qualifier_args(line, &line, sm);
|
|
|
|
|
2023-09-14 02:18:58 -07:00
|
|
|
if (rest)
|
|
|
|
{
|
2023-11-10 13:37:40 -08:00
|
|
|
*rest = line;
|
2023-09-14 02:18:58 -07:00
|
|
|
while (isspace(**rest))
|
|
|
|
++*rest;
|
|
|
|
}
|
2023-11-10 13:37:40 -08:00
|
|
|
return holds;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool match_string_with_args(const char *line, const char *token, const char **const rest,
|
|
|
|
enum shader_model sm)
|
|
|
|
{
|
|
|
|
return match_string_generic(line, token, rest, false, true, sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool match_string(const char *line, const char *token, const char **const rest)
|
|
|
|
{
|
|
|
|
return match_string_generic(line, token, rest, false, false, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool match_directive_substring_with_args(const char *line, const char *token,
|
|
|
|
const char **const rest, enum shader_model sm)
|
|
|
|
{
|
|
|
|
return match_string_generic(line, token, rest, true, true, sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool match_directive_substring(const char *line, const char *token, const char **const rest)
|
|
|
|
{
|
|
|
|
return match_string_generic(line, token, rest, true, false, 0);
|
2023-09-14 02:18:58 -07:00
|
|
|
}
|
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
static const char *close_parentheses(const char *line)
|
|
|
|
{
|
|
|
|
while (isspace(*line))
|
|
|
|
++line;
|
|
|
|
|
|
|
|
if (*line != ')')
|
|
|
|
fatal_error("Malformed probe arguments '%s'.\n", line);
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2022-03-19 10:35:31 -07:00
|
|
|
static void parse_require_directive(struct shader_runner *runner, const char *line)
|
2022-01-26 06:35:33 -08:00
|
|
|
{
|
2023-09-14 02:29:24 -07:00
|
|
|
bool less_than = false;
|
2023-07-12 22:41:14 -07:00
|
|
|
unsigned int i;
|
|
|
|
|
2023-09-14 02:29:24 -07:00
|
|
|
if (match_string(line, "shader model >=", &line)
|
|
|
|
|| (less_than = match_string(line, "shader model <", &line)))
|
2022-01-26 06:35:33 -08:00
|
|
|
{
|
|
|
|
for (i = 0; i < ARRAY_SIZE(model_strings); ++i)
|
|
|
|
{
|
|
|
|
if (match_string(line, model_strings[i], &line))
|
|
|
|
{
|
2023-09-14 02:29:24 -07:00
|
|
|
if (less_than)
|
|
|
|
{
|
|
|
|
if (!i)
|
|
|
|
fatal_error("Shader model < '%s' is invalid.\n", line);
|
|
|
|
runner->maximum_shader_model = min(runner->maximum_shader_model, i - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
runner->minimum_shader_model = max(runner->minimum_shader_model, i);
|
|
|
|
}
|
2022-01-26 06:35:33 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fatal_error("Unknown shader model '%s'.\n", line);
|
|
|
|
}
|
2023-07-12 22:41:14 -07:00
|
|
|
else if (match_string(line, "options:", &line))
|
|
|
|
{
|
|
|
|
static const struct option
|
|
|
|
{
|
|
|
|
unsigned int option;
|
|
|
|
const char *name;
|
|
|
|
}
|
|
|
|
options[] =
|
|
|
|
{
|
|
|
|
{ 0, "none" },
|
|
|
|
{ D3DCOMPILE_PACK_MATRIX_ROW_MAJOR, "row-major" },
|
|
|
|
{ D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR, "column-major" },
|
2023-08-25 06:05:51 -07:00
|
|
|
{ D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY, "backcompat" },
|
2023-07-12 22:41:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
runner->compile_options = 0;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(options); ++i)
|
|
|
|
{
|
|
|
|
if (match_string(line, options[i].name, &line))
|
|
|
|
runner->compile_options |= options[i].option;
|
|
|
|
}
|
|
|
|
}
|
2023-12-12 06:27:41 -08:00
|
|
|
else if (match_string(line, "float64", &line))
|
|
|
|
{
|
|
|
|
runner->require_float64 = true;
|
|
|
|
}
|
2023-11-22 19:17:54 -08:00
|
|
|
else if (match_string(line, "int64", &line))
|
|
|
|
{
|
|
|
|
runner->require_int64 = true;
|
|
|
|
}
|
2023-10-13 14:35:12 -07:00
|
|
|
else if (match_string(line, "rov", &line))
|
|
|
|
{
|
|
|
|
runner->require_rov = true;
|
|
|
|
}
|
2022-01-26 06:35:33 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fatal_error("Unknown require directive '%s'.\n", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 18:42:16 -07:00
|
|
|
static DXGI_FORMAT parse_format(const char *line, enum texture_data_type *data_type, unsigned int *texel_size, const char **rest)
|
2021-10-03 17:19:09 -07:00
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *string;
|
|
|
|
enum texture_data_type data_type;
|
|
|
|
unsigned int texel_size;
|
|
|
|
DXGI_FORMAT format;
|
|
|
|
}
|
|
|
|
formats[] =
|
|
|
|
{
|
|
|
|
{"r32g32b32a32 float", TEXTURE_DATA_FLOAT, 16, DXGI_FORMAT_R32G32B32A32_FLOAT},
|
2023-04-20 17:46:27 -07:00
|
|
|
{"r32g32b32a32 uint", TEXTURE_DATA_UINT, 16, DXGI_FORMAT_R32G32B32A32_UINT},
|
2022-04-05 03:33:05 -07:00
|
|
|
{"r32g32 float", TEXTURE_DATA_FLOAT, 8, DXGI_FORMAT_R32G32_FLOAT},
|
2023-04-20 17:46:27 -07:00
|
|
|
{"r32g32 int", TEXTURE_DATA_SINT, 8, DXGI_FORMAT_R32G32_SINT},
|
2021-10-03 17:19:09 -07:00
|
|
|
{"r32g32 uint", TEXTURE_DATA_UINT, 8, DXGI_FORMAT_R32G32_UINT},
|
|
|
|
{"r32 float", TEXTURE_DATA_FLOAT, 4, DXGI_FORMAT_R32_FLOAT},
|
|
|
|
{"r32 sint", TEXTURE_DATA_SINT, 4, DXGI_FORMAT_R32_SINT},
|
2022-04-05 03:33:05 -07:00
|
|
|
{"r32 uint", TEXTURE_DATA_UINT, 4, DXGI_FORMAT_R32_UINT},
|
2021-10-03 17:19:09 -07:00
|
|
|
};
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(formats); ++i)
|
|
|
|
{
|
2022-03-21 18:42:16 -07:00
|
|
|
if (match_string(line, formats[i].string, rest))
|
2021-10-03 17:19:09 -07:00
|
|
|
{
|
2022-03-21 18:42:16 -07:00
|
|
|
if (data_type)
|
|
|
|
*data_type = formats[i].data_type;
|
|
|
|
*texel_size = formats[i].texel_size;
|
|
|
|
return formats[i].format;
|
2021-10-03 17:19:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 11:35:50 -07:00
|
|
|
fatal_error("Unknown format '%s'.\n", line);
|
2021-10-03 17:19:09 -07:00
|
|
|
}
|
|
|
|
|
2021-11-05 11:35:49 -07:00
|
|
|
static D3D12_TEXTURE_ADDRESS_MODE parse_sampler_address_mode(const char *line, const char **rest)
|
|
|
|
{
|
|
|
|
if (match_string(line, "border", rest))
|
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_BORDER;
|
|
|
|
if (match_string(line, "clamp", rest))
|
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
|
|
|
if (match_string(line, "mirror_once", rest))
|
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE;
|
|
|
|
if (match_string(line, "mirror", rest))
|
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_MIRROR;
|
|
|
|
if (match_string(line, "wrap", rest))
|
|
|
|
return D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
2021-11-05 11:35:50 -07:00
|
|
|
|
|
|
|
fatal_error("Unknown sampler address mode '%s'.\n", line);
|
2021-11-05 11:35:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_sampler_directive(struct sampler *sampler, const char *line)
|
|
|
|
{
|
|
|
|
if (match_string(line, "address", &line))
|
|
|
|
{
|
|
|
|
sampler->u_address = parse_sampler_address_mode(line, &line);
|
|
|
|
sampler->v_address = parse_sampler_address_mode(line, &line);
|
|
|
|
sampler->w_address = parse_sampler_address_mode(line, &line);
|
|
|
|
}
|
|
|
|
else if (match_string(line, "filter", &line))
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *string;
|
|
|
|
D3D12_FILTER filter;
|
|
|
|
}
|
|
|
|
filters[] =
|
|
|
|
{
|
|
|
|
{"point point point", D3D12_FILTER_MIN_MAG_MIP_POINT},
|
|
|
|
{"point point linear", D3D12_FILTER_MIN_MAG_POINT_MIP_LINEAR},
|
|
|
|
{"point linear point", D3D12_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
|
|
|
|
{"point linear linear", D3D12_FILTER_MIN_POINT_MAG_MIP_LINEAR},
|
|
|
|
{"linear point point", D3D12_FILTER_MIN_LINEAR_MAG_MIP_POINT},
|
|
|
|
{"linear point linear", D3D12_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
|
|
|
|
{"linear linear point", D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT},
|
|
|
|
{"linear linear linear", D3D12_FILTER_MIN_MAG_MIP_LINEAR},
|
|
|
|
};
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(filters); ++i)
|
|
|
|
{
|
|
|
|
if (match_string(line, filters[i].string, &line))
|
|
|
|
{
|
|
|
|
sampler->filter = filters[i].filter;
|
2021-11-05 11:35:50 -07:00
|
|
|
return;
|
2021-11-05 11:35:49 -07:00
|
|
|
}
|
|
|
|
}
|
2021-11-05 11:35:50 -07:00
|
|
|
|
|
|
|
fatal_error("Unknown sampler filter '%s'.\n", line);
|
2021-11-05 11:35:49 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-05 11:35:50 -07:00
|
|
|
fatal_error("Unknown sampler directive '%s'.\n", line);
|
2021-11-05 11:35:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 18:42:17 -07:00
|
|
|
static void parse_resource_directive(struct resource_params *resource, const char *line)
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2021-10-03 17:19:09 -07:00
|
|
|
if (match_string(line, "format", &line))
|
|
|
|
{
|
2022-03-21 18:42:17 -07:00
|
|
|
resource->format = parse_format(line, &resource->data_type, &resource->texel_size, &line);
|
2021-10-03 17:19:09 -07:00
|
|
|
}
|
|
|
|
else if (match_string(line, "size", &line))
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2024-01-24 11:11:17 -08:00
|
|
|
if (sscanf(line, "( buffer , %u ) ", &resource->width) == 1)
|
|
|
|
{
|
|
|
|
resource->dimension = RESOURCE_DIMENSION_BUFFER;
|
|
|
|
resource->height = 1;
|
|
|
|
}
|
|
|
|
else if (sscanf(line, "( 2d , %u , %u ) ", &resource->width, &resource->height) == 2)
|
|
|
|
{
|
|
|
|
resource->dimension = RESOURCE_DIMENSION_2D;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fatal_error("Malformed resource size '%s'.\n", line);
|
|
|
|
}
|
2021-10-03 17:19:08 -07:00
|
|
|
}
|
2023-04-30 17:23:00 -07:00
|
|
|
else if (match_string(line, "levels", &line))
|
|
|
|
{
|
|
|
|
char *rest;
|
|
|
|
|
|
|
|
resource->level_count = strtoul(line, &rest, 10);
|
|
|
|
if (rest == line)
|
|
|
|
fatal_error("Malformed texture directive '%s'.\n", line);
|
|
|
|
}
|
2021-10-03 17:19:08 -07:00
|
|
|
else
|
|
|
|
{
|
2021-10-03 17:19:09 -07:00
|
|
|
union
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
int32_t i;
|
|
|
|
uint32_t u;
|
|
|
|
} u;
|
2021-10-03 17:19:08 -07:00
|
|
|
char *rest;
|
|
|
|
|
2021-10-03 17:19:09 -07:00
|
|
|
u.u = 0;
|
|
|
|
|
|
|
|
for (;;)
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2022-03-21 18:42:17 -07:00
|
|
|
switch (resource->data_type)
|
2021-10-03 17:19:09 -07:00
|
|
|
{
|
|
|
|
case TEXTURE_DATA_FLOAT:
|
|
|
|
u.f = strtof(line, &rest);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEXTURE_DATA_SINT:
|
2023-04-20 17:46:27 -07:00
|
|
|
u.i = strtol(line, &rest, 0);
|
2021-10-03 17:19:09 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TEXTURE_DATA_UINT:
|
2023-04-20 17:46:27 -07:00
|
|
|
u.u = strtoul(line, &rest, 0);
|
2021-10-03 17:19:09 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rest == line)
|
|
|
|
break;
|
|
|
|
|
2022-03-21 18:42:17 -07:00
|
|
|
vkd3d_array_reserve((void **)&resource->data, &resource->data_capacity, resource->data_size + sizeof(u), 1);
|
|
|
|
memcpy(resource->data + resource->data_size, &u, sizeof(u));
|
|
|
|
resource->data_size += sizeof(u);
|
2021-10-03 17:19:08 -07:00
|
|
|
line = rest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 18:42:16 -07:00
|
|
|
static void parse_input_layout_directive(struct shader_runner *runner, const char *line)
|
|
|
|
{
|
|
|
|
struct input_element *element;
|
|
|
|
const char *rest;
|
|
|
|
|
|
|
|
vkd3d_array_reserve((void **)&runner->input_elements, &runner->input_element_capacity,
|
|
|
|
runner->input_element_count + 1, sizeof(*runner->input_elements));
|
|
|
|
element = &runner->input_elements[runner->input_element_count++];
|
|
|
|
|
|
|
|
element->slot = strtoul(line, (char **)&rest, 10);
|
|
|
|
if (rest == line)
|
|
|
|
fatal_error("Malformed input layout directive '%s'.\n", line);
|
|
|
|
line = rest;
|
|
|
|
|
|
|
|
element->format = parse_format(line, NULL, &element->texel_size, &line);
|
|
|
|
|
|
|
|
if (!(rest = strpbrk(line, " \n")))
|
|
|
|
rest = line + strlen(line);
|
|
|
|
element->name = malloc(rest - line + 1);
|
|
|
|
memcpy(element->name, line, rest - line);
|
|
|
|
element->name[rest - line] = 0;
|
|
|
|
line = rest;
|
|
|
|
|
|
|
|
element->index = strtoul(line, (char **)&rest, 10);
|
|
|
|
if (rest == line)
|
|
|
|
element->index = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-08 16:18:35 -07:00
|
|
|
void init_resource(struct resource *resource, const struct resource_params *params)
|
|
|
|
{
|
|
|
|
resource->type = params->type;
|
2024-01-22 15:20:18 -08:00
|
|
|
resource->dimension = params->dimension;
|
2022-06-08 16:18:35 -07:00
|
|
|
resource->slot = params->slot;
|
2022-06-08 16:18:37 -07:00
|
|
|
resource->format = params->format;
|
2022-06-08 16:18:35 -07:00
|
|
|
resource->size = params->data_size;
|
2022-06-08 16:18:37 -07:00
|
|
|
resource->texel_size = params->texel_size;
|
|
|
|
resource->width = params->width;
|
|
|
|
resource->height = params->height;
|
|
|
|
}
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
struct resource *shader_runner_get_resource(struct shader_runner *runner, enum resource_type type, unsigned int slot)
|
2022-06-08 16:18:37 -07:00
|
|
|
{
|
|
|
|
struct resource *resource;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < runner->resource_count; ++i)
|
|
|
|
{
|
|
|
|
resource = runner->resources[i];
|
|
|
|
|
|
|
|
if (resource->type == type && resource->slot == slot)
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2022-06-08 16:18:35 -07:00
|
|
|
}
|
|
|
|
|
2022-04-07 16:58:13 -07:00
|
|
|
static void set_resource(struct shader_runner *runner, struct resource *resource)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < runner->resource_count; ++i)
|
|
|
|
{
|
|
|
|
if (runner->resources[i]->slot == resource->slot && runner->resources[i]->type == resource->type)
|
|
|
|
{
|
|
|
|
runner->ops->destroy_resource(runner, runner->resources[i]);
|
|
|
|
runner->resources[i] = resource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 10:18:29 -07:00
|
|
|
if (runner->resource_count == MAX_RESOURCES)
|
|
|
|
fatal_error("Too many resources declared.\n");
|
|
|
|
|
2022-04-07 16:58:13 -07:00
|
|
|
runner->resources[runner->resource_count++] = resource;
|
|
|
|
}
|
|
|
|
|
2022-03-19 10:35:31 -07:00
|
|
|
static void set_uniforms(struct shader_runner *runner, size_t offset, size_t count, const void *uniforms)
|
2022-01-26 17:40:32 -08:00
|
|
|
{
|
2024-01-31 10:21:23 -08:00
|
|
|
size_t initial_count = runner->uniform_count;
|
|
|
|
|
2022-03-19 10:35:31 -07:00
|
|
|
runner->uniform_count = align(max(runner->uniform_count, offset + count), 4);
|
|
|
|
vkd3d_array_reserve((void **)&runner->uniforms, &runner->uniform_capacity,
|
|
|
|
runner->uniform_count, sizeof(*runner->uniforms));
|
2024-01-31 10:21:23 -08:00
|
|
|
memset(runner->uniforms + initial_count, 127,
|
|
|
|
(runner->uniform_count - initial_count) * sizeof(*runner->uniforms));
|
2022-03-19 10:35:31 -07:00
|
|
|
memcpy(runner->uniforms + offset, uniforms, count * sizeof(*runner->uniforms));
|
2022-01-26 17:40:32 -08:00
|
|
|
}
|
|
|
|
|
2023-03-17 04:35:13 -07:00
|
|
|
static void read_int(const char **line, int *i)
|
|
|
|
{
|
|
|
|
char *rest;
|
|
|
|
long val;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtol(*line, &rest, 0);
|
|
|
|
|
|
|
|
if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest)))
|
|
|
|
fatal_error("Malformed int constant '%s'.\n", *line);
|
|
|
|
|
|
|
|
*i = val;
|
|
|
|
if (*i != val)
|
|
|
|
fatal_error("Out of range int constant '%.*s'.\n", (int)(rest - *line), *line);
|
|
|
|
|
|
|
|
*line = rest;
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
static void read_uint(const char **line, unsigned int *u, bool is_uniform)
|
2023-03-17 04:35:13 -07:00
|
|
|
{
|
|
|
|
char *rest;
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtoul(*line, &rest, 0);
|
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
if (errno != 0 || (is_uniform && *rest != '\0' && !isspace((unsigned char)*rest)))
|
2023-03-17 04:35:13 -07:00
|
|
|
fatal_error("Malformed uint constant '%s'.\n", *line);
|
|
|
|
|
|
|
|
*u = val;
|
|
|
|
if (*u != val)
|
|
|
|
fatal_error("Out of range uint constant '%.*s'.\n", (int)(rest - *line), *line);
|
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
*line = rest + (!is_uniform && *rest == ',');
|
2023-03-17 04:35:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void read_int4(const char **line, struct ivec4 *v)
|
|
|
|
{
|
|
|
|
read_int(line, &v->x);
|
|
|
|
read_int(line, &v->y);
|
|
|
|
read_int(line, &v->z);
|
|
|
|
read_int(line, &v->w);
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
static void read_uint4(const char **line, struct uvec4 *v, bool is_uniform)
|
2023-03-17 04:35:13 -07:00
|
|
|
{
|
2023-10-13 14:27:44 -07:00
|
|
|
read_uint(line, &v->x, is_uniform);
|
|
|
|
read_uint(line, &v->y, is_uniform);
|
|
|
|
read_uint(line, &v->z, is_uniform);
|
|
|
|
read_uint(line, &v->w, is_uniform);
|
2023-03-17 04:35:13 -07:00
|
|
|
}
|
|
|
|
|
2023-11-09 20:48:23 -08:00
|
|
|
static void read_int64(const char **line, int64_t *i)
|
|
|
|
{
|
|
|
|
char *rest;
|
|
|
|
int64_t val;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtoll(*line, &rest, 0);
|
|
|
|
|
|
|
|
if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest)))
|
|
|
|
fatal_error("Malformed int64 constant '%s'.\n", *line);
|
|
|
|
|
|
|
|
*i = val;
|
|
|
|
*line = rest;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_uint64(const char **line, uint64_t *u)
|
|
|
|
{
|
|
|
|
char *rest;
|
|
|
|
uint64_t val;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtoull(*line, &rest, 0);
|
|
|
|
|
|
|
|
if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest)))
|
|
|
|
fatal_error("Malformed uint64 constant '%s'.\n", *line);
|
|
|
|
|
|
|
|
*u = val;
|
|
|
|
*line = rest;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_int64_t2(const char **line, struct i64vec2 *v)
|
|
|
|
{
|
|
|
|
read_int64(line, &v->x);
|
|
|
|
read_int64(line, &v->y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_uint64_t2(const char **line, struct u64vec2 *v)
|
|
|
|
{
|
|
|
|
read_uint64(line, &v->x);
|
|
|
|
read_uint64(line, &v->y);
|
|
|
|
}
|
|
|
|
|
2022-03-19 10:35:31 -07:00
|
|
|
static void parse_test_directive(struct shader_runner *runner, const char *line)
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
2024-01-29 15:07:39 -08:00
|
|
|
bool skip_directive = false;
|
|
|
|
const char *line_ini;
|
|
|
|
bool match = true;
|
2022-06-08 16:18:38 -07:00
|
|
|
char *rest;
|
2021-08-13 14:37:31 -07:00
|
|
|
int ret;
|
2022-06-08 16:18:38 -07:00
|
|
|
|
2022-04-14 03:52:33 -07:00
|
|
|
runner->is_todo = false;
|
|
|
|
|
2024-01-29 15:07:39 -08:00
|
|
|
while (match)
|
2023-11-10 13:37:40 -08:00
|
|
|
{
|
2024-01-29 15:07:39 -08:00
|
|
|
match = false;
|
|
|
|
|
|
|
|
if (match_string_with_args(line, "todo", &line, runner->minimum_shader_model))
|
|
|
|
{
|
|
|
|
runner->is_todo = true;
|
|
|
|
match = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_ini = line;
|
|
|
|
if (match_string_with_args(line, "if", &line, runner->minimum_shader_model))
|
|
|
|
{
|
|
|
|
match = true;
|
|
|
|
}
|
|
|
|
else if (line != line_ini)
|
|
|
|
{
|
|
|
|
/* Matched "if" but for other shader models. */
|
|
|
|
skip_directive = true;
|
|
|
|
match = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skip_directive)
|
|
|
|
{
|
|
|
|
const char *new_line;
|
|
|
|
|
|
|
|
if ((new_line = strchr(line, '\n')))
|
|
|
|
line = new_line + 1;
|
|
|
|
else
|
|
|
|
line += strlen(line);
|
|
|
|
return;
|
2023-11-10 13:37:40 -08:00
|
|
|
}
|
2022-04-14 03:52:33 -07:00
|
|
|
|
2021-08-13 14:37:31 -07:00
|
|
|
if (match_string(line, "dispatch", &line))
|
|
|
|
{
|
|
|
|
unsigned int x, y, z;
|
|
|
|
|
|
|
|
ret = sscanf(line, "%u %u %u", &x, &y, &z);
|
|
|
|
if (ret < 3)
|
|
|
|
fatal_error("Malformed dispatch arguments '%s'.\n", line);
|
|
|
|
|
|
|
|
runner->last_render_failed = !runner->ops->dispatch(runner, x, y, z);
|
|
|
|
}
|
|
|
|
else if (match_string(line, "draw quad", &line))
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
2022-04-07 16:58:13 -07:00
|
|
|
struct resource_params params;
|
|
|
|
struct input_element *element;
|
2024-01-24 14:44:47 -08:00
|
|
|
unsigned int i;
|
2022-04-07 16:58:13 -07:00
|
|
|
|
|
|
|
/* For simplicity, draw a large triangle instead. */
|
|
|
|
static const struct vec2 quad[] =
|
|
|
|
{
|
|
|
|
{-2.0f, -2.0f},
|
|
|
|
{-2.0f, 4.0f},
|
|
|
|
{ 4.0f, -2.0f},
|
|
|
|
};
|
|
|
|
|
2022-03-21 18:42:15 -07:00
|
|
|
static const char vs_source[] =
|
2022-08-15 17:53:55 -07:00
|
|
|
"float4 main(float4 pos : position) : sv_position\n"
|
2022-03-21 18:42:15 -07:00
|
|
|
"{\n"
|
2022-08-15 17:53:55 -07:00
|
|
|
" return pos;\n"
|
2022-03-21 18:42:15 -07:00
|
|
|
"}";
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
if (!shader_runner_get_resource(runner, RESOURCE_TYPE_RENDER_TARGET, 0))
|
2022-06-08 16:18:37 -07:00
|
|
|
{
|
|
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
params.slot = 0;
|
|
|
|
params.type = RESOURCE_TYPE_RENDER_TARGET;
|
2024-01-22 15:20:18 -08:00
|
|
|
params.dimension = RESOURCE_DIMENSION_2D;
|
2022-06-08 16:18:37 -07:00
|
|
|
params.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
|
|
|
params.data_type = TEXTURE_DATA_FLOAT;
|
|
|
|
params.texel_size = 16;
|
|
|
|
params.width = RENDER_TARGET_WIDTH;
|
|
|
|
params.height = RENDER_TARGET_HEIGHT;
|
2023-04-30 17:23:00 -07:00
|
|
|
params.level_count = 1;
|
2022-06-08 16:18:37 -07:00
|
|
|
|
|
|
|
set_resource(runner, runner->ops->create_resource(runner, ¶ms));
|
|
|
|
}
|
|
|
|
|
2024-01-24 14:44:47 -08:00
|
|
|
for (i = 0; i < runner->input_element_count; ++i)
|
|
|
|
free(runner->input_elements[i].name);
|
|
|
|
|
2022-04-07 16:58:13 -07:00
|
|
|
vkd3d_array_reserve((void **)&runner->input_elements, &runner->input_element_capacity,
|
|
|
|
1, sizeof(*runner->input_elements));
|
|
|
|
element = &runner->input_elements[0];
|
2022-08-15 17:53:55 -07:00
|
|
|
element->name = strdup("position");
|
2022-04-07 16:58:13 -07:00
|
|
|
element->slot = 0;
|
|
|
|
element->format = DXGI_FORMAT_R32G32_FLOAT;
|
|
|
|
element->texel_size = sizeof(*quad);
|
|
|
|
element->index = 0;
|
|
|
|
runner->input_element_count = 1;
|
|
|
|
|
|
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
params.slot = 0;
|
|
|
|
params.type = RESOURCE_TYPE_VERTEX_BUFFER;
|
2024-01-22 15:20:18 -08:00
|
|
|
params.dimension = RESOURCE_DIMENSION_BUFFER;
|
2022-04-07 16:58:13 -07:00
|
|
|
params.data = malloc(sizeof(quad));
|
|
|
|
memcpy(params.data, quad, sizeof(quad));
|
|
|
|
params.data_size = sizeof(quad);
|
|
|
|
set_resource(runner, runner->ops->create_resource(runner, ¶ms));
|
2024-01-24 13:50:30 -08:00
|
|
|
free(params.data);
|
2022-04-07 16:58:13 -07:00
|
|
|
|
2022-03-21 18:42:15 -07:00
|
|
|
if (!runner->vs_source)
|
|
|
|
runner->vs_source = strdup(vs_source);
|
|
|
|
|
2022-04-14 03:52:32 -07:00
|
|
|
runner->last_render_failed = !runner->ops->draw(runner, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, 3);
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
2022-03-21 18:42:21 -07:00
|
|
|
else if (match_string(line, "draw", &line))
|
|
|
|
{
|
|
|
|
D3D_PRIMITIVE_TOPOLOGY topology;
|
2022-06-08 16:18:37 -07:00
|
|
|
struct resource_params params;
|
2022-03-21 18:42:21 -07:00
|
|
|
unsigned int vertex_count;
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
if (!shader_runner_get_resource(runner, RESOURCE_TYPE_RENDER_TARGET, 0))
|
2022-06-08 16:18:37 -07:00
|
|
|
{
|
|
|
|
memset(¶ms, 0, sizeof(params));
|
|
|
|
params.slot = 0;
|
|
|
|
params.type = RESOURCE_TYPE_RENDER_TARGET;
|
2024-01-22 15:20:18 -08:00
|
|
|
params.dimension = RESOURCE_DIMENSION_2D;
|
2022-06-08 16:18:37 -07:00
|
|
|
params.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
|
|
|
params.data_type = TEXTURE_DATA_FLOAT;
|
|
|
|
params.texel_size = 16;
|
|
|
|
params.width = RENDER_TARGET_WIDTH;
|
|
|
|
params.height = RENDER_TARGET_HEIGHT;
|
2023-04-30 17:23:00 -07:00
|
|
|
params.level_count = 1;
|
2022-06-08 16:18:37 -07:00
|
|
|
|
|
|
|
set_resource(runner, runner->ops->create_resource(runner, ¶ms));
|
|
|
|
}
|
|
|
|
|
2022-03-21 18:42:21 -07:00
|
|
|
if (match_string(line, "triangle list", &line))
|
|
|
|
topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
2022-04-05 03:33:05 -07:00
|
|
|
else if (match_string(line, "triangle strip", &line))
|
|
|
|
topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
|
2022-03-21 18:42:21 -07:00
|
|
|
else
|
|
|
|
fatal_error("Unknown primitive topology '%s'.\n", line);
|
|
|
|
|
|
|
|
vertex_count = strtoul(line, &rest, 10);
|
|
|
|
if (line == rest)
|
|
|
|
fatal_error("Malformed vertex count '%s'.\n", line);
|
|
|
|
|
2022-04-14 03:52:32 -07:00
|
|
|
runner->last_render_failed = !runner->ops->draw(runner, topology, vertex_count);
|
2022-03-21 18:42:21 -07:00
|
|
|
}
|
2022-04-17 23:33:58 -07:00
|
|
|
else if (match_string(line, "probe", &line))
|
2020-09-30 19:01:21 -07:00
|
|
|
{
|
2022-06-08 16:18:39 -07:00
|
|
|
unsigned int left, top, right, bottom, ulps, slot;
|
2022-05-17 06:45:41 -07:00
|
|
|
struct resource_readback *rb;
|
2022-06-08 16:18:37 -07:00
|
|
|
struct resource *resource;
|
2020-09-30 19:01:21 -07:00
|
|
|
RECT rect;
|
2021-08-13 14:37:31 -07:00
|
|
|
int len;
|
2020-09-30 19:01:21 -07:00
|
|
|
|
2022-04-14 03:52:32 -07:00
|
|
|
if (runner->last_render_failed)
|
|
|
|
return;
|
|
|
|
|
2022-06-08 16:18:38 -07:00
|
|
|
if (match_string(line, "uav", &line))
|
|
|
|
{
|
2022-06-08 16:18:39 -07:00
|
|
|
slot = strtoul(line, &rest, 10);
|
2022-06-08 16:18:38 -07:00
|
|
|
|
|
|
|
if (rest == line)
|
|
|
|
fatal_error("Malformed UAV index '%s'.\n", line);
|
|
|
|
line = rest;
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
resource = shader_runner_get_resource(runner, RESOURCE_TYPE_UAV, slot);
|
2022-06-08 16:18:38 -07:00
|
|
|
}
|
2024-01-24 11:35:39 -08:00
|
|
|
else if (match_string(line, "rtv", &line))
|
2022-06-08 16:18:39 -07:00
|
|
|
{
|
|
|
|
slot = strtoul(line, &rest, 10);
|
|
|
|
|
|
|
|
if (rest == line)
|
|
|
|
fatal_error("Malformed render target index '%s'.\n", line);
|
|
|
|
line = rest;
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
resource = shader_runner_get_resource(runner, RESOURCE_TYPE_RENDER_TARGET, slot);
|
2022-06-08 16:18:39 -07:00
|
|
|
}
|
2022-06-08 16:18:38 -07:00
|
|
|
else
|
|
|
|
{
|
2023-09-21 22:31:31 -07:00
|
|
|
resource = shader_runner_get_resource(runner, RESOURCE_TYPE_RENDER_TARGET, 0);
|
2022-06-08 16:18:38 -07:00
|
|
|
}
|
|
|
|
|
2022-06-08 16:18:37 -07:00
|
|
|
rb = runner->ops->get_resource_readback(runner, resource);
|
|
|
|
|
2022-04-17 23:33:58 -07:00
|
|
|
if (match_string(line, "all", &line))
|
|
|
|
{
|
2022-06-08 16:18:37 -07:00
|
|
|
set_rect(&rect, 0, 0, resource->width, resource->height);
|
2022-04-17 23:33:58 -07:00
|
|
|
}
|
2022-06-08 16:18:38 -07:00
|
|
|
else if (sscanf(line, " ( %d , %d , %d , %d )%n", &left, &top, &right, &bottom, &len) == 4)
|
2022-04-17 23:33:58 -07:00
|
|
|
{
|
|
|
|
set_rect(&rect, left, top, right, bottom);
|
|
|
|
line += len;
|
|
|
|
}
|
2022-06-08 16:18:38 -07:00
|
|
|
else if (sscanf(line, " ( %u , %u )%n", &left, &top, &len) == 2)
|
2022-04-17 23:33:58 -07:00
|
|
|
{
|
|
|
|
set_rect(&rect, left, top, left + 1, top + 1);
|
|
|
|
line += len;
|
|
|
|
}
|
2024-01-24 11:35:39 -08:00
|
|
|
else if (sscanf(line, " ( %u )%n", &left, &len) == 1)
|
|
|
|
{
|
|
|
|
set_rect(&rect, left, 0, left + 1, 1);
|
|
|
|
line += len;
|
|
|
|
}
|
2022-05-17 06:45:41 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fatal_error("Malformed probe arguments '%s'.\n", line);
|
|
|
|
}
|
2020-10-01 21:09:44 -07:00
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
if (match_string(line, "rgbaui", &line))
|
|
|
|
{
|
|
|
|
struct uvec4 v;
|
|
|
|
|
|
|
|
if (*line != '(')
|
|
|
|
fatal_error("Malformed probe arguments '%s'.\n", line);
|
|
|
|
++line;
|
|
|
|
read_uint4(&line, &v, false);
|
|
|
|
line = close_parentheses(line);
|
|
|
|
todo_if(runner->is_todo) check_readback_data_uvec4(rb, &rect, &v);
|
|
|
|
}
|
|
|
|
else if (match_string(line, "rgba", &line))
|
2022-05-17 06:45:42 -07:00
|
|
|
{
|
|
|
|
struct vec4 v;
|
2022-04-14 03:52:32 -07:00
|
|
|
|
2022-05-17 06:45:42 -07:00
|
|
|
ret = sscanf(line, "( %f , %f , %f , %f ) %u", &v.x, &v.y, &v.z, &v.w, &ulps);
|
|
|
|
if (ret < 4)
|
|
|
|
fatal_error("Malformed probe arguments '%s'.\n", line);
|
|
|
|
if (ret < 5)
|
|
|
|
ulps = 0;
|
|
|
|
todo_if(runner->is_todo) check_readback_data_vec4(rb, &rect, &v, ulps);
|
|
|
|
}
|
2023-10-13 14:27:44 -07:00
|
|
|
else if (match_string(line, "rui", &line))
|
|
|
|
{
|
|
|
|
unsigned int expect;
|
|
|
|
D3D12_BOX box;
|
|
|
|
|
|
|
|
box.left = rect.left;
|
|
|
|
box.right = rect.right;
|
|
|
|
box.top = rect.top;
|
|
|
|
box.bottom = rect.bottom;
|
|
|
|
box.front = 0;
|
|
|
|
box.back = 1;
|
|
|
|
if (*line != '(')
|
|
|
|
fatal_error("Malformed probe arguments '%s'.\n", line);
|
|
|
|
++line;
|
|
|
|
read_uint(&line, &expect, false);
|
|
|
|
line = close_parentheses(line);
|
|
|
|
todo_if(runner->is_todo) check_readback_data_uint(rb, &box, expect, 0);
|
|
|
|
}
|
2022-05-17 06:45:42 -07:00
|
|
|
else if (match_string(line, "r", &line))
|
|
|
|
{
|
|
|
|
float expect;
|
|
|
|
|
|
|
|
ret = sscanf(line, "( %f ) %u", &expect, &ulps);
|
|
|
|
if (ret < 1)
|
|
|
|
fatal_error("Malformed probe arguments '%s'.\n", line);
|
|
|
|
if (ret < 2)
|
|
|
|
ulps = 0;
|
|
|
|
todo_if(runner->is_todo) check_readback_data_float(rb, &rect, expect, ulps);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-05 11:35:50 -07:00
|
|
|
fatal_error("Malformed probe arguments '%s'.\n", line);
|
2022-05-17 06:45:42 -07:00
|
|
|
}
|
2020-10-01 21:09:44 -07:00
|
|
|
|
2022-05-17 06:45:41 -07:00
|
|
|
runner->ops->release_readback(runner, rb);
|
2020-09-30 19:01:21 -07:00
|
|
|
}
|
2020-09-30 19:01:18 -07:00
|
|
|
else if (match_string(line, "uniform", &line))
|
|
|
|
{
|
|
|
|
unsigned int offset;
|
|
|
|
|
|
|
|
if (!sscanf(line, "%u", &offset))
|
2022-09-27 11:35:16 -07:00
|
|
|
fatal_error("Malformed uniform offset '%s'.\n", line);
|
2020-09-30 19:01:18 -07:00
|
|
|
line = strchr(line, ' ') + 1;
|
|
|
|
|
|
|
|
if (match_string(line, "float4", &line))
|
|
|
|
{
|
|
|
|
struct vec4 v;
|
|
|
|
|
|
|
|
if (sscanf(line, "%f %f %f %f", &v.x, &v.y, &v.z, &v.w) < 4)
|
2021-11-05 11:35:50 -07:00
|
|
|
fatal_error("Malformed float4 constant '%s'.\n", line);
|
2022-03-19 10:35:31 -07:00
|
|
|
set_uniforms(runner, offset, 4, &v);
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
2021-09-09 19:11:32 -07:00
|
|
|
else if (match_string(line, "float", &line))
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
|
|
|
|
if (sscanf(line, "%f", &f) < 1)
|
2021-11-05 11:35:50 -07:00
|
|
|
fatal_error("Malformed float constant '%s'.\n", line);
|
2022-03-19 10:35:31 -07:00
|
|
|
set_uniforms(runner, offset, 1, &f);
|
2021-09-09 19:11:32 -07:00
|
|
|
}
|
2023-11-09 20:48:23 -08:00
|
|
|
else if (match_string(line, "double2", &line))
|
|
|
|
{
|
|
|
|
struct dvec2 v;
|
|
|
|
|
|
|
|
if (sscanf(line, "%lf %lf", &v.x, &v.y) < 2)
|
|
|
|
fatal_error("Malformed double2 constant '%s'.\n", line);
|
|
|
|
set_uniforms(runner, offset, 4, &v);
|
|
|
|
}
|
2023-03-17 04:35:13 -07:00
|
|
|
else if (match_string(line, "int4", &line))
|
|
|
|
{
|
|
|
|
struct ivec4 v;
|
|
|
|
|
|
|
|
read_int4(&line, &v);
|
|
|
|
set_uniforms(runner, offset, 4, &v);
|
|
|
|
}
|
|
|
|
else if (match_string(line, "uint4", &line))
|
2022-02-02 04:46:13 -08:00
|
|
|
{
|
2023-03-17 04:35:13 -07:00
|
|
|
struct uvec4 v;
|
2022-02-02 04:46:13 -08:00
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
read_uint4(&line, &v, true);
|
2023-03-17 04:35:13 -07:00
|
|
|
set_uniforms(runner, offset, 4, &v);
|
2022-02-02 04:46:13 -08:00
|
|
|
}
|
2021-09-09 19:11:32 -07:00
|
|
|
else if (match_string(line, "int", &line))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2023-03-17 04:35:13 -07:00
|
|
|
read_int(&line, &i);
|
2022-03-19 10:35:31 -07:00
|
|
|
set_uniforms(runner, offset, 1, &i);
|
2021-09-09 19:11:32 -07:00
|
|
|
}
|
2020-09-30 19:01:22 -07:00
|
|
|
else if (match_string(line, "uint", &line))
|
|
|
|
{
|
|
|
|
unsigned int u;
|
|
|
|
|
2023-10-13 14:27:44 -07:00
|
|
|
read_uint(&line, &u, true);
|
2022-03-19 10:35:31 -07:00
|
|
|
set_uniforms(runner, offset, 1, &u);
|
2020-09-30 19:01:22 -07:00
|
|
|
}
|
2023-11-09 20:48:23 -08:00
|
|
|
else if (match_string(line, "int64_t2", &line))
|
|
|
|
{
|
|
|
|
struct i64vec2 v;
|
|
|
|
|
|
|
|
read_int64_t2(&line, &v);
|
|
|
|
set_uniforms(runner, offset, 4, &v);
|
|
|
|
}
|
|
|
|
else if (match_string(line, "uint64_t2", &line))
|
|
|
|
{
|
|
|
|
struct u64vec2 v;
|
|
|
|
|
|
|
|
read_uint64_t2(&line, &v);
|
|
|
|
set_uniforms(runner, offset, 4, &v);
|
|
|
|
}
|
2022-09-27 11:35:16 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fatal_error("Unknown uniform type '%s'.\n", line);
|
|
|
|
}
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-05 11:35:50 -07:00
|
|
|
fatal_error("Unknown test directive '%s'.\n", line);
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
struct sampler *shader_runner_get_sampler(struct shader_runner *runner, unsigned int slot)
|
2021-11-05 11:35:49 -07:00
|
|
|
{
|
|
|
|
struct sampler *sampler;
|
|
|
|
size_t i;
|
|
|
|
|
2022-03-19 10:35:31 -07:00
|
|
|
for (i = 0; i < runner->sampler_count; ++i)
|
2021-11-05 11:35:49 -07:00
|
|
|
{
|
2022-03-19 10:35:31 -07:00
|
|
|
sampler = &runner->samplers[i];
|
2021-11-05 11:35:49 -07:00
|
|
|
|
|
|
|
if (sampler->slot == slot)
|
|
|
|
return sampler;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-03-21 18:42:18 -07:00
|
|
|
unsigned int get_vb_stride(const struct shader_runner *runner, unsigned int slot)
|
|
|
|
{
|
|
|
|
unsigned int stride = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* We currently don't deal with vertex formats less than 32 bits, so don't
|
|
|
|
* bother with alignment. */
|
|
|
|
for (i = 0; i < runner->input_element_count; ++i)
|
|
|
|
{
|
|
|
|
const struct input_element *element = &runner->input_elements[i];
|
|
|
|
|
|
|
|
if (element->slot == slot)
|
|
|
|
stride += element->texel_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stride;
|
|
|
|
}
|
|
|
|
|
2023-11-15 12:41:33 -08:00
|
|
|
static HRESULT map_special_hrs(HRESULT hr)
|
2023-04-20 08:09:05 -07:00
|
|
|
{
|
2023-11-15 12:41:33 -08:00
|
|
|
if (hr == 0x88760b59)
|
|
|
|
{
|
|
|
|
trace("Mapping hr %#x (D3DXERR_INVALIDDATA) as %#x.\n", hr, E_FAIL);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2023-04-20 08:09:05 -07:00
|
|
|
if (hr == 0x80010064)
|
|
|
|
{
|
2023-11-11 17:48:30 -08:00
|
|
|
trace("Mapping unidentified hr %#x as %#x.\n", hr, E_FAIL);
|
2023-04-20 08:09:05 -07:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:32:25 -07:00
|
|
|
const char *shader_type_string(enum shader_type type)
|
|
|
|
{
|
|
|
|
static const char *const shader_types[] =
|
|
|
|
{
|
|
|
|
[SHADER_TYPE_CS] = "cs",
|
|
|
|
[SHADER_TYPE_PS] = "ps",
|
|
|
|
[SHADER_TYPE_VS] = "vs",
|
2023-10-12 03:51:19 -07:00
|
|
|
[SHADER_TYPE_FX] = "fx",
|
2023-09-20 21:32:25 -07:00
|
|
|
};
|
|
|
|
assert(type < ARRAY_SIZE(shader_types));
|
|
|
|
return shader_types[type];
|
|
|
|
}
|
|
|
|
|
2023-09-14 02:29:24 -07:00
|
|
|
/* Avoid issues with calling convention mismatch and different methods for string
|
|
|
|
* retrieval by copying all IDxcBlob objects to a new ID3D10Blob. */
|
|
|
|
|
|
|
|
static void d3d10_blob_from_dxc_blob_utf8(IDxcBlobUtf8 *blob, ID3D10Blob **blob_out)
|
|
|
|
{
|
|
|
|
ID3D10Blob *d3d_blob;
|
|
|
|
size_t size;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
size = IDxcBlobUtf8_GetStringLength(blob) + 1;
|
|
|
|
if (FAILED(hr = D3DCreateBlob(size, (ID3DBlob **)&d3d_blob)))
|
|
|
|
{
|
|
|
|
trace("Failed to create blob, hr %#x.\n", hr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ID3D10Blob_GetBufferPointer(d3d_blob), IDxcBlobUtf8_GetStringPointer(blob), size);
|
|
|
|
*blob_out = d3d_blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT d3d10_blob_from_dxc_blob(IDxcBlob *blob, ID3D10Blob **blob_out)
|
|
|
|
{
|
|
|
|
ID3D10Blob *d3d_blob;
|
|
|
|
size_t size;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
size = IDxcBlob_GetBufferSize(blob);
|
|
|
|
if (FAILED(hr = D3DCreateBlob(size, (ID3DBlob **)&d3d_blob)))
|
|
|
|
{
|
|
|
|
trace("Failed to create blob, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ID3D10Blob_GetBufferPointer(d3d_blob), IDxcBlob_GetBufferPointer(blob), size);
|
|
|
|
*blob_out = d3d_blob;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT dxc_compiler_compile_shader(void *dxc_compiler, enum shader_type type, unsigned int compile_options,
|
|
|
|
const char *hlsl, ID3D10Blob **blob_out, ID3D10Blob **errors_out)
|
|
|
|
{
|
|
|
|
DxcBuffer src_buf = {hlsl, strlen(hlsl), 65001};
|
|
|
|
IDxcCompiler3 *compiler = dxc_compiler;
|
|
|
|
HRESULT hr, compile_hr;
|
|
|
|
IDxcBlobUtf8 *errors;
|
|
|
|
IDxcResult *result;
|
|
|
|
size_t arg_count;
|
|
|
|
IDxcBlob *blob;
|
|
|
|
|
|
|
|
static const WCHAR *const shader_profiles[] =
|
|
|
|
{
|
|
|
|
[SHADER_TYPE_CS] = L"cs_6_0",
|
|
|
|
[SHADER_TYPE_PS] = L"ps_6_0",
|
|
|
|
[SHADER_TYPE_VS] = L"vs_6_0",
|
|
|
|
};
|
|
|
|
const WCHAR *args[] =
|
|
|
|
{
|
|
|
|
L"/T",
|
|
|
|
shader_profiles[type],
|
|
|
|
L"/Qstrip_reflect",
|
|
|
|
L"/Qstrip_debug",
|
|
|
|
L"/flegacy-macro-expansion",
|
|
|
|
L"/flegacy-resource-reservation",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
*blob_out = NULL;
|
|
|
|
*errors_out = NULL;
|
|
|
|
|
|
|
|
arg_count = ARRAY_SIZE(args) - 3;
|
|
|
|
if (compile_options & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR)
|
|
|
|
args[arg_count++] = L"/Zpr";
|
|
|
|
if (compile_options & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR)
|
|
|
|
args[arg_count++] = L"/Zpc";
|
|
|
|
if (compile_options & D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY)
|
|
|
|
args[arg_count++] = L"/Gec";
|
|
|
|
|
|
|
|
if (FAILED(hr = IDxcCompiler3_Compile(compiler, &src_buf, args, arg_count, NULL, &IID_IDxcResult, (void **)&result)))
|
|
|
|
{
|
|
|
|
trace("Failed to compile shader, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IDxcResult_HasOutput(result, DXC_OUT_ERRORS)
|
|
|
|
&& SUCCEEDED(hr = IDxcResult_GetOutput(result, DXC_OUT_ERRORS, &IID_IDxcBlobUtf8, (void **)&errors, NULL)))
|
|
|
|
{
|
|
|
|
if (IDxcBlobUtf8_GetStringLength(errors))
|
|
|
|
d3d10_blob_from_dxc_blob_utf8(errors, errors_out);
|
|
|
|
IDxcBlobUtf8_Release(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = IDxcResult_GetStatus(result, &compile_hr)) || FAILED((hr = compile_hr)))
|
|
|
|
{
|
|
|
|
if (hr == DXC_E_LLVM_CAST_ERROR)
|
|
|
|
hr = E_FAIL;
|
|
|
|
goto result_release;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = IDxcResult_GetOutput(result, DXC_OUT_OBJECT, &IID_IDxcBlob, (void **)&blob, NULL)))
|
|
|
|
goto result_release;
|
|
|
|
|
|
|
|
IDxcResult_Release(result);
|
|
|
|
|
|
|
|
hr = d3d10_blob_from_dxc_blob(blob, blob_out);
|
|
|
|
IDxcBlob_Release(blob);
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
result_release:
|
|
|
|
IDxcResult_Release(result);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void compile_shader(struct shader_runner *runner, IDxcCompiler3 *dxc_compiler, const char *source, size_t len,
|
|
|
|
enum shader_type type, HRESULT expect)
|
2022-10-30 15:21:12 -07:00
|
|
|
{
|
2023-09-14 02:29:24 -07:00
|
|
|
bool use_dxcompiler = runner->minimum_shader_model >= SHADER_MODEL_6_0;
|
2022-10-30 15:21:12 -07:00
|
|
|
ID3D10Blob *blob = NULL, *errors = NULL;
|
|
|
|
char profile[7];
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
static const char *const shader_models[] =
|
|
|
|
{
|
2023-11-15 12:41:33 -08:00
|
|
|
[SHADER_MODEL_2_0] = "2_0",
|
|
|
|
[SHADER_MODEL_3_0] = "3_0",
|
2022-10-30 15:21:12 -07:00
|
|
|
[SHADER_MODEL_4_0] = "4_0",
|
|
|
|
[SHADER_MODEL_4_1] = "4_1",
|
|
|
|
[SHADER_MODEL_5_0] = "5_0",
|
|
|
|
[SHADER_MODEL_5_1] = "5_1",
|
2023-09-14 02:29:24 -07:00
|
|
|
[SHADER_MODEL_6_0] = "6_0",
|
2022-10-30 15:21:12 -07:00
|
|
|
};
|
|
|
|
|
2023-10-12 03:51:19 -07:00
|
|
|
static const char *const effect_models[] =
|
|
|
|
{
|
|
|
|
[SHADER_MODEL_2_0] = "2_0",
|
|
|
|
[SHADER_MODEL_4_0] = "4_0",
|
|
|
|
[SHADER_MODEL_4_1] = "4_1",
|
|
|
|
[SHADER_MODEL_5_0] = "5_0",
|
|
|
|
};
|
|
|
|
|
2023-09-14 02:29:24 -07:00
|
|
|
if (use_dxcompiler)
|
|
|
|
{
|
|
|
|
assert(dxc_compiler);
|
|
|
|
hr = dxc_compiler_compile_shader(dxc_compiler, type, runner->compile_options, source, &blob, &errors);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-12 03:51:19 -07:00
|
|
|
if (type == SHADER_TYPE_FX)
|
|
|
|
sprintf(profile, "%s_%s", shader_type_string(type), effect_models[runner->minimum_shader_model]);
|
|
|
|
else
|
|
|
|
sprintf(profile, "%s_%s", shader_type_string(type), shader_models[runner->minimum_shader_model]);
|
2023-09-14 02:29:24 -07:00
|
|
|
hr = D3DCompile(source, len, NULL, NULL, NULL, "main", profile, runner->compile_options, 0, &blob, &errors);
|
|
|
|
}
|
2023-11-15 12:41:33 -08:00
|
|
|
hr = map_special_hrs(hr);
|
2023-01-16 14:08:01 -08:00
|
|
|
ok(hr == expect, "Got unexpected hr %#x.\n", hr);
|
2022-10-30 15:21:12 -07:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
ID3D10Blob_Release(blob);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert_that(!blob, "Expected no compiled shader blob.\n");
|
|
|
|
assert_that(!!errors, "Expected non-NULL error blob.\n");
|
|
|
|
}
|
|
|
|
if (errors)
|
|
|
|
{
|
|
|
|
if (vkd3d_test_state.debug_level)
|
|
|
|
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
|
|
|
ID3D10Blob_Release(errors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-10 13:37:40 -08:00
|
|
|
static enum parse_state get_parse_state_todo(enum parse_state state)
|
|
|
|
{
|
|
|
|
if (state == STATE_SHADER_COMPUTE)
|
|
|
|
return STATE_SHADER_COMPUTE_TODO;
|
|
|
|
else if (state == STATE_SHADER_PIXEL)
|
|
|
|
return STATE_SHADER_PIXEL_TODO;
|
|
|
|
else if (state == STATE_SHADER_VERTEX)
|
|
|
|
return STATE_SHADER_VERTEX_TODO;
|
|
|
|
else
|
|
|
|
return STATE_SHADER_EFFECT_TODO;
|
|
|
|
}
|
|
|
|
|
2023-09-14 02:18:58 -07:00
|
|
|
static enum parse_state read_shader_directive(struct shader_runner *runner, enum parse_state state, const char *line,
|
|
|
|
const char *src, HRESULT *expect_hr)
|
|
|
|
{
|
|
|
|
while (*src && *src != ']')
|
|
|
|
{
|
2023-11-10 13:37:40 -08:00
|
|
|
const char *src_start = src;
|
|
|
|
|
|
|
|
if (match_directive_substring_with_args(src, "todo", &src, runner->minimum_shader_model))
|
2023-09-14 02:18:58 -07:00
|
|
|
{
|
2023-11-10 13:37:40 -08:00
|
|
|
/* 'todo' is not meaningful when dxcompiler is in use. */
|
2023-09-14 02:29:24 -07:00
|
|
|
if (runner->minimum_shader_model >= SHADER_MODEL_6_0)
|
|
|
|
continue;
|
2023-11-10 13:37:40 -08:00
|
|
|
state = get_parse_state_todo(state);
|
2023-09-14 02:18:58 -07:00
|
|
|
}
|
2023-11-10 13:37:40 -08:00
|
|
|
else if (match_directive_substring_with_args(src, "fail", &src, runner->minimum_shader_model))
|
2023-09-14 02:18:58 -07:00
|
|
|
{
|
|
|
|
*expect_hr = E_FAIL;
|
|
|
|
}
|
2023-11-10 13:37:40 -08:00
|
|
|
else if (match_directive_substring_with_args(src, "notimpl", &src, runner->minimum_shader_model))
|
2023-09-14 02:29:24 -07:00
|
|
|
{
|
2023-11-10 13:37:40 -08:00
|
|
|
*expect_hr = E_NOTIMPL;
|
2023-09-14 02:18:58 -07:00
|
|
|
}
|
2023-11-10 13:37:40 -08:00
|
|
|
|
|
|
|
if (src == src_start)
|
2023-09-14 02:18:58 -07:00
|
|
|
{
|
|
|
|
fatal_error("Malformed line '%s'.\n", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(src, "]\n"))
|
|
|
|
fatal_error("Malformed line '%s'.\n", line);
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2024-02-19 07:47:11 -08:00
|
|
|
static bool check_requirements(const struct shader_runner *runner, const struct shader_runner_caps *caps)
|
|
|
|
{
|
|
|
|
if (runner->maximum_shader_model < runner->minimum_shader_model)
|
|
|
|
return false;
|
|
|
|
if (runner->require_float64 && !caps->float64)
|
|
|
|
return false;
|
|
|
|
if (runner->require_int64 && !caps->int64)
|
|
|
|
return false;
|
|
|
|
if (runner->require_rov && !caps->rov)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void run_shader_tests(struct shader_runner *runner, const struct shader_runner_caps *caps,
|
|
|
|
const struct shader_runner_ops *ops, void *dxc_compiler)
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
|
|
|
size_t shader_source_size = 0, shader_source_len = 0;
|
2022-03-21 18:42:17 -07:00
|
|
|
struct resource_params current_resource;
|
2021-11-05 11:35:49 -07:00
|
|
|
struct sampler *current_sampler = NULL;
|
2020-09-30 19:01:18 -07:00
|
|
|
enum parse_state state = STATE_NONE;
|
2020-10-03 14:24:26 -07:00
|
|
|
unsigned int i, line_number = 0;
|
2020-09-30 19:01:18 -07:00
|
|
|
char *shader_source = NULL;
|
2023-01-16 14:08:01 -08:00
|
|
|
HRESULT expect_hr = S_OK;
|
2023-09-20 18:54:27 -07:00
|
|
|
bool skip_tests = false;
|
2023-09-14 02:18:58 -07:00
|
|
|
char line_buffer[256];
|
2023-12-07 08:26:34 -08:00
|
|
|
const char *testname;
|
2020-09-30 19:01:18 -07:00
|
|
|
FILE *f;
|
|
|
|
|
2024-02-19 08:01:00 -08:00
|
|
|
trace("Compiling SM%s-SM%s shaders with %s and executing with %s.\n",
|
|
|
|
model_strings[caps->minimum_shader_model], model_strings[caps->maximum_shader_model],
|
|
|
|
dxc_compiler ? "dxcompiler" : HLSL_COMPILER, caps->runner);
|
2024-02-19 07:57:32 -08:00
|
|
|
trace(" float64: %u.\n", caps->float64);
|
|
|
|
trace(" int64: %u.\n", caps->int64);
|
|
|
|
trace(" rov: %u.\n", caps->rov);
|
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
if (!test_options.filename)
|
|
|
|
fatal_error("No filename specified.\n");
|
2020-09-30 19:01:18 -07:00
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
if (!(f = fopen(test_options.filename, "r")))
|
|
|
|
fatal_error("Unable to open '%s' for reading: %s\n", test_options.filename, strerror(errno));
|
2020-09-30 19:01:18 -07:00
|
|
|
|
2022-03-19 10:35:31 -07:00
|
|
|
memset(runner, 0, sizeof(*runner));
|
|
|
|
runner->ops = ops;
|
2024-02-19 07:47:11 -08:00
|
|
|
runner->minimum_shader_model = caps->minimum_shader_model;
|
|
|
|
runner->maximum_shader_model = caps->maximum_shader_model;
|
2020-09-30 19:01:18 -07:00
|
|
|
|
2023-12-07 08:26:34 -08:00
|
|
|
if ((testname = strrchr(test_options.filename, '/')))
|
|
|
|
++testname;
|
|
|
|
else
|
|
|
|
testname = test_options.filename;
|
|
|
|
|
2020-10-03 14:24:26 -07:00
|
|
|
for (;;)
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
2023-09-14 02:18:58 -07:00
|
|
|
char *ret = fgets(line_buffer, sizeof(line_buffer), f);
|
|
|
|
const char *line = line_buffer;
|
2020-09-30 19:01:22 -07:00
|
|
|
|
2023-12-07 08:26:34 -08:00
|
|
|
if (line_number++)
|
|
|
|
vkd3d_test_pop_context();
|
|
|
|
vkd3d_test_push_context("%s:%u", testname, line_number);
|
2020-10-03 14:24:26 -07:00
|
|
|
|
|
|
|
if (!ret || line[0] == '[')
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
2022-03-21 18:42:16 -07:00
|
|
|
case STATE_INPUT_LAYOUT:
|
2020-09-30 19:01:18 -07:00
|
|
|
case STATE_NONE:
|
2021-11-05 11:35:49 -07:00
|
|
|
case STATE_SAMPLER:
|
2020-09-30 19:01:18 -07:00
|
|
|
case STATE_TEST:
|
2022-01-26 17:40:29 -08:00
|
|
|
break;
|
|
|
|
|
2022-04-07 16:58:14 -07:00
|
|
|
case STATE_REQUIRE:
|
2024-02-19 07:47:11 -08:00
|
|
|
if (!check_requirements(runner, caps))
|
2023-09-20 18:54:27 -07:00
|
|
|
skip_tests = true;
|
2022-04-07 16:58:14 -07:00
|
|
|
break;
|
|
|
|
|
2022-06-08 16:18:35 -07:00
|
|
|
case STATE_RESOURCE:
|
2023-10-17 03:01:01 -07:00
|
|
|
/* Not every backend supports every resource type
|
|
|
|
* (specifically, D3D9 doesn't support UAVs and
|
|
|
|
* textures with data type other than float). */
|
|
|
|
if (!skip_tests)
|
|
|
|
{
|
|
|
|
set_resource(runner, runner->ops->create_resource(runner, ¤t_resource));
|
|
|
|
}
|
2022-03-21 18:42:17 -07:00
|
|
|
free(current_resource.data);
|
2020-09-30 19:01:18 -07:00
|
|
|
break;
|
|
|
|
|
2021-08-13 14:37:31 -07:00
|
|
|
case STATE_SHADER_COMPUTE:
|
2022-10-30 15:21:12 -07:00
|
|
|
case STATE_SHADER_COMPUTE_TODO:
|
2023-09-20 18:54:27 -07:00
|
|
|
if (!skip_tests)
|
|
|
|
{
|
|
|
|
todo_if (state == STATE_SHADER_COMPUTE_TODO)
|
2023-09-14 02:29:24 -07:00
|
|
|
compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_CS,
|
|
|
|
expect_hr);
|
2023-09-20 18:54:27 -07:00
|
|
|
}
|
2021-08-13 14:37:31 -07:00
|
|
|
free(runner->cs_source);
|
|
|
|
runner->cs_source = shader_source;
|
|
|
|
shader_source = NULL;
|
|
|
|
shader_source_len = 0;
|
|
|
|
shader_source_size = 0;
|
|
|
|
break;
|
|
|
|
|
2020-09-30 19:01:18 -07:00
|
|
|
case STATE_SHADER_PIXEL:
|
2022-10-30 15:21:12 -07:00
|
|
|
case STATE_SHADER_PIXEL_TODO:
|
2023-09-20 18:54:27 -07:00
|
|
|
if (!skip_tests)
|
|
|
|
{
|
|
|
|
todo_if (state == STATE_SHADER_PIXEL_TODO)
|
2023-09-14 02:29:24 -07:00
|
|
|
compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_PS,
|
|
|
|
expect_hr);
|
2023-09-20 18:54:27 -07:00
|
|
|
}
|
2022-03-19 10:35:31 -07:00
|
|
|
free(runner->ps_source);
|
|
|
|
runner->ps_source = shader_source;
|
2022-01-26 17:40:31 -08:00
|
|
|
shader_source = NULL;
|
2020-09-30 19:01:18 -07:00
|
|
|
shader_source_len = 0;
|
2022-01-26 17:40:31 -08:00
|
|
|
shader_source_size = 0;
|
2020-09-30 19:01:18 -07:00
|
|
|
break;
|
2020-10-03 14:24:26 -07:00
|
|
|
|
2022-03-21 18:42:14 -07:00
|
|
|
case STATE_SHADER_VERTEX:
|
2023-04-04 16:23:26 -07:00
|
|
|
case STATE_SHADER_VERTEX_TODO:
|
2023-09-20 18:54:27 -07:00
|
|
|
if (!skip_tests)
|
|
|
|
{
|
|
|
|
todo_if (state == STATE_SHADER_VERTEX_TODO)
|
2023-09-14 02:29:24 -07:00
|
|
|
compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_VS,
|
|
|
|
expect_hr);
|
2023-09-20 18:54:27 -07:00
|
|
|
}
|
2022-03-21 18:42:14 -07:00
|
|
|
free(runner->vs_source);
|
|
|
|
runner->vs_source = shader_source;
|
|
|
|
shader_source = NULL;
|
|
|
|
shader_source_len = 0;
|
|
|
|
shader_source_size = 0;
|
|
|
|
break;
|
|
|
|
|
2023-10-12 03:51:19 -07:00
|
|
|
case STATE_SHADER_EFFECT:
|
|
|
|
case STATE_SHADER_EFFECT_TODO:
|
|
|
|
if (!skip_tests)
|
|
|
|
{
|
|
|
|
todo_if (state == STATE_SHADER_EFFECT_TODO)
|
|
|
|
compile_shader(runner, dxc_compiler, shader_source, shader_source_len, SHADER_TYPE_FX,
|
|
|
|
expect_hr);
|
|
|
|
}
|
|
|
|
free(runner->fx_source);
|
|
|
|
runner->fx_source = shader_source;
|
|
|
|
shader_source = NULL;
|
|
|
|
shader_source_len = 0;
|
|
|
|
shader_source_size = 0;
|
|
|
|
break;
|
|
|
|
|
2020-11-23 22:29:57 -08:00
|
|
|
case STATE_PREPROC_INVALID:
|
|
|
|
{
|
|
|
|
ID3D10Blob *blob = NULL, *errors = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2023-09-20 18:54:27 -07:00
|
|
|
if (skip_tests)
|
|
|
|
break;
|
|
|
|
|
2020-11-23 22:29:57 -08:00
|
|
|
hr = D3DPreprocess(shader_source, strlen(shader_source), NULL, NULL, NULL, &blob, &errors);
|
|
|
|
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
|
|
|
|
ok(!blob, "Expected no compiled shader blob.\n");
|
|
|
|
ok(!!errors, "Expected non-NULL error blob.\n");
|
|
|
|
|
|
|
|
if (errors)
|
|
|
|
{
|
|
|
|
if (vkd3d_test_state.debug_level)
|
|
|
|
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
|
|
|
ID3D10Blob_Release(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
shader_source_len = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-21 15:23:45 -08:00
|
|
|
case STATE_PREPROC:
|
|
|
|
{
|
|
|
|
ID3D10Blob *blob = NULL, *errors = NULL;
|
2020-12-01 18:51:08 -08:00
|
|
|
SIZE_T size;
|
2020-11-21 15:23:45 -08:00
|
|
|
HRESULT hr;
|
|
|
|
char *text;
|
|
|
|
|
2023-09-20 18:54:27 -07:00
|
|
|
if (skip_tests)
|
|
|
|
break;
|
|
|
|
|
2020-11-21 15:23:45 -08:00
|
|
|
hr = D3DPreprocess(shader_source, strlen(shader_source), NULL, NULL, NULL, &blob, &errors);
|
|
|
|
ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
if (errors)
|
|
|
|
{
|
|
|
|
if (vkd3d_test_state.debug_level)
|
|
|
|
trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
|
|
|
|
ID3D10Blob_Release(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
text = ID3D10Blob_GetBufferPointer(blob);
|
2020-12-01 18:51:08 -08:00
|
|
|
size = ID3D10Blob_GetBufferSize(blob);
|
|
|
|
ok(vkd3d_memmem(text, size, "pass", strlen("pass")),
|
|
|
|
"'pass' not found in preprocessed shader.\n");
|
|
|
|
ok(!vkd3d_memmem(text, size, "fail", strlen("fail")),
|
|
|
|
"'fail' found in preprocessed shader.\n");
|
2020-11-21 15:23:45 -08:00
|
|
|
ID3D10Blob_Release(blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
shader_source_len = 0;
|
|
|
|
break;
|
|
|
|
}
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
2023-04-17 05:53:24 -07:00
|
|
|
|
2023-04-12 09:34:42 -07:00
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
}
|
2020-09-30 19:01:18 -07:00
|
|
|
|
2020-10-03 14:24:26 -07:00
|
|
|
if (line[0] == '[')
|
|
|
|
{
|
2021-10-03 17:19:08 -07:00
|
|
|
unsigned int index;
|
|
|
|
|
2023-09-14 02:18:58 -07:00
|
|
|
if (match_directive_substring(line, "[compute shader", &line))
|
2021-08-13 14:37:31 -07:00
|
|
|
{
|
|
|
|
state = STATE_SHADER_COMPUTE;
|
2023-01-16 14:08:01 -08:00
|
|
|
expect_hr = S_OK;
|
2023-09-14 02:18:58 -07:00
|
|
|
state = read_shader_directive(runner, state, line_buffer, line, &expect_hr);
|
2021-08-16 10:25:41 -07:00
|
|
|
}
|
2021-08-13 14:37:31 -07:00
|
|
|
else if (!strcmp(line, "[require]\n"))
|
2022-01-26 06:35:33 -08:00
|
|
|
{
|
|
|
|
state = STATE_REQUIRE;
|
2024-02-19 07:47:11 -08:00
|
|
|
runner->minimum_shader_model = caps->minimum_shader_model;
|
|
|
|
runner->maximum_shader_model = caps->maximum_shader_model;
|
2023-12-12 06:27:41 -08:00
|
|
|
runner->require_float64 = false;
|
2023-11-22 19:17:54 -08:00
|
|
|
runner->require_int64 = false;
|
2023-10-13 14:35:12 -07:00
|
|
|
runner->require_rov = false;
|
2023-09-20 18:54:27 -07:00
|
|
|
runner->compile_options = 0;
|
|
|
|
skip_tests = false;
|
2022-01-26 06:35:33 -08:00
|
|
|
}
|
2023-09-14 02:18:58 -07:00
|
|
|
else if (match_directive_substring(line, "[pixel shader", &line))
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2020-09-30 19:01:18 -07:00
|
|
|
state = STATE_SHADER_PIXEL;
|
2023-01-16 14:08:01 -08:00
|
|
|
expect_hr = S_OK;
|
2023-09-14 02:18:58 -07:00
|
|
|
state = read_shader_directive(runner, state, line_buffer, line, &expect_hr);
|
2021-09-11 09:20:32 -07:00
|
|
|
}
|
2021-11-05 11:35:49 -07:00
|
|
|
else if (sscanf(line, "[sampler %u]\n", &index))
|
|
|
|
{
|
|
|
|
state = STATE_SAMPLER;
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
if (!(current_sampler = shader_runner_get_sampler(runner, index)))
|
2021-11-05 11:35:49 -07:00
|
|
|
{
|
2022-04-11 10:18:30 -07:00
|
|
|
if (runner->sampler_count == MAX_SAMPLERS)
|
|
|
|
fatal_error("Too many samplers declared.\n");
|
|
|
|
|
|
|
|
current_sampler = &runner->samplers[runner->sampler_count++];
|
2021-11-05 11:35:49 -07:00
|
|
|
}
|
2022-04-11 10:18:30 -07:00
|
|
|
memset(current_sampler, 0, sizeof(*current_sampler));
|
2021-11-05 11:35:49 -07:00
|
|
|
current_sampler->slot = index;
|
|
|
|
current_sampler->filter = D3D12_FILTER_MIN_MAG_MIP_POINT;
|
|
|
|
current_sampler->u_address = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
|
|
|
current_sampler->v_address = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
|
|
|
current_sampler->w_address = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
|
|
|
|
}
|
2024-01-24 11:11:17 -08:00
|
|
|
else if (sscanf(line, "[rtv %u]\n", &index))
|
2022-06-08 16:18:39 -07:00
|
|
|
{
|
|
|
|
state = STATE_RESOURCE;
|
|
|
|
|
|
|
|
memset(¤t_resource, 0, sizeof(current_resource));
|
|
|
|
|
|
|
|
current_resource.slot = index;
|
|
|
|
current_resource.type = RESOURCE_TYPE_RENDER_TARGET;
|
|
|
|
current_resource.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
|
|
|
current_resource.data_type = TEXTURE_DATA_FLOAT;
|
|
|
|
current_resource.texel_size = 16;
|
2023-04-30 17:23:00 -07:00
|
|
|
current_resource.level_count = 1;
|
2022-06-08 16:18:39 -07:00
|
|
|
}
|
2024-01-24 11:11:17 -08:00
|
|
|
else if (sscanf(line, "[srv %u]\n", &index))
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2022-06-08 16:18:35 -07:00
|
|
|
state = STATE_RESOURCE;
|
2021-10-03 17:19:08 -07:00
|
|
|
|
2022-03-21 18:42:17 -07:00
|
|
|
memset(¤t_resource, 0, sizeof(current_resource));
|
2022-01-26 17:40:29 -08:00
|
|
|
|
2022-03-21 18:42:17 -07:00
|
|
|
current_resource.slot = index;
|
|
|
|
current_resource.type = RESOURCE_TYPE_TEXTURE;
|
|
|
|
current_resource.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
|
|
|
current_resource.data_type = TEXTURE_DATA_FLOAT;
|
|
|
|
current_resource.texel_size = 16;
|
2023-04-30 17:23:00 -07:00
|
|
|
current_resource.level_count = 1;
|
2021-10-03 17:19:08 -07:00
|
|
|
}
|
2022-06-08 16:18:35 -07:00
|
|
|
else if (sscanf(line, "[uav %u]\n", &index))
|
|
|
|
{
|
|
|
|
state = STATE_RESOURCE;
|
|
|
|
|
|
|
|
memset(¤t_resource, 0, sizeof(current_resource));
|
|
|
|
|
|
|
|
current_resource.slot = index;
|
|
|
|
current_resource.type = RESOURCE_TYPE_UAV;
|
2023-05-09 10:56:55 -07:00
|
|
|
current_resource.format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
|
|
|
current_resource.data_type = TEXTURE_DATA_FLOAT;
|
|
|
|
current_resource.texel_size = 16;
|
|
|
|
current_resource.level_count = 1;
|
|
|
|
}
|
2024-01-24 11:11:17 -08:00
|
|
|
else if (sscanf(line, "[vb %u]\n", &index))
|
2022-03-21 18:42:18 -07:00
|
|
|
{
|
2022-06-08 16:18:35 -07:00
|
|
|
state = STATE_RESOURCE;
|
2022-03-21 18:42:18 -07:00
|
|
|
|
|
|
|
memset(¤t_resource, 0, sizeof(current_resource));
|
|
|
|
|
|
|
|
current_resource.slot = index;
|
|
|
|
current_resource.type = RESOURCE_TYPE_VERTEX_BUFFER;
|
2024-01-22 15:20:18 -08:00
|
|
|
current_resource.dimension = RESOURCE_DIMENSION_BUFFER;
|
2022-03-21 18:42:18 -07:00
|
|
|
current_resource.data_type = TEXTURE_DATA_FLOAT;
|
|
|
|
}
|
2020-09-30 19:01:18 -07:00
|
|
|
else if (!strcmp(line, "[test]\n"))
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2020-09-30 19:01:18 -07:00
|
|
|
state = STATE_TEST;
|
2021-10-03 17:19:08 -07:00
|
|
|
}
|
2020-11-21 15:23:45 -08:00
|
|
|
else if (!strcmp(line, "[preproc]\n"))
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2020-11-21 15:23:45 -08:00
|
|
|
state = STATE_PREPROC;
|
2021-10-03 17:19:08 -07:00
|
|
|
}
|
2020-11-23 22:29:57 -08:00
|
|
|
else if (!strcmp(line, "[preproc fail]\n"))
|
2021-10-03 17:19:08 -07:00
|
|
|
{
|
2020-11-23 22:29:57 -08:00
|
|
|
state = STATE_PREPROC_INVALID;
|
2021-10-03 17:19:08 -07:00
|
|
|
}
|
2023-09-14 02:18:58 -07:00
|
|
|
else if (match_directive_substring(line, "[vertex shader", &line))
|
2022-03-21 18:42:14 -07:00
|
|
|
{
|
|
|
|
state = STATE_SHADER_VERTEX;
|
2023-04-04 15:59:43 -07:00
|
|
|
expect_hr = S_OK;
|
2023-09-14 02:18:58 -07:00
|
|
|
state = read_shader_directive(runner, state, line_buffer, line, &expect_hr);
|
2023-04-04 16:23:26 -07:00
|
|
|
}
|
2023-10-12 03:51:19 -07:00
|
|
|
else if (match_directive_substring(line, "[effect", &line))
|
|
|
|
{
|
|
|
|
state = STATE_SHADER_EFFECT;
|
|
|
|
expect_hr = S_OK;
|
|
|
|
state = read_shader_directive(runner, state, line_buffer, line, &expect_hr);
|
|
|
|
}
|
2022-03-21 18:42:16 -07:00
|
|
|
else if (!strcmp(line, "[input layout]\n"))
|
|
|
|
{
|
|
|
|
state = STATE_INPUT_LAYOUT;
|
|
|
|
|
|
|
|
for (i = 0; i < runner->input_element_count; ++i)
|
|
|
|
free(runner->input_elements[i].name);
|
|
|
|
runner->input_element_count = 0;
|
|
|
|
}
|
2020-09-30 19:01:18 -07:00
|
|
|
}
|
2021-10-03 17:19:07 -07:00
|
|
|
else if (line[0] != '%' && line[0] != '\n')
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case STATE_NONE:
|
2021-11-05 11:35:50 -07:00
|
|
|
fatal_error("Malformed line '%s'.\n", line);
|
2020-09-30 19:01:18 -07:00
|
|
|
break;
|
|
|
|
|
2022-03-21 18:42:16 -07:00
|
|
|
case STATE_INPUT_LAYOUT:
|
|
|
|
parse_input_layout_directive(runner, line);
|
|
|
|
break;
|
|
|
|
|
2020-11-21 15:23:45 -08:00
|
|
|
case STATE_PREPROC:
|
2020-11-23 22:29:57 -08:00
|
|
|
case STATE_PREPROC_INVALID:
|
2021-08-13 14:37:31 -07:00
|
|
|
case STATE_SHADER_COMPUTE:
|
2022-10-30 15:21:12 -07:00
|
|
|
case STATE_SHADER_COMPUTE_TODO:
|
2020-09-30 19:01:18 -07:00
|
|
|
case STATE_SHADER_PIXEL:
|
2022-10-30 15:21:12 -07:00
|
|
|
case STATE_SHADER_PIXEL_TODO:
|
2022-03-21 18:42:14 -07:00
|
|
|
case STATE_SHADER_VERTEX:
|
2023-04-04 16:23:26 -07:00
|
|
|
case STATE_SHADER_VERTEX_TODO:
|
2023-10-12 03:51:19 -07:00
|
|
|
case STATE_SHADER_EFFECT:
|
|
|
|
case STATE_SHADER_EFFECT_TODO:
|
2020-09-30 19:01:18 -07:00
|
|
|
{
|
|
|
|
size_t len = strlen(line);
|
|
|
|
|
|
|
|
vkd3d_array_reserve((void **)&shader_source, &shader_source_size, shader_source_len + len + 1, 1);
|
|
|
|
memcpy(shader_source + shader_source_len, line, len + 1);
|
|
|
|
shader_source_len += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-26 06:35:33 -08:00
|
|
|
case STATE_REQUIRE:
|
2022-03-19 10:35:31 -07:00
|
|
|
parse_require_directive(runner, line);
|
2022-01-26 06:35:33 -08:00
|
|
|
break;
|
|
|
|
|
2022-06-08 16:18:35 -07:00
|
|
|
case STATE_RESOURCE:
|
|
|
|
parse_resource_directive(¤t_resource, line);
|
2021-11-05 11:35:49 -07:00
|
|
|
break;
|
|
|
|
|
2022-06-08 16:18:35 -07:00
|
|
|
case STATE_SAMPLER:
|
|
|
|
parse_sampler_directive(current_sampler, line);
|
2021-10-03 17:19:08 -07:00
|
|
|
break;
|
|
|
|
|
2020-09-30 19:01:18 -07:00
|
|
|
case STATE_TEST:
|
2023-09-14 02:29:24 -07:00
|
|
|
/* Compilation which fails with dxcompiler is not 'todo', therefore the tests are
|
|
|
|
* not 'todo' either. They cannot run, so skip them entirely. */
|
|
|
|
if (!skip_tests && SUCCEEDED(expect_hr))
|
2023-09-20 18:54:27 -07:00
|
|
|
parse_test_directive(runner, line);
|
2020-09-30 19:01:18 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-07 08:26:34 -08:00
|
|
|
if (line_number)
|
|
|
|
vkd3d_test_pop_context();
|
|
|
|
|
2022-03-21 18:42:16 -07:00
|
|
|
for (i = 0; i < runner->input_element_count; ++i)
|
|
|
|
free(runner->input_elements[i].name);
|
|
|
|
free(runner->input_elements);
|
2022-03-21 18:42:14 -07:00
|
|
|
free(runner->vs_source);
|
2022-03-19 10:35:31 -07:00
|
|
|
free(runner->ps_source);
|
2024-01-24 15:21:49 -08:00
|
|
|
free(runner->cs_source);
|
|
|
|
free(runner->fx_source);
|
2024-01-24 13:53:35 -08:00
|
|
|
free(runner->uniforms);
|
2022-03-21 18:42:17 -07:00
|
|
|
for (i = 0; i < runner->resource_count; ++i)
|
2022-01-26 17:40:29 -08:00
|
|
|
{
|
2022-03-21 18:42:17 -07:00
|
|
|
if (runner->resources[i])
|
|
|
|
runner->ops->destroy_resource(runner, runner->resources[i]);
|
2022-01-26 17:40:29 -08:00
|
|
|
}
|
2020-09-30 19:01:18 -07:00
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
2022-01-26 17:40:27 -08:00
|
|
|
|
2023-01-18 05:30:47 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
static void print_dll_version(const char *file_name)
|
|
|
|
{
|
|
|
|
BOOL (WINAPI *GetFileVersionInfoA)(const char *, DWORD, DWORD, void *);
|
|
|
|
BOOL (WINAPI *VerQueryValueA)(void *, char *, void **, UINT*);
|
|
|
|
DWORD (WINAPI *GetFileVersionInfoSizeA)(const char *, DWORD *);
|
|
|
|
HMODULE version_module;
|
|
|
|
DWORD size, handle;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
version_module = LoadLibraryA("version.dll");
|
|
|
|
if (!version_module)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
#define X(name) name = (void *)GetProcAddress(version_module, #name);
|
|
|
|
X(GetFileVersionInfoSizeA);
|
|
|
|
X(GetFileVersionInfoA);
|
|
|
|
X(VerQueryValueA);
|
|
|
|
#undef X
|
|
|
|
|
|
|
|
if (!GetFileVersionInfoSizeA || !GetFileVersionInfoA || !VerQueryValueA)
|
|
|
|
{
|
|
|
|
FreeLibrary(version_module);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = GetFileVersionInfoSizeA(file_name, &handle);
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
char *data = malloc(size);
|
|
|
|
|
|
|
|
if (GetFileVersionInfoA(file_name, handle, size, data))
|
|
|
|
{
|
|
|
|
VS_FIXEDFILEINFO *info;
|
|
|
|
UINT len;
|
|
|
|
|
|
|
|
if (VerQueryValueA(data, "\\", (void **)&info, &len))
|
|
|
|
{
|
|
|
|
trace("%s version: %lu.%lu.%lu.%lu\n", file_name,
|
|
|
|
info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
|
|
|
|
info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff);
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeLibrary(version_module);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (!done)
|
|
|
|
trace("%s version: unknown\n", file_name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-09-14 02:29:24 -07:00
|
|
|
#if defined(SONAME_LIBDXCOMPILER) && !defined(VKD3D_CROSSTEST)
|
2023-10-16 07:00:46 -07:00
|
|
|
static IDxcCompiler3 *dxcompiler_create(void)
|
2023-09-14 02:29:24 -07:00
|
|
|
{
|
|
|
|
DxcCreateInstanceProc create_instance;
|
|
|
|
IDxcCompiler3 *compiler;
|
|
|
|
HRESULT hr;
|
|
|
|
void *dll;
|
|
|
|
|
2023-10-02 05:08:44 -07:00
|
|
|
dll = vkd3d_dlopen(SONAME_LIBDXCOMPILER);
|
|
|
|
ok(dll, "Failed to load dxcompiler library, %s.\n", vkd3d_dlerror());
|
|
|
|
if (!dll)
|
2023-09-14 02:29:24 -07:00
|
|
|
return NULL;
|
|
|
|
|
2023-10-02 05:08:44 -07:00
|
|
|
create_instance = (DxcCreateInstanceProc)vkd3d_dlsym(dll, "DxcCreateInstance");
|
|
|
|
ok(create_instance, "Failed to get DxcCreateInstance() pointer.\n");
|
|
|
|
if (!create_instance)
|
2023-09-14 02:29:24 -07:00
|
|
|
return NULL;
|
|
|
|
|
2023-10-02 05:08:44 -07:00
|
|
|
hr = create_instance(&CLSID_DxcCompiler, &IID_IDxcCompiler3, (void **)&compiler);
|
|
|
|
ok(SUCCEEDED(hr), "Failed to create instance, hr %#x.\n", hr);
|
|
|
|
if (FAILED(hr))
|
2023-09-14 02:29:24 -07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return compiler;
|
|
|
|
}
|
|
|
|
#elif !defined(VKD3D_CROSSTEST)
|
2023-10-16 07:00:46 -07:00
|
|
|
static IDxcCompiler3 *dxcompiler_create(void)
|
2023-09-14 02:29:24 -07:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-26 17:40:27 -08:00
|
|
|
START_TEST(shader_runner)
|
|
|
|
{
|
2023-09-14 02:29:24 -07:00
|
|
|
#ifndef VKD3D_CROSSTEST
|
|
|
|
IDxcCompiler3 *dxc_compiler;
|
|
|
|
#endif
|
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
parse_args(argc, argv);
|
|
|
|
|
2023-01-18 05:30:47 -08:00
|
|
|
#if defined(VKD3D_CROSSTEST)
|
|
|
|
trace("Running tests from a Windows cross build\n");
|
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
run_shader_tests_d3d9();
|
2023-01-18 05:30:47 -08:00
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
run_shader_tests_d3d11();
|
2023-01-18 05:30:47 -08:00
|
|
|
|
2023-12-13 22:08:41 -08:00
|
|
|
run_shader_tests_d3d12(NULL);
|
2023-01-18 05:30:47 -08:00
|
|
|
|
|
|
|
print_dll_version("d3dcompiler_47.dll");
|
|
|
|
print_dll_version("dxgi.dll");
|
|
|
|
print_dll_version("d3d9.dll");
|
|
|
|
print_dll_version("d3d11.dll");
|
|
|
|
print_dll_version("d3d12.dll");
|
2023-12-13 22:08:41 -08:00
|
|
|
|
2023-01-18 05:30:47 -08:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
trace("Running tests from a Windows non-cross build\n");
|
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
run_shader_tests_d3d9();
|
2023-01-18 05:30:47 -08:00
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
run_shader_tests_d3d11();
|
2023-01-18 05:30:47 -08:00
|
|
|
|
2023-12-13 22:08:41 -08:00
|
|
|
dxc_compiler = dxcompiler_create();
|
|
|
|
run_shader_tests_d3d12(dxc_compiler);
|
2023-09-14 02:29:24 -07:00
|
|
|
|
2023-12-13 22:08:41 -08:00
|
|
|
if (dxc_compiler)
|
2023-09-14 02:29:24 -07:00
|
|
|
{
|
|
|
|
IDxcCompiler3_Release(dxc_compiler);
|
|
|
|
print_dll_version(SONAME_LIBDXCOMPILER);
|
|
|
|
}
|
2023-01-18 05:30:47 -08:00
|
|
|
print_dll_version("d3d9.dll");
|
|
|
|
print_dll_version("d3d11.dll");
|
2023-12-13 22:08:41 -08:00
|
|
|
|
2022-04-11 10:18:31 -07:00
|
|
|
#else
|
2023-01-18 05:30:47 -08:00
|
|
|
trace("Running tests from a Unix build\n");
|
|
|
|
|
2023-09-21 22:31:31 -07:00
|
|
|
# ifdef HAVE_OPENGL
|
|
|
|
run_shader_tests_gl();
|
|
|
|
# endif
|
|
|
|
|
2023-02-21 15:46:36 -08:00
|
|
|
run_shader_tests_vulkan();
|
2023-01-18 05:30:47 -08:00
|
|
|
|
2023-12-13 22:08:41 -08:00
|
|
|
dxc_compiler = dxcompiler_create();
|
|
|
|
run_shader_tests_d3d12(dxc_compiler);
|
2023-09-14 02:29:24 -07:00
|
|
|
|
2023-12-13 22:08:41 -08:00
|
|
|
if (dxc_compiler)
|
2023-09-14 02:29:24 -07:00
|
|
|
IDxcCompiler3_Release(dxc_compiler);
|
2023-12-13 22:08:41 -08:00
|
|
|
|
2023-01-18 05:30:47 -08:00
|
|
|
#endif
|
2022-01-26 17:40:27 -08:00
|
|
|
}
|