diff --git a/res/sh/common.hlsl b/res/sh/common.hlsl index c1e397f3..b220cf9a 100644 --- a/res/sh/common.hlsl +++ b/res/sh/common.hlsl @@ -1,5 +1,4 @@ #define DECL(t, n) t n : n -#define DESV(t, n, s) t n : s #define PI 3.14159265359 #define GOLDEN 1.61803398875 diff --git a/res/sh/material.hlsl b/res/sh/material.hlsl index f439449b..08c44e85 100644 --- a/res/sh/material.hlsl +++ b/res/sh/material.hlsl @@ -1,6 +1,6 @@ #include "sh/common.hlsl" -struct sh_material_constant { +struct sh_material_constants { float4x4 projection; uint instance_offset; }; @@ -24,7 +24,7 @@ struct sh_material_instance { cbuffer cbuff : register(b0) { - struct sh_material_constant g_constant; + struct sh_material_constants g_constants; }; StructuredBuffer g_instances : register(t0); @@ -44,32 +44,32 @@ static const float2 g_quad_verts[4] = { float2(-0.5f, 0.5f) }; -static const int2 g_uv_factors[4] = { - int2(0, 0), - int2(1, 0), - int2(1, 1), - int2(0, 1) +struct vs_input { + DECL(uint, SV_InstanceID); + DECL(uint, SV_VertexID); }; struct vs_output { - DESV(float4, screen_pos, SV_POSITION); + DECL(float4, SV_Position); DECL(float2, uv); DECL(float4, tint_lin); }; [RootSignature(ROOTSIG)] -struct vs_output sh_material_vs(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) +struct vs_output vs(struct vs_input input) { - struct sh_material_instance instance = g_instances[g_constant.instance_offset + instance_id]; - float2 vert = g_quad_verts[vertex_id]; - float2 uv_factor = g_uv_factors[vertex_id]; + struct sh_material_instance instance = g_instances[g_constants.instance_offset + input.SV_InstanceID]; + float2 vert = g_quad_verts[input.SV_VertexID]; + float2 world_pos = mul(instance.xf, float3(vert, 1)).xy; + float4 clip_pos = mul(g_constants.projection, float4(world_pos, 0, 1)); + float2 uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0)); + float4 tint_lin = linear_from_srgb32(instance.tint_srgb); struct vs_output output; - output.screen_pos = mul(g_constant.projection, float4(world_pos, 0, 1)); - output.uv = instance.uv0 + uv_factor * (instance.uv1 - instance.uv0); - output.tint_lin = linear_from_srgb32(instance.tint_srgb); - + output.SV_Position = clip_pos; + output.uv = uv; + output.tint_lin = tint_lin; return output; } @@ -77,9 +77,18 @@ struct vs_output sh_material_vs(uint instance_id : SV_InstanceID, uint vertex_id * Pixel shader * ========================== */ +struct ps_input { + struct vs_output vs; +}; + +struct ps_output { + DECL(float4, SV_Target); +}; + [RootSignature(ROOTSIG)] -float4 sh_material_ps(struct vs_output input) : SV_TARGET +struct ps_output ps(struct ps_input input) { - float4 color = g_texture.Sample(g_sampler, input.uv) * input.tint_lin; - return color; + struct ps_output output; + output.SV_Target = g_texture.Sample(g_sampler, input.vs.uv) * input.vs.tint_lin; + return output; } diff --git a/res/shaders_dx11/texture.hlsl b/res/shaders_dx11/texture.hlsl index f5c37b88..cb76cb66 100644 --- a/res/shaders_dx11/texture.hlsl +++ b/res/shaders_dx11/texture.hlsl @@ -1,5 +1,10 @@ #include "shaders_dx11/common.hlsl" +struct vs_constants { + float4x4 projection; + uint instance_offset; +}; + struct vs_instance { float2x3 xf; float2 uv0; @@ -8,56 +13,52 @@ struct vs_instance { float emittance; }; -struct ps_input { - DESV(float4, screen_pos, SV_POSITION); - DECL(float2, uv); - DECL(float4, tint_lin); -}; - /* ========================== * * Globals * ========================== */ -StructuredBuffer G_instance_buffer : register(t0); +StructuredBuffer g_instances : register(t0); -Texture2D G_texture : register(t1); +Texture2D g_texture : register(t1); -SamplerState G_sampler : register(s0); +SamplerState g_sampler : register(s0); -cbuffer constants : register(b0) +cbuffer cbuff : register(b0) { - float4x4 G_projection; - uint G_instance_offset; + struct vs_constants g_constants; }; /* ========================== * * Vertex shader * ========================== */ -static const float2 G_quad_verts[4] = { +static const float2 g_quad_verts[4] = { float2(-0.5f, -0.5f), float2( 0.5f, -0.5f), float2( 0.5f, 0.5f), float2(-0.5f, 0.5f) }; -static const int2 G_uv_factors[4] = { - int2(0, 0), - int2(1, 0), - int2(1, 1), - int2(0, 1) +struct vs_input { + DECL(uint, SV_InstanceID); + DECL(uint, SV_VertexID); }; -ps_input vs_main(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) +struct vs_output { + DECL(float4, SV_Position); + DECL(float2, uv); + DECL(float4, tint_lin); +}; + +struct vs_output vs_main(struct vs_input input) { - vs_instance instance = G_instance_buffer[G_instance_offset + instance_id]; - float2 vert = G_quad_verts[vertex_id]; - float2 uv_factor = G_uv_factors[vertex_id]; + vs_instance instance = g_instances[g_constants.instance_offset + input.SV_InstanceID]; + float2 vert = g_quad_verts[input.SV_VertexID]; float2 world_pos = mul(instance.xf, float3(vert, 1)).xy; - ps_input output; - output.screen_pos = mul(G_projection, float4(world_pos, 0, 1)); - output.uv = instance.uv0 + uv_factor * (instance.uv1 - instance.uv0); + struct vs_output output; + output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1)); + output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0)); output.tint_lin = linear_from_srgb32(instance.tint_srgb); return output; @@ -67,8 +68,17 @@ ps_input vs_main(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) * Pixel shader * ========================== */ -float4 ps_main(ps_input input) : SV_TARGET +struct ps_input { + struct vs_output vs; +}; + +struct ps_output { + DECL(float4, SV_Target); +}; + +struct ps_output ps_main(struct ps_input input) { - float4 color = G_texture.Sample(G_sampler, input.uv) * input.tint_lin; - return color; + struct ps_output output; + output.SV_Target = g_texture.Sample(g_sampler, input.vs.uv) * input.vs.tint_lin; + return output; } diff --git a/src/draw.c b/src/draw.c index 25527d00..90b0e81c 100644 --- a/src/draw.c +++ b/src/draw.c @@ -28,19 +28,19 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr, * View * ========================== */ -void draw_set_view(struct gpu_handle cmd_list, struct xform xf) +void draw_set_view(struct gpu_handle plan, struct xform xf) { struct gpu_cmd_params cmd = ZI; cmd.kind = GPU_CMD_KIND_DRAW_VIEW; cmd.view.xf = xf; - gpu_push_cmd(cmd_list, cmd); + gpu_push_cmd(plan, cmd); } /* ========================== * * Texture * ========================== */ -void draw_texture(struct gpu_handle cmd_list, struct draw_texture_params params) +void draw_texture(struct gpu_handle plan, 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 cmd_list, struct draw_texture_params params) cmd.texture.clip = params.clip; cmd.texture.tint = params.tint; cmd.texture.emittance = params.emittance; - gpu_push_cmd(cmd_list, cmd); + gpu_push_cmd(plan, cmd); } /* ========================== * * Fill shapes * ========================== */ -void draw_poly_ex(struct gpu_handle cmd_list, struct v2_array vertices, struct gpu_indices indices, u32 color) +void draw_poly_ex(struct gpu_handle plan, 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(cmd_list, cmd); + gpu_push_cmd(plan, cmd); } /* Draws a filled polygon using triangles in a fan pattern */ -void draw_poly(struct gpu_handle cmd_list, struct v2_array vertices, u32 color) +void draw_poly(struct gpu_handle plan, struct v2_array vertices, u32 color) { if (vertices.count >= 3) { struct arena_temp scratch = scratch_begin_no_conflict(); @@ -88,13 +88,13 @@ void draw_poly(struct gpu_handle cmd_list, struct v2_array vertices, u32 color) indices.indices[tri_offset + 2] = (i + 2); } - draw_poly_ex(cmd_list, vertices, indices, color); + draw_poly_ex(plan, vertices, indices, color); scratch_end(scratch); } } -void draw_circle(struct gpu_handle cmd_list, struct v2 pos, f32 radius, u32 color, u32 detail) +void draw_circle(struct gpu_handle plan, struct v2 pos, f32 radius, u32 color, u32 detail) { struct arena_temp scratch = scratch_begin_no_conflict(); @@ -112,12 +112,12 @@ void draw_circle(struct gpu_handle cmd_list, struct v2 pos, f32 radius, u32 colo .points = points, .count = detail }; - draw_poly(cmd_list, vertices, color); + draw_poly(plan, vertices, color); scratch_end(scratch); } -void draw_quad(struct gpu_handle cmd_list, struct quad quad, u32 color) +void draw_quad(struct gpu_handle plan, struct quad quad, u32 color) { LOCAL_PERSIST u32 indices_array[6] = { 0, 1, 2, @@ -125,57 +125,57 @@ void draw_quad(struct gpu_handle cmd_list, 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(cmd_list, vertices, indices, color); + draw_poly_ex(plan, vertices, indices, color); } /* ========================== * * Line shapes * ========================== */ -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_gradient_line(struct gpu_handle plan, 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(cmd_list, DRAW_TEXTURE_PARAMS(.texture = G.solid_white_texture, .tint0 = start_color, .tint1 = end_color, .quad = quad)); + draw_texture(plan, 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(cmd_list, quad, start_color); + draw_quad(plan, quad, start_color); #endif } -void draw_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, u32 color) +void draw_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 color) { struct quad quad = quad_from_line(start, end, thickness); - draw_quad(cmd_list, quad, color); + draw_quad(plan, quad, color); } -void draw_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f32 thickness, u32 color) +void draw_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, f32 thickness, u32 color) { struct quad quad = quad_from_ray(pos, rel, thickness); - draw_quad(cmd_list, quad, color); + draw_quad(plan, quad, color); } -void draw_poly_line(struct gpu_handle cmd_list, struct v2_array points, b32 loop, f32 thickness, u32 color) +void draw_poly_line(struct gpu_handle plan, 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(cmd_list, q, color); + draw_quad(plan, 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(cmd_list, q, color); + draw_quad(plan, q, color); } } } -void draw_circle_line(struct gpu_handle cmd_list, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail) +void draw_circle_line(struct gpu_handle plan, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail) { struct arena_temp scratch = scratch_begin_no_conflict(); @@ -193,19 +193,19 @@ void draw_circle_line(struct gpu_handle cmd_list, struct v2 pos, f32 radius, f32 .points = points, .count = detail }; - draw_poly_line(cmd_list, a, true, thickness, color); + draw_poly_line(plan, a, true, thickness, color); scratch_end(scratch); } -void draw_quad_line(struct gpu_handle cmd_list, struct quad quad, f32 thickness, u32 color) +void draw_quad_line(struct gpu_handle plan, 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(cmd_list, a, true, thickness, color); + draw_poly_line(plan, a, true, thickness, 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_line(struct gpu_handle plan, 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 */ @@ -229,19 +229,19 @@ void draw_arrow_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, .points = head_points, .count = ARRAY_COUNT(head_points) }; - draw_poly(cmd_list, head_points_v2_array, color); + draw_poly(plan, head_points_v2_array, color); struct quad line_quad = quad_from_line(start, head_start, thickness); - draw_quad(cmd_list, line_quad, color); + draw_quad(plan, line_quad, 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_arrow_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color) { struct v2 end = v2_add(pos, rel); - draw_arrow_line(cmd_list, pos, end, thickness, arrowhead_height, color); + draw_arrow_line(plan, pos, end, thickness, arrowhead_height, color); } -void draw_collider_line(struct gpu_handle cmd_list, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail) +void draw_collider_line(struct gpu_handle plan, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail) { struct arena_temp scratch = scratch_begin_no_conflict(); struct v2_array poly = ZI; @@ -262,7 +262,7 @@ void draw_collider_line(struct gpu_handle cmd_list, struct collider_shape shape, poly.points[i] = p; } } - draw_poly_line(cmd_list, poly, true, thickness, color); + draw_poly_line(plan, poly, true, thickness, color); scratch_end(scratch); } @@ -270,7 +270,7 @@ void draw_collider_line(struct gpu_handle cmd_list, struct collider_shape shape, * Grid * ========================== */ -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) +void draw_grid(struct gpu_handle plan, 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; @@ -283,7 +283,7 @@ void draw_grid(struct gpu_handle cmd_list, struct xform xf, u32 bg0_color, u32 b cmd.grid.line_thickness = thickness; cmd.grid.line_spacing = spacing; cmd.grid.offset = offset; - gpu_push_cmd(cmd_list, cmd); + gpu_push_cmd(plan, cmd); } /* ========================== * @@ -291,7 +291,7 @@ void draw_grid(struct gpu_handle cmd_list, struct xform xf, u32 bg0_color, u32 b * ========================== */ /* Returns the rect of the text area */ -struct rect draw_text(struct gpu_handle cmd_list, struct draw_text_params params) +struct rect draw_text(struct gpu_handle plan, struct draw_text_params params) { struct arena_temp scratch = scratch_begin_no_conflict(); @@ -459,7 +459,7 @@ struct rect draw_text(struct gpu_handle cmd_list, 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(cmd_list, DRAW_TEXTURE_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip)); + draw_texture(plan, DRAW_TEXTURE_PARAMS(.xf = xf, .texture = params.font->texture, .tint = params.color, .clip = tg->clip)); draw_pos.x += tg->advance; } diff --git a/src/draw.h b/src/draw.h index f1e07477..5ead83e3 100644 --- a/src/draw.h +++ b/src/draw.h @@ -14,7 +14,7 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr, * View * ========================== */ -void draw_set_view(struct gpu_handle cmd_list, struct xform xf); +void draw_set_view(struct gpu_handle plan, struct xform xf); /* ========================== * * Texture @@ -35,47 +35,47 @@ struct draw_texture_params { f32 emittance; }; -void draw_texture(struct gpu_handle cmd_list, struct draw_texture_params params); +void draw_texture(struct gpu_handle plan, struct draw_texture_params params); /* ========================== * * Fill shapes * ========================== */ -void draw_poly_ex(struct gpu_handle cmd_list, struct v2_array vertices, struct gpu_indices indices, u32 color); +void draw_poly_ex(struct gpu_handle plan, struct v2_array vertices, struct gpu_indices indices, u32 color); -void draw_poly(struct gpu_handle cmd_list, struct v2_array points, u32 color); +void draw_poly(struct gpu_handle plan, struct v2_array points, u32 color); -void draw_circle(struct gpu_handle cmd_list, struct v2 pos, f32 radius, u32 color, u32 detail); +void draw_circle(struct gpu_handle plan, struct v2 pos, f32 radius, u32 color, u32 detail); -void draw_quad(struct gpu_handle cmd_list, struct quad quad, u32 color); +void draw_quad(struct gpu_handle plan, struct quad quad, u32 color); /* ========================== * * Line shapes * ========================== */ -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_gradient_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 start_color, u32 end_color); -void draw_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end, f32 thickness, u32 color); +void draw_line(struct gpu_handle plan, struct v2 start, struct v2 end, f32 thickness, u32 color); -void draw_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f32 thickness, u32 color); +void draw_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, 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_poly_line(struct gpu_handle plan, struct v2_array points, b32 loop, f32 thickness, u32 color); -void draw_circle_line(struct gpu_handle cmd_list, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail); +void draw_circle_line(struct gpu_handle plan, struct v2 pos, f32 radius, f32 thickness, u32 color, u32 detail); -void draw_quad_line(struct gpu_handle cmd_list, struct quad quad, f32 thickness, u32 color); +void draw_quad_line(struct gpu_handle plan, struct quad quad, f32 thickness, 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_line(struct gpu_handle plan, struct v2 start, struct v2 end, 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_arrow_ray(struct gpu_handle plan, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color); -void draw_collider_line(struct gpu_handle cmd_list, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail); +void draw_collider_line(struct gpu_handle plan, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail); /* ========================== * * Grid * ========================== */ -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); +void draw_grid(struct gpu_handle plan, 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 cmd_list, struct draw_text_params params); +struct rect draw_text(struct gpu_handle plan, struct draw_text_params params); #endif diff --git a/src/gpu.h b/src/gpu.h index 4e867b1b..0199264a 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -113,18 +113,18 @@ struct gpu_cmd_params { }; }; -struct gpu_handle gpu_cmd_list_alloc(void); +struct gpu_handle gpu_plan_alloc(void); -void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params); +void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params); -void gpu_submit_cmds(struct gpu_handle gpu_cmd_list); +void gpu_submit_plan(struct gpu_handle gpu_plan); /* ========================== * * Dispatch * ========================== */ struct gpu_dispatch_params { - struct gpu_handle_array cmd_lists; + struct gpu_handle_array plans; struct gpu_handle draw_target; struct rect draw_target_viewport; }; diff --git a/src/gpu_dx11.c b/src/gpu_dx11.c index 124dd81a..1df984a7 100644 --- a/src/gpu_dx11.c +++ b/src/gpu_dx11.c @@ -60,7 +60,7 @@ enum dx11_shader_kind { enum dx11_handle_kind { DX11_HANDLE_KIND_NONE, DX11_HANDLE_KIND_TEXTURE, - DX11_HANDLE_KIND_CMD_LIST, + DX11_HANDLE_KIND_PLAN, DX11_HANDLE_KIND_DISPATCH_STATE, NUM_DX11_HANDLE_KINDS @@ -149,7 +149,7 @@ struct dx11_cmd { struct dx11_cmd *next; }; -struct dx11_cmd_list { +struct dx11_plan { struct dx11_handle_header header; /* Commands w/ data still in cpu memory */ @@ -178,7 +178,7 @@ struct dx11_cmd_list { } test; } buffers; - struct dx11_cmd_list *next_free; + struct dx11_plan *next_free; }; struct dx11_texture { @@ -236,10 +236,10 @@ GLOBAL struct { struct arena buffers_arena; struct dx11_buffer *first_free_buffer; - /* Cmd list pool */ - struct sys_mutex handles_mutex; - struct arena handles_arena; - struct dx11_cmd_list *first_free_cmd_list; + /* Plan pool */ + struct sys_mutex plans_mutex; + struct arena plans_arena; + struct dx11_plan *first_free_plan; /* 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 list pool */ - G.handles_mutex = sys_mutex_alloc(); - G.handles_arena = arena_alloc(GIGABYTE(64)); + /* Initialize plans pool */ + G.plans_mutex = sys_mutex_alloc(); + G.plans_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_LIST: + case DX11_HANDLE_KIND_PLAN: { /* TODO */ ASSERT(false); @@ -1274,41 +1274,41 @@ INTERNAL void dx11_buffer_submit(struct dx11_buffer *buffer) } /* ========================== * - * Cmd list + * Plan * ========================== */ -struct gpu_handle gpu_cmd_list_alloc(void) +struct gpu_handle gpu_plan_alloc(void) { __prof; - struct dx11_cmd_list *list = NULL; + struct dx11_plan *plan = NULL; { struct arena cpu_cmds_arena = ZI; struct arena gpu_cmds_arena = ZI; { - 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; + struct sys_lock lock = sys_mutex_lock_e(&G.plans_mutex); + if (G.first_free_plan) { + plan = G.first_free_plan; + G.first_free_plan = plan->next_free; + cpu_cmds_arena = plan->cpu_cmds_arena; + gpu_cmds_arena = plan->gpu_cmds_arena; } else { - list = arena_push_no_zero(&G.handles_arena, struct dx11_cmd_list); + plan = arena_push_no_zero(&G.plans_arena, struct dx11_plan); } sys_mutex_unlock(&lock); } - MEMZERO_STRUCT(list); + MEMZERO_STRUCT(plan); if (!cpu_cmds_arena.base) { cpu_cmds_arena = arena_alloc(GIGABYTE(64)); } if (!gpu_cmds_arena.base) { gpu_cmds_arena = arena_alloc(GIGABYTE(64)); } - 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); + plan->cpu_cmds_arena = cpu_cmds_arena; + plan->gpu_cmds_arena = gpu_cmds_arena; + arena_reset(&plan->cpu_cmds_arena); + arena_reset(&plan->gpu_cmds_arena); } - list->header.kind = DX11_HANDLE_KIND_CMD_LIST; + plan->header.kind = DX11_HANDLE_KIND_PLAN; /* Desc template */ const D3D11_BUFFER_DESC structured_buffer_desc = { @@ -1333,41 +1333,41 @@ struct gpu_handle gpu_cmd_list_alloc(void) idesc.BindFlags = D3D11_BIND_INDEX_BUFFER; idesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - list->buffers.mesh.vertex_buffer = dx11_buffer_alloc(vdesc, NULL); - list->buffers.mesh.index_buffer = dx11_buffer_alloc(idesc, NULL); + plan->buffers.mesh.vertex_buffer = dx11_buffer_alloc(vdesc, NULL); + plan->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); - list->buffers.texture.instance_buffer = dx11_buffer_alloc(desc, NULL); + plan->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); - list->buffers.grid.instance_buffer = dx11_buffer_alloc(desc, NULL); + plan->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); - list->buffers.test.instance_buffer = dx11_buffer_alloc(desc, NULL); + plan->buffers.test.instance_buffer = dx11_buffer_alloc(desc, NULL); } } struct gpu_handle res = ZI; - res.v = (u64)list; + res.v = (u64)plan; return res; } -void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params) +void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params) { __prof; - struct dx11_cmd_list *list = (struct dx11_cmd_list *)gpu_cmd_list.v; + struct dx11_plan *plan = (struct dx11_plan *)gpu_plan.v; switch (params.kind) { default: @@ -1378,20 +1378,20 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params) case GPU_CMD_KIND_DRAW_VIEW: { - struct dx11_cmd *cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd); + struct dx11_cmd *cmd = arena_push(&plan->cpu_cmds_arena, struct dx11_cmd); cmd->kind = params.kind; cmd->view.xf = params.view.xf; - if (list->cpu_last_cmd) { - list->cpu_last_cmd->next = cmd; + if (plan->cpu_last_cmd) { + plan->cpu_last_cmd->next = cmd; } else { - list->cpu_first_cmd = cmd; + plan->cpu_first_cmd = cmd; } - list->cpu_last_cmd = cmd; + plan->cpu_last_cmd = cmd; } break; case GPU_CMD_KIND_DRAW_MESH: { - struct dx11_cmd *cmd = list->cpu_last_cmd; + struct dx11_cmd *cmd = plan->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_list, struct gpu_cmd_params params) /* Start new cmd */ if (!cmd) { /* TODO: Better count method */ - cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd); + cmd = arena_push(&plan->cpu_cmds_arena, struct dx11_cmd); cmd->kind = params.kind; - 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(u32)); - if (list->cpu_last_cmd) { - list->cpu_last_cmd->next = cmd; + cmd->mesh.vertex_offset = (plan->buffers.mesh.vertex_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_mesh_vertex)); + cmd->mesh.index_offset = (plan->buffers.mesh.index_buffer->cpu_buffer_arena.pos / sizeof(u32)); + if (plan->cpu_last_cmd) { + plan->cpu_last_cmd->next = cmd; } else { - list->cpu_first_cmd = cmd; + plan->cpu_first_cmd = cmd; } - list->cpu_last_cmd = cmd; + plan->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(list->buffers.mesh.vertex_buffer, sizeof(struct dx11_mesh_vertex) * vertex_count); + struct dx11_mesh_vertex *verts = dx11_buffer_push(plan->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_list, struct gpu_cmd_params params) /* Push indices */ u64 index_count = params.mesh.indices.count; - u32 *indices = dx11_buffer_push(list->buffers.mesh.index_buffer, sizeof(u32) * index_count); + u32 *indices = dx11_buffer_push(plan->buffers.mesh.index_buffer, sizeof(u32) * 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_list, struct gpu_cmd_params params) case GPU_CMD_KIND_DRAW_TEXTURE: { - struct dx11_cmd *cmd = list->cpu_last_cmd; + struct dx11_cmd *cmd = plan->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_list, struct gpu_cmd_params params) /* Start new cmd */ if (!cmd) { /* TODO: Better count method */ - cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd); + cmd = arena_push(&plan->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 = (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; + cmd->texture.instance_offset = (plan->buffers.texture.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_texture_instance)); + if (plan->cpu_last_cmd) { + plan->cpu_last_cmd->next = cmd; } else { - list->cpu_first_cmd = cmd; + plan->cpu_first_cmd = cmd; } - list->cpu_last_cmd = cmd; + plan->cpu_last_cmd = cmd; } /* Push instance data */ ++cmd->texture.instance_count; - struct dx11_texture_instance *instance = dx11_buffer_push(list->buffers.texture.instance_buffer, sizeof(struct dx11_texture_instance)); + struct dx11_texture_instance *instance = dx11_buffer_push(plan->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_list, struct gpu_cmd_params params) case GPU_CMD_KIND_DRAW_GRID: { - struct dx11_cmd *cmd = list->cpu_last_cmd; + struct dx11_cmd *cmd = plan->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_list, struct gpu_cmd_params params) /* Start new cmd */ if (!cmd) { /* TODO: Better count method */ - cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd); + cmd = arena_push(&plan->cpu_cmds_arena, struct dx11_cmd); cmd->kind = params.kind; - 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; + cmd->grid.instance_offset = (plan->buffers.grid.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_grid_instance)); + if (plan->cpu_last_cmd) { + plan->cpu_last_cmd->next = cmd; } else { - list->cpu_first_cmd = cmd; + plan->cpu_first_cmd = cmd; } - list->cpu_last_cmd = cmd; + plan->cpu_last_cmd = cmd; } /* Push instance data */ ++cmd->grid.instance_count; - struct dx11_grid_instance *instance = dx11_buffer_push(list->buffers.grid.instance_buffer, sizeof(struct dx11_grid_instance)); + struct dx11_grid_instance *instance = dx11_buffer_push(plan->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_list, struct gpu_cmd_params params) case GPU_CMD_KIND_TEST: { - struct dx11_cmd *cmd = arena_push(&list->cpu_cmds_arena, struct dx11_cmd); + struct dx11_cmd *cmd = arena_push(&plan->cpu_cmds_arena, struct dx11_cmd); cmd->kind = params.kind; - 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; + cmd->test.instance_offset = (plan->buffers.test.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_test_instance)); + if (plan->cpu_last_cmd) { + plan->cpu_last_cmd->next = cmd; } else { - list->cpu_first_cmd = cmd; + plan->cpu_first_cmd = cmd; } - list->cpu_last_cmd = cmd; + plan->cpu_last_cmd = cmd; /* Push instance data */ ++cmd->test.instance_count; - struct dx11_test_instance *instance = dx11_buffer_push(list->buffers.test.instance_buffer, sizeof(struct dx11_test_instance)); + struct dx11_test_instance *instance = dx11_buffer_push(plan->buffers.test.instance_buffer, sizeof(struct dx11_test_instance)); instance->xf = params.test.xf; } break; } } -void gpu_submit_cmds(struct gpu_handle gpu_cmd_list) +void gpu_submit_plan(struct gpu_handle gpu_plan) { __prof; - struct dx11_cmd_list *list = (struct dx11_cmd_list *)gpu_cmd_list.v; + struct dx11_plan *plan = (struct dx11_plan *)gpu_plan.v; - /* Swap cmd lists */ - 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; + /* Swap cmd plans */ + struct arena swp_arena = plan->gpu_cmds_arena; + plan->gpu_cmds_arena = plan->cpu_cmds_arena; + plan->gpu_first_cmd = plan->cpu_first_cmd; + plan->gpu_last_cmd = plan->cpu_last_cmd; /* Reset cpu cmds */ - list->cpu_cmds_arena = swp_arena; - list->cpu_first_cmd = NULL; - list->cpu_last_cmd = NULL; - arena_reset(&list->cpu_cmds_arena); + plan->cpu_cmds_arena = swp_arena; + plan->cpu_first_cmd = NULL; + plan->cpu_last_cmd = NULL; + arena_reset(&plan->cpu_cmds_arena); /* Submit mesh buffers */ - dx11_buffer_submit(list->buffers.mesh.vertex_buffer); - dx11_buffer_submit(list->buffers.mesh.index_buffer); + dx11_buffer_submit(plan->buffers.mesh.vertex_buffer); + dx11_buffer_submit(plan->buffers.mesh.index_buffer); /* Submit texture buffers */ - dx11_buffer_submit(list->buffers.texture.instance_buffer); + dx11_buffer_submit(plan->buffers.texture.instance_buffer); /* Submit grid buffers */ - dx11_buffer_submit(list->buffers.grid.instance_buffer); + dx11_buffer_submit(plan->buffers.grid.instance_buffer); /* Submit test buffers */ - dx11_buffer_submit(list->buffers.test.instance_buffer); + dx11_buffer_submit(plan->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 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) { + for (u64 handles_array_index = 0; handles_array_index < params.plans.count; ++handles_array_index) { + struct dx11_plan *plan = (struct dx11_plan *)params.plans.handles[handles_array_index]->v; + for (struct dx11_cmd *cmd = plan->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 = list->buffers.mesh.vertex_buffer; - struct dx11_buffer *index_buffer = list->buffers.mesh.index_buffer; + struct dx11_buffer *vertex_buffer = plan->buffers.mesh.vertex_buffer; + struct dx11_buffer *index_buffer = plan->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 = list->buffers.texture.instance_buffer; + struct dx11_buffer *instance_buffer = plan->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 = list->buffers.grid.instance_buffer; + struct dx11_buffer *instance_buffer = plan->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 = list->buffers.test.instance_buffer; + struct dx11_buffer *instance_buffer = plan->buffers.test.instance_buffer; u32 instance_offset = cmd->test.instance_offset; u32 instance_count = cmd->test.instance_count; diff --git a/src/gpu_dx12.c b/src/gpu_dx12.c index ff5e839f..8613d100 100644 --- a/src/gpu_dx12.c +++ b/src/gpu_dx12.c @@ -29,11 +29,13 @@ #define SH_CPU 1 -#define DX12_WAIT_FRAME_LATENCY 1 +//#define DX12_WAIT_FRAME_LATENCY 1 +//#define DX12_SWAPCHAIN_FLAGS ((DX12_ALLOW_TEARING * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) | (DX12_WAIT_FRAME_LATENCY * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT)) + #define DX12_ALLOW_TEARING 1 +#define DX12_SWAPCHAIN_FLAGS (DX12_ALLOW_TEARING * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) #define DX12_SWAPCHAIN_BUFFER_COUNT (3) -#define DX12_SWAPCHAIN_FLAGS ((DX12_ALLOW_TEARING * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) | (DX12_WAIT_FRAME_LATENCY * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT)) #define DX12_SWAPCHAIN_FORMAT (DXGI_FORMAT_R8G8B8A8_UNORM) //#define DX12_SWAPCHAIN_RTV_FORMAT (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) @@ -60,8 +62,7 @@ struct pipeline_desc { struct pipeline { struct pipeline_desc desc; ID3D12PipelineState *pso; - ID3D12RootSignature *rs; - + ID3D12RootSignature *rootsig; }; struct pipeline_result { @@ -75,10 +76,14 @@ struct pipeline_error { struct string msg; }; +struct dx12_resource { + enum D3D12_RESOURCE_STATES state; +}; + enum dx12_handle_kind { DX12_HANDLE_KIND_NONE, DX12_HANDLE_KIND_TEXTURE, - DX12_HANDLE_KIND_COMMAND_LIST, + DX12_HANDLE_KIND_PLAN, NUM_DX12_HANDLE_KINDS }; @@ -125,7 +130,7 @@ GLOBAL struct { ID3D12CommandAllocator *swapchain_ca; IDXGISwapChain3 *swapchain; ID3D12DescriptorHeap *swapchain_rtv_heap; - ID3D12Resource *swapchain_rtvs[DX12_SWAPCHAIN_BUFFER_COUNT]; + ID3D12Resource *swapchain_buffers[DX12_SWAPCHAIN_BUFFER_COUNT]; } G = ZI, DEBUG_ALIAS(G, G_gpu_dx12); /* ========================== * @@ -160,8 +165,8 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown) __prof; #if DX12_DEBUG /* Release objects to make live object reporting less noisy */ - for (u64 i = 0; i < ARRAY_COUNT(G.swapchain_rtvs); ++i) { - ID3D12Resource_Release(G.swapchain_rtvs[i]); + for (u64 i = 0; i < ARRAY_COUNT(G.swapchain_buffers); ++i) { + ID3D12Resource_Release(G.swapchain_buffers[i]); } ID3D12DescriptorHeap_Release(G.swapchain_rtv_heap); IDXGISwapChain3_Release(G.swapchain); @@ -505,16 +510,16 @@ INTERNAL void dx12_init_base(struct sys_window *window) } /* Create swacphain RTVs */ - ID3D12Resource *swapchain_rtvs[DX12_SWAPCHAIN_BUFFER_COUNT] = ZI; + ID3D12Resource *swapchain_buffers[DX12_SWAPCHAIN_BUFFER_COUNT] = ZI; { D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = ZI; ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(swapchain_rtv_heap, &rtv_handle); for (u32 i = 0; i < DX12_SWAPCHAIN_BUFFER_COUNT; ++i) { - hr = IDXGISwapChain3_GetBuffer(swapchain, i, &IID_ID3D12Resource, (void **)&swapchain_rtvs[i]); + hr = IDXGISwapChain3_GetBuffer(swapchain, i, &IID_ID3D12Resource, (void **)&swapchain_buffers[i]); if (FAILED(hr)) { - dx12_init_error(LIT("Failed to create swapchain RTV")); + dx12_init_error(LIT("Failed to get swapchain buffer")); } - ID3D12Device_CreateRenderTargetView(device, swapchain_rtvs[i], NULL, rtv_handle); + ID3D12Device_CreateRenderTargetView(device, swapchain_buffers[i], NULL, rtv_handle); rtv_handle.ptr += desc_size_rtv; } } @@ -529,7 +534,7 @@ INTERNAL void dx12_init_base(struct sys_window *window) G.swapchain_ca = swapchain_ca; G.swapchain = swapchain; G.swapchain_rtv_heap = swapchain_rtv_heap; - MEMCPY(&G.swapchain_rtvs, swapchain_rtvs, sizeof(G.swapchain_rtvs)); + MEMCPY(&G.swapchain_buffers, swapchain_buffers, sizeof(G.swapchain_buffers)); IDXGIFactory6_Release(factory); scratch_end(scratch); @@ -578,8 +583,8 @@ INTERNAL void dx12_init_pipelines(void) /* Material pipeline */ { .name = "material", - .vs = { "sh/material.hlsl", "sh_material_vs" }, - .ps = { "sh/material.hlsl", "sh_material_ps" } + .vs = { "sh/material.hlsl", "vs" }, + .ps = { "sh/material.hlsl", "ps" } } }; @@ -829,7 +834,7 @@ INTERNAL WORK_TASK_FUNC_DEF(pipeline_load_task, load_arg_raw) struct work_slate ws = work_slate_begin(); work_slate_push_task(&ws, shader_compile_task, &vs); work_slate_push_task(&ws, shader_compile_task, &ps); - struct work_handle work = work_slate_end_and_help(&ws, WORK_PRIORITY_NORMAL); + struct work_handle work = work_slate_end_and_help(&ws, WORK_PRIORITY_HIGH); work_wait(work); success = vs.success && ps.success; } @@ -838,47 +843,47 @@ INTERNAL WORK_TASK_FUNC_DEF(pipeline_load_task, load_arg_raw) * NOTE: This isn't necessary for creating the root signature (since it * could reuse the shader blob), however we'd like to verify that the * root signature exists and matches between shaders. */ - ID3D10Blob *rs_blob = NULL; + ID3D10Blob *rootsig_blob = NULL; if (success) { __profscope(Validate root signatures); - char *vs_rs_data = NULL; - char *ps_rs_data = NULL; - u32 vs_rs_data_len = 0; - u32 ps_rs_data_len = 0; - ID3D10Blob *vs_rs_blob = NULL; - ID3D10Blob *ps_rs_blob = NULL; - D3DGetBlobPart(ID3D10Blob_GetBufferPointer(vs.blob), ID3D10Blob_GetBufferSize(vs.blob), D3D_BLOB_ROOT_SIGNATURE, 0, &vs_rs_blob); - D3DGetBlobPart(ID3D10Blob_GetBufferPointer(ps.blob), ID3D10Blob_GetBufferSize(ps.blob), D3D_BLOB_ROOT_SIGNATURE, 0, &ps_rs_blob); - if (vs_rs_blob) { - vs_rs_data = ID3D10Blob_GetBufferPointer(vs_rs_blob); - vs_rs_data_len = ID3D10Blob_GetBufferSize(vs_rs_blob); + char *vs_rootsig_data = NULL; + char *ps_rootsig_data = NULL; + u32 vs_rootsig_data_len = 0; + u32 ps_rootsig_data_len = 0; + ID3D10Blob *vs_rootsig_blob = NULL; + ID3D10Blob *ps_rootsig_blob = NULL; + D3DGetBlobPart(ID3D10Blob_GetBufferPointer(vs.blob), ID3D10Blob_GetBufferSize(vs.blob), D3D_BLOB_ROOT_SIGNATURE, 0, &vs_rootsig_blob); + D3DGetBlobPart(ID3D10Blob_GetBufferPointer(ps.blob), ID3D10Blob_GetBufferSize(ps.blob), D3D_BLOB_ROOT_SIGNATURE, 0, &ps_rootsig_blob); + if (vs_rootsig_blob) { + vs_rootsig_data = ID3D10Blob_GetBufferPointer(vs_rootsig_blob); + vs_rootsig_data_len = ID3D10Blob_GetBufferSize(vs_rootsig_blob); } - if (ps_rs_blob) { - ps_rs_data = ID3D10Blob_GetBufferPointer(ps_rs_blob); - ps_rs_data_len = ID3D10Blob_GetBufferSize(ps_rs_blob); + if (ps_rootsig_blob) { + ps_rootsig_data = ID3D10Blob_GetBufferPointer(ps_rootsig_blob); + ps_rootsig_data_len = ID3D10Blob_GetBufferSize(ps_rootsig_blob); } - if (vs_rs_data_len == 0) { + if (vs_rootsig_data_len == 0) { success = false; error_str = LIT("Vertex shader is missing root signature"); - } else if (ps_rs_data_len == 0) { + } else if (ps_rootsig_data_len == 0) { success = false; error_str = LIT("Pixel shader is missing root signature"); - } else if (vs_rs_data_len != ps_rs_data_len || !MEMEQ(vs_rs_data, ps_rs_data, vs_rs_data_len)) { + } else if (vs_rootsig_data_len != ps_rootsig_data_len || !MEMEQ(vs_rootsig_data, ps_rootsig_data, vs_rootsig_data_len)) { success = false; error_str = LIT("Root signature mismatch between vertex and pixel shader"); } else { - rs_blob = vs_rs_blob; + rootsig_blob = vs_rootsig_blob; } - if (ps_rs_blob) { - ID3D10Blob_Release(ps_rs_blob); + if (ps_rootsig_blob) { + ID3D10Blob_Release(ps_rootsig_blob); } } /* Create root signature */ - ID3D12RootSignature *rs = NULL; + ID3D12RootSignature *rootsig = NULL; if (success) { __profscope(Create root signature); - hr = ID3D12Device_CreateRootSignature(G.device, 0, ID3D10Blob_GetBufferPointer(rs_blob), ID3D10Blob_GetBufferSize(rs_blob), &IID_ID3D12RootSignature, (void **)&rs); + hr = ID3D12Device_CreateRootSignature(G.device, 0, ID3D10Blob_GetBufferPointer(rootsig_blob), ID3D10Blob_GetBufferSize(rootsig_blob), &IID_ID3D12RootSignature, (void **)&rootsig); if (FAILED(hr)) { error_str = LIT("Failed to create root signature"); success = false; @@ -926,7 +931,7 @@ INTERNAL WORK_TASK_FUNC_DEF(pipeline_load_task, load_arg_raw) /* PSO */ D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { 0 }; - pso_desc.pRootSignature = rs; + pso_desc.pRootSignature = rootsig; if (vs.success) { pso_desc.VS.pShaderBytecode = ID3D10Blob_GetBufferPointer(vs.blob); pso_desc.VS.BytecodeLength = ID3D10Blob_GetBufferSize(vs.blob); @@ -971,15 +976,15 @@ INTERNAL WORK_TASK_FUNC_DEF(pipeline_load_task, load_arg_raw) } pipeline->pso = pso; - pipeline->rs = rs; + pipeline->rootsig = rootsig; result->elapsed = sys_time_ns() - start_ns; resource_close(&vs_res); if (!ps_res_is_shared) { resource_close(&ps_res); } - if (rs_blob) { - ID3D10Blob_Release(rs_blob); + if (rootsig_blob) { + ID3D10Blob_Release(rootsig_blob); } if (vs.blob) { ID3D10Blob_Release(vs.blob); @@ -1017,7 +1022,7 @@ INTERNAL struct pipeline_result *pipeline_alloc_from_descs(struct arena *arena, work_slate_push_task(&ws, pipeline_load_task, arg); } - struct work_handle work = work_slate_end_and_help(&ws, WORK_PRIORITY_NORMAL); + struct work_handle work = work_slate_end_and_help(&ws, WORK_PRIORITY_HIGH); work_wait(work); return results; @@ -1070,24 +1075,24 @@ struct v2i32 gpu_texture_get_size(struct gpu_handle texture) } /* ========================== * - * Cmd list + * Plan * ========================== */ -struct gpu_handle gpu_cmd_list_alloc(void) +struct gpu_handle gpu_plan_alloc(void) { struct gpu_handle res = ZI; return res; } -void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params) +void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params) { - (UNUSED)gpu_cmd_list; + (UNUSED)gpu_plan; (UNUSED)params; } -void gpu_submit_cmds(struct gpu_handle gpu_cmd_list) +void gpu_submit_plan(struct gpu_handle gpu_plan) { - (UNUSED)gpu_cmd_list; + (UNUSED)gpu_plan; } /* ========================== * @@ -1101,6 +1106,24 @@ struct gpu_handle gpu_dispatch_state_alloc(void) } #if 0 + +INTERNAL void dx12_barrier(ID3D12CommandList *cl, struct dx12_resource *resource, enum D3D12_RESOURCE_STATES state) +{ + if (state != resource->state) { + struct D3D12_RESOURCE_TRANSITION_BARRIER rtb = ZI; + rtb.pResource = resource->res; + rtb.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + rtb.StateBefore = resource->state; + rtb.StateAfter = state; + + struct D3D12_RESOURCE_BARRIER rb = ZI; + rb.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + rb.Flags = + + resource->state = state; + } +} + void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_params params) { (UNUSED)gpu_dispatch_state; @@ -1108,12 +1131,28 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para struct pipeline_scope *pipeline_scope = pipeline_scope_begin(); - struct dx12_command_list *command_list = handle_get_data(gpu_command_list, DX12_HANDLE_KIND_COMMAND_LIST); + struct dx12_dispatch_state *dispatch_state = handle_get_date(gpu_dispatch_state, DX12_HANDLE_KIND_DISPATCH_STATE); + struct dx12_plan *plan = handle_get_data(dispatch_state->plan, DX12_HANDLE_KIND_PLAN); /* Material pass */ { struct pipeline *pipeline = dx12_get_pipeline(pipeline_scope, LIT("material")); + /* Bind pipeline */ + ID3D12CommandList_SetPipelineState(command_list, pipeline->pso); + ID3D12CommandList_SetGraphicsRootSignature(command_list, pipeline->rs); + + /* Bind resources */ + cl->SetGraphicsRootDescriptorTable(0, m_srvHeap->GetGPUDescriptorHandleForHeapStart()); + + /* Setup RS */ + cl->RSSetViewports(1, &m_viewport); + cl->RSSetScissorRects(1, &m_scissorRect); + + // Indicate that the texture will be used as a render target + dx12_barrier(cl, target, D3D12_RESOURCE_STATE_RENDER_TARGET); + D3D12_RESOURCE_BARRIER barrier_start = dx12_barrier(target, D3D12_RESOURCE_STATE_RENDER_TARGET); + cl->ResourceBarrier(1, barrier_start); } pipeline_scope_end(pipeline_scope); diff --git a/src/user.c b/src/user.c index 8b673d55..0d322b3b 100644 --- a/src/user.c +++ b/src/user.c @@ -74,9 +74,9 @@ GLOBAL struct { struct gpu_handle user_texture; struct gpu_handle backbuffer_texture; - struct gpu_handle world_gpu_cmd_list; - struct gpu_handle user_gpu_cmd_list; - struct gpu_handle backbuffer_gpu_cmd_list; + struct gpu_handle world_gpu_plan; + struct gpu_handle user_gpu_plan; + struct gpu_handle backbuffer_gpu_plan; 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_list = gpu_cmd_list_alloc(); - G.user_gpu_cmd_list = gpu_cmd_list_alloc(); - G.backbuffer_gpu_cmd_list = gpu_cmd_list_alloc(); + G.world_gpu_plan = gpu_plan_alloc(); + G.user_gpu_plan = gpu_plan_alloc(); + G.backbuffer_gpu_plan = gpu_plan_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_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); + draw_arrow_ray(G.user_gpu_plan, pos, x_ray, thickness, arrowhead_len, color_x); + draw_arrow_ray(G.user_gpu_plan, 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_list, quad, color); + //draw_quad(G.user_gpu_plan, 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_list, pos, vel_ray, thickness, arrow_len, color_vel); + draw_arrow_ray(G.user_gpu_plan, 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_list, quad_from_rect(log->bounds), ALPHA_F(color, opacity)); + draw_quad(G.user_gpu_plan, 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_list, params); + struct rect bounds = draw_text(G.user_gpu_plan, 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_list, G.world_to_user_xf); - draw_set_view(G.user_gpu_cmd_list, XFORM_IDENT); + draw_set_view(G.world_gpu_plan, G.world_to_user_xf); + draw_set_view(G.user_gpu_plan, 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_list, 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_plan, 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_list, cmd); + gpu_push_cmd(G.world_gpu_plan, 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_list, b, thickness / 2, color_end, 20); + draw_circle(G.world_gpu_plan, b, thickness / 2, color_end, 20); } - draw_gradient_line(G.world_gpu_cmd_list, a, b, thickness, color_start, color_end); + draw_gradient_line(G.world_gpu_plan, a, b, thickness, color_start, color_end); } @@ -1281,7 +1281,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_list, params); + draw_texture(G.world_gpu_plan, params); } } @@ -1301,7 +1301,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_list, params); + draw_texture(G.world_gpu_plan, params); } } } @@ -1329,7 +1329,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_list, quad, thickness, color); + draw_quad_line(G.user_gpu_plan, quad, thickness, color); } /* Draw focus arrow */ @@ -1340,7 +1340,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_list, start, end, 3, 10, RGBA_F(1, 1, 1, 0.5)); + draw_arrow_line(G.user_gpu_plan, start, end, 3, 10, RGBA_F(1, 1, 1, 0.5)); } #if 0 @@ -1366,16 +1366,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_list, quad, 2, quad_color); + draw_quad_line(G.user_gpu_plan, quad, 2, quad_color); } - draw_circle(G.user_gpu_cmd_list, center, 3, point_color, 20); + draw_circle(G.user_gpu_plan, 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_list, center, ray, 2, 10, ray_color); + draw_arrow_ray(G.user_gpu_plan, center, ray, 2, 10, ray_color); } } } @@ -1392,7 +1392,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_list, point, radius, color, 10); + draw_circle(G.user_gpu_plan, point, radius, color, 10); DEBUGBREAKABLE; } @@ -1407,8 +1407,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_list, point_start, point_end, 3, 10, color); - draw_circle(G.user_gpu_cmd_list, point_start, 4, color, 10); + draw_arrow_line(G.user_gpu_plan, point_start, point_end, 3, 10, color); + draw_circle(G.user_gpu_plan, point_start, 4, color, 10); } /* Draw collider */ @@ -1420,13 +1420,13 @@ INTERNAL void user_update(void) /* Draw collider using support points */ u32 detail = 32; struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf); - draw_collider_line(G.user_gpu_cmd_list, collider, collider_draw_xf, thickness, color, detail); + draw_collider_line(G.user_gpu_plan, collider, collider_draw_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_list, p, 3, COLOR_BLUE, 10); + draw_circle(G.user_gpu_plan, p, 3, COLOR_BLUE, 10); } } if (collider.count == 1 && collider.radius > 0) { @@ -1435,14 +1435,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_list, start, end, thickness, color); + draw_line(G.user_gpu_plan, 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_list, p, 3, COLOR_RED, 10); + draw_circle(G.user_gpu_plan, p, 3, COLOR_RED, 10); } #endif } @@ -1466,7 +1466,7 @@ INTERNAL void user_update(void) /* Draw point */ { - draw_circle(G.user_gpu_cmd_list, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10); + draw_circle(G.user_gpu_plan, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10); } /* Draw normal */ @@ -1476,7 +1476,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_list, start, end, arrow_thickness, arrow_height, color); + draw_arrow_line(G.user_gpu_plan, start, end, arrow_thickness, arrow_height, color); } #if 0 /* Draw contact info */ @@ -1506,7 +1506,7 @@ INTERNAL void user_update(void) FMT_UINT(data->num_points)); - 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); + draw_text(G.user_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, dbg_pt)), V2(0, offset_px)), text); } } #endif @@ -1534,8 +1534,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_list, a, radius, color, 10); - draw_circle(G.user_gpu_cmd_list, b, radius, color, 10); + draw_circle(G.user_gpu_plan, a, radius, color, 10); + draw_circle(G.user_gpu_plan, b, radius, color, 10); } #endif @@ -1552,28 +1552,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_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); + draw_line(G.user_gpu_plan, a, b, thickness, color_line); + draw_circle(G.user_gpu_plan, a, radius, color_a, 10); + draw_circle(G.user_gpu_plan, 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_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); + draw_line(G.user_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped); + draw_circle(G.user_gpu_plan, a_clipped, radius, color_a_clipped, 10); + draw_circle(G.user_gpu_plan, 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_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); + draw_line(G.user_gpu_plan, a, b, thickness, color_line); + draw_circle(G.user_gpu_plan, a, radius, color_a, 10); + draw_circle(G.user_gpu_plan, 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_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); + draw_line(G.user_gpu_plan, a_clipped, b_clipped, thickness, color_line_clipped); + draw_circle(G.user_gpu_plan, a_clipped, radius, color_a_clipped, 10); + draw_circle(G.user_gpu_plan, b_clipped, radius, color_b_clipped, 10); } } @@ -1614,7 +1614,7 @@ INTERNAL void user_update(void) FMT_FLOAT_P(xform_get_rotation(e1_xf), 24)); - 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); + draw_text(G.user_gpu_plan, disp_font, v2_add(v2_round(xform_mul_v2(G.world_to_user_xf, V2(0, 0))), V2(0, offset_px)), text); } } #endif @@ -1630,8 +1630,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_list, m, true, thickness, color); - //draw_poly(G.user_gpu_cmd_list, m, color); + draw_poly_line(G.user_gpu_plan, m, true, thickness, color); + //draw_poly(G.user_gpu_plan, m, color); } /* Draw cloud */ @@ -1643,7 +1643,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_list, p, radius, color, 10); + draw_circle(G.user_gpu_plan, p, radius, color, 10); } } @@ -1657,8 +1657,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_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_poly_line(G.user_gpu_plan, m, true, thickness, color); + for (u64 i = 0; i < m.count; ++i) draw_circle(G.user_gpu_plan, m.points[i], 10, color, 10); } /* Draw simplex */ @@ -1676,18 +1676,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_list, simplex_array.points[0], thickness * 3, color, 10); + draw_circle(G.user_gpu_plan, 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_list, simplex_array.points[1], thickness * 3, color, 10); + draw_circle(G.user_gpu_plan, simplex_array.points[1], thickness * 3, color, 10); } if (simplex.len >= 3) { u32 color = color_first; - draw_circle(G.user_gpu_cmd_list, simplex_array.points[2], thickness * 3, color, 10); + draw_circle(G.user_gpu_plan, simplex_array.points[2], thickness * 3, color, 10); } if (simplex.len >= 2) { - draw_poly_line(G.user_gpu_cmd_list, simplex_array, simplex.len > 2, thickness, line_color); + draw_poly_line(G.user_gpu_plan, simplex_array, simplex.len > 2, thickness, line_color); } } @@ -1699,7 +1699,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_list, start, end, arrow_thickness, arrowhead_height, color); + draw_arrow_line(G.user_gpu_plan, start, end, arrow_thickness, arrowhead_height, color); } } #endif @@ -1714,7 +1714,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_list, start, end, thickness, arrow_height, color); + draw_arrow_line(G.user_gpu_plan, start, end, thickness, arrow_height, color); } /* Draw camera rect */ @@ -1726,7 +1726,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_list, quad, thickness, color); + draw_quad_line(G.user_gpu_plan, quad, thickness, color); } arena_temp_end(temp); @@ -1744,7 +1744,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_list, DRAW_TEXTURE_PARAMS(.xf = xf, .sprite = crosshair_tag)); + draw_texture(G.user_gpu_plan, 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)); @@ -1942,7 +1942,7 @@ INTERNAL void user_update(void) struct string dbg_text = ZI; dbg_text.text = arena_push_dry(temp.arena, u8); dbg_text.len += get_ent_debug_text(temp.arena, ent).len; - draw_text(G.user_gpu_cmd_list, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text)); + draw_text(G.user_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = dbg_text)); arena_temp_end(temp); } @@ -2042,16 +2042,16 @@ INTERNAL void user_update(void) //text.len += string_copy(temp.arena, LIT("\n")).len; #if COLLIDER_DEBUG - draw_text(G.user_gpu_cmd_list, font, pos, string_format(temp.arena, LIT("collider gjk steps: %F"), FMT_UINT(collider_debug_steps))); + draw_text(G.user_gpu_plan, 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_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); + //draw_text(G.user_gpu_plan, 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_plan, 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_list, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE)); + draw_text(G.user_gpu_plan, DRAW_TEXT_PARAMS(.font = font, .pos = pos, .str = text, .offset_y = offset_y, .color = COLOR_WHITE)); arena_temp_end(temp); } } @@ -2101,13 +2101,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_list, params); + draw_texture(G.backbuffer_gpu_plan, params); } - /* Send cmds to GPU */ - gpu_submit_cmds(G.world_gpu_cmd_list); - gpu_submit_cmds(G.user_gpu_cmd_list); - gpu_submit_cmds(G.backbuffer_gpu_cmd_list); + /* Send plans to GPU */ + gpu_submit_plan(G.world_gpu_plan); + gpu_submit_plan(G.user_gpu_plan); + gpu_submit_plan(G.backbuffer_gpu_plan); /* Clear textures */ gpu_texture_clear(G.user_texture, 0); @@ -2115,10 +2115,10 @@ INTERNAL void user_update(void) /* Render to user texture */ { - struct gpu_handle *dispatch_cmds[] = { &G.world_gpu_cmd_list, &G.user_gpu_cmd_list }; + struct gpu_handle *plans[] = { &G.world_gpu_plan, &G.user_gpu_plan }; struct gpu_dispatch_params params = ZI; - params.cmd_lists.handles = dispatch_cmds; - params.cmd_lists.count = ARRAY_COUNT(dispatch_cmds); + params.plans.handles = plans; + params.plans.count = ARRAY_COUNT(plans); params.draw_target = G.user_texture; params.draw_target_viewport = user_viewport; gpu_dispatch(G.user_dispatch_state, params); @@ -2126,10 +2126,10 @@ INTERNAL void user_update(void) /* Render to backbuffer texture */ { - struct gpu_handle *dispatch_cmds[] = { &G.backbuffer_gpu_cmd_list }; + struct gpu_handle *plans[] = { &G.backbuffer_gpu_plan }; struct gpu_dispatch_params params = ZI; - params.cmd_lists.handles = dispatch_cmds; - params.cmd_lists.count = ARRAY_COUNT(dispatch_cmds); + params.plans.handles = plans; + params.plans.count = ARRAY_COUNT(plans); params.draw_target = G.backbuffer_texture; params.draw_target_viewport = backbuffer_viewport; gpu_dispatch(G.backbuffer_dispatch_state, params);