1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-23 20:47:45 +00:00
novus/renderer/include/rendersystem.h
Joshua Goins b9b162b377 Add experimental new rendering system
I started writing this late last year, and finally uploading parts of
it. Currently, doesn't work, but doesn't crash either. Enable it via
the NOVUS_USE_NEW_RENDERER environment variable.

The goal is to use the game's own shaders instead of creating our own,
it's lacking support for buffers with actual data in them and constants
so while it "works" nothing is displayed on screen yet.
2024-04-20 17:29:29 -04:00

71 lines
No EOL
2.1 KiB
C++

// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QDebug>
#include <string_view>
#include <physis.hpp>
#include <spirv.hpp>
#include <spirv_cross.hpp>
#include <spirv_glsl.hpp>
#include <vulkan/vulkan.h>
class Renderer;
struct RenderModel;
class RenderSystem
{
public:
RenderSystem(Renderer &renderer, GameData *data);
void testInit(::RenderModel *m);
void render(uint32_t imageIndex, VkCommandBuffer commandBuffer);
void setSize(uint32_t width, uint32_t height);
private:
void beginPass(uint32_t imageIndex, VkCommandBuffer commandBuffer, std::string_view passName);
void endPass(VkCommandBuffer commandBuffer);
void bindPipeline(VkCommandBuffer commandBuffer, physis_Shader &vertexShader, physis_Shader &pixelShader);
VkShaderModule convertShaderModule(const physis_Shader &shader, spv::ExecutionModel executionModel);
spirv_cross::CompilerGLSL getShaderModuleResources(const physis_Shader &shader);
struct RenderModel {
physis_SHPK shpk;
::RenderModel *internal_model = nullptr;
};
std::vector<RenderModel> m_renderModels;
struct RequestedBinding {
VkDescriptorType type;
VkShaderStageFlags stageFlags;
bool used = false;
};
struct RequestedSet {
bool used = true;
VkDescriptorSetLayout layout = VK_NULL_HANDLE;
std::vector<RequestedBinding> bindings;
};
struct CachedPipeline {
VkPipeline pipeline = VK_NULL_HANDLE;
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE;
std::vector<VkDescriptorSetLayout> setLayouts;
std::map<uint64_t, VkDescriptorSet> cachedDescriptors;
std::vector<RequestedSet> requestedSets;
};
// combined vertex + pixel code length
std::unordered_map<uint32_t, CachedPipeline> m_cachedPipelines;
Renderer &m_renderer;
GameData *m_data = nullptr;
VkExtent2D m_extent = {640, 480};
VkDescriptorSet createDescriptorFor(const RenderModel &model, const CachedPipeline &cachedPipeline, int i);
};