Skip to content

Commit

Permalink
Add function hooks for VK_EXT_shader_object
Browse files Browse the repository at this point in the history
Functions that are provided by VK_EXT_shader_object as well as other extensions are declared as an OR of both extensions in the macro.

Added a new feature boolean: m_ShaderObject to WrappedVulkan that can be checked against wherever the dynamic state booleans are used.

Co-authored-by: James Sumihiro <james.sumihiro@ntd.nintendo.com>
  • Loading branch information
2 people authored and baldurk committed May 4, 2024
1 parent 0b0d8b4 commit 20f0d68
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 210 deletions.
5 changes: 4 additions & 1 deletion renderdoc/driver/vulkan/vk_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,8 @@ enum class VulkanChunk : uint32_t
vkCmdCopyAccelerationStructureToMemoryKHR,
vkCmdCopyMemoryToAccelerationStructureKHR,
vkCreateAccelerationStructureKHR,
vkCmdBindShadersEXT,
vkCreateShadersEXT,
Max,
};

Expand Down Expand Up @@ -1120,7 +1122,8 @@ DECLARE_REFLECTION_ENUM(VulkanChunk);
SERIALISE_HANDLE(VkSurfaceKHR) \
SERIALISE_HANDLE(VkDescriptorUpdateTemplate) \
SERIALISE_HANDLE(VkSamplerYcbcrConversion) \
SERIALISE_HANDLE(VkAccelerationStructureKHR)
SERIALISE_HANDLE(VkAccelerationStructureKHR) \
SERIALISE_HANDLE(VkShaderEXT)

#define SERIALISE_HANDLE(type) DECLARE_REFLECTION_STRUCT(type)

Expand Down
5 changes: 5 additions & 0 deletions renderdoc/driver/vulkan/vk_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4057,6 +4057,11 @@ bool WrappedVulkan::ProcessChunk(ReadSerialiser &ser, VulkanChunk chunk)
case VulkanChunk::vkCreateAccelerationStructureKHR:
return Serialise_vkCreateAccelerationStructureKHR(ser, VK_NULL_HANDLE, NULL, NULL, NULL);

case VulkanChunk::vkCmdBindShadersEXT:
return Serialise_vkCmdBindShadersEXT(ser, VK_NULL_HANDLE, 0, NULL, NULL);
case VulkanChunk::vkCreateShadersEXT:
return Serialise_vkCreateShadersEXT(ser, VK_NULL_HANDLE, 0, NULL, NULL, NULL);

// chunks that are reserved but not yet serialised
case VulkanChunk::vkResetCommandPool:
case VulkanChunk::vkCreateDepthTargetView:
Expand Down
16 changes: 16 additions & 0 deletions renderdoc/driver/vulkan/vk_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ class WrappedVulkan : public IFrameCapturer
bool m_TaskShaders = false;
bool m_ListRestart = false;
bool m_AccelerationStructures = false;
bool m_ShaderObject = false;

PFN_vkSetDeviceLoaderData m_SetDeviceLoaderData;

Expand Down Expand Up @@ -2939,4 +2940,19 @@ class WrappedVulkan : public IFrameCapturer
VkDevice device, uint32_t accelerationStructureCount,
const VkAccelerationStructureKHR *pAccelerationStructures, VkQueryType queryType,
size_t dataSize, void *pData, size_t stride);

// VK_EXT_shader_object
IMPLEMENT_FUNCTION_SERIALISED(void, vkCmdBindShadersEXT, VkCommandBuffer commandBuffer,
uint32_t stageCount, const VkShaderStageFlagBits *pStages,
const VkShaderEXT *pShaders);

IMPLEMENT_FUNCTION_SERIALISED(VkResult, vkCreateShadersEXT, VkDevice device,
uint32_t createInfoCount, const VkShaderCreateInfoEXT *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkShaderEXT *pShaders);

void vkDestroyShaderEXT(VkDevice device, VkShaderEXT shader,
const VkAllocationCallbacks *pAllocator);

VkResult vkGetShaderBinaryDataEXT(VkDevice device, VkShaderEXT shader, size_t *pDataSize,
void *pData);
};
458 changes: 251 additions & 207 deletions renderdoc/driver/vulkan/vk_hookset_defs.h

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions renderdoc/driver/vulkan/vk_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ WRAPPED_POOL_INST(WrappedVkSurfaceKHR)
WRAPPED_POOL_INST(WrappedVkDescriptorUpdateTemplate)
WRAPPED_POOL_INST(WrappedVkSamplerYcbcrConversion)
WRAPPED_POOL_INST(WrappedVkAccelerationStructureKHR)
WRAPPED_POOL_INST(WrappedVkShaderEXT)

