Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodesk: Added TF_VERIFY_VK_RESULT for Vulkan #3333

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions pxr/imaging/hgiVulkan/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ HgiVulkanBuffer::HgiVulkanBuffer(
VkBufferCreateInfo bi = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
bi.size = desc.byteSize;
bi.usage = HgiVulkanConversions::GetBufferUsage(desc.usage);
bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT;
bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE; // gfx queue only

Expand All @@ -52,9 +52,7 @@ HgiVulkanBuffer::HgiVulkanBuffer(
VmaAllocationCreateInfo ai = {};
ai.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; // GPU efficient

TF_VERIFY(
vmaCreateBuffer(vma,&bi,&ai,&_vkBuffer,&_vmaAllocation,0) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vmaCreateBuffer(vma,&bi,&ai,&_vkBuffer,&_vmaAllocation,0));

// Debug label
if (!_descriptor.debugName.empty()) {
Expand Down Expand Up @@ -150,11 +148,11 @@ HgiVulkanBuffer::GetCPUStagingAddress()
}

if (!_cpuStagingAddress) {
TF_VERIFY(
TF_VERIFY_VK_RESULT(
vmaMapMemory(
_device->GetVulkanMemoryAllocator(),
_stagingBuffer->GetVulkanMemoryAllocation(),
&_cpuStagingAddress) == VK_SUCCESS
_device->GetVulkanMemoryAllocator(),
_stagingBuffer->GetVulkanMemoryAllocation(),
&_cpuStagingAddress)
);
}

Expand Down Expand Up @@ -210,7 +208,7 @@ HgiVulkanBuffer::CreateStagingBuffer(
VkBufferCreateInfo bi = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
bi.size = desc.byteSize;
bi.usage = HgiVulkanConversions::GetBufferUsage(desc.usage);
bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
bi.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_BUFFER_USAGE_TRANSFER_DST_BIT;
bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE; // gfx queue only

Expand All @@ -221,14 +219,12 @@ HgiVulkanBuffer::CreateStagingBuffer(

VkBuffer buffer = 0;
VmaAllocation alloc = 0;
TF_VERIFY(
vmaCreateBuffer(vma, &bi, &ai, &buffer, &alloc, 0) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vmaCreateBuffer(vma, &bi, &ai, &buffer, &alloc, 0));

// Map the (HOST_VISIBLE) buffer and upload data
if (desc.initialData) {
void* map;
TF_VERIFY(vmaMapMemory(vma, alloc, &map) == VK_SUCCESS);
TF_VERIFY_VK_RESULT(vmaMapMemory(vma, alloc, &map));
memcpy(map, desc.initialData, desc.byteSize);
vmaUnmapMemory(vma, alloc);
}
Expand Down
42 changes: 9 additions & 33 deletions pxr/imaging/hgiVulkan/commandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ HgiVulkanCommandBuffer::HgiVulkanCommandBuffer(
allocInfo.commandPool = pool;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;

TF_VERIFY(
vkAllocateCommandBuffers(
vkDevice,
&allocInfo,
&_vkCommandBuffer) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkAllocateCommandBuffers(vkDevice, &allocInfo, &_vkCommandBuffer));

// Assign a debug label to command buffer
uint64_t cmdBufHandle = (uint64_t)_vkCommandBuffer;
Expand All @@ -58,23 +53,13 @@ HgiVulkanCommandBuffer::HgiVulkanCommandBuffer(
VkFenceCreateInfo fenceInfo = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
fenceInfo.flags = 0; // Unsignaled starting state

TF_VERIFY(
vkCreateFence(
vkDevice,
&fenceInfo,
HgiVulkanAllocator(),
&_vkFence) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkCreateFence(vkDevice, &fenceInfo, HgiVulkanAllocator(), &_vkFence));

// Create semaphore for GPU-GPU synchronization
VkSemaphoreCreateInfo semaCreateInfo =
{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
TF_VERIFY(
vkCreateSemaphore(
vkDevice,
&semaCreateInfo,
HgiVulkanAllocator(),
&_vkSemaphore) == VK_SUCCESS
TF_VERIFY_VK_RESULT(
vkCreateSemaphore(vkDevice, &semaCreateInfo, HgiVulkanAllocator(), &_vkSemaphore)
);

// Assign a debug label to fence.
Expand Down Expand Up @@ -105,9 +90,7 @@ HgiVulkanCommandBuffer::BeginCommandBuffer(uint8_t inflightId)
{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;

TF_VERIFY(
vkBeginCommandBuffer(_vkCommandBuffer, &beginInfo) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkBeginCommandBuffer(_vkCommandBuffer, &beginInfo));

_inflightId = inflightId;
_isInFlight = true;
Expand All @@ -133,9 +116,7 @@ HgiVulkanCommandBuffer::EndCommandBuffer()
TF_VERIFY(_isInFlight);
TF_VERIFY(!_isSubmitted);

TF_VERIFY(
vkEndCommandBuffer(_vkCommandBuffer) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkEndCommandBuffer(_vkCommandBuffer));

_isSubmitted = true;
}
Expand Down Expand Up @@ -163,8 +144,7 @@ HgiVulkanCommandBuffer::UpdateInFlightStatus(HgiSubmitWaitType wait)
}

static const uint64_t timeOut = 100000000000;
TF_VERIFY(vkWaitForFences(
vkDevice, 1, &_vkFence, VK_TRUE, timeOut) == VK_SUCCESS);
TF_VERIFY_VK_RESULT(vkWaitForFences(vkDevice, 1, &_vkFence, VK_TRUE, timeOut));
}

_isInFlight = false;
Expand All @@ -191,9 +171,7 @@ HgiVulkanCommandBuffer::ResetIfConsumedByGPU(HgiSubmitWaitType wait)
VkDevice vkDevice = _device->GetVulkanDevice();

// GPU is done with command buffer, reset fence and command buffer.
TF_VERIFY(
vkResetFences(vkDevice, 1, &_vkFence) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkResetFences(vkDevice, 1, &_vkFence));

// It might be more efficient to reset the cmd pool instead of individual
// command buffers. But we may not have a clear 'StartFrame' / 'EndFrame'
Expand All @@ -202,9 +180,7 @@ HgiVulkanCommandBuffer::ResetIfConsumedByGPU(HgiSubmitWaitType wait)
// been consumed by the GPU.

VkCommandBufferResetFlags flags = _GetCommandBufferResetFlags();
TF_VERIFY(
vkResetCommandBuffer(_vkCommandBuffer, flags) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkResetCommandBuffer(_vkCommandBuffer, flags));

// Command buffer may now be reused for new recordings / resource creation.
_isSubmitted = false;
Expand Down
17 changes: 6 additions & 11 deletions pxr/imaging/hgiVulkan/commandQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "pxr/imaging/hgiVulkan/device.h"

#include "pxr/base/tf/diagnostic.h"
#include "pxr/imaging/hgiVulkan/diagnostic.h"

PXR_NAMESPACE_OPEN_SCOPE

Expand All @@ -27,12 +28,12 @@ _CreateCommandPool(HgiVulkanDevice* device)

VkCommandPool pool = nullptr;

TF_VERIFY(
TF_VERIFY_VK_RESULT(
vkCreateCommandPool(
device->GetVulkanDevice(),
&poolCreateInfo,
HgiVulkanAllocator(),
&pool) == VK_SUCCESS
&pool)
);

HgiVulkanCommandQueue::HgiVulkan_CommandPool* newPool =
Expand Down Expand Up @@ -110,9 +111,7 @@ HgiVulkanCommandQueue::SubmitToQueue(
resourceInfo.signalSemaphoreCount = 1;
resourceInfo.pSignalSemaphores = &semaphore;

TF_VERIFY(
vkQueueSubmit(_vkGfxQueue, 1, &resourceInfo, rFence) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkQueueSubmit(_vkGfxQueue, 1, &resourceInfo, rFence));

_resourceCommandBuffer = nullptr;
}
Expand All @@ -139,17 +138,13 @@ HgiVulkanCommandQueue::SubmitToQueue(
// Record and submission order does not guarantee execution order.
// VK docs: "Execution Model" & "Implicit Synchronization Guarantees".
// The vulkan queue must be externally synchronized.
TF_VERIFY(
vkQueueSubmit(_vkGfxQueue, 1, &workInfo, wFence) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkQueueSubmit(_vkGfxQueue, 1, &workInfo, wFence));

// Optional blocking wait
if (wait == HgiSubmitWaitTypeWaitUntilCompleted) {
static const uint64_t timeOut = 100000000000;
VkDevice vkDevice = _device->GetVulkanDevice();
TF_VERIFY(
vkWaitForFences(vkDevice, 1, &wFence, VK_TRUE, timeOut)==VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkWaitForFences(vkDevice, 1, &wFence, VK_TRUE, timeOut));
// When the client waits for the cmd buf to finish on GPU they will
// expect to have the CompletedHandlers run. For example when the
// client wants to do a GPU->CPU read back (memcpy)
Expand Down
8 changes: 4 additions & 4 deletions pxr/imaging/hgiVulkan/computePipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ HgiVulkanComputePipeline::HgiVulkanComputePipeline(
pipeLayCreateInfo.setLayoutCount = (uint32_t)_vkDescriptorSetLayouts.size();
pipeLayCreateInfo.pSetLayouts = _vkDescriptorSetLayouts.data();

TF_VERIFY(
TF_VERIFY_VK_RESULT(
vkCreatePipelineLayout(
_device->GetVulkanDevice(),
&pipeLayCreateInfo,
HgiVulkanAllocator(),
&_vkPipelineLayout) == VK_SUCCESS
&_vkPipelineLayout)
);

// Debug label
Expand All @@ -97,14 +97,14 @@ HgiVulkanComputePipeline::HgiVulkanComputePipeline(
//
HgiVulkanPipelineCache* pCache = device->GetPipelineCache();

TF_VERIFY(
TF_VERIFY_VK_RESULT(
vkCreateComputePipelines(
_device->GetVulkanDevice(),
pCache->GetVulkanPipelineCache(),
1,
&pipeCreateInfo,
HgiVulkanAllocator(),
&_vkPipeline) == VK_SUCCESS
&_vkPipeline)
);

// Debug label
Expand Down
30 changes: 11 additions & 19 deletions pxr/imaging/hgiVulkan/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance)
const uint32_t maxDevices = 64;
VkPhysicalDevice physicalDevices[maxDevices];
uint32_t physicalDeviceCount = maxDevices;
TF_VERIFY(
TF_VERIFY_VK_RESULT(
vkEnumeratePhysicalDevices(
instance->GetVulkanInstance(),
&physicalDeviceCount,
physicalDevices) == VK_SUCCESS
physicalDevices)
);

for (uint32_t i = 0; i < physicalDeviceCount; i++) {
Expand Down Expand Up @@ -123,22 +123,22 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance)
//

uint32_t extensionCount = 0;
TF_VERIFY(
TF_VERIFY_VK_RESULT(
vkEnumerateDeviceExtensionProperties(
_vkPhysicalDevice,
nullptr,
&extensionCount,
nullptr) == VK_SUCCESS
nullptr)
);

_vkExtensions.resize(extensionCount);

TF_VERIFY(
TF_VERIFY_VK_RESULT(
vkEnumerateDeviceExtensionProperties(
_vkPhysicalDevice,
nullptr,
&extensionCount,
_vkExtensions.data()) == VK_SUCCESS
_vkExtensions.data())
);

//
Expand Down Expand Up @@ -282,12 +282,8 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance)
createInfo.enabledExtensionCount = (uint32_t) extensions.size();
createInfo.pNext = &features;

TF_VERIFY(
vkCreateDevice(
_vkPhysicalDevice,
&createInfo,
HgiVulkanAllocator(),
&_vkDevice) == VK_SUCCESS
TF_VERIFY_VK_RESULT(
vkCreateDevice(_vkPhysicalDevice, &createInfo, HgiVulkanAllocator(), &_vkDevice)
);

HgiVulkanSetupDeviceDebug(instance, this);
Expand Down Expand Up @@ -315,9 +311,7 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance)
allocatorInfo.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT;
}

TF_VERIFY(
vmaCreateAllocator(&allocatorInfo, &_vmaAllocator) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vmaCreateAllocator(&allocatorInfo, &_vmaAllocator));

//
// Command Queue
Expand All @@ -335,7 +329,7 @@ HgiVulkanDevice::HgiVulkanDevice(HgiVulkanInstance* instance)
HgiVulkanDevice::~HgiVulkanDevice()
{
// Make sure device is idle before destroying objects.
TF_VERIFY(vkDeviceWaitIdle(_vkDevice) == VK_SUCCESS);
TF_VERIFY_VK_RESULT(vkDeviceWaitIdle(_vkDevice));

delete _pipelineCache;
delete _commandQueue;
Expand Down Expand Up @@ -389,9 +383,7 @@ HgiVulkanDevice::GetPipelineCache() const
void
HgiVulkanDevice::WaitForIdle()
{
TF_VERIFY(
vkDeviceWaitIdle(_vkDevice) == VK_SUCCESS
);
TF_VERIFY_VK_RESULT(vkDeviceWaitIdle(_vkDevice));
}

bool
Expand Down
22 changes: 19 additions & 3 deletions pxr/imaging/hgiVulkan/diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/tf/envSetting.h"

#include <vulkan/vk_enum_string_helper.h>

#include <cstring>


PXR_NAMESPACE_OPEN_SCOPE


TF_DEFINE_ENV_SETTING(HGIVULKAN_DEBUG, 0, "Enable debugging for HgiVulkan");
TF_DEFINE_ENV_SETTING(HGIVULKAN_DEBUG_VERBOSE, 0,
TF_DEFINE_ENV_SETTING(HGIVULKAN_DEBUG_VERBOSE, 0,
"Enable verbose debugging for HgiVulkan");

bool
Expand Down Expand Up @@ -108,12 +110,12 @@ HgiVulkanCreateDebug(HgiVulkanInstance* instance)
dbgMsgCreateInfo.pfnUserCallback = _VulkanDebugCallback;
dbgMsgCreateInfo.pUserData = nullptr;

TF_VERIFY(
TF_VERIFY_VK_RESULT(
instance->vkCreateDebugUtilsMessengerEXT(
vkInstance,
&dbgMsgCreateInfo,
HgiVulkanAllocator(),
&instance->vkDebugMessenger) == VK_SUCCESS
&instance->vkDebugMessenger)
);
}

Expand Down Expand Up @@ -250,4 +252,18 @@ HgiVulkanEndQueueLabel(HgiVulkanDevice* device)
device->vkQueueEndDebugUtilsLabelEXT(gfxQueue);
}

const char*
HgiVulkanResultString(VkResult result)
{
return string_VkResult(result);
}

const char*
HgiVulkanCommandResultString(const char* cmd, VkResult result)
{
static thread_local std::string buffer;
buffer = std::string(cmd) + ": " + string_VkResult(result);
return buffer.c_str();
}

PXR_NAMESPACE_CLOSE_SCOPE
Loading
Loading