From: Zebediah Figura zfigura@codeweavers.com
--- dlls/wined3d/shader_spirv.c | 60 +++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 6 deletions(-)
diff --git a/dlls/wined3d/shader_spirv.c b/dlls/wined3d/shader_spirv.c index dab0e3dc5f9..a32767efc68 100644 --- a/dlls/wined3d/shader_spirv.c +++ b/dlls/wined3d/shader_spirv.c @@ -57,6 +57,12 @@ struct shader_spirv_compile_arguments { union { + struct + { + /* The maximum inter-stage register index for an sm1 shader is 11. */ + struct vkd3d_shader_varying_map varying_map[12]; + unsigned int varying_count; + } vs; struct { uint32_t alpha_swizzle; @@ -81,6 +87,7 @@ struct shader_spirv_graphics_program_vk SIZE_T variants_size, variant_count;
struct vkd3d_shader_scan_descriptor_info descriptor_info; + struct vkd3d_shader_scan_signature_info signature_info; };
struct shader_spirv_compute_program_vk @@ -95,6 +102,7 @@ struct shader_spirv_compute_program_vk
struct wined3d_shader_spirv_compile_args { + struct vkd3d_shader_varying_map_info varying_map; struct vkd3d_shader_spirv_target_info spirv_target; struct vkd3d_shader_parameter sample_count; unsigned int ps_alpha_swizzle[WINED3D_MAX_RENDER_TARGETS]; @@ -155,6 +163,22 @@ static void shader_spirv_compile_arguments_init(struct shader_spirv_compile_argu args->u.fs.dual_source_blending = state->blend_state && state->blend_state->dual_source; break;
+ case WINED3D_SHADER_TYPE_VERTEX: + { + struct wined3d_shader *ps = state->shader[WINED3D_SHADER_TYPE_PIXEL]; + struct shader_spirv_graphics_program_vk *ps_program = ps->backend_data; + struct shader_spirv_graphics_program_vk *vs_program = shader->backend_data; + unsigned int count = ARRAY_SIZE(args->u.vs.varying_map); + + if (shader->reg_maps.shader_version.major < 4) + { + vkd3d_shader_build_varying_map(&vs_program->signature_info.output, + &ps_program->signature_info.input, &count, args->u.vs.varying_map); + args->u.vs.varying_count = count; + } + break; + } + default: break; } @@ -162,7 +186,8 @@ static void shader_spirv_compile_arguments_init(struct shader_spirv_compile_argu
static void shader_spirv_init_compile_args(struct wined3d_shader_spirv_compile_args *args, struct vkd3d_shader_interface_info *vkd3d_interface, enum vkd3d_shader_spirv_environment environment, - enum wined3d_shader_type shader_type, const struct shader_spirv_compile_arguments *compile_args) + enum wined3d_shader_type shader_type, enum vkd3d_shader_source_type source_type, + const struct shader_spirv_compile_arguments *compile_args) { unsigned int i;
@@ -199,6 +224,19 @@ static void shader_spirv_init_compile_args(struct wined3d_shader_spirv_compile_a args->spirv_target.output_swizzles = args->ps_alpha_swizzle; args->spirv_target.output_swizzle_count = ARRAY_SIZE(args->ps_alpha_swizzle); } + else if (shader_type == WINED3D_SHADER_TYPE_VERTEX) + { + args->spirv_target.next = &args->varying_map; + + args->varying_map.type = VKD3D_SHADER_STRUCTURE_TYPE_VARYING_MAP_INFO; + args->varying_map.next = vkd3d_interface; + + if (source_type == VKD3D_SHADER_SOURCE_D3D_BYTECODE) + { + args->varying_map.varying_map = compile_args->u.vs.varying_map; + args->varying_map.varying_count = compile_args->u.vs.varying_count; + } + } }
static void shader_spirv_init_shader_interface_vk(struct wined3d_shader_spirv_shader_interface *iface, @@ -240,6 +278,7 @@ static VkShaderModule shader_spirv_compile_shader(struct wined3d_context_vk *con const struct shader_spirv_compile_arguments *args, const struct shader_spirv_resource_bindings *bindings, const struct wined3d_stream_output_desc *so_desc) { + enum vkd3d_shader_source_type source_type = shader_spirv_get_source_type(*(const uint32_t *)shader_desc->byte_code); struct wined3d_shader_spirv_compile_args compile_args; struct wined3d_shader_spirv_shader_interface iface; VkShaderModuleCreateInfo shader_create_info; @@ -254,13 +293,13 @@ static VkShaderModule shader_spirv_compile_shader(struct wined3d_context_vk *con
shader_spirv_init_shader_interface_vk(&iface, bindings, so_desc); shader_spirv_init_compile_args(&compile_args, &iface.vkd3d_interface, - VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0, shader_type, args); + VKD3D_SHADER_SPIRV_ENVIRONMENT_VULKAN_1_0, shader_type, source_type, args);
info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; info.next = &compile_args.spirv_target; info.source.code = shader_desc->byte_code; info.source.size = shader_desc->byte_code_size; - info.source_type = shader_spirv_get_source_type(*(const uint32_t *)info.source.code); + info.source_type = source_type; info.target_type = VKD3D_SHADER_TARGET_SPIRV_BINARY; info.options = spirv_compile_options; info.option_count = ARRAY_SIZE(spirv_compile_options); @@ -687,7 +726,8 @@ static bool shader_spirv_resource_bindings_init(struct shader_spirv_resource_bin }
static void shader_spirv_scan_shader(struct wined3d_shader *shader, - struct vkd3d_shader_scan_descriptor_info *descriptor_info) + struct vkd3d_shader_scan_descriptor_info *descriptor_info, + struct vkd3d_shader_scan_signature_info *signature_info) { struct vkd3d_shader_compile_info info; char *messages; @@ -696,6 +736,13 @@ static void shader_spirv_scan_shader(struct wined3d_shader *shader, memset(descriptor_info, 0, sizeof(*descriptor_info)); descriptor_info->type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_DESCRIPTOR_INFO;
+ if (signature_info) + { + memset(signature_info, 0, sizeof(*signature_info)); + signature_info->type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_SIGNATURE_INFO; + descriptor_info->next = signature_info; + } + info.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO; info.next = descriptor_info; info.source.code = shader->byte_code; @@ -736,7 +783,7 @@ static void shader_spirv_precompile_compute(struct wined3d_shader *shader) shader->backend_data = program_vk; }
- shader_spirv_scan_shader(shader, &program_vk->descriptor_info); + shader_spirv_scan_shader(shader, &program_vk->descriptor_info, NULL); }
static void shader_spirv_precompile(void *shader_priv, struct wined3d_shader *shader) @@ -758,7 +805,7 @@ static void shader_spirv_precompile(void *shader_priv, struct wined3d_shader *sh shader->backend_data = program_vk; }
- shader_spirv_scan_shader(shader, &program_vk->descriptor_info); + shader_spirv_scan_shader(shader, &program_vk->descriptor_info, &program_vk->signature_info); }
static void shader_spirv_select(void *shader_priv, struct wined3d_context *context, @@ -967,6 +1014,7 @@ static void shader_spirv_destroy(struct wined3d_shader *shader) } heap_free(program_vk->variants); vkd3d_shader_free_scan_descriptor_info(&program_vk->descriptor_info); + vkd3d_shader_free_scan_signature_info(&program_vk->signature_info);
shader->backend_data = NULL; heap_free(program_vk);