byte VkResourceRecord::markerValue[32] = {
0xaa, 0xbb, 0xcc, 0xdd, 0x88, 0x77, 0x66, 0x55, 0x01, 0x23, 0x45, 0x67, 0x98, 0x76, 0x54, 0x32,
Expand Down Expand Up @@ -144,6 +145,8 @@ VkResourceType IdentifyTypeByPtr(WrappedVkRes *ptr)
return eResSamplerConversion;
if(WrappedVkAccelerationStructureKHR::IsAlloc(ptr))
return eResAccelerationStructureKHR;
if(WrappedVkShaderEXT::IsAlloc(ptr))
return eResShaderEXT;

RDCERR("Unknown type for ptr 0x%p", ptr);

Expand Down
12 changes: 12 additions & 0 deletions renderdoc/driver/vulkan/vk_resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum VkResourceType
eResDescUpdateTemplate,
eResSamplerConversion,
eResAccelerationStructureKHR,
eResShaderEXT,
};

DECLARE_REFLECTION_ENUM(VkResourceType);
Expand Down Expand Up @@ -573,6 +574,16 @@ struct WrappedVkAccelerationStructureKHR : WrappedVkNonDispRes
TypeEnum = eResAccelerationStructureKHR,
};
};
struct WrappedVkShaderEXT : WrappedVkNonDispRes
{
WrappedVkShaderEXT(VkShaderEXT obj, ResourceId objId) : WrappedVkNonDispRes(obj, objId) {}
typedef VkShaderEXT InnerType;
ALLOCATE_WITH_WRAPPED_POOL(WrappedVkShaderEXT);
enum
{
TypeEnum = eResShaderEXT,
};
};

// VkDisplayKHR and VkDisplayModeKHR are both UNWRAPPED because there's no need to wrap them.
// The only thing we need to wrap VkSurfaceKHR for is to get back the window from it later.
Expand Down Expand Up @@ -676,6 +687,7 @@ UNWRAP_NONDISP_HELPER(VkSurfaceKHR)
UNWRAP_NONDISP_HELPER(VkDescriptorUpdateTemplate)
UNWRAP_NONDISP_HELPER(VkSamplerYcbcrConversion)
UNWRAP_NONDISP_HELPER(VkAccelerationStructureKHR)
UNWRAP_NONDISP_HELPER(VkShaderEXT)

// VkDisplayKHR and VkDisplayModeKHR are both UNWRAPPED because there's no need to wrap them.
// The only thing we need to wrap VkSurfaceKHR for is to get back the window from it later.
Expand Down
5 changes: 4 additions & 1 deletion renderdoc/driver/vulkan/vk_stringise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
template <>
rdcstr DoStringise(const VulkanChunk &el)
{
RDCCOMPILE_ASSERT((uint32_t)VulkanChunk::Max == 1207, "Chunks changed without updating names");
RDCCOMPILE_ASSERT((uint32_t)VulkanChunk::Max == 1209, "Chunks changed without updating names");

BEGIN_ENUM_STRINGISE(VulkanChunk)
{
Expand Down Expand Up @@ -239,6 +239,8 @@ rdcstr DoStringise(const VulkanChunk &el)
STRINGISE_ENUM_CLASS(vkCmdCopyAccelerationStructureToMemoryKHR)
STRINGISE_ENUM_CLASS(vkCmdCopyMemoryToAccelerationStructureKHR)
STRINGISE_ENUM_CLASS(vkCreateAccelerationStructureKHR)
STRINGISE_ENUM_CLASS(vkCmdBindShadersEXT)
STRINGISE_ENUM_CLASS(vkCreateShadersEXT)
STRINGISE_ENUM_CLASS_NAMED(Max, "Max Chunk");
}
END_ENUM_STRINGISE()
Expand Down Expand Up @@ -280,6 +282,7 @@ rdcstr DoStringise(const VkResourceType &el)
STRINGISE_ENUM(eResDescUpdateTemplate)
STRINGISE_ENUM(eResSamplerConversion)
STRINGISE_ENUM(eResAccelerationStructureKHR)
STRINGISE_ENUM(eResShaderEXT)
}
END_ENUM_STRINGISE();
}
Expand Down
113 changes: 113 additions & 0 deletions renderdoc/driver/vulkan/wrappers/vk_cmd_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8013,6 +8013,115 @@ VkResult WrappedVulkan::vkCopyMemoryToAccelerationStructureKHR(
return VK_ERROR_UNKNOWN;
}

