Merge pull request #89 from KhronosGroup/nowrite-noread-fix

Fix handling of NoWrite/NoRead decoration for images.
This commit is contained in:
Hans-Kristian Arntzen 2017-01-05 20:37:59 +01:00 committed by GitHub
commit 0338a5c755
5 changed files with 31 additions and 13 deletions

View File

@ -234,6 +234,10 @@ static void print_resources(const Compiler &compiler, const char *tag, const vec
fprintf(stderr, " (Binding : %u)", compiler.get_decoration(res.id, DecorationBinding));
if (mask & (1ull << DecorationInputAttachmentIndex))
fprintf(stderr, " (Attachment : %u)", compiler.get_decoration(res.id, DecorationInputAttachmentIndex));
if (mask & (1ull << DecorationNonReadable))
fprintf(stderr, " writeonly");
if (mask & (1ull << DecorationNonWritable))
fprintf(stderr, " readonly");
if (is_sized_block)
fprintf(stderr, " (BlockSize : %u bytes)", block_size);
fprintf(stderr, "\n");

View File

@ -1438,17 +1438,6 @@ void Compiler::parse(const Instruction &instruction)
if (variable_storage_is_aliased(var))
aliased_variables.push_back(var.self);
// glslangValidator does not emit required qualifiers here.
// Solve this by making the image access as restricted as possible
// and loosen up if we need to.
auto &vartype = expression_type(id);
if (vartype.basetype == SPIRType::Image)
{
auto &flags = meta.at(id).decoration.decoration_flags;
flags |= 1ull << DecorationNonWritable;
flags |= 1ull << DecorationNonReadable;
}
break;
}

View File

@ -266,6 +266,7 @@ string CompilerGLSL::compile()
{
// Scan the SPIR-V to find trivial uses of extensions.
find_static_extensions();
fixup_image_load_store_access();
uint32_t pass_count = 0;
do
@ -1263,6 +1264,30 @@ void CompilerGLSL::emit_pls()
}
}
void CompilerGLSL::fixup_image_load_store_access()
{
for (auto &id : ids)
{
if (id.get_type() != TypeVariable)
continue;
uint32_t var = id.get<SPIRVariable>().self;
auto &vartype = expression_type(var);
if (vartype.basetype == SPIRType::Image)
{
// Older glslangValidator does not emit required qualifiers here.
// Solve this by making the image access as restricted as possible and loosen up if we need to.
// If any no-read/no-write flags are actually set, assume that the compiler knows what it's doing.
auto &flags = meta.at(var).decoration.decoration_flags;
static const uint64_t NoWrite = 1ull << DecorationNonWritable;
static const uint64_t NoRead = 1ull << DecorationNonReadable;
if ((flags & (NoWrite | NoRead)) == 0)
flags |= NoRead | NoWrite;
}
}
}
void CompilerGLSL::emit_resources()
{
auto &execution = get_entry_point();

View File

@ -390,8 +390,8 @@ protected:
void find_static_extensions();
std::string emit_for_loop_initializers(const SPIRBlock &block);
bool optimize_read_modify_write(const std::string &lhs, const std::string &rhs);
void fixup_image_load_store_access();
};
}

View File

@ -1995,7 +1995,7 @@ size_t CompilerMSL::get_declared_type_size(uint32_t type_id, uint64_t dec_mask)
}
// If the opcode requires a bespoke custom function be output, remember it.
bool CompilerMSL::CustomFunctionHandler::handle(Op opcode, const uint32_t *args, uint32_t length)
bool CompilerMSL::CustomFunctionHandler::handle(Op opcode, const uint32_t * /*args*/, uint32_t /*length*/)
{
switch (opcode)
{