<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 8, 2019 at 8:33 AM Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Although on GLSL those are set using a layout qualifier to<br>
gl_FragCoord builtin, they are basically a global mode. In fact, on<br>
SPIR-V they are set as an global ExecutionMode, not as a decoration<br>
for the builtin. With this change, we are just mapping them more<br>
similar to SPIR-V, instead of more similar to GLSL.<br>
<br>
FWIW, shader_info.fs already had pixel_center_integer, so this change<br>
also removes some redundancy.<br>
<br>
This change was needed because recently spirv_to_nir changed the order<br>
in which execution modes and variables are handled, so the variables<br>
didn't get the correct values. Now the info is set on the shader<br>
itself.<br>
<br>
Fixes: e68871f6a ("spirv: Handle constants and types before execution<br>
modes")<br>
---<br>
src/compiler/glsl/glsl_to_nir.cpp | 9 +++++++--<br>
src/compiler/nir/nir.h | 8 --------<br>
src/compiler/nir/nir_lower_system_values.c | 6 ------<br>
src/compiler/nir/nir_lower_wpos_ytransform.c | 4 ++--<br>
src/compiler/shader_info.h | 6 ++++++<br>
src/compiler/spirv/spirv_to_nir.c | 4 ++--<br>
src/compiler/spirv/vtn_private.h | 2 --<br>
src/compiler/spirv/vtn_variables.c | 6 ------<br>
src/intel/blorp/blorp_blit.c | 2 +-<br>
src/intel/blorp/blorp_clear.c | 3 ++-<br>
src/intel/blorp/blorp_nir_builder.h | 1 -<br>
src/intel/vulkan/anv_nir_lower_input_attachments.c | 2 +-<br>
src/mesa/program/prog_to_nir.c | 8 ++++----<br>
13 files changed, 25 insertions(+), 36 deletions(-)<br>
<br>
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp<br>
index 09599e4cee7..6ff20e8a692 100644<br>
--- a/src/compiler/glsl/glsl_to_nir.cpp<br>
+++ b/src/compiler/glsl/glsl_to_nir.cpp<br>
@@ -397,8 +397,13 @@ nir_visitor::visit(ir_variable *ir)<br>
}<br>
<br>
var->data.interpolation = ir->data.interpolation;<br>
- var->data.origin_upper_left = ir->data.origin_upper_left;<br>
- var->data.pixel_center_integer = ir->data.pixel_center_integer;<br>
+ /* We only set the values of origin_upper_left and pixel_center_integer if<br>
+ * they are set, to avoid following variables ovewritting them<br>
+ */<br>
+ if (ir->data.origin_upper_left)<br>
+ shader->info.fs.origin_upper_left = ir->data.origin_upper_left;<br>
+ if (ir->data.pixel_center_integer)<br>
+ shader->info.fs.pixel_center_integer = ir->data.pixel_center_integer;<br></blockquote><div><br></div><div>We should make this conditional on the variable being a fragment system value and having a location of SYSTEM_VALUE_FRAG_COORD. That should also prevent it from happening twice. Also, this could be made part of the info gathering pass that gets run on GLSL shaders instead of part of glsl_to_nir.</div><div><br></div><div>Other than that, I really like this approach.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
var->data.location_frac = ir->data.location_frac;<br>
<br>
switch (ir->data.depth_layout) {<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index ff2c41faf27..bb2d3884acb 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -237,14 +237,6 @@ typedef struct nir_variable {<br>
*/<br>
unsigned interpolation:2;<br>
<br>
- /**<br>
- * \name ARB_fragment_coord_conventions<br>
- * @{<br>
- */<br>
- unsigned origin_upper_left:1;<br>
- unsigned pixel_center_integer:1;<br>
- /*@}*/<br>
-<br>
/**<br>
* If non-zero, then this variable may be packed along with other variables<br>
* into a single varying slot, so this offset should be applied when<br>
diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c<br>
index 7c1aa5fa801..68b0ea89c8d 100644<br>
--- a/src/compiler/nir/nir_lower_system_values.c<br>
+++ b/src/compiler/nir/nir_lower_system_values.c<br>
@@ -254,12 +254,6 @@ convert_block(nir_block *block, nir_builder *b)<br>
break;<br>
}<br>
<br>
- case SYSTEM_VALUE_FRAG_COORD:<br>
- assert(b->shader->info.stage == MESA_SHADER_FRAGMENT);<br>
- b->shader->info.fs.pixel_center_integer =<br>
- var->data.pixel_center_integer;<br>
- break;<br>
-<br>
default:<br>
break;<br>
}<br>
diff --git a/src/compiler/nir/nir_lower_wpos_ytransform.c b/src/compiler/nir/nir_lower_wpos_ytransform.c<br>
index 444e211b680..34a4801d66b 100644<br>
--- a/src/compiler/nir/nir_lower_wpos_ytransform.c<br>
+++ b/src/compiler/nir/nir_lower_wpos_ytransform.c<br>
@@ -181,7 +181,7 @@ lower_fragcoord(lower_wpos_ytransform_state *state,<br>
* u,h -> l,i: (99.5 + 0.5) * -1 + 100 = 0<br>
*/<br>
<br>
- if (fragcoord->data.origin_upper_left) {<br>
+ if (state->shader->info.fs.origin_upper_left) {<br>
/* Fragment shader wants origin in upper-left */<br>
if (options->fs_coord_origin_upper_left) {<br>
/* the driver supports upper-left origin */<br>
@@ -203,7 +203,7 @@ lower_fragcoord(lower_wpos_ytransform_state *state,<br>
}<br>
}<br>
<br>
- if (fragcoord->data.pixel_center_integer) {<br>
+ if (state->shader->info.fs.pixel_center_integer) {<br>
/* Fragment shader wants pixel center integer */<br>
if (options->fs_coord_pixel_center_integer) {<br>
/* the driver supports pixel center integer */<br>
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h<br>
index 3d871938751..12f869ebb52 100644<br>
--- a/src/compiler/shader_info.h<br>
+++ b/src/compiler/shader_info.h<br>
@@ -192,7 +192,13 @@ typedef struct shader_info {<br>
<br>
bool post_depth_coverage;<br>
<br>
+ /**<br>
+ * \name ARB_fragment_coord_conventions<br>
+ * @{<br>
+ */<br>
bool pixel_center_integer;<br>
+ bool origin_upper_left:1;<br>
+ /*@}*/<br>
<br>
bool pixel_interlock_ordered;<br>
bool pixel_interlock_unordered;<br>
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c<br>
index 1cbc926c818..945214aca00 100644<br>
--- a/src/compiler/spirv/spirv_to_nir.c<br>
+++ b/src/compiler/spirv/spirv_to_nir.c<br>
@@ -3784,7 +3784,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,<br>
switch(mode->exec_mode) {<br>
case SpvExecutionModeOriginUpperLeft:<br>
case SpvExecutionModeOriginLowerLeft:<br>
- b->origin_upper_left =<br>
+ b->shader->info.fs.origin_upper_left =<br>
(mode->exec_mode == SpvExecutionModeOriginUpperLeft);<br>
break;<br>
<br>
@@ -3907,7 +3907,7 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,<br>
break;<br>
<br>
case SpvExecutionModePixelCenterInteger:<br>
- b->pixel_center_integer = true;<br>
+ b->shader->info.fs.pixel_center_integer = true;<br>
break;<br>
<br>
case SpvExecutionModeXfb:<br>
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h<br>
index 63313034ba6..f3d54051885 100644<br>
--- a/src/compiler/spirv/vtn_private.h<br>
+++ b/src/compiler/spirv/vtn_private.h<br>
@@ -601,8 +601,6 @@ struct vtn_builder {<br>
const char *entry_point_name;<br>
struct vtn_value *entry_point;<br>
struct vtn_value *workgroup_size_builtin;<br>
- bool origin_upper_left;<br>
- bool pixel_center_integer;<br>
bool variable_pointers;<br>
<br>
struct vtn_function *func;<br>
diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c<br>
index f6b458b7e78..51152520bb6 100644<br>
--- a/src/compiler/spirv/vtn_variables.c<br>
+++ b/src/compiler/spirv/vtn_variables.c<br>
@@ -1448,12 +1448,6 @@ apply_var_decoration(struct vtn_builder *b,<br>
case SpvBuiltInCullDistance:<br>
var_data->compact = true;<br>
break;<br>
- case SpvBuiltInFragCoord:<br>
- var_data->pixel_center_integer = b->pixel_center_integer;<br>
- /* fallthrough */<br>
- case SpvBuiltInSamplePosition:<br>
- var_data->origin_upper_left = b->origin_upper_left;<br>
- break;<br>
default:<br>
break;<br>
}<br>
diff --git a/src/intel/blorp/blorp_blit.c b/src/intel/blorp/blorp_blit.c<br>
index b4bd9aac19a..ad93f58ae53 100644<br>
--- a/src/intel/blorp/blorp_blit.c<br>
+++ b/src/intel/blorp/blorp_blit.c<br>
@@ -87,7 +87,7 @@ brw_blorp_blit_vars_init(nir_builder *b, struct brw_blorp_blit_vars *v,<br>
v->frag_coord = nir_variable_create(b->shader, nir_var_shader_in,<br>
glsl_vec4_type(), "gl_FragCoord");<br>
v->frag_coord->data.location = VARYING_SLOT_POS;<br>
- v->frag_coord->data.origin_upper_left = true;<br>
+ b->shader->info.fs.origin_upper_left = true;<br>
<br>
v->color_out = nir_variable_create(b->shader, nir_var_shader_out,<br>
glsl_vec4_type(), "gl_FragColor");<br>
diff --git a/src/intel/blorp/blorp_clear.c b/src/intel/blorp/blorp_clear.c<br>
index 0b26755e90a..181b492ab1f 100644<br>
--- a/src/intel/blorp/blorp_clear.c<br>
+++ b/src/intel/blorp/blorp_clear.c<br>
@@ -75,7 +75,7 @@ blorp_params_get_clear_kernel(struct blorp_batch *batch,<br>
nir_variable_create(b.shader, nir_var_shader_in,<br>
glsl_vec4_type(), "gl_FragCoord");<br>
frag_coord->data.location = VARYING_SLOT_POS;<br>
- frag_coord->data.origin_upper_left = true;<br>
+ b.shader->info.fs.origin_upper_left = true;<br>
<br>
nir_ssa_def *pos = nir_f2i32(&b, nir_load_var(&b, frag_coord));<br>
nir_ssa_def *comp = nir_umod(&b, nir_channel(&b, pos, 0),<br>
@@ -969,6 +969,7 @@ blorp_params_get_mcs_partial_resolve_kernel(struct blorp_batch *batch,<br>
frag_color->data.location = FRAG_RESULT_COLOR;<br>
<br>
/* Do an MCS fetch and check if it is equal to the magic clear value */<br>
+ b.shader->info.fs.origin_upper_left = true;<br>
nir_ssa_def *mcs =<br>
blorp_nir_txf_ms_mcs(&b, nir_f2i32(&b, blorp_nir_frag_coord(&b)),<br>
nir_load_layer_id(&b));<br>
diff --git a/src/intel/blorp/blorp_nir_builder.h b/src/intel/blorp/blorp_nir_builder.h<br>
index 7f23abdef4d..289cfb782c4 100644<br>
--- a/src/intel/blorp/blorp_nir_builder.h<br>
+++ b/src/intel/blorp/blorp_nir_builder.h<br>
@@ -31,7 +31,6 @@ blorp_nir_frag_coord(nir_builder *b)<br>
glsl_vec4_type(), "gl_FragCoord");<br>
<br>
frag_coord->data.location = VARYING_SLOT_POS;<br>
- frag_coord->data.origin_upper_left = true;<br>
<br>
return nir_load_var(b, frag_coord);<br>
}<br>
diff --git a/src/intel/vulkan/anv_nir_lower_input_attachments.c b/src/intel/vulkan/anv_nir_lower_input_attachments.c<br>
index 655e5844955..6568ec860fb 100644<br>
--- a/src/intel/vulkan/anv_nir_lower_input_attachments.c<br>
+++ b/src/intel/vulkan/anv_nir_lower_input_attachments.c<br>
@@ -35,7 +35,7 @@ load_frag_coord(nir_builder *b)<br>
nir_variable *pos = nir_variable_create(b->shader, nir_var_shader_in,<br>
glsl_vec4_type(), NULL);<br>
pos->data.location = VARYING_SLOT_POS;<br>
- pos->data.origin_upper_left = true;<br>
+ b->shader->info.fs.origin_upper_left = true;<br>
<br>
return nir_load_var(b, pos);<br>
}<br>
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c<br>
index afa490cdb36..84ffdd0c510 100644<br>
--- a/src/mesa/program/prog_to_nir.c<br>
+++ b/src/mesa/program/prog_to_nir.c<br>
@@ -880,8 +880,8 @@ setup_registers_and_variables(struct ptn_compile *c)<br>
<br>
if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB) {<br>
if (i == VARYING_SLOT_POS) {<br>
- var->data.origin_upper_left = c->prog->OriginUpperLeft;<br>
- var->data.pixel_center_integer = c->prog->PixelCenterInteger;<br>
+ shader->info.fs.origin_upper_left = c->prog->OriginUpperLeft;<br>
+ shader->info.fs.pixel_center_integer = c->prog->PixelCenterInteger;<br>
} else if (i == VARYING_SLOT_FOGC) {<br>
/* fogcoord is defined as <f, 0.0, 0.0, 1.0>. Make the actual<br>
* input variable a float, and create a local containing the<br>
@@ -925,8 +925,8 @@ setup_registers_and_variables(struct ptn_compile *c)<br>
<br>
if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB &&<br>
i == SYSTEM_VALUE_FRAG_COORD) {<br>
- var->data.origin_upper_left = c->prog->OriginUpperLeft;<br>
- var->data.pixel_center_integer = c->prog->PixelCenterInteger;<br>
+ shader->info.fs.origin_upper_left = c->prog->OriginUpperLeft;<br>
+ shader->info.fs.pixel_center_integer = c->prog->PixelCenterInteger;<br></blockquote><div><br></div><div>The fact that ARB programs also match kind-of confirms for me that this is the right solution. That said, we probably shouldn't be handling this in variable setup; we should probably, again, make it part of a more general info-gathering.</div><div><br></div><div>--Jason<br></div></div></div>