external/swiftshader
リビジョン | 711867566999bc34b019a4666302f990a08fd1cd (tree) |
---|---|
日時 | 2020-04-14 10:16:06 |
作者 | Nicolas Capens <capn@goog...> |
コミッター | Nicolas Capens |
Use the type and result ID helpers
Avoid directly accessing SPIR-V instruction words. The helper methods
provide self-explanatory semantics so we can eliminate local variables
to store these IDs.
Bug: b/129000021
Change-Id: Ie42782d53b9c24014b6a1b1f51b82085b6c2ebef
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43694
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
@@ -816,15 +816,16 @@ void SpirvShader::ProcessInterfaceVariable(Object &object) | ||
816 | 816 | |
817 | 817 | if(objectTy.isBuiltInBlock) |
818 | 818 | { |
819 | - // walk the builtin block, registering each of its members separately. | |
819 | + // Walk the builtin block, registering each of its members separately. | |
820 | 820 | auto m = memberDecorations.find(objectTy.element); |
821 | - ASSERT(m != memberDecorations.end()); // otherwise we wouldn't have marked the type chain | |
821 | + ASSERT(m != memberDecorations.end()); // Otherwise we wouldn't have marked the type chain | |
822 | 822 | auto &structType = pointeeTy.definition; |
823 | + auto memberIndex = 0u; | |
823 | 824 | auto offset = 0u; |
824 | - auto word = 2u; | |
825 | + | |
825 | 826 | for(auto &member : m->second) |
826 | 827 | { |
827 | - auto &memberType = getType(structType.word(word)); | |
828 | + auto &memberType = getType(structType.word(2 + memberIndex)); | |
828 | 829 | |
829 | 830 | if(member.HasBuiltIn) |
830 | 831 | { |
@@ -832,8 +833,9 @@ void SpirvShader::ProcessInterfaceVariable(Object &object) | ||
832 | 833 | } |
833 | 834 | |
834 | 835 | offset += memberType.sizeInComponents; |
835 | - ++word; | |
836 | + ++memberIndex; | |
836 | 837 | } |
838 | + | |
837 | 839 | return; |
838 | 840 | } |
839 | 841 |
@@ -1510,22 +1512,19 @@ void SpirvShader::emitProlog(SpirvRoutine *routine) const | ||
1510 | 1512 | { |
1511 | 1513 | case spv::OpVariable: |
1512 | 1514 | { |
1513 | - Type::ID resultPointerTypeId = insn.word(1); | |
1514 | - auto resultPointerType = getType(resultPointerTypeId); | |
1515 | + auto resultPointerType = getType(insn.resultTypeId()); | |
1515 | 1516 | auto pointeeType = getType(resultPointerType.element); |
1516 | 1517 | |
1517 | 1518 | if(pointeeType.sizeInComponents > 0) // TODO: what to do about zero-slot objects? |
1518 | 1519 | { |
1519 | - Object::ID resultId = insn.word(2); | |
1520 | - routine->createVariable(resultId, pointeeType.sizeInComponents); | |
1520 | + routine->createVariable(insn.resultId(), pointeeType.sizeInComponents); | |
1521 | 1521 | } |
1522 | 1522 | break; |
1523 | 1523 | } |
1524 | 1524 | case spv::OpPhi: |
1525 | 1525 | { |
1526 | - auto type = getType(insn.word(1)); | |
1527 | - Object::ID resultId = insn.word(2); | |
1528 | - routine->phis.emplace(resultId, SpirvRoutine::Variable(type.sizeInComponents)); | |
1526 | + auto type = getType(insn.resultTypeId()); | |
1527 | + routine->phis.emplace(insn.resultId(), SpirvRoutine::Variable(type.sizeInComponents)); | |
1529 | 1528 | break; |
1530 | 1529 | } |
1531 | 1530 |
@@ -1541,11 +1540,8 @@ void SpirvShader::emitProlog(SpirvRoutine *routine) const | ||
1541 | 1540 | case spv::OpImageSampleProjDrefImplicitLod: |
1542 | 1541 | case spv::OpImageSampleProjExplicitLod: |
1543 | 1542 | case spv::OpImageSampleProjImplicitLod: |
1544 | - { | |
1545 | - Object::ID resultId = insn.word(2); | |
1546 | - routine->samplerCache.emplace(resultId, SpirvRoutine::SamplerCache{}); | |
1543 | + routine->samplerCache.emplace(insn.resultId(), SpirvRoutine::SamplerCache{}); | |
1547 | 1544 | break; |
1548 | - } | |
1549 | 1545 | |
1550 | 1546 | default: |
1551 | 1547 | // Nothing else produces interface variables, so can all be safely ignored. |
@@ -1998,8 +1994,8 @@ SpirvShader::EmitResult SpirvShader::EmitAccessChain(InsnIterator insn, EmitStat | ||
1998 | 1994 | |
1999 | 1995 | SpirvShader::EmitResult SpirvShader::EmitCompositeConstruct(InsnIterator insn, EmitState *state) const |
2000 | 1996 | { |
2001 | - auto &type = getType(insn.word(1)); | |
2002 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
1997 | + auto &type = getType(insn.resultTypeId()); | |
1998 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2003 | 1999 | auto offset = 0u; |
2004 | 2000 | |
2005 | 2001 | for(auto i = 0u; i < insn.wordCount() - 3; i++) |
@@ -2022,7 +2018,7 @@ SpirvShader::EmitResult SpirvShader::EmitCompositeInsert(InsnIterator insn, Emit | ||
2022 | 2018 | { |
2023 | 2019 | Type::ID resultTypeId = insn.word(1); |
2024 | 2020 | auto &type = getType(resultTypeId); |
2025 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2021 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2026 | 2022 | auto &newPartObject = getObject(insn.word(3)); |
2027 | 2023 | auto &newPartObjectTy = getType(newPartObject); |
2028 | 2024 | auto firstNewComponent = WalkLiteralAccessChain(resultTypeId, insn.wordCount() - 5, insn.wordPointer(5)); |
@@ -2051,8 +2047,8 @@ SpirvShader::EmitResult SpirvShader::EmitCompositeInsert(InsnIterator insn, Emit | ||
2051 | 2047 | |
2052 | 2048 | SpirvShader::EmitResult SpirvShader::EmitCompositeExtract(InsnIterator insn, EmitState *state) const |
2053 | 2049 | { |
2054 | - auto &type = getType(insn.word(1)); | |
2055 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2050 | + auto &type = getType(insn.resultTypeId()); | |
2051 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2056 | 2052 | auto &compositeObject = getObject(insn.word(3)); |
2057 | 2053 | Type::ID compositeTypeId = compositeObject.definition.word(1); |
2058 | 2054 | auto firstComponent = WalkLiteralAccessChain(compositeTypeId, insn.wordCount() - 4, insn.wordPointer(4)); |
@@ -2068,8 +2064,8 @@ SpirvShader::EmitResult SpirvShader::EmitCompositeExtract(InsnIterator insn, Emi | ||
2068 | 2064 | |
2069 | 2065 | SpirvShader::EmitResult SpirvShader::EmitVectorShuffle(InsnIterator insn, EmitState *state) const |
2070 | 2066 | { |
2071 | - auto &type = getType(insn.word(1)); | |
2072 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2067 | + auto &type = getType(insn.resultTypeId()); | |
2068 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2073 | 2069 | |
2074 | 2070 | // Note: number of components in result type, first half type, and second |
2075 | 2071 | // half type are all independent. |
@@ -2102,8 +2098,8 @@ SpirvShader::EmitResult SpirvShader::EmitVectorShuffle(InsnIterator insn, EmitSt | ||
2102 | 2098 | |
2103 | 2099 | SpirvShader::EmitResult SpirvShader::EmitVectorExtractDynamic(InsnIterator insn, EmitState *state) const |
2104 | 2100 | { |
2105 | - auto &type = getType(insn.word(1)); | |
2106 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2101 | + auto &type = getType(insn.resultTypeId()); | |
2102 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2107 | 2103 | auto &srcType = getType(getObject(insn.word(3))); |
2108 | 2104 | |
2109 | 2105 | Operand src(this, state, insn.word(3)); |
@@ -2122,8 +2118,8 @@ SpirvShader::EmitResult SpirvShader::EmitVectorExtractDynamic(InsnIterator insn, | ||
2122 | 2118 | |
2123 | 2119 | SpirvShader::EmitResult SpirvShader::EmitVectorInsertDynamic(InsnIterator insn, EmitState *state) const |
2124 | 2120 | { |
2125 | - auto &type = getType(insn.word(1)); | |
2126 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2121 | + auto &type = getType(insn.resultTypeId()); | |
2122 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2127 | 2123 | |
2128 | 2124 | Operand src(this, state, insn.word(3)); |
2129 | 2125 | Operand component(this, state, insn.word(4)); |
@@ -2139,8 +2135,8 @@ SpirvShader::EmitResult SpirvShader::EmitVectorInsertDynamic(InsnIterator insn, | ||
2139 | 2135 | |
2140 | 2136 | SpirvShader::EmitResult SpirvShader::EmitSelect(InsnIterator insn, EmitState *state) const |
2141 | 2137 | { |
2142 | - auto &type = getType(insn.word(1)); | |
2143 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2138 | + auto &type = getType(insn.resultTypeId()); | |
2139 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2144 | 2140 | auto cond = Operand(this, state, insn.word(3)); |
2145 | 2141 | auto condIsScalar = (getType(cond).sizeInComponents == 1); |
2146 | 2142 | auto lhs = Operand(this, state, insn.word(4)); |
@@ -2157,9 +2153,9 @@ SpirvShader::EmitResult SpirvShader::EmitSelect(InsnIterator insn, EmitState *st | ||
2157 | 2153 | |
2158 | 2154 | SpirvShader::EmitResult SpirvShader::EmitAny(InsnIterator insn, EmitState *state) const |
2159 | 2155 | { |
2160 | - auto &type = getType(insn.word(1)); | |
2156 | + auto &type = getType(insn.resultTypeId()); | |
2161 | 2157 | ASSERT(type.sizeInComponents == 1); |
2162 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2158 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2163 | 2159 | auto &srcType = getType(getObject(insn.word(3))); |
2164 | 2160 | auto src = Operand(this, state, insn.word(3)); |
2165 | 2161 |
@@ -2176,9 +2172,9 @@ SpirvShader::EmitResult SpirvShader::EmitAny(InsnIterator insn, EmitState *state | ||
2176 | 2172 | |
2177 | 2173 | SpirvShader::EmitResult SpirvShader::EmitAll(InsnIterator insn, EmitState *state) const |
2178 | 2174 | { |
2179 | - auto &type = getType(insn.word(1)); | |
2175 | + auto &type = getType(insn.resultTypeId()); | |
2180 | 2176 | ASSERT(type.sizeInComponents == 1); |
2181 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
2177 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2182 | 2178 | auto &srcType = getType(getObject(insn.word(3))); |
2183 | 2179 | auto src = Operand(this, state, insn.word(3)); |
2184 | 2180 |
@@ -2298,10 +2294,10 @@ SpirvShader::EmitResult SpirvShader::EmitAtomicCompareExchange(InsnIterator insn | ||
2298 | 2294 | |
2299 | 2295 | SpirvShader::EmitResult SpirvShader::EmitCopyObject(InsnIterator insn, EmitState *state) const |
2300 | 2296 | { |
2301 | - auto ty = getType(insn.word(1)); | |
2302 | - auto &dst = state->createIntermediate(insn.word(2), ty.sizeInComponents); | |
2297 | + auto type = getType(insn.resultTypeId()); | |
2298 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
2303 | 2299 | auto src = Operand(this, state, insn.word(3)); |
2304 | - for(uint32_t i = 0; i < ty.sizeInComponents; i++) | |
2300 | + for(uint32_t i = 0; i < type.sizeInComponents; i++) | |
2305 | 2301 | { |
2306 | 2302 | dst.move(i, src.Int(i)); |
2307 | 2303 | } |
@@ -2310,12 +2306,10 @@ SpirvShader::EmitResult SpirvShader::EmitCopyObject(InsnIterator insn, EmitState | ||
2310 | 2306 | |
2311 | 2307 | SpirvShader::EmitResult SpirvShader::EmitArrayLength(InsnIterator insn, EmitState *state) const |
2312 | 2308 | { |
2313 | - auto resultTyId = Type::ID(insn.word(1)); | |
2314 | - auto resultId = Object::ID(insn.word(2)); | |
2315 | 2309 | auto structPtrId = Object::ID(insn.word(3)); |
2316 | 2310 | auto arrayFieldIdx = insn.word(4); |
2317 | 2311 | |
2318 | - auto &resultType = getType(resultTyId); | |
2312 | + auto &resultType = getType(insn.resultTypeId()); | |
2319 | 2313 | ASSERT(resultType.sizeInComponents == 1); |
2320 | 2314 | ASSERT(resultType.definition.opcode() == spv::OpTypeInt); |
2321 | 2315 |
@@ -2323,7 +2317,7 @@ SpirvShader::EmitResult SpirvShader::EmitArrayLength(InsnIterator insn, EmitStat | ||
2323 | 2317 | auto &structTy = getType(structPtrTy.element); |
2324 | 2318 | auto arrayId = Type::ID(structTy.definition.word(2 + arrayFieldIdx)); |
2325 | 2319 | |
2326 | - auto &result = state->createIntermediate(resultId, 1); | |
2320 | + auto &result = state->createIntermediate(insn.resultId(), 1); | |
2327 | 2321 | auto structBase = GetPointerToData(structPtrId, 0, state); |
2328 | 2322 | |
2329 | 2323 | Decorations structDecorations = {}; |
@@ -2374,14 +2368,13 @@ void SpirvShader::emitEpilog(SpirvRoutine *routine) const | ||
2374 | 2368 | { |
2375 | 2369 | case spv::OpVariable: |
2376 | 2370 | { |
2377 | - Object::ID resultId = insn.word(2); | |
2378 | - auto &object = getObject(resultId); | |
2371 | + auto &object = getObject(insn.resultId()); | |
2379 | 2372 | auto &objectTy = getType(object); |
2380 | 2373 | if(object.kind == Object::Kind::InterfaceVariable && objectTy.storageClass == spv::StorageClassOutput) |
2381 | 2374 | { |
2382 | - auto &dst = routine->getVariable(resultId); | |
2375 | + auto &dst = routine->getVariable(insn.resultId()); | |
2383 | 2376 | int offset = 0; |
2384 | - VisitInterface(resultId, | |
2377 | + VisitInterface(insn.resultId(), | |
2385 | 2378 | [&](Decorations const &d, AttribType type) { |
2386 | 2379 | auto scalarSlot = d.Location << 2 | d.Component; |
2387 | 2380 | routine->outputs[scalarSlot] = dst[offset++]; |
@@ -22,8 +22,8 @@ namespace sw { | ||
22 | 22 | |
23 | 23 | SpirvShader::EmitResult SpirvShader::EmitVectorTimesScalar(InsnIterator insn, EmitState *state) const |
24 | 24 | { |
25 | - auto &type = getType(insn.word(1)); | |
26 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
25 | + auto &type = getType(insn.resultTypeId()); | |
26 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
27 | 27 | auto lhs = Operand(this, state, insn.word(3)); |
28 | 28 | auto rhs = Operand(this, state, insn.word(4)); |
29 | 29 |
@@ -37,8 +37,8 @@ SpirvShader::EmitResult SpirvShader::EmitVectorTimesScalar(InsnIterator insn, Em | ||
37 | 37 | |
38 | 38 | SpirvShader::EmitResult SpirvShader::EmitMatrixTimesVector(InsnIterator insn, EmitState *state) const |
39 | 39 | { |
40 | - auto &type = getType(insn.word(1)); | |
41 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
40 | + auto &type = getType(insn.resultTypeId()); | |
41 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
42 | 42 | auto lhs = Operand(this, state, insn.word(3)); |
43 | 43 | auto rhs = Operand(this, state, insn.word(4)); |
44 | 44 | auto rhsType = getType(rhs); |
@@ -58,8 +58,8 @@ SpirvShader::EmitResult SpirvShader::EmitMatrixTimesVector(InsnIterator insn, Em | ||
58 | 58 | |
59 | 59 | SpirvShader::EmitResult SpirvShader::EmitVectorTimesMatrix(InsnIterator insn, EmitState *state) const |
60 | 60 | { |
61 | - auto &type = getType(insn.word(1)); | |
62 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
61 | + auto &type = getType(insn.resultTypeId()); | |
62 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
63 | 63 | auto lhs = Operand(this, state, insn.word(3)); |
64 | 64 | auto rhs = Operand(this, state, insn.word(4)); |
65 | 65 | auto lhsType = getType(lhs); |
@@ -79,8 +79,8 @@ SpirvShader::EmitResult SpirvShader::EmitVectorTimesMatrix(InsnIterator insn, Em | ||
79 | 79 | |
80 | 80 | SpirvShader::EmitResult SpirvShader::EmitMatrixTimesMatrix(InsnIterator insn, EmitState *state) const |
81 | 81 | { |
82 | - auto &type = getType(insn.word(1)); | |
83 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
82 | + auto &type = getType(insn.resultTypeId()); | |
83 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
84 | 84 | auto lhs = Operand(this, state, insn.word(3)); |
85 | 85 | auto rhs = Operand(this, state, insn.word(4)); |
86 | 86 |
@@ -106,8 +106,8 @@ SpirvShader::EmitResult SpirvShader::EmitMatrixTimesMatrix(InsnIterator insn, Em | ||
106 | 106 | |
107 | 107 | SpirvShader::EmitResult SpirvShader::EmitOuterProduct(InsnIterator insn, EmitState *state) const |
108 | 108 | { |
109 | - auto &type = getType(insn.word(1)); | |
110 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
109 | + auto &type = getType(insn.resultTypeId()); | |
110 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
111 | 111 | auto lhs = Operand(this, state, insn.word(3)); |
112 | 112 | auto rhs = Operand(this, state, insn.word(4)); |
113 | 113 | auto &lhsType = getType(lhs); |
@@ -135,8 +135,8 @@ SpirvShader::EmitResult SpirvShader::EmitOuterProduct(InsnIterator insn, EmitSta | ||
135 | 135 | |
136 | 136 | SpirvShader::EmitResult SpirvShader::EmitTranspose(InsnIterator insn, EmitState *state) const |
137 | 137 | { |
138 | - auto &type = getType(insn.word(1)); | |
139 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
138 | + auto &type = getType(insn.resultTypeId()); | |
139 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
140 | 140 | auto mat = Operand(this, state, insn.word(3)); |
141 | 141 | |
142 | 142 | auto numCols = type.definition.word(3); |
@@ -155,8 +155,8 @@ SpirvShader::EmitResult SpirvShader::EmitTranspose(InsnIterator insn, EmitState | ||
155 | 155 | |
156 | 156 | SpirvShader::EmitResult SpirvShader::EmitUnaryOp(InsnIterator insn, EmitState *state) const |
157 | 157 | { |
158 | - auto &type = getType(insn.word(1)); | |
159 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
158 | + auto &type = getType(insn.resultTypeId()); | |
159 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
160 | 160 | auto src = Operand(this, state, insn.word(3)); |
161 | 161 | |
162 | 162 | for(auto i = 0u; i < type.sizeInComponents; i++) |
@@ -317,8 +317,8 @@ SpirvShader::EmitResult SpirvShader::EmitUnaryOp(InsnIterator insn, EmitState *s | ||
317 | 317 | |
318 | 318 | SpirvShader::EmitResult SpirvShader::EmitBinaryOp(InsnIterator insn, EmitState *state) const |
319 | 319 | { |
320 | - auto &type = getType(insn.word(1)); | |
321 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
320 | + auto &type = getType(insn.resultTypeId()); | |
321 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
322 | 322 | auto &lhsType = getType(getObject(insn.word(3))); |
323 | 323 | auto lhs = Operand(this, state, insn.word(3)); |
324 | 324 | auto rhs = Operand(this, state, insn.word(4)); |
@@ -520,9 +520,9 @@ SpirvShader::EmitResult SpirvShader::EmitBinaryOp(InsnIterator insn, EmitState * | ||
520 | 520 | |
521 | 521 | SpirvShader::EmitResult SpirvShader::EmitDot(InsnIterator insn, EmitState *state) const |
522 | 522 | { |
523 | - auto &type = getType(insn.word(1)); | |
523 | + auto &type = getType(insn.resultTypeId()); | |
524 | 524 | ASSERT(type.sizeInComponents == 1); |
525 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
525 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
526 | 526 | auto &lhsType = getType(getObject(insn.word(3))); |
527 | 527 | auto lhs = Operand(this, state, insn.word(3)); |
528 | 528 | auto rhs = Operand(this, state, insn.word(4)); |
@@ -27,8 +27,8 @@ namespace sw { | ||
27 | 27 | |
28 | 28 | SpirvShader::EmitResult SpirvShader::EmitExtGLSLstd450(InsnIterator insn, EmitState *state) const |
29 | 29 | { |
30 | - auto &type = getType(insn.word(1)); | |
31 | - auto &dst = state->createIntermediate(insn.word(2), type.sizeInComponents); | |
30 | + auto &type = getType(insn.resultTypeId()); | |
31 | + auto &dst = state->createIntermediate(insn.resultId(), type.sizeInComponents); | |
32 | 32 | auto extInstIndex = static_cast<GLSLstd450>(insn.word(4)); |
33 | 33 | |
34 | 34 | switch(extInstIndex) |
@@ -107,13 +107,11 @@ SpirvShader::EmitResult SpirvShader::EmitImageFetch(InsnIterator insn, EmitState | ||
107 | 107 | |
108 | 108 | SpirvShader::EmitResult SpirvShader::EmitImageSample(ImageInstruction instruction, InsnIterator insn, EmitState *state) const |
109 | 109 | { |
110 | - Type::ID resultTypeId = insn.word(1); | |
111 | - Object::ID resultId = insn.word(2); | |
112 | 110 | Object::ID sampledImageId = insn.word(3); // For OpImageFetch this is just an Image, not a SampledImage. |
113 | 111 | Object::ID coordinateId = insn.word(4); |
114 | - auto &resultType = getType(resultTypeId); | |
112 | + auto &resultType = getType(insn.resultTypeId()); | |
115 | 113 | |
116 | - auto &result = state->createIntermediate(resultId, resultType.sizeInComponents); | |
114 | + auto &result = state->createIntermediate(insn.resultId(), resultType.sizeInComponents); | |
117 | 115 | auto imageDescriptor = state->getPointer(sampledImageId).base; // vk::SampledImageDescriptor* |
118 | 116 | |
119 | 117 | // If using a separate sampler, look through the OpSampledImage instruction to find the sampler descriptor |
@@ -291,7 +289,7 @@ SpirvShader::EmitResult SpirvShader::EmitImageSample(ImageInstruction instructio | ||
291 | 289 | in[i] = As<SIMD::Float>(sampleValue.Int(0)); |
292 | 290 | } |
293 | 291 | |
294 | - auto cacheIt = state->routine->samplerCache.find(resultId); | |
292 | + auto cacheIt = state->routine->samplerCache.find(insn.resultId()); | |
295 | 293 | ASSERT(cacheIt != state->routine->samplerCache.end()); |
296 | 294 | auto &cache = cacheIt->second; |
297 | 295 | auto cacheHit = cache.imageDescriptor == imageDescriptor && cache.sampler == sampler; |
@@ -313,12 +311,11 @@ SpirvShader::EmitResult SpirvShader::EmitImageSample(ImageInstruction instructio | ||
313 | 311 | |
314 | 312 | SpirvShader::EmitResult SpirvShader::EmitImageQuerySizeLod(InsnIterator insn, EmitState *state) const |
315 | 313 | { |
316 | - auto &resultTy = getType(Type::ID(insn.word(1))); | |
317 | - auto resultId = Object::ID(insn.word(2)); | |
314 | + auto &resultTy = getType(Type::ID(insn.resultTypeId())); | |
318 | 315 | auto imageId = Object::ID(insn.word(3)); |
319 | 316 | auto lodId = Object::ID(insn.word(4)); |
320 | 317 | |
321 | - auto &dst = state->createIntermediate(resultId, resultTy.sizeInComponents); | |
318 | + auto &dst = state->createIntermediate(insn.resultId(), resultTy.sizeInComponents); | |
322 | 319 | GetImageDimensions(state, resultTy, imageId, lodId, dst); |
323 | 320 | |
324 | 321 | return EmitResult::Continue; |
@@ -326,12 +323,11 @@ SpirvShader::EmitResult SpirvShader::EmitImageQuerySizeLod(InsnIterator insn, Em | ||
326 | 323 | |
327 | 324 | SpirvShader::EmitResult SpirvShader::EmitImageQuerySize(InsnIterator insn, EmitState *state) const |
328 | 325 | { |
329 | - auto &resultTy = getType(Type::ID(insn.word(1))); | |
330 | - auto resultId = Object::ID(insn.word(2)); | |
326 | + auto &resultTy = getType(Type::ID(insn.resultTypeId())); | |
331 | 327 | auto imageId = Object::ID(insn.word(3)); |
332 | 328 | auto lodId = Object::ID(0); |
333 | 329 | |
334 | - auto &dst = state->createIntermediate(resultId, resultTy.sizeInComponents); | |
330 | + auto &dst = state->createIntermediate(insn.resultId(), resultTy.sizeInComponents); | |
335 | 331 | GetImageDimensions(state, resultTy, imageId, lodId, dst); |
336 | 332 | |
337 | 333 | return EmitResult::Continue; |
@@ -412,9 +408,8 @@ void SpirvShader::GetImageDimensions(EmitState const *state, Type const &resultT | ||
412 | 408 | |
413 | 409 | SpirvShader::EmitResult SpirvShader::EmitImageQueryLevels(InsnIterator insn, EmitState *state) const |
414 | 410 | { |
415 | - auto &resultTy = getType(Type::ID(insn.word(1))); | |
411 | + auto &resultTy = getType(Type::ID(insn.resultTypeId())); | |
416 | 412 | ASSERT(resultTy.sizeInComponents == 1); |
417 | - auto resultId = Object::ID(insn.word(2)); | |
418 | 413 | auto imageId = Object::ID(insn.word(3)); |
419 | 414 | |
420 | 415 | const DescriptorDecorations &d = descriptorDecorations.at(imageId); |
@@ -434,7 +429,7 @@ SpirvShader::EmitResult SpirvShader::EmitImageQueryLevels(InsnIterator insn, Emi | ||
434 | 429 | UNREACHABLE("Image descriptorType: %d", int(bindingLayout.descriptorType)); |
435 | 430 | } |
436 | 431 | |
437 | - auto &dst = state->createIntermediate(resultId, 1); | |
432 | + auto &dst = state->createIntermediate(insn.resultId(), 1); | |
438 | 433 | dst.move(0, SIMD::Int(mipLevels)); |
439 | 434 | |
440 | 435 | return EmitResult::Continue; |
@@ -442,9 +437,8 @@ SpirvShader::EmitResult SpirvShader::EmitImageQueryLevels(InsnIterator insn, Emi | ||
442 | 437 | |
443 | 438 | SpirvShader::EmitResult SpirvShader::EmitImageQuerySamples(InsnIterator insn, EmitState *state) const |
444 | 439 | { |
445 | - auto &resultTy = getType(Type::ID(insn.word(1))); | |
440 | + auto &resultTy = getType(Type::ID(insn.resultTypeId())); | |
446 | 441 | ASSERT(resultTy.sizeInComponents == 1); |
447 | - auto resultId = Object::ID(insn.word(2)); | |
448 | 442 | auto imageId = Object::ID(insn.word(3)); |
449 | 443 | auto imageTy = getType(getObject(imageId)); |
450 | 444 | ASSERT(imageTy.definition.opcode() == spv::OpTypeImage); |
@@ -471,7 +465,7 @@ SpirvShader::EmitResult SpirvShader::EmitImageQuerySamples(InsnIterator insn, Em | ||
471 | 465 | UNREACHABLE("Image descriptorType: %d", int(bindingLayout.descriptorType)); |
472 | 466 | } |
473 | 467 | |
474 | - auto &dst = state->createIntermediate(resultId, 1); | |
468 | + auto &dst = state->createIntermediate(insn.resultId(), 1); | |
475 | 469 | dst.move(0, SIMD::Int(sampleCount)); |
476 | 470 | |
477 | 471 | return EmitResult::Continue; |
@@ -545,7 +539,6 @@ SpirvShader::EmitResult SpirvShader::EmitImageRead(InsnIterator insn, EmitState | ||
545 | 539 | auto imageId = Object::ID(insn.word(3)); |
546 | 540 | auto &image = getObject(imageId); |
547 | 541 | auto &imageType = getType(image); |
548 | - Object::ID resultId = insn.word(2); | |
549 | 542 | |
550 | 543 | Object::ID sampleId = 0; |
551 | 544 |
@@ -593,7 +586,7 @@ SpirvShader::EmitResult SpirvShader::EmitImageRead(InsnIterator insn, EmitState | ||
593 | 586 | |
594 | 587 | auto imageSizeInBytes = *Pointer<Int>(binding + OFFSET(vk::StorageImageDescriptor, sizeInBytes)); |
595 | 588 | |
596 | - auto &dst = state->createIntermediate(resultId, resultType.sizeInComponents); | |
589 | + auto &dst = state->createIntermediate(insn.resultId(), resultType.sizeInComponents); | |
597 | 590 | |
598 | 591 | auto texelSize = vk::Format(vkFormat).bytes(); |
599 | 592 | auto basePtr = SIMD::Pointer(imageBase, imageSizeInBytes); |