Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 296aa25

Browse files
committed
Collect type and variable definitions from SPIRV shader
Many other pieces will need an index of spirv-id to defining instruction. Start building that up. Bug: b/120799499 Change-Id: Ief6583f45c49fce02cb5dc40d12c6ba928e48fd7 Reviewed-on: https://swiftshader-review.googlesource.com/c/23428 Tested-by: Chris Forbes <chrisforbes@google.com> Reviewed-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com> Reviewed-by: Corentin Wallez <cwallez@google.com>
1 parent af4ed53 commit 296aa25

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/Pipeline/SpirvShader.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,41 @@ namespace sw
3535
ProcessExecutionMode(insn);
3636
break;
3737

38+
case spv::OpTypeVoid:
39+
case spv::OpTypeBool:
40+
case spv::OpTypeInt:
41+
case spv::OpTypeFloat:
42+
case spv::OpTypeVector:
43+
case spv::OpTypeMatrix:
44+
case spv::OpTypeImage:
45+
case spv::OpTypeSampler:
46+
case spv::OpTypeSampledImage:
47+
case spv::OpTypeArray:
48+
case spv::OpTypeRuntimeArray:
49+
case spv::OpTypeStruct:
50+
case spv::OpTypePointer:
51+
case spv::OpTypeFunction: {
52+
auto resultId = insn.word(1);
53+
auto &object = defs[resultId];
54+
object.kind = Object::Kind::Type;
55+
object.definition = insn;
56+
break;
57+
}
58+
59+
case spv::OpVariable: {
60+
auto typeId = insn.word(1);
61+
auto resultId = insn.word(2);
62+
auto storageClass = static_cast<spv::StorageClass>(insn.word(3));
63+
if (insn.wordCount() > 4)
64+
UNIMPLEMENTED("Variable initializers not yet supported");
65+
66+
auto &object = defs[resultId];
67+
object.kind = Object::Kind::Variable;
68+
object.definition = insn;
69+
object.storageClass = storageClass;
70+
break;
71+
}
72+
3873
default:
3974
break; // This is OK, these passes are intentionally partial
4075
}

src/Pipeline/SpirvShader.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ namespace sw
8888
InsnIterator end() const
8989
{ return InsnIterator{insns.cend()}; }
9090

91+
class Object
92+
{
93+
public:
94+
InsnIterator definition;
95+
spv::StorageClass storageClass;
96+
97+
enum class Kind
98+
{
99+
Unknown, /* for paranoia -- if we get left with an object in this state, the module was broken */
100+
Type,
101+
Variable,
102+
Value,
103+
} kind = Kind::Unknown;
104+
};
105+
91106
int getSerialID() const
92107
{ return serialID; }
93108

@@ -112,6 +127,7 @@ namespace sw
112127
const int serialID;
113128
static volatile int serialCounter;
114129
Modes modes;
130+
std::unordered_map<uint32_t, Object> defs;
115131

116132
void ProcessExecutionMode(InsnIterator it);
117133
};

0 commit comments

Comments
 (0)