Files
RayTracer/src/gpu/GPURenderer.h
T

102 lines
2.8 KiB
C++
Raw Normal View History

2025-01-25 13:04:12 +01:00
#pragma once
2025-01-28 13:11:40 +01:00
#include "gpu/GPUScene.h"
2025-01-25 20:08:21 +01:00
#include "scene/Renderer.h"
2025-01-25 13:04:12 +01:00
#include <vulkan/vulkan.hpp>
#include <vulkan/vulkan_raii.hpp>
2025-02-25 05:10:35 +01:00
#include <vk_mem_alloc.h>
2025-01-25 13:04:12 +01:00
using namespace vk::raii;
2025-01-25 20:08:21 +01:00
struct GPURenderer : public Renderer
2025-01-25 13:04:12 +01:00
{
public:
2025-01-25 20:08:21 +01:00
GPURenderer();
2025-02-27 20:25:53 +09:00
virtual ~GPURenderer();
2025-02-25 05:10:35 +01:00
virtual void addPointLight(PointLight point) override { scene->addPointLight(point); }
virtual void addDirectionalLight(DirectionalLight dir) override { scene->addDirectionalLight(dir); }
virtual void addModel(PModel model, glm::mat4 transform) override { scene->addModel(std::move(model), transform); }
virtual void addModels(std::vector<PModel> models, glm::mat4 transform) override { scene->addModels(std::move(models), transform); }
virtual void generate() override { scene->generate(); }
2025-01-28 19:44:47 +01:00
virtual void render(Camera cam, RenderParameter param) override;
2025-01-25 13:04:12 +01:00
2025-02-27 20:25:53 +09:00
virtual void beginFrame() override;
virtual void update() override;
2025-01-25 13:04:12 +01:00
private:
2025-01-28 00:08:52 +01:00
struct GPUCamera
{
glm::vec3 cameraPosition;
float f;
glm::vec3 cameraForward;
float S_O;
glm::vec3 fogEmm;
float ks;
float A;
float ka;
};
2025-01-28 19:44:47 +01:00
struct SampleParams
{
uint32_t pass;
uint32_t samplesPerPixel;
uint32_t numDirectionalLights;
uint32_t numPointLights;
};
2025-01-25 14:51:17 +01:00
void createDevice();
void createDescriptors();
2025-01-28 19:44:47 +01:00
void createPipeline();
2025-01-28 13:11:40 +01:00
2025-02-25 05:10:35 +01:00
GPUScene* scene;
2025-01-25 13:04:12 +01:00
Context context;
2025-01-28 19:44:47 +01:00
Instance instance = nullptr;
PhysicalDevice physicalDevice = nullptr;
Device device = nullptr;
Queue queue = nullptr;
VmaAllocator allocator = nullptr;
2025-01-25 13:04:12 +01:00
2025-01-28 19:44:47 +01:00
vk::PhysicalDeviceAccelerationStructurePropertiesKHR accelerationProperties = {};
vk::PhysicalDeviceRayTracingPipelinePropertiesKHR rayTracingProperties = {};
uint32_t computeQueueFamily = 0;
CommandPool cmdPool = nullptr;
CommandBuffers cmdBuffers = nullptr;
2025-01-28 13:11:40 +01:00
std::vector<Semaphore> semaphores;
std::vector<Fence> fences;
2025-01-25 13:04:12 +01:00
2025-01-28 19:44:47 +01:00
DescriptorSetLayout descriptorLayout = nullptr;
DescriptorSet descriptorSet = nullptr;
DescriptorPool descriptorPool = nullptr;
PipelineLayout pipelineLayout = nullptr;
2025-01-25 13:04:12 +01:00
2025-01-28 19:44:47 +01:00
ShaderModule rayGen = nullptr;
ShaderModule closestHit = nullptr;
ShaderModule miss = nullptr;
2025-01-25 13:04:12 +01:00
2025-01-28 19:44:47 +01:00
Pipeline pipeline = nullptr;
2025-01-25 13:04:12 +01:00
2025-01-28 19:44:47 +01:00
Buffer rayGenSBT = nullptr;
vk::StridedDeviceAddressRegionKHR rayGenAddr;
VmaAllocation rayGenAlloc;
Buffer closestHitSBT = nullptr;
vk::StridedDeviceAddressRegionKHR closestHitAddr;
VmaAllocation closestHitAlloc;
Buffer missSBT = nullptr;
vk::StridedDeviceAddressRegionKHR missAddr;
VmaAllocation missAlloc;
Buffer cameraBuffer = nullptr;
2025-01-28 00:08:52 +01:00
VmaAllocation cameraAllocation;
2025-01-28 19:44:47 +01:00
Image radianceAccumulator = nullptr;
ImageView radianceView = nullptr;
2025-01-28 00:08:52 +01:00
VmaAllocation radianceAllocation;
2025-01-28 19:44:47 +01:00
Image image = nullptr;
ImageView imageView = nullptr;
2025-01-28 00:08:52 +01:00
VmaAllocation imageAllocation;
2025-01-28 19:44:47 +01:00
void uploadToGPU(Buffer& buffer, void* data, size_t size);
2025-01-25 13:04:12 +01:00
};