Skip to content

Commit

Permalink
add VK_KHR_maintenance5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
qbojj committed Mar 7, 2024
1 parent 10d4023 commit 071e612
Show file tree
Hide file tree
Showing 26 changed files with 1,046 additions and 345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ void VulkanPipelineStateViewer::setState()
BufferDescription *buf = m_Ctx.GetBuffer(state.inputAssembly.indexBuffer.resourceId);

if(buf)
length = buf->length;
length = qMin(buf->length, state.inputAssembly.indexBuffer.byteSize);

RDTreeWidgetItem *node = new RDTreeWidgetItem(
{tr("Index"), state.inputAssembly.indexBuffer.resourceId, tr("Index"), lit("-"),
Expand Down Expand Up @@ -3802,7 +3802,7 @@ void VulkanPipelineStateViewer::exportHTML(QXmlStreamWriter &xml, const VKPipe::
if(ib)
{
name = m_Ctx.GetResourceName(ia.indexBuffer.resourceId);
length = ib->length;
length = qMin(ib->length, ia.indexBuffer.byteSize);
}

QString ifmt = lit("UNKNOWN");
Expand Down
2 changes: 1 addition & 1 deletion renderdoc/api/replay/pipestate.inl
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ BoundVBuffer PipeState::GetIBuffer() const
ret.resourceId = m_Vulkan->inputAssembly.indexBuffer.resourceId;
ret.byteOffset = m_Vulkan->inputAssembly.indexBuffer.byteOffset;
ret.byteStride = m_Vulkan->inputAssembly.indexBuffer.byteStride;
ret.byteSize = ~0ULL;
ret.byteSize = m_Vulkan->inputAssembly.indexBuffer.byteSize;
}
}

Expand Down
5 changes: 4 additions & 1 deletion renderdoc/api/replay/vk_pipestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ When not using pipeline libraries, this will be identical to :data:`pipelinePreR
)");
ResourceId pipelineFragmentLayoutResourceId;
DOCUMENT("The flags used to create the pipeline object.");
uint32_t flags = 0;
uint64_t flags = 0;

DOCUMENT(R"(The bound descriptor sets.
Expand All @@ -411,6 +411,9 @@ struct IndexBuffer
DOCUMENT("The byte offset from the start of the buffer to the beginning of the index data.");
uint64_t byteOffset = 0;

DOCUMENT("The number of bytes in the index buffer.");
uint64_t byteSize = 0;

DOCUMENT(R"(The number of bytes for each index in the index buffer. Typically 2 or 4 bytes but
it can be 0 if no index buffer is bound.
)");
Expand Down
2 changes: 1 addition & 1 deletion renderdoc/driver/vulkan/extension_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Maintainers can update this file by updating vk.xml in this folder and running `
* `VK_KHR_maintenance2`
* `VK_KHR_maintenance3`
* `VK_KHR_maintenance4`
* `VK_KHR_maintenance5`
* `VK_KHR_multiview`
* `VK_KHR_performance_query`
* `VK_KHR_pipeline_executable_properties`
Expand Down Expand Up @@ -235,7 +236,6 @@ KHR extensions will definitely be implemented at some point, though KHR extensio

* `VK_KHR_cooperative_matrix`
* `VK_KHR_dynamic_rendering_local_read`
* `VK_KHR_maintenance5`
* `VK_KHR_maintenance6`
* `VK_KHR_map_memory2`
* `VK_KHR_shader_expect_assume`
Expand Down
40 changes: 40 additions & 0 deletions renderdoc/driver/vulkan/vk_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
#define VkAccessFlagBits2 VkAccessFlagBits2_VkFlags64_typedef
#define VkPipelineStageFlagBits2 VkPipelineStageFlagBits2_VkFlags64_typedef
#define VkFormatFeatureFlagBits2 VkFormatFeatureFlagBits2_VkFlags64_typedef
#define VkBufferUsageFlagBits2KHR VkBufferUsageFlagBits2KHR_VkFlags64_typedef
#define VkPipelineCreateFlagBits2KHR VkPipelineCreateFlagBits2KHR_VkFlags64_typedef

#include "core/core.h"
#include "core/resource_manager.h"
Expand All @@ -84,6 +86,8 @@
#undef VkAccessFlagBits2
#undef VkPipelineStageFlagBits2
#undef VkFormatFeatureFlagBits2
#undef VkBufferUsageFlagBits2KHR
#undef VkPipelineCreateFlagBits2KHR

#undef Bool
#undef None
Expand Down Expand Up @@ -129,6 +133,14 @@ int SampleIndex(VkSampleCountFlagBits countFlag);
int StageIndex(VkShaderStageFlagBits stageFlag);
VkShaderStageFlags ShaderMaskFromIndex(size_t index);

// VK_KHR_maintenance5 helpers
VkPipelineCreateFlags2KHR GetPipelineCreateFlags(const VkGraphicsPipelineCreateInfo *info);
VkPipelineCreateFlags2KHR GetPipelineCreateFlags(const VkComputePipelineCreateInfo *info);
VkBufferUsageFlags2KHR GetBufferUsageFlags(const VkBufferCreateInfo *info);
void SetPipelineCreateFlags(VkGraphicsPipelineCreateInfo *info, VkPipelineCreateFlags2KHR flags);
void SetPipelineCreateFlags(VkComputePipelineCreateInfo *info, VkPipelineCreateFlags2KHR flags);
void SetBufferUsageFlags(VkBufferCreateInfo *info, VkBufferUsageFlags2KHR flags);

struct PackedWindowHandle
{
PackedWindowHandle(WindowingSystem s, void *h) : system(s), handle(h) {}
Expand Down Expand Up @@ -1065,6 +1077,7 @@ enum class VulkanChunk : uint32_t
vkCmdCopyAccelerationStructureToMemoryKHR,
vkCmdCopyMemoryToAccelerationStructureKHR,
vkCreateAccelerationStructureKHR,
vkCmdBindIndexBuffer2KHR,
Max,
};

Expand Down Expand Up @@ -1547,6 +1560,14 @@ DECLARE_REFLECTION_STRUCT(VkVertexInputBindingDescription2EXT);
DECLARE_REFLECTION_STRUCT(VkWriteDescriptorSet);
DECLARE_REFLECTION_STRUCT(VkWriteDescriptorSetAccelerationStructureKHR);
DECLARE_REFLECTION_STRUCT(VkWriteDescriptorSetInlineUniformBlock);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceMaintenance5FeaturesKHR);
DECLARE_REFLECTION_STRUCT(VkPhysicalDeviceMaintenance5PropertiesKHR);
DECLARE_REFLECTION_STRUCT(VkRenderingAreaInfoKHR);
DECLARE_REFLECTION_STRUCT(VkDeviceImageSubresourceInfoKHR);
DECLARE_REFLECTION_STRUCT(VkPipelineCreateFlags2CreateInfoKHR);
DECLARE_REFLECTION_STRUCT(VkBufferUsageFlags2CreateInfoKHR);
DECLARE_REFLECTION_STRUCT(VkImageSubresource2KHR);
DECLARE_REFLECTION_STRUCT(VkSubresourceLayout2KHR);

