From f3ec9833e8812b521c57083336f7b0ff46841716 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Wed, 21 Oct 2020 16:09:57 -0400 Subject: [PATCH] Fix storage class issues for push constant variables. Change-Id: I433159717b831e9dbfc251c38687572bdc45c959 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/329037 Auto-Submit: Jim Van Verth Commit-Queue: Ethan Nicholas Reviewed-by: Ethan Nicholas --- src/sksl/SkSLSPIRVCodeGenerator.cpp | 13 +++++++++---- src/sksl/SkSLSPIRVCodeGenerator.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index ac70d8f3a0..ba43ff95a4 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -475,7 +475,10 @@ SpvId SPIRVCodeGenerator::getType(const Type& type) { SpvId SPIRVCodeGenerator::getType(const Type& rawType, const MemoryLayout& layout) { const Type& type = this->getActualType(rawType); - String key = type.name() + to_string((int) layout.fStd); + String key = type.name(); + if (type.typeKind() == Type::TypeKind::kStruct || type.typeKind() == Type::TypeKind::kArray) { + key += to_string((int)layout.fStd); + } auto entry = fTypeMap.find(key); if (entry == fTypeMap.end()) { SpvId result = this->nextId(); @@ -1892,6 +1895,7 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O fRTHeightStructId = this->writeInterfaceBlock(intf, false); fRTHeightFieldIndex = 0; + fRTHeightStorageClass = SpvStorageClassUniform; } SkASSERT(fRTHeightFieldIndex != (SpvId)-1); @@ -1899,7 +1903,7 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O SpvId fieldIndexId = this->writeIntLiteral(fieldIndex); SpvId heightPtr = this->nextId(); this->writeOpCode(SpvOpAccessChain, 5, out); - this->writeWord(this->getPointerType(*fContext.fFloat_Type, SpvStorageClassUniform), + this->writeWord(this->getPointerType(*fContext.fFloat_Type, fRTHeightStorageClass), out); this->writeWord(heightPtr, out); this->writeWord(fRTHeightStructId, out); @@ -2706,17 +2710,19 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a fDefaultLayout; SpvId result = this->nextId(); const Type* type = &intf.variable().type(); + Modifiers intfModifiers = intf.variable().modifiers(); + SpvStorageClass_ storageClass = get_storage_class(intfModifiers); if (fProgram.fInputs.fRTHeight && appendRTHeight) { SkASSERT(fRTHeightStructId == (SpvId) -1); SkASSERT(fRTHeightFieldIndex == (SpvId) -1); std::vector fields = type->fields(); fRTHeightStructId = result; fRTHeightFieldIndex = fields.size(); + fRTHeightStorageClass = storageClass; fields.emplace_back(Modifiers(), StringFragment(SKSL_RTHEIGHT_NAME), fContext.fFloat_Type.get()); type = new Type(type->fOffset, type->name(), fields); } SpvId typeId; - Modifiers intfModifiers = intf.variable().modifiers(); if (intfModifiers.fLayout.fBuiltin == SK_IN_BUILTIN) { for (const auto& e : fProgram.elements()) { if (e->is()) { @@ -2736,7 +2742,6 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a } else if (intfModifiers.fLayout.fBuiltin == -1) { this->writeInstruction(SpvOpDecorate, typeId, SpvDecorationBlock, fDecorationBuffer); } - SpvStorageClass_ storageClass = get_storage_class(intfModifiers); SpvId ptrType = this->nextId(); this->writeInstruction(SpvOpTypePointer, ptrType, storageClass, typeId, fConstantBuffer); this->writeInstruction(SpvOpVariable, ptrType, result, storageClass, fConstantBuffer); diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h index 2a78e187c2..3d77265509 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.h +++ b/src/sksl/SkSLSPIRVCodeGenerator.h @@ -398,6 +398,7 @@ private: std::stack fContinueTarget; SpvId fRTHeightStructId = (SpvId) -1; SpvId fRTHeightFieldIndex = (SpvId) -1; + SpvStorageClass_ fRTHeightStorageClass; // holds variables synthesized during output, for lifetime purposes SymbolTable fSynthetics; int fSkInCount = 1;