ObjectivelyGPU
Object oriented graphics framework for SDL3 and C
Loading...
Searching...
No Matches
RenderDevice.c File Reference
#include <assert.h>
#include <string.h>
#include <SDL3/SDL_surface.h>
#include <Objectively/Resource.h>
#include "Buffer.h"
#include "CommandBuffer.h"
#include "ComputePipeline.h"
#include "CopyPass.h"
#include "Framebuffer.h"
#include "GraphicsPipeline.h"
#include "QueryPool.h"
#include "RenderDevice.h"
#include "Sampler.h"
#include "Shader.h"
#include "Texture.h"
#include "TransferBuffer.h"

Data Structures

struct  GPU_ShaderFormat
 Metadata for a shader binary format: its SDL enum, the file extension of the transpiled blob, and the entry-point name the toolchain emits for each stage. shadercross names every MSL (and hence metallib) entry point "main0"; SPIR-V and DXIL keep the GLSL/HLSL default "main". More...
 

Macros

#define GPU_DEBUG   true
 Whether to create the SDL_GPUDevice with backend validation/debug layers.
 
#define _Class   _RenderDevice
 

Functions

static Resource * resolveShaderResource (const char *name, SDL_GPUShaderFormat supported, GPU_ShaderFormat *resolved)
 A helper.
 
static void dealloc (Object *self)
 
static CommandBufferacquireCommandBuffer (const RenderDevice *self)
 
static CommandBufferbeginFrame (RenderDevice *self)
 
static FenceendFrameAndFence (RenderDevice *self)
 
static void endFrame (RenderDevice *self)
 
static BuffercreateBuffer (RenderDevice *self, const SDL_GPUBufferCreateInfo *info)
 
static BuffercreateBufferWithConstMem (RenderDevice *self, SDL_GPUBufferUsageFlags usage, const void *mem, Uint32 size)
 
static BuffercreateBufferWithData (RenderDevice *self, SDL_GPUBufferUsageFlags usage, const Data *data)
 
static ComputePipelinecreateComputePipeline (RenderDevice *self, const SDL_GPUComputePipelineCreateInfo *info)
 
static FramebuffercreateFramebuffer (RenderDevice *self, const GPU_FramebufferCreateInfo *info)
 
static GraphicsPipelinecreateGraphicsPipeline (RenderDevice *self, const SDL_GPUGraphicsPipelineCreateInfo *info)
 
static QueryPoolcreateQueryPool (RenderDevice *self, const SDL_GPUQueryPoolCreateInfo *info)
 
static SamplercreateSampler (RenderDevice *self, const SDL_GPUSamplerCreateInfo *info)
 
static SamplercreateSamplerLinearRepeat (RenderDevice *self)
 
static SamplercreateSamplerLinearClamp (RenderDevice *self)
 
static SamplercreateSamplerNearestClamp (RenderDevice *self)
 
static SamplercreateSamplerShadowCompare (RenderDevice *self)
 
static ShadercreateShader (RenderDevice *self, const SDL_GPUShaderCreateInfo *info)
 
static TexturecreateTexture (RenderDevice *self, const SDL_GPUTextureCreateInfo *info, const void *pixels)
 
static TransferBuffercreateTransferBuffer (RenderDevice *self, const SDL_GPUTransferBufferCreateInfo *info)
 
static TexturecreateTextureFromSurface (RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps)
 
static TexturecreateSolidColorTexture (RenderDevice *self, SDL_GPUTextureType type, Uint32 layerCount, Uint32 rgba)
 
static SDL_GPUTextureFormat getSwapchainTextureFormat (const RenderDevice *self)
 
static RenderDeviceinit (RenderDevice *self)
 
static RenderDeviceinitWithWindow (RenderDevice *self, SDL_Window *window)
 
static ShaderloadShader (RenderDevice *self, const char *name, const SDL_GPUShaderCreateInfo *info)
 
static ComputePipelineloadComputePipeline (RenderDevice *self, const char *name, const SDL_GPUComputePipelineCreateInfo *info)
 
