2022-07-27 15:25:25 +00:00
|
|
|
#include "BackendBinding.hpp"
|
|
|
|
|
|
|
|
#include "../internal.hpp"
|
|
|
|
|
|
|
|
#include <SDL_vulkan.h>
|
|
|
|
#include <dawn/native/VulkanBackend.h>
|
|
|
|
|
|
|
|
namespace aurora::webgpu::utils {
|
|
|
|
static Module Log("aurora::webgpu::utils::VulkanBinding");
|
|
|
|
|
|
|
|
class VulkanBinding : public BackendBinding {
|
|
|
|
public:
|
|
|
|
VulkanBinding(SDL_Window* window, WGPUDevice device) : BackendBinding(window, device) {}
|
|
|
|
|
|
|
|
uint64_t GetSwapChainImplementation() override {
|
|
|
|
if (m_swapChainImpl.userData == nullptr) {
|
|
|
|
CreateSwapChainImpl();
|
|
|
|
}
|
|
|
|
return reinterpret_cast<uint64_t>(&m_swapChainImpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
WGPUTextureFormat GetPreferredSwapChainTextureFormat() override {
|
|
|
|
if (m_swapChainImpl.userData == nullptr) {
|
|
|
|
CreateSwapChainImpl();
|
|
|
|
}
|
|
|
|
return dawn::native::vulkan::GetNativeSwapChainPreferredFormat(&m_swapChainImpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DawnSwapChainImplementation m_swapChainImpl{};
|
|
|
|
|
|
|
|
void CreateSwapChainImpl() {
|
|
|
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
2022-08-09 06:05:33 +00:00
|
|
|
ASSERT(SDL_Vulkan_CreateSurface(m_window, dawn::native::vulkan::GetInstance(m_device), &surface),
|
|
|
|
"Failed to create Vulkan surface: {}", SDL_GetError());
|
2022-07-27 15:25:25 +00:00
|
|
|
m_swapChainImpl = dawn::native::vulkan::CreateNativeSwapChainImpl(m_device, surface);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
BackendBinding* CreateVulkanBinding(SDL_Window* window, WGPUDevice device) { return new VulkanBinding(window, device); }
|
|
|
|
} // namespace aurora::webgpu::utils
|