Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
-- v8: vkd3d-compiler: Add CLI option to specify default matrix packing order.
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 | 56 ++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 12 deletions(-)
diff --git a/programs/vkd3d-compiler/main.c b/programs/vkd3d-compiler/main.c index b94272a5..3341e037 100644 --- a/programs/vkd3d-compiler/main.c +++ b/programs/vkd3d-compiler/main.c @@ -35,13 +35,14 @@ #include <term.h> #endif
-#define MAX_COMPILE_OPTIONS 4 +#define MAX_COMPILE_OPTIONS 5
enum { OPTION_HELP = CHAR_MAX + 1, OPTION_BUFFER_UAV, OPTION_ENTRY, + OPTION_MATRIX_STORAGE_ORDER, OPTION_OUTPUT, OPTION_PRINT_SOURCE_TYPES, OPTION_PRINT_TARGET_TYPES, @@ -184,6 +185,9 @@ static void print_usage(const char *program_name) " --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" + " --matrix-storage-order=<order>\n" + " Specify default matrix storage 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" @@ -332,6 +336,23 @@ static bool parse_formatting(uint32_t *formatting, bool *colour, char *arg) return true; }
+static bool parse_matrix_storage_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,22 +439,24 @@ 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;
static struct option long_options[] = { - {"help", no_argument, NULL, OPTION_HELP}, - {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV}, - {"entry", required_argument, NULL, OPTION_ENTRY}, - {"output", required_argument, NULL, OPTION_OUTPUT}, - {"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}, - {"profile", required_argument, NULL, OPTION_PROFILE}, - {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG}, - {"version", no_argument, NULL, OPTION_VERSION}, - {NULL, 0, NULL, 0}, + {"help", no_argument, NULL, OPTION_HELP}, + {"buffer-uav", required_argument, NULL, OPTION_BUFFER_UAV}, + {"entry", required_argument, NULL, OPTION_ENTRY}, + {"matrix-storage-order", required_argument, NULL, OPTION_MATRIX_STORAGE_ORDER}, + {"output", required_argument, NULL, OPTION_OUTPUT}, + {"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}, + {"profile", required_argument, NULL, OPTION_PROFILE}, + {"strip-debug", no_argument, NULL, OPTION_STRIP_DEBUG}, + {"version", no_argument, NULL, OPTION_VERSION}, + {NULL, 0, NULL, 0}, };
memset(options, 0, sizeof(*options)); @@ -485,6 +508,15 @@ static bool parse_command_line(int argc, char **argv, struct options *options) options->output_filename = optarg; break;
+ case OPTION_MATRIX_STORAGE_ORDER: + if (!parse_matrix_storage_order(&pack_matrix_order, optarg)) + { + fprintf(stderr, "Invalid matrix storage 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;
Ok, I reformatted it a bit to reduce the width.
This merge request was approved by Henri Verbeet.