Foramatting

This commit is contained in:
Zachary Levy
2026-04-19 07:06:42 -07:00
parent c786147720
commit 30b72128b2
3 changed files with 167 additions and 180 deletions

View File

@@ -100,11 +100,11 @@ Shape_Params :: struct #raw_union {
// GPU layout: 64 bytes, std430-compatible. The shader declares this as a storage buffer struct.
Primitive :: struct {
bounds: [4]f32, // 0: min_x, min_y, max_x, max_y (world-space, pre-DPI)
color: Color, // 16: u8x4, unpacked in shader via unpackUnorm4x8
kind_flags: u32, // 20: (kind as u32) | (flags as u32 << 8)
_pad: [2]f32, // 24: alignment to vec4 boundary
params: Shape_Params, // 32: two vec4s of shape params
bounds: [4]f32, // 0: min_x, min_y, max_x, max_y (world-space, pre-DPI)
color: Color, // 16: u8x4, unpacked in shader via unpackUnorm4x8
kind_flags: u32, // 20: (kind as u32) | (flags as u32 << 8)
_pad: [2]f32, // 24: alignment to vec4 boundary
params: Shape_Params, // 32: two vec4s of shape params
}
#assert(size_of(Primitive) == 64)
@@ -279,14 +279,14 @@ create_pipeline_2d_base :: proc(
pipeline.white_texture = sdl.CreateGPUTexture(
device,
sdl.GPUTextureCreateInfo {
type = .D2,
format = .R8G8B8A8_UNORM,
usage = {.SAMPLER},
width = 1,
height = 1,
type = .D2,
format = .R8G8B8A8_UNORM,
usage = {.SAMPLER},
width = 1,
height = 1,
layer_count_or_depth = 1,
num_levels = 1,
sample_count = ._1,
num_levels = 1,
sample_count = ._1,
},
)
if pipeline.white_texture == nil {
@@ -314,9 +314,13 @@ create_pipeline_2d_base :: proc(
mem.copy(white_ptr, &white_pixel, size_of(white_pixel))
sdl.UnmapGPUTransferBuffer(device, white_transfer)
quad_verts := [6]Vertex{
{position = {0, 0}}, {position = {1, 0}}, {position = {0, 1}},
{position = {0, 1}}, {position = {1, 0}}, {position = {1, 1}},
quad_verts := [6]Vertex {
{position = {0, 0}},
{position = {1, 0}},
{position = {0, 1}},
{position = {0, 1}},
{position = {1, 0}},
{position = {1, 1}},
}
quad_transfer := sdl.CreateGPUTransferBuffer(
device,
@@ -353,11 +357,7 @@ create_pipeline_2d_base :: proc(
sdl.UploadToGPUBuffer(
upload_pass,
sdl.GPUTransferBufferLocation{transfer_buffer = quad_transfer},
sdl.GPUBufferRegion{
buffer = pipeline.unit_quad_buffer,
offset = 0,
size = size_of(quad_verts),
},
sdl.GPUBufferRegion{buffer = pipeline.unit_quad_buffer, offset = 0, size = size_of(quad_verts)},
false,
)
@@ -373,9 +373,9 @@ create_pipeline_2d_base :: proc(
pipeline.sampler = sdl.CreateGPUSampler(
device,
sdl.GPUSamplerCreateInfo {
min_filter = .LINEAR,
mag_filter = .LINEAR,
mipmap_mode = .LINEAR,
min_filter = .LINEAR,
mag_filter = .LINEAR,
mipmap_mode = .LINEAR,
address_mode_u = .CLAMP_TO_EDGE,
address_mode_v = .CLAMP_TO_EDGE,
address_mode_w = .CLAMP_TO_EDGE,
@@ -428,11 +428,7 @@ upload :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPass) {
sdl.UploadToGPUBuffer(
pass,
sdl.GPUTransferBufferLocation{transfer_buffer = GLOB.pipeline_2d_base.vertex_buffer.transfer},
sdl.GPUBufferRegion{
buffer = GLOB.pipeline_2d_base.vertex_buffer.gpu,
offset = 0,
size = total_vert_size,
},
sdl.GPUBufferRegion{buffer = GLOB.pipeline_2d_base.vertex_buffer.gpu, offset = 0, size = total_vert_size},
false,
)
}
@@ -459,11 +455,7 @@ upload :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPass) {
sdl.UploadToGPUBuffer(
pass,
sdl.GPUTransferBufferLocation{transfer_buffer = GLOB.pipeline_2d_base.index_buffer.transfer},
sdl.GPUBufferRegion{
buffer = GLOB.pipeline_2d_base.index_buffer.gpu,
offset = 0,
size = index_size,
},
sdl.GPUBufferRegion{buffer = GLOB.pipeline_2d_base.index_buffer.gpu, offset = 0, size = index_size},
false,
)
}
@@ -480,9 +472,7 @@ upload :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPass) {
sdl.GPUBufferUsageFlags{.GRAPHICS_STORAGE_READ},
)
p_array := sdl.MapGPUTransferBuffer(
device, GLOB.pipeline_2d_base.primitive_buffer.transfer, false,
)
p_array := sdl.MapGPUTransferBuffer(device, GLOB.pipeline_2d_base.primitive_buffer.transfer, false)
if p_array == nil {
log.panicf("Failed to map primitive transfer buffer: %s", sdl.GetError())
}
@@ -491,14 +481,8 @@ upload :: proc(device: ^sdl.GPUDevice, pass: ^sdl.GPUCopyPass) {
sdl.UploadToGPUBuffer(
pass,
sdl.GPUTransferBufferLocation{
transfer_buffer = GLOB.pipeline_2d_base.primitive_buffer.transfer,
},
sdl.GPUBufferRegion{
buffer = GLOB.pipeline_2d_base.primitive_buffer.gpu,
offset = 0,
size = prim_size,
},
sdl.GPUTransferBufferLocation{transfer_buffer = GLOB.pipeline_2d_base.primitive_buffer.transfer},
sdl.GPUBufferRegion{buffer = GLOB.pipeline_2d_base.primitive_buffer.gpu, offset = 0, size = prim_size},
false,
)
}
@@ -521,10 +505,8 @@ draw_layer :: proc(
cmd_buffer,
&sdl.GPUColorTargetInfo {
texture = render_texture,
clear_color = sdl.FColor {
clear_color[0], clear_color[1], clear_color[2], clear_color[3],
},
load_op = .CLEAR,
clear_color = sdl.FColor{clear_color[0], clear_color[1], clear_color[2], clear_color[3]},
load_op = .CLEAR,
store_op = .STORE,
},
1,
@@ -540,10 +522,8 @@ draw_layer :: proc(
cmd_buffer,
&sdl.GPUColorTargetInfo {
texture = render_texture,
clear_color = sdl.FColor {
clear_color[0], clear_color[1], clear_color[2], clear_color[3],
},
load_op = GLOB.cleared ? .LOAD : .CLEAR,
clear_color = sdl.FColor{clear_color[0], clear_color[1], clear_color[2], clear_color[3]},
load_op = GLOB.cleared ? .LOAD : .CLEAR,
store_op = .STORE,
},
1,
@@ -571,16 +551,14 @@ draw_layer :: proc(
// Shorthand aliases for frequently-used pipeline resources
main_vbuf := GLOB.pipeline_2d_base.vertex_buffer.gpu
unit_quad := GLOB.pipeline_2d_base.unit_quad_buffer
white := GLOB.pipeline_2d_base.white_texture
sampler := GLOB.pipeline_2d_base.sampler
w := f32(swapchain_w)
h := f32(swapchain_h)
white := GLOB.pipeline_2d_base.white_texture
sampler := GLOB.pipeline_2d_base.sampler
w := f32(swapchain_w)
h := f32(swapchain_h)
// Initial GPU state: tessellated mode, main vertex buffer, no atlas bound yet
push_globals(cmd_buffer, w, h, .Tessellated)
sdl.BindGPUVertexBuffers(
render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1,
)
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1)
current_mode: Draw_Mode = .Tessellated
current_vbuf := main_vbuf
@@ -600,16 +578,15 @@ draw_layer :: proc(
current_mode = .Tessellated
}
if current_vbuf != main_vbuf {
sdl.BindGPUVertexBuffers(
render_pass, 0,
&sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1,
)
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1)
current_vbuf = main_vbuf
}
if current_atlas != white {
sdl.BindGPUFragmentSamplers(
render_pass, 0,
&sdl.GPUTextureSamplerBinding{texture = white, sampler = sampler}, 1,
render_pass,
0,
&sdl.GPUTextureSamplerBinding{texture = white, sampler = sampler},
1,
)
current_atlas = white
}
@@ -621,20 +598,15 @@ draw_layer :: proc(
current_mode = .Tessellated
}
if current_vbuf != main_vbuf {
sdl.BindGPUVertexBuffers(
render_pass, 0,
&sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1,
)
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = main_vbuf, offset = 0}, 1)
current_vbuf = main_vbuf
}
chunk := &GLOB.tmp_text_batches[batch.offset]
if current_atlas != chunk.atlas_texture {
sdl.BindGPUFragmentSamplers(
render_pass, 0,
&sdl.GPUTextureSamplerBinding {
texture = chunk.atlas_texture,
sampler = sampler,
},
render_pass,
0,
&sdl.GPUTextureSamplerBinding{texture = chunk.atlas_texture, sampler = sampler},
1,
)
current_atlas = chunk.atlas_texture
@@ -654,16 +626,15 @@ draw_layer :: proc(
current_mode = .SDF
}
if current_vbuf != unit_quad {
sdl.BindGPUVertexBuffers(
render_pass, 0,
&sdl.GPUBufferBinding{buffer = unit_quad, offset = 0}, 1,
)
sdl.BindGPUVertexBuffers(render_pass, 0, &sdl.GPUBufferBinding{buffer = unit_quad, offset = 0}, 1)
current_vbuf = unit_quad
}
if current_atlas != white {
sdl.BindGPUFragmentSamplers(
render_pass, 0,
&sdl.GPUTextureSamplerBinding{texture = white, sampler = sampler}, 1,
render_pass,
0,
&sdl.GPUTextureSamplerBinding{texture = white, sampler = sampler},
1,
)
current_atlas = white
}