MSL: Emit correct SSBO constness for argument buffers.

This commit is contained in:
Hans-Kristian Arntzen 2019-03-15 12:05:35 +01:00
parent 969566aff5
commit bc21ccb7ce
4 changed files with 13 additions and 9 deletions

View File

@ -41,7 +41,7 @@ struct spvDescriptorSetBuffer1
{
array<texture2d<float>, 4> uTexture2 [[id(3)]];
device SSBO* m_60 [[id(7)]];
device SSBOs* ssbos [[id(8)]][2];
const device SSBOs* ssbos [[id(8)]][2];
array<sampler, 2> uSampler [[id(10)]];
};

View File

@ -43,7 +43,7 @@ struct spvDescriptorSetBuffer1
{
array<texture2d<float>, 4> uTexture2 [[id(3)]];
device SSBO* v_60 [[id(7)]];
device SSBOs* ssbos [[id(8)]][2];
const device SSBOs* ssbos [[id(8)]][2];
array<sampler, 2> uSampler [[id(10)]];
};

View File

@ -5429,7 +5429,7 @@ string CompilerMSL::get_argument_address_space(const SPIRVariable &argument)
return "thread";
}
string CompilerMSL::get_type_address_space(const SPIRType &type)
string CompilerMSL::get_type_address_space(const SPIRType &type, uint32_t id)
{
switch (type.storage)
{
@ -5437,8 +5437,10 @@ string CompilerMSL::get_type_address_space(const SPIRType &type)
return "threadgroup";
case StorageClassStorageBuffer:
// FIXME: Need to use 'const device' for pointers into non-writable SSBOs
return "device";
{
auto flags = id ? get_buffer_block_flags(id) : Bitset();
return flags.get(DecorationNonWritable) ? "const device" : "device";
}
case StorageClassUniform:
case StorageClassUniformConstant:
@ -5446,9 +5448,11 @@ string CompilerMSL::get_type_address_space(const SPIRType &type)
if (type.basetype == SPIRType::Struct)
{
bool ssbo = has_decoration(type.self, DecorationBufferBlock);
// FIXME: Need to use 'const device' for pointers into non-writable SSBOs
if (ssbo)
return "device";
{
auto flags = id ? get_buffer_block_flags(id) : Bitset();
return flags.get(DecorationNonWritable) ? "const device" : "device";
}
else
return "constant";
}
@ -6378,7 +6382,7 @@ string CompilerMSL::type_to_glsl(const SPIRType &type, uint32_t id)
// Pointer?
if (type.pointer)
{
type_name = join(get_type_address_space(type), " ", type_to_glsl(get<SPIRType>(type.parent_type), id));
type_name = join(get_type_address_space(type, id), " ", type_to_glsl(get<SPIRType>(type.parent_type), id));
switch (type.basetype)
{
case SPIRType::Image:

View File

@ -438,7 +438,7 @@ protected:
bool is_member_packable(SPIRType &ib_type, uint32_t index);
MSLStructMemberKey get_struct_member_key(uint32_t type_id, uint32_t index);
std::string get_argument_address_space(const SPIRVariable &argument);
std::string get_type_address_space(const SPIRType &type);
std::string get_type_address_space(const SPIRType &type, uint32_t id);
SPIRType &get_stage_in_struct_type();
SPIRType &get_stage_out_struct_type();
SPIRType &get_patch_stage_in_struct_type();