spirv,vulkan: Implement OpConstantSizeOfKHR

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40649>
This commit is contained in:
Faith Ekstrand 2025-06-19 15:36:41 -04:00 committed by Marge Bot
parent ad9f92ba10
commit b42b7c8f60
3 changed files with 57 additions and 0 deletions

View file

@ -93,6 +93,16 @@ struct spirv_to_nir_options {
*/
uint32_t min_ssbo_alignment;
/* These must be identical to the values set in
* VkPhysicalDeviceDescriptorHeapPropertiesEXT
*/
uint32_t sampler_descriptor_size;
uint32_t sampler_descriptor_alignment;
uint32_t image_descriptor_size;
uint32_t image_descriptor_alignment;
uint32_t buffer_descriptor_size;
uint32_t buffer_descriptor_alignment;
const nir_shader *clc_shader;
struct {

View file

@ -3014,6 +3014,39 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
val->is_null_constant = true;
break;
case SpvOpConstantSizeOfEXT: {
vtn_fail_if(val->type->type != glsl_uint_type() &&
val->type->type != glsl_int_type() &&
val->type->type != glsl_uint64_t_type() &&
val->type->type != glsl_int64_t_type(),
"Result Type must be a 32-bit or 64-bit integer type scalar.");
struct vtn_type *type = vtn_get_type(b, w[3]);
switch (type->base_type) {
case vtn_base_type_image:
val->constant->values[0].u32 =
align(b->options->image_descriptor_size,
b->options->image_descriptor_alignment);
break;
case vtn_base_type_sampler:
val->constant->values[0].u32 =
align(b->options->sampler_descriptor_size,
b->options->sampler_descriptor_alignment);
break;
case vtn_base_type_accel_struct:
case vtn_base_type_buffer:
val->constant->values[0].u32 =
align(b->options->buffer_descriptor_size,
b->options->buffer_descriptor_alignment);
break;
default:
vtn_fail("Type must be an OpTypeBufferKHR, OpTypeImage, "
"OpTypeAccelerationStructureKHR, OpTypeTensorARM, or "
"OpTypeSampler instruction.");
}
break;
}
default:
vtn_fail_with_opcode("Unhandled opcode", opcode);
}
@ -6095,6 +6128,7 @@ vtn_handle_variable_or_type_instruction(struct vtn_builder *b, SpvOp opcode,
case SpvOpSpecConstantComposite:
case SpvOpSpecConstantCompositeReplicateEXT:
case SpvOpSpecConstantOp:
case SpvOpConstantSizeOfEXT:
vtn_handle_constant(b, opcode, w, count);
break;

View file

@ -136,6 +136,19 @@ vk_spirv_to_nir(struct vk_device *device,
spirv_options_local.debug.func = spirv_nir_debug;
spirv_options_local.debug.private_data = (void *)device;
spirv_options_local.sampler_descriptor_size =
device->physical->properties.samplerDescriptorSize;
spirv_options_local.sampler_descriptor_alignment =
device->physical->properties.samplerDescriptorAlignment;
spirv_options_local.image_descriptor_size =
device->physical->properties.imageDescriptorSize;
spirv_options_local.image_descriptor_alignment =
device->physical->properties.imageDescriptorAlignment;
spirv_options_local.buffer_descriptor_size =
device->physical->properties.bufferDescriptorSize;
spirv_options_local.buffer_descriptor_alignment =
device->physical->properties.bufferDescriptorAlignment;
uint32_t num_spec_entries = 0;
struct nir_spirv_specialization *spec_entries =
vk_spec_info_to_nir_spirv(spec_info, &num_spec_entries);