template <typename SerialiserType>
bool WrappedVulkan::Serialise_vkCmdBindShadersEXT(SerialiserType &ser,
VkCommandBuffer commandBuffer, uint32_t stageCount,
const VkShaderStageFlagBits *pStages,
const VkShaderEXT *pShaders)
{
SERIALISE_ELEMENT(commandBuffer);
SERIALISE_ELEMENT(stageCount);
SERIALISE_ELEMENT_ARRAY(pStages, stageCount);
SERIALISE_ELEMENT_ARRAY(pShaders, stageCount).Important();

Serialise_DebugMessages(ser);

SERIALISE_CHECK_READ_ERRORS();

if(IsReplayingAndReading())
{
m_LastCmdBufferID = GetResourceManager()->GetOriginalID(GetResID(commandBuffer));

if(IsActiveReplaying(m_State))
{
if(InRerecordRange(m_LastCmdBufferID))
{
commandBuffer = RerecordCmdBuf(m_LastCmdBufferID);

{
VulkanRenderState &renderstate = GetCmdRenderState();

for(uint32_t i = 0; i < stageCount; i++)
{
int stageIndex = StageIndex(pStages[i]);

// calling vkCmdBindShadersEXT disturbs the corresponding pipeline bind points
// such that any pipelines previously bound to those points are no longer bound
if(stageIndex == (int)ShaderStage::Compute)
{
renderstate.compute.pipeline = ResourceId();
}
else
{
renderstate.graphics.pipeline = ResourceId();
}
}
}
}
else
{
commandBuffer = VK_NULL_HANDLE;
}
}
else
{
// track while reading since Serialise_vkCmdBindPipeline does as well
for(uint32_t i = 0; i < stageCount; i++)
{
int stageIndex = StageIndex(pStages[i]);

if(stageIndex == (int)ShaderStage::Compute)
{
m_BakedCmdBufferInfo[m_LastCmdBufferID].state.compute.pipeline = ResourceId();
}
else
{
m_BakedCmdBufferInfo[m_LastCmdBufferID].state.graphics.pipeline = ResourceId();
}
}
}

if(commandBuffer != VK_NULL_HANDLE)
ObjDisp(commandBuffer)
->CmdBindShadersEXT(Unwrap(commandBuffer), stageCount, pStages,
UnwrapArray(pShaders, stageCount));
}

return true;
}

void WrappedVulkan::vkCmdBindShadersEXT(VkCommandBuffer commandBuffer, uint32_t stageCount,
const VkShaderStageFlagBits *pStages,
const VkShaderEXT *pShaders)
{
SCOPED_DBG_SINK();

SERIALISE_TIME_CALL(ObjDisp(commandBuffer)
->CmdBindShadersEXT(Unwrap(commandBuffer), stageCount, pStages,
UnwrapArray(pShaders, stageCount)));

if(IsCaptureMode(m_State))
{
VkResourceRecord *record = GetRecord(commandBuffer);

CACHE_THREAD_SERIALISER();

SCOPED_SERIALISE_CHUNK(VulkanChunk::vkCmdBindShadersEXT);
Serialise_vkCmdBindShadersEXT(ser, commandBuffer, stageCount, pStages, pShaders);

record->AddChunk(scope.Get(&record->cmdInfo->alloc));
if(pShaders)
{
for(uint32_t i = 0; i < stageCount; i++)
{
// binding NULL is legal
if(pShaders[i] != VK_NULL_HANDLE)
record->MarkResourceFrameReferenced(GetResID(pShaders[i]), eFrameRef_Read);
}
}
}
}

INSTANTIATE_FUNCTION_SERIALISED(VkResult, vkCreateCommandPool, VkDevice device,
const VkCommandPoolCreateInfo *pCreateInfo,
const VkAllocationCallbacks *, VkCommandPool *pCommandPool);
Expand Down Expand Up @@ -8196,3 +8305,7 @@ INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdCopyAccelerationStructureToMemoryKHR,
INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdCopyMemoryToAccelerationStructureKHR,
VkCommandBuffer commandBuffer,
const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo)

INSTANTIATE_FUNCTION_SERIALISED(void, vkCmdBindShadersEXT, VkCommandBuffer commandBuffer,
uint32_t stageCount, const VkShaderStageFlagBits *pStages,
const VkShaderEXT *pShaders);
9 changes: 9 additions & 0 deletions renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,15 @@ bool WrappedVulkan::Serialise_vkCreateDevice(SerialiserType &ser, VkPhysicalDevi
CHECK_PHYS_EXT_FEATURE(nestedCommandBufferSimultaneousUse);
}
END_PHYS_EXT_CHECK();