static GraphicsPipelineloadGraphicsPipeline (RenderDevice *self, const char *vertexShaderName, const SDL_GPUShaderCreateInfo *vertexShaderInfo, const char *fragmentShaderName, const SDL_GPUShaderCreateInfo *fragmentShaderInfo, SDL_GPUGraphicsPipelineCreateInfo *info)
 
static bool setAllowedFramesInFlight (const RenderDevice *self, Uint32 allowed)
 
static void setFramebuffer (RenderDevice *self, Framebuffer *framebuffer)
 
static bool setSwapchainParameters (const RenderDevice *self, SDL_GPUSwapchainComposition composition, SDL_GPUPresentMode mode)
 
static void setWindow (RenderDevice *self, SDL_Window *window)
 
static bool supportsPresentMode (const RenderDevice *self, SDL_GPUPresentMode mode)
 
static bool supportsSwapchainComposition (const RenderDevice *self, SDL_GPUSwapchainComposition composition)
 
static bool textureSupportsFormat (const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUTextureType type, SDL_GPUTextureUsageFlags usage)
 
static bool textureSupportsSampleCount (const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUSampleCount sample_count)
 
static bool waitForIdle (const RenderDevice *self)
 
static bool waitForSwapchain (const RenderDevice *self)
 
static void initialize (Class *clazz)
 
Class * _RenderDevice (void)
 

Variables

static const GPU_ShaderFormat GPU_ShaderFormats []
 The shader formats supported by ObjectivelyGPU.
 

Macro Definition Documentation

◆ _Class

#define _Class   _RenderDevice

◆ GPU_DEBUG

#define GPU_DEBUG   true

Whether to create the SDL_GPUDevice with backend validation/debug layers.

Defaults to enabled unless NDEBUG is defined (i.e. on for debug builds, off for release). Override by defining GPU_DEBUG to true or false at build time.

Function Documentation

◆ _RenderDevice()

Class * _RenderDevice ( void  )

◆ acquireCommandBuffer()

static CommandBuffer * acquireCommandBuffer ( const RenderDevice self)
static

◆ beginFrame()

static CommandBuffer * beginFrame ( RenderDevice self)
static

◆ createBuffer()

static Buffer * createBuffer ( RenderDevice self,
const SDL_GPUBufferCreateInfo *  info 
)
static

◆ createBufferWithConstMem()

static Buffer * createBufferWithConstMem ( RenderDevice self,
SDL_GPUBufferUsageFlags  usage,
const void *  mem,
Uint32  size 
)
static

◆ createBufferWithData()

static Buffer * createBufferWithData ( RenderDevice self,
SDL_GPUBufferUsageFlags  usage,
const Data *  data 
)
static

◆ createComputePipeline()

static ComputePipeline * createComputePipeline ( RenderDevice self,
const SDL_GPUComputePipelineCreateInfo *  info 
)
static

◆ createFramebuffer()

static Framebuffer * createFramebuffer ( RenderDevice self,
const GPU_FramebufferCreateInfo info 
)
static

◆ createGraphicsPipeline()

static GraphicsPipeline * createGraphicsPipeline ( RenderDevice self,
const SDL_GPUGraphicsPipelineCreateInfo *  info 
)
static

◆ createQueryPool()

static QueryPool * createQueryPool ( RenderDevice self,
const SDL_GPUQueryPoolCreateInfo info 
)
static

◆ createSampler()

static Sampler * createSampler ( RenderDevice self,
const SDL_GPUSamplerCreateInfo *  info 
)
static

◆ createSamplerLinearClamp()

static Sampler * createSamplerLinearClamp ( RenderDevice self)
static

◆ createSamplerLinearRepeat()

static Sampler * createSamplerLinearRepeat ( RenderDevice self)
static

◆ createSamplerNearestClamp()

static Sampler * createSamplerNearestClamp ( RenderDevice self)
static

◆ createSamplerShadowCompare()

static Sampler * createSamplerShadowCompare ( RenderDevice self)
static

◆ createShader()

static Shader * createShader ( RenderDevice self,
const SDL_GPUShaderCreateInfo *  info 
)
static

◆ createSolidColorTexture()

static Texture * createSolidColorTexture ( RenderDevice self,
SDL_GPUTextureType  type,
Uint32  layerCount,
Uint32  rgba 
)
static

◆ createTexture()

