Skip to content

Commit 5f6fb7a

Browse files
committed
specialize_explicit_layout: correctly handle PC, ubo, ssbo
1 parent 2350561 commit 5f6fb7a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/backend/spirv/spirv_specialize_explicit_layout.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ typedef struct {
1616
const CompilerConfig* config;
1717
} Context;
1818

19-
static bool has_explicit_layout(AddressSpace as) {
19+
static bool has_explicit_layout(const TargetConfig* target, AddressSpace as) {
2020
switch (as) {
21-
case AsInput:
22-
case AsUInput:
23-
case AsOutput:
24-
case AsPrivate: return false;
25-
case AsShared: return false;
26-
case AsFunction: return false;
27-
default: return true;
21+
// despite not being physical, they require explicit layout
22+
case AsShaderStorageBufferObject:
23+
case AsUniform:
24+
case AsPushConstant: return true;
25+
default: break;
2826
}
27+
return target->memory.address_spaces[as].physical;
2928
}
3029

3130
static const Type* rebuild_aggregate_type(Rewriter* r, const Type* t) {
@@ -83,7 +82,7 @@ static const Node* process(Context* ctx, const Node* node) {
8382
switch (node->tag) {
8483
case GlobalVariable_TAG: {
8584
GlobalVariable payload = shd_rewrite_global_head_payload(r, node->payload.global_variable);
86-
if (has_explicit_layout(payload.address_space)) {
85+
if (has_explicit_layout(&shd_get_arena_config(a)->target, payload.address_space)) {
8786
payload.type = shd_rewrite_node(&ctx->aggregate_types, payload.type);
8887
}
8988
Node* ngv = shd_global_var(r->dst_module, payload);
@@ -95,7 +94,7 @@ static const Node* process(Context* ctx, const Node* node) {
9594
case PtrType_TAG: {
9695
PtrType payload = node->payload.ptr_type;
9796
payload.pointed_type = shd_rewrite_node(&ctx->rewriter, payload.pointed_type);
98-
if (has_explicit_layout(payload.address_space))
97+
if (has_explicit_layout(&shd_get_arena_config(a)->target, payload.address_space))
9998
payload.pointed_type = shd_rewrite_node(&ctx->aggregate_types, payload.pointed_type);
10099
return ptr_type(a, payload);
101100
}
@@ -109,7 +108,7 @@ static const Node* process(Context* ctx, const Node* node) {
109108
payload.ptr = shd_rewrite_node(r, payload.ptr);
110109
const Node* nld = load(a, payload);
111110
// get rid of explicit layout at the value level
112-
if (has_explicit_layout(old_ptr_t->payload.ptr_type.address_space) && shd_is_aggregate_t(pointee_type))
111+
if (has_explicit_layout(&shd_get_arena_config(a)->target, old_ptr_t->payload.ptr_type.address_space) && shd_is_aggregate_t(pointee_type))
113112
nld = mem_and_value_helper(a, nld, aggregate_cast_helper(a, pointee_type, nld));
114113
return nld;
115114
}
@@ -123,7 +122,7 @@ static const Node* process(Context* ctx, const Node* node) {
123122
payload.ptr = shd_rewrite_node(r, payload.ptr);
124123
payload.value = shd_rewrite_node(r, payload.value);
125124
// add explicit layout when storing
126-
if (has_explicit_layout(old_ptr_t->payload.ptr_type.address_space) && shd_is_aggregate_t(pointee_type))
125+
if (has_explicit_layout(&shd_get_arena_config(a)->target, old_ptr_t->payload.ptr_type.address_space) && shd_is_aggregate_t(pointee_type))
127126
payload.value = aggregate_cast_helper(a, shd_rewrite_node(&ctx->aggregate_types, pointee_type), payload.value);
128127
return store(a, payload);
129128
}

0 commit comments

Comments
 (0)