Move ShaderStage and name into Shader struct

These fields will eventually be determined automatically but for now it
makes more sense to pass them as arguements to RenderDriver::create_shader.
This commit is contained in:
2025-04-23 00:25:15 +10:00
parent 74eba7266e
commit e710b80f36
4 changed files with 11 additions and 8 deletions

View File

@@ -38,7 +38,7 @@ namespace Nova {
virtual void resize_swapchain(SwapchainID swapchain) = 0; virtual void resize_swapchain(SwapchainID swapchain) = 0;
virtual void destroy_swapchain(SwapchainID swapchain) = 0; virtual void destroy_swapchain(SwapchainID swapchain) = 0;
[[nodiscard]] virtual ShaderID create_shader(const std::span<u8> bytes) = 0; [[nodiscard]] virtual ShaderID create_shader(const std::span<u8> bytes, ShaderStage stage) = 0;
virtual void destroy_shader(ShaderID shader) = 0; virtual void destroy_shader(ShaderID shader) = 0;
[[nodiscard]] virtual PipelineID create_pipeline(GraphicsPipelineParams& params) = 0; [[nodiscard]] virtual PipelineID create_pipeline(GraphicsPipelineParams& params) = 0;

View File

@@ -9,7 +9,6 @@
#include <nova/render/render_fwd.h> #include <nova/render/render_fwd.h>
#include <nova/types.h> #include <nova/types.h>
#include <unordered_map>
#include <vector> #include <vector>
namespace Nova { namespace Nova {
@@ -27,7 +26,7 @@ namespace Nova {
}; };
struct GraphicsPipelineParams { struct GraphicsPipelineParams {
std::unordered_map<ShaderStage, ShaderID> shaders; std::vector<ShaderID> shaders;
std::vector<VertexBinding> bindings; std::vector<VertexBinding> bindings;
std::vector<VertexAttribute> attributes; std::vector<VertexAttribute> attributes;
PrimitiveTopology topology = PrimitiveTopology::TRIANGLE_LIST; PrimitiveTopology topology = PrimitiveTopology::TRIANGLE_LIST;

View File

@@ -553,11 +553,13 @@ void VulkanRenderDriver::destroy_swapchain(SwapchainID p_swapchain) {
delete p_swapchain; delete p_swapchain;
} }
ShaderID VulkanRenderDriver::create_shader(const std::span<u8> p_bytes) { ShaderID VulkanRenderDriver::create_shader(const std::span<u8> p_bytes, ShaderStage p_stage) {
NOVA_AUTO_TRACE(); NOVA_AUTO_TRACE();
NOVA_ASSERT(!p_bytes.empty()); NOVA_ASSERT(!p_bytes.empty());
Shader* shader = new Shader(); Shader* shader = new Shader();
shader->stage = p_stage; // TODO: Get from shader code
shader->name = "main"; // TODO: Get from shader code
VkShaderModuleCreateInfo create {}; VkShaderModuleCreateInfo create {};
create.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; create.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
@@ -587,12 +589,12 @@ PipelineID VulkanRenderDriver::create_pipeline(GraphicsPipelineParams& p_params)
NOVA_ASSERT(p_params.render_pass); NOVA_ASSERT(p_params.render_pass);
std::vector<VkPipelineShaderStageCreateInfo> shader_stages; std::vector<VkPipelineShaderStageCreateInfo> shader_stages;
for (const auto& [stage, shader] : p_params.shaders) { for (const auto& shader : p_params.shaders) {
VkPipelineShaderStageCreateInfo stage_create {}; VkPipelineShaderStageCreateInfo stage_create {};
stage_create.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; stage_create.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
stage_create.stage = VK_SHADER_STAGE_MAP[static_cast<int>(stage)]; stage_create.stage = VK_SHADER_STAGE_MAP[static_cast<int>(shader->stage)];
stage_create.module = shader->handle; stage_create.module = shader->handle;
stage_create.pName = "main"; // TODO: Get from shader stage_create.pName = shader->name.c_str();
// TODO: Get specialization info from shader // TODO: Get specialization info from shader
shader_stages.push_back(stage_create); shader_stages.push_back(stage_create);
} }

View File

@@ -26,6 +26,8 @@ namespace Nova {
struct Shader { struct Shader {
VkShaderModule handle = VK_NULL_HANDLE; VkShaderModule handle = VK_NULL_HANDLE;
ShaderStage stage = ShaderStage::VERTEX;
std::string name;
}; };
struct Surface { struct Surface {
@@ -67,7 +69,7 @@ namespace Nova {
void resize_swapchain(SwapchainID swapchain) override; void resize_swapchain(SwapchainID swapchain) override;
void destroy_swapchain(SwapchainID swapchain) override; void destroy_swapchain(SwapchainID swapchain) override;
[[nodiscard]] ShaderID create_shader(const std::span<u8> bytes) override; [[nodiscard]] ShaderID create_shader(const std::span<u8> bytes, ShaderStage stage) override;
void destroy_shader(ShaderID shader) override; void destroy_shader(ShaderID shader) override;
[[nodiscard]] PipelineID create_pipeline(GraphicsPipelineParams& params) override; [[nodiscard]] PipelineID create_pipeline(GraphicsPipelineParams& params) override;