Skip to content

Commit

Permalink
Removed <vulkan/vulkan.hpp> from the public header <nvrhi/vulkan.h> -…
Browse files Browse the repository at this point in the history
… see #13
  • Loading branch information
apanteleev committed Aug 16, 2023
1 parent 26c1232 commit 2f6a8c3
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 113 deletions.
31 changes: 13 additions & 18 deletions include/nvrhi/vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#pragma once

#include <vulkan/vulkan.h>

#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
#include <vulkan/vulkan.hpp>

#include <nvrhi/nvrhi.h>

namespace nvrhi
Expand All @@ -43,12 +39,12 @@ namespace nvrhi::vulkan
{
public:
// Additional Vulkan-specific public methods
virtual vk::Semaphore getQueueSemaphore(CommandQueue queue) = 0;
virtual void queueWaitForSemaphore(CommandQueue waitQueue, vk::Semaphore semaphore, uint64_t value) = 0;
virtual void queueSignalSemaphore(CommandQueue executionQueue, vk::Semaphore semaphore, uint64_t value) = 0;
virtual VkSemaphore getQueueSemaphore(CommandQueue queue) = 0;
virtual void queueWaitForSemaphore(CommandQueue waitQueue, VkSemaphore semaphore, uint64_t value) = 0;
virtual void queueSignalSemaphore(CommandQueue executionQueue, VkSemaphore semaphore, uint64_t value) = 0;
virtual uint64_t queueGetCompletedInstance(CommandQueue queue) = 0;
virtual FramebufferHandle createHandleForNativeFramebuffer(vk::RenderPass renderPass,
vk::Framebuffer framebuffer, const FramebufferDesc& desc, bool transferOwnership) = 0;
virtual FramebufferHandle createHandleForNativeFramebuffer(VkRenderPass renderPass,
VkFramebuffer framebuffer, const FramebufferDesc& desc, bool transferOwnership) = 0;
};

typedef RefCountPtr<IDevice> DeviceHandle;
Expand All @@ -57,19 +53,19 @@ namespace nvrhi::vulkan
{
IMessageCallback* errorCB = nullptr;

vk::Instance instance;
vk::PhysicalDevice physicalDevice;
vk::Device device;
VkInstance instance;
VkPhysicalDevice physicalDevice;
VkDevice device;

// any of the queues can be null if this context doesn't intend to use them
vk::Queue graphicsQueue;
VkQueue graphicsQueue;
int graphicsQueueIndex = -1;
vk::Queue transferQueue;
VkQueue transferQueue;
int transferQueueIndex = -1;
vk::Queue computeQueue;
VkQueue computeQueue;
int computeQueueIndex = -1;

vk::AllocationCallbacks *allocationCallbacks = nullptr;
VkAllocationCallbacks *allocationCallbacks = nullptr;

const char **instanceExtensions = nullptr;
size_t numInstanceExtensions = 0;
Expand All @@ -85,8 +81,7 @@ namespace nvrhi::vulkan

NVRHI_API DeviceHandle createDevice(const DeviceDesc& desc);

NVRHI_API vk::Format convertFormat(nvrhi::Format format);
NVRHI_API VkFormat convertFormat(nvrhi::Format format);

NVRHI_API const char* resultToString(VkResult result);
NVRHI_API const char* resultToString(vk::Result result);
}
11 changes: 7 additions & 4 deletions src/vulkan/vulkan-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <mutex>
#include <list>

#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
#include <vulkan/vulkan.hpp>

#ifdef NVRHI_WITH_RTXMU
#include <rtxmu/VkAccelStructManager.h>
#endif
Expand Down Expand Up @@ -1118,11 +1121,11 @@ namespace nvrhi::vulkan
IMessageCallback* getMessageCallback() override { return m_Context.messageCallback; }

