Skip to content

Commit

Permalink
Merge pull request KhronosGroup#945 from ashleyharris-maptek-com-au/f…
Browse files Browse the repository at this point in the history
…ixHlslAttributeLeak

Don't apply vertex attribute remapping to other interface blocks
  • Loading branch information
HansKristian-Work authored Apr 12, 2019
2 parents ac5a957 + cc2d290 commit 7a87701
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions spirv_hlsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,17 +723,25 @@ string CompilerHLSL::to_interpolation_qualifiers(const Bitset &flags)
return res;
}

std::string CompilerHLSL::to_semantic(uint32_t vertex_location)
std::string CompilerHLSL::to_semantic(uint32_t location, ExecutionModel em, StorageClass sc)
{
for (auto &attribute : remap_vertex_attributes)
if (attribute.location == vertex_location)
return attribute.semantic;
if (em == ExecutionModelVertex && sc == StorageClassInput)
{
// We have a vertex attribute - we should look at remapping it if the user provided
// vertex attribute hints.
for (auto &attribute : remap_vertex_attributes)
if (attribute.location == location)
return attribute.semantic;
}

return join("TEXCOORD", vertex_location);
// Not a vertex attribute, or no remap_vertex_attributes entry.
return join("TEXCOORD", location);
}

void CompilerHLSL::emit_io_block(const SPIRVariable &var)
{
auto &execution = get_entry_point();

auto &type = get<SPIRType>(var.basetype);
add_resource_name(type.self);

Expand All @@ -749,15 +757,15 @@ void CompilerHLSL::emit_io_block(const SPIRVariable &var)
if (has_member_decoration(type.self, i, DecorationLocation))
{
uint32_t location = get_member_decoration(type.self, i, DecorationLocation);
semantic = join(" : ", to_semantic(location));
semantic = join(" : ", to_semantic(location, execution.model, var.storage));
}
else
{
// If the block itself has a location, but not its members, use the implicit location.
// There could be a conflict if the block members partially specialize the locations.
// It is unclear how SPIR-V deals with this. Assume this does not happen for now.
uint32_t location = base_location + i;
semantic = join(" : ", to_semantic(location));
semantic = join(" : ", to_semantic(location, execution.model, var.storage));
}

add_member_name(type, i);
Expand Down Expand Up @@ -820,7 +828,7 @@ void CompilerHLSL::emit_interface_block_in_struct(const SPIRVariable &var, unord
location_number = get_vacant_location();

// Allow semantic remap if specified.
auto semantic = to_semantic(location_number);
auto semantic = to_semantic(location_number, execution.model, var.storage);

if (need_matrix_unroll && type.columns > 1)
{
Expand Down
2 changes: 1 addition & 1 deletion spirv_hlsl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class CompilerHLSL : public CompilerGLSL
uint32_t type_to_consumed_locations(const SPIRType &type) const;

void emit_io_block(const SPIRVariable &var);
std::string to_semantic(uint32_t vertex_location);
std::string to_semantic(uint32_t location, spv::ExecutionModel em, spv::StorageClass sc);

uint32_t num_workgroups_builtin = 0;

Expand Down

0 comments on commit 7a87701

Please sign in to comment.