[Mesa-dev] [PATCH v2 2/2] r600: set rounding mode for texture array layer selection

Gert Wollny gert.wollny at collabora.com
Fri Jun 29 14:35:37 UTC 2018


The evaluation of the array layer index is "floor(z+0.5)", and the default
rounding mode doesn't correctly evaluate this. Therefore, set the rounding
mode to "trunc" and z-filter mode to "point".
For other textures make sure the the default rounding mode and z-filter are
used.

Fixes single-sample tests out of:
  dEQP-GLES3.functional.texture.shadow.2d_array.*
  dEQP-GLES3.functional.texture.vertex.2d_array.*
  dEQP-GLES3.functional.texture.filtering.2d_array.*
(With the single sample tests the rounding accuracy is tested too)

v2: * reword comments and commit message
    * clear S_03C008_TRUNC_COORD for all non-array types

Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
---
 src/gallium/drivers/r600/evergreen_state.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index a484f0078a..b8ed4fea33 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -2413,6 +2413,28 @@ static void evergreen_emit_sampler_states(struct r600_context *rctx,
 		rstate = texinfo->states.states[i];
 		assert(rstate);
 
+		/* For texture arrays the formula select the layer is (floor(z + 0.5)) and
+		 * apparently tha hardware doesn't trigger this when the texture is in ARRAY mode
+		 * Neither does the default z-rounding mode provide the required 0.5 shift
+		 * nor does it round with sufficinet accuracy. Consequently set the coordinate
+		 * interpolation and truncate mode here to get "floor" for positive coordinates.
+		 * Adding the 0.5 offset is done in the shader.
+		 * Also  make sure that for other texture types the default is used.
+		 */
+		struct r600_pipe_sampler_view	*rview = texinfo->views.views[i];
+		if (rview) {
+			rstate->tex_sampler_words[0] &= C_03C000_Z_FILTER;
+			enum pipe_texture_target target = rview->base.texture->target;
+			if (target == PIPE_TEXTURE_2D_ARRAY ||
+				target == PIPE_TEXTURE_CUBE_ARRAY ||
+				target == PIPE_TEXTURE_1D_ARRAY) {
+				rstate->tex_sampler_words[0] |= S_03C000_Z_FILTER(V_03C000_SQ_TEX_Z_FILTER_POINT);
+				rstate->tex_sampler_words[2] |= S_03C008_TRUNCATE_COORD(1);
+			} else {
+				rstate->tex_sampler_words[2] &= C_03C008_TRUNCATE_COORD;
+			}
+		}
+
 		radeon_emit(cs, PKT3(PKT3_SET_SAMPLER, 3, 0) | pkt_flags);
 		radeon_emit(cs, (resource_id_base + i) * 3);
 		radeon_emit_array(cs, rstate->tex_sampler_words, 3);
-- 
2.16.4



More information about the mesa-dev mailing list