Skip to content

Commit

Permalink
object debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingstom committed Oct 26, 2023
1 parent 2102a94 commit 64ba2e8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 50 deletions.
11 changes: 0 additions & 11 deletions engine/api/gpuResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ enum class ShaderStage : uint8_t
MS = 8,
};

enum class ResourceType : uint8_t
{
Undefined = 0,
Sampler = 1,
SampledImage = 2,
CombineSamplerImage = 3,
StorageImage = 4,
UniformBuffer = 5,
StorageBuffer = 6,
};

enum ResourceState
{
RESOURCE_STATE_UNDEFINED = 0,
Expand Down
22 changes: 15 additions & 7 deletions engine/api/vulkan/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ std::unique_ptr<Device> Device::Create(const DeviceCreateInfo& createInfo)

VkDevice handle = VK_NULL_HANDLE;
_VR(vkCreateDevice(physicalDevice->getHandle(), &deviceCreateInfo, gVkAllocator, &handle));
_VR(utils::setDebugObjectName(handle, VK_OBJECT_TYPE_DEVICE, reinterpret_cast<uint64_t>(handle), "Device"))

// Initialize Device class.
auto device = std::unique_ptr<Device>(new Device(createInfo, physicalDevice, handle));
Expand Down Expand Up @@ -158,7 +159,7 @@ VkFormat Device::getDepthFormat() const
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
}

