Mesa (main): r300: set PVS_XYZW_VALID_INST properly to last position write

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 1 21:24:56 UTC 2022


Module: Mesa
Branch: main
Commit: fb233ac411a2923119e0b3053bf677c9a550074d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fb233ac411a2923119e0b3053bf677c9a550074d

Author: Pavel Ondračka <pavel.ondracka at gmail.com>
Date:   Fri Mar  4 10:27:54 2022 +0100

r300: set PVS_XYZW_VALID_INST properly to last position write

This is a potential performance optimization, from the docs:
The PVS Instruction which updates the clip coordinatea position for
the last time. This value is used to lower the processing priority
while trivial clip and back-face culling decisions are made. This
field must be set to valid instruction.

Right now it is set at the last instruction. However, there is no
measurable performance effect in either Unigine Sanctuary, Lightsmark
or GLmark.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6045
Signed-off-by: Pavel Ondračka <pavel.ondracka at gmail.com>
Reviewed-by: Filip Gawin <filip.gawin at zoho.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15677>

---

 src/gallium/drivers/r300/compiler/r3xx_vertprog.c | 15 +++++++++++++++
 src/gallium/drivers/r300/compiler/radeon_code.h   |  1 +
 src/gallium/drivers/r300/r300_emit.c              |  2 +-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r300/compiler/r3xx_vertprog.c b/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
index bbfbf6ea9dd..3814698047d 100644
--- a/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
+++ b/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
@@ -372,11 +372,13 @@ static void translate_vertex_program(struct radeon_compiler *c, void *user)
 	unsigned loops[R500_PVS_MAX_LOOP_DEPTH] = {};
 	unsigned loop_depth = 0;
 	bool last_input_read_at_loop_end = false;
+	bool last_pos_write_at_loop_end = false;
 
 	compiler->code->pos_end = 0;	/* Not supported yet */
 	compiler->code->length = 0;
 	compiler->code->num_temporaries = 0;
 	compiler->code->last_input_read = 0;
+	compiler->code->last_pos_write = 0;
 
 	compiler->SetHwInputOutput(compiler);
 
@@ -454,6 +456,10 @@ static void translate_vertex_program(struct radeon_compiler *c, void *user)
 				compiler->code->last_input_read = compiler->code->length / 4;
 				last_input_read_at_loop_end = false;
 			}
+			if (loop_depth == 1 && last_pos_write_at_loop_end) {
+				compiler->code->last_pos_write = compiler->code->length / 4;
+				last_pos_write_at_loop_end = false;
+			}
 
 			ret_addr = loops[--loop_depth];
 			act_addr = ret_addr - 1;
@@ -543,6 +549,15 @@ static void translate_vertex_program(struct radeon_compiler *c, void *user)
 		    vpi->DstReg.Index >= compiler->code->num_temporaries)
 			compiler->code->num_temporaries = vpi->DstReg.Index + 1;
 
+		/* last instruction that writes position */
+		if (info->HasDstReg && vpi->DstReg.File == RC_FILE_OUTPUT &&
+		    t_dst_index(compiler->code, &vpi->DstReg) == 0) {
+			if (loop_depth == 0)
+				compiler->code->last_pos_write = compiler->code->length / 4;
+			else
+				last_pos_write_at_loop_end = true;
+		}
+
 		for (unsigned i = 0; i < info->NumSrcRegs; i++) {
 			if (vpi->SrcReg[i].File == RC_FILE_TEMPORARY &&
 			    vpi->SrcReg[i].Index >= compiler->code->num_temporaries)
diff --git a/src/gallium/drivers/r300/compiler/radeon_code.h b/src/gallium/drivers/r300/compiler/radeon_code.h
index 52bfab7f1f5..f362da46c07 100644
--- a/src/gallium/drivers/r300/compiler/radeon_code.h
+++ b/src/gallium/drivers/r300/compiler/radeon_code.h
@@ -271,6 +271,7 @@ struct r300_vertex_program_code {
 	int inputs[VSF_MAX_INPUTS];
 	int outputs[VSF_MAX_OUTPUTS];
 	unsigned last_input_read;
+	unsigned last_pos_write;
 
 	struct rc_constant_list constants;
 	unsigned *constants_remap_table;
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index f6212582c2a..f28cdb7252f 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -1126,7 +1126,7 @@ void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state)
      * R300_VAP_PVS_CODE_CNTL_1
      * See the r5xx docs for instructions on how to use these. */
     OUT_CS_REG(R300_VAP_PVS_CODE_CNTL_0, R300_PVS_FIRST_INST(0) |
-	       R300_PVS_XYZW_VALID_INST(instruction_count - 1) |
+	       R300_PVS_XYZW_VALID_INST(code->last_pos_write) |
 	       R300_PVS_LAST_INST(instruction_count - 1));
     OUT_CS_REG(R300_VAP_PVS_CODE_CNTL_1, code->last_input_read);
 



More information about the mesa-commit mailing list