// vulkan::IDevice implementation
vk::Semaphore getQueueSemaphore(CommandQueue queue) override;
void queueWaitForSemaphore(CommandQueue waitQueue, vk::Semaphore semaphore, uint64_t value) override;
void queueSignalSemaphore(CommandQueue executionQueue, vk::Semaphore semaphore, uint64_t value) override;
VkSemaphore getQueueSemaphore(CommandQueue queue) override;
void queueWaitForSemaphore(CommandQueue waitQueue, VkSemaphore semaphore, uint64_t value) override;
void queueSignalSemaphore(CommandQueue executionQueue, VkSemaphore semaphore, uint64_t value) override;
uint64_t queueGetCompletedInstance(CommandQueue queue) override;
FramebufferHandle createHandleForNativeFramebuffer(vk::RenderPass renderPass, vk::Framebuffer framebuffer,
FramebufferHandle createHandleForNativeFramebuffer(VkRenderPass renderPass, VkFramebuffer framebuffer,
const FramebufferDesc& desc, bool transferOwnership) override;

private:
Expand Down
147 changes: 71 additions & 76 deletions src/vulkan/vulkan-constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,82 +33,82 @@ namespace nvrhi::vulkan
struct FormatMapping
{
nvrhi::Format rhiFormat;
vk::Format vkFormat;
VkFormat vkFormat;
};

static const std::array<FormatMapping, size_t(Format::COUNT)> c_FormatMap = { {
{ Format::UNKNOWN, vk::Format(VK_FORMAT_UNDEFINED) },
{ Format::R8_UINT, vk::Format(VK_FORMAT_R8_UINT) },
{ Format::R8_SINT, vk::Format(VK_FORMAT_R8_SINT) },
{ Format::R8_UNORM, vk::Format(VK_FORMAT_R8_UNORM) },
{ Format::R8_SNORM, vk::Format(VK_FORMAT_R8_SNORM) },
{ Format::RG8_UINT, vk::Format(VK_FORMAT_R8G8_UINT) },
{ Format::RG8_SINT, vk::Format(VK_FORMAT_R8G8_SINT) },
{ Format::RG8_UNORM, vk::Format(VK_FORMAT_R8G8_UNORM) },
{ Format::RG8_SNORM, vk::Format(VK_FORMAT_R8G8_SNORM) },
{ Format::R16_UINT, vk::Format(VK_FORMAT_R16_UINT) },
{ Format::R16_SINT, vk::Format(VK_FORMAT_R16_SINT) },
{ Format::R16_UNORM, vk::Format(VK_FORMAT_R16_UNORM) },
{ Format::R16_SNORM, vk::Format(VK_FORMAT_R16_SNORM) },
{ Format::R16_FLOAT, vk::Format(VK_FORMAT_R16_SFLOAT) },
{ Format::BGRA4_UNORM, vk::Format(VK_FORMAT_B4G4R4A4_UNORM_PACK16) },
{ Format::B5G6R5_UNORM, vk::Format(VK_FORMAT_B5G6R5_UNORM_PACK16) },
{ Format::B5G5R5A1_UNORM, vk::Format(VK_FORMAT_B5G5R5A1_UNORM_PACK16) },
{ Format::RGBA8_UINT, vk::Format(VK_FORMAT_R8G8B8A8_UINT) },
{ Format::RGBA8_SINT, vk::Format(VK_FORMAT_R8G8B8A8_SINT) },
{ Format::RGBA8_UNORM, vk::Format(VK_FORMAT_R8G8B8A8_UNORM) },
{ Format::RGBA8_SNORM, vk::Format(VK_FORMAT_R8G8B8A8_SNORM) },
{ Format::BGRA8_UNORM, vk::Format(VK_FORMAT_B8G8R8A8_UNORM) },
{ Format::SRGBA8_UNORM, vk::Format(VK_FORMAT_R8G8B8A8_SRGB) },
{ Format::SBGRA8_UNORM, vk::Format(VK_FORMAT_B8G8R8A8_SRGB) },
{ Format::R10G10B10A2_UNORM, vk::Format(VK_FORMAT_A2B10G10R10_UNORM_PACK32) },
{ Format::R11G11B10_FLOAT, vk::Format(VK_FORMAT_B10G11R11_UFLOAT_PACK32) },
{ Format::RG16_UINT, vk::Format(VK_FORMAT_R16G16_UINT) },
{ Format::RG16_SINT, vk::Format(VK_FORMAT_R16G16_SINT) },
{ Format::RG16_UNORM, vk::Format(VK_FORMAT_R16G16_UNORM) },
{ Format::RG16_SNORM, vk::Format(VK_FORMAT_R16G16_SNORM) },
{ Format::RG16_FLOAT, vk::Format(VK_FORMAT_R16G16_SFLOAT) },
{ Format::R32_UINT, vk::Format(VK_FORMAT_R32_UINT) },
{ Format::R32_SINT, vk::Format(VK_FORMAT_R32_SINT) },
{ Format::R32_FLOAT, vk::Format(VK_FORMAT_R32_SFLOAT) },
{ Format::RGBA16_UINT, vk::Format(VK_FORMAT_R16G16B16A16_UINT) },
{ Format::RGBA16_SINT, vk::Format(VK_FORMAT_R16G16B16A16_SINT) },
{ Format::RGBA16_FLOAT, vk::Format(VK_FORMAT_R16G16B16A16_SFLOAT) },
{ Format::RGBA16_UNORM, vk::Format(VK_FORMAT_R16G16B16A16_UNORM) },
{ Format::RGBA16_SNORM, vk::Format(VK_FORMAT_R16G16B16A16_SNORM) },
{ Format::RG32_UINT, vk::Format(VK_FORMAT_R32G32_UINT) },
{ Format::RG32_SINT, vk::Format(VK_FORMAT_R32G32_SINT) },
{ Format::RG32_FLOAT, vk::Format(VK_FORMAT_R32G32_SFLOAT) },
{ Format::RGB32_UINT, vk::Format(VK_FORMAT_R32G32B32_UINT) },
{ Format::RGB32_SINT, vk::Format(VK_FORMAT_R32G32B32_SINT) },
{ Format::RGB32_FLOAT, vk::Format(VK_FORMAT_R32G32B32_SFLOAT) },
{ Format::RGBA32_UINT, vk::Format(VK_FORMAT_R32G32B32A32_UINT) },
{ Format::RGBA32_SINT, vk::Format(VK_FORMAT_R32G32B32A32_SINT) },
{ Format::RGBA32_FLOAT, vk::Format(VK_FORMAT_R32G32B32A32_SFLOAT) },
{ Format::D16, vk::Format(VK_FORMAT_D16_UNORM) },
{ Format::D24S8, vk::Format(VK_FORMAT_D24_UNORM_S8_UINT) },
{ Format::X24G8_UINT, vk::Format(VK_FORMAT_D24_UNORM_S8_UINT) },
{ Format::D32, vk::Format(VK_FORMAT_D32_SFLOAT) },
{ Format::D32S8, vk::Format(VK_FORMAT_D32_SFLOAT_S8_UINT) },
{ Format::X32G8_UINT, vk::Format(VK_FORMAT_D32_SFLOAT_S8_UINT) },
{ Format::BC1_UNORM, vk::Format(VK_FORMAT_BC1_RGB_UNORM_BLOCK) },
{ Format::BC1_UNORM_SRGB, vk::Format(VK_FORMAT_BC1_RGB_SRGB_BLOCK) },
{ Format::BC2_UNORM, vk::Format(VK_FORMAT_BC2_UNORM_BLOCK) },
{ Format::BC2_UNORM_SRGB, vk::Format(VK_FORMAT_BC2_SRGB_BLOCK) },
{ Format::BC3_UNORM, vk::Format(VK_FORMAT_BC3_UNORM_BLOCK) },
{ Format::BC3_UNORM_SRGB, vk::Format(VK_FORMAT_BC3_SRGB_BLOCK) },
{ Format::BC4_UNORM, vk::Format(VK_FORMAT_BC4_UNORM_BLOCK) },
{ Format::BC4_SNORM, vk::Format(VK_FORMAT_BC4_SNORM_BLOCK) },
{ Format::BC5_UNORM, vk::Format(VK_FORMAT_BC5_UNORM_BLOCK) },
{ Format::BC5_SNORM, vk::Format(VK_FORMAT_BC5_SNORM_BLOCK) },
{ Format::BC6H_UFLOAT, vk::Format(VK_FORMAT_BC6H_UFLOAT_BLOCK) },
{ Format::BC6H_SFLOAT, vk::Format(VK_FORMAT_BC6H_SFLOAT_BLOCK) },
{ Format::BC7_UNORM, vk::Format(VK_FORMAT_BC7_UNORM_BLOCK) },
{ Format::BC7_UNORM_SRGB, vk::Format(VK_FORMAT_BC7_SRGB_BLOCK) },
{ Format::UNKNOWN, VK_FORMAT_UNDEFINED },
{ Format::R8_UINT, VK_FORMAT_R8_UINT },
{ Format::R8_SINT, VK_FORMAT_R8_SINT },
{ Format::R8_UNORM, VK_FORMAT_R8_UNORM },
{ Format::R8_SNORM, VK_FORMAT_R8_SNORM },
{ Format::RG8_UINT, VK_FORMAT_R8G8_UINT },
{ Format::RG8_SINT, VK_FORMAT_R8G8_SINT },
{ Format::RG8_UNORM, VK_FORMAT_R8G8_UNORM },
{ Format::RG8_SNORM, VK_FORMAT_R8G8_SNORM },
{ Format::R16_UINT, VK_FORMAT_R16_UINT },
{ Format::R16_SINT, VK_FORMAT_R16_SINT },
{ Format::R16_UNORM, VK_FORMAT_R16_UNORM },
{ Format::R16_SNORM, VK_FORMAT_R16_SNORM },
{ Format::R16_FLOAT, VK_FORMAT_R16_SFLOAT },
{ Format::BGRA4_UNORM, VK_FORMAT_B4G4R4A4_UNORM_PACK16 },
{ Format::B5G6R5_UNORM, VK_FORMAT_B5G6R5_UNORM_PACK16 },
{ Format::B5G5R5A1_UNORM, VK_FORMAT_B5G5R5A1_UNORM_PACK16 },
{ Format::RGBA8_UINT, VK_FORMAT_R8G8B8A8_UINT },
{ Format::RGBA8_SINT, VK_FORMAT_R8G8B8A8_SINT },
{ Format::RGBA8_UNORM, VK_FORMAT_R8G8B8A8_UNORM },
{ Format::RGBA8_SNORM, VK_FORMAT_R8G8B8A8_SNORM },
{ Format::BGRA8_UNORM, VK_FORMAT_B8G8R8A8_UNORM },
{ Format::SRGBA8_UNORM, VK_FORMAT_R8G8B8A8_SRGB },
{ Format::SBGRA8_UNORM, VK_FORMAT_B8G8R8A8_SRGB },
{ Format::R10G10B10A2_UNORM, VK_FORMAT_A2B10G10R10_UNORM_PACK32 },
{ Format::R11G11B10_FLOAT, VK_FORMAT_B10G11R11_UFLOAT_PACK32 },
{ Format::RG16_UINT, VK_FORMAT_R16G16_UINT },
{ Format::RG16_SINT, VK_FORMAT_R16G16_SINT },
{ Format::RG16_UNORM, VK_FORMAT_R16G16_UNORM },
{ Format::RG16_SNORM, VK_FORMAT_R16G16_SNORM },
{ Format::RG16_FLOAT, VK_FORMAT_R16G16_SFLOAT },
{ Format::R32_UINT, VK_FORMAT_R32_UINT },
{ Format::R32_SINT, VK_FORMAT_R32_SINT },
{ Format::R32_FLOAT, VK_FORMAT_R32_SFLOAT },
{ Format::RGBA16_UINT, VK_FORMAT_R16G16B16A16_UINT },
{ Format::RGBA16_SINT, VK_FORMAT_R16G16B16A16_SINT },
{ Format::RGBA16_FLOAT, VK_FORMAT_R16G16B16A16_SFLOAT },
{ Format::RGBA16_UNORM, VK_FORMAT_R16G16B16A16_UNORM },
{ Format::RGBA16_SNORM, VK_FORMAT_R16G16B16A16_SNORM },
{ Format::RG32_UINT, VK_FORMAT_R32G32_UINT },
{ Format::RG32_SINT, VK_FORMAT_R32G32_SINT },
{ Format::RG32_FLOAT, VK_FORMAT_R32G32_SFLOAT },
{ Format::RGB32_UINT, VK_FORMAT_R32G32B32_UINT },
{ Format::RGB32_SINT, VK_FORMAT_R32G32B32_SINT },
{ Format::RGB32_FLOAT, VK_FORMAT_R32G32B32_SFLOAT },
{ Format::RGBA32_UINT, VK_FORMAT_R32G32B32A32_UINT },
{ Format::RGBA32_SINT, VK_FORMAT_R32G32B32A32_SINT },
{ Format::RGBA32_FLOAT, VK_FORMAT_R32G32B32A32_SFLOAT },
{ Format::D16, VK_FORMAT_D16_UNORM },
{ Format::D24S8, VK_FORMAT_D24_UNORM_S8_UINT },
{ Format::X24G8_UINT, VK_FORMAT_D24_UNORM_S8_UINT },
{ Format::D32, VK_FORMAT_D32_SFLOAT },
{ Format::D32S8, VK_FORMAT_D32_SFLOAT_S8_UINT },
{ Format::X32G8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT },
{ Format::BC1_UNORM, VK_FORMAT_BC1_RGB_UNORM_BLOCK },
{ Format::BC1_UNORM_SRGB, VK_FORMAT_BC1_RGB_SRGB_BLOCK },
{ Format::BC2_UNORM, VK_FORMAT_BC2_UNORM_BLOCK },
{ Format::BC2_UNORM_SRGB, VK_FORMAT_BC2_SRGB_BLOCK },
{ Format::BC3_UNORM, VK_FORMAT_BC3_UNORM_BLOCK },
{ Format::BC3_UNORM_SRGB, VK_FORMAT_BC3_SRGB_BLOCK },
{ Format::BC4_UNORM, VK_FORMAT_BC4_UNORM_BLOCK },
{ Format::BC4_SNORM, VK_FORMAT_BC4_SNORM_BLOCK },
{ Format::BC5_UNORM, VK_FORMAT_BC5_UNORM_BLOCK },
{ Format::BC5_SNORM, VK_FORMAT_BC5_SNORM_BLOCK },
{ Format::BC6H_UFLOAT, VK_FORMAT_BC6H_UFLOAT_BLOCK },
{ Format::BC6H_SFLOAT, VK_FORMAT_BC6H_SFLOAT_BLOCK },
{ Format::BC7_UNORM, VK_FORMAT_BC7_UNORM_BLOCK },
{ Format::BC7_UNORM_SRGB, VK_FORMAT_BC7_SRGB_BLOCK },

} };

vk::Format convertFormat(nvrhi::Format format)
VkFormat convertFormat(nvrhi::Format format)
{
assert(format < nvrhi::Format::COUNT);
assert(c_FormatMap[uint32_t(format)].rhiFormat == format);
Expand Down Expand Up @@ -469,12 +469,7 @@ namespace nvrhi::vulkan
}
}
}

