Skip to content

Commit

Permalink
layers: Fix VK_AMD_shader_fragment_mask
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jun 7, 2024
1 parent b94b372 commit de711c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
36 changes: 22 additions & 14 deletions layers/state_tracker/shader_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ static void FindPointersAndObjects(const Instruction& insn, vvl::unordered_set<u
case spv::OpImageSparseGather:
case spv::OpImageSparseDrefGather:
case spv::OpImageTexelPointer:
case spv::OpFragmentFetchAMD:
case spv::OpFragmentMaskFetchAMD:
// Note: we only explore parts of the image which might actually contain ids we care about for the above analyses.
// - NOT the shader input/output interfaces.
result.insert(insn.Word(3)); // Image or sampled image
Expand Down Expand Up @@ -609,6 +611,8 @@ ImageAccess::ImageAccess(const Module& module_state, const Instruction& image_in
case spv::OpImageGather:
case spv::OpImageSparseGather:
case spv::OpImageQueryLod:
case spv::OpFragmentFetchAMD:
case spv::OpFragmentMaskFetchAMD:
break;

case spv::OpImageSparseTexelsResident:
Expand Down Expand Up @@ -1002,7 +1006,9 @@ Module::StaticData::StaticData(const Module& module_state, StatelessData* statel
case spv::OpImageGather:
case spv::OpImageQueryLod:
case spv::OpImageSparseFetch:
case spv::OpImageSparseGather: {
case spv::OpImageSparseGather:
case spv::OpFragmentFetchAMD:
case spv::OpFragmentMaskFetchAMD: {
image_instructions.push_back(&insn);
break;
}
Expand Down Expand Up @@ -1950,21 +1956,21 @@ ResourceInterfaceVariable::ResourceInterfaceVariable(const Module& module_state,

// Handle anything specific to the base type
if (base_type.Opcode() == spv::OpTypeImage) {
const auto image_access_it = image_access_map.find(id);
if (image_access_it != image_access_map.end()) {
const bool is_sampled_without_sampler = base_type.Word(7) == 2; // Word(7) == Sampled
if (is_sampled_without_sampler) {
if (info.image_dim == spv::DimSubpassData) {
is_input_attachment = true;
input_attachment_index_read.resize(array_length); // is zero if runtime array
} else if (info.image_dim == spv::DimBuffer) {
is_storage_texel_buffer = true;
} else {
is_storage_image = true;
}
// Things marked regardless of the image being accessed or not
const bool is_sampled_without_sampler = base_type.Word(7) == 2; // Word(7) == Sampled
if (is_sampled_without_sampler) {
if (info.image_dim == spv::DimSubpassData) {
is_input_attachment = true;
input_attachment_index_read.resize(array_length); // is zero if runtime array
} else if (info.image_dim == spv::DimBuffer) {
is_storage_texel_buffer = true;
} else {
is_storage_image = true;
}
const bool is_image_without_format = ((is_sampled_without_sampler) && (base_type.Word(8) == spv::ImageFormatUnknown));
}

const auto image_access_it = image_access_map.find(id);
if (image_access_it != image_access_map.end()) {
for (const auto& image_access_ptr : image_access_it->second) {
const auto& image_access = *image_access_ptr;

Expand All @@ -1982,6 +1988,8 @@ ResourceInterfaceVariable::ResourceInterfaceVariable(const Module& module_state,
image_access_chain_indexes.insert(image_access.image_access_chain_index);
}

const bool is_image_without_format =
((is_sampled_without_sampler) && (base_type.Word(8) == spv::ImageFormatUnknown));
if (image_access.access_mask & AccessBit::image_write) {
if (is_image_without_format) {
info.is_write_without_format |= true;
Expand Down
2 changes: 2 additions & 0 deletions layers/vulkan/generated/spirv_grammar_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@ static constexpr uint32_t OpcodeImageAccessPosition(uint32_t opcode) {
case spv::OpImageSparseGather:
case spv::OpImageSparseDrefGather:
case spv::OpImageSparseRead:
case spv::OpFragmentMaskFetchAMD:
case spv::OpFragmentFetchAMD:
case spv::OpImageSampleFootprintNV:
return 3;

Expand Down
3 changes: 3 additions & 0 deletions scripts/generators/spirv_grammar_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def parseGrammar(self, grammar):
self.imageAccessOperand[imageRef].append(opname)
elif sampledImageRef != 0:
self.imageAccessOperand[sampledImageRef].append(opname)
# exceptions that don't fit the OpImage naming
if opname == 'OpFragmentFetchAMD' or opname == 'OpFragmentMaskFetchAMD':
self.imageAccessOperand[3].append(opname)

# We want to manually mark "Label" if an ID is used for Control Flow
# It is easier to manage the few cases here then complex the operand logic above
Expand Down

0 comments on commit de711c9

Please sign in to comment.