static Texture * createTexture ( RenderDevice self,
const SDL_GPUTextureCreateInfo *  info,
const void *  pixels 
)
static

◆ createTextureFromSurface()

static Texture * createTextureFromSurface ( RenderDevice self,
SDL_Surface *  surface,
SDL_GPUTextureUsageFlags  usage,
bool  generateMipmaps 
)
static

◆ createTransferBuffer()

static TransferBuffer * createTransferBuffer ( RenderDevice self,
const SDL_GPUTransferBufferCreateInfo *  info 
)
static

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

◆ endFrame()

static void endFrame ( RenderDevice self)
static

◆ endFrameAndFence()

static Fence * endFrameAndFence ( RenderDevice self)
static

◆ getSwapchainTextureFormat()

static SDL_GPUTextureFormat getSwapchainTextureFormat ( const RenderDevice self)
static

◆ init()

static RenderDevice * init ( RenderDevice self)
static

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

◆ initWithWindow()

static RenderDevice * initWithWindow ( RenderDevice self,
SDL_Window *  window 
)
static

◆ loadComputePipeline()

static ComputePipeline * loadComputePipeline ( RenderDevice self,
const char *  name,
const SDL_GPUComputePipelineCreateInfo *  info 
)
static

◆ loadGraphicsPipeline()

static GraphicsPipeline * loadGraphicsPipeline ( RenderDevice self,
const char *  vertexShaderName,
const SDL_GPUShaderCreateInfo *  vertexShaderInfo,
const char *  fragmentShaderName,
const SDL_GPUShaderCreateInfo *  fragmentShaderInfo,
SDL_GPUGraphicsPipelineCreateInfo *  info 
)
static

◆ loadShader()

static Shader * loadShader ( RenderDevice self,
const char *  name,
const SDL_GPUShaderCreateInfo *  info 
)
static

◆ resolveShaderResource()

static Resource * resolveShaderResource ( const char *  name,
SDL_GPUShaderFormat  supported,
GPU_ShaderFormat resolved 
)
static

A helper.

◆ setAllowedFramesInFlight()

static bool setAllowedFramesInFlight ( const RenderDevice self,
Uint32  allowed 
)
static

◆ setFramebuffer()

static void setFramebuffer ( RenderDevice self,
Framebuffer framebuffer 
)
static

◆ setSwapchainParameters()

static bool setSwapchainParameters ( const RenderDevice self,
SDL_GPUSwapchainComposition  composition,
SDL_GPUPresentMode  mode 
)
static

◆ setWindow()

static void setWindow ( RenderDevice self,
SDL_Window *  window 
)
static

◆ supportsPresentMode()

static bool supportsPresentMode ( const RenderDevice self,
SDL_GPUPresentMode  mode 
)
static

◆ supportsSwapchainComposition()

static bool supportsSwapchainComposition ( const RenderDevice self,
SDL_GPUSwapchainComposition  composition 
)
static

◆ textureSupportsFormat()

static bool textureSupportsFormat ( const RenderDevice self,
SDL_GPUTextureFormat  format,
SDL_GPUTextureType  type,
SDL_GPUTextureUsageFlags  usage 
)
static

◆ textureSupportsSampleCount()

static bool textureSupportsSampleCount ( const RenderDevice self,
SDL_GPUTextureFormat  format,
SDL_GPUSampleCount  sample_count 
)
static

◆ waitForIdle()

static bool waitForIdle ( const RenderDevice self)
static

◆ waitForSwapchain()

static bool waitForSwapchain ( const RenderDevice self)
static

Variable Documentation

◆ GPU_ShaderFormats

const GPU_ShaderFormat GPU_ShaderFormats[]
static
Initial value:
= {
{ SDL_GPU_SHADERFORMAT_METALLIB, ".metallib", "main0", "main0", "main0" },
{ SDL_GPU_SHADERFORMAT_MSL, ".metal", "main0", "main0", "main0" },
{ SDL_GPU_SHADERFORMAT_DXIL, ".dxil", "main", "main", "main" },
{ SDL_GPU_SHADERFORMAT_SPIRV, ".spv", "main", "main", "main" },
}

The shader formats supported by ObjectivelyGPU.