spirv: Recognize zero initializers in Workgroup variables
This will be used to implement VK_KHR_zero_initialize_workgroup_memory. Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8708>
This commit is contained in:

committed by
Marge Bot

parent
378eca1394
commit
c4f2297f00
@@ -368,6 +368,8 @@ typedef struct shader_info {
|
||||
*/
|
||||
enum gl_derivative_group derivative_group:2;
|
||||
|
||||
bool zero_initialize_shared_memory;
|
||||
|
||||
/**
|
||||
* Size of shared variables accessed by the compute shader.
|
||||
*/
|
||||
|
@@ -2167,6 +2167,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
|
||||
|
||||
case SpvOpConstantNull:
|
||||
val->constant = vtn_null_constant(b, val->type);
|
||||
val->is_null_constant = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@@ -603,6 +603,9 @@ struct vtn_value {
|
||||
* the existence of a NonUniform decoration on this value.*/
|
||||
uint32_t propagated_non_uniform : 1;
|
||||
|
||||
/* Valid for vtn_value_type_constant to indicate the value is OpConstantNull. */
|
||||
bool is_null_constant:1;
|
||||
|
||||
const char *name;
|
||||
struct vtn_decoration *decoration;
|
||||
struct vtn_type *type;
|
||||
|
@@ -1977,6 +1977,26 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
|
||||
}
|
||||
|
||||
if (initializer) {
|
||||
switch (var->mode) {
|
||||
case vtn_variable_mode_workgroup:
|
||||
/* VK_KHR_zero_initialize_workgroup_memory. */
|
||||
vtn_fail_if(b->options->environment != NIR_SPIRV_VULKAN,
|
||||
"Only Vulkan supports variable initializer "
|
||||
"for Workgroup variable %u",
|
||||
vtn_id_for_value(b, val));
|
||||
vtn_fail_if(initializer->value_type != vtn_value_type_constant ||
|
||||
!initializer->is_null_constant,
|
||||
"Workgroup variable %u can only have OpConstantNull "
|
||||
"as initializer, but have %u instead",
|
||||
vtn_id_for_value(b, val),
|
||||
vtn_id_for_value(b, initializer));
|
||||
b->shader->info.cs.zero_initialize_shared_memory = true;
|
||||
break;
|
||||
default:
|
||||
/* Nothing to check. */
|
||||
break;
|
||||
}
|
||||
|
||||
switch (initializer->value_type) {
|
||||
case vtn_value_type_constant:
|
||||
var->var->constant_initializer =
|
||||
|
Reference in New Issue
Block a user