Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
-- v6: vkd3d-compiler: Add CLI option to specify default matrix packing order. tests: Add some tests for matrix packing compiler options. tests: Add test file syntax to specify compiler options. vkd3d-shader: Add compiler option to specify matrix majority.
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- include/vkd3d_shader.h | 17 +++++++++++++++++ libs/vkd3d-shader/hlsl.c | 21 ++++++++++++++++++--- libs/vkd3d-utils/vkd3d_utils_main.c | 15 +++++++++++++-- 3 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 8133d240..d6653d18 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -139,6 +139,14 @@ enum vkd3d_shader_compile_option_formatting_flags VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_FORMATTING_FLAGS), };
+enum vkd3d_shader_compile_option_pack_matrix_order +{ + VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR = 0x00000001, + VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR = 0x00000002, + + VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER), +}; + enum vkd3d_shader_compile_option_name { /** @@ -169,6 +177,15 @@ enum vkd3d_shader_compile_option_name * \since 1.7 */ VKD3D_SHADER_COMPILE_OPTION_WRITE_TESS_GEOM_POINT_SIZE = 0x00000006, + /** + * This option specifies default matrix packing order. It's only supported for HLSL source type. + * Explicit variable modifiers or pragmas will take precedence. + * + * \a value is a member of enum vkd3d_shader_compile_option_pack_matrix_order. + * + * \since 1.9 + */ + VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER = 0x00000007,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_NAME), }; diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 369af86b..290af22f 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3296,9 +3296,11 @@ static void declare_predefined_types(struct hlsl_ctx *ctx) } }
-static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const char *source_name, +static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compile_info *compile_info, const struct hlsl_profile_info *profile, struct vkd3d_shader_message_context *message_context) { + unsigned int i; + memset(ctx, 0, sizeof(*ctx));
ctx->profile = profile; @@ -3307,7 +3309,7 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const char *source_name,
if (!(ctx->source_files = hlsl_alloc(ctx, sizeof(*ctx->source_files)))) return false; - if (!(ctx->source_files[0] = hlsl_strdup(ctx, source_name ? source_name : "<anonymous>"))) + if (!(ctx->source_files[0] = hlsl_strdup(ctx, compile_info->source_name ? compile_info->source_name : "<anonymous>"))) { vkd3d_free(ctx->source_files); return false; @@ -3346,6 +3348,19 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const char *source_name, return false; ctx->cur_buffer = ctx->globals_buffer;
+ for (i = 0; i < compile_info->option_count; ++i) + { + const struct vkd3d_shader_compile_option *option = &compile_info->options[i]; + + if (option->name == VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER) + { + if (option->value == VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR) + ctx->matrix_majority = HLSL_MODIFIER_ROW_MAJOR; + else if (option->value == VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR) + ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR; + } + } + return true; }
@@ -3423,7 +3438,7 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d return VKD3D_ERROR_INVALID_ARGUMENT; }
- if (!hlsl_ctx_init(&ctx, compile_info->source_name, profile, message_context)) + if (!hlsl_ctx_init(&ctx, compile_info, profile, message_context)) return VKD3D_ERROR_OUT_OF_MEMORY;
if ((ret = hlsl_lexer_compile(&ctx, hlsl)) == 2) diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index 8a349ba8..7a13d6ca 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -158,7 +158,7 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen { struct vkd3d_shader_preprocess_info preprocess_info; struct vkd3d_shader_hlsl_source_info hlsl_info; - struct vkd3d_shader_compile_option options[2]; + struct vkd3d_shader_compile_option options[3]; struct vkd3d_shader_compile_info compile_info; struct vkd3d_shader_compile_option *option; struct vkd3d_shader_code byte_code; @@ -198,7 +198,7 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen debugstr_a(profile), flags, effect_flags, secondary_flags, secondary_data, secondary_data_size, shader_blob, messages_blob);
- if (flags & ~D3DCOMPILE_DEBUG) + if (flags & ~(D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR)) FIXME("Ignoring flags %#x.\n", flags); if (effect_flags) FIXME("Ignoring effect flags %#x.\n", effect_flags); @@ -262,6 +262,17 @@ HRESULT WINAPI D3DCompile2(const void *data, SIZE_T data_size, const char *filen option->value = true; }
+ if (flags & (D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR)) + { + option = &options[compile_info.option_count++]; + option->name = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER; + option->value = 0; + if (flags & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR) + option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR; + if (flags & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR) + option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR; + } + ret = vkd3d_shader_compile(&compile_info, &byte_code, &messages);
if (messages && messages_blob)
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- tests/shader_runner.c | 27 ++++++++++++++++++++++++--- tests/shader_runner.h | 2 ++ tests/shader_runner_d3d11.c | 13 ++++++------- tests/shader_runner_d3d12.c | 3 +-- tests/shader_runner_d3d9.c | 11 +++++------ tests/shader_runner_vulkan.c | 28 +++++++++++++++++++++++++++- 6 files changed, 65 insertions(+), 19 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 8a4b7138..126cf6ab 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -111,6 +111,8 @@ static bool match_string(const char *line, const char *token, const char **const
static void parse_require_directive(struct shader_runner *runner, const char *line) { + unsigned int i; + if (match_string(line, "shader model >=", &line)) { static const char *const model_strings[] = @@ -122,7 +124,6 @@ static void parse_require_directive(struct shader_runner *runner, const char *li [SHADER_MODEL_5_0] = "5.0", [SHADER_MODEL_5_1] = "5.1", }; - unsigned int i;
for (i = 0; i < ARRAY_SIZE(model_strings); ++i) { @@ -135,6 +136,27 @@ static void parse_require_directive(struct shader_runner *runner, const char *li
fatal_error("Unknown shader model '%s'.\n", line); } + 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" }, + }; + + 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; + } + } else { fatal_error("Unknown require directive '%s'.\n", line); @@ -751,9 +773,9 @@ static HRESULT map_unidentified_hrs(HRESULT hr)
static void compile_shader(struct shader_runner *runner, const char *source, size_t len, const char *type, HRESULT expect) { + UINT flags = runner->compile_options | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY; ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; - UINT flags = 0; HRESULT hr;
static const char *const shader_models[] = @@ -766,7 +788,6 @@ static void compile_shader(struct shader_runner *runner, const char *source, siz [SHADER_MODEL_5_1] = "5_1", };
- flags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY; sprintf(profile, "%s_%s", type, shader_models[runner->minimum_shader_model]); hr = D3DCompile(source, len, NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors); hr = map_unidentified_hrs(hr); diff --git a/tests/shader_runner.h b/tests/shader_runner.h index 7a2498f4..0844943d 100644 --- a/tests/shader_runner.h +++ b/tests/shader_runner.h @@ -123,6 +123,8 @@ struct shader_runner
struct input_element *input_elements; size_t input_element_count, input_element_capacity; + + unsigned int compile_options; };
struct shader_runner_ops diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c index a5e0b92b..788d8af4 100644 --- a/tests/shader_runner_d3d11.c +++ b/tests/shader_runner_d3d11.c @@ -72,11 +72,11 @@ static struct d3d11_shader_runner *d3d11_shader_runner(struct shader_runner *r) return CONTAINING_RECORD(r, struct d3d11_shader_runner, r); }
-static ID3D10Blob *compile_shader(const char *source, const char *type, enum shader_model shader_model) +static ID3D10Blob *compile_shader(const struct d3d11_shader_runner *runner, const char *source, const char *type) { + UINT flags = runner->r.compile_options | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY; ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; - UINT flags = 0; HRESULT hr;
static const char *const shader_models[] = @@ -89,8 +89,7 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha [SHADER_MODEL_5_1] = "5_1", };
- flags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY; - sprintf(profile, "%s_%s", type, shader_models[shader_model]); + sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]); hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors); ok(hr == S_OK, "Failed to compile shader, hr %#lx.\n", hr); if (errors) @@ -477,7 +476,7 @@ static bool d3d11_runner_dispatch(struct shader_runner *r, unsigned int x, unsig HRESULT hr; size_t i;
- if (!(cs_code = compile_shader(runner->r.cs_source, "cs", runner->r.minimum_shader_model))) + if (!(cs_code = compile_shader(runner, runner->r.cs_source, "cs"))) return false;
hr = ID3D11Device_CreateComputeShader(device, ID3D10Blob_GetBufferPointer(cs_code), @@ -550,10 +549,10 @@ static bool d3d11_runner_draw(struct shader_runner *r, unsigned int i; HRESULT hr;
- if (!(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model))) + if (!(vs_code = compile_shader(runner, runner->r.vs_source, "vs"))) return false;
- if (!(ps_code = compile_shader(runner->r.ps_source, "ps", runner->r.minimum_shader_model))) + if (!(ps_code = compile_shader(runner, runner->r.ps_source, "ps"))) { ID3D10Blob_Release(vs_code); return false; diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index d95851ba..daeb11e8 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -58,9 +58,9 @@ static struct d3d12_shader_runner *d3d12_shader_runner(struct shader_runner *r)
static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, const char *source, const char *type) { + UINT flags = runner->r.compile_options | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY; ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; - UINT flags = 0; HRESULT hr;
static const char *const shader_models[] = @@ -73,7 +73,6 @@ static ID3D10Blob *compile_shader(const struct d3d12_shader_runner *runner, cons [SHADER_MODEL_5_1] = "5_1", };
- flags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY; sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]); hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors); ok(FAILED(hr) == !blob, "Got unexpected hr %#x, blob %p.\n", hr, blob); diff --git a/tests/shader_runner_d3d9.c b/tests/shader_runner_d3d9.c index 4245c6e3..0c6d3788 100644 --- a/tests/shader_runner_d3d9.c +++ b/tests/shader_runner_d3d9.c @@ -56,11 +56,10 @@ static struct d3d9_shader_runner *d3d9_shader_runner(struct shader_runner *r)
static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT sdk_version);
-static ID3D10Blob *compile_shader(const char *source, const char *type, enum shader_model shader_model) +static ID3D10Blob *compile_shader(const struct d3d9_shader_runner *runner, const char *source, const char *type) { ID3D10Blob *blob = NULL, *errors = NULL; char profile[7]; - UINT flags = 0; HRESULT hr;
static const char *const shader_models[] = @@ -69,8 +68,8 @@ static ID3D10Blob *compile_shader(const char *source, const char *type, enum sha [SHADER_MODEL_3_0] = "3_0", };
- sprintf(profile, "%s_%s", type, shader_models[shader_model]); - hr = D3DCompile(source, strlen(source), NULL, NULL, NULL, "main", profile, flags, 0, &blob, &errors); + sprintf(profile, "%s_%s", 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) { @@ -335,10 +334,10 @@ static bool d3d9_runner_draw(struct shader_runner *r, unsigned int i, j; HRESULT hr;
- if (!(vs_code = compile_shader(runner->r.vs_source, "vs", runner->r.minimum_shader_model))) + if (!(vs_code = compile_shader(runner, runner->r.vs_source, "vs"))) return false;
- if (!(ps_code = compile_shader(runner->r.ps_source, "ps", runner->r.minimum_shader_model))) + if (!(ps_code = compile_shader(runner, runner->r.ps_source, "ps"))) { ID3D10Blob_Release(vs_code); return false; diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index ce9ac7e8..716b922c 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -26,6 +26,7 @@ #include "vulkan/vulkan.h" #include "vkd3d_shader.h" #include "vkd3d.h" +#include "vkd3d_d3dcompiler.h" #include "shader_runner.h" #include "vkd3d_test.h"
@@ -386,8 +387,9 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char struct vkd3d_shader_resource_binding bindings[MAX_RESOURCES + MAX_SAMPLERS]; struct vkd3d_shader_push_constant_buffer push_constants; struct vkd3d_shader_resource_binding *binding; + struct vkd3d_shader_compile_option options[1]; + unsigned int i, compile_options; char profile[7]; - unsigned int i; char *messages; int ret;
@@ -408,6 +410,30 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char info.target_type = VKD3D_SHADER_TARGET_DXBC_TPF; info.log_level = VKD3D_SHADER_LOG_WARNING;
+ info.options = options; + info.option_count = 0; + compile_options = runner->r.compile_options; + if (compile_options) + { + struct vkd3d_shader_compile_option *option; + + if (compile_options & (D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR)) + { + option = &options[info.option_count++]; + option->name = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER; + option->value = 0; + if (compile_options & D3DCOMPILE_PACK_MATRIX_ROW_MAJOR) + option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR; + if (compile_options & D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR) + option->value |= VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR; + + compile_options &= ~(D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR); + } + + if (compile_options) + fatal_error("Unsupported compiler options %#x.\n", compile_options); + } + hlsl_info.entry_point = "main"; sprintf(profile, "%s_%s", type, shader_models[runner->r.minimum_shader_model]); hlsl_info.profile = profile;
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- tests/hlsl/majority-pragma.shader_test | 144 +++++++++++++++++++++++++ 1 file changed, 144 insertions(+)
diff --git a/tests/hlsl/majority-pragma.shader_test b/tests/hlsl/majority-pragma.shader_test index 10778fd0..808313e7 100644 --- a/tests/hlsl/majority-pragma.shader_test +++ b/tests/hlsl/majority-pragma.shader_test @@ -223,3 +223,147 @@ uniform 8 float4 0.0 0.5 0.0 0.0 uniform 12 float4 0.0 0.6 0.0 0.0 draw quad probe all rgba (0.3, 0.4, 0.5, 0.6) + +% Compiler options +[require] +options: row-major + +[pixel shader] +#pragma pack_matrix(column_major) +uniform float4x4 m; + +float4 main() : sv_target +{ + float4 ret; + ret.xy = m[0].yz; + ret.zw = m[1].yz; + return ret; +} + +[test] +uniform 0 float4 0.1 0.5 0.9 1.3 +uniform 4 float4 0.2 0.6 1.0 1.4 +uniform 8 float4 0.3 0.7 1.1 1.5 +uniform 12 float4 0.4 0.8 1.2 1.6 +draw quad +probe all rgba (0.2, 0.3, 0.6, 0.7) 1 + +[require] +options: column-major + +[pixel shader] +uniform float4x4 m; + +float4 main() : sv_target +{ + float4 ret; + ret.xy = m[0].yz; + ret.zw = m[1].yz; + return ret; +} + +[test] +uniform 0 float4 0.1 0.5 0.9 1.3 +uniform 4 float4 0.2 0.6 1.0 1.4 +uniform 8 float4 0.3 0.7 1.1 1.5 +uniform 12 float4 0.4 0.8 1.2 1.6 +draw quad +probe all rgba (0.2, 0.3, 0.6, 0.7) 1 + +[require] +options: row-major + +[pixel shader] +uniform float4x4 m; + +float4 main() : sv_target +{ + float4 ret; + ret.xy = m[0].yz; + ret.zw = m[1].yz; + return ret; +} + +[test] +uniform 0 float4 0.1 0.5 0.9 1.3 +uniform 4 float4 0.2 0.6 1.0 1.4 +uniform 8 float4 0.3 0.7 1.1 1.5 +uniform 12 float4 0.4 0.8 1.2 1.6 +draw quad +probe all rgba (0.5, 0.9, 0.6, 1.0) 1 + +[require] +options: column-major + +[pixel shader] +uniform float4x4 m1; +#pragma pack_matrix(row_major) +uniform float4x4 m2; + +float4 main() : sv_target +{ + float4 ret; + ret.xy = m1[0].zw; + ret.zw = m2[0].zw; + return ret; +} + +[test] +uniform 0 float4 0.1 0.5 0.9 1.3 +uniform 4 float4 0.2 0.6 1.0 1.4 +uniform 8 float4 0.3 0.7 1.1 1.5 +uniform 12 float4 0.4 0.8 1.2 1.6 +uniform 16 float4 1.7 2.1 2.5 2.9 +uniform 20 float4 1.8 2.2 2.6 3.0 +uniform 24 float4 1.9 2.3 2.7 3.1 +uniform 28 float4 2.0 2.4 2.8 3.2 +draw quad +probe all rgba (0.3, 0.4, 2.5, 2.9) 1 + +[require] +options: row-major + +[pixel shader] +uniform float4x4 m1; +#pragma pack_matrix(column_major) +uniform float4x4 m2; + +float4 main() : sv_target +{ + float4 ret; + ret.xy = m1[3].zw; + ret.zw = m2[3].zw; + return ret; +} + +[test] +uniform 0 float4 0.1 0.5 0.9 1.3 +uniform 4 float4 0.2 0.6 1.0 1.4 +uniform 8 float4 0.3 0.7 1.1 1.5 +uniform 12 float4 0.4 0.8 1.2 1.6 +uniform 16 float4 1.7 2.1 2.5 2.9 +uniform 20 float4 1.8 2.2 2.6 3.0 +uniform 24 float4 1.9 2.3 2.7 3.1 +uniform 28 float4 2.0 2.4 2.8 3.2 +draw quad +probe all rgba (1.2, 1.6, 3.1, 3.2) 1 + +[require] +options: column-major row-major + +[pixel shader] +uniform float2x2 m; + +float4 main() : sv_target +{ + float4 ret; + ret.xy = m[0]; + ret.zw = m[1]; + return ret; +} + +[test] +uniform 0 float4 0.1 0.2 0.0 0.0 +uniform 4 float4 0.3 0.4 0.0 0.0 +draw quad +probe all rgba (0.1, 0.3, 0.2, 0.4) 1
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- programs/vkd3d-compiler/main.c | 89 +++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 29 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index b94272a5..4edf8a05 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -35,7 +35,7 @@ #include <term.h> #endif
-#define MAX_COMPILE_OPTIONS 4 +#define MAX_COMPILE_OPTIONS 5
enum { @@ -43,6 +43,7 @@ enum OPTION_BUFFER_UAV, OPTION_ENTRY, OPTION_OUTPUT, + OPTION_PACK_MATRIX_ORDER, OPTION_PRINT_SOURCE_TYPES, OPTION_PRINT_TARGET_TYPES, OPTION_PROFILE, @@ -177,34 +178,36 @@ static void print_usage(const char *program_name) static const char usage[] = "[options...] [file]\n" "Options:\n" - " -h, --help Display this information and exit.\n" - " -b <type> Specify the target type. Use --print-target-types to\n" - " list the valid and default target types for a given\n" - " source type.\n" - " --buffer-uav=<type> Specify the buffer type to use for buffer UAV bindings.\n" - " Valid values are 'buffer-texture' (default) and\n" - " 'storage-buffer'.\n" - " -e, --entry=<name> Use <name> as the entry point (default is "main").\n" - " -E Preprocess the source code instead of compiling it.\n" - " -o, --output=<file> Write the output to <file>. If <file> is '-' or no\n" - " output file is specified, output will be written to\n" - " standard output.\n" - " --formatting=<flags> Specify the formatting options for text output.\n" - " <flags> is a comma separated list of formatting flags,\n" - " optionally prefixed by '+' or '-'. Valid flags are\n" - " 'colour', 'indent', 'offsets', 'header', and 'raw-ids'.\n" - " The 'indent' and 'header' flags are enabled by default.\n" - " --print-source-types Display the supported source types and exit.\n" - " --print-target-types Display the supported target types for the specified\n" - " source type and exit.\n" - " -p, --profile=<name> Specify the target shader profile for HLSL shaders.\n" - " --strip-debug Strip debug information from the output.\n" - " -V, --version Display version information and exit.\n" - " -x <type> Specify the type of the source. Use --print-source-types\n" - " to list valid source types. The default source type is\n" - " automatically detected from the input shader.\n" - " -- Stop option processing. Any subsequent argument is\n" - " interpreted as a filename.\n" + " -h, --help Display this information and exit.\n" + " -b <type> Specify the target type. Use --print-target-types to\n" + " list the valid and default target types for a given\n" + " source type.\n" + " --buffer-uav=<type> Specify the buffer type to use for buffer UAV bindings.\n" + " Valid values are 'buffer-texture' (default) and\n" + " 'storage-buffer'.\n" + " --pack-matrix-order=<order> Specify default matrix packing order. Valid values are\n" + " 'column' (default) and 'row'.\n" + " -e, --entry=<name> Use <name> as the entry point (default is "main").\n" + " -E Preprocess the source code instead of compiling it.\n" + " -o, --output=<file> Write the output to <file>. If <file> is '-' or no\n" + " output file is specified, output will be written to\n" + " standard output.\n" + " --formatting=<flags> Specify the formatting options for text output.\n" + " <flags> is a comma separated list of formatting flags,\n" + " optionally prefixed by '+' or '-'. Valid flags are\n" + " 'colour', 'indent', 'offsets', 'header', and 'raw-ids'.\n" + " The 'indent' and 'header' flags are enabled by default.\n" + " --print-source-types Display the supported source types and exit.\n" + " --print-target-types Display the supported target types for the specified\n" + " source type and exit.\n" + " -p, --profile=<name> Specify the target shader profile for HLSL shaders.\n" + " --strip-debug Strip debug information from the output.\n" + " -V, --version Display version information and exit.\n" + " -x <type> Specify the type of the source. Use --print-source-types\n" + " to list valid source types. The default source type is\n" + " automatically detected from the input shader.\n" + " -- Stop option processing. Any subsequent argument is\n" + " interpreted as a filename.\n" "\n" "If the input file is '-' or not specified, input will be read from standard\n" "input.\n"; @@ -332,6 +335,23 @@ static bool parse_formatting(uint32_t *formatting, bool *colour, char *arg) return true; }
+static bool parse_pack_matrix_order(enum vkd3d_shader_compile_option_pack_matrix_order *order, const char *arg) +{ + if (!strcmp(arg, "column")) + { + *order = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR; + return true; + } + + if (!strcmp(arg, "row")) + { + *order = VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR; + return true; + } + + return false; +} + static enum vkd3d_shader_source_type parse_source_type(const char *source) { unsigned int i; @@ -418,6 +438,7 @@ static bool validate_target_type(
static bool parse_command_line(int argc, char **argv, struct options *options) { + enum vkd3d_shader_compile_option_pack_matrix_order pack_matrix_order; enum vkd3d_shader_compile_option_buffer_uav buffer_uav; int option;
@@ -427,6 +448,7 @@ static bool parse_command_line(int argc, char **argv, struct options *options) {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV}, {"entry", required_argument, NULL, OPTION_ENTRY}, {"output", required_argument, NULL, OPTION_OUTPUT}, + {"pack-matrix-order", required_argument, NULL, OPTION_PACK_MATRIX_ORDER}, {"formatting", required_argument, NULL, OPTION_TEXT_FORMATTING}, {"print-source-types", no_argument, NULL, OPTION_PRINT_SOURCE_TYPES}, {"print-target-types", no_argument, NULL, OPTION_PRINT_TARGET_TYPES}, @@ -485,6 +507,15 @@ static bool parse_command_line(int argc, char **argv, struct options *options) options->output_filename = optarg; break;
+ case OPTION_PACK_MATRIX_ORDER: + if (!parse_pack_matrix_order(&pack_matrix_order, optarg)) + { + fprintf(stderr, "Invalid matrix packing order '%s' specified.\n", optarg); + return false; + } + add_compile_option(options, VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER, pack_matrix_order); + break; + case OPTION_PROFILE: case 'p': options->profile = optarg;
On Tue Jul 18 12:57:42 2023 +0000, Henri Verbeet wrote:
Could we add vkd3d-compiler support as well, please? I notice we're missing vkd3d-compiler support for VKD3D_SHADER_COMPILE_OPTION_TYPED_UAV and VKD3D_SHADER_COMPILE_OPTION_WRITE_TESS_GEOM_POINT_SIZE as well; it would be even better if we could add those as well.
Sure. Pushed something for matrix order option. I'll add missing options later in a separate MR.
This merge request was approved by Zebediah Figura.
This merge request was approved by Giovanni Mascellani.
This merge request was approved by Henri Verbeet.
diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index ce9ac7e8..716b922c 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -26,6 +26,7 @@ #include "vulkan/vulkan.h" #include "vkd3d_shader.h" #include "vkd3d.h" +#include "vkd3d_d3dcompiler.h" #include "shader_runner.h" #include "vkd3d_test.h"
That seems a bit unfortunate. I wouldn't want to delay the series over it, but architecturally it might be nicer to use something specific to the shader runner, instead of reusing the d3dcompiler flags.
On Thu Jul 20 15:11:36 2023 +0000, Henri Verbeet wrote:
diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index ce9ac7e8..716b922c 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -26,6 +26,7 @@ #include "vulkan/vulkan.h" #include "vkd3d_shader.h" #include "vkd3d.h" +#include "vkd3d_d3dcompiler.h" #include "shader_runner.h" #include "vkd3d_test.h"
That seems a bit unfortunate. I wouldn't want to delay the series over it, but architecturally it might be nicer to use something specific to the shader runner, instead of reusing the d3dcompiler flags.
Is that because it's a vulkan one, or it's better to avoid in all runners? We have this header used by d3d9 and d3d11 runners already, so I didn't think much of it.
Is that because it's a vulkan one, or it's better to avoid in all runners? We have this header used by d3d9 and d3d11 runners already, so I didn't think much of it.
I think it applies generally, but we probably wouldn't care that much for the D3D runners because they end up depending on D3D headers anyway. It's much more visible for the Vulkan and (future) OpenGL runners.
Okay, so to avoid introducing another mask for options, we could use vkd3d options structure to pass them from parsing part, and convert to d3dcompiler mask when calling D3DCompile().
If I'm going to change something anyway, any --pack-matrix-order sound good? I was thinking to call it --matrix-pack-order, for some reason that sounded slightly better to me.
That seems a bit unfortunate. I wouldn't want to delay the series over it, but architecturally it might be nicer to use something specific to the shader runner, instead of reusing the d3dcompiler flags.
True, although for a test infrastructure I can't help but wonder how much we care. Also, I already added a lot of instances where the shader runner architecture just uses d3d12 constants.
If I'm going to change something anyway, any --pack-matrix-order sound good? I was thinking to call it --matrix-pack-order, for some reason that sounded slightly better to me.
--matrix-pack-order sounds better to me as well, perhaps even --matrix-storage-order.
That seems a bit unfortunate. I wouldn't want to delay the series over it, but architecturally it might be nicer to use something specific to the shader runner, instead of reusing the d3dcompiler flags.
True, although for a test infrastructure I can't help but wonder how much we care.
We don't care too much, but I figured I'd at least mention it.
On Thu Jul 20 20:15:19 2023 +0000, Henri Verbeet wrote:
If I'm going to change something anyway, any --pack-matrix-order sound
good? I was thinking to call it --matrix-pack-order, for some reason that sounded slightly better to me. --matrix-pack-order sounds better to me as well, perhaps even --matrix-storage-order.
That seems a bit unfortunate. I wouldn't want to delay the series
over it, but architecturally it might be nicer to use something specific to the shader runner, instead of reusing the d3dcompiler flags.
True, although for a test infrastructure I can't help but wonder how
much we care. We don't care too much, but I figured I'd at least mention it.
I think I changed it to match D3DCOMPILE_PACK_MATRIX_* naming, but I think it's fine to change user-facing name only.