DECLARE_DESERIALISE_TYPE(VkAccelerationStructureBuildGeometryInfoKHR);
DECLARE_DESERIALISE_TYPE(VkAccelerationStructureBuildSizesInfoKHR);
Expand Down Expand Up @@ -1973,6 +1994,14 @@ DECLARE_DESERIALISE_TYPE(VkVertexInputBindingDescription2EXT);
DECLARE_DESERIALISE_TYPE(VkWriteDescriptorSet);
DECLARE_DESERIALISE_TYPE(VkWriteDescriptorSetAccelerationStructureKHR);
DECLARE_DESERIALISE_TYPE(VkWriteDescriptorSetInlineUniformBlock);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceMaintenance5FeaturesKHR);
DECLARE_DESERIALISE_TYPE(VkPhysicalDeviceMaintenance5PropertiesKHR);
DECLARE_DESERIALISE_TYPE(VkRenderingAreaInfoKHR);
DECLARE_DESERIALISE_TYPE(VkDeviceImageSubresourceInfoKHR);
DECLARE_DESERIALISE_TYPE(VkPipelineCreateFlags2CreateInfoKHR);
DECLARE_DESERIALISE_TYPE(VkBufferUsageFlags2CreateInfoKHR);
DECLARE_DESERIALISE_TYPE(VkImageSubresource2KHR);
DECLARE_DESERIALISE_TYPE(VkSubresourceLayout2KHR);

