rename gpu_cmd_list -> gpu_plan

This commit is contained in:
jacob 2025-06-10 00:04:39 -05:00
parent 1c18cba5f8
commit 68c116095c
9 changed files with 390 additions and 333 deletions

View File

@ -1,5 +1,4 @@
#define DECL(t, n) t n : n #define DECL(t, n) t n : n
#define DESV(t, n, s) t n : s
#define PI 3.14159265359 #define PI 3.14159265359
#define GOLDEN 1.61803398875 #define GOLDEN 1.61803398875

View File

@ -1,6 +1,6 @@
#include "sh/common.hlsl" #include "sh/common.hlsl"
struct sh_material_constant { struct sh_material_constants {
float4x4 projection; float4x4 projection;
uint instance_offset; uint instance_offset;
}; };
@ -24,7 +24,7 @@ struct sh_material_instance {
cbuffer cbuff : register(b0) cbuffer cbuff : register(b0)
{ {
struct sh_material_constant g_constant; struct sh_material_constants g_constants;
}; };
StructuredBuffer<struct sh_material_instance> g_instances : register(t0); StructuredBuffer<struct sh_material_instance> g_instances : register(t0);
@ -44,32 +44,32 @@ static const float2 g_quad_verts[4] = {
float2(-0.5f, 0.5f) float2(-0.5f, 0.5f)
}; };
static const int2 g_uv_factors[4] = { struct vs_input {
int2(0, 0), DECL(uint, SV_InstanceID);
int2(1, 0), DECL(uint, SV_VertexID);
int2(1, 1),
int2(0, 1)
}; };
struct vs_output { struct vs_output {
DESV(float4, screen_pos, SV_POSITION); DECL(float4, SV_Position);
DECL(float2, uv); DECL(float2, uv);
DECL(float4, tint_lin); DECL(float4, tint_lin);
}; };
[RootSignature(ROOTSIG)] [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]; struct sh_material_instance instance = g_instances[g_constants.instance_offset + input.SV_InstanceID];
float2 vert = g_quad_verts[vertex_id]; float2 vert = g_quad_verts[input.SV_VertexID];
float2 uv_factor = g_uv_factors[vertex_id];
float2 world_pos = mul(instance.xf, float3(vert, 1)).xy; 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; struct vs_output output;
output.screen_pos = mul(g_constant.projection, float4(world_pos, 0, 1)); output.SV_Position = clip_pos;
output.uv = instance.uv0 + uv_factor * (instance.uv1 - instance.uv0); output.uv = uv;
output.tint_lin = linear_from_srgb32(instance.tint_srgb); output.tint_lin = tint_lin;
return output; return output;
} }
@ -77,9 +77,18 @@ struct vs_output sh_material_vs(uint instance_id : SV_InstanceID, uint vertex_id
* Pixel shader * Pixel shader
* ========================== */ * ========================== */
struct ps_input {
struct vs_output vs;
};
struct ps_output {
DECL(float4, SV_Target);
};
[RootSignature(ROOTSIG)] [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; struct ps_output output;
return color; output.SV_Target = g_texture.Sample(g_sampler, input.vs.uv) * input.vs.tint_lin;
return output;
} }

View File

