engine/include/gfx_device.h

119 lines
4.1 KiB
C
Raw Permalink Normal View History

2023-04-29 14:22:25 +00:00
#ifndef ENGINE_INCLUDE_GFX_DEVICE_H_
#define ENGINE_INCLUDE_GFX_DEVICE_H_
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
struct SDL_Window; // <SDL_video.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 {
public:
GFXDevice(const char* app_name, const char* app_version, SDL_Window* window,
gfx::GraphicsSettings settings);
GFXDevice(const GFXDevice&) = delete;
GFXDevice& operator=(const GFXDevice&) = delete;
~GFXDevice();
void GetViewportSize(uint32_t* w, uint32_t* h);
gfx::DrawBuffer* BeginRender();
2023-05-29 13:52:14 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender().
- draw_buffer is invalid after this function has been called. */
2023-04-29 14:22:25 +00:00
void FinishRender(gfx::DrawBuffer* draw_buffer);
2023-05-29 13:52:14 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- pipeline MUST be a valid pointer returned by CreatePipeline() */
2023-04-29 14:22:25 +00:00
void CmdBindPipeline(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline);
2023-05-29 13:52:14 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
2023-04-29 14:22:25 +00:00
void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding,
const gfx::Buffer* buffer);
2023-05-29 13:52:14 +00:00
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
2023-04-29 14:22:25 +00:00
void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer,
const gfx::Buffer* buffer);
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);
void CmdPushConstants(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline, uint32_t offset,
uint32_t size, const void* data);
void CmdBindDescriptorSet(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline,
const gfx::DescriptorSet* set, uint32_t set_number);
gfx::Pipeline* CreatePipeline(const gfx::PipelineInfo& info);
void DestroyPipeline(const gfx::Pipeline* pipeline);
gfx::DescriptorSetLayout* CreateDescriptorSetLayout(
const std::vector<gfx::DescriptorSetLayoutBinding>& bindings);
void DestroyDescriptorSetLayout(const gfx::DescriptorSetLayout* layout);
gfx::DescriptorSet* AllocateDescriptorSet(
const gfx::DescriptorSetLayout* layout);
2023-05-29 13:52:14 +00:00
void FreeDescriptorSet(const gfx::DescriptorSet* set);
2023-04-29 14:22:25 +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
2023-04-29 14:22:25 +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
2023-04-29 14:22:25 +00:00
gfx::UniformBuffer* CreateUniformBuffer(uint64_t size,
const void* initial_data);
2022-10-27 22:06:56 +00:00
2023-04-29 14:22:25 +00:00
void DestroyUniformBuffer(const gfx::UniformBuffer* descriptor_buffer);
2023-03-12 20:39:11 +00:00
2023-04-29 14:22:25 +00:00
void WriteUniformBuffer(gfx::UniformBuffer* buffer, uint64_t offset,
uint64_t size, const void* data);
2023-04-29 14:22:25 +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
2023-04-29 14:22:25 +00:00
void DestroyBuffer(const gfx::Buffer* buffer);
2022-10-31 16:21:07 +00:00
2023-04-29 14:22:25 +00:00
gfx::Image* CreateImage(uint32_t w, uint32_t h, const void* image_data);
2023-03-13 17:10:46 +00:00
2023-04-29 14:22:25 +00:00
void DestroyImage(const gfx::Image* image);
2022-10-07 14:18:09 +00:00
2023-04-29 14:22:25 +00:00
const gfx::Sampler* CreateSampler(const gfx::SamplerInfo& info);
2023-03-21 23:52:52 +00:00
2023-04-29 14:22:25 +00:00
void DestroySampler(const gfx::Sampler* sampler);
2023-04-29 14:22:25 +00:00
uint64_t GetFrameCount();
2023-03-13 17:10:46 +00:00
2023-04-29 14:22:25 +00:00
void LogPerformanceInfo();
2023-04-29 14:22:25 +00:00
// wait until all the active GPU queues have finished working
void WaitIdle();
2023-04-29 14:22:25 +00:00
private:
struct Impl;
std::unique_ptr<Impl> pimpl;
};
2022-09-13 18:25:18 +00:00
2023-04-29 14:22:25 +00:00
} // namespace engine
2022-09-13 18:25:18 +00:00
2023-04-29 14:22:25 +00:00
#endif