// plain structs with no next chain
DECLARE_REFLECTION_STRUCT(VkAabbPositionsKHR);
Expand Down Expand Up @@ -2061,6 +2090,7 @@ DECLARE_REFLECTION_STRUCT(VkVertexInputBindingDescription);
DECLARE_REFLECTION_STRUCT(VkVertexInputBindingDivisorDescriptionEXT);
DECLARE_REFLECTION_STRUCT(VkViewport);
DECLARE_REFLECTION_STRUCT(VkXYColorEXT);
DECLARE_REFLECTION_STRUCT(VkSubresourceLayout);

// rdcarray serialisation is generic but the stringification is not
DECLARE_STRINGISE_TYPE(rdcarray<VkAccelerationStructureBuildRangeInfoKHR>);
Expand Down Expand Up @@ -2158,6 +2188,14 @@ enum VkFormatFeatureFlagBits2 : uint64_t
{
};

enum VkBufferUsageFlagBits2KHR : uint64_t
{
};

enum VkPipelineCreateFlagBits2KHR : uint64_t
{
};

// enums

DECLARE_REFLECTION_ENUM(VkAccelerationStructureBuildTypeKHR);
Expand Down Expand Up @@ -2312,6 +2350,8 @@ DECLARE_REFLECTION_ENUM(VkValidationCheckEXT);
DECLARE_REFLECTION_ENUM(VkValidationFeatureDisableEXT);
DECLARE_REFLECTION_ENUM(VkValidationFeatureEnableEXT);
DECLARE_REFLECTION_ENUM(VkVertexInputRate);
DECLARE_REFLECTION_ENUM(VkBufferUsageFlagBits2KHR);
DECLARE_REFLECTION_ENUM(VkPipelineCreateFlagBits2KHR);

// win32 only enums
#ifdef VK_USE_PLATFORM_WIN32_KHR
Expand Down
88 changes: 88 additions & 0 deletions renderdoc/driver/vulkan/vk_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

#include "stb/stb_image_write.h"

#include <assert.h>

RDOC_EXTERN_CONFIG(bool, Vulkan_Debug_VerboseCommandRecording);

