Skip to content

Commit

Permalink
Fix writing immutable combined sampler
Browse files Browse the repository at this point in the history
When writing the immutable samples so they can be read as a normal
sampler, it is written to the start of the descriptor.  However, if the
sampler is part of a combined image&sampler, it needs to be written
after the image descriptor.  This change will add that offset when
necessary.
  • Loading branch information
s-perron authored and JaxLinAMD committed Dec 14, 2021
1 parent f90b2c9 commit 8f77c62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion icd/api/include/vk_descriptor_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class DescriptorSet final : public NonDispatchable<VkDescriptorSet, DescriptorSe
DescriptorAddr* pBaseAddrs,
void* pAllocHandle);

void WriteImmutableSamplers();
void WriteImmutableSamplers(
uint32_t imageDescSizeInBytes);

void Reset();

Expand Down
2 changes: 1 addition & 1 deletion icd/api/vk_descriptor_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ VkResult DescriptorPool::AllocDescriptorSets(
pSetAllocHandle);
if (m_pDevice->MustWriteImmutableSamplers())
{
pSet->WriteImmutableSamplers();
pSet->WriteImmutableSamplers(m_pDevice->GetProperties().descriptorSizes.imageView);
}
}
else
Expand Down
19 changes: 14 additions & 5 deletions icd/api/vk_descriptor_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void DescriptorSet<numPalDevices>::Reassign(
// =====================================================================================================================
// Writes the immutable samplers in the layout to memory.
template <uint32_t numPalDevices>
void DescriptorSet<numPalDevices>::WriteImmutableSamplers()
void DescriptorSet<numPalDevices>::WriteImmutableSamplers(
uint32_t imageDescSizeInBytes)
{
for (uint32_t deviceIdx = 0; deviceIdx < numPalDevices; deviceIdx++)
{
Expand All @@ -104,6 +105,10 @@ void DescriptorSet<numPalDevices>::WriteImmutableSamplers()
{
uint32_t* pSamplerDesc = Layout()->Info().imm.pImmutableSamplerData + bindingInfo.imm.dwOffset;
uint32_t* pDestAddr = StaticCpuAddress(deviceIdx) + Layout()->GetDstStaOffset(bindingInfo, 0);
if (bindingInfo.info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
{
pDestAddr += (imageDescSizeInBytes / sizeof(uint32_t));
}
memcpy(pDestAddr, pSamplerDesc, sizeof(uint32)*bindingInfo.imm.dwSize);
}
}
Expand Down Expand Up @@ -1070,7 +1075,8 @@ template
void DescriptorSet<1>::Reset();

template
void DescriptorSet<1>::WriteImmutableSamplers();
void DescriptorSet<1>::WriteImmutableSamplers(
uint32_t imageDescSizeInBytes);

template
DescriptorSet<2>::DescriptorSet(uint32_t heapIndex);
Expand All @@ -1086,7 +1092,8 @@ template
void DescriptorSet<2>::Reset();

template
void DescriptorSet<2>::WriteImmutableSamplers();
void DescriptorSet<2>::WriteImmutableSamplers(
uint32_t imageDescSizeInBytes);

template
DescriptorSet<3>::DescriptorSet(uint32_t heapIndex);
Expand All @@ -1102,7 +1109,8 @@ template
void DescriptorSet<3>::Reset();

template
void DescriptorSet<3>::WriteImmutableSamplers();
void DescriptorSet<3>::WriteImmutableSamplers(
uint32_t imageDescSizeInBytes);

template
DescriptorSet<4>::DescriptorSet(uint32_t heapIndex);
Expand All @@ -1118,6 +1126,7 @@ template
void DescriptorSet<4>::Reset();

template
void DescriptorSet<4>::WriteImmutableSamplers();
void DescriptorSet<4>::WriteImmutableSamplers(
uint32_t imageDescSizeInBytes);

} // namespace vk

0 comments on commit 8f77c62

Please sign in to comment.