From 0bf5bbb3e41ee47b317a5aa7f7f72e0612f1c49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 24 Oct 2022 15:17:38 +0200 Subject: [PATCH] microsoft/spirv2dxil: Refactor to make SM and validator versions public Part-of: --- src/gallium/drivers/d3d12/d3d12_compiler.cpp | 2 +- src/microsoft/compiler/dxil_validator.h | 14 +---- src/microsoft/compiler/dxil_versions.h | 58 ++++++++++++++++++++ src/microsoft/compiler/nir_to_dxil.h | 17 +----- src/microsoft/spirv_to_dxil/spirv_to_dxil.h | 2 + 5 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 src/microsoft/compiler/dxil_versions.h diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp b/src/gallium/drivers/d3d12/d3d12_compiler.cpp index c80f1b6ae40..8b2d2174a91 100644 --- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp +++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp @@ -150,7 +150,7 @@ compile_nir(struct d3d12_context *ctx, struct d3d12_shader_selector *sel, opts.environment = DXIL_ENVIRONMENT_GL; static_assert(D3D_SHADER_MODEL_6_0 == 0x60 && SHADER_MODEL_6_0 == 0x60000, "Validating math below"); static_assert(D3D_SHADER_MODEL_6_7 == 0x67 && SHADER_MODEL_6_7 == 0x60007, "Validating math below"); - opts.shader_model_max = ((screen->max_shader_model & 0xf0) << 12) | (screen->max_shader_model & 0xf); + opts.shader_model_max = static_cast(((screen->max_shader_model & 0xf0) << 12) | (screen->max_shader_model & 0xf)); #ifdef _WIN32 opts.validator_version_max = dxil_get_validator_version(ctx->dxil_validator); #endif diff --git a/src/microsoft/compiler/dxil_validator.h b/src/microsoft/compiler/dxil_validator.h index 8a7db43b212..d867d377263 100644 --- a/src/microsoft/compiler/dxil_validator.h +++ b/src/microsoft/compiler/dxil_validator.h @@ -24,6 +24,8 @@ #ifndef DXIL_VALIDATOR_H #define DXIL_VALIDATOR_H +#include "dxil_versions.h" + #include struct dxil_validator; @@ -32,18 +34,6 @@ struct dxil_validator; extern "C" { #endif -enum dxil_validator_version { - NO_DXIL_VALIDATION, - DXIL_VALIDATOR_1_0 = 0x10000, - DXIL_VALIDATOR_1_1, - DXIL_VALIDATOR_1_2, - DXIL_VALIDATOR_1_3, - DXIL_VALIDATOR_1_4, - DXIL_VALIDATOR_1_5, - DXIL_VALIDATOR_1_6, - DXIL_VALIDATOR_1_7, -}; - struct dxil_validator * dxil_create_validator(const void *ctx); diff --git a/src/microsoft/compiler/dxil_versions.h b/src/microsoft/compiler/dxil_versions.h new file mode 100644 index 00000000000..83c80d56f93 --- /dev/null +++ b/src/microsoft/compiler/dxil_versions.h @@ -0,0 +1,58 @@ +/* + * Copyright © Microsoft 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. + */ + +#ifndef DXIL_VERSIONS_H +#define DXIL_VERSIONS_H + +#ifdef __cplusplus +extern "C" { +#endif + +enum dxil_shader_model { + SHADER_MODEL_6_0 = 0x60000, + SHADER_MODEL_6_1, + SHADER_MODEL_6_2, + SHADER_MODEL_6_3, + SHADER_MODEL_6_4, + SHADER_MODEL_6_5, + SHADER_MODEL_6_6, + SHADER_MODEL_6_7, +}; + +enum dxil_validator_version { + NO_DXIL_VALIDATION, + DXIL_VALIDATOR_1_0 = 0x10000, + DXIL_VALIDATOR_1_1, + DXIL_VALIDATOR_1_2, + DXIL_VALIDATOR_1_3, + DXIL_VALIDATOR_1_4, + DXIL_VALIDATOR_1_5, + DXIL_VALIDATOR_1_6, + DXIL_VALIDATOR_1_7, +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/microsoft/compiler/nir_to_dxil.h b/src/microsoft/compiler/nir_to_dxil.h index c431906138a..5e04641ac2e 100644 --- a/src/microsoft/compiler/nir_to_dxil.h +++ b/src/microsoft/compiler/nir_to_dxil.h @@ -27,7 +27,7 @@ #include #include "nir.h" -#include "dxil_validator.h" +#include "dxil_versions.h" #ifdef __cplusplus extern "C" { @@ -81,17 +81,6 @@ enum dxil_environment { DXIL_ENVIRONMENT_VULKAN, }; -enum dxil_shader_model { - SHADER_MODEL_6_0 = 0x60000, - SHADER_MODEL_6_1, - SHADER_MODEL_6_2, - SHADER_MODEL_6_3, - SHADER_MODEL_6_4, - SHADER_MODEL_6_5, - SHADER_MODEL_6_6, - SHADER_MODEL_6_7, -}; - struct nir_to_dxil_options { bool interpolate_at_vertex; bool lower_int16; @@ -102,8 +91,8 @@ struct nir_to_dxil_options { unsigned num_kernel_globals; unsigned input_clip_size; enum dxil_environment environment; - uint32_t shader_model_max; - uint32_t validator_version_max; + enum dxil_shader_model shader_model_max; + enum dxil_validator_version validator_version_max; }; typedef void (*dxil_msg_callback)(void *priv, const char *msg); diff --git a/src/microsoft/spirv_to_dxil/spirv_to_dxil.h b/src/microsoft/spirv_to_dxil/spirv_to_dxil.h index ee657ebb0eb..345b5467f6f 100644 --- a/src/microsoft/spirv_to_dxil/spirv_to_dxil.h +++ b/src/microsoft/spirv_to_dxil/spirv_to_dxil.h @@ -24,6 +24,8 @@ #ifndef SPIRV_TO_DXIL_H #define SPIRV_TO_DXIL_H +#include "dxil_versions.h" + #include #include #include