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 CommandBuffer * acquireCommandBuffer (const RenderDevice *self)
static CommandBuffer * beginFrame (RenderDevice *self)
static Fence * endFrameAndFence (RenderDevice *self)
static void endFrame (RenderDevice *self)
static Buffer * createBuffer (RenderDevice *self, const SDL_GPUBufferCreateInfo *info)
static Buffer * createBufferWithConstMem (RenderDevice *self, SDL_GPUBufferUsageFlags usage, const void *mem, Uint32 size)
static Buffer * createBufferWithData (RenderDevice *self, SDL_GPUBufferUsageFlags usage, const Data *data)
static ComputePipeline * createComputePipeline (RenderDevice *self, const SDL_GPUComputePipelineCreateInfo *info)
static Framebuffer * createFramebuffer (RenderDevice *self, const GPU_FramebufferCreateInfo *info)
static GraphicsPipeline * createGraphicsPipeline (RenderDevice *self, const SDL_GPUGraphicsPipelineCreateInfo *info)
static QueryPool * createQueryPool (RenderDevice *self, const SDL_GPUQueryPoolCreateInfo *info)
static Sampler * createSampler (RenderDevice *self, const SDL_GPUSamplerCreateInfo *info)
static Sampler * createSamplerLinearRepeat (RenderDevice *self)
static Sampler * createSamplerLinearClamp (RenderDevice *self)
static Sampler * createSamplerNearestClamp (RenderDevice *self)
static Sampler * createSamplerShadowCompare (RenderDevice *self)
static Shader * createShader (RenderDevice *self, const SDL_GPUShaderCreateInfo *info)
static Texture * createTexture (RenderDevice *self, const SDL_GPUTextureCreateInfo *info, const void *pixels)
static TransferBuffer * createTransferBuffer (RenderDevice *self, const SDL_GPUTransferBufferCreateInfo *info)
static Texture * createTextureFromSurface (RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps)
static Texture * createSolidColorTexture (RenderDevice *self, SDL_GPUTextureType type, Uint32 layerCount, Uint32 rgba)
static SDL_GPUTextureFormat getSwapchainTextureFormat (const RenderDevice *self)
static RenderDevice * init (RenderDevice *self, const char *driverName)
static RenderDevice * initWithWindow (RenderDevice *self, SDL_Window *window, const char *driverName)
static Shader * loadShader (RenderDevice *self, const char *name, const SDL_GPUShaderCreateInfo *info)
static ComputePipeline * loadComputePipeline (RenderDevice *self, const char *name, const SDL_GPUComputePipelineCreateInfo *info)
static GraphicsPipeline * loadGraphicsPipeline (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()

CommandBuffer * acquireCommandBuffer ( const RenderDevice * self)
static

◆ beginFrame()

CommandBuffer * beginFrame ( RenderDevice * self)
static

◆ createBuffer()

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

◆ createBufferWithConstMem()

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

◆ createBufferWithData()

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

◆ createComputePipeline()

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

◆ createFramebuffer()

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

◆ createGraphicsPipeline()

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

◆ createQueryPool()

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

◆ createSampler()

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

◆ createSamplerLinearClamp()

Sampler * createSamplerLinearClamp ( RenderDevice * self)
static

◆ createSamplerLinearRepeat()

Sampler * createSamplerLinearRepeat ( RenderDevice * self)
static

◆ createSamplerNearestClamp()

Sampler * createSamplerNearestClamp ( RenderDevice * self)
static

◆ createSamplerShadowCompare()

Sampler * createSamplerShadowCompare ( RenderDevice * self)
static

◆ createShader()

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

◆ createSolidColorTexture()

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

◆ createTexture()

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

◆ createTextureFromSurface()

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

◆ createTransferBuffer()

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

◆ dealloc()

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

◆ endFrame()

void endFrame ( RenderDevice * self)
static

◆ endFrameAndFence()

Fence * endFrameAndFence ( RenderDevice * self)
static

◆ getSwapchainTextureFormat()

SDL_GPUTextureFormat getSwapchainTextureFormat ( const RenderDevice * self)
static

◆ init()

RenderDevice * init ( RenderDevice * self,
const char * driverName )
static

◆ initialize()

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

◆ initWithWindow()

RenderDevice * initWithWindow ( RenderDevice * self,
SDL_Window * window,
const char * driverName )
static

◆ loadComputePipeline()

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

◆ loadGraphicsPipeline()

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

◆ loadShader()

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

◆ resolveShaderResource()

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

A helper.

◆ setAllowedFramesInFlight()

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

◆ setFramebuffer()

void setFramebuffer ( RenderDevice * self,
Framebuffer * framebuffer )
static

◆ setSwapchainParameters()

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

◆ setWindow()

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

◆ supportsPresentMode()

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

◆ supportsSwapchainComposition()

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

◆ textureSupportsFormat()

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

◆ textureSupportsSampleCount()

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

◆ waitForIdle()

bool waitForIdle ( const RenderDevice * self)
static

◆ waitForSwapchain()

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.