102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
backend_sdl3gpu.c File Reference
#include "backend_sdl3gpu_private.h"
#include "graphics_private.h"
#include <dttr_log.h>
#include <dttr_config.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  graphics_pending_upload
struct  graphics_replay_stats
struct  graphics_replay_state

Macros

#define DRIVER_DISPLAY_VULKAN   "Vulkan"
#define DRIVER_DISPLAY_DIRECT3D12   "Direct3D 12"

Functions

static void cleanup (DTTR_BackendState *state)
static SDL_GPUSampleCount msaa_sample_count_from_config (int value)
static int msaa_sample_count_to_int (SDL_GPUSampleCount value)
static SDL_GPUSampleCount select_msaa_sample_count (DTTR_BackendState *state)
static void destroy_device (DTTR_BackendState *state)
static void release_window_device (DTTR_BackendState *state)
static bool try_create_device_for_driver (DTTR_BackendState *state, const SDL_GPUShaderFormat requested_formats, const char *driver)
static const char * graphics_api_driver_name (DTTR_GraphicsApi api)
static bool create_device (DTTR_BackendState *state)
bool dttr_graphics_sdl3gpu_init (DTTR_BackendState *state)
static bool msaa_enabled (const DTTR_BackendState *state)
static SDL_GPUTransferBuffer * create_upload_buffer (DTTR_BackendState *state, uint32_t bytes)
static void release_upload_pool_slot (DTTR_BackendState *state, int pool_slot)
static int acquire_upload_pool_slot (DTTR_BackendState *state, uint32_t bytes)
static void bind_frame_vertex_buffer (const DTTR_BackendState *state, SDL_GPURenderPass *render_pass)
static void end_render_pass_if_active (DTTR_BackendState *state)
static void release_deferred_texture_destroys (DTTR_BackendState *state)
static void defer_texture_destroy (DTTR_BackendState *state, int texture_index)
static bool upload_texture_data (DTTR_BackendState *state, SDL_GPUCopyPass *copy, SDL_GPUTexture *tex, void *pixels, int width, int height, uint32_t bytes)
static int collect_and_upload_pending (DTTR_BackendState *state, SDL_GPUCopyPass *copy, graphics_pending_upload *pending_uploads, int max_uploads)
static void generate_pending_mipmaps (DTTR_BackendState *state, SDL_GPUCommandBuffer *cmd, const graphics_pending_upload *pending, int pending_count, uint32_t *uploaded_texture_count, uint64_t *uploaded_bytes)
static void upload_pending_textures (DTTR_BackendState *state, SDL_GPUCommandBuffer *cmd)
static void set_default_viewport (const DTTR_BackendState *state)
static bool begin_draw_pass_if_needed (DTTR_BackendState *state)
static void reset_replay_state (graphics_replay_state *replay_state)
static void begin_clear_pass (DTTR_BackendState *state, const DTTR_BatchRecord *rec, graphics_replay_state *replay_state)
static void draw_batch_record (DTTR_BackendState *state, const DTTR_BatchRecord *rec, graphics_replay_state *replay_state, graphics_replay_stats *replay_stats)
static graphics_replay_stats replay_batch_records (DTTR_BackendState *state)
static void begin_frame (DTTR_BackendState *state)
static void end_frame (DTTR_BackendState *state)
static bool ensure_video_texture (DTTR_BackendState *state, int width, int height)
static bool present_video_frame_bgra (DTTR_BackendState *state, const uint8_t *pixels, int width, int height, int stride)
static bool resize (DTTR_BackendState *state, int width, int height)
static const char * driver_display_name (const char *driver)
static const char * get_driver_name (const DTTR_BackendState *state)

Variables

static const DTTR_RendererVtbl renderer

Macro Definition Documentation

◆ DRIVER_DISPLAY_DIRECT3D12

#define DRIVER_DISPLAY_DIRECT3D12   "Direct3D 12"

Definition at line 9 of file backend_sdl3gpu.c.

Referenced by driver_display_name().

◆ DRIVER_DISPLAY_VULKAN

#define DRIVER_DISPLAY_VULKAN   "Vulkan"

Definition at line 8 of file backend_sdl3gpu.c.

Referenced by driver_display_name().

Function Documentation

◆ acquire_upload_pool_slot()

int acquire_upload_pool_slot ( DTTR_BackendState * state,
uint32_t bytes )
static

◆ begin_clear_pass()

◆ begin_draw_pass_if_needed()

bool begin_draw_pass_if_needed ( DTTR_BackendState * state)
static

◆ begin_frame()

◆ bind_frame_vertex_buffer()

void bind_frame_vertex_buffer ( const DTTR_BackendState * state,
SDL_GPURenderPass * render_pass )
static

Definition at line 423 of file backend_sdl3gpu.c.

References state.

Referenced by begin_clear_pass(), and begin_draw_pass_if_needed().

◆ cleanup()

◆ collect_and_upload_pending()

int collect_and_upload_pending ( DTTR_BackendState * state,
SDL_GPUCopyPass * copy,
graphics_pending_upload * pending_uploads,
int max_uploads )
static

◆ create_device()

◆ create_upload_buffer()

SDL_GPUTransferBuffer * create_upload_buffer ( DTTR_BackendState * state,
uint32_t bytes )
static

Definition at line 347 of file backend_sdl3gpu.c.

References state.

Referenced by acquire_upload_pool_slot(), present_video_frame_bgra(), and upload_texture_data().

◆ defer_texture_destroy()