const char* resultToString(vk::Result result)
{
return resultToString((VkResult)result);
}


vk::PrimitiveTopology convertPrimitiveTopology(PrimitiveType topology)
{
switch(topology)
Expand Down
8 changes: 4 additions & 4 deletions src/vulkan/vulkan-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace nvrhi::vulkan
}

Device::Device(const DeviceDesc& desc)
: m_Context(desc.instance, desc.physicalDevice, desc.device, desc.allocationCallbacks)
: m_Context(desc.instance, desc.physicalDevice, desc.device, reinterpret_cast<vk::AllocationCallbacks*>(desc.allocationCallbacks))
, m_Allocator(m_Context)
, m_TimerQueryAllocator(desc.maxTimerQueries, true)
{
Expand Down Expand Up @@ -323,10 +323,10 @@ namespace nvrhi::vulkan

FormatSupport Device::queryFormatSupport(Format format)
{
vk::Format vulkanFormat = convertFormat(format);
VkFormat vulkanFormat = convertFormat(format);

vk::FormatProperties props;
m_Context.physicalDevice.getFormatProperties(vulkanFormat, &props);
m_Context.physicalDevice.getFormatProperties(vk::Format(vulkanFormat), &props);

FormatSupport result = FormatSupport::None;

Expand Down Expand Up @@ -450,7 +450,7 @@ namespace nvrhi::vulkan
{
std::stringstream ss;
ss << "Failed to allocate memory for Heap " << utils::DebugNameToString(d.debugName)
<< ", VkResult = " << resultToString(res);
<< ", VkResult = " << resultToString(VkResult(res));

m_Context.error(ss.str());

Expand Down
4 changes: 2 additions & 2 deletions src/vulkan/vulkan-graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace nvrhi::vulkan
assert(fb->framebufferInfo.width == std::max(t->desc.width >> rt.subresources.baseMipLevel, 1u));
assert(fb->framebufferInfo.height == std::max(t->desc.height >> rt.subresources.baseMipLevel, 1u));

const vk::Format attachmentFormat = (rt.format == Format::UNKNOWN ? t->imageInfo.format : convertFormat(rt.format));
const vk::Format attachmentFormat = (rt.format == Format::UNKNOWN ? t->imageInfo.format : vk::Format(convertFormat(rt.format)));

attachmentDescs[i] = vk::AttachmentDescription2()
.setFormat(attachmentFormat)
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace nvrhi::vulkan
return FramebufferHandle::Create(fb);
}

FramebufferHandle Device::createHandleForNativeFramebuffer(vk::RenderPass renderPass, vk::Framebuffer framebuffer,
FramebufferHandle Device::createHandleForNativeFramebuffer(VkRenderPass renderPass, VkFramebuffer framebuffer,
const FramebufferDesc& desc, bool transferOwnership)
{
Framebuffer* fb = new Framebuffer(m_Context);
Expand Down
6 changes: 3 additions & 3 deletions src/vulkan/vulkan-queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,21 @@ namespace nvrhi::vulkan
return nullptr;
}

vk::Semaphore Device::getQueueSemaphore(CommandQueue queueID)
VkSemaphore Device::getQueueSemaphore(CommandQueue queueID)
{
Queue& queue = *m_Queues[uint32_t(queueID)];

return queue.trackingSemaphore;
}

void Device::queueWaitForSemaphore(CommandQueue waitQueueID, vk::Semaphore semaphore, uint64_t value)
void Device::queueWaitForSemaphore(CommandQueue waitQueueID, VkSemaphore semaphore, uint64_t value)
{
Queue& waitQueue = *m_Queues[uint32_t(waitQueueID)];

waitQueue.addWaitSemaphore(semaphore, value);
}

void Device::queueSignalSemaphore(CommandQueue executionQueueID, vk::Semaphore semaphore, uint64_t value)
void Device::queueSignalSemaphore(CommandQueue executionQueueID, VkSemaphore semaphore, uint64_t value)
{
Queue& executionQueue = *m_Queues[uint32_t(executionQueueID)];

Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vulkan-raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace nvrhi::vulkan
break;
}

dstt.setVertexFormat(convertFormat(srct.vertexFormat));
dstt.setVertexFormat(vk::Format(convertFormat(srct.vertexFormat)));
dstt.setVertexData(getBufferAddress(srct.vertexBuffer, srct.vertexOffset));
dstt.setVertexStride(srct.vertexStride);
dstt.setMaxVertex(std::max(srct.vertexCount, 1u) - 1u);
Expand Down
Loading

0 comments on commit 2f6a8c3

Please sign in to comment.