@ -1,5 +1,10 @@
#include "shaders_dx11/common.hlsl" #include "shaders_dx11/common.hlsl"
struct vs_constants {
float4x4 projection;
uint instance_offset;
};
struct vs_instance { struct vs_instance {
float2x3 xf; float2x3 xf;
float2 uv0; float2 uv0;
@ -8,56 +13,52 @@ struct vs_instance {
float emittance; float emittance;
}; };
struct ps_input {
DESV(float4, screen_pos, SV_POSITION);
DECL(float2, uv);
DECL(float4, tint_lin);
};
/* ========================== * /* ========================== *
* Globals * Globals
* ========================== */ * ========================== */
StructuredBuffer<vs_instance> G_instance_buffer : register(t0); StructuredBuffer<vs_instance> 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; struct vs_constants g_constants;
uint G_instance_offset;
}; };
/* ========================== * /* ========================== *
* Vertex shader * 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),
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] = { struct vs_input {
int2(0, 0), DECL(uint, SV_InstanceID);
int2(1, 0), DECL(uint, SV_VertexID);
int2(1, 1),
int2(0, 1)
}; };
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]; vs_instance instance = g_instances[g_constants.instance_offset + input.SV_InstanceID];
float2 vert = G_quad_verts[vertex_id]; float2 vert = g_quad_verts[input.SV_VertexID];
float2 uv_factor = G_uv_factors[vertex_id];
float2 world_pos = mul(instance.xf, float3(vert, 1)).xy; float2 world_pos = mul(instance.xf, float3(vert, 1)).xy;
ps_input output; struct vs_output output;
output.screen_pos = mul(G_projection, float4(world_pos, 0, 1)); output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1));
output.uv = instance.uv0 + uv_factor * (instance.uv1 - instance.uv0); output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
output.tint_lin = linear_from_srgb32(instance.tint_srgb); output.tint_lin = linear_from_srgb32(instance.tint_srgb);
return output; return output;
@ -67,8 +68,17 @@ ps_input vs_main(uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID)
* Pixel shader * 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; struct ps_output output;
return color; output.SV_Target = g_texture.Sample(g_sampler, input.vs.uv) * input.vs.tint_lin;
return output;
} }

View File

@ -28,19 +28,19 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
* View * 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; struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_VIEW; cmd.kind = GPU_CMD_KIND_DRAW_VIEW;
cmd.view.xf = xf; cmd.view.xf = xf;
gpu_push_cmd(cmd_list, cmd); gpu_push_cmd(plan, cmd);
} }
/* ========================== * /* ========================== *
* Texture * 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; struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_TEXTURE; 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.clip = params.clip;
cmd.texture.tint = params.tint; cmd.texture.tint = params.tint;
cmd.texture.emittance = params.emittance; cmd.texture.emittance = params.emittance;
gpu_push_cmd(cmd_list, cmd); gpu_push_cmd(plan, cmd);
} }
/* ========================== * /* ========================== *
* Fill shapes * 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; struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_MESH; cmd.kind = GPU_CMD_KIND_DRAW_MESH;
cmd.mesh.vertices = vertices; cmd.mesh.vertices = vertices;
cmd.mesh.indices = indices; cmd.mesh.indices = indices;
cmd.mesh.color = color; 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 */ /* 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) { if (vertices.count >= 3) {
struct arena_temp scratch = scratch_begin_no_conflict(); 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); 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); 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(); 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, .points = points,
.count = detail .count = detail
}; };
draw_poly(cmd_list, vertices, color); draw_poly(plan, vertices, color);
scratch_end(scratch); 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] = { LOCAL_PERSIST u32 indices_array[6] = {
0, 1, 2, 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 v2_array vertices = { .count = 4, .points = quad.e };
struct gpu_indices indices = { .count = 6, .indices = indices_array }; 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 * 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 #if 0
struct quad quad = quad_from_line(start, end, thickness); 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 #else
/* Placeholder */ /* Placeholder */
(UNUSED)end_color; (UNUSED)end_color;
struct quad quad = quad_from_line(start, end, thickness); struct quad quad = quad_from_line(start, end, thickness);
draw_quad(cmd_list, quad, start_color); draw_quad(plan, quad, start_color);
#endif #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); 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); 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) { if (points.count >= 2) {
for (u64 i = 1; i < points.count; ++i) { for (u64 i = 1; i < points.count; ++i) {
struct v2 p1 = points.points[i - 1]; struct v2 p1 = points.points[i - 1];
struct v2 p2 = points.points[i]; struct v2 p2 = points.points[i];
struct quad q = quad_from_line(p1, p2, thickness); 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) { if (loop && points.count > 2) {
struct v2 p1 = points.points[points.count - 1]; struct v2 p1 = points.points[points.count - 1];
struct v2 p2 = points.points[0]; struct v2 p2 = points.points[0];
struct quad q = quad_from_line(p1, p2, thickness); 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(); 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, .points = points,
.count = detail .count = detail
}; };
draw_poly_line(cmd_list, a, true, thickness, color); draw_poly_line(plan, a, true, thickness, color);
scratch_end(scratch); 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 points[] = { quad.p0, quad.p1, quad.p2, quad.p3 };
struct v2_array a = { .points = points, .count = ARRAY_COUNT(points) }; 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 */ 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, .points = head_points,
.count = ARRAY_COUNT(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); 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); 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 arena_temp scratch = scratch_begin_no_conflict();
struct v2_array poly = ZI; 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; poly.points[i] = p;
} }
} }
draw_poly_line(cmd_list, poly, true, thickness, color); draw_poly_line(plan, poly, true, thickness, color);
scratch_end(scratch); scratch_end(scratch);
} }
@ -270,7 +270,7 @@ void draw_collider_line(struct gpu_handle cmd_list, struct collider_shape shape,
* Grid * 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; struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_DRAW_GRID; 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_thickness = thickness;
cmd.grid.line_spacing = spacing; cmd.grid.line_spacing = spacing;
cmd.grid.offset = offset; 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 */ /* 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(); 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 pos = V2(draw_pos.x + tg->off_x, draw_pos.y + tg->off_y);
struct v2 size = V2(tg->width, tg->height); struct v2 size = V2(tg->width, tg->height);
struct xform xf = xform_from_rect(RECT_FROM_V2(pos, size)); 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; draw_pos.x += tg->advance;
} }

View File

@ -14,7 +14,7 @@ struct draw_startup_receipt draw_startup(struct gpu_startup_receipt *gpu_sr,
* View * 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 * Texture
@ -35,47 +35,47 @@ struct draw_texture_params {
f32 emittance; 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 * 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 * 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 * 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 * Text
@ -123,6 +123,6 @@ struct draw_text_params {
struct string str; 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 #endif

View File

@ -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 * Dispatch
* ========================== */ * ========================== */
struct gpu_dispatch_params { struct gpu_dispatch_params {
struct gpu_handle_array cmd_lists; struct gpu_handle_array plans;
struct gpu_handle draw_target; struct gpu_handle draw_target;
struct rect draw_target_viewport; struct rect draw_target_viewport;
}; };

View File

@ -60,7 +60,7 @@ enum dx11_shader_kind {
enum dx11_handle_kind { enum dx11_handle_kind {
DX11_HANDLE_KIND_NONE, DX11_HANDLE_KIND_NONE,
DX11_HANDLE_KIND_TEXTURE, DX11_HANDLE_KIND_TEXTURE,
DX11_HANDLE_KIND_CMD_LIST, DX11_HANDLE_KIND_PLAN,
DX11_HANDLE_KIND_DISPATCH_STATE, DX11_HANDLE_KIND_DISPATCH_STATE,
NUM_DX11_HANDLE_KINDS NUM_DX11_HANDLE_KINDS
@ -149,7 +149,7 @@ struct dx11_cmd {
struct dx11_cmd *next; struct dx11_cmd *next;
}; };
struct dx11_cmd_list { struct dx11_plan {
struct dx11_handle_header header; struct dx11_handle_header header;
/* Commands w/ data still in cpu memory */ /* Commands w/ data still in cpu memory */
@ -178,7 +178,7 @@ struct dx11_cmd_list {
} test; } test;
} buffers; } buffers;
struct dx11_cmd_list *next_free; struct dx11_plan *next_free;
}; };
struct dx11_texture { struct dx11_texture {
@ -236,10 +236,10 @@ GLOBAL struct {
struct arena buffers_arena; struct arena buffers_arena;
struct dx11_buffer *first_free_buffer; struct dx11_buffer *first_free_buffer;
/* Cmd list pool */ /* Plan pool */
struct sys_mutex handles_mutex; struct sys_mutex plans_mutex;
struct arena handles_arena; struct arena plans_arena;
struct dx11_cmd_list *first_free_cmd_list; struct dx11_plan *first_free_plan;
/* Dispatch state pool */ /* Dispatch state pool */
struct sys_mutex dispatch_states_mutex; 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_mutex = sys_mutex_alloc();
G.buffers_arena = arena_alloc(GIGABYTE(64)); G.buffers_arena = arena_alloc(GIGABYTE(64));
/* Initialize cmd list pool */ /* Initialize plans pool */
G.handles_mutex = sys_mutex_alloc(); G.plans_mutex = sys_mutex_alloc();
G.handles_arena = arena_alloc(GIGABYTE(64)); G.plans_arena = arena_alloc(GIGABYTE(64));
/* Initialize dispatch state pool */ /* Initialize dispatch state pool */
G.dispatch_states_mutex = sys_mutex_alloc(); 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); dx11_texture_release((struct dx11_texture *)header);
} break; } break;
case DX11_HANDLE_KIND_CMD_LIST: case DX11_HANDLE_KIND_PLAN:
{ {
/* TODO */ /* TODO */
ASSERT(false); 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; __prof;
struct dx11_cmd_list *list = NULL; struct dx11_plan *plan = NULL;
{ {
struct arena cpu_cmds_arena = ZI; struct arena cpu_cmds_arena = ZI;
struct arena gpu_cmds_arena = ZI; struct arena gpu_cmds_arena = ZI;
{ {
struct sys_lock lock = sys_mutex_lock_e(&G.handles_mutex); struct sys_lock lock = sys_mutex_lock_e(&G.plans_mutex);
if (G.first_free_cmd_list) { if (G.first_free_plan) {
list = G.first_free_cmd_list; plan = G.first_free_plan;
G.first_free_cmd_list = list->next_free; G.first_free_plan = plan->next_free;
cpu_cmds_arena = list->cpu_cmds_arena; cpu_cmds_arena = plan->cpu_cmds_arena;
gpu_cmds_arena = list->gpu_cmds_arena; gpu_cmds_arena = plan->gpu_cmds_arena;
} else { } 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); sys_mutex_unlock(&lock);
} }
MEMZERO_STRUCT(list); MEMZERO_STRUCT(plan);
if (!cpu_cmds_arena.base) { if (!cpu_cmds_arena.base) {
cpu_cmds_arena = arena_alloc(GIGABYTE(64)); cpu_cmds_arena = arena_alloc(GIGABYTE(64));
} }
if (!gpu_cmds_arena.base) { if (!gpu_cmds_arena.base) {
gpu_cmds_arena = arena_alloc(GIGABYTE(64)); gpu_cmds_arena = arena_alloc(GIGABYTE(64));
} }
list->cpu_cmds_arena = cpu_cmds_arena; plan->cpu_cmds_arena = cpu_cmds_arena;
list->gpu_cmds_arena = gpu_cmds_arena; plan->gpu_cmds_arena = gpu_cmds_arena;
arena_reset(&list->cpu_cmds_arena); arena_reset(&plan->cpu_cmds_arena);
arena_reset(&list->gpu_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 */ /* Desc template */
const D3D11_BUFFER_DESC structured_buffer_desc = { 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.BindFlags = D3D11_BIND_INDEX_BUFFER;
idesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; idesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
list->buffers.mesh.vertex_buffer = dx11_buffer_alloc(vdesc, NULL); plan->buffers.mesh.vertex_buffer = dx11_buffer_alloc(vdesc, NULL);
list->buffers.mesh.index_buffer = dx11_buffer_alloc(idesc, NULL); plan->buffers.mesh.index_buffer = dx11_buffer_alloc(idesc, NULL);
} }
/* Texture buffers */ /* Texture buffers */
{ {
struct D3D11_BUFFER_DESC desc = structured_buffer_desc; struct D3D11_BUFFER_DESC desc = structured_buffer_desc;
desc.StructureByteStride = sizeof(struct dx11_texture_instance); 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 */ /* Grid buffers */
{ {
struct D3D11_BUFFER_DESC desc = structured_buffer_desc; struct D3D11_BUFFER_DESC desc = structured_buffer_desc;
desc.StructureByteStride = sizeof(struct dx11_grid_instance); 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 */ /* Test buffers */
{ {
struct D3D11_BUFFER_DESC desc = structured_buffer_desc; struct D3D11_BUFFER_DESC desc = structured_buffer_desc;
desc.StructureByteStride = sizeof(struct dx11_test_instance); 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; struct gpu_handle res = ZI;
res.v = (u64)list; res.v = (u64)plan;
return res; 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; __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) { switch (params.kind) {
default: 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: 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->kind = params.kind;
cmd->view.xf = params.view.xf; cmd->view.xf = params.view.xf;
if (list->cpu_last_cmd) { if (plan->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd; plan->cpu_last_cmd->next = cmd;
} else { } else {
list->cpu_first_cmd = cmd; plan->cpu_first_cmd = cmd;
} }
list->cpu_last_cmd = cmd; plan->cpu_last_cmd = cmd;
} break; } break;
case GPU_CMD_KIND_DRAW_MESH: 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) { if (cmd && cmd->kind != params.kind) {
/* Cannot batch */ /* Cannot batch */
cmd = NULL; cmd = NULL;
@ -1400,23 +1400,23 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params)
/* Start new cmd */ /* Start new cmd */
if (!cmd) { if (!cmd) {
/* TODO: Better count method */ /* 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->kind = params.kind;
cmd->mesh.vertex_offset = (list->buffers.mesh.vertex_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_mesh_vertex)); cmd->mesh.vertex_offset = (plan->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)); cmd->mesh.index_offset = (plan->buffers.mesh.index_buffer->cpu_buffer_arena.pos / sizeof(u32));
if (list->cpu_last_cmd) { if (plan->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd; plan->cpu_last_cmd->next = cmd;
} else { } else {
list->cpu_first_cmd = cmd; plan->cpu_first_cmd = cmd;
} }
list->cpu_last_cmd = cmd; plan->cpu_last_cmd = cmd;
} }
/* Push vertices */ /* Push vertices */
u64 vertex_count = params.mesh.vertices.count; u64 vertex_count = params.mesh.vertices.count;
u64 start_index = cmd->mesh.vertex_count; u64 start_index = cmd->mesh.vertex_count;
cmd->mesh.vertex_count += 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) { for (u64 i = 0; i < vertex_count; ++i) {
struct dx11_mesh_vertex *vert = &verts[i]; struct dx11_mesh_vertex *vert = &verts[i];
vert->pos = params.mesh.vertices.points[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 */ /* Push indices */
u64 index_count = params.mesh.indices.count; 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; cmd->mesh.index_count += index_count;
for (u64 i = 0; i < index_count; ++i) { for (u64 i = 0; i < index_count; ++i) {
indices[i] = start_index + params.mesh.indices.indices[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: case GPU_CMD_KIND_DRAW_TEXTURE:
{ {
struct dx11_cmd *cmd = list->cpu_last_cmd; struct dx11_cmd *cmd = plan->cpu_last_cmd;
if (cmd && if (cmd &&
((cmd->kind != params.kind) || ((cmd->kind != params.kind) ||
(cmd->texture.sprite.hash != params.texture.sprite.hash) || (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 */ /* Start new cmd */
if (!cmd) { if (!cmd) {
/* TODO: Better count method */ /* 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->kind = params.kind;
cmd->texture.sprite = params.texture.sprite; cmd->texture.sprite = params.texture.sprite;
cmd->texture.texture = params.texture.texture; cmd->texture.texture = params.texture.texture;
cmd->texture.instance_offset = (list->buffers.texture.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_texture_instance)); cmd->texture.instance_offset = (plan->buffers.texture.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_texture_instance));
if (list->cpu_last_cmd) { if (plan->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd; plan->cpu_last_cmd->next = cmd;
} else { } else {
list->cpu_first_cmd = cmd; plan->cpu_first_cmd = cmd;
} }
list->cpu_last_cmd = cmd; plan->cpu_last_cmd = cmd;
} }
/* Push instance data */ /* Push instance data */
++cmd->texture.instance_count; ++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->xf = params.texture.xf;
instance->uv0 = params.texture.clip.p0; instance->uv0 = params.texture.clip.p0;
instance->uv1 = params.texture.clip.p1; 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: 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) { if (cmd && cmd->kind != params.kind) {
/* Cannot batch */ /* Cannot batch */
cmd = NULL; cmd = NULL;
@ -1480,20 +1480,20 @@ void gpu_push_cmd(struct gpu_handle gpu_cmd_list, struct gpu_cmd_params params)
/* Start new cmd */ /* Start new cmd */
if (!cmd) { if (!cmd) {
/* TODO: Better count method */ /* 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->kind = params.kind;
cmd->grid.instance_offset = (list->buffers.grid.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_grid_instance)); cmd->grid.instance_offset = (plan->buffers.grid.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_grid_instance));
if (list->cpu_last_cmd) { if (plan->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd; plan->cpu_last_cmd->next = cmd;
} else { } else {
list->cpu_first_cmd = cmd; plan->cpu_first_cmd = cmd;
} }
list->cpu_last_cmd = cmd; plan->cpu_last_cmd = cmd;
} }
/* Push instance data */ /* Push instance data */
++cmd->grid.instance_count; ++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->xf = params.grid.xf;
instance->line_thickness = params.grid.line_thickness; instance->line_thickness = params.grid.line_thickness;
instance->line_spacing = params.grid.line_spacing; 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: 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->kind = params.kind;
cmd->test.instance_offset = (list->buffers.test.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_test_instance)); cmd->test.instance_offset = (plan->buffers.test.instance_buffer->cpu_buffer_arena.pos / sizeof(struct dx11_test_instance));
if (list->cpu_last_cmd) { if (plan->cpu_last_cmd) {
list->cpu_last_cmd->next = cmd; plan->cpu_last_cmd->next = cmd;
} else { } else {
list->cpu_first_cmd = cmd; plan->cpu_first_cmd = cmd;
} }
list->cpu_last_cmd = cmd; plan->cpu_last_cmd = cmd;
/* Push instance data */ /* Push instance data */
++cmd->test.instance_count; ++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; instance->xf = params.test.xf;
} break; } break;
} }
} }
void gpu_submit_cmds(struct gpu_handle gpu_cmd_list) void gpu_submit_plan(struct gpu_handle gpu_plan)
{ {
__prof; __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 */ /* Swap cmd plans */
struct arena swp_arena = list->gpu_cmds_arena; struct arena swp_arena = plan->gpu_cmds_arena;
list->gpu_cmds_arena = list->cpu_cmds_arena; plan->gpu_cmds_arena = plan->cpu_cmds_arena;
list->gpu_first_cmd = list->cpu_first_cmd; plan->gpu_first_cmd = plan->cpu_first_cmd;
list->gpu_last_cmd = list->cpu_last_cmd; plan->gpu_last_cmd = plan->cpu_last_cmd;
/* Reset cpu cmds */ /* Reset cpu cmds */
list->cpu_cmds_arena = swp_arena; plan->cpu_cmds_arena = swp_arena;
list->cpu_first_cmd = NULL; plan->cpu_first_cmd = NULL;
list->cpu_last_cmd = NULL; plan->cpu_last_cmd = NULL;
arena_reset(&list->cpu_cmds_arena); arena_reset(&plan->cpu_cmds_arena);
/* Submit mesh buffers */ /* Submit mesh buffers */
dx11_buffer_submit(list->buffers.mesh.vertex_buffer); dx11_buffer_submit(plan->buffers.mesh.vertex_buffer);
dx11_buffer_submit(list->buffers.mesh.index_buffer); dx11_buffer_submit(plan->buffers.mesh.index_buffer);
/* Submit texture buffers */ /* Submit texture buffers */
dx11_buffer_submit(list->buffers.texture.instance_buffer); dx11_buffer_submit(plan->buffers.texture.instance_buffer);
/* Submit grid buffers */ /* Submit grid buffers */
dx11_buffer_submit(list->buffers.grid.instance_buffer); dx11_buffer_submit(plan->buffers.grid.instance_buffer);
/* Submit test buffers */ /* 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(Regular pass);
__profscope_dx11(G.profiling_ctx, Regular pass, RGB_F(0.2, 0.5, 0.5)); __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) { for (u64 handles_array_index = 0; handles_array_index < params.plans.count; ++handles_array_index) {
struct dx11_cmd_list *list = (struct dx11_cmd_list *)params.cmd_lists.handles[handles_array_index]->v; struct dx11_plan *plan = (struct dx11_plan *)params.plans.handles[handles_array_index]->v;
for (struct dx11_cmd *cmd = list->gpu_first_cmd; cmd; cmd = cmd->next) { for (struct dx11_cmd *cmd = plan->gpu_first_cmd; cmd; cmd = cmd->next) {
enum gpu_cmd_kind cmd_kind = cmd->kind; enum gpu_cmd_kind cmd_kind = cmd->kind;
switch (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)); __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]; struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_MESH];
if (shader->valid) { if (shader->valid) {
struct dx11_buffer *vertex_buffer = list->buffers.mesh.vertex_buffer; struct dx11_buffer *vertex_buffer = plan->buffers.mesh.vertex_buffer;
struct dx11_buffer *index_buffer = list->buffers.mesh.index_buffer; struct dx11_buffer *index_buffer = plan->buffers.mesh.index_buffer;
u32 vertex_offset = cmd->mesh.vertex_offset; u32 vertex_offset = cmd->mesh.vertex_offset;
u32 index_offset = cmd->mesh.index_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) { 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_offset = cmd->texture.instance_offset;
u32 instance_count = cmd->texture.instance_count; 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)); __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]; struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_GRID];
if (shader->valid) { 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_offset = cmd->grid.instance_offset;
u32 instance_count = cmd->grid.instance_count; 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)); __profscope_dx11(G.profiling_ctx, Test, RGB_F(1, 0.2, 1));
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEST]; struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEST];
if (shader->valid) { 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_offset = cmd->test.instance_offset;
u32 instance_count = cmd->test.instance_count; u32 instance_count = cmd->test.instance_count;

View File

@ -29,11 +29,13 @@
#define SH_CPU 1 #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_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_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_FORMAT (DXGI_FORMAT_R8G8B8A8_UNORM)
//#define DX12_SWAPCHAIN_RTV_FORMAT (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) //#define DX12_SWAPCHAIN_RTV_FORMAT (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
@ -60,8 +62,7 @@ struct pipeline_desc {
struct pipeline { struct pipeline {
struct pipeline_desc desc; struct pipeline_desc desc;
ID3D12PipelineState *pso; ID3D12PipelineState *pso;
ID3D12RootSignature *rs; ID3D12RootSignature *rootsig;
}; };
struct pipeline_result { struct pipeline_result {
@ -75,10 +76,14 @@ struct pipeline_error {
struct string msg; struct string msg;
}; };
struct dx12_resource {
enum D3D12_RESOURCE_STATES state;
};
enum dx12_handle_kind { enum dx12_handle_kind {
DX12_HANDLE_KIND_NONE, DX12_HANDLE_KIND_NONE,
DX12_HANDLE_KIND_TEXTURE, DX12_HANDLE_KIND_TEXTURE,
DX12_HANDLE_KIND_COMMAND_LIST, DX12_HANDLE_KIND_PLAN,
NUM_DX12_HANDLE_KINDS NUM_DX12_HANDLE_KINDS
}; };
@ -125,7 +130,7 @@ GLOBAL struct {
ID3D12CommandAllocator *swapchain_ca; ID3D12CommandAllocator *swapchain_ca;
IDXGISwapChain3 *swapchain; IDXGISwapChain3 *swapchain;
ID3D12DescriptorHeap *swapchain_rtv_heap; 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); } G = ZI, DEBUG_ALIAS(G, G_gpu_dx12);
/* ========================== * /* ========================== *
@ -160,8 +165,8 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown)
__prof; __prof;
#if DX12_DEBUG #if DX12_DEBUG
/* Release objects to make live object reporting less noisy */ /* Release objects to make live object reporting less noisy */
for (u64 i = 0; i < ARRAY_COUNT(G.swapchain_rtvs); ++i) { for (u64 i = 0; i < ARRAY_COUNT(G.swapchain_buffers); ++i) {
ID3D12Resource_Release(G.swapchain_rtvs[i]); ID3D12Resource_Release(G.swapchain_buffers[i]);
} }
ID3D12DescriptorHeap_Release(G.swapchain_rtv_heap); ID3D12DescriptorHeap_Release(G.swapchain_rtv_heap);
IDXGISwapChain3_Release(G.swapchain); IDXGISwapChain3_Release(G.swapchain);
@ -505,16 +510,16 @@ INTERNAL void dx12_init_base(struct sys_window *window)
} }
/* Create swacphain RTVs */ /* 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; D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = ZI;
ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(swapchain_rtv_heap, &rtv_handle); ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(swapchain_rtv_heap, &rtv_handle);
for (u32 i = 0; i < DX12_SWAPCHAIN_BUFFER_COUNT; ++i) { 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)) { 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; 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_ca = swapchain_ca;
G.swapchain = swapchain; G.swapchain = swapchain;
G.swapchain_rtv_heap = swapchain_rtv_heap; 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); IDXGIFactory6_Release(factory);
scratch_end(scratch); scratch_end(scratch);
@ -578,8 +583,8 @@ INTERNAL void dx12_init_pipelines(void)
/* Material pipeline */ /* Material pipeline */
{ {
.name = "material", .name = "material",
.vs = { "sh/material.hlsl", "sh_material_vs" }, .vs = { "sh/material.hlsl", "vs" },
.ps = { "sh/material.hlsl", "sh_material_ps" } .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(); struct work_slate ws = work_slate_begin();
work_slate_push_task(&ws, shader_compile_task, &vs); work_slate_push_task(&ws, shader_compile_task, &vs);
work_slate_push_task(&ws, shader_compile_task, &ps); 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); work_wait(work);
success = vs.success && ps.success; 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 * 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 * could reuse the shader blob), however we'd like to verify that the
* root signature exists and matches between shaders. */ * root signature exists and matches between shaders. */
ID3D10Blob *rs_blob = NULL; ID3D10Blob *rootsig_blob = NULL;
if (success) { if (success) {
__profscope(Validate root signatures); __profscope(Validate root signatures);
char *vs_rs_data = NULL; char *vs_rootsig_data = NULL;
char *ps_rs_data = NULL; char *ps_rootsig_data = NULL;
u32 vs_rs_data_len = 0; u32 vs_rootsig_data_len = 0;
u32 ps_rs_data_len = 0; u32 ps_rootsig_data_len = 0;
ID3D10Blob *vs_rs_blob = NULL; ID3D10Blob *vs_rootsig_blob = NULL;
ID3D10Blob *ps_rs_blob = NULL; ID3D10Blob *ps_rootsig_blob = NULL;
D3DGetBlobPart(ID3D10Blob_GetBufferPointer(vs.blob), ID3D10Blob_GetBufferSize(vs.blob), D3D_BLOB_ROOT_SIGNATURE, 0, &vs_rs_blob); 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_rs_blob); D3DGetBlobPart(ID3D10Blob_GetBufferPointer(ps.blob), ID3D10Blob_GetBufferSize(ps.blob), D3D_BLOB_ROOT_SIGNATURE, 0, &ps_rootsig_blob);
if (vs_rs_blob) { if (vs_rootsig_blob) {
vs_rs_data = ID3D10Blob_GetBufferPointer(vs_rs_blob); vs_rootsig_data = ID3D10Blob_GetBufferPointer(vs_rootsig_blob);
vs_rs_data_len = ID3D10Blob_GetBufferSize(vs_rs_blob); vs_rootsig_data_len = ID3D10Blob_GetBufferSize(vs_rootsig_blob);
} }
if (ps_rs_blob) { if (ps_rootsig_blob) {
ps_rs_data = ID3D10Blob_GetBufferPointer(ps_rs_blob); ps_rootsig_data = ID3D10Blob_GetBufferPointer(ps_rootsig_blob);
ps_rs_data_len = ID3D10Blob_GetBufferSize(ps_rs_blob); ps_rootsig_data_len = ID3D10Blob_GetBufferSize(ps_rootsig_blob);
} }
if (vs_rs_data_len == 0) { if (vs_rootsig_data_len == 0) {
success = false; success = false;
error_str = LIT("Vertex shader is missing root signature"); 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; success = false;
error_str = LIT("Pixel shader is missing root signature"); 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; success = false;
error_str = LIT("Root signature mismatch between vertex and pixel shader"); error_str = LIT("Root signature mismatch between vertex and pixel shader");
} else { } else {
rs_blob = vs_rs_blob; rootsig_blob = vs_rootsig_blob;
} }
if (ps_rs_blob) { if (ps_rootsig_blob) {
ID3D10Blob_Release(ps_rs_blob); ID3D10Blob_Release(ps_rootsig_blob);
} }
} }
/* Create root signature */ /* Create root signature */
ID3D12RootSignature *rs = NULL; ID3D12RootSignature *rootsig = NULL;
if (success) { if (success) {
__profscope(Create root signature); __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)) { if (FAILED(hr)) {
error_str = LIT("Failed to create root signature"); error_str = LIT("Failed to create root signature");
success = false; success = false;
@ -926,7 +931,7 @@ INTERNAL WORK_TASK_FUNC_DEF(pipeline_load_task, load_arg_raw)
/* PSO */ /* PSO */
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { 0 }; D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { 0 };
pso_desc.pRootSignature = rs; pso_desc.pRootSignature = rootsig;
if (vs.success) { if (vs.success) {
pso_desc.VS.pShaderBytecode = ID3D10Blob_GetBufferPointer(vs.blob); pso_desc.VS.pShaderBytecode = ID3D10Blob_GetBufferPointer(vs.blob);
pso_desc.VS.BytecodeLength = ID3D10Blob_GetBufferSize(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->pso = pso;
pipeline->rs = rs; pipeline->rootsig = rootsig;
result->elapsed = sys_time_ns() - start_ns; result->elapsed = sys_time_ns() - start_ns;
resource_close(&vs_res); resource_close(&vs_res);
if (!ps_res_is_shared) { if (!ps_res_is_shared) {
resource_close(&ps_res); resource_close(&ps_res);
} }
if (rs_blob) { if (rootsig_blob) {
ID3D10Blob_Release(rs_blob); ID3D10Blob_Release(rootsig_blob);
} }
if (vs.blob) { if (vs.blob) {
ID3D10Blob_Release(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); 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); work_wait(work);
return results; 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; struct gpu_handle res = ZI;
return res; 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; (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 #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) void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_params params)
{ {
(UNUSED)gpu_dispatch_state; (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 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 */ /* Material pass */
{ {
struct pipeline *pipeline = dx12_get_pipeline(pipeline_scope, LIT("material")); 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); pipeline_scope_end(pipeline_scope);

View File

@ -74,9 +74,9 @@ GLOBAL struct {
struct gpu_handle user_texture; struct gpu_handle user_texture;
struct gpu_handle backbuffer_texture; struct gpu_handle backbuffer_texture;
struct gpu_handle world_gpu_cmd_list; struct gpu_handle world_gpu_plan;
struct gpu_handle user_gpu_cmd_list; struct gpu_handle user_gpu_plan;
struct gpu_handle backbuffer_gpu_cmd_list; struct gpu_handle backbuffer_gpu_plan;
struct gpu_handle user_dispatch_state; struct gpu_handle user_dispatch_state;
struct gpu_handle backbuffer_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 */ /* GPU handles */
G.world_to_user_xf = XFORM_IDENT; G.world_to_user_xf = XFORM_IDENT;
G.world_gpu_cmd_list = gpu_cmd_list_alloc(); G.world_gpu_plan = gpu_plan_alloc();
G.user_gpu_cmd_list = gpu_cmd_list_alloc(); G.user_gpu_plan = gpu_plan_alloc();
G.backbuffer_gpu_cmd_list = gpu_cmd_list_alloc(); G.backbuffer_gpu_plan = gpu_plan_alloc();
G.user_dispatch_state = gpu_dispatch_state_alloc(); G.user_dispatch_state = gpu_dispatch_state_alloc();
G.backbuffer_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); x_ray = v2_mul(x_ray, ray_scale);
y_ray = v2_mul(y_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_plan, 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, y_ray, thickness, arrowhead_len, color_y);
//u32 color_quad = RGBA_F(0, 1, 1, 0.3); //u32 color_quad = RGBA_F(0, 1, 1, 0.3);
//struct quad quad = quad_from_rect(RECT(0, 0, 1, -1)); //struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
//quad = xform_mul_quad(xf, quad_scale(quad, 0.075f)); //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) 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); struct v2 vel_ray = xform_basis_mul_v2(G.world_to_user_xf, velocity);
if (v2_len(vel_ray) > 0.00001) { 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) { if (log->level <= level) {
/* Draw background */ /* Draw background */
u32 color = colors[log->level][log->color_index]; 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 */ /* Draw text */
struct string text = log->msg; 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 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; struct rect draw_bounds = bounds;
draw_bounds.x -= bg_margin; draw_bounds.x -= bg_margin;
@ -1037,8 +1037,8 @@ INTERNAL void user_update(void)
* Set draw views * Set draw views
* ========================== */ * ========================== */
draw_set_view(G.world_gpu_cmd_list, G.world_to_user_xf); draw_set_view(G.world_gpu_plan, G.world_to_user_xf);
draw_set_view(G.user_gpu_cmd_list, XFORM_IDENT); draw_set_view(G.user_gpu_plan, XFORM_IDENT);
/* ========================== * /* ========================== *
* Update listener from view * 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); 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 color0 = RGBA_F(0.17f, 0.17f, 0.17f, 1.f);
u32 color1 = RGBA_F(0.15f, 0.15f, 0.15f, 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; struct gpu_cmd_params cmd = ZI;
cmd.kind = GPU_CMD_KIND_TEST; cmd.kind = GPU_CMD_KIND_TEST;
cmd.test.xf = xform_from_rect(RECT_FROM_V2(pos, size)); 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 #if 0
@ -1260,9 +1260,9 @@ INTERNAL void user_update(void)
u32 color_end = RGBA_F(1, 0.8, 0.4, opacity_b); u32 color_end = RGBA_F(1, 0.8, 0.4, opacity_b);
if (opacity_b > 0.99f) { 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; u32 tint = ent->sprite_tint;
struct sprite_sheet_frame frame = sprite_sheet_get_frame(sheet, ent->animation_frame); 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); 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 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 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); 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); u32 color = RGBA_F(1, 0, 1, 0.5);
struct quad quad = quad_from_aabb(aabb); struct quad quad = quad_from_aabb(aabb);
quad = xform_mul_quad(G.world_to_user_xf, quad); 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 */ /* Draw focus arrow */
@ -1340,7 +1340,7 @@ INTERNAL void user_update(void)
start = xform_mul_v2(G.world_to_user_xf, start); start = xform_mul_v2(G.world_to_user_xf, start);
struct v2 end = v2_add(xf.og, ent->control.focus); struct v2 end = v2_add(xf.og, ent->control.focus);
end = xform_mul_v2(G.world_to_user_xf, end); 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 #if 0
@ -1366,16 +1366,16 @@ INTERNAL void user_update(void)
struct quad quad = quad_from_rect(slice.rect); struct quad quad = quad_from_rect(slice.rect);
quad = xform_mul_quad(sprite_xform, quad); quad = xform_mul_quad(sprite_xform, quad);
quad = xform_mul_quad(G.world_to_user_xf, 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) { if (slice.has_ray) {
struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir); struct v2 ray = xform_basis_mul_v2(sprite_xform, slice.dir);
ray = xform_basis_mul_v2(G.world_to_user_xf, ray); ray = xform_basis_mul_v2(G.world_to_user_xf, ray);
ray = v2_with_len(ray, 25); 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; f32 radius = 3;
struct v2 point = xform_mul_v2(e1_xf, ent->weld_joint_data.point_local_e1); 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); 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; DEBUGBREAKABLE;
} }
@ -1407,8 +1407,8 @@ INTERNAL void user_update(void)
struct v2 point_end = G.world_cursor; struct v2 point_end = G.world_cursor;
point_start = xform_mul_v2(G.world_to_user_xf, point_start); point_start = xform_mul_v2(G.world_to_user_xf, point_start);
point_end = xform_mul_v2(G.world_to_user_xf, point_end); 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_arrow_line(G.user_gpu_plan, point_start, point_end, 3, 10, color);
draw_circle(G.user_gpu_cmd_list, point_start, 4, color, 10); draw_circle(G.user_gpu_plan, point_start, 4, color, 10);
} }
/* Draw collider */ /* Draw collider */
@ -1420,13 +1420,13 @@ INTERNAL void user_update(void)
/* Draw collider using support points */ /* Draw collider using support points */
u32 detail = 32; u32 detail = 32;
struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf); 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 */ /* Draw collider shape points */
for (u32 i = 0; i < collider.count; ++i) { 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]); 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) { 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; struct v2 end = collider_get_support_point(&collider, xf, v2_neg(xf.by)).p;
start = xform_mul_v2(G.world_to_user_xf, start); start = xform_mul_v2(G.world_to_user_xf, start);
end = xform_mul_v2(G.world_to_user_xf, end); 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 #if 0
/* Draw support point at focus dir */ /* Draw support point at focus dir */
{ {
struct v2 p = collider_support_point(&collider, xf, ent->control.focus); struct v2 p = collider_support_point(&collider, xf, ent->control.focus);
p = xform_mul_v2(G.world_to_user_xf, p); 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 #endif
} }
@ -1466,7 +1466,7 @@ INTERNAL void user_update(void)
/* Draw point */ /* 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 */ /* Draw normal */
@ -1476,7 +1476,7 @@ INTERNAL void user_update(void)
f32 arrow_height = 5; f32 arrow_height = 5;
struct v2 start = xform_mul_v2(G.world_to_user_xf, dbg_pt); 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))); 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 #if 0
/* Draw contact info */ /* Draw contact info */
@ -1506,7 +1506,7 @@ INTERNAL void user_update(void)
FMT_UINT(data->num_points)); 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 #endif
@ -1534,8 +1534,8 @@ INTERNAL void user_update(void)
u32 color = RGBA_F(1, 1, 0, 0.5); u32 color = RGBA_F(1, 1, 0, 0.5);
struct v2 a = xform_mul_v2(G.world_to_user_xf, data->closest0); 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); 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_plan, a, radius, color, 10);
draw_circle(G.user_gpu_cmd_list, b, radius, color, 10); draw_circle(G.user_gpu_plan, b, radius, color, 10);
} }
#endif #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 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); 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_line(G.user_gpu_plan, a, b, thickness, color_line);
draw_circle(G.user_gpu_cmd_list, a, radius, color_a, 10); draw_circle(G.user_gpu_plan, a, radius, color_a, 10);
draw_circle(G.user_gpu_cmd_list, b, radius, color_b, 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 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); 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_line(G.user_gpu_plan, 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_plan, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_cmd_list, b_clipped, radius, color_b_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 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); 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_line(G.user_gpu_plan, a, b, thickness, color_line);
draw_circle(G.user_gpu_cmd_list, a, radius, color_a, 10); draw_circle(G.user_gpu_plan, a, radius, color_a, 10);
draw_circle(G.user_gpu_cmd_list, b, radius, color_b, 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 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); 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_line(G.user_gpu_plan, 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_plan, a_clipped, radius, color_a_clipped, 10);
draw_circle(G.user_gpu_cmd_list, b_clipped, radius, color_b_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)); 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 #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); 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]); 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_line(G.user_gpu_plan, m, true, thickness, color);
//draw_poly(G.user_gpu_cmd_list, m, color); //draw_poly(G.user_gpu_plan, m, color);
} }
/* Draw cloud */ /* Draw cloud */
@ -1643,7 +1643,7 @@ INTERNAL void user_update(void)
for (u64 i = 0; i < m.count; ++i) { for (u64 i = 0; i < m.count; ++i) {
struct v2 p = xform_mul_v2(G.world_to_user_xf, m.points[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 .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]); 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_line(G.user_gpu_plan, 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); for (u64 i = 0; i < m.count; ++i) draw_circle(G.user_gpu_plan, m.points[i], 10, color, 10);
} }
/* Draw simplex */ /* Draw simplex */
@ -1676,18 +1676,18 @@ INTERNAL void user_update(void)
if (simplex.len >= 1) { if (simplex.len >= 1) {
u32 color = simplex.len == 1 ? color_first : (simplex.len == 2 ? color_second : color_third); 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) { if (simplex.len >= 2) {
u32 color = simplex.len == 2 ? color_first : color_second; 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) { if (simplex.len >= 3) {
u32 color = color_first; 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) { 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; f32 arrowhead_height = 10;
struct v2 start = xform_mul_v2(G.world_to_user_xf, V2(0, 0)); 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)); 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 #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 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); 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 */ /* Draw camera rect */
@ -1726,7 +1726,7 @@ INTERNAL void user_update(void)
struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED); struct quad quad = xform_mul_quad(quad_xf, QUAD_UNIT_SQUARE_CENTERED);
quad = xform_mul_quad(G.world_to_user_xf, quad); 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); arena_temp_end(temp);
@ -1744,7 +1744,7 @@ INTERNAL void user_update(void)
struct v2 size = V2(t->width, t->height); struct v2 size = V2(t->width, t->height);
struct xform xf = XFORM_TRS(.t = crosshair_pos, .s = size); 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); 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)); 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; struct string dbg_text = ZI;
dbg_text.text = arena_push_dry(temp.arena, u8); dbg_text.text = arena_push_dry(temp.arena, u8);
dbg_text.len += get_ent_debug_text(temp.arena, ent).len; 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); arena_temp_end(temp);
} }
@ -2042,16 +2042,16 @@ INTERNAL void user_update(void)
//text.len += string_copy(temp.arena, LIT("\n")).len; //text.len += string_copy(temp.arena, LIT("\n")).len;
#if COLLIDER_DEBUG #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; pos.y += spacing;
#endif #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_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_cmd_list, font, pos, text); //draw_text(G.user_gpu_plan, font, pos, text);
struct v2 pos = V2(10, G.user_size.y); struct v2 pos = V2(10, G.user_size.y);
enum draw_text_offset_y offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM; 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); 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 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); 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 */ /* Send plans to GPU */
gpu_submit_cmds(G.world_gpu_cmd_list); gpu_submit_plan(G.world_gpu_plan);
gpu_submit_cmds(G.user_gpu_cmd_list); gpu_submit_plan(G.user_gpu_plan);
gpu_submit_cmds(G.backbuffer_gpu_cmd_list); gpu_submit_plan(G.backbuffer_gpu_plan);
/* Clear textures */ /* Clear textures */
gpu_texture_clear(G.user_texture, 0); gpu_texture_clear(G.user_texture, 0);
@ -2115,10 +2115,10 @@ INTERNAL void user_update(void)
/* Render to user texture */ /* 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; struct gpu_dispatch_params params = ZI;
params.cmd_lists.handles = dispatch_cmds; params.plans.handles = plans;
params.cmd_lists.count = ARRAY_COUNT(dispatch_cmds); params.plans.count = ARRAY_COUNT(plans);
params.draw_target = G.user_texture; params.draw_target = G.user_texture;
params.draw_target_viewport = user_viewport; params.draw_target_viewport = user_viewport;
gpu_dispatch(G.user_dispatch_state, params); gpu_dispatch(G.user_dispatch_state, params);
@ -2126,10 +2126,10 @@ INTERNAL void user_update(void)
/* Render to backbuffer texture */ /* 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; struct gpu_dispatch_params params = ZI;
params.cmd_lists.handles = dispatch_cmds; params.plans.handles = plans;
params.cmd_lists.count = ARRAY_COUNT(dispatch_cmds); params.plans.count = ARRAY_COUNT(plans);
params.draw_target = G.backbuffer_texture; params.draw_target = G.backbuffer_texture;
params.draw_target_viewport = backbuffer_viewport; params.draw_target_viewport = backbuffer_viewport;
gpu_dispatch(G.backbuffer_dispatch_state, params); gpu_dispatch(G.backbuffer_dispatch_state, params);