void defer_texture_destroy ( DTTR_BackendState * state,
int texture_index )
static

◆ destroy_device()

void destroy_device ( DTTR_BackendState * state)
static

Definition at line 85 of file backend_sdl3gpu.c.

References NULL, and state.

Referenced by release_window_device(), and try_create_device_for_driver().

◆ draw_batch_record()

◆ driver_display_name()

const char * driver_display_name ( const char * driver)
static

◆ dttr_graphics_sdl3gpu_init()

◆ end_frame()

◆ end_render_pass_if_active()

void end_render_pass_if_active ( DTTR_BackendState * state)
static

Definition at line 438 of file backend_sdl3gpu.c.

References NULL, and state.

Referenced by begin_clear_pass(), and replay_batch_records().

◆ ensure_video_texture()

bool ensure_video_texture ( DTTR_BackendState * state,
int width,
int height )
static

Definition at line 1130 of file backend_sdl3gpu.c.

References NULL, and state.

Referenced by present_video_frame_bgra().

◆ generate_pending_mipmaps()

void generate_pending_mipmaps ( DTTR_BackendState * state,
SDL_GPUCommandBuffer * cmd,
const graphics_pending_upload * pending,
int pending_count,
uint32_t * uploaded_texture_count,
uint64_t * uploaded_bytes )
static

Definition at line 661 of file backend_sdl3gpu.c.

References graphics_pending_upload::bytes, and state.

Referenced by upload_pending_textures().

◆ get_driver_name()

const char * get_driver_name ( const DTTR_BackendState * state)
static

Definition at line 1310 of file backend_sdl3gpu.c.

References driver_display_name(), and state.

◆ graphics_api_driver_name()

const char * graphics_api_driver_name ( DTTR_GraphicsApi api)
static

◆ msaa_enabled()

bool msaa_enabled ( const DTTR_BackendState * state)
static

Definition at line 342 of file backend_sdl3gpu.c.

References NULL, and state.

Referenced by begin_clear_pass(), and begin_draw_pass_if_needed().

◆ msaa_sample_count_from_config()

SDL_GPUSampleCount msaa_sample_count_from_config ( int value)
static

Definition at line 23 of file backend_sdl3gpu.c.

Referenced by select_msaa_sample_count().

◆ msaa_sample_count_to_int()

int msaa_sample_count_to_int ( SDL_GPUSampleCount value)
static

Definition at line 36 of file backend_sdl3gpu.c.

Referenced by dttr_graphics_sdl3gpu_init(), and select_msaa_sample_count().

◆ present_video_frame_bgra()

bool present_video_frame_bgra ( DTTR_BackendState * state,
const uint8_t * pixels,
int width,
int height,
int stride )
static

◆ release_deferred_texture_destroys()

void release_deferred_texture_destroys ( DTTR_BackendState * state)
static

◆ release_upload_pool_slot()

void release_upload_pool_slot ( DTTR_BackendState * state,
int pool_slot )
static

Definition at line 359 of file backend_sdl3gpu.c.

References DTTR_UPLOAD_POOL_SIZE, and state.

Referenced by upload_texture_data().

◆ release_window_device()

void release_window_device ( DTTR_BackendState * state)
static

Definition at line 94 of file backend_sdl3gpu.c.

References destroy_device(), and state.

Referenced by cleanup(), dttr_graphics_sdl3gpu_init(), and try_create_device_for_driver().

◆ replay_batch_records()

◆ reset_replay_state()

◆ resize()

bool resize ( DTTR_BackendState * state,
int width,
int height )
static

Definition at line 1293 of file backend_sdl3gpu.c.

References dttr_graphics_sdl3gpu_resize_render_textures(), and state.

◆ select_msaa_sample_count()

SDL_GPUSampleCount select_msaa_sample_count ( DTTR_BackendState * state)
static

◆ set_default_viewport()

void set_default_viewport ( const DTTR_BackendState * state)
static

Definition at line 725 of file backend_sdl3gpu.c.

References float, and state.

Referenced by begin_clear_pass(), and begin_draw_pass_if_needed().

◆ try_create_device_for_driver()

bool try_create_device_for_driver ( DTTR_BackendState * state,
const SDL_GPUShaderFormat requested_formats,
const char * driver )
static

◆ upload_pending_textures()

void upload_pending_textures ( DTTR_BackendState * state,
SDL_GPUCommandBuffer * cmd )
static

◆ upload_texture_data()

bool upload_texture_data ( DTTR_BackendState * state,
SDL_GPUCopyPass * copy,
SDL_GPUTexture * tex,
void * pixels,
int width,
int height,
uint32_t bytes )
static

Variable Documentation

◆ renderer

const DTTR_RendererVtbl renderer
static
Initial value:
= {
.begin_frame = begin_frame,
.end_frame = end_frame,
.present_video_frame_bgra = present_video_frame_bgra,
.resize = resize,
.cleanup = cleanup,
.get_driver_name = get_driver_name,
.defer_texture_destroy = defer_texture_destroy,
}
static void defer_texture_destroy(DTTR_BackendState *state, int texture_index)
static void begin_frame(DTTR_BackendState *state)
static const char * get_driver_name(const DTTR_BackendState *state)
static void end_frame(DTTR_BackendState *state)
static void cleanup(DTTR_BackendState *state)
static bool present_video_frame_bgra(DTTR_BackendState *state, const uint8_t *pixels, int width, int height, int stride)
static bool resize(DTTR_BackendState *state, int width, int height)

Definition at line 20 of file backend_sdl3gpu.c.