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:
Caio Marcelo de Oliveira Filho
2020-06-24 13:44:08 -07:00
committed by Marge Bot
parent 378eca1394
commit c4f2297f00
4 changed files with 26 additions and 0 deletions

View File

@@ -368,6 +368,8 @@ typedef struct shader_info {
*/ */
enum gl_derivative_group derivative_group:2; enum gl_derivative_group derivative_group:2;
bool zero_initialize_shared_memory;
/** /**
* Size of shared variables accessed by the compute shader. * Size of shared variables accessed by the compute shader.
*/ */

View File

@@ -2167,6 +2167,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
case SpvOpConstantNull: case SpvOpConstantNull:
val->constant = vtn_null_constant(b, val->type); val->constant = vtn_null_constant(b, val->type);
val->is_null_constant = true;
break; break;
default: default:

View File

@@ -603,6 +603,9 @@ struct vtn_value {
* the existence of a NonUniform decoration on this value.*/ * the existence of a NonUniform decoration on this value.*/
uint32_t propagated_non_uniform : 1; 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; const char *name;
struct vtn_decoration *decoration; struct vtn_decoration *decoration;
struct vtn_type *type; struct vtn_type *type;

View File

@@ -1977,6 +1977,26 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
} }
if (initializer) { 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) { switch (initializer->value_type) {
case vtn_value_type_constant: case vtn_value_type_constant:
var->var->constant_initializer = var->var->constant_initializer =