diff --git a/gapii/cc/vulkan_extras.inl b/gapii/cc/vulkan_extras.inl index 200d13b720..1ca72cf808 100644 --- a/gapii/cc/vulkan_extras.inl +++ b/gapii/cc/vulkan_extras.inl @@ -70,6 +70,23 @@ uint32_t SpyOverride_vkCreateSwapchainKHR(VkDevice device, VkSwapchainCreateInfoKHR* pCreateInfo, VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pImage); +uint32_t SpyOverride_vkDebugMarkerSetObjectTagEXT( + VkDevice device, VkDebugMarkerObjectTagInfoEXT* pTagInfo) { + return VkResult::VK_SUCCESS; +} + +uint32_t SpyOverride_vkDebugMarkerSetObjectNameEXT( + VkDevice device, VkDebugMarkerObjectNameInfoEXT* pNameInfo) { + return VkResult::VK_SUCCESS; +} + +void SpyOverride_vkCmdDebugMarkerBeginEXT( + VkCommandBuffer commandBuffer, VkDebugMarkerMarkerInfoEXT* pMarkerInfo) {} + +void SpyOverride_vkCmdDebugMarkerEndEXT(VkCommandBuffer commandBuffer) {} + +void SpyOverride_vkCmdDebugMarkerInsertEXT( + VkCommandBuffer commandBuffer, VkDebugMarkerMarkerInfoEXT* pMarkerInfo) {} void SpyOverride_RecreateInstance(const VkInstanceCreateInfo*, VkInstance*) {} void SpyOverride_RecreateState() {} void SpyOverride_RecreatePhysicalDevices(VkInstance, uint32_t*, @@ -206,8 +223,7 @@ void SpyOverride_RecreateCmdSetViewport(VkCommandBuffer, uint32_t, uint32_t, const VkViewport*) {} void SpyOverride_RecreateCmdSetDepthBias(VkCommandBuffer, float, float, float) { } -void SpyOverride_RecreateCmdSetDepthBounds(VkCommandBuffer, float, float) { -} +void SpyOverride_RecreateCmdSetDepthBounds(VkCommandBuffer, float, float) {} void SpyOverride_RecreateCmdSetLineWidth(VkCommandBuffer, float) {} void SpyOverride_RecreateCmdSetStencilCompareMask(VkCommandBuffer, VkStencilFaceFlags, diff --git a/gapii/vulkan/vk_graphics_spy/cc/GraphicsSpyLayer.json b/gapii/vulkan/vk_graphics_spy/cc/GraphicsSpyLayer.json index de05ff4d00..cce9343dc5 100644 --- a/gapii/vulkan/vk_graphics_spy/cc/GraphicsSpyLayer.json +++ b/gapii/vulkan/vk_graphics_spy/cc/GraphicsSpyLayer.json @@ -10,7 +10,19 @@ "functions": { "vkGetDeviceProcAddr": "gapid_vkGetDeviceProcAddr", "vkGetInstanceProcAddr": "gapid_vkGetInstanceProcAddr" - } + }, + "device_extensions": [ + { + "name": "VK_EXT_debug_marker", + "spec_version": "4", + "entrypoints": ["vkDebugMarkerSetObjectTagEXT", + "vkDebugMarkerSetObjectNameEXT", + "vkCmdDebugMarkerBeginEXT", + "vkCmdDebugMarkerEndEXT", + "vkCmdDebugMarkerInsertEXT" + ] + } + ] } } diff --git a/gapis/api/vulkan/custom_replay.go b/gapis/api/vulkan/custom_replay.go index ec259417ed..41981009d2 100644 --- a/gapis/api/vulkan/custom_replay.go +++ b/gapis/api/vulkan/custom_replay.go @@ -16,6 +16,7 @@ package vulkan import ( "context" + "strings" "github.com/google/gapid/gapis/api" "github.com/google/gapid/gapis/memory" @@ -1181,12 +1182,51 @@ func (a *RecreateComputePipeline) Mutate(ctx context.Context, s *api.State, b *b } func (a *VkCreateDevice) Mutate(ctx context.Context, s *api.State, b *builder.Builder) error { - // Hijack VkCreateDevice's Mutate() method entirely with our ReplayCreateVkDevice's Mutate(). - // Similar to VkCreateInstance's Mutate() above. + // Hijack VkCreateDevice's Mutate() method entirely with our + // ReplayCreateVkDevice's Mutate(). Similar to VkCreateInstance's Mutate() + // above. + // And we need to strip off the VK_EXT_debug_marker extension name when + // building instructions for replay. + createInfoPtr := a.PCreateInfo + allocated := []*api.AllocResult{} + if b != nil { + a.Extras().Observations().ApplyReads(s.Memory.ApplicationPool()) + createInfo := a.PCreateInfo.Read(ctx, a, s, nil) + defer func() { + for _, d := range allocated { + d.Free() + } + }() + extensionCount := uint64(createInfo.EnabledExtensionCount) + newExtensionNames := []memory.Pointer{} + for _, e := range createInfo.PpEnabledExtensionNames.Slice(0, extensionCount, s.MemoryLayout).Read(ctx, a, s, nil) { + extensionName := string(memory.CharToBytes(e.StringSlice(ctx, s).Read(ctx, a, s, nil))) + if !strings.Contains(extensionName, "VK_EXT_debug_marker") { + nameSliceData := s.AllocDataOrPanic(ctx, extensionName) + allocated = append(allocated, &nameSliceData) + newExtensionNames = append(newExtensionNames, nameSliceData.Ptr()) + } + } + new_extensionNamesData := s.AllocDataOrPanic(ctx, newExtensionNames) + allocated = append(allocated, &new_extensionNamesData) + createInfo.EnabledExtensionCount = uint32(len(newExtensionNames)) + createInfo.PpEnabledExtensionNames = NewCharᶜᵖᶜᵖ(new_extensionNamesData.Ptr()) + + newCreateInfoData := s.AllocDataOrPanic(ctx, createInfo) + allocated = append(allocated, &newCreateInfoData) + createInfoPtr = NewVkDeviceCreateInfoᶜᵖ(newCreateInfoData.Ptr()) + } cb := CommandBuilder{Thread: a.thread} - hijack := cb.ReplayCreateVkDevice(a.PhysicalDevice, a.PCreateInfo, a.PAllocator, a.PDevice, a.Result) + hijack := cb.ReplayCreateVkDevice(a.PhysicalDevice, createInfoPtr, a.PAllocator, a.PDevice, a.Result) hijack.Extras().MustClone(a.Extras().All()...) + + if b != nil { + for _, d := range allocated { + hijack.AddRead(d.Data()) + } + } + err := hijack.Mutate(ctx, s, b) if b == nil || err != nil { diff --git a/gapis/api/vulkan/templates/vk_spy_helpers.cpp.tmpl b/gapis/api/vulkan/templates/vk_spy_helpers.cpp.tmpl index d609ba2762..2f78dffce8 100644 --- a/gapis/api/vulkan/templates/vk_spy_helpers.cpp.tmpl +++ b/gapis/api/vulkan/templates/vk_spy_helpers.cpp.tmpl @@ -150,8 +150,59 @@ uint32_t VulkanSpy::SpyOverride_vkEnumerateInstanceExtensionProperties(const cha return VkResult::VK_SUCCESS; } -uint32_t VulkanSpy::SpyOverride_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { - *pCount = 0; +uint32_t VulkanSpy::SpyOverride_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) { + //auto next_layer_enumerate_extensions = mImports.mVkInstanceFunctions[PhysicalDevices[physicalDevice]->mInstance].vkEnumerateDeviceExtensionProperties; + gapii::VulkanImports::PFNVKENUMERATEDEVICEEXTENSIONPROPERTIES next_layer_enumerate_extensions = NULL; + auto phy_dev_iter = PhysicalDevices.find(physicalDevice); + if (phy_dev_iter != PhysicalDevices.end()) { + auto inst_func_iter = mImports.mVkInstanceFunctions.find(phy_dev_iter->second->mInstance); + if (inst_func_iter != mImports.mVkInstanceFunctions.end()) { + next_layer_enumerate_extensions = reinterpret_cast( + inst_func_iter->second.vkEnumerateDeviceExtensionProperties); + } + } + + uint32_t next_layer_count = 0; + uint32_t next_layer_result; + if (next_layer_enumerate_extensions) { + next_layer_result = next_layer_enumerate_extensions(physicalDevice, pLayerName, &next_layer_count, NULL); + if (next_layer_result != VkResult::VK_SUCCESS) { + return next_layer_result; + } + } + std::vector properties(next_layer_count, VkExtensionProperties{}); + //properties.reserve(next_layer_count+1); + if (next_layer_enumerate_extensions) { + next_layer_result = next_layer_enumerate_extensions(physicalDevice, pLayerName, &next_layer_count, properties.data()); + if (next_layer_result != VkResult::VK_SUCCESS) { + return next_layer_result; + } + } + bool has_debug_marker_ext = false; + for (VkExtensionProperties& ext : properties) { + // TODO: Check the spec version and emit warning if not match. + // TODO: refer to VK_EXT_DEBUG_MARKER_EXTENSION_NAME + if (!strcmp(ext.mextensionName, "VK_EXT_debug_marker")) { + has_debug_marker_ext = true; + break; + } + } + if (!has_debug_marker_ext) { + // TODO: refer to VK_EXT_DEBUG_MARKER_EXTENSION_NAME and VK_EXT_DEBUG_MARKER_SPEC_VERSION + char debug_marker_extension_name[] = "VK_EXT_debug_marker"; + uint32_t debug_marker_spec_version = 4; + properties.emplace_back(VkExtensionProperties{debug_marker_extension_name, debug_marker_spec_version}); + } + if (pProperties == NULL) { + *pCount = properties.size(); + return VkResult::VK_SUCCESS; + } + uint32_t copy_count = properties.size() < *pCount ? properties.size():*pCount; + memcpy(pProperties, properties.data(), copy_count * sizeof(VkExtensionProperties)); + if (*pCount < properties.size()) { + return VkResult::VK_INCOMPLETE; + } + *pCount = properties.size(); return VkResult::VK_SUCCESS; } @@ -223,7 +274,7 @@ void VulkanSpy::SpyOverride_vkDestroyInstance(VkInstance instance, VkAllocationC } uint32_t VulkanSpy::SpyOverride_vkCreateDevice(VkPhysicalDevice physicalDevice, VkDeviceCreateInfo* pCreateInfo, VkAllocationCallbacks* pAllocator, VkDevice* pDevice) { - VkLayerDeviceCreateInfo *layer_info = get_layer_link_info(pCreateInfo); + VkLayerDeviceCreateInfo *layer_info = get_layer_link_info(pCreateInfo); // Grab the fpGetInstanceProcAddr from the layer_info. We will get // vkCreateDevice from this. // Note: we cannot use our instance_map because we do not have a @@ -248,6 +299,30 @@ uint32_t VulkanSpy::SpyOverride_vkCreateDevice(VkPhysicalDevice physicalDevice, // so increment the pointer for it. layer_info->u.pLayerInfo = layer_info->u.pLayerInfo->pNext; + //// Prepare the enabled extension list for the next layer's vkCreateDevice + auto enumerate_dev_exts = reinterpret_cast( + mImports.mVkInstanceFunctions[PhysicalDevices[physicalDevice]->mInstance].vkEnumerateDeviceExtensionProperties); + uint32_t extension_count = 0; + uint32_t enumerate_extension_result; + enumerate_extension_result = enumerate_dev_exts(physicalDevice, nullptr, &extension_count, nullptr); + if (enumerate_extension_result != VkResult::VK_SUCCESS) { + return VkResult::VK_ERROR_INITIALIZATION_FAILED; + } + std::vector ext_properties; + ext_properties.reserve(extension_count); + enumerate_extension_result = enumerate_dev_exts(physicalDevice, nullptr, &extension_count, ext_properties.data()); + if (enumerate_extension_result != VkResult::VK_SUCCESS) { + return VkResult::VK_ERROR_INITIALIZATION_FAILED; + } + std::vector extension_names; + for(uint32_t i = 0; i < pCreateInfo->menabledExtensionCount; i++) { + if (strcmp(pCreateInfo->mppEnabledExtensionNames[i], "VK_EXT_debug_marker")) { + extension_names.push_back(pCreateInfo->mppEnabledExtensionNames[i]); + } + } + pCreateInfo->mppEnabledExtensionNames = extension_names.data(); + pCreateInfo->menabledExtensionCount = extension_names.size(); + // Actually make the call to vkCreateDevice. uint32_t result = create_device(physicalDevice, pCreateInfo, pAllocator, pDevice); diff --git a/gapis/api/vulkan/vulkan.api b/gapis/api/vulkan/vulkan.api index e6bd1a3d27..6bfab6589d 100644 --- a/gapis/api/vulkan/vulkan.api +++ b/gapis/api/vulkan/vulkan.api @@ -83,6 +83,8 @@ define NULL_HANDLE 0 @extension("VK_EXT_debug_report") define VK_EXT_DEBUG_REPORT_SPEC_VERSION 1 @extension("VK_EXT_debug_report") define VK_EXT_DEBUG_REPORT_EXTENSION_NAME "VK_EXT_debug_report" +@extension("VK_EXT_debug_marker") define VK_EXT_DEBUG_MARKER_SPEC_VERSION 4 +@extension("VK_EXT_debug_marker") define VK_EXT_DEBUG_MARKER_EXTENSION_NAME "VK_EXT_debug_marker" ///////////// // Types // @@ -279,6 +281,11 @@ enum VkStructureType { //@extension("VK_EXT_debug_report") VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT = 1000011000, + //@extension("VK_EXT_debug_marker") + VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT = 1000022000 + VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_TAG_INFO_EXT = 1000022001 + VK_STRUCTURE_TYPE_DEBUG_MARKER_MARKER_INFO_EXT = 1000022002 + //@extension("VK_NV_dedicated_allocation") VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_IMAGE_CREATE_INFO_NV = 1000026000, VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV = 1000026001, @@ -2694,6 +2701,7 @@ cmd VkResult vkEnumerateInstanceExtensionProperties( } @indirect("VkPhysicalDevice", "VkInstance") +@override cmd VkResult vkEnumerateDeviceExtensionProperties( VkPhysicalDevice physicalDevice, string pLayerName, @@ -8644,6 +8652,100 @@ cmd void vkDebugReportMessageEXT( } extern void validate(string layerName, bool condition, string message) +// ---------------------------------------------------------------------------- +// VK_EXT_debug_marker +// ---------------------------------------------------------------------------- +@extension("VK_EXT_debug_marker") +@serialize +class VkDebugMarkerObjectNameInfoEXT { + VkStructureType sType + const void* pNext + VkDebugReportObjectTypeEXT objectType + u64 object + const char* pObjectName +} + +@extension("VK_EXT_debug_marker") +@serialize +class VkDebugMarkerObjectTagInfoEXT { + VkStructureType sType + const void* pNext + VkDebugReportObjectTypeEXT objectType + u64 object + u64 tagName + size tagSize + const void* pTag +} + +@extension("VK_EXT_debug_marker") +@serialize +class VkDebugMarkerMarkerInfoEXT { + VkStructureType sType + const void* pNext + const char* pMarkerName + @readonly f32[4] color +} + +@threadSafety("app") +@extension("VK_EXT_debug_marker") +@extension("VK_EXT_debug_report") +@indirect("VkDevice") +@override +@no_replay +cmd VkResult vkDebugMarkerSetObjectTagEXT( + VkDevice device, + VkDebugMarkerObjectTagInfoEXT* pTagInfo) { + read(pTagInfo[0:1]) + return ? +} + +@threadSafety("app") +@extension("VK_EXT_debug_marker") +@extension("VK_EXT_debug_report") +@indirect("VkDevice") +@override +@no_replay +cmd VkResult vkDebugMarkerSetObjectNameEXT( + VkDevice device, + VkDebugMarkerObjectNameInfoEXT* pNameInfo) { + read(pNameInfo[0:1]) + return ? +} + +@threadSafety("app") +@indirect("VkCommandBuffer", "VkDevice") +@extension("VK_EXT_debug_marker") +@extension("VK_EXT_debug_report") +@override +@no_replay +cmd void vkCmdDebugMarkerBeginEXT( + VkCommandBuffer commandBuffer, + VkDebugMarkerMarkerInfoEXT* pMarkerInfo) { + read(pMarkerInfo[0:1]) +} + +@threadSafety("app") +@indirect("VkCommandBuffer", "VkDevice") +@extension("VK_EXT_debug_marker") +@extension("VK_EXT_debug_report") +@override +@no_replay +cmd void vkCmdDebugMarkerEndEXT( + VkCommandBuffer commandBuffer) { +} + +@threadSafety("app") +@indirect("VkCommandBuffer", "VkDevice") +@extension("VK_EXT_debug_marker") +@extension("VK_EXT_debug_report") +@override +@no_replay +cmd void vkCmdDebugMarkerInsertEXT( + VkCommandBuffer commandBuffer, + VkDebugMarkerMarkerInfoEXT* pMarkerInfo) { + read(pMarkerInfo[0:1]) +} + ///////////////////////////// // Struct subroutines // ///////////////////////////// diff --git a/gapis/resolve/command_tree.go b/gapis/resolve/command_tree.go index 5b2e1e36c4..98eafb2610 100644 --- a/gapis/resolve/command_tree.go +++ b/gapis/resolve/command_tree.go @@ -281,7 +281,7 @@ func (r *CommandTreeResolvable) Resolve(ctx context.Context) (interface{}, error if v, ok := snc.SubcommandGroups[id]; ok { r := out.root.AddRoot([]uint64{uint64(id)}) - // subcommands are added before nested SubCmdRoots. + // subcommands are added before nesting SubCmdRoots. cv := append([]api.SubCmdIdx{}, v...) sort.SliceStable(cv, func(i, j int) bool { return len(cv[i]) < len(cv[j]) }) for _, x := range cv {