Skip to content

Commit 90882b4

Browse files
authored
Fix vulkan validation errors (#478)
* Ignore invalid validation error for acceleration structure null descriptors * Bind 3D texture render targets as 2D arrays
1 parent 7943066 commit 90882b4

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

src/vulkan/vk-command.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,12 @@ void CommandRecorder::cmdBeginRenderPass(const commands::BeginRenderPass& cmd)
603603

604604
// Create attachment info
605605
VkRenderingAttachmentInfoKHR attachmentInfo = {VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR};
606-
attachmentInfo.imageView = checked_cast<TextureViewImpl*>(attachment.view)->getView().imageView;
606+
attachmentInfo.imageView = checked_cast<TextureViewImpl*>(attachment.view)->getRenderTargetView().imageView;
607607
attachmentInfo.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
608608
if (attachment.resolveTarget)
609609
{
610610
attachmentInfo.resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
611-
attachmentInfo.resolveImageView = resolveView->getView().imageView;
611+
attachmentInfo.resolveImageView = resolveView->getRenderTargetView().imageView;
612612
attachmentInfo.resolveImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
613613
}
614614
attachmentInfo.loadOp = translateLoadOp(attachment.loadOp);
@@ -648,7 +648,7 @@ void CommandRecorder::cmdBeginRenderPass(const commands::BeginRenderPass& cmd)
648648
{
649649
hasDepthAttachment = true;
650650
const auto& dsa = *desc.depthStencilAttachment;
651-
depthAttachmentInfo.imageView = checked_cast<TextureViewImpl*>(dsa.view)->getView().imageView;
651+
depthAttachmentInfo.imageView = checked_cast<TextureViewImpl*>(dsa.view)->getRenderTargetView().imageView;
652652
depthAttachmentInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
653653
depthAttachmentInfo.loadOp = translateLoadOp(dsa.depthLoadOp);
654654
depthAttachmentInfo.storeOp = translateStoreOp(dsa.depthStoreOp);
@@ -658,7 +658,7 @@ void CommandRecorder::cmdBeginRenderPass(const commands::BeginRenderPass& cmd)
658658
{
659659
hasStencilAttachment = true;
660660
const auto& dsa = *desc.depthStencilAttachment;
661-
stencilAttachmentInfo.imageView = checked_cast<TextureViewImpl*>(dsa.view)->getView().imageView;
661+
stencilAttachmentInfo.imageView = checked_cast<TextureViewImpl*>(dsa.view)->getRenderTargetView().imageView;
662662
stencilAttachmentInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
663663
stencilAttachmentInfo.loadOp = translateLoadOp(dsa.stencilLoadOp);
664664
stencilAttachmentInfo.storeOp = translateStoreOp(dsa.stencilStoreOp);

src/vulkan/vk-device.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,23 @@ VkBool32 DeviceImpl::handleDebugMessage(
9393
{
9494
return VK_FALSE;
9595
}
96-
// Ignore: VUID-StandaloneSpirv-None-10684
96+
// Ignore: VUID-StandaloneSpirv-None-10684
9797
// https://vulkan.lunarg.com/doc/view/1.4.313.1/windows/antora/spec/latest/appendices/spirvenv.html#VUID-StandaloneSpirv-None-10684
9898
// Not quite clear why this is happening, but for now we will ignore it.
9999
if (pCallbackData->messageIdNumber == -1307510846)
100100
{
101101
return VK_FALSE;
102102
}
103103

104+
// Ignore: VUID-VkWriteDescriptorSetAccelerationStructureKHR-pAccelerationStructures-03580
105+
// https://vulkan.lunarg.com/doc/view/1.4.321.1/windows/antora/spec/latest/chapters/descriptorsets.html#VUID-VkWriteDescriptorSetAccelerationStructureKHR-pAccelerationStructures-03580
106+
// Vulkan spec requires the nullDescriptor feature in VK_EXT_robustness2 to allow null-descriptors for acceleration
107+
// structures but currently complains even when nullDescriptor is available and enabled.
108+
if (pCallbackData->messageIdNumber == -1248876731)
109+
{
110+
return VK_FALSE;
111+
}
112+
104113
DebugMessageType msgType = DebugMessageType::Info;
105114

106115
const char* severity = "message";

src/vulkan/vk-texture.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ TextureViewImpl::TextureViewImpl(Device* device, const TextureViewDesc& desc)
114114
{
115115
}
116116

117-
TextureSubresourceView TextureImpl::getView(Format format, TextureAspect aspect, const SubresourceRange& range)
117+
TextureSubresourceView TextureImpl::getView(
118+
Format format,
119+
TextureAspect aspect,
120+
const SubresourceRange& range,
121+
bool isRenderTarget
122+
)
118123
{
119124
DeviceImpl* device = getDevice<DeviceImpl>();
120125

121-
ViewKey key = {format, aspect, range};
126+
ViewKey key = {format, aspect, range, isRenderTarget};
122127

123128
std::lock_guard<std::mutex> lock(m_mutex);
124129

@@ -154,7 +159,8 @@ TextureSubresourceView TextureImpl::getView(Format format, TextureAspect aspect,
154159
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
155160
break;
156161
case TextureType::Texture3D:
157-
createInfo.viewType = VK_IMAGE_VIEW_TYPE_3D;
162+
// 3D textures are bound as 2D arrays when used as render targets.
163+
createInfo.viewType = isRenderTarget ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_3D;
158164
break;
159165
case TextureType::TextureCube:
160166
createInfo.viewType = VK_IMAGE_VIEW_TYPE_CUBE;
@@ -171,6 +177,12 @@ TextureSubresourceView TextureImpl::getView(Format format, TextureAspect aspect,
171177
createInfo.subresourceRange.layerCount = range.layerCount;
172178
createInfo.subresourceRange.levelCount = range.mipCount;
173179

180+
if (isRenderTarget && m_desc.type == TextureType::Texture3D)
181+
{
182+
createInfo.subresourceRange.baseArrayLayer = 0;
183+
createInfo.subresourceRange.layerCount = m_desc.size.depth;
184+
}
185+
174186
VkResult result = device->m_api.vkCreateImageView(device->m_api.m_device, &createInfo, nullptr, &view.imageView);
175187
SLANG_RHI_ASSERT(result == VK_SUCCESS);
176188
return view;
@@ -200,7 +212,12 @@ Result TextureViewImpl::getDescriptorHandle(DescriptorHandleAccess access, Descr
200212

201213
TextureSubresourceView TextureViewImpl::getView()
202214
{
203-
return m_texture->getView(m_desc.format, m_desc.aspect, m_desc.subresourceRange);
215+
return m_texture->getView(m_desc.format, m_desc.aspect, m_desc.subresourceRange, false);
216+
}
217+
218+
TextureSubresourceView TextureViewImpl::getRenderTargetView()
219+
{
220+
return m_texture->getView(m_desc.format, m_desc.aspect, m_desc.subresourceRange, true);
204221
}
205222

206223
Result DeviceImpl::createTexture(const TextureDesc& desc_, const SubresourceData* initData, ITexture** outTexture)
@@ -241,6 +258,11 @@ Result DeviceImpl::createTexture(const TextureDesc& desc_, const SubresourceData
241258
{
242259
imageInfo.imageType = VK_IMAGE_TYPE_3D;
243260
imageInfo.extent = VkExtent3D{desc.size.width, desc.size.height, desc.size.depth};
261+
// When using 3D textures as render targets, we need to be able to create 2d array views.
262+
if (is_set(desc.usage, TextureUsage::RenderTarget))
263+
{
264+
imageInfo.flags = VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT;
265+
}
244266
break;
245267
}
246268
case TextureType::TextureCube:

src/vulkan/vk-texture.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ class TextureImpl : public Texture
3131
Format format;
3232
TextureAspect aspect;
3333
SubresourceRange range;
34+
bool isRenderTarget;
3435
bool operator==(const ViewKey& other) const
3536
{
36-
return format == other.format && aspect == other.aspect && range == other.range;
37+
return format == other.format && aspect == other.aspect && range == other.range &&
38+
isRenderTarget == other.isRenderTarget;
3739
}
3840
};
3941

@@ -56,7 +58,12 @@ class TextureImpl : public Texture
5658
std::mutex m_mutex;
5759
std::unordered_map<ViewKey, TextureSubresourceView, ViewKeyHasher> m_views;
5860

59-
TextureSubresourceView getView(Format format, TextureAspect aspect, const SubresourceRange& range);
61+
TextureSubresourceView getView(
62+
Format format,
63+
TextureAspect aspect,
64+
const SubresourceRange& range,
65+
bool isRenderTarget
66+
);
6067
};
6168

6269
class TextureViewImpl : public TextureView
@@ -79,6 +86,7 @@ class TextureViewImpl : public TextureView
7986
) override;
8087

8188
TextureSubresourceView getView();
89+
TextureSubresourceView getRenderTargetView();
8290
};
8391

8492
} // namespace rhi::vk

0 commit comments

Comments
 (0)