metaforce/aurora/lib/dawn/VulkanBinding.cpp

40 lines
1.2 KiB
C++
Raw Normal View History

2022-02-16 23:13:40 +00:00
#include "BackendBinding.hpp"
#include <SDL_vulkan.h>
#include <cassert>
#include <dawn/native/VulkanBackend.h>
2022-02-19 05:33:56 +00:00
namespace aurora::gpu::utils {
2022-02-16 23:13:40 +00:00
class VulkanBinding : public BackendBinding {
public:
VulkanBinding(SDL_Window* window, WGPUDevice device) : BackendBinding(window, device) {}
uint64_t GetSwapChainImplementation() override {
if (m_swapChainImpl.userData == nullptr) {
2022-02-19 05:33:56 +00:00
CreateSwapChainImpl();
2022-02-16 23:13:40 +00:00
}
return reinterpret_cast<uint64_t>(&m_swapChainImpl);
}
WGPUTextureFormat GetPreferredSwapChainTextureFormat() override {
2022-02-19 05:33:56 +00:00
if (m_swapChainImpl.userData == nullptr) {
CreateSwapChainImpl();
}
2022-02-16 23:13:40 +00:00
return dawn::native::vulkan::GetNativeSwapChainPreferredFormat(&m_swapChainImpl);
}
private:
DawnSwapChainImplementation m_swapChainImpl{};
2022-02-19 05:33:56 +00:00
void CreateSwapChainImpl() {
VkSurfaceKHR surface = VK_NULL_HANDLE;
if (SDL_Vulkan_CreateSurface(m_window, dawn::native::vulkan::GetInstance(m_device), &surface) != SDL_TRUE) {
assert(false);
}
m_swapChainImpl = dawn::native::vulkan::CreateNativeSwapChainImpl(m_device, surface);
}
2022-02-16 23:13:40 +00:00
};
BackendBinding* CreateVulkanBinding(SDL_Window* window, WGPUDevice device) { return new VulkanBinding(window, device); }
2022-02-19 05:33:56 +00:00
} // namespace aurora::gpu::utils