Skip to content

Commit

Permalink
Add VK_EXT_debug_marker (#994)
Browse files Browse the repository at this point in the history
Enables extension when tracing and show the commands in the trace
  • Loading branch information
Qining authored Aug 25, 2017
1 parent 0c47ee9 commit 84668f0
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 10 deletions.
20 changes: 18 additions & 2 deletions gapii/cc/vulkan_extras.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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*,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion gapii/vulkan/vk_graphics_spy/cc/GraphicsSpyLayer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
}
}

46 changes: 43 additions & 3 deletions gapis/api/vulkan/custom_replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package vulkan

import (
"context"
"strings"

"github.com/google/gapid/gapis/api"
"github.com/google/gapid/gapis/memory"
Expand Down Expand Up @@ -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 {
Expand Down
81 changes: 78 additions & 3 deletions gapis/api/vulkan/templates/vk_spy_helpers.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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<gapii::VulkanImports::PFNVKENUMERATEDEVICEEXTENSIONPROPERTIES>(
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<VkExtensionProperties> 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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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<gapii::VulkanImports::PFNVKENUMERATEDEVICEEXTENSIONPROPERTIES>(
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<VkExtensionProperties> 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<char*> 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);

Expand Down
102 changes: 102 additions & 0 deletions gapis/api/vulkan/vulkan.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2694,6 +2701,7 @@ cmd VkResult vkEnumerateInstanceExtensionProperties(
}

@indirect("VkPhysicalDevice", "VkInstance")
@override
cmd VkResult vkEnumerateDeviceExtensionProperties(
VkPhysicalDevice physicalDevice,
string pLayerName,
Expand Down Expand Up @@ -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 //
/////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion gapis/resolve/command_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 84668f0

Please sign in to comment.