BEGIN_PHYS_EXT_CHECK(VkPhysicalDeviceShaderObjectFeaturesEXT,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT);
{
CHECK_PHYS_EXT_FEATURE(shaderObject);

m_ShaderObject = ext->shaderObject != VK_FALSE;
}
END_PHYS_EXT_CHECK();
}

if(availFeatures.depthClamp)
Expand Down
6 changes: 6 additions & 0 deletions renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,3 +1228,9 @@ void WrappedVulkan::vkGetDeviceAccelerationStructureCompatibilityKHR(
{
*pCompatibility = VK_ACCELERATION_STRUCTURE_COMPATIBILITY_INCOMPATIBLE_KHR;
}

VkResult WrappedVulkan::vkGetShaderBinaryDataEXT(VkDevice device, VkShaderEXT shader,
size_t *pDataSize, void *pData)
{
return VK_ERROR_INITIALIZATION_FAILED;
}
14 changes: 13 additions & 1 deletion renderdoc/driver/vulkan/wrappers/vk_misc_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ DESTROY_IMPL(VkQueryPool, DestroyQueryPool)
DESTROY_IMPL(VkDescriptorUpdateTemplate, DestroyDescriptorUpdateTemplate)
DESTROY_IMPL(VkSamplerYcbcrConversion, DestroySamplerYcbcrConversion)
DESTROY_IMPL(VkAccelerationStructureKHR, DestroyAccelerationStructureKHR)
DESTROY_IMPL(VkShaderEXT, DestroyShaderEXT)

#undef DESTROY_IMPL

Expand Down Expand Up @@ -573,6 +574,13 @@ bool WrappedVulkan::ReleaseResource(WrappedVkRes *res)
vt->DestroyAccelerationStructureKHR(Unwrap(dev), real, NULL);
break;
}
case eResShaderEXT:
{
VkShaderEXT real = nondisp->real.As<VkShaderEXT>();
GetResourceManager()->ReleaseWrappedResource(VkShaderEXT(handle));
vt->DestroyShaderEXT(Unwrap(dev), real, NULL);
break;
}
}

return true;
Expand Down Expand Up @@ -2021,6 +2029,7 @@ static ObjData GetObjData(VkObjectType objType, uint64_t object)
case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR:
ret.record = GetRecord((VkAccelerationStructureKHR)object);
break;
case VK_OBJECT_TYPE_SHADER_EXT: ret.record = GetRecord((VkShaderEXT)object); break;

/////////////////////////////
// special cases
Expand Down Expand Up @@ -2065,7 +2074,6 @@ static ObjData GetObjData(VkObjectType objType, uint64_t object)
case VK_OBJECT_TYPE_BUFFER_COLLECTION_FUCHSIA:
case VK_OBJECT_TYPE_MICROMAP_EXT:
case VK_OBJECT_TYPE_OPTICAL_FLOW_SESSION_NV:
case VK_OBJECT_TYPE_SHADER_EXT:
case VK_OBJECT_TYPE_UNKNOWN:
case VK_OBJECT_TYPE_VIDEO_SESSION_KHR:
case VK_OBJECT_TYPE_VIDEO_SESSION_PARAMETERS_KHR:
Expand Down Expand Up @@ -2284,6 +2292,9 @@ bool WrappedVulkan::Serialise_vkDebugMarkerSetObjectNameEXT(
case eResAccelerationStructureKHR:
type = VK_DEBUG_REPORT_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR_EXT;
break;
case eResShaderEXT:
RDCWARN("There is no VkDebugReportObjectTypeEXT for VkShaderEXT");
break;
}

if(ObjDisp(m_Device)->DebugMarkerSetObjectNameEXT &&
Expand Down Expand Up @@ -2474,6 +2485,7 @@ bool WrappedVulkan::Serialise_vkSetDebugUtilsObjectNameEXT(
case eResDescUpdateTemplate: type = VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE; break;
case eResSamplerConversion: type = VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION; break;
case eResAccelerationStructureKHR: type = VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR; break;
case eResShaderEXT: type = VK_OBJECT_TYPE_SHADER_EXT; break;
}

if(ObjDisp(m_Device)->SetDebugUtilsObjectNameEXT && type != VK_OBJECT_TYPE_UNKNOWN &&
Expand Down
Loading

0 comments on commit 20f0d68

Please sign in to comment.