RDOC_DEBUG_CONFIG(bool, Vulkan_Debug_SingleSubmitFlushing, false,
Expand Down Expand Up @@ -1514,6 +1516,10 @@ static const VkExtensionProperties supportedExtensions[] = {
VK_KHR_MAINTENANCE_4_EXTENSION_NAME,
VK_KHR_MAINTENANCE_4_SPEC_VERSION,
},
{
VK_KHR_MAINTENANCE_5_EXTENSION_NAME,
VK_KHR_MAINTENANCE_5_SPEC_VERSION,
},
{
VK_KHR_MULTIVIEW_EXTENSION_NAME,
VK_KHR_MULTIVIEW_SPEC_VERSION,
Expand Down Expand Up @@ -4003,6 +4009,10 @@ bool WrappedVulkan::ProcessChunk(ReadSerialiser &ser, VulkanChunk chunk)
case VulkanChunk::vkCreateAccelerationStructureKHR:
return Serialise_vkCreateAccelerationStructureKHR(ser, VK_NULL_HANDLE, NULL, NULL, NULL);

case VulkanChunk::vkCmdBindIndexBuffer2KHR:
return Serialise_vkCmdBindIndexBuffer2KHR(ser, VK_NULL_HANDLE, VK_NULL_HANDLE, 0, 0,
VK_INDEX_TYPE_MAX_ENUM);

// chunks that are reserved but not yet serialised
case VulkanChunk::vkResetCommandPool:
case VulkanChunk::vkCreateDepthTargetView:
Expand Down Expand Up @@ -5573,6 +5583,84 @@ void WrappedVulkan::ReplayDraw(VkCommandBuffer cmd, const ActionDescription &act
}
}

VkPipelineCreateFlags2KHR WrappedVulkan::GetPipelineCreateFlags(const VkGraphicsPipelineCreateInfo *info)
{
const VkPipelineCreateFlags2CreateInfoKHR *flags2 =
(const VkPipelineCreateFlags2CreateInfoKHR *)FindNextStruct(
info, VK_STRUCTURE_TYPE_PIPELINE_CREATE_FLAGS_2_CREATE_INFO_KHR);
if(flags2)
return flags2->flags;

return info->flags;
}

VkPipelineCreateFlags2KHR WrappedVulkan::GetPipelineCreateFlags(const VkComputePipelineCreateInfo *info)
{
const VkPipelineCreateFlags2CreateInfoKHR *flags2 =
(const VkPipelineCreateFlags2CreateInfoKHR *)FindNextStruct(
info, VK_STRUCTURE_TYPE_PIPELINE_CREATE_FLAGS_2_CREATE_INFO_KHR);
if(flags2)
return flags2->flags;

return info->flags;
}

VkBufferUsageFlags2KHR WrappedVulkan::GetBufferUsageFlags(const VkBufferCreateInfo *info)
{
const VkBufferUsageFlags2CreateInfoKHR *usage2 =
(const VkBufferUsageFlags2CreateInfoKHR *)FindNextStruct(
info, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
if(usage2)
return usage2->usage;

return info->usage;
}

void WrappedVulkan::SetPipelineCreateFlags(VkGraphicsPipelineCreateInfo *info,
VkPipelineCreateFlags2KHR flags)
{
VkPipelineCreateFlags2CreateInfoKHR *flags2 = (VkPipelineCreateFlags2CreateInfoKHR *)FindNextStruct(
info, VK_STRUCTURE_TYPE_PIPELINE_CREATE_FLAGS_2_CREATE_INFO_KHR);
if(flags2)
{
flags2->flags = flags;
}
else
{
assert(flags <= VK_PIPELINE_CREATE_FLAG_BITS_MAX_ENUM);
info->flags = (VkPipelineCreateFlags)flags;
}
}
void WrappedVulkan::SetPipelineCreateFlags(VkComputePipelineCreateInfo *info,
VkPipelineCreateFlags2KHR flags)
{
VkPipelineCreateFlags2CreateInfoKHR *flags2 = (VkPipelineCreateFlags2CreateInfoKHR *)FindNextStruct(
info, VK_STRUCTURE_TYPE_PIPELINE_CREATE_FLAGS_2_CREATE_INFO_KHR);
if(flags2)
{
flags2->flags = flags;
}
else
{
assert(flags <= VK_PIPELINE_CREATE_FLAG_BITS_MAX_ENUM);
info->flags = (VkPipelineCreateFlags)flags;
}
}
void WrappedVulkan::SetBufferUsageFlags(VkBufferCreateInfo *info, VkBufferUsageFlags2KHR flags)
{
VkBufferUsageFlags2CreateInfoKHR *usage2 = (VkBufferUsageFlags2CreateInfoKHR *)FindNextStruct(
info, VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR);
if(usage2)
{
usage2->usage = flags;
}
else
{
assert(flags <= VK_BUFFER_USAGE_FLAG_BITS_MAX_ENUM);
info->usage = (VkBufferUsageFlags)flags;
}
}

#if ENABLED(ENABLE_UNIT_TESTS)

#undef None
Expand Down
25 changes: 25 additions & 0 deletions renderdoc/driver/vulkan/vk_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,17 @@ class WrappedVulkan : public IFrameCapturer
return NULL;
}

// VK_KHR_maintenance5 helpers
static VkPipelineCreateFlags2KHR GetPipelineCreateFlags(const VkGraphicsPipelineCreateInfo *info);
static VkPipelineCreateFlags2KHR GetPipelineCreateFlags(const VkComputePipelineCreateInfo *info);
static VkBufferUsageFlags2KHR GetBufferUsageFlags(const VkBufferCreateInfo *info);

static void SetPipelineCreateFlags(VkGraphicsPipelineCreateInfo *info,
VkPipelineCreateFlags2KHR flags);
static void SetPipelineCreateFlags(VkComputePipelineCreateInfo *info,
VkPipelineCreateFlags2KHR flags);
static void SetBufferUsageFlags(VkBufferCreateInfo *info, VkBufferUsageFlags2KHR flags);

// Device initialization

IMPLEMENT_FUNCTION_SERIALISED(VkResult, vkCreateInstance, const VkInstanceCreateInfo *pCreateInfo,
Expand Down Expand Up @@ -2861,4 +2872,18 @@ class WrappedVulkan : public IFrameCapturer
VkDevice device, uint32_t accelerationStructureCount,
const VkAccelerationStructureKHR *pAccelerationStructures, VkQueryType queryType,
size_t dataSize, void *pData, size_t stride);

// VK_KHR_maintenance5
IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdBindIndexBuffer2KHR, VkCommandBuffer commandBuffer,
VkBuffer buffer, VkDeviceSize offset, VkDeviceSize size,
VkIndexType indexType);
IMPLEMENT_FUNCTION_SERIALISED(void, vkGetDeviceImageSubresourceLayoutKHR, VkDevice device,
const VkDeviceImageSubresourceInfoKHR *pInfo,
VkSubresourceLayout2KHR *pLayout);
IMPLEMENT_FUNCTION_SERIALISED(void, vkGetImageSubresourceLayout2KHR, VkDevice device,
VkImage image, const VkImageSubresource2KHR *pSubresource,
VkSubresourceLayout2KHR *pLayout);
IMPLEMENT_FUNCTION_SERIALISED(void, vkGetRenderingAreaGranularityKHR, VkDevice device,
const VkRenderingAreaInfoKHR *pRenderingAreaInfo,
VkExtent2D *pGranularity);
};
36 changes: 18 additions & 18 deletions renderdoc/driver/vulkan/vk_dispatchtables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ void InitInstanceExtensionTables(VkInstance instance, InstanceDeviceInfo *info)
}

