aco: fix adjusting the sample index with FMASK if value is negative
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 27 Apr 2020 15:27:22 +0000 (17:27 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 07:29:54 +0000 (07:29 +0000)
The SPIR-V spec doesn't say explicitly that the sample index
must be an unsigned integer.

This fixes crashes with some new VK_EXT_robustness2 tests.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4775>

src/amd/compiler/aco_instruction_selection.cpp

index b6456a0fcf7d6c2ea66ba9f054189f9e3ca75a0d..16d76be03c990597c87f36f26692fc21b1673ace 100644 (file)
@@ -5659,8 +5659,12 @@ static Temp adjust_sample_index_using_fmask(isel_context *ctx, bool da, std::vec
    ctx->block->instructions.emplace_back(std::move(load));
 
    Operand sample_index4;
-   if (sample_index.isConstant() && sample_index.constantValue() < 16) {
-      sample_index4 = Operand(sample_index.constantValue() << 2);
+   if (sample_index.isConstant()) {
+      if (sample_index.constantValue() < 16) {
+         sample_index4 = Operand(sample_index.constantValue() << 2);
+      } else {
+         sample_index4 = Operand(0u);
+      }
    } else if (sample_index.regClass() == s1) {
       sample_index4 = bld.sop2(aco_opcode::s_lshl_b32, bld.def(s1), bld.def(s1, scc), sample_index, Operand(2u));
    } else {