<div dir="ltr"><div>For the first two:</div><div><br></div><div>Reviewed-by: Marek Olšák <<a href="mailto:marek.olsak@amd.com">marek.olsak@amd.com</a>></div><div><br></div><div>Marek<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 6, 2019 at 11:06 PM Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu">imirkin@alum.mit.edu</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">Both AMD and NVIDIA hardware define it this way. Instead of replicating<br>
the logic everywhere, just fix it up in one place.<br>
<br>
Signed-off-by: Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" target="_blank">imirkin@alum.mit.edu</a>><br>
---<br>
<br>
I'm open to also not doing this. Just seems like it'll make our<br>
collective lives a little easier, since this is what the hw wants (and<br>
presumably other APIs ... PTX definitely defines it this way).<br>
<br>
If there's push-back, I can also duplicate the logic in codegen.<br>
<br>
src/gallium/docs/source/tgsi.rst | 2 +-<br>
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c | 12 ------------<br>
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 11 ++++++++++-<br>
3 files changed, 11 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst<br>
index 17ad097e85e..e72b047dbd5 100644<br>
--- a/src/gallium/docs/source/tgsi.rst<br>
+++ b/src/gallium/docs/source/tgsi.rst<br>
@@ -2846,7 +2846,7 @@ These atomic operations may only be used with 32-bit integer image formats.<br>
<br>
dst_x = resource[offset] + 1<br>
<br>
- resource[offset] = dst_x < src_x ? dst_x : 0<br>
+ resource[offset] = dst_x <= src_x ? dst_x : 0<br>
<br>
<br>
.. opcode:: ATOMDEC_WRAP - Atomic decrement + wrap around<br>
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c<br>
index 4a4ba43780a..f79ed2c57e1 100644<br>
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c<br>
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c<br>
@@ -828,18 +828,6 @@ static void atomic_emit(<br>
args.data[num_data++] =<br>
ac_to_integer(&ctx->ac, lp_build_emit_fetch(bld_base, inst, 2, 0));<br>
<br>
- if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMINC_WRAP) {<br>
- /* ATOMIC_INC instruction does:<br>
- * value = (value + 1) % (data + 1)<br>
- * but we want:<br>
- * value = (value + 1) % data<br>
- * So replace 'data' by 'data - 1'.<br>
- */<br>
- args.data[0] = LLVMBuildSub(ctx->ac.builder,<br>
- args.data[0],<br>
- ctx->ac.i32_1, "");<br>
- }<br>
-<br>
args.cache_policy = get_cache_policy(ctx, inst, true, false, false);<br>
<br>
if (inst->Src[0].Register.File == TGSI_FILE_BUFFER) {<br>
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp<br>
index ff2ec0726e8..9b982569490 100644<br>
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp<br>
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp<br>
@@ -3938,9 +3938,18 @@ glsl_to_tgsi_visitor::visit_image_intrinsic(ir_call *ir)<br>
case ir_intrinsic_image_atomic_comp_swap:<br>
opcode = TGSI_OPCODE_ATOMCAS;<br>
break;<br>
- case ir_intrinsic_image_atomic_inc_wrap:<br>
+ case ir_intrinsic_image_atomic_inc_wrap: {<br>
+ /* There's a bit of disagreement between GLSL and the hardware. The<br>
+ * hardware wants to wrap after the given wrap value, while GLSL<br>
+ * wants to wrap at the value. Subtract 1 to make up the difference.<br>
+ */<br>
+ st_src_reg wrap = get_temp(glsl_type::uint_type);<br>
+ emit_asm(ir, TGSI_OPCODE_ADD, st_dst_reg(wrap),<br>
+ arg1, st_src_reg_for_int(-1));<br>
+ arg1 = wrap;<br>
opcode = TGSI_OPCODE_ATOMINC_WRAP;<br>
break;<br>
+ }<br>
case ir_intrinsic_image_atomic_dec_wrap:<br>
opcode = TGSI_OPCODE_ATOMDEC_WRAP;<br>
break;<br>
-- <br>
2.21.0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a></blockquote></div>