OSDN Git Service

Eliminate Intermediate::replace()
authorNicolas Capens <capn@google.com>
Wed, 27 Mar 2019 19:27:27 +0000 (15:27 -0400)
committerNicolas Capens <nicolascapens@google.com>
Mon, 1 Apr 2019 14:46:35 +0000 (14:46 +0000)
With Reactor variables now merely tracking the last assigned rvalue if
used within a single basic block, we can avoid the unsafe replace()
operation on SpirvShader::Intermediate.

This effectively reverts
https://swiftshader-review.googlesource.com/c/SwiftShader/+/27769

Bug b/129356087
Bug b/128527271

Change-Id: Ibfafc6960ac7e10b898ff8804752b928a7fc1988
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28109
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
src/Pipeline/SpirvShader.cpp
src/Pipeline/SpirvShader.hpp

index e64c953..2106bdc 100644 (file)
@@ -1277,14 +1277,13 @@ namespace sw
                if (blockId != mainBlockId)
                {
                        // Set the activeLaneMask.
-                       Intermediate activeLaneMask(1);
-                       activeLaneMask.move(0, SIMD::Int(0));
+                       SIMD::Int activeLaneMask(0);
                        for (auto in : block.ins)
                        {
                                auto inMask = GetActiveLaneMaskEdge(state, in, blockId);
-                               activeLaneMask.replace(0, activeLaneMask.Int(0) | inMask);
+                               activeLaneMask |= inMask;
                        }
-                       state->setActiveLaneMask(activeLaneMask.Int(0));
+                       state->setActiveLaneMask(activeLaneMask);
                }
 
                EmitInstructions(block.begin(), block.end(), state);
@@ -3030,7 +3029,7 @@ namespace sw
                auto type = getType(typeId);
                auto objectId = Object::ID(insn.word(2));
 
-               auto &dst = routine->createIntermediate(objectId, type.sizeInComponents);
+               auto tmp = std::unique_ptr<SIMD::Int[]>(new SIMD::Int[type.sizeInComponents]);
 
                bool first = true;
                for (uint32_t w = 3; w < insn.wordCount(); w += 2)
@@ -3044,11 +3043,17 @@ namespace sw
                        for (uint32_t i = 0; i < type.sizeInComponents; i++)
                        {
                                auto inMasked = in.Int(i) & mask;
-                               dst.replace(i, first ? inMasked : (dst.Int(i) | inMasked));
+                               tmp[i] = first ? inMasked : (tmp[i] | inMasked);
                        }
                        first = false;
                }
 
+               auto &dst = routine->createIntermediate(objectId, type.sizeInComponents);
+               for(uint32_t i = 0; i < type.sizeInComponents; i++)
+               {
+                       dst.move(i, tmp[i]);
+               }
+
                return EmitResult::Continue;
        }
 
index d7d4b4e..5bcef33 100644 (file)
@@ -86,14 +86,6 @@ namespace sw
                void move(uint32_t i, const RValue<SIMD::Int> &scalar)   { emplace(i, scalar.value); }
                void move(uint32_t i, const RValue<SIMD::UInt> &scalar)  { emplace(i, scalar.value); }
 
-               void replace(uint32_t i, RValue<SIMD::Float> &&scalar) { replace(i, scalar.value); }
-               void replace(uint32_t i, RValue<SIMD::Int> &&scalar)   { replace(i, scalar.value); }
-               void replace(uint32_t i, RValue<SIMD::UInt> &&scalar)  { replace(i, scalar.value); }
-
-               void replace(uint32_t i, const RValue<SIMD::Float> &scalar) { replace(i, scalar.value); }
-               void replace(uint32_t i, const RValue<SIMD::Int> &scalar)   { replace(i, scalar.value); }
-               void replace(uint32_t i, const RValue<SIMD::UInt> &scalar)  { replace(i, scalar.value); }
-
                // Value retrieval functions.
                RValue<SIMD::Float> Float(uint32_t i) const
                {
@@ -130,12 +122,6 @@ namespace sw
                        scalar[i] = value;
                }
 
-               void replace(uint32_t i, rr::Value *value)
-               {
-                       ASSERT(i < size);
-                       scalar[i] = value;
-               }
-
                rr::Value **const scalar;
                uint32_t size;
        };