From: Józef Kucia jkucia@codeweavers.com
Also adds initial infrastructure for more flexible shader parameters.
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- include/vkd3d_shader.h | 48 +++++++++++++++++++++++++++++++++ libs/vkd3d-shader/spirv.c | 57 ++++++++++++++++++++++++++++++++++----- libs/vkd3d/state.c | 2 ++ 3 files changed, 100 insertions(+), 7 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index cfb026348d05..28c32746491f 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -90,6 +90,50 @@ enum vkd3d_shader_binding_flag VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_BINDING_FLAG), };
+enum vkd3d_shader_parameter_type +{ + VKD3D_SHADER_PARAMETER_TYPE_UNKNOWN, + VKD3D_SHADER_PARAMETER_TYPE_IMMEDIATE_CONSTANT, + VKD3D_SHADER_PARAMETER_TYPE_SPECIALIZATION_CONSTANT, +}; + +enum vkd3d_shader_parameter_data_type +{ + VKD3D_SHADER_PARAMETER_DATA_TYPE_UNKNOWN, + VKD3D_SHADER_PARAMETER_DATA_TYPE_UINT32, +}; + +enum vkd3d_shader_parameter_name +{ + VKD3D_SHADER_PARAMETER_NAME_UNKNOWN, + VKD3D_SHADER_PARAMETER_NAME_RASTERIZER_SAMPLE_COUNT, +}; + +struct vkd3d_shader_parameter_immediate_constant +{ + union + { + uint32_t u32; + } u; +}; + +struct vkd3d_shader_parameter_specialization_constant +{ + uint32_t id; +}; + +struct vkd3d_shader_parameter +{ + enum vkd3d_shader_parameter_name name; + enum vkd3d_shader_parameter_type type; + enum vkd3d_shader_parameter_data_type data_type; + union + { + struct vkd3d_shader_parameter_immediate_constant immediate_constant; + struct vkd3d_shader_parameter_specialization_constant specialization_constant; + } u; +}; + struct vkd3d_shader_resource_binding { enum vkd3d_shader_descriptor_type type; @@ -185,6 +229,10 @@ struct vkd3d_shader_compile_arguments const void *next;
enum vkd3d_shader_target target; + + unsigned int parameter_count; + struct vkd3d_shader_parameter *parameters; + bool dual_source_blending; const unsigned int *output_swizzles; unsigned int output_swizzle_count; diff --git a/libs/vkd3d-shader/spirv.c b/libs/vkd3d-shader/spirv.c index 738fcc94bfaf..81830e383e13 100644 --- a/libs/vkd3d-shader/spirv.c +++ b/libs/vkd3d-shader/spirv.c @@ -2477,6 +2477,46 @@ static uint32_t vkd3d_dxbc_compiler_emit_array_variable(struct vkd3d_dxbc_compil return vkd3d_spirv_build_op_variable(builder, stream, ptr_type_id, storage_class, 0); }
+static const struct vkd3d_shader_parameter *vkd3d_dxbc_compiler_get_shader_parameter( + struct vkd3d_dxbc_compiler *compiler, enum vkd3d_shader_parameter_name name) +{ + const struct vkd3d_shader_compile_arguments *compile_args = compiler->compile_args; + unsigned int i; + + for (i = 0; compile_args && i < compile_args->parameter_count; ++i) + { + if (compile_args->parameters[i].name == name) + return &compile_args->parameters[i]; + } + + return NULL; +} + +static uint32_t vkd3d_dxbc_compiler_emit_uint_shader_parameter(struct vkd3d_dxbc_compiler *compiler, + enum vkd3d_shader_parameter_name name) +{ + struct vkd3d_spirv_builder *builder = &compiler->spirv_builder; + const struct vkd3d_shader_parameter *parameter; + uint32_t id; + + if (!(parameter = vkd3d_dxbc_compiler_get_shader_parameter(compiler, name))) + { + FIXME("Unresolved shader parameter %#x.\n", name); + goto fail; + } + + if (parameter->type == VKD3D_SHADER_PARAMETER_TYPE_IMMEDIATE_CONSTANT) + { + return vkd3d_dxbc_compiler_get_constant_uint(compiler, parameter->u.immediate_constant.u.u32); + } + + FIXME("Unhandled parameter type %#x.\n", parameter->type); + +fail: + id = vkd3d_spirv_get_type_id(builder, VKD3D_TYPE_UINT, 1); + return vkd3d_spirv_build_op_undef(builder, &builder->global_stream, id); +} + static uint32_t vkd3d_dxbc_compiler_emit_construct_vector(struct vkd3d_dxbc_compiler *compiler, enum vkd3d_component_type component_type, unsigned int component_count, uint32_t val_id, unsigned int val_component_idx, unsigned int val_component_count) @@ -7563,21 +7603,24 @@ static void vkd3d_dxbc_compiler_emit_sample_info(struct vkd3d_dxbc_compiler *com const struct vkd3d_shader_dst_param *dst = instruction->dst; const struct vkd3d_shader_src_param *src = instruction->src; uint32_t constituents[VKD3D_VEC4_SIZE]; - struct vkd3d_shader_image image; uint32_t type_id, val_id; unsigned int i;
if (src->reg.type == VKD3DSPR_RASTERIZER) { - FIXME("Rasterizer not supported.\n"); - return; + val_id = vkd3d_dxbc_compiler_emit_uint_shader_parameter(compiler, + VKD3D_SHADER_PARAMETER_NAME_RASTERIZER_SAMPLE_COUNT); } + else + { + struct vkd3d_shader_image image;
- vkd3d_spirv_enable_capability(builder, SpvCapabilityImageQuery); + vkd3d_spirv_enable_capability(builder, SpvCapabilityImageQuery);
- vkd3d_dxbc_compiler_prepare_image(compiler, &image, &src->reg, NULL, VKD3D_IMAGE_FLAG_NONE); - type_id = vkd3d_spirv_get_type_id(builder, VKD3D_TYPE_UINT, 1); - val_id = vkd3d_spirv_build_op_image_query_samples(builder, type_id, image.image_id); + vkd3d_dxbc_compiler_prepare_image(compiler, &image, &src->reg, NULL, VKD3D_IMAGE_FLAG_NONE); + type_id = vkd3d_spirv_get_type_id(builder, VKD3D_TYPE_UINT, 1); + val_id = vkd3d_spirv_build_op_image_query_samples(builder, type_id, image.image_id); + }
constituents[0] = val_id; for (i = 1; i < VKD3D_VEC4_SIZE; ++i) diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 980d9edde608..a6b5fdd0ede5 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -2074,6 +2074,8 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s ps_compile_args.type = VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_ARGUMENTS; ps_compile_args.next = NULL; ps_compile_args.target = VKD3D_SHADER_TARGET_SPIRV_VULKAN_1_0; + ps_compile_args.parameter_count = 0; + ps_compile_args.parameters = NULL; ps_compile_args.dual_source_blending = is_dual_source_blending(&desc->BlendState.RenderTarget[0]); ps_compile_args.output_swizzles = ps_output_swizzle; ps_compile_args.output_swizzle_count = rt_count;