Result Device::create(const ImageViewCreateInfo& createInfo, ImageView** ppImageView)
Result Device::create(const ImageViewCreateInfo& createInfo, ImageView** ppImageView, std::string_view debugName)
{
VkImageViewCreateInfo info{
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
Expand All @@ -178,13 +179,14 @@ Result Device::create(const ImageViewCreateInfo& createInfo, ImageView** ppImage

VkImageView handle = VK_NULL_HANDLE;
_VR(m_table.vkCreateImageView(getHandle(), &info, gVkAllocator, &handle));
_VR(utils::setDebugObjectName(getHandle(), VK_OBJECT_TYPE_IMAGE_VIEW, reinterpret_cast<uint64_t>(handle), debugName))

*ppImageView = new ImageView(createInfo, handle);

return Result::Success;
}

Result Device::create(const BufferCreateInfo& createInfo, Buffer** ppBuffer)
Result Device::create(const BufferCreateInfo& createInfo, Buffer** ppBuffer, std::string_view debugName)
{
// create buffer
VkBufferCreateInfo bufferInfo{
Expand All @@ -195,6 +197,7 @@ Result Device::create(const BufferCreateInfo& createInfo, Buffer** ppBuffer)
};
VkBuffer buffer;
_VR(m_table.vkCreateBuffer(getHandle(), &bufferInfo, gVkAllocator, &buffer));
_VR(utils::setDebugObjectName(getHandle(), VK_OBJECT_TYPE_BUFFER, reinterpret_cast<uint64_t>(buffer), debugName))

VkMemoryDedicatedRequirementsKHR dedicatedRequirements = {
VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR,
Expand Down Expand Up @@ -245,7 +248,7 @@ Result Device::create(const BufferCreateInfo& createInfo, Buffer** ppBuffer)
return Result::Success;
}

Result Device::create(const ImageCreateInfo& createInfo, Image** ppImage)
Result Device::create(const ImageCreateInfo& createInfo, Image** ppImage, std::string_view debugName)
{
VkImageCreateInfo imageCreateInfo{
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
Expand All @@ -267,6 +270,7 @@ Result Device::create(const ImageCreateInfo& createInfo, Image** ppImage)

VkImage image;
_VR(m_table.vkCreateImage(m_handle, &imageCreateInfo, gVkAllocator, &image));
_VR(utils::setDebugObjectName(getHandle(), VK_OBJECT_TYPE_IMAGE, reinterpret_cast<uint64_t>(image), debugName))

VkMemoryDedicatedRequirementsKHR dedicatedRequirements = {
VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR,
Expand Down Expand Up @@ -351,7 +355,7 @@ void Device::destroy(ImageView* pImageView)
pImageView = nullptr;
}

Result Device::create(const SwapChainCreateInfo& createInfo, SwapChain** ppSwapchain)
Result Device::create(const SwapChainCreateInfo& createInfo, SwapChain** ppSwapchain, std::string_view debugName)
{
*ppSwapchain = new SwapChain(createInfo, this);
return Result::Success;
Expand Down Expand Up @@ -444,7 +448,7 @@ void Device::freeCommandBuffers(uint32_t commandBufferCount, CommandBuffer** ppC
}
}

Result Device::create(const GraphicsPipelineCreateInfo& createInfo, Pipeline** ppPipeline)
Result Device::create(const GraphicsPipelineCreateInfo& createInfo, Pipeline** ppPipeline, std::string_view debugName)
{
std::vector<VkPipelineShaderStageCreateInfo> shaderStages;

Expand Down Expand Up @@ -565,6 +569,7 @@ Result Device::create(const GraphicsPipelineCreateInfo& createInfo, Pipeline** p
.stencilAttachmentFormat(createInfo.stencilFormat)
.build(this, VK_NULL_HANDLE, program->getPipelineLayout(), &handle, createInfo.debugName);

_VR(utils::setDebugObjectName(getHandle(), VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(handle), debugName))
*ppPipeline = new Pipeline(this, rps, handle, program);

return Result::Success;
Expand All @@ -579,7 +584,7 @@ void Device::destroy(Pipeline* pipeline)
pipeline = nullptr;
}

Result Device::create(const ComputePipelineCreateInfo& createInfo, Pipeline** ppPipeline)
Result Device::create(const ComputePipelineCreateInfo& createInfo, Pipeline** ppPipeline, std::string_view debugName)
{
APH_ASSERT(createInfo.pCompute);
auto program = new ShaderProgram(this, createInfo.pCompute, createInfo.pSamplerBank);
Expand All @@ -588,6 +593,7 @@ Result Device::create(const ComputePipelineCreateInfo& createInfo, Pipeline** pp
program->getShader(ShaderStage::CS)->getHandle());
VkPipeline handle = VK_NULL_HANDLE;
_VR(m_table.vkCreateComputePipelines(this->getHandle(), VK_NULL_HANDLE, 1, &ci, gVkAllocator, &handle));
_VR(utils::setDebugObjectName(getHandle(), VK_OBJECT_TYPE_PIPELINE, reinterpret_cast<uint64_t>(handle), debugName))
*ppPipeline = new Pipeline(this, createInfo, handle, program);
return Result::Success;
}
Expand Down Expand Up @@ -646,7 +652,7 @@ void Device::unMapMemory(Buffer* pBuffer)
m_table.vkUnmapMemory(getHandle(), pBuffer->getMemory());
}

Result Device::create(const SamplerCreateInfo& createInfo, Sampler** ppSampler)
Result Device::create(const SamplerCreateInfo& createInfo, Sampler** ppSampler, std::string_view debugName)
{
VkSampler sampler = {};
YcbcrData ycbcr;
Expand Down Expand Up @@ -717,6 +723,7 @@ Result Device::create(const SamplerCreateInfo& createInfo, Sampler** ppSampler)
};

_VR(m_table.vkCreateSamplerYcbcrConversion(getHandle(), &vkConvertInfo, gVkAllocator, &ycbcr.conversion));
_VR(utils::setDebugObjectName(getHandle(), VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION, reinterpret_cast<uint64_t>(ycbcr.conversion), debugName))

ycbcr.info.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
ycbcr.info.pNext = nullptr;
Expand All @@ -726,6 +733,7 @@ Result Device::create(const SamplerCreateInfo& createInfo, Sampler** ppSampler)
}

_VR(m_table.vkCreateSampler(getHandle(), &ci, gVkAllocator, &sampler));
_VR(utils::setDebugObjectName(getHandle(), VK_OBJECT_TYPE_SAMPLER, reinterpret_cast<uint64_t>(sampler), debugName))
*ppSampler = new Sampler(this, createInfo, sampler);
return Result::Success;
}
Expand Down
14 changes: 7 additions & 7 deletions engine/api/vulkan/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class Device : public ResourceHandle<VkDevice, DeviceCreateInfo>
static void Destroy(Device* pDevice);

public:
Result create(const SamplerCreateInfo& createInfo, Sampler** ppSampler);
Result create(const BufferCreateInfo& createInfo, Buffer** ppBuffer);
Result create(const ImageCreateInfo& createInfo, Image** ppImage);
Result create(const ImageViewCreateInfo& createInfo, ImageView** ppImageView);
Result create(const SwapChainCreateInfo& createInfo, SwapChain** ppSwapchain);
Result create(const GraphicsPipelineCreateInfo& createInfo, Pipeline** ppPipeline);
Result create(const ComputePipelineCreateInfo& createInfo, Pipeline** ppPipeline);
Result create(const SamplerCreateInfo& createInfo, Sampler** ppSampler, std::string_view debugName = "");
Result create(const BufferCreateInfo& createInfo, Buffer** ppBuffer, std::string_view debugName = "");
Result create(const ImageCreateInfo& createInfo, Image** ppImage, std::string_view debugName = "");
Result create(const ImageViewCreateInfo& createInfo, ImageView** ppImageView, std::string_view debugName = "");
Result create(const SwapChainCreateInfo& createInfo, SwapChain** ppSwapchain, std::string_view debugName = "");
Result create(const GraphicsPipelineCreateInfo& createInfo, Pipeline** ppPipeline, std::string_view debugName = "");
Result create(const ComputePipelineCreateInfo& createInfo, Pipeline** ppPipeline, std::string_view debugName = "");

public:
void destroy(Buffer* pBuffer);
Expand Down
37 changes: 15 additions & 22 deletions engine/api/vulkan/vkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,6 @@ VkShaderStageFlags VkCast(const std::vector<ShaderStage>& stages)
return flags;
}

VkDescriptorType VkCast(ResourceType type)
{
switch(type)
{
case ResourceType::Sampler:
return VK_DESCRIPTOR_TYPE_SAMPLER;
case ResourceType::SampledImage:
return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
case ResourceType::CombineSamplerImage:
return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
case ResourceType::StorageImage:
return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
case ResourceType::UniformBuffer:
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
case ResourceType::StorageBuffer:
return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
default:
assert("Invalid resource type.");
return {};
}
}

VkShaderStageFlagBits VkCast(ShaderStage stage)
{
switch(stage)
Expand Down Expand Up @@ -412,6 +390,21 @@ VkIndexType VkCast(IndexType indexType)
return VK_INDEX_TYPE_NONE_KHR;
}
}

VkResult setDebugObjectName(VkDevice device, VkObjectType type, uint64_t handle, std::string_view name)
{
if(name.empty())
{
return VK_SUCCESS;
}
const VkDebugUtilsObjectNameInfoEXT ni = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.objectType = type,
.objectHandle = handle,
.pObjectName = name.data(),
};
return vkSetDebugUtilsObjectNameEXT(device, &ni);
}
} // namespace aph::vk::utils

