Merge pull request #2063 from KhronosGroup/fix-2060

Merge #2061
This commit is contained in:
Hans-Kristian Arntzen 2022-11-21 14:29:47 +01:00 committed by GitHub
commit c77b09b57c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 5 deletions

View File

@ -0,0 +1,28 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct SSBO;
struct S
{
float3 v;
};
struct SSBO
{
S s[1];
};
struct PC
{
uint2 ptr;
};
kernel void main0(constant PC& pc [[buffer(0)]])
{
device SSBO* ssbo = reinterpret_cast<device SSBO*>(as_type<ulong>(pc.ptr));
ssbo->s[0].v = float3(1.0);
}

View File

@ -0,0 +1,21 @@
#version 460
#extension GL_EXT_buffer_reference: enable
#extension GL_EXT_buffer_reference_uvec2: enable
struct S {
vec3 v;
};
layout(buffer_reference) buffer SSBO{
S s[];
};
layout(push_constant) uniform PC {
uvec2 ptr;
} pc;
void main(){
SSBO ssbo = SSBO(pc.ptr);
ssbo.s[0].v = vec3(1.0);
}

View File

@ -9418,7 +9418,13 @@ string CompilerGLSL::access_chain_internal(uint32_t base, const uint32_t *indice
else if (flatten_member_reference)
expr += join("_", to_member_name(*type, index));
else
expr += to_member_reference(base, *type, index, ptr_chain);
{
// Any pointer de-refences for values are handled in the first access chain.
// For pointer chains, the pointer-ness is resolved through an array access.
// The only time this is not true is when accessing array of SSBO/UBO.
// This case is explicitly handled.
expr += to_member_reference(base, *type, index, ptr_chain || i != 0);
}
}
if (has_member_decoration(type->self, index, DecorationInvariant))

View File

@ -770,7 +770,7 @@ protected:
std::string address_of_expression(const std::string &expr);
void strip_enclosed_expression(std::string &expr);
std::string to_member_name(const SPIRType &type, uint32_t index);
virtual std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain);
virtual std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain_is_resolved);
std::string to_multi_member_reference(const SPIRType &type, const SmallVector<uint32_t> &indices);
std::string type_to_glsl_constructor(const SPIRType &type);
std::string argument_decl(const SPIRFunction::Parameter &arg);

View File

@ -14445,7 +14445,7 @@ void CompilerMSL::sync_entry_point_aliases_and_names()
entry.second.name = ir.meta[entry.first].decoration.alias;
}
string CompilerMSL::to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain)
string CompilerMSL::to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain_is_resolved)
{
auto *var = maybe_get_backing_variable(base);
// If this is a buffer array, we have to dereference the buffer pointers.
@ -14464,7 +14464,7 @@ string CompilerMSL::to_member_reference(uint32_t base, const SPIRType &type, uin
declared_as_pointer = is_buffer_variable && is_array(get<SPIRType>(var->basetype));
}
if (declared_as_pointer || (!ptr_chain && should_dereference(base)))
if (declared_as_pointer || (!ptr_chain_is_resolved && should_dereference(base)))
return join("->", to_member_name(type, index));
else
return join(".", to_member_name(type, index));

View File

@ -831,7 +831,7 @@ protected:
std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override;
bool emit_complex_bitcast(uint32_t result_id, uint32_t id, uint32_t op0) override;
bool skip_argument(uint32_t id) const override;
std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain) override;
std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain_is_resolved) override;
std::string to_qualifiers_glsl(uint32_t id) override;
void replace_illegal_names() override;
void declare_constant_arrays();