Skip to content

Commit

Permalink
Only warn if descriptor is bound but not contained by descriptor set.
Browse files Browse the repository at this point in the history
  • Loading branch information
crud89 committed Feb 27, 2024
1 parent 84a903e commit 1ae7bb3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 9 deletions.
48 changes: 44 additions & 4 deletions src/Backends/DirectX12/src/descriptor_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ void DirectX12DescriptorSet::update(UInt32 binding, const IDirectX12Buffer& buff
if (bufferElement + elementCount > buffer.elements()) [[unlikely]]
LITEFX_WARNING(DIRECTX12_LOG, "The buffer only has {0} elements, however there are {1} elements starting at element {2} specified.", buffer.elements(), elementCount, bufferElement);

const auto& descriptorLayout = m_impl->m_layout.descriptor(binding);
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const DirectX12DescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(DIRECTX12_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

const auto& descriptorLayout = *(*match);
auto offset = m_impl->m_layout.descriptorOffsetForBinding(binding) + firstDescriptor;
auto descriptorSize = m_impl->m_layout.device().handle()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
CD3DX12_CPU_DESCRIPTOR_HANDLE descriptorHandle(m_impl->m_bufferHeap->GetCPUDescriptorHandleForHeapStart(), offset, descriptorSize);
Expand Down Expand Up @@ -222,8 +232,18 @@ void DirectX12DescriptorSet::update(UInt32 binding, const IDirectX12Buffer& buff
void DirectX12DescriptorSet::update(UInt32 binding, const IDirectX12Image& texture, UInt32 descriptor, UInt32 firstLevel, UInt32 levels, UInt32 firstLayer, UInt32 layers) const
{
// TODO: Add LOD lower bound (for clamping) as parameter?
// Acquire a descriptor handle.
const auto& descriptorLayout = m_impl->m_layout.descriptor(binding);
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const DirectX12DescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(DIRECTX12_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

const auto& descriptorLayout = *(*match);

auto offset = m_impl->m_layout.descriptorOffsetForBinding(binding);
CD3DX12_CPU_DESCRIPTOR_HANDLE descriptorHandle(m_impl->m_bufferHeap->GetCPUDescriptorHandleForHeapStart(), offset + descriptor, m_impl->m_layout.device().handle()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));

Expand Down Expand Up @@ -383,6 +403,16 @@ void DirectX12DescriptorSet::update(UInt32 binding, const IDirectX12Image& textu

void DirectX12DescriptorSet::update(UInt32 binding, const IDirectX12Sampler& sampler, UInt32 descriptor) const
{
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const DirectX12DescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(DIRECTX12_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

auto offset = m_impl->m_layout.descriptorOffsetForBinding(binding);

D3D12_SAMPLER_DESC samplerInfo = {
Expand All @@ -405,7 +435,17 @@ void DirectX12DescriptorSet::update(UInt32 binding, const IDirectX12Sampler& sam

void DirectX12DescriptorSet::update(UInt32 binding, const IDirectX12AccelerationStructure& accelerationStructure, UInt32 descriptor) const
{
const auto& layout = m_impl->m_layout.descriptor(binding);
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const DirectX12DescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(DIRECTX12_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

const auto& layout = *(*match);

if (layout.descriptorType() != DescriptorType::AccelerationStructure) [[unlikely]]
throw InvalidArgumentException("binding", "Invalid descriptor type. The binding {0} does not point to an acceleration structure descriptor.", binding);
Expand Down
51 changes: 46 additions & 5 deletions src/Backends/Vulkan/src/descriptor_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,25 @@ const VulkanDescriptorSetLayout& VulkanDescriptorSet::layout() const noexcept

void VulkanDescriptorSet::update(UInt32 binding, const IVulkanBuffer& buffer, UInt32 bufferElement, UInt32 elements, UInt32 firstDescriptor) const
{
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const VulkanDescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(VULKAN_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

const auto& descriptorLayout = *(*match);

VkWriteDescriptorSet descriptorWrite{ };
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrite.dstSet = this->handle();
descriptorWrite.dstBinding = binding;
descriptorWrite.dstArrayElement = firstDescriptor;
descriptorWrite.descriptorCount = 1;

auto& descriptorLayout = m_impl->m_layout.descriptor(binding);
Array<VkDescriptorBufferInfo> bufferInfos;
UInt32 elementCount = elements > 0 ? elements : buffer.elements() - bufferElement;

Expand Down Expand Up @@ -159,6 +170,18 @@ void VulkanDescriptorSet::update(UInt32 binding, const IVulkanBuffer& buffer, UI

void VulkanDescriptorSet::update(UInt32 binding, const IVulkanImage& texture, UInt32 descriptor, UInt32 firstLevel, UInt32 levels, UInt32 firstLayer, UInt32 layers) const
{
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const VulkanDescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(VULKAN_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

const auto& layout = *(*match);

VkDescriptorImageInfo imageInfo{ };
VkWriteDescriptorSet descriptorWrite{ };
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Expand All @@ -168,8 +191,6 @@ void VulkanDescriptorSet::update(UInt32 binding, const IVulkanImage& texture, UI
descriptorWrite.descriptorCount = 1;
descriptorWrite.pImageInfo = &imageInfo;

const auto& layout = m_impl->m_layout.descriptor(binding);

switch (layout.descriptorType())
{
case DescriptorType::Texture:
Expand Down Expand Up @@ -241,7 +262,17 @@ void VulkanDescriptorSet::update(UInt32 binding, const IVulkanImage& texture, UI

void VulkanDescriptorSet::update(UInt32 binding, const IVulkanSampler& sampler, UInt32 descriptor) const
{
const auto& layout = m_impl->m_layout.descriptor(binding);
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const VulkanDescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(VULKAN_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

const auto& layout = *(*match);

if (layout.descriptorType() != DescriptorType::Sampler) [[unlikely]]
throw InvalidArgumentException("binding", "Invalid descriptor type. The binding {0} does not point to a sampler descriptor.", binding);
Expand All @@ -263,7 +294,17 @@ void VulkanDescriptorSet::update(UInt32 binding, const IVulkanSampler& sampler,

void VulkanDescriptorSet::update(UInt32 binding, const IVulkanAccelerationStructure& accelerationStructure, UInt32 descriptor) const
{
const auto& layout = m_impl->m_layout.descriptor(binding);
// Find the descriptor.
auto descriptors = m_impl->m_layout.descriptors();
auto match = std::ranges::find_if(descriptors, [&binding](const VulkanDescriptorLayout* layout) { return layout->binding() == binding; });

if (match == descriptors.end()) [[unlikely]]
{
LITEFX_WARNING(VULKAN_LOG, "The descriptor set {0} does not contain a descriptor at binding {1}.", m_impl->m_layout.space(), binding);
return;
}

const auto& layout = *(*match);

if (layout.descriptorType() != DescriptorType::AccelerationStructure) [[unlikely]]
throw InvalidArgumentException("binding", "Invalid descriptor type. The binding {0} does not point to an acceleration structure descriptor.", binding);
Expand Down

0 comments on commit 1ae7bb3

Please sign in to comment.