Skip to content

Commit 866466c

Browse files
committed
Updated spirv-cross.
1 parent acf695a commit 866466c

File tree

6 files changed

+188
-101
lines changed

6 files changed

+188
-101
lines changed

3rdparty/spirv-cross/spirv_cfg.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,26 @@ void CFG::build_immediate_dominators()
5959
for (auto i = post_order.size(); i; i--)
6060
{
6161
uint32_t block = post_order[i - 1];
62-
auto &pred = preceding_edges[block];
63-
if (pred.empty()) // This is for the entry block, but we've already set up the dominators.
64-
continue;
6562

66-
for (auto &edge : pred)
63+
const auto resolve_preds = [&](const SmallVector<uint32_t> &pred)
6764
{
68-
if (immediate_dominators[block])
65+
if (pred.empty()) // This is for the entry block, but we've already set up the dominators.
66+
return;
67+
68+
for (auto &edge : pred)
6969
{
70-
assert(immediate_dominators[edge]);
71-
immediate_dominators[block] = find_common_dominator(immediate_dominators[block], edge);
70+
if (immediate_dominators[block])
71+
{
72+
assert(immediate_dominators[edge]);
73+
immediate_dominators[block] = find_common_dominator(immediate_dominators[block], edge);
74+
}
75+
else
76+
immediate_dominators[block] = edge;
7277
}
73-
else
74-
immediate_dominators[block] = edge;
75-
}
78+
};
79+
80+
resolve_preds(preceding_edges[block]);
81+
resolve_preds(virtual_dominance_preceding_edges[block]);
7682
}
7783
}
7884

@@ -193,6 +199,13 @@ void CFG::post_order_visit_resolve(uint32_t block_id)
193199
if (block.merge == SPIRBlock::MergeLoop && !is_back_edge(block.merge_block))
194200
add_branch(block_id, block.merge_block);
195201

202+
// Similar case as do/while loops, but expressed in a different form.
203+
// if (true) { foo = 1; } else { return/unreachable/kill/blah; } access(foo);
204+
// Only consider this branch when computing dominance to avoid breaking other analysis like
205+
// parameter preservation.
206+
if (block.merge == SPIRBlock::MergeSelection && !is_back_edge(block.next_block))
207+
add_virtual_dominance_branch(block_id, block.next_block);
208+
196209
// First visit our branch targets.
197210
switch (block.terminator)
198211
{
@@ -289,18 +302,26 @@ void CFG::build_post_order_visit_order()
289302
post_order_visit_entry(block);
290303
}
291304

305+
static void add_unique(SmallVector <uint32_t> &l, uint32_t value)
306+
{
307+
auto itr = find(begin(l), end(l), value);
308+
if (itr == end(l))
309+
l.push_back(value);
310+
}
311+
292312
void CFG::add_branch(uint32_t from, uint32_t to)
293313
{
294314
assert(from && to);
295-
const auto add_unique = [](SmallVector<uint32_t> &l, uint32_t value) {
296-
auto itr = find(begin(l), end(l), value);
297-
if (itr == end(l))
298-
l.push_back(value);
299-
};
300315
add_unique(preceding_edges[to], from);
301316
add_unique(succeeding_edges[from], to);
302317
}
303318

319+
void CFG::add_virtual_dominance_branch(uint32_t from, uint32_t to)
320+
{
321+
assert(from && to);
322+
add_unique(virtual_dominance_preceding_edges[to], from);
323+
}
324+
304325
uint32_t CFG::find_loop_dominator(uint32_t block_id) const
305326
{
306327
while (block_id != SPIRBlock::NoDominator)

3rdparty/spirv-cross/spirv_cfg.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ class CFG
122122
Compiler &compiler;
123123
const SPIRFunction &func;
124124
std::unordered_map<uint32_t, SmallVector<uint32_t>> preceding_edges;
125+
std::unordered_map<uint32_t, SmallVector<uint32_t>> virtual_dominance_preceding_edges;
125126
std::unordered_map<uint32_t, SmallVector<uint32_t>> succeeding_edges;
126127
std::unordered_map<uint32_t, uint32_t> immediate_dominators;
127128
std::unordered_map<uint32_t, VisitOrder> visit_order;
128129
SmallVector<uint32_t> post_order;
129130
SmallVector<uint32_t> empty_vector;
130131

131132
void add_branch(uint32_t from, uint32_t to);
133+
void add_virtual_dominance_branch(uint32_t from, uint32_t to);
132134
void build_post_order_visit_order();
133135
void build_immediate_dominators();
134136
void post_order_visit_branches(uint32_t block);

3rdparty/spirv-cross/spirv_glsl.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,9 +1335,6 @@ void CompilerGLSL::emit_struct(SPIRType &type)
13351335
emitted = true;
13361336
}
13371337

1338-
if (has_extended_decoration(type.self, SPIRVCrossDecorationPaddingTarget))
1339-
emit_struct_padding_target(type);
1340-
13411338
end_scope_decl();
13421339

