vkd3d-shader: Introduce SPIRV_ENVIRONMENT_VULKAN_1_1.

The SPIR-V backend may emit SPIR-V 1.3 if Vulkan 1.1 is available.
Some extensions which provide wave op instructions are available in
SPIR-V 1.0, but these are not sufficient to implement all Shader Model 6
wave op intrinsics. SPIR-V 1.3 has all of the required instructions, but
does not support reading from a quad at a non-constant (but uniform) lane
index, so it may later prove necessary to introduce a Vulkan 1.2
environment.
This commit is contained in:
Conor McCarthy 2024-04-10 11:36:19 +10:00 committed by Alexandre Julliard
parent a7870e1793
commit 6975a8d726
Notes: Alexandre Julliard 2024-04-17 23:29:42 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/776
2 changed files with 13 additions and 6 deletions

View File

@ -923,6 +923,8 @@ enum vkd3d_shader_spirv_environment
VKD3D_SHADER_SPIRV_ENVIRONMENT_NONE,
VKD3D_SHADER_SPIRV_ENVIRONMENT_OPENGL_4_5,
VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0, /* default target */
/** \since 1.12 */
VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_1,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SPIRV_ENVIRONMENT),
};

View File

@ -45,6 +45,8 @@ static spv_target_env spv_target_env_from_vkd3d(enum vkd3d_shader_spirv_environm
return SPV_ENV_OPENGL_4_5;
case VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0:
return SPV_ENV_VULKAN_1_0;
case VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_1:
return SPV_ENV_VULKAN_1_1;
default:
ERR("Invalid environment %#x.\n", environment);
return SPV_ENV_VULKAN_1_0;
@ -223,7 +225,8 @@ enum vkd3d_shader_input_sysval_semantic vkd3d_siv_from_sysval_indexed(enum vkd3d
}
}
#define VKD3D_SPIRV_VERSION 0x00010000
#define VKD3D_SPIRV_VERSION_1_0 0x00010000
#define VKD3D_SPIRV_VERSION_1_3 0x00010300
#define VKD3D_SPIRV_GENERATOR_ID 18
#define VKD3D_SPIRV_GENERATOR_VERSION 11
#define VKD3D_SPIRV_GENERATOR_MAGIC vkd3d_make_u32(VKD3D_SPIRV_GENERATOR_VERSION, VKD3D_SPIRV_GENERATOR_ID)
@ -1915,7 +1918,7 @@ static void vkd3d_spirv_builder_free(struct vkd3d_spirv_builder *builder)
}
static bool vkd3d_spirv_compile_module(struct vkd3d_spirv_builder *builder,
struct vkd3d_shader_code *spirv, const char *entry_point)
struct vkd3d_shader_code *spirv, const char *entry_point, enum vkd3d_shader_spirv_environment environment)
{
uint64_t capability_mask = builder->capability_mask;
struct vkd3d_spirv_stream stream;
@ -1926,7 +1929,8 @@ static bool vkd3d_spirv_compile_module(struct vkd3d_spirv_builder *builder,
vkd3d_spirv_stream_init(&stream);
vkd3d_spirv_build_word(&stream, SpvMagicNumber);
vkd3d_spirv_build_word(&stream, VKD3D_SPIRV_VERSION);
vkd3d_spirv_build_word(&stream, (environment == VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_1)
? VKD3D_SPIRV_VERSION_1_3 : VKD3D_SPIRV_VERSION_1_0);
vkd3d_spirv_build_word(&stream, VKD3D_SPIRV_GENERATOR_MAGIC);
vkd3d_spirv_build_word(&stream, builder->current_id); /* bound */
vkd3d_spirv_build_word(&stream, 0); /* schema, reserved */
@ -2475,6 +2479,7 @@ static struct spirv_compiler *spirv_compiler_create(const struct vsir_program *p
{
case VKD3D_SHADER_SPIRV_ENVIRONMENT_OPENGL_4_5:
case VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0:
case VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_1:
break;
default:
WARN("Invalid target environment %#x.\n", target_info->environment);
@ -10155,6 +10160,7 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
struct vkd3d_shader_instruction_array instructions;
struct vsir_program *program = &parser->program;
enum vkd3d_shader_spirv_environment environment;
enum vkd3d_result result = VKD3D_OK;
unsigned int i;
@ -10239,12 +10245,12 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
if (compiler->strip_debug)
vkd3d_spirv_stream_clear(&builder->debug_stream);
if (!vkd3d_spirv_compile_module(builder, spirv, spirv_compiler_get_entry_point_name(compiler)))
environment = spirv_compiler_get_target_environment(compiler);
if (!vkd3d_spirv_compile_module(builder, spirv, spirv_compiler_get_entry_point_name(compiler), environment))
return VKD3D_ERROR;
if (TRACE_ON() || parser->config_flags & VKD3D_SHADER_CONFIG_FLAG_FORCE_VALIDATION)
{
enum vkd3d_shader_spirv_environment environment = spirv_compiler_get_target_environment(compiler);
struct vkd3d_string_buffer buffer;
if (TRACE_ON())
@ -10272,7 +10278,6 @@ static int spirv_compiler_generate_spirv(struct spirv_compiler *compiler,
if (compile_info->target_type == VKD3D_SHADER_TARGET_SPIRV_TEXT)
{
struct vkd3d_shader_code text;
enum vkd3d_shader_spirv_environment environment = spirv_compiler_get_target_environment(compiler);
if (vkd3d_spirv_binary_to_text(spirv, environment, compiler->formatting, &text) != VKD3D_OK)
return VKD3D_ERROR;
vkd3d_shader_free_shader_code(spirv);