namespace aph::vk
Expand Down
4 changes: 2 additions & 2 deletions engine/api/vulkan/vkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace aph::vk
#else
#define _VR(f) (f)
#endif
}
} // namespace aph::vk

namespace aph::vk::utils
{
Expand All @@ -43,13 +43,13 @@ VkAccessFlags getAccessFlags(ResourceState state);
VkImageLayout getImageLayout(ResourceState state);
Format getFormatFromVk(VkFormat format);
Result getResult(VkResult result);
VkResult setDebugObjectName(VkDevice device, VkObjectType type, uint64_t handle, std::string_view name);
} // namespace aph::vk::utils

// convert
namespace aph::vk::utils
{
VkShaderStageFlagBits VkCast(ShaderStage stage);
VkDescriptorType VkCast(ResourceType type);
VkShaderStageFlags VkCast(const std::vector<ShaderStage>& stages);
VkDebugUtilsLabelEXT VkCast(const DebugLabel& label);
VkFormat VkCast(TinyImageFormat format);
Expand Down
2 changes: 1 addition & 1 deletion engine/renderer/api/vulkan/uiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ UI::UI(const UICreateInfo& ci) :
}

// init imgui
// IMGUI_CHECKVERSION();
IMGUI_CHECKVERSION();
m_pContext = ImGui::CreateContext();
auto& io = ImGui::GetIO();
io.IniFilename = ci.configFile.c_str();
Expand Down

0 comments on commit 64ba2e8

Please sign in to comment.