11 const SDL_GPUBufferCreateInfo vbuf_info = {
12 .usage = SDL_GPU_BUFFERUSAGE_VERTEX,
13 .size = frame_buffer_size,
16 state->vertex_buffer = SDL_CreateGPUBuffer(
state->device, &vbuf_info);
18 const SDL_GPUTransferBufferCreateInfo tbuf_info = {
19 .usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
20 .size = frame_buffer_size,
23 state->transfer_buffer = SDL_CreateGPUTransferBuffer(
state->device, &tbuf_info);
28 for (
int cu = 0; cu < 2; cu++) {
29 for (
int cv = 0; cv < 2; cv++) {
30 const SDL_GPUSamplerCreateInfo si = {
31 .min_filter = SDL_GPU_FILTER_LINEAR,
32 .mag_filter = SDL_GPU_FILTER_LINEAR,
33 .mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR,
34 .address_mode_u = cu ? SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE
35 : SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
36 .address_mode_v = cv ? SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE
37 : SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
38 .enable_anisotropy =
true,
42 state->samplers[cu * 2 + cv] = SDL_CreateGPUSampler(
state->device, &si);
49 const SDL_GPUTextureFormat swapchain_fmt = SDL_GetGPUSwapchainTextureFormat(
53 const SDL_GPUSampleCount sample_count =
state->msaa_sample_count;
55 const SDL_GPUTextureCreateInfo rt_info = {
56 .type = SDL_GPU_TEXTURETYPE_2D,
57 .format = swapchain_fmt,
58 .usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER,
59 .width =
state->width,
60 .height =
state->height,
61 .layer_count_or_depth = 1,
63 .sample_count = SDL_GPU_SAMPLECOUNT_1,
66 state->render_target = SDL_CreateGPUTexture(
state->device, &rt_info);
70 if (sample_count != SDL_GPU_SAMPLECOUNT_1) {
71 const SDL_GPUTextureCreateInfo msaa_rt_info = {
72 .type = SDL_GPU_TEXTURETYPE_2D,
73 .format = swapchain_fmt,
74 .usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET,
75 .width =
state->width,
76 .height =
state->height,
77 .layer_count_or_depth = 1,
79 .sample_count = sample_count,
82 state->msaa_render_target = SDL_CreateGPUTexture(
state->device, &msaa_rt_info);
85 const SDL_GPUTextureCreateInfo depth_tex_info = {
86 .type = SDL_GPU_TEXTURETYPE_2D,
87 .format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT,
88 .usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET,
89 .width =
state->width,
90 .height =
state->height,
91 .layer_count_or_depth = 1,
93 .sample_count = sample_count,
96 state->depth_texture = SDL_CreateGPUTexture(
state->device, &depth_tex_info);
101 const SDL_GPUTextureCreateInfo dummy_tex_info = {
102 .type = SDL_GPU_TEXTURETYPE_2D,
103 .format = SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM,
104 .usage = SDL_GPU_TEXTUREUSAGE_SAMPLER,
107 .layer_count_or_depth = 1,
111 state->dummy_texture = SDL_CreateGPUTexture(
state->device, &dummy_tex_info);
116 const uint32_t white_pixel = 0xFFFFFFFF;
117 const uint32_t buf_size =
sizeof(white_pixel);
119 const SDL_GPUTransferBufferCreateInfo tbuf_info = {
120 .usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
124 SDL_GPUTransferBuffer *tbuf = SDL_CreateGPUTransferBuffer(
state->device, &tbuf_info);
130 void *mapped = SDL_MapGPUTransferBuffer(
state->device, tbuf,
false);
133 SDL_ReleaseGPUTransferBuffer(
state->device, tbuf);
137 memcpy(mapped, &white_pixel, buf_size);
138 SDL_UnmapGPUTransferBuffer(
state->device, tbuf);
140 SDL_GPUCommandBuffer *cmd = SDL_AcquireGPUCommandBuffer(
state->device);
143 SDL_ReleaseGPUTransferBuffer(
state->device, tbuf);
147 SDL_GPUCopyPass *copy = SDL_BeginGPUCopyPass(cmd);
150 const SDL_GPUTextureTransferInfo
src = {
151 .transfer_buffer = tbuf,
155 const SDL_GPUTextureRegion
dst = {
156 .texture =
state->dummy_texture,
162 SDL_UploadToGPUTexture(copy, &
src, &
dst,
false);
163 SDL_EndGPUCopyPass(copy);
166 SDL_SubmitGPUCommandBuffer(cmd);
167 SDL_ReleaseGPUTransferBuffer(
state->device, tbuf);