engine/include/gfx_device.h

109 lines
4.3 KiB
C
Raw Normal View History

2024-03-31 10:11:22 +00:00
#pragma once
2022-10-22 12:15:25 +00:00
2022-09-17 00:22:35 +00:00
#include <memory>
2023-05-01 13:13:35 +00:00
#include "gfx.h"
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
struct SDL_Window; // <SDL_video.h>
struct ImDrawData; // "imgui/imgui.h"
2022-09-13 18:25:18 +00:00
2022-10-02 15:34:51 +00:00
namespace engine {
2022-09-13 18:25:18 +00:00
2023-04-29 14:22:25 +00:00
class GFXDevice {
2024-03-31 10:11:22 +00:00
public:
GFXDevice(const char* app_name, const char* app_version, SDL_Window* window, gfx::GraphicsSettings settings);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
GFXDevice(const GFXDevice&) = delete;
GFXDevice& operator=(const GFXDevice&) = delete;
~GFXDevice();
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void GetViewportSize(uint32_t* w, uint32_t* h);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void SetupImguiBackend();
void ShutdownImguiBackend();
void CmdRenderImguiDrawData(gfx::DrawBuffer* draw_buffer, ImDrawData* draw_data);
2023-10-01 10:38:27 +00:00
2024-04-13 11:11:36 +00:00
gfx::DrawBuffer* BeginRender(bool window_resized);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender().
- draw_buffer is invalid after this function has been called. */
void FinishRender(gfx::DrawBuffer* draw_buffer);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
gfx::Image* CreateShadowmapImage();
gfx::DrawBuffer* BeginShadowmapRender(gfx::Image* image);
void FinishShadowmapRender(gfx::DrawBuffer* draw_buffer, gfx::Image* image);
2024-03-26 11:18:50 +00:00
2024-03-31 10:11:22 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- pipeline MUST be a valid pointer returned by CreatePipeline() */
void CmdBindPipeline(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding, const gfx::Buffer* buffer);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer, const gfx::Buffer* buffer);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void CmdDrawIndexed(gfx::DrawBuffer* draw_buffer, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t vertex_offset,
uint32_t first_instance);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance);
2024-03-31 10:11:22 +00:00
void CmdPushConstants(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline, uint32_t offset, uint32_t size, const void* data);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void CmdBindDescriptorSet(gfx::DrawBuffer* draw_buffer, const gfx::Pipeline* pipeline, const gfx::DescriptorSet* set, uint32_t set_number);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
gfx::Pipeline* CreatePipeline(const gfx::PipelineInfo& info);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void DestroyPipeline(const gfx::Pipeline* pipeline);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
gfx::DescriptorSetLayout* CreateDescriptorSetLayout(const std::vector<gfx::DescriptorSetLayoutBinding>& bindings);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void DestroyDescriptorSetLayout(const gfx::DescriptorSetLayout* layout);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
gfx::DescriptorSet* AllocateDescriptorSet(const gfx::DescriptorSetLayout* layout);
2023-04-29 14:22:25 +00:00
2024-03-31 10:11:22 +00:00
void FreeDescriptorSet(const gfx::DescriptorSet* set);
2023-05-29 13:52:14 +00:00
2024-03-31 10:11:22 +00:00
// This updates all copies of the descriptor.
// This cannot be used after any frames have been renderered
void UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set, uint32_t binding, const gfx::UniformBuffer* buffer, size_t offset, size_t range);
2022-09-19 17:33:56 +00:00
2024-03-31 10:11:22 +00:00
void UpdateDescriptorCombinedImageSampler(const gfx::DescriptorSet* set, uint32_t binding, const gfx::Image* image, const gfx::Sampler* sampler);
2022-09-13 18:25:18 +00:00
2024-03-31 10:11:22 +00:00
gfx::UniformBuffer* CreateUniformBuffer(uint64_t size, const void* initial_data);
2022-10-27 22:06:56 +00:00
2024-03-31 10:11:22 +00:00
void DestroyUniformBuffer(const gfx::UniformBuffer* descriptor_buffer);
2023-03-12 20:39:11 +00:00
2024-03-31 10:11:22 +00:00
void WriteUniformBuffer(gfx::UniformBuffer* buffer, uint64_t offset, uint64_t size, const void* data);
2024-03-31 10:11:22 +00:00
// Loads data into staging buffer and copies that into a single GPU buffer.
gfx::Buffer* CreateBuffer(gfx::BufferType type, uint64_t size, const void* data);
2023-03-13 01:19:32 +00:00
2024-03-31 10:11:22 +00:00
void DestroyBuffer(const gfx::Buffer* buffer);
2022-10-31 16:21:07 +00:00
2024-03-31 10:11:22 +00:00
gfx::Image* CreateImage(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const void* image_data);
2023-03-13 17:10:46 +00:00
2024-03-31 10:11:22 +00:00
gfx::Image* CreateImageCubemap(uint32_t w, uint32_t h, gfx::ImageFormat input_format, const std::array<const void*, 6>& image_data);
2024-03-19 11:32:51 +00:00
2024-03-31 10:11:22 +00:00
void DestroyImage(const gfx::Image* image);
2022-10-07 14:18:09 +00:00
2024-03-31 10:11:22 +00:00
const gfx::Sampler* CreateSampler(const gfx::SamplerInfo& info);
2023-03-21 23:52:52 +00:00
2024-03-31 10:11:22 +00:00
void DestroySampler(const gfx::Sampler* sampler);
2024-03-31 10:11:22 +00:00
uint64_t GetFrameCount();
2023-03-13 17:10:46 +00:00
2024-03-31 10:11:22 +00:00
void LogPerformanceInfo();
2024-03-31 10:11:22 +00:00
// wait until all the active GPU queues have finished working
void WaitIdle();
2024-03-31 10:11:22 +00:00
private:
struct Impl;
std::unique_ptr<Impl> pimpl;
2023-04-29 14:22:25 +00:00
};
2022-09-13 18:25:18 +00:00
2024-04-13 11:11:36 +00:00
} // namespace engine