16#include <SDL3/SDL_gpu.h>
17#include <SDL3/SDL_log.h>
26#include <unordered_map>
27#include <unordered_set>
39 inline constexpr SDL_GPUTextureFormat
kDrawFormat = SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM;
40 inline constexpr SDL_GPUTextureFormat
kDepthFormat = SDL_GPU_TEXTUREFORMAT_D32_FLOAT;
61 void SetCapacity(uint32_t capacity) { m_capacity = capacity; }
70 const SDLGPUImage*
At(uint32_t slot)
const {
return slot < m_images.
size() ? m_images[slot] :
nullptr; }
75 uint32_t m_capacity = 4096;
76 std::vector<SDLGPUImage*> m_images;
77 std::vector<uint32_t> m_free;
112 std::vector<SDL_GPUBuffer*>
buffers {
nullptr };
120 SDL_GPUBuffer*
CreateBuffer(SDL_GPUBufferUsageFlags usage,
const void* data, uint32_t bytes);
163 std::unordered_map<RHI::ResidentBufferId, Resident>
residents;
The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient,...
Definition gui_gradient_manager.h:65
Definition gui_image_batcher.h:24
The images the shaders can sample, each at an ImageIndex. Implemented by the backend.
Definition gui_image.h:106
An image made by GraphicsContext::CreateImage; the backend defines its contents.
Definition gui_image.h:102
What GraphicsContext::RenderScene's record gets: the backend's recording state, as the struct of the ...
Definition gui_graphics_api.h:41
Bakes serializable Styles into deduplicated runtime layout/visual styles; a StyleRef holds indices in...
Definition gui_style_manager.h:39
SDL_Window *(*)(OSWindowHandle window) WindowResolver
The SDL window of a window backend's window (OSWindowHandle): SDLWindowBackend sets it.
Definition sdlgpu_graphics_context.h:58
The images the shaders sample, by ImageIndex (1-based; the shaders' slot is one less).
Definition sdlgpu_device.h:59
void Remove(ImageIndex index) override
Frees the index for reuse; the image itself stays.
void Clear() override
Removes every image, freeing all indices.
void SetImage(ImageIndex index, SDLGPUImage *image)
Points the slot at another image.
ImageIndex Add(Image *image) override
Adds an image (not owned) and returns its index.
ImageIndex ReserveIndex()
A slot with no image yet, for one that comes later (a text atlas page).
const SDLGPUImage * At(uint32_t slot) const
The image in a 0-based slot, or null.
Definition sdlgpu_device.h:70
void SetCapacity(uint32_t capacity)
Definition sdlgpu_device.h:61
An image (GraphicsContext::CreateImage): a texture sampled by the shaders.
Definition sdlgpu_device.h:48
SDL_GPUTexture * texture
Definition sdlgpu_device.h:50
Sampler sampler
Definition sdlgpu_device.h:51
std::optional< ImageFormat > sourceFormat
Made by CreateImage from pixels of this format: UpdateImageRows can write into it.
Definition sdlgpu_device.h:54
uint2 size
Definition sdlgpu_device.h:52
uint64_t ResidentBufferId
GPU storage kept across frames (UploadResidentBuffers); 0 is none.
Definition gui_rhi.h:36
Sampler
How an image is filtered and addressed when sampled.
Definition gui_image.h:89
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:99
std::array< RHI::GpuPipeline, kPrimitiveKindCount > PipelineSet
Definition gui_primitive_renderer.h:31
uint64_t DeviceAddress
Shader-visible buffer address.
Definition gui_render_primitives.h:206
ResidentState
Where a resident buffer is.
Definition gui_rhi.h:40
@ NearestRepeat
Definition gui_image.h:92
@ Invalid
Definition gui_image.h:99
Definition sdlgpu_device.h:37
uint32_t AddressEntry(DeviceAddress address)
Definition sdlgpu_device.h:43
constexpr SDL_GPUTextureFormat kDrawFormat
The format windows draw in, whatever their swapchain's: the blit to it converts.
Definition sdlgpu_device.h:39
DeviceAddress MakeAddress(uint32_t entry, uint32_t offset)
What a DeviceAddress holds: the buffer table's entry, and the byte offset into it.
Definition sdlgpu_device.h:42
uint32_t AddressOffset(DeviceAddress address)
Definition sdlgpu_device.h:44
constexpr SDL_GPUTextureFormat kDepthFormat
Definition sdlgpu_device.h:40
Definition gui_logging.h:24
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
Definition gui_base_types.h:394
Where SDL GPU's messages go.
Definition sdlgpu_graphics_context.h:49
Definition sdlgpu_device.h:135
SDL_GPUBuffer * buffer
Definition sdlgpu_device.h:136
uint32_t bytes
Definition sdlgpu_device.h:138
SDL_GPUTransferBuffer * staging
Definition sdlgpu_device.h:137
RecordCopies' working lists, kept between frames for their storage.
Definition sdlgpu_device.h:148
std::vector< BufferCopy > buffers
Definition sdlgpu_device.h:150
std::vector< SDLGPUImage * > released
Definition sdlgpu_device.h:151
std::vector< TextureCopy > textures
Definition sdlgpu_device.h:149
Definition sdlgpu_device.h:234
SDL_GPUTexture * texture
Definition sdlgpu_device.h:235
uint2 size
Definition sdlgpu_device.h:236
Definition sdlgpu_device.h:158
uint32_t entry
Definition sdlgpu_device.h:160
SDL_GPUBuffer * buffer
Definition sdlgpu_device.h:159
bool ready
Definition sdlgpu_device.h:161
Definition sdlgpu_device.h:213
std::function< void(const ScenePayload &scene)> record
Definition sdlgpu_device.h:217
color4f clear
Definition sdlgpu_device.h:216
ID window
Definition sdlgpu_device.h:215
ID key
Definition sdlgpu_device.h:214
What RenderScene keeps for a key: its color texture (in the image set) and depth, both in liveImages.
Definition sdlgpu_device.h:205
uint64_t lastFrame
the frame it was last asked for
Definition sdlgpu_device.h:210
uint2 extent
Definition sdlgpu_device.h:209
ImageIndex index
Definition sdlgpu_device.h:208
SDLGPUImage * color
Definition sdlgpu_device.h:206
SDLGPUImage * depth
Definition sdlgpu_device.h:207
A whole image's pixels, or rows rows from firstRow written into one already up (UpdateImageRows); 0 r...
Definition sdlgpu_device.h:128
SDLGPUImage * image
Definition sdlgpu_device.h:129
SDL_GPUTransferBuffer * staging
Definition sdlgpu_device.h:130
uint32_t firstRow
Definition sdlgpu_device.h:131
uint32_t rows
Definition sdlgpu_device.h:132
Definition sdlgpu_device.h:93
SDL_GPUDevice * device
Definition sdlgpu_device.h:100
SDL_GPUTexture * blankImage
bound where a draw has fewer images
Definition sdlgpu_device.h:177
std::vector< uint32_t > freeBuffers
Definition sdlgpu_device.h:113
SDL_GPUShaderFormat shaderFormat
the one the GUI's shaders are taken in
Definition sdlgpu_device.h:102
DebugConfig debug
Definition sdlgpu_device.h:94
float elapsedTime
Definition sdlgpu_device.h:194
void ReleaseBuffer(SDL_GPUBuffer *&buffer)
Lets go of a buffer: its pending copy, if any, isn't made.
bool EnsureQuadIndices(uint32_t quads)
Grows the quads' index buffer to hold quads (copied with the window frame's copies).
PipelineSet pipelines
pipeline: the object; layout: the kind
Definition sdlgpu_device.h:182
std::vector< ImageIndex > gradientPages
each gradient page's index in the image set
Definition sdlgpu_device.h:192
RHI::ResidentState ResidentState(RHI::ResidentBufferId id) const
RHI::ResidentBufferId CreateResident(std::span< const RHI::UploadRequest > requests, std::span< DeviceAddress > addresses)
SDL_GPUBuffer * CreateBuffer(SDL_GPUBufferUsageFlags usage, const void *data, uint32_t bytes)
A GPU buffer of usage and a transfer buffer holding data, copied at the next window frame's start.
StyleManager * lastStyles
PrepareFrame's, for a live resize's redraw.
Definition sdlgpu_device.h:195
std::vector< TextureCopy > textureCopies
Definition sdlgpu_device.h:141
SDL_GPUBuffer * blankBuffer
bound to the storage slots a draw doesn't use
Definition sdlgpu_device.h:183
std::vector< SceneRequest > sceneRequests
Definition sdlgpu_device.h:220
struct tachyon::sdlgpu::SDLGPUGraphicsContext::Impl::CopyScratch copyScratch
std::array< SDL_GPUGraphicsPipeline *, kPrimitiveKindCount > pipelineObjects
Definition sdlgpu_device.h:181
void * previousLogData
Definition sdlgpu_device.h:108
GradientManager * lastGradients
Definition sdlgpu_device.h:196
SDL_GPUSampler * SamplerFor(tachyon::Sampler sampler) const
std::mutex copyMutex
images are made and let go on any thread
Definition sdlgpu_device.h:140
std::unordered_map< ID, Scene > scenes
Definition sdlgpu_device.h:219
std::vector< SDL_GPUBuffer * > buffers
entry 0 is none
Definition sdlgpu_device.h:112
static constexpr SDL_GPUTextureFormat kSceneColorFormat
Definition sdlgpu_device.h:199
bool lowPower
Definition sdlgpu_device.h:96
std::string driverAsked
SetDriver; empty, SDL's choice.
Definition sdlgpu_device.h:95
std::unordered_map< ID, ImageTarget > imageTargets
Definition sdlgpu_device.h:238
SDL_GPUDevice * externalDevice
the host's (SetExternalDevice): not destroyed at Cleanup
Definition sdlgpu_device.h:101
void RecordScenes(SDL_GPUCommandBuffer *cmd, ID window)
Clears and records the scenes asked for in window this frame, before its UI's render pass and outside...
void ReleaseResident(RHI::ResidentBufferId id)
ImageBatcher batcher
Definition sdlgpu_device.h:193
SDLGPUImage * CreateTargetImage(uint2 size, SDL_GPUTextureFormat format, SDL_GPUTextureUsageFlags usage, Sampler sampler)
A texture the GPU draws into (a scene's), in liveImages so DestroyImageAtEnd frees it; null on failur...
std::vector< BufferCopy > bufferCopies
Definition sdlgpu_device.h:142
SDL_GPUBuffer * Buffer(uint32_t entry) const
Definition sdlgpu_device.h:116
SDL_GPUBuffer * colorStyles
Definition sdlgpu_device.h:191
WindowResolver resolveWindow
Definition sdlgpu_device.h:97
uint32_t AddBuffer(SDL_GPUBuffer *buffer)
uint64_t sceneFrame
Definition sdlgpu_device.h:221
std::array< SDL_GPUSampler *, 3 > samplers
nearest repeat, linear repeat, linear clamp
Definition sdlgpu_device.h:176
std::vector< SDLGPUImage * > releasedImages
Images let go of (DestroyImageAtEnd, on any thread), freed by RecordCopies on the frame's thread afte...
Definition sdlgpu_device.h:145
SDL_GPUBuffer * boxStyles
Definition sdlgpu_device.h:190
std::unordered_map< uint32_t, std::unique_ptr< SDLGPUImage > > externalImages
By image slot index: the host's texture, which the GUI never releases.
Definition sdlgpu_device.h:232
SDLGPUImageSet imageSet
Definition sdlgpu_device.h:175
uint32_t imageSlots
Definition sdlgpu_device.h:98
RHI::ResidentBufferId nextResident
Definition sdlgpu_device.h:167
std::unordered_map< RHI::ResidentBufferId, Resident > residents
Definition sdlgpu_device.h:163
SDL_GPUBuffer * quadIndices
p * 4 + { 0, 1, 3, 0, 3, 2 } for each quad p
Definition sdlgpu_device.h:184
void RemoveBuffer(uint32_t entry)
std::string deviceName
Definition sdlgpu_device.h:104
SDL_LogOutputFunction previousLog
SDL's log output while the debug callback takes SDL GPU's messages.
Definition sdlgpu_device.h:107
static constexpr uint64_t kSceneKeepFrames
a scene not asked for this long goes
Definition sdlgpu_device.h:200
std::unordered_set< SDLGPUImage * > liveImages
Every image made and not let go for a frame: Cleanup frees what's left.
Definition sdlgpu_device.h:174
std::vector< RHI::ResidentBufferId > pendingResidents
Made and not copied yet, oldest first; one let go of meanwhile is no longer in residents and is passe...
Definition sdlgpu_device.h:166
std::string driver
the one in use
Definition sdlgpu_device.h:103
uint32_t quadCapacity
Definition sdlgpu_device.h:185
bool logHooked
Definition sdlgpu_device.h:109
void RecordCopies(SDL_GPUCopyPass *pass)
Records the queued copies; resident buffers they make are Ready after.
Definition gui_base_types.h:74