OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSLSPIRVCodeGenerator.h" | 8 #include "SkSLSPIRVCodeGenerator.h" |
9 | 9 |
10 #include "string.h" | 10 #include "string.h" |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 SpvId SPIRVCodeGenerator::nextId() { | 966 SpvId SPIRVCodeGenerator::nextId() { |
967 return fIdCount++; | 967 return fIdCount++; |
968 } | 968 } |
969 | 969 |
970 void SPIRVCodeGenerator::writeStruct(const Type& type, SpvId resultId) { | 970 void SPIRVCodeGenerator::writeStruct(const Type& type, SpvId resultId) { |
971 this->writeInstruction(SpvOpName, resultId, type.name().c_str(), fNameBuffer
); | 971 this->writeInstruction(SpvOpName, resultId, type.name().c_str(), fNameBuffer
); |
972 // go ahead and write all of the field types, so we don't inadvertently writ
e them while we're | 972 // go ahead and write all of the field types, so we don't inadvertently writ
e them while we're |
973 // in the middle of writing the struct instruction | 973 // in the middle of writing the struct instruction |
974 std::vector<SpvId> types; | 974 std::vector<SpvId> types; |
975 for (const auto& f : type.fields()) { | 975 for (const auto& f : type.fields()) { |
976 types.push_back(this->getType(f.fType)); | 976 types.push_back(this->getType(*f.fType)); |
977 } | 977 } |
978 this->writeOpCode(SpvOpTypeStruct, 2 + (int32_t) types.size(), fConstantBuff
er); | 978 this->writeOpCode(SpvOpTypeStruct, 2 + (int32_t) types.size(), fConstantBuff
er); |
979 this->writeWord(resultId, fConstantBuffer); | 979 this->writeWord(resultId, fConstantBuffer); |
980 for (SpvId id : types) { | 980 for (SpvId id : types) { |
981 this->writeWord(id, fConstantBuffer); | 981 this->writeWord(id, fConstantBuffer); |
982 } | 982 } |
983 size_t offset = 0; | 983 size_t offset = 0; |
984 for (int32_t i = 0; i < (int32_t) type.fields().size(); i++) { | 984 for (int32_t i = 0; i < (int32_t) type.fields().size(); i++) { |
985 size_t size = type.fields()[i].fType.size(); | 985 size_t size = type.fields()[i].fType->size(); |
986 size_t alignment = type.fields()[i].fType.alignment(); | 986 size_t alignment = type.fields()[i].fType->alignment(); |
987 size_t mod = offset % alignment; | 987 size_t mod = offset % alignment; |
988 if (mod != 0) { | 988 if (mod != 0) { |
989 offset += alignment - mod; | 989 offset += alignment - mod; |
990 } | 990 } |
991 this->writeInstruction(SpvOpMemberName, resultId, i, type.fields()[i].fN
ame.c_str(), | 991 this->writeInstruction(SpvOpMemberName, resultId, i, type.fields()[i].fN
ame.c_str(), |
992 fNameBuffer); | 992 fNameBuffer); |
993 this->writeLayout(type.fields()[i].fModifiers.fLayout, resultId, i); | 993 this->writeLayout(type.fields()[i].fModifiers.fLayout, resultId, i); |
994 if (type.fields()[i].fModifiers.fLayout.fBuiltin < 0) { | 994 if (type.fields()[i].fModifiers.fLayout.fBuiltin < 0) { |
995 this->writeInstruction(SpvOpMemberDecorate, resultId, (SpvId) i, Spv
DecorationOffset, | 995 this->writeInstruction(SpvOpMemberDecorate, resultId, (SpvId) i, Spv
DecorationOffset, |
996 (SpvId) offset, fDecorationBuffer); | 996 (SpvId) offset, fDecorationBuffer); |
997 } | 997 } |
998 if (type.fields()[i].fType.kind() == Type::kMatrix_Kind) { | 998 if (type.fields()[i].fType->kind() == Type::kMatrix_Kind) { |
999 this->writeInstruction(SpvOpMemberDecorate, resultId, i, SpvDecorati
onColMajor, | 999 this->writeInstruction(SpvOpMemberDecorate, resultId, i, SpvDecorati
onColMajor, |
1000 fDecorationBuffer); | 1000 fDecorationBuffer); |
1001 this->writeInstruction(SpvOpMemberDecorate, resultId, i, SpvDecorati
onMatrixStride, | 1001 this->writeInstruction(SpvOpMemberDecorate, resultId, i, SpvDecorati
onMatrixStride, |
1002 (SpvId) type.fields()[i].fType.stride(), fDec
orationBuffer); | 1002 (SpvId) type.fields()[i].fType->stride(), fDe
corationBuffer); |
1003 } | 1003 } |
1004 offset += size; | 1004 offset += size; |
1005 Type::Kind kind = type.fields()[i].fType.kind(); | 1005 Type::Kind kind = type.fields()[i].fType->kind(); |
1006 if ((kind == Type::kArray_Kind || kind == Type::kStruct_Kind) && offset
% alignment != 0) { | 1006 if ((kind == Type::kArray_Kind || kind == Type::kStruct_Kind) && offset
% alignment != 0) { |
1007 offset += alignment - offset % alignment; | 1007 offset += alignment - offset % alignment; |
1008 } | 1008 } |
1009 ASSERT(offset % alignment == 0); | 1009 ASSERT(offset % alignment == 0); |
1010 } | 1010 } |
1011 } | 1011 } |
1012 | 1012 |
1013 SpvId SPIRVCodeGenerator::getType(const Type& type) { | 1013 SpvId SPIRVCodeGenerator::getType(const Type& type) { |
1014 auto entry = fTypeMap.find(type.name()); | 1014 auto entry = fTypeMap.find(type.name()); |
1015 if (entry == fTypeMap.end()) { | 1015 if (entry == fTypeMap.end()) { |
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2626 this->writeWord(SpvVersion, out); | 2626 this->writeWord(SpvVersion, out); |
2627 this->writeWord(SKSL_MAGIC, out); | 2627 this->writeWord(SKSL_MAGIC, out); |
2628 std::stringstream buffer; | 2628 std::stringstream buffer; |
2629 this->writeInstructions(program, buffer); | 2629 this->writeInstructions(program, buffer); |
2630 this->writeWord(fIdCount, out); | 2630 this->writeWord(fIdCount, out); |
2631 this->writeWord(0, out); // reserved, always zero | 2631 this->writeWord(0, out); // reserved, always zero |
2632 out << buffer.str(); | 2632 out << buffer.str(); |
2633 } | 2633 } |
2634 | 2634 |
2635 } | 2635 } |
OLD | NEW |