Add create/destroy_shader functions to RenderDriver
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <nova/render/render_fwd.h>
|
||||
#include <nova/types.h>
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
namespace Nova {
|
||||
@@ -41,5 +42,8 @@ namespace Nova {
|
||||
[[nodiscard]] virtual SwapchainID create_swapchain(SurfaceID surface) = 0;
|
||||
virtual void resize_swapchain(SwapchainID swapchain) = 0;
|
||||
virtual void destroy_swapchain(SwapchainID swapchain) = 0;
|
||||
|
||||
[[nodiscard]] virtual ShaderID create_shader(const std::span<u8> bytes) = 0;
|
||||
virtual void destroy_shader(ShaderID shader) = 0;
|
||||
};
|
||||
} // namespace Nova
|
||||
|
||||
@@ -12,9 +12,11 @@ namespace Nova {
|
||||
class RenderDriver;
|
||||
struct RenderDevice;
|
||||
|
||||
struct Shader;
|
||||
struct Surface;
|
||||
struct Swapchain;
|
||||
|
||||
using ShaderID = Shader*;
|
||||
using SurfaceID = Surface*;
|
||||
using SwapchainID = Swapchain*;
|
||||
} // namespace Nova
|
||||
|
||||
@@ -291,6 +291,35 @@ void VulkanRenderDriver::destroy_swapchain(SwapchainID p_swapchain) {
|
||||
delete p_swapchain;
|
||||
}
|
||||
|
||||
ShaderID VulkanRenderDriver::create_shader(const std::span<u8> p_bytes) {
|
||||
NOVA_AUTO_TRACE();
|
||||
NOVA_ASSERT(!p_bytes.empty());
|
||||
|
||||
Shader* shader = new Shader();
|
||||
|
||||
VkShaderModuleCreateInfo create {};
|
||||
create.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
create.codeSize = p_bytes.size();
|
||||
create.pCode = reinterpret_cast<const u32*>(p_bytes.data());
|
||||
|
||||
if (vkCreateShaderModule(m_device, &create, get_allocator(VK_OBJECT_TYPE_SHADER_MODULE), &shader->handle)
|
||||
!= VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to create shader module");
|
||||
}
|
||||
|
||||
NOVA_LOG("VkShaderModule created");
|
||||
return shader;
|
||||
}
|
||||
|
||||
void VulkanRenderDriver::destroy_shader(ShaderID p_shader) {
|
||||
NOVA_AUTO_TRACE();
|
||||
NOVA_ASSERT(p_shader);
|
||||
if (p_shader->handle) {
|
||||
vkDestroyShaderModule(m_device, p_shader->handle, get_allocator(VK_OBJECT_TYPE_SHADER_MODULE));
|
||||
}
|
||||
delete p_shader;
|
||||
}
|
||||
|
||||
VkInstance VulkanRenderDriver::get_instance() const {
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
#include <vector>
|
||||
|
||||
namespace Nova {
|
||||
struct Shader {
|
||||
VkShaderModule handle = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
struct Surface {
|
||||
VkSurfaceKHR handle = VK_NULL_HANDLE;
|
||||
u32 width = 0;
|
||||
@@ -53,6 +57,9 @@ namespace Nova {
|
||||
void resize_swapchain(SwapchainID swapchain) override;
|
||||
void destroy_swapchain(SwapchainID swapchain) override;
|
||||
|
||||
[[nodiscard]] ShaderID create_shader(const std::span<u8> bytes) override;
|
||||
void destroy_shader(ShaderID shader) override;
|
||||
|
||||
[[nodiscard]] VkInstance get_instance() const;
|
||||
[[nodiscard]] VkAllocationCallbacks* get_allocator(VkObjectType type) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user