rename gpu_cmd_store -> gpu_cmd_list

This commit is contained in:
jacob 2025-06-07 20:26:20 -05:00
parent 74609cdb3c
commit df4eb24fe3
6 changed files with 243 additions and 243 deletions

View File

@ -28,19 +28,19 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
* View
* ========================== */
void draw_set_view(struct gpu_handle store, struct xform xf)
void draw_set_view(struct gpu_handle cmd_list, struct xform xf)
{
struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_VIEW;
cmd.view.xf = xf;
gpu_push_cmd(store, cmd);
gpu_push_cmd(cmd_list, cmd);
}
/* ========================== *
* Texture
* ========================== */
void draw_texture(struct gpu_handle store, struct draw_texture_params params)
void draw_texture(struct gpu_handle cmd_list, struct draw_texture_params params)
{
struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_TEXTURE;
@ -50,25 +50,25 @@ void draw_texture(struct gpu_handle store, struct draw_texture_params params)
cmd.texture.clip = params.clip;
cmd.texture.tint = params.tint;
cmd.texture.emittance = params.emittance;
gpu_push_cmd(store, cmd);
gpu_push_cmd(cmd_list, cmd);
}
/* ========================== *
* Fill shapes
* ========================== */
void draw_poly_ex(struct gpu_handle store, struct v2_array vertices, struct gpu_indices indices, u32 color)
void draw_poly_ex(struct gpu_handle cmd_list, struct v2_array vertices, struct gpu_indices indices, u32 color)
{
struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_MESH;
cmd.mesh.vertices = vertices;
cmd.mesh.indices = indices;
cmd.mesh.color = color;
gpu_push_cmd(store, cmd);
gpu_push_cmd(cmd_list, cmd);
}
/* Draws a filled polygon using triangles in a fan pattern */
void draw_poly(struct gpu_handle store, struct v2_array vertices, u32 color)
void draw_poly(struct gpu_handle cmd_list, struct v2_array vertices, u32 color)
{
if (vertices.count >= 3) {
struct temp_arena scratch = scratch_begin_no_conflict();
@ -88,13 +88,13 @@ void draw_poly(struct gpu_handle store, struct v2_array vertices, u32 color)
indices.indices[tri_offset + 2] = (i + 2);
}
draw_poly_ex(store, vertices, indices, color);
draw_poly_ex(cmd_list, vertices, indices, color);
scratch_end(scratch);
}
}
void draw_circle(struct gpu_handle store, struct v2 pos, f32 radius, u32 color, u32 detail)
void draw_circle(struct gpu_handle cmd_list, struct v2 pos, f32 radius, u32 color, u32 detail)
{
struct temp_arena scratch = scratch_begin_no_conflict();
@ -111,12 +111,12 @@ void draw_circle(struct gpu_handle store, struct v2 pos, f32 radius, u32 color,
.points = points,
.count = detail
};
draw_poly(store, vertices, color);
draw_poly(cmd_list, vertices, color);
scratch_end(scratch);
}
void draw_quad(struct gpu_handle store, struct quad quad, u32 color)
void draw_quad(struct gpu_handle cmd_list, struct quad quad, u32 color)
{
LOCAL_PERSIST u16 indices_array[6] = {
0, 1, 2,
@ -124,57 +124,57 @@ void draw_quad(struct gpu_handle store, struct quad quad, u32 color)
};
struct v2_array vertices = { .count = 4, .points = quad.e };
struct gpu_indices indices = { .count = 6, .indices = indices_array };
draw_poly_ex(store, vertices, indices, color);
draw_poly_ex(cmd_list, vertices, indices, color);
}
/* ========================== *
* Line shapes
* ========================== */
void draw_gradient_line(struct gpu_handle store, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color)
void draw_gradient_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color)
{
#if 0
struct quad quad = quad_from_line(start, end, thickness);
draw_texture(store, DRAW_TEXTURE_PARAMS(.texture = G.solid_white_texture, .tint0 = start_color, .tint1 = end_color, .quad = quad));
draw_texture(cmd_list, DRAW_TEXTURE_PARAMS(.texture = G.solid_white_texture, .tint0 = start_color, .tint1 = end_color, .quad = quad));
#else
/* Placeholder */
(UNUSED)end_color;
struct quad quad = quad_from_line(start, end, thickness);
draw_quad(store, quad, start_color);
draw_quad(cmd_list, quad, start_color);
#endif
}
void draw_line(struct gpu_handle store, struct v2 start, struct v2 end, f32 thickness, u32 color)
void draw_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, u32 color)
{
struct quad quad = quad_from_line(start, end, thickness);
draw_quad(store, quad, color);
draw_quad(cmd_list, quad, color);
}
void draw_ray(struct gpu_handle store, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
void draw_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f32 thickness, u32 color)
{
struct quad quad = quad_from_ray(pos, rel, thickness);
draw_quad(store, quad, color);
draw_quad(cmd_list, quad, color);
}
void draw_poly_line(struct gpu_handle store, struct v2_array points, b32 loop, f32 thickness, u32 color)
void draw_poly_line(struct gpu_handle cmd_list, struct v2_array points, b32 loop, f32 thickness, u32 color)
{
if (points.count >= 2) {
for (u64 i = 1; i < points.count; ++i) {
struct v2 p1 = points.points[i - 1];
struct v2 p2 = points.points[i];
struct quad q = quad_from_line(p1, p2, thickness);
draw_quad(store, q, color);
draw_quad(cmd_list, q, color);
}
if (loop && points.count > 2) {
struct v2 p1 = points.points[points.count - 1];
struct v2 p2 = points.points[0];
struct quad q = quad_from_line(p1, p2, thickness);
draw_quad(store, q, color);
draw_quad(cmd_list, q, color);
}
}
}
void draw_circle_line(struct gpu_handle store, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
void draw_circle_line(struct gpu_handle cmd_list, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail)
{
struct temp_arena scratch = scratch_begin_no_conflict();
@ -191,19 +191,19 @@ void draw_circle_line(struct gpu_handle store, struct v2 pos, f32 radius, f32 th
.points = points,
.count = detail
};
draw_poly_line(store, a, true, thickness, color);
draw_poly_line(cmd_list, a, true, thickness, color);
scratch_end(scratch);
}
void draw_quad_line(struct gpu_handle store, struct quad quad, f32 thickness, u32 color)
void draw_quad_line(struct gpu_handle cmd_list, struct quad quad, f32 thickness, u32 color)
{
struct v2 points[] = { quad.p0, quad.p1, quad.p2, quad.p3 };
struct v2_array a = { .points = points, .count = ARRAY_COUNT(points) };
draw_poly_line(store, a, true, thickness, color);
draw_poly_line(cmd_list, a, true, thickness, color);
}
void draw_arrow_line(struct gpu_handle store, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color)
void draw_arrow_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color)
{
const f32 head_width_ratio = 0.5f; /* Width of arrowhead relative to its length */
@ -227,19 +227,19 @@ void draw_arrow_line(struct gpu_handle store, struct v2 start, struct v2 end, f3
.points = head_points,
.count = ARRAY_COUNT(head_points)
};
draw_poly(store, head_points_v2_array, color);
draw_poly(cmd_list, head_points_v2_array, color);
struct quad line_quad = quad_from_line(start, head_start, thickness);
draw_quad(store, line_quad, color);
draw_quad(cmd_list, line_quad, color);
}
void draw_arrow_ray(struct gpu_handle store, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color)
void draw_arrow_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color)
{
struct v2 end = v2_add(pos, rel);
draw_arrow_line(store, pos, end, thickness, arrowhead_height, color);
draw_arrow_line(cmd_list, pos, end, thickness, arrowhead_height, color);
}
void draw_collider_line(struct gpu_handle store, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
void draw_collider_line(struct gpu_handle cmd_list, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
{
struct temp_arena scratch = scratch_begin_no_conflict();
@ -253,7 +253,7 @@ void draw_collider_line(struct gpu_handle store, struct xform draw_xf, struct co
}
struct v2_array poly = { .points = points, .count = detail };
draw_poly_line(store, poly, true, thickness, color);
draw_poly_line(cmd_list, poly, true, thickness, color);
scratch_end(scratch);
}
@ -262,7 +262,7 @@ void draw_collider_line(struct gpu_handle store, struct xform draw_xf, struct co
* Grid
* ========================== */
void draw_grid(struct gpu_handle store, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset)
void draw_grid(struct gpu_handle cmd_list, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset)
{
struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_GRID;
@ -275,7 +275,7 @@ void draw_grid(struct gpu_handle store, struct xform xf, u32 bg0_color, u32 bg1_
cmd.grid.line_thickness = thickness;
cmd.grid.line_spacing = spacing;
cmd.grid.offset = offset;
gpu_push_cmd(store, cmd);
gpu_push_cmd(cmd_list, cmd);
}
/* ========================== *
@ -283,7 +283,7 @@ void draw_grid(struct gpu_handle store, struct xform xf, u32 bg0_color, u32 bg1_
* ========================== */
/* Returns the rect of the text area */
struct rect draw_text(struct gpu_handle store, struct draw_text_params params)
struct rect draw_text(struct gpu_handle cmd_list, struct draw_text_params params)
{
struct temp_arena scratch = scratch_begin_no_conflict();
@ -451,7 +451,7 @@ struct rect draw_text(struct gpu_handle store, struct draw_text_params params)
struct v2 pos = V2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y);
struct v2 size = V2(tg->width, tg->height);
struct xform xf = xform_from_rect(RECT_FROM_V2(pos, size));
draw_texture(store, DRAW_TEXTURE_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
draw_texture(cmd_list, DRAW_TEXTURE_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip));
draw_pos.x += tg->advance;
}

View File

@ -14,7 +14,7 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
* View
* ========================== */
void draw_set_view(struct gpu_handle store, struct xform xf);
void draw_set_view(struct gpu_handle cmd_list, struct xform xf);
/* ========================== *
* Texture
@ -35,47 +35,47 @@ struct draw_texture_params {
f32 emittance;
};
void draw_texture(struct gpu_handle store, struct draw_texture_params params);
void draw_texture(struct gpu_handle cmd_list, struct draw_texture_params params);
/* ========================== *
* Fill shapes
* ========================== */
void draw_poly_ex(struct gpu_handle store, struct v2_array vertices, struct gpu_indices indices, u32 color);
void draw_poly_ex(struct gpu_handle cmd_list, struct v2_array vertices, struct gpu_indices indices, u32 color);
void draw_poly(struct gpu_handle store, struct v2_array points, u32 color);
void draw_poly(struct gpu_handle cmd_list, struct v2_array points, u32 color);
void draw_circle(struct gpu_handle store, struct v2 pos, f32 radius, u32 color, u32 detail);
void draw_circle(struct gpu_handle cmd_list, struct v2 pos, f32 radius, u32 color, u32 detail);
void draw_quad(struct gpu_handle store, struct quad quad, u32 color);
void draw_quad(struct gpu_handle cmd_list, struct quad quad, u32 color);
/* ========================== *
* Line shapes
* ========================== */
void draw_gradient_line(struct gpu_handle store, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
void draw_gradient_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color);
void draw_line(struct gpu_handle store, struct v2 start, struct v2 end, f32 thickness, u32 color);
void draw_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, u32 color);
void draw_ray(struct gpu_handle store, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
void draw_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f32 thickness, u32 color);
void draw_poly_line(struct gpu_handle store, struct v2_array points, b32 loop, f32 thickness, u32 color);
void draw_poly_line(struct gpu_handle cmd_list, struct v2_array points, b32 loop, f32 thickness, u32 color);
void draw_circle_line(struct gpu_handle store, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
void draw_circle_line(struct gpu_handle cmd_list, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail);
void draw_quad_line(struct gpu_handle store, struct quad quad, f32 thickness, u32 color);
void draw_quad_line(struct gpu_handle cmd_list, struct quad quad, f32 thickness, u32 color);
void draw_arrow_line(struct gpu_handle store, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color);
void draw_arrow_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, f32 arrowhead_height, u32 color);
void draw_arrow_ray(struct gpu_handle store, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
void draw_arrow_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
void draw_collider_line(struct gpu_handle store, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
void draw_collider_line(struct gpu_handle cmd_list, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
/* ========================== *
* Grid
* ========================== */
void draw_grid(struct gpu_handle store, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset);
void draw_grid(struct gpu_handle cmd_list, struct xform xf, u32 bg0_color, u32 bg1_color, u32 line_color, u32 x_color, u32 y_color, f32 thickness, f32 spacing, struct v2 offset);
/* ========================== *
* Text
@ -123,6 +123,6 @@ struct draw_text_params {
struct string str;
};
struct rect draw_text(struct gpu_handle store, struct draw_text_params params);
struct rect draw_text(struct gpu_handle cmd_list, struct draw_text_params params);
#endif

View File

@ -27,6 +27,11 @@ struct gpu_handle {
};
};
struct gpu_handle_array {
u64 count;
struct gpu_handle **handles;
};
void gpu_release(struct gpu_handle handle);
/* ========================== *
@ -108,23 +113,18 @@ struct gpu_cmd_params {
};
};
struct gpu_handle gpu_cmd_store_alloc(void);
struct gpu_handle gpu_cmd_list_alloc(void);
void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params);
void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params);
void gpu_submit_cmds(struct gpu_handle gpu_cmd_store);
void gpu_submit_cmds(struct gpu_handle gpu_cmd_list);
/* ========================== *
* Dispatch
* ========================== */
struct gpu_dispatch_cmds_array {
u64 count;
struct gpu_handle **stores;
};
struct gpu_dispatch_params {
struct gpu_dispatch_cmds_array cmds_array;
struct gpu_handle_array cmd_lists;
struct gpu_handle draw_target;
struct rect draw_target_viewport;
};

View File

@ -60,7 +60,7 @@ enum dx11_shader_kind {
enum dx11_handle_kind {
DX11_HANDLE_KIND_NONE,
DX11_HANDLE_KIND_TEXTURE,
DX11_HANDLE_KIND_CMD_STORE,
DX11_HANDLE_KIND_CMD_LIST,
DX11_HANDLE_KIND_DISPATCH_STATE,
NUM_DX11_HANDLE_KINDS
@ -149,7 +149,7 @@ struct dx11_cmd {
struct dx11_cmd *next;
};
struct dx11_cmd_store {
struct dx11_cmd_list {
struct dx11_handle_header header;
/* Commands w/ data still in cpu memory */
@ -178,7 +178,7 @@ struct dx11_cmd_store {
} test;
} buffers;
struct dx11_cmd_store *next_free;
struct dx11_cmd_list *next_free;
};
struct dx11_texture {
@ -236,10 +236,10 @@ GLOBAL struct {
struct arena buffers_arena;
struct dx11_buffer *first_free_buffer;
/* Cmd store pool */
struct sys_mutex cmd_stores_mutex;
struct arena cmd_stores_arena;
struct dx11_cmd_store *first_free_cmd_store;
/* Cmd list pool */
struct sys_mutex handles_mutex;
struct arena handles_arena;
struct dx11_cmd_list *first_free_cmd_list;
/* Dispatch state pool */
struct sys_mutex dispatch_states_mutex;
@ -284,9 +284,9 @@ struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, str
G.buffers_mutex = sys_mutex_alloc();
G.buffers_arena = arena_alloc(GIGABYTE(64));
/* Initialize cmd store pool */
G.cmd_stores_mutex = sys_mutex_alloc();
G.cmd_stores_arena = arena_alloc(GIGABYTE(64));
/* Initialize cmd list pool */
G.handles_mutex = sys_mutex_alloc();
G.handles_arena = arena_alloc(GIGABYTE(64));
/* Initialize dispatch state pool */
G.dispatch_states_mutex = sys_mutex_alloc();
@ -560,7 +560,7 @@ void gpu_release(struct gpu_handle handle)
dx11_texture_release((struct dx11_texture *)header);
} break;
case DX11_HANDLE_KIND_CMD_STORE:
case DX11_HANDLE_KIND_CMD_LIST:
{
/* TODO */
ASSERT(false);
@ -1274,41 +1274,41 @@ INTERNAL void dx11_buffer_submit(struct dx11_buffer *buffer)
}
/* ========================== *
* Cmd store
* Cmd list
* ========================== */
struct gpu_handle gpu_cmd_store_alloc(void)
struct gpu_handle gpu_cmd_list_alloc(void)
{
__prof;
struct dx11_cmd_store *store = NULL;
struct dx11_cmd_list *list = NULL;
{
struct arena cpu_cmds_arena = ZI;
struct arena gpu_cmds_arena = ZI;
{
struct sys_lock lock = sys_mutex_lock_e(&G.cmd_stores_mutex);
if (G.first_free_cmd_store) {
store = G.first_free_cmd_store;
G.first_free_cmd_store = store->next_free;
cpu_cmds_arena = store->cpu_cmds_arena;
gpu_cmds_arena = store->gpu_cmds_arena;
struct sys_lock lock = sys_mutex_lock_e(&G.handles_mutex);
if (G.first_free_cmd_list) {
list = G.first_free_cmd_list;
G.first_free_cmd_list = list->next_free;
cpu_cmds_arena = list->cpu_cmds_arena;
gpu_cmds_arena = list->gpu_cmds_arena;
} else {
store = arena_push_no_zero(&G.cmd_stores_arena, struct dx11_cmd_store);
list = arena_push_no_zero(&G.handles_arena, struct dx11_cmd_list);
}
sys_mutex_unlock(&lock);
}
MEMZERO_STRUCT(store);
MEMZERO_STRUCT(list);
if (!cpu_cmds_arena.base) {
cpu_cmds_arena = arena_alloc(GIGABYTE(64));
}
if (!gpu_cmds_arena.base) {
gpu_cmds_arena = arena_alloc(GIGABYTE(64));
}
store->cpu_cmds_arena = cpu_cmds_arena;
store->gpu_cmds_arena = gpu_cmds_arena;
arena_reset(&store->cpu_cmds_arena);
arena_reset(&store->gpu_cmds_arena);
list->cpu_cmds_arena = cpu_cmds_arena;
list->gpu_cmds_arena = gpu_cmds_arena;
arena_reset(&list->cpu_cmds_arena);
arena_reset(&list->gpu_cmds_arena);
}
store->header.kind = DX11_HANDLE_KIND_CMD_STORE;
list->header.kind = DX11_HANDLE_KIND_CMD_LIST;
/* Desc template */
const D3D11_BUFFER_DESC structured_buffer_desc = {
@ -1333,41 +1333,41 @@ struct gpu_handle gpu_cmd_store_alloc(void)
idesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
idesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
store->buffers.mesh.vertex_buffer = dx11_buffer_alloc(vdesc, NULL);
store->buffers.mesh.index_buffer = dx11_buffer_alloc(idesc, NULL);
list->buffers.mesh.vertex_buffer = dx11_buffer_alloc(vdesc, NULL);
list->buffers.mesh.index_buffer = dx11_buffer_alloc(idesc, NULL);
}
/* Texture buffers */
{
struct D3D11_BUFFER_DESC desc = structured_buffer_desc;
desc.StructureByteStride = sizeof(struct dx11_texture_instance);
store->buffers.texture.instance_buffer = dx11_buffer_alloc(desc, NULL);
list->buffers.texture.instance_buffer = dx11_buffer_alloc(desc, NULL);
}
/* Grid buffers */
{
struct D3D11_BUFFER_DESC desc = structured_buffer_desc;
desc.StructureByteStride = sizeof(struct dx11_grid_instance);
store->buffers.grid.instance_buffer = dx11_buffer_alloc(desc, NULL);
list->buffers.grid.instance_buffer = dx11_buffer_alloc(desc, NULL);
}
/* Test buffers */
{
struct D3D11_BUFFER_DESC desc = structured_buffer_desc;
desc.StructureByteStride = sizeof(struct dx11_test_instance);
store->buffers.test.instance_buffer = dx11_buffer_alloc(desc, NULL);
list->buffers.test.instance_buffer = dx11_buffer_alloc(desc, NULL);
}
}
struct gpu_handle res = ZI;
res.v = (u64)store;
res.v = (u64)list;
return res;
}
void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params)
{
__prof;
struct dx11_cmd_store *store = (struct dx11_cmd_store *)gpu_cmd_store.v;
struct dx11_cmd_list *list = (struct dx11_cmd_list *)gpu_cmd_list.v;
switch (params.kind) {
default:
@ -1378,20 +1378,20 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
case GPU_CMD_KIND_DRAW_VIEW:
{
struct dx11_cmd *cmd = arena_push(&store->cpu_cmds_arena, struct dx11_cmd);
struct dx11_cmd *cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd);
cmd->kind = params.kind;
cmd->view.xf = params.view.xf;
if (store->cpu_last_cmd) {
store->cpu_last_cmd->next = cmd;
if (list->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd;
} else {
store->cpu_first_cmd = cmd;
list->cpu_first_cmd = cmd;
}
store->cpu_last_cmd = cmd;
list->cpu_last_cmd = cmd;
} break;
case GPU_CMD_KIND_DRAW_MESH:
{
struct dx11_cmd *cmd = store->cpu_last_cmd;
struct dx11_cmd *cmd = list->cpu_last_cmd;
if (cmd && cmd->kind != params.kind) {
/* Cannot batch */
cmd = NULL;
@ -1400,23 +1400,23 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
/* Start new cmd */
if (!cmd) {
/* TODO: Better count method */
cmd = arena_push(&store->cpu_cmds_arena, struct dx11_cmd);
cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd);
cmd->kind = params.kind;
cmd->mesh.vertex_offset = (store->buffers.mesh.vertex_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_mesh_vertex));
cmd->mesh.index_offset = (store->buffers.mesh.index_buffer->cpu_buffer_arena.pos / sizeof(u16));
if (store->cpu_last_cmd) {
store->cpu_last_cmd->next = cmd;
cmd->mesh.vertex_offset = (list->buffers.mesh.vertex_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_mesh_vertex));
cmd->mesh.index_offset = (list->buffers.mesh.index_buffer->cpu_buffer_arena.pos / sizeof(u16));
if (list->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd;
} else {
store->cpu_first_cmd = cmd;
list->cpu_first_cmd = cmd;
}
store->cpu_last_cmd = cmd;
list->cpu_last_cmd = cmd;
}
/* Push vertices */
u64 vertex_count = params.mesh.vertices.count;
u64 start_index = cmd->mesh.vertex_count;
cmd->mesh.vertex_count += vertex_count;
struct dx11_mesh_vertex *verts = dx11_buffer_push(store->buffers.mesh.vertex_buffer, sizeof(struct dx11_mesh_vertex) * vertex_count);
struct dx11_mesh_vertex *verts = dx11_buffer_push(list->buffers.mesh.vertex_buffer, sizeof(struct dx11_mesh_vertex) * vertex_count);
for (u64 i = 0; i < vertex_count; ++i) {
struct dx11_mesh_vertex *vert = &verts[i];
vert->pos = params.mesh.vertices.points[i];
@ -1425,7 +1425,7 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
/* Push indices */
u64 index_count = params.mesh.indices.count;
u16 *indices = dx11_buffer_push(store->buffers.mesh.index_buffer, sizeof(u16) * index_count);
u16 *indices = dx11_buffer_push(list->buffers.mesh.index_buffer, sizeof(u16) * index_count);
cmd->mesh.index_count += index_count;
for (u64 i = 0; i < index_count; ++i) {
indices[i] = start_index + params.mesh.indices.indices[i];
@ -1434,7 +1434,7 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
case GPU_CMD_KIND_DRAW_TEXTURE:
{
struct dx11_cmd *cmd = store->cpu_last_cmd;
struct dx11_cmd *cmd = list->cpu_last_cmd;
if (cmd &&
((cmd->kind != params.kind) ||
(cmd->texture.sprite.hash != params.texture.sprite.hash) ||
@ -1446,22 +1446,22 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
/* Start new cmd */
if (!cmd) {
/* TODO: Better count method */
cmd = arena_push(&store->cpu_cmds_arena, struct dx11_cmd);
cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd);
cmd->kind = params.kind;
cmd->texture.sprite = params.texture.sprite;
cmd->texture.texture = params.texture.texture;
cmd->texture.instance_offset = (store->buffers.texture.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_texture_instance));
if (store->cpu_last_cmd) {
store->cpu_last_cmd->next = cmd;
cmd->texture.instance_offset = (list->buffers.texture.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_texture_instance));
if (list->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd;
} else {
store->cpu_first_cmd = cmd;
list->cpu_first_cmd = cmd;
}
store->cpu_last_cmd = cmd;
list->cpu_last_cmd = cmd;
}
/* Push instance data */
++cmd->texture.instance_count;
struct dx11_texture_instance *instance = dx11_buffer_push(store->buffers.texture.instance_buffer, sizeof(struct dx11_texture_instance));
struct dx11_texture_instance *instance = dx11_buffer_push(list->buffers.texture.instance_buffer, sizeof(struct dx11_texture_instance));
instance->xf = params.texture.xf;
instance->uv0 = params.texture.clip.p0;
instance->uv1 = params.texture.clip.p1;
@ -1471,7 +1471,7 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
case GPU_CMD_KIND_DRAW_GRID:
{
struct dx11_cmd *cmd = store->cpu_last_cmd;
struct dx11_cmd *cmd = list->cpu_last_cmd;
if (cmd && cmd->kind != params.kind) {
/* Cannot batch */
cmd = NULL;
@ -1480,20 +1480,20 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
/* Start new cmd */
if (!cmd) {
/* TODO: Better count method */
cmd = arena_push(&store->cpu_cmds_arena, struct dx11_cmd);
cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd);
cmd->kind = params.kind;
cmd->grid.instance_offset = (store->buffers.grid.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_grid_instance));
if (store->cpu_last_cmd) {
store->cpu_last_cmd->next = cmd;
cmd->grid.instance_offset = (list->buffers.grid.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_grid_instance));
if (list->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd;
} else {
store->cpu_first_cmd = cmd;
list->cpu_first_cmd = cmd;
}
store->cpu_last_cmd = cmd;
list->cpu_last_cmd = cmd;
}
/* Push instance data */
++cmd->grid.instance_count;
struct dx11_grid_instance *instance = dx11_buffer_push(store->buffers.grid.instance_buffer, sizeof(struct dx11_grid_instance));
struct dx11_grid_instance *instance = dx11_buffer_push(list->buffers.grid.instance_buffer, sizeof(struct dx11_grid_instance));
instance->xf = params.grid.xf;
instance->line_thickness = params.grid.line_thickness;
instance->line_spacing = params.grid.line_spacing;
@ -1507,53 +1507,53 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
case GPU_CMD_KIND_TEST:
{
struct dx11_cmd *cmd = arena_push(&store->cpu_cmds_arena, struct dx11_cmd);
struct dx11_cmd *cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd);
cmd->kind = params.kind;
cmd->test.instance_offset = (store->buffers.test.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_test_instance));
if (store->cpu_last_cmd) {
store->cpu_last_cmd->next = cmd;
cmd->test.instance_offset = (list->buffers.test.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_test_instance));
if (list->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd;
} else {
store->cpu_first_cmd = cmd;
list->cpu_first_cmd = cmd;
}
store->cpu_last_cmd = cmd;
list->cpu_last_cmd = cmd;
/* Push instance data */
++cmd->test.instance_count;
struct dx11_test_instance *instance = dx11_buffer_push(store->buffers.test.instance_buffer, sizeof(struct dx11_test_instance));
struct dx11_test_instance *instance = dx11_buffer_push(list->buffers.test.instance_buffer, sizeof(struct dx11_test_instance));
instance->xf = params.test.xf;
} break;
}
}
void gpu_submit_cmds(struct gpu_handle gpu_cmd_store)
void gpu_submit_cmds(struct gpu_handle gpu_cmd_list)
{
__prof;
struct dx11_cmd_store *store = (struct dx11_cmd_store *)gpu_cmd_store.v;
struct dx11_cmd_list *list = (struct dx11_cmd_list *)gpu_cmd_list.v;
/* Swap cmd lists */
struct arena swp_arena = store->gpu_cmds_arena;
store->gpu_cmds_arena = store->cpu_cmds_arena;
store->gpu_first_cmd = store->cpu_first_cmd;
store->gpu_last_cmd = store->cpu_last_cmd;
struct arena swp_arena = list->gpu_cmds_arena;
list->gpu_cmds_arena = list->cpu_cmds_arena;
list->gpu_first_cmd = list->cpu_first_cmd;
list->gpu_last_cmd = list->cpu_last_cmd;
/* Reset cpu cmds */
store->cpu_cmds_arena = swp_arena;
store->cpu_first_cmd = NULL;
store->cpu_last_cmd = NULL;
arena_reset(&store->cpu_cmds_arena);
list->cpu_cmds_arena = swp_arena;
list->cpu_first_cmd = NULL;
list->cpu_last_cmd = NULL;
arena_reset(&list->cpu_cmds_arena);
/* Submit mesh buffers */
dx11_buffer_submit(store->buffers.mesh.vertex_buffer);
dx11_buffer_submit(store->buffers.mesh.index_buffer);
dx11_buffer_submit(list->buffers.mesh.vertex_buffer);
dx11_buffer_submit(list->buffers.mesh.index_buffer);
/* Submit texture buffers */
dx11_buffer_submit(store->buffers.texture.instance_buffer);
dx11_buffer_submit(list->buffers.texture.instance_buffer);
/* Submit grid buffers */
dx11_buffer_submit(store->buffers.grid.instance_buffer);
dx11_buffer_submit(list->buffers.grid.instance_buffer);
/* Submit test buffers */
dx11_buffer_submit(store->buffers.test.instance_buffer);
dx11_buffer_submit(list->buffers.test.instance_buffer);
}
/* ========================== *
@ -1702,9 +1702,9 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
{
__profscope(Regular pass);
__profscope_dx11(G.profiling_ctx, Regular pass, RGB_F(0.2, 0.5, 0.5));
for (u64 cmd_stores_array_index = 0; cmd_stores_array_index < params.cmds_array.count; ++cmd_stores_array_index) {
struct dx11_cmd_store *store = (struct dx11_cmd_store *)params.cmds_array.stores[cmd_stores_array_index]->v;
for (struct dx11_cmd *cmd = store->gpu_first_cmd; cmd; cmd = cmd->next) {
for (u64 handles_array_index = 0; handles_array_index < params.cmd_lists.count; ++handles_array_index) {
struct dx11_cmd_list *list = (struct dx11_cmd_list *)params.cmd_lists.handles[handles_array_index]->v;
for (struct dx11_cmd *cmd = list->gpu_first_cmd; cmd; cmd = cmd->next) {
enum gpu_cmd_kind cmd_kind = cmd->kind;
switch (cmd_kind) {
@ -1726,8 +1726,8 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
__profscope_dx11(G.profiling_ctx, Draw mesh, RGB_F(0.5, 0.2, 0.2));
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_MESH];
if (shader->valid) {
struct dx11_buffer *vertex_buffer = store->buffers.mesh.vertex_buffer;
struct dx11_buffer *index_buffer = store->buffers.mesh.index_buffer;
struct dx11_buffer *vertex_buffer = list->buffers.mesh.vertex_buffer;
struct dx11_buffer *index_buffer = list->buffers.mesh.index_buffer;
u32 vertex_offset = cmd->mesh.vertex_offset;
u32 index_offset = cmd->mesh.index_offset;
@ -1785,7 +1785,7 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
}
if (texture && texture->srv) {
struct dx11_buffer *instance_buffer = store->buffers.texture.instance_buffer;
struct dx11_buffer *instance_buffer = list->buffers.texture.instance_buffer;
u32 instance_offset = cmd->texture.instance_offset;
u32 instance_count = cmd->texture.instance_count;
@ -1833,7 +1833,7 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
__profscope_dx11(G.profiling_ctx, Draw grid, RGB_F(0.2, 0.2, 0.5));
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_GRID];
if (shader->valid) {
struct dx11_buffer *instance_buffer = store->buffers.grid.instance_buffer;
struct dx11_buffer *instance_buffer = list->buffers.grid.instance_buffer;
u32 instance_offset = cmd->grid.instance_offset;
u32 instance_count = cmd->grid.instance_count;
@ -1880,7 +1880,7 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
__profscope_dx11(G.profiling_ctx, Test, RGB_F(1, 0.2, 1));
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEST];
if (shader->valid) {
struct dx11_buffer *instance_buffer = store->buffers.test.instance_buffer;
struct dx11_buffer *instance_buffer = list->buffers.test.instance_buffer;
u32 instance_offset = cmd->test.instance_offset;
u32 instance_count = cmd->test.instance_count;

View File

@ -962,24 +962,24 @@ struct v2i32 gpu_texture_get_size(struct gpu_handle texture)
}
/* ========================== *
* Cmd buffer
* Cmd list
* ========================== */
struct gpu_handle gpu_cmd_store_alloc(void)
struct gpu_handle gpu_cmd_list_alloc(void)
{
struct gpu_handle res = ZI;
return res;
}
void gpu_push_cmd(struct gpu_handle gpu_cmd_store, struct gpu_cmd_params params)
void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params)
{
(UNUSED)gpu_cmd_store;
(UNUSED)gpu_cmd_list;
(UNUSED)params;
}
void gpu_submit_cmds(struct gpu_handle gpu_cmd_store)
void gpu_submit_cmds(struct gpu_handle gpu_cmd_list)
{
(UNUSED)gpu_cmd_store;
(UNUSED)gpu_cmd_list;
}
/* ========================== *

View File

@ -74,9 +74,9 @@ GLOBAL struct {
struct gpu_handle user_texture;
struct gpu_handle backbuffer_texture;
struct gpu_handle world_gpu_cmd_store;
struct gpu_handle user_gpu_cmd_store;
struct gpu_handle backbuffer_gpu_cmd_store;
struct gpu_handle world_gpu_cmd_list;
struct gpu_handle user_gpu_cmd_list;
struct gpu_handle backbuffer_gpu_cmd_list;
struct gpu_handle user_dispatch_state;
struct gpu_handle backbuffer_dispatch_state;
@ -258,9 +258,9 @@ struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr,
/* GPU handles */
G.world_to_user_xf = XFORM_IDENT;
G.world_gpu_cmd_store = gpu_cmd_store_alloc();
G.user_gpu_cmd_store = gpu_cmd_store_alloc();
G.backbuffer_gpu_cmd_store = gpu_cmd_store_alloc();
G.world_gpu_cmd_list = gpu_cmd_list_alloc();
G.user_gpu_cmd_list = gpu_cmd_list_alloc();
G.backbuffer_gpu_cmd_list = gpu_cmd_list_alloc();
G.user_dispatch_state = gpu_dispatch_state_alloc();
G.backbuffer_dispatch_state = gpu_dispatch_state_alloc();
@ -349,13 +349,13 @@ INTERNAL void debug_draw_xform(struct xform xf, u32 color_x, u32 color_y)
x_ray = v2_mul(x_ray, ray_scale);
y_ray = v2_mul(y_ray, ray_scale);
draw_arrow_ray(G.user_gpu_cmd_store, pos, x_ray, thickness, arrowhead_len, color_x);
draw_arrow_ray(G.user_gpu_cmd_store, pos, y_ray, thickness, arrowhead_len, color_y);
draw_arrow_ray(G.user_gpu_cmd_list, pos, x_ray, thickness, arrowhead_len, color_x);
draw_arrow_ray(G.user_gpu_cmd_list, pos, y_ray, thickness, arrowhead_len, color_y);
//u32 color_quad = RGBA_F(0, 1, 1, 0.3);
//struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
//quad = xform_mul_quad(xf, quad_scale(quad, 0.075f));
//draw_quad(G.user_gpu_cmd_store, quad, color);
//draw_quad(G.user_gpu_cmd_list, quad, color);
}
INTERNAL void debug_draw_movement(struct sim_ent *ent)
@ -372,7 +372,7 @@ INTERNAL void debug_draw_movement(struct sim_ent *ent)
struct v2 vel_ray = xform_basis_mul_v2(G.world_to_user_xf, velocity);
if (v2_len(vel_ray) > 0.00001) {
draw_arrow_ray(G.user_gpu_cmd_store, pos, vel_ray, thickness, arrow_len, color_vel);
draw_arrow_ray(G.user_gpu_cmd_list, pos, vel_ray, thickness, arrow_len, color_vel);
}
}
@ -542,7 +542,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
if (log->level <= level) {
/* Draw background */
u32 color = colors[log->level][log->color_index];
draw_quad(G.user_gpu_cmd_store, quad_from_rect(log->bounds), ALPHA_F(color, opacity));
draw_quad(G.user_gpu_cmd_list, quad_from_rect(log->bounds), ALPHA_F(color, opacity));
/* Draw text */
struct string text = log->msg;
@ -559,7 +559,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
}
struct draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA_F(COLOR_WHITE, opacity), .str = text);
struct rect bounds = draw_text(G.user_gpu_cmd_store, params);
struct rect bounds = draw_text(G.user_gpu_cmd_list, params);
struct rect draw_bounds = bounds;
draw_bounds.x -= bg_margin;
@ -1037,8 +1037,8 @@ INTERNAL void user_update(void)
* Set draw views
* ========================== */
draw_set_view(G.world_gpu_cmd_store, G.world_to_user_xf);
draw_set_view(G.user_gpu_cmd_store, XFORM_IDENT);
draw_set_view(G.world_gpu_cmd_list, G.world_to_user_xf);
draw_set_view(G.user_gpu_cmd_list, XFORM_IDENT);
/* ========================== *
* Update listener from view
@ -1065,7 +1065,7 @@ INTERNAL void user_update(void)
struct v2 size = xform_basis_invert_mul_v2(G.world_to_user_xf, G.user_size);
u32 color0 = RGBA_F(0.17f, 0.17f, 0.17f, 1.f);
u32 color1 = RGBA_F(0.15f, 0.15f, 0.15f, 1.f);
draw_grid(G.world_gpu_cmd_store, xform_from_rect(RECT_FROM_V2(pos, size)), color0, color1, RGBA(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
draw_grid(G.world_gpu_cmd_list, xform_from_rect(RECT_FROM_V2(pos, size)), color0, color1, RGBA(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
}
/* ========================== *
@ -1078,7 +1078,7 @@ INTERNAL void user_update(void)
struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_TEST;
cmd.test.xf = xform_from_rect(RECT_FROM_V2(pos, size));
gpu_push_cmd(G.world_gpu_cmd_store, cmd);
gpu_push_cmd(G.world_gpu_cmd_list, cmd);
}
#if 0
@ -1260,9 +1260,9 @@ INTERNAL void user_update(void)
u32 color_end = RGBA_F(1, 0.8, 0.4, opacity_b);
if (opacity_b > 0.99f) {
draw_circle(G.world_gpu_cmd_store, b, thickness / 2, color_end, 20);
draw_circle(G.world_gpu_cmd_list, b, thickness / 2, color_end, 20);
}
draw_gradient_line(G.world_gpu_cmd_store, a, b, thickness, color_start, color_end);
draw_gradient_line(G.world_gpu_cmd_list, a, b, thickness, color_start, color_end);
}
@ -1284,7 +1284,7 @@ INTERNAL void user_update(void)
u32 tint = ent->sprite_tint;
struct sprite_sheet_frame frame = sprite_sheet_get_frame(sheet, ent->animation_frame);
struct draw_texture_params params = DRAW_TEXTURE_PARAMS(.xf = sprite_xform, .sprite = sprite, .tint = tint, .clip = frame.clip, .emittance = emittance);
draw_texture(G.world_gpu_cmd_store, params);
draw_texture(G.world_gpu_cmd_list, params);
}
}
@ -1304,7 +1304,7 @@ INTERNAL void user_update(void)
struct v2 pos = sim_pos_from_world_tile_index(world_tile_index);
struct xform tile_xf = xform_from_rect(RECT_FROM_V2(pos, V2(tile_size, tile_size)));
struct draw_texture_params params = DRAW_TEXTURE_PARAMS(.xf = tile_xf, .sprite = tile_sprite);
draw_texture(G.world_gpu_cmd_store, params);
draw_texture(G.world_gpu_cmd_list, params);
}
}
}
@ -1332,7 +1332,7 @@ INTERNAL void user_update(void)
u32 color = RGBA_F(1, 0, 1, 0.5);
struct quad quad = quad_from_aabb(aabb);
quad = xform_mul_quad(G.world_to_user_xf, quad);
draw_quad_line(G.user_gpu_cmd_store, quad, thickness, color);
draw_quad_line(G.user_gpu_cmd_list, quad, thickness, color);
}
/* Draw focus arrow */
@ -1343,7 +1343,7 @@ INTERNAL void user_update(void)
start = xform_mul_v2(G.world_to_user_xf, start);
struct v2 end = v2_add(xf.og, ent->control.focus);
end = xform_mul_v2(G.world_to_user_xf, end);
draw_arrow_line(G.user_gpu_cmd_store, start, end, 3, 10, RGBA_F(1, 1, 1, 0.5));
draw_arrow_line(G.user_gpu_cmd_list, start, end, 3, 10, RGBA_F(1, 1, 1, 0.5));
}
#if 0
@ -1369,16 +1369,16 @@ INTERNAL void user_update(void)
struct quad quad = quad_from_rect(slice.rect);
quad = xform_mul_quad(sprite_xform, quad);
quad = xform_mul_quad(G.world_to_user_xf, quad);
draw_quad_line(G.user_gpu_cmd_store, quad, 2, quad_color);
draw_quad_line(G.user_gpu_cmd_list, quad, 2, quad_color);
}
draw_circle(G.user_gpu_cmd_store, center, 3, point_color, 20);
draw_circle(G.user_gpu_cmd_list, center, 3, point_color, 20);
if (slice.has_ray) {
struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir);
ray = xform_basis_mul_v2(G.world_to_user_xf, ray);
ray = v2_with_len(ray, 25);
draw_arrow_ray(G.user_gpu_cmd_store, center, ray, 2, 10, ray_color);
draw_arrow_ray(G.user_gpu_cmd_list, center, ray, 2, 10, ray_color);
}
}
}
@ -1395,7 +1395,7 @@ INTERNAL void user_update(void)
f32 radius = 3;
struct v2 point = xform_mul_v2(e1_xf, ent->weld_joint_data.point_local_e1);
point = xform_mul_v2(G.world_to_user_xf, point);
draw_circle(G.user_gpu_cmd_store, point, radius, color, 10);
draw_circle(G.user_gpu_cmd_list, point, radius, color, 10);
DEBUGBREAKABLE;
}
@ -1410,8 +1410,8 @@ INTERNAL void user_update(void)
struct v2 point_end = G.world_cursor;
point_start = xform_mul_v2(G.world_to_user_xf, point_start);
point_end = xform_mul_v2(G.world_to_user_xf, point_end);
draw_arrow_line(G.user_gpu_cmd_store, point_start, point_end, 3, 10, color);
draw_circle(G.user_gpu_cmd_store, point_start, 4, color, 10);
draw_arrow_line(G.user_gpu_cmd_list, point_start, point_end, 3, 10, color);
draw_circle(G.user_gpu_cmd_list, point_start, 4, color, 10);
}
/* Draw collider */
@ -1422,13 +1422,13 @@ INTERNAL void user_update(void)
{
/* Draw collider using support points */
u32 detail = 32;
draw_collider_line(G.user_gpu_cmd_store, G.world_to_user_xf, collider, xf, thickness, color, detail);
draw_collider_line(G.user_gpu_cmd_list, G.world_to_user_xf, collider, xf, thickness, color, detail);
}
{
/* Draw collider shape points */
for (u32 i = 0; i < collider.count; ++i) {
struct v2 p = xform_mul_v2(xform_mul(G.world_to_user_xf, xf), collider.points[i]);
draw_circle(G.user_gpu_cmd_store, p, 3, COLOR_BLUE, 10);
draw_circle(G.user_gpu_cmd_list, p, 3, COLOR_BLUE, 10);
}
}
if (collider.count == 1 && collider.radius > 0) {
@ -1437,14 +1437,14 @@ INTERNAL void user_update(void)
struct v2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p;
start = xform_mul_v2(G.world_to_user_xf, start);
end = xform_mul_v2(G.world_to_user_xf, end);
draw_line(G.user_gpu_cmd_store, start, end, thickness, color);
draw_line(G.user_gpu_cmd_list, start, end, thickness, color);
}
#if 0
/* Draw support point at focus dir */
{
struct v2 p = collider_support_point(&collider, xf, ent->control.focus);
p = xform_mul_v2(G.world_to_user_xf, p);
draw_circle(G.user_gpu_cmd_store, p, 3, COLOR_RED, 10);
draw_circle(G.user_gpu_cmd_list, p, 3, COLOR_RED, 10);
}
#endif
}
@ -1468,7 +1468,7 @@ INTERNAL void user_update(void)
/* Draw point */
{
draw_circle(G.user_gpu_cmd_store, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
draw_circle(G.user_gpu_cmd_list, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
}
/* Draw normal */
@ -1478,7 +1478,7 @@ INTERNAL void user_update(void)
f32 arrow_height = 5;
struct v2 start = xform_mul_v2(G.world_to_user_xf, dbg_pt);
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_add(dbg_pt, v2_mul(v2_norm(data->normal), len)));
draw_arrow_line(G.user_gpu_cmd_store, start, end, arrow_thickness, arrow_height, color);
draw_arrow_line(G.user_gpu_cmd_list, start, end, arrow_thickness, arrow_height, color);
}
#if 0
/* Draw contact info */
@ -1508,7 +1508,7 @@ INTERNAL void user_update(void)
FMT_UINT(data->num_points));
draw_text(G.user_gpu_cmd_store, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
draw_text(G.user_gpu_cmd_list, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text);
}
}
#endif
@ -1536,8 +1536,8 @@ INTERNAL void user_update(void)
u32 color = RGBA_F(1, 1, 0, 0.5);
struct v2 a = xform_mul_v2(G.world_to_user_xf, data->closest0);
struct v2 b = xform_mul_v2(G.world_to_user_xf, data->closest1);
draw_circle(G.user_gpu_cmd_store, a, radius, color, 10);
draw_circle(G.user_gpu_cmd_store, b, radius, color, 10);
draw_circle(G.user_gpu_cmd_list, a, radius, color, 10);
draw_circle(G.user_gpu_cmd_list, b, radius, color, 10);
}
#endif
@ -1554,28 +1554,28 @@ INTERNAL void user_update(void)
{
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a0);
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b0);
draw_line(G.user_gpu_cmd_store, a, b, thickness, color_line);
draw_circle(G.user_gpu_cmd_store, a, radius, color_a, 10);
draw_circle(G.user_gpu_cmd_store, b, radius, color_b, 10);
draw_line(G.user_gpu_cmd_list, a, b, thickness, color_line);
draw_circle(G.user_gpu_cmd_list, a, radius, color_a, 10);
draw_circle(G.user_gpu_cmd_list, b, radius, color_b, 10);
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a0_clipped);
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b0_clipped);
draw_line(G.user_gpu_cmd_store, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.user_gpu_cmd_store, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_cmd_store, b_clipped, radius, color_b_clipped, 10);
draw_line(G.user_gpu_cmd_list, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.user_gpu_cmd_list, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_cmd_list, b_clipped, radius, color_b_clipped, 10);
}
{
struct v2 a = xform_mul_v2(G.world_to_user_xf, collider_res.a1);
struct v2 b = xform_mul_v2(G.world_to_user_xf, collider_res.b1);
draw_line(G.user_gpu_cmd_store, a, b, thickness, color_line);
draw_circle(G.user_gpu_cmd_store, a, radius, color_a, 10);
draw_circle(G.user_gpu_cmd_store, b, radius, color_b, 10);
draw_line(G.user_gpu_cmd_list, a, b, thickness, color_line);
draw_circle(G.user_gpu_cmd_list, a, radius, color_a, 10);
draw_circle(G.user_gpu_cmd_list, b, radius, color_b, 10);
struct v2 a_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.a1_clipped);
struct v2 b_clipped = xform_mul_v2(G.world_to_user_xf, collider_res.b1_clipped);
draw_line(G.user_gpu_cmd_store, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.user_gpu_cmd_store, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_cmd_store, b_clipped, radius, color_b_clipped, 10);
draw_line(G.user_gpu_cmd_list, a_clipped, b_clipped, thickness, color_line_clipped);
draw_circle(G.user_gpu_cmd_list, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_cmd_list, b_clipped, radius, color_b_clipped, 10);
}
}
@ -1616,7 +1616,7 @@ INTERNAL void user_update(void)
FMT_FLOAT_P(xform_get_rotation(e1_xf), 24));
draw_text(G.user_gpu_cmd_store, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text);
draw_text(G.user_gpu_cmd_list, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text);
}
}
#endif
@ -1632,8 +1632,8 @@ INTERNAL void user_update(void)
struct v2_array m = menkowski(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf, detail);
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
draw_poly_line(G.user_gpu_cmd_store, m, true, thickness, color);
//draw_poly(G.user_gpu_cmd_store, m, color);
draw_poly_line(G.user_gpu_cmd_list, m, true, thickness, color);
//draw_poly(G.user_gpu_cmd_list, m, color);
}
/* Draw cloud */
@ -1645,7 +1645,7 @@ INTERNAL void user_update(void)
for (u64 i = 0; i < m.count; ++i) {
struct v2 p = xform_mul_v2(G.world_to_user_xf, m.points[i]);
draw_circle(G.user_gpu_cmd_store, p, radius, color, 10);
draw_circle(G.user_gpu_cmd_list, p, radius, color, 10);
}
}
@ -1659,8 +1659,8 @@ INTERNAL void user_update(void)
.count = collider_res.prototype.len
};
for (u64 i = 0; i < m.count; ++i) m.points[i] = xform_mul_v2(G.world_to_user_xf, m.points[i]);
draw_poly_line(G.user_gpu_cmd_store, m, true, thickness, color);
for (u64 i = 0; i < m.count; ++i) draw_circle(G.user_gpu_cmd_store, m.points[i], 10, color, 10);
draw_poly_line(G.user_gpu_cmd_list, m, true, thickness, color);
for (u64 i = 0; i < m.count; ++i) draw_circle(G.user_gpu_cmd_list, m.points[i], 10, color, 10);
}
/* Draw simplex */
@ -1678,18 +1678,18 @@ INTERNAL void user_update(void)
if (simplex.len >= 1) {
u32 color = simplex.len == 1 ? color_first : (simplex.len == 2 ? color_second : color_third);
draw_circle(G.user_gpu_cmd_store, simplex_array.points[0], thickness * 3, color, 10);
draw_circle(G.user_gpu_cmd_list, simplex_array.points[0], thickness * 3, color, 10);
}
if (simplex.len >= 2) {
u32 color = simplex.len == 2 ? color_first : color_second;
draw_circle(G.user_gpu_cmd_store, simplex_array.points[1], thickness * 3, color, 10);
draw_circle(G.user_gpu_cmd_list, simplex_array.points[1], thickness * 3, color, 10);
}
if (simplex.len >= 3) {
u32 color = color_first;
draw_circle(G.user_gpu_cmd_store, simplex_array.points[2], thickness * 3, color, 10);
draw_circle(G.user_gpu_cmd_list, simplex_array.points[2], thickness * 3, color, 10);
}
if (simplex.len >= 2) {
draw_poly_line(G.user_gpu_cmd_store, simplex_array, simplex.len > 2, thickness, line_color);
draw_poly_line(G.user_gpu_cmd_list, simplex_array, simplex.len > 2, thickness, line_color);
}
}
@ -1701,7 +1701,7 @@ INTERNAL void user_update(void)
f32 arrowhead_height = 10;
struct v2 start = xform_mul_v2(G.world_to_user_xf, V2(0, 0));
struct v2 end = xform_mul_v2(G.world_to_user_xf, v2_mul(v2_norm(collider_res.normal), len));
draw_arrow_line(G.user_gpu_cmd_store, start, end, arrow_thickness, arrowhead_height, color);
draw_arrow_line(G.user_gpu_cmd_list, start, end, arrow_thickness, arrowhead_height, color);
}
}
#endif
@ -1716,7 +1716,7 @@ INTERNAL void user_update(void)
struct v2 start = xform_mul_v2(G.world_to_user_xf, xf.og);
struct v2 end = xform_mul_v2(G.world_to_user_xf, parent_xf.og);
draw_arrow_line(G.user_gpu_cmd_store, start, end, thickness, arrow_height, color);
draw_arrow_line(G.user_gpu_cmd_list, start, end, thickness, arrow_height, color);
}
/* Draw camera rect */
@ -1728,7 +1728,7 @@ INTERNAL void user_update(void)
struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED);
quad = xform_mul_quad(G.world_to_user_xf, quad);
draw_quad_line(G.user_gpu_cmd_store, quad, thickness, color);
draw_quad_line(G.user_gpu_cmd_list, quad, thickness, color);
}
arena_temp_end(temp);
@ -1746,7 +1746,7 @@ INTERNAL void user_update(void)
struct v2 size = V2(t->width, t->height);
struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size);
draw_texture(G.user_gpu_cmd_store, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair_tag));
draw_texture(G.user_gpu_cmd_list, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair_tag));
struct rect cursor_clip = RECT_FROM_V2(G.user_screen_offset, G.user_size);
cursor_clip.pos = v2_add(cursor_clip.pos, v2_mul(size, 0.5f));
@ -1944,7 +1944,7 @@ INTERNAL void user_update(void)
struct string dbg_text = ZI;
dbg_text.text = arena_dry_push(temp.arena, u8);
dbg_text.len += get_ent_debug_text(temp.arena, ent).len;
draw_text(G.user_gpu_cmd_store, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
draw_text(G.user_gpu_cmd_list, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text));
arena_temp_end(temp);
}
@ -2044,16 +2044,16 @@ INTERNAL void user_update(void)
//text.len += string_copy(temp.arena, LIT("\n")).len;
#if COLLIDER_DEBUG
draw_text(G.user_gpu_cmd_store, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps)));
draw_text(G.user_gpu_cmd_list, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps)));
pos.y += spacing;
#endif
//draw_text(G.user_gpu_cmd_store, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
//draw_text(G.user_gpu_cmd_store, font, pos, text);
//draw_text(G.user_gpu_cmd_list, font, pos, string_format(temp.arena, LIT("blended world entities: %F/%F"), FMT_UINT(G.ss_blended->num_ents_allocated), FMT_UINT(G.ss_blended->num_ents_reserved)));
//draw_text(G.user_gpu_cmd_list, font, pos, text);
struct v2 pos = V2(10, G.user_size.y);
enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM;
draw_text(G.user_gpu_cmd_store, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
draw_text(G.user_gpu_cmd_list, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE));
arena_temp_end(temp);
}
}
@ -2103,13 +2103,13 @@ INTERNAL void user_update(void)
{
struct xform xf = XFORM_TRS(.t = v2_mul(V2(backbuffer_resolution.x, backbuffer_resolution.y), 0.5), .s = G.user_size);
struct draw_texture_params params = DRAW_TEXTURE_PARAMS(.xf = xf, .texture = G.user_texture);
draw_texture(G.backbuffer_gpu_cmd_store, params);
draw_texture(G.backbuffer_gpu_cmd_list, params);
}
/* Send cmds to GPU */
gpu_submit_cmds(G.world_gpu_cmd_store);
gpu_submit_cmds(G.user_gpu_cmd_store);
gpu_submit_cmds(G.backbuffer_gpu_cmd_store);
gpu_submit_cmds(G.world_gpu_cmd_list);
gpu_submit_cmds(G.user_gpu_cmd_list);
gpu_submit_cmds(G.backbuffer_gpu_cmd_list);
/* Clear textures */
gpu_texture_clear(G.user_texture, 0);
@ -2117,10 +2117,10 @@ INTERNAL void user_update(void)
/* Render to user texture */
{
struct gpu_handle *dispatch_cmds[] = { &G.world_gpu_cmd_store, &G.user_gpu_cmd_store };
struct gpu_handle *dispatch_cmds[] = { &G.world_gpu_cmd_list, &G.user_gpu_cmd_list };
struct gpu_dispatch_params params = ZI;
params.cmds_array.stores = dispatch_cmds;
params.cmds_array.count = ARRAY_COUNT(dispatch_cmds);
params.cmd_lists.handles = dispatch_cmds;
params.cmd_lists.count = ARRAY_COUNT(dispatch_cmds);
params.draw_target = G.user_texture;
params.draw_target_viewport = user_viewport;
gpu_dispatch(G.user_dispatch_state, params);
@ -2128,10 +2128,10 @@ INTERNAL void user_update(void)
/* Render to backbuffer texture */
{
struct gpu_handle *dispatch_cmds[] = { &G.backbuffer_gpu_cmd_store };
struct gpu_handle *dispatch_cmds[] = { &G.backbuffer_gpu_cmd_list };
struct gpu_dispatch_params params = ZI;
params.cmds_array.stores = dispatch_cmds;
params.cmds_array.count = ARRAY_COUNT(dispatch_cmds);
params.cmd_lists.handles = dispatch_cmds;
params.cmd_lists.count = ARRAY_COUNT(dispatch_cmds);
params.draw_target = G.backbuffer_texture;
params.draw_target_viewport = backbuffer_viewport;
gpu_dispatch(G.backbuffer_dispatch_state, params);