#undef HookInitPromotedExtension
#define HookInitPromotedExtension(cond, func, suffix) \
if(cond) \
{ \
InstanceGPA(func); \
InstanceGPA(CONCAT(func, suffix)); \
if(table->func == NULL) \
table->func = table->CONCAT(func, suffix); \
if(table->CONCAT(func, suffix) == NULL) \
table->CONCAT(func, suffix) = table->func; \
#define HookInitPromotedExtension(cond, version, func, suffix) \
if(cond) \
{ \
InstanceGPA(func); \
InstanceGPA(CONCAT(func, suffix)); \
if(table->func == NULL) \
table->func = table->CONCAT(func, suffix); \
if(table->CONCAT(func, suffix) == NULL) \
table->CONCAT(func, suffix) = table->func; \
}

#undef HookInitExtensionEXTtoKHR
Expand Down Expand Up @@ -140,15 +140,15 @@ void InitDeviceExtensionTables(VkDevice device, InstanceDeviceInfo *info)
}

#undef HookInitPromotedExtension
#define HookInitPromotedExtension(cond, func, suffix) \
if(cond) \
{ \
DeviceGPA(func); \
DeviceGPA(CONCAT(func, suffix)); \
if(table->func == NULL) \
table->func = table->CONCAT(func, suffix); \
if(table->CONCAT(func, suffix) == NULL) \
table->CONCAT(func, suffix) = table->func; \
#define HookInitPromotedExtension(cond, version, func, suffix) \
if(cond) \
{ \
DeviceGPA(func); \
DeviceGPA(CONCAT(func, suffix)); \
if(table->func == NULL) \
table->func = table->CONCAT(func, suffix); \
if(table->CONCAT(func, suffix) == NULL) \
table->CONCAT(func, suffix) = table->func; \
}

#undef HookInitExtensionEXTtoKHR
Expand Down
Loading

0 comments on commit 071e612

Please sign in to comment.