TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
sdlgpu_rhi.h
Go to the documentation of this file.
1#pragma once
2
3// Inside the SDL GPU backend: the GUI's pipelines, and a window frame's recording surface for the
4// PrimitiveRenderer (RHI::RenderCommandList). SDL wants copies outside render passes, and the
5// renderer uploads and draws in one go: the command list keeps the frame's uploads in a staging
6// area and its draws in a list, which the window copies and replays after.
7
9
10#include <vector>
11
12namespace tachyon::sdlgpu
13{
18
20 {
21 public:
24 SDLGPUCommandList(SDLGPUGraphicsContext::Impl& device, std::vector<std::byte>& staging)
25 : m_device(device), m_staging(staging) {}
26
29 void Begin(uint32_t stagingEntry)
30 {
31 m_stagingEntry = stagingEntry;
32 m_draws.clear();
33 m_mostQuads = 0;
34 }
35
37 void DrawPrimitives(const RHI::GpuPipeline& pipeline, const GPUDrawPushConstants& pushConstants,
38 uint32_t primitiveCount, uint32_t firstPrimitive, PrimitiveShape shape,
39 std::span<const std::byte> primitives) override;
40 void UploadTransientBuffers(std::span<const RHI::UploadRequest> requests, std::span<DeviceAddress> addresses) override;
41 RHI::ResidentBufferId UploadResidentBuffers(std::span<const RHI::UploadRequest> requests,
42 std::span<DeviceAddress> addresses) override;
45
47 uint32_t MostQuads() const { return m_mostQuads; }
49 void Replay(SDL_GPUCommandBuffer* commands, SDL_GPURenderPass* pass) const;
50
51 private:
52 struct Draw
53 {
54 uint32_t kind = 0;
56 uint32_t count = 0;
57 uint32_t bufferEntry = 0;
58 uint32_t imageCount = 0;
59 std::array<uint32_t, ImageBatcher::kMaxImages> images {};
60 DrawUniforms uniforms {};
61 };
62
63 SDLGPUGraphicsContext::Impl& m_device;
64 std::vector<std::byte>& m_staging;
65 uint32_t m_stagingEntry = 0;
66 std::vector<Draw> m_draws;
67 std::vector<ImageBatcher::Batch> m_batches;
68 uint32_t m_mostQuads = 0;
69 };
70}
One frame's recording surface for one window.
Definition gui_rhi.h:62
RHI::ResidentState ResidentBufferState(RHI::ResidentBufferId id) const override
void ReleaseResidentBuffer(RHI::ResidentBufferId id) override
Frees the buffer once no frame in flight reads it; an unknown id does nothing.
RHI::ResidentBufferId UploadResidentBuffers(std::span< const RHI::UploadRequest > requests, std::span< DeviceAddress > addresses) override
void Begin(uint32_t stagingEntry)
A new frame: the last one's draws gone.
Definition sdlgpu_rhi.h:29
void Replay(SDL_GPUCommandBuffer *commands, SDL_GPURenderPass *pass) const
Records the kept draws into the render pass.
void UploadTransientBuffers(std::span< const RHI::UploadRequest > requests, std::span< DeviceAddress > addresses) override
uint32_t MostQuads() const
The most quads one draw has: the quads' index buffer must hold them.
Definition sdlgpu_rhi.h:47
void DrawPrimitives(const RHI::GpuPipeline &pipeline, const GPUDrawPushConstants &pushConstants, uint32_t primitiveCount, uint32_t firstPrimitive, PrimitiveShape shape, std::span< const std::byte > primitives) override
Cut where a run would read more than the 16 images a draw binds, and kept for Replay.
SDLGPUCommandList(SDLGPUGraphicsContext::Impl &device, std::vector< std::byte > &staging)
staging takes each frame's transient data.
Definition sdlgpu_rhi.h:24
uint64_t ResidentBufferId
GPU storage kept across frames (UploadResidentBuffers); 0 is none.
Definition gui_rhi.h:36
ResidentState
Where a resident buffer is.
Definition gui_rhi.h:40
PrimitiveShape
The vertices a primitive's vertex shader is run for; gl_VertexIndex divided by their count is the pri...
Definition gui_render_primitives.h:225
@ Quad
4 corners of its rectangle, drawn as two indexed triangles (0,1,3, 0,3,2)
Definition gui_render_primitives.h:226
Definition sdlgpu_device.h:37
bool CreatePipelines(SDLGPUGraphicsContext::Impl &device)
A pipeline per primitive kind from the built-in SDL GPU shaders, in the format the device takes.
void ReleasePipelines(SDLGPUGraphicsContext::Impl &device)
Definition gui_render_primitives.h:257
Definition gui_rhi.h:22
The uniforms both stages of every draw get, as all_common.slang declares them.
Definition sdlgpu_device.h:82