13431340
if (emitted)
@@ -10872,6 +10869,15 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice
1087210869
access_meshlet_position_y = true;
1087310870
}
1087410871

10872+
if (get<SPIRType>(type->parent_type).op == OpTypeStruct &&
10873+
has_decoration(type->parent_type, DecorationArrayStride))
10874+
{
10875+
uint32_t native_stride = get_decoration(type->parent_type, DecorationArrayStride);
10876+
uint32_t array_stride = get_decoration(type_id, DecorationArrayStride);
10877+
if (native_stride != array_stride)
10878+
expr += ".data";
10879+
}
10880+
1087510881
type_id = type->parent_type;
1087610882
type = &get<SPIRType>(type_id);
1087710883

@@ -10957,6 +10963,7 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice
1095710963
physical_type = 0;
1095810964

1095910965
row_major_matrix_needs_conversion = member_is_non_native_row_major_matrix(*type, index);
10966+
type_id = type->member_types[index];
1096010967
type = &get<SPIRType>(type->member_types[index]);
1096110968
}
1096210969
// Matrix -> Vector
@@ -11168,9 +11175,9 @@ string CompilerGLSL::to_flattened_struct_member(const string &basename, const SP
1116811175
return ret;
1116911176
}
1117011177

11171-
uint32_t CompilerGLSL::get_physical_type_stride(const SPIRType &) const
11178+
uint32_t CompilerGLSL::get_physical_type_id_stride(TypeID) const
1117211179
{
11173-
SPIRV_CROSS_THROW("Invalid to call get_physical_type_stride on a backend without native pointer support.");
11180+
SPIRV_CROSS_THROW("Invalid to call get_physical_type_id_stride on a backend without native pointer support.");
1117411181
}
1117511182

1117611183
string CompilerGLSL::access_chain(uint32_t base, const uint32_t *indices, uint32_t count, const SPIRType &target_type,
@@ -11231,13 +11238,13 @@ string CompilerGLSL::access_chain(uint32_t base, const uint32_t *indices, uint32
1123111238
// If there is a mismatch we have to go via 64-bit pointer arithmetic :'(
1123211239
// Using packed hacks only gets us so far, and is not designed to deal with pointer to
1123311240
// random values. It works for structs though.
11234-
auto &pointee_type = get_pointee_type(get<SPIRType>(type_id));
11235-
uint32_t physical_stride = get_physical_type_stride(pointee_type);
11241+
TypeID pointee_type_id = get_pointee_type_id(type_id);
11242+
uint32_t physical_stride = get_physical_type_id_stride(pointee_type_id);
1123611243
uint32_t requested_stride = get_decoration(type_id, DecorationArrayStride);
1123711244
if (physical_stride != requested_stride)
1123811245
{
1123911246
flags |= ACCESS_CHAIN_PTR_CHAIN_POINTER_ARITH_BIT;
11240-
if (is_vector(pointee_type))
11247+
if (is_vector(get<SPIRType>(pointee_type_id)))
1124111248
flags |= ACCESS_CHAIN_PTR_CHAIN_CAST_TO_SCALAR_BIT;
1124211249
}
1124311250
}
@@ -16338,10 +16345,6 @@ void CompilerGLSL::emit_struct_member(const SPIRType &type, uint32_t member_type
1633816345
variable_decl(membertype, to_member_name(type, index)), ";");
1633916346
}
1634016347

16341-
void CompilerGLSL::emit_struct_padding_target(const SPIRType &)
16342-
{
16343-
}
16344-
1634516348
string CompilerGLSL::flags_to_qualifiers_glsl(const SPIRType &type, uint32_t id, const Bitset &flags)
1634616349
{
1634716350
// GL_EXT_buffer_reference variables can be marked as restrict.

3rdparty/spirv-cross/spirv_glsl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ class CompilerGLSL : public Compiler
447447
virtual std::string builtin_to_glsl(BuiltIn builtin, StorageClass storage);
448448
virtual void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
449449
const std::string &qualifier = "", uint32_t base_offset = 0);
450-
virtual void emit_struct_padding_target(const SPIRType &type);
451450
virtual std::string image_type_glsl(const SPIRType &type, uint32_t id = 0, bool member = false);
452451
std::string constant_expression(const SPIRConstant &c,
453452
bool inside_block_like_struct_scope = false,
@@ -773,7 +772,7 @@ class CompilerGLSL : public Compiler
773772

774773
// Only meaningful on backends with physical pointer support ala MSL.
775774
// Relevant for PtrAccessChain / BDA.
776-
virtual uint32_t get_physical_type_stride(const SPIRType &type) const;
775+
virtual uint32_t get_physical_type_id_stride(TypeID type_id) const;
777776

778777
StorageClass get_expression_effective_storage_class(uint32_t ptr);
779778
virtual bool access_chain_needs_stage_io_builtin_translation(uint32_t base);

0 commit comments

Comments
 (0)