dx12 progress

This commit is contained in:
jacob 2025-06-17 15:21:26 -05:00
parent 68c116095c
commit 29ec298b48
20 changed files with 990 additions and 434 deletions

View File

@ -562,7 +562,7 @@ void OnBuild(StringList cli_args)
if (arg_msvc) { if (arg_msvc) {
StringListAppend(&perm, &compile_args, Lit("/fsanitize=address")); StringListAppend(&perm, &compile_args, Lit("/fsanitize=address"));
} else { } else {
StringListAppend(&perm, &compile_and_link_args, Lit("-fsanitize=address -shared-libasan")); StringListAppend(&perm, &compile_and_link_args, Lit("-fsanitize=address"));
} }
} }

View File

@ -19,8 +19,14 @@ struct sh_material_instance {
#define ROOTSIG \ #define ROOTSIG \
"CBV(b0), " \ "CBV(b0), " \
"DescriptorTable(SRV(t0), SRV(t1)), " \ "SRV(t0), " \
"DescriptorTable(Sampler(s0))" "DescriptorTable(SRV(t1, numDescriptors = unbounded)), " \
"StaticSampler(s0, " \
"filter = FILTER_MIN_MAG_MIP_POINT, " \
"addressU = TEXTURE_ADDRESS_CLAMP, " \
"addressV = TEXTURE_ADDRESS_CLAMP, " \
"addressW = TEXTURE_ADDRESS_CLAMP, " \
"maxAnisotropy = 1)"
cbuffer cbuff : register(b0) cbuffer cbuff : register(b0)
{ {
@ -33,6 +39,8 @@ Texture2D g_texture : register(t1);
SamplerState g_sampler : register(s0); SamplerState g_sampler : register(s0);
/* TODO: Ensure `NonUniformResourceIndex` is used once bindless */
/* ========================== * /* ========================== *
* Vertex shader * Vertex shader
* ========================== */ * ========================== */
@ -60,16 +68,12 @@ struct vs_output vs(struct vs_input input)
{ {
struct sh_material_instance instance = g_instances[g_constants.instance_offset + input.SV_InstanceID]; struct sh_material_instance instance = g_instances[g_constants.instance_offset + input.SV_InstanceID];
float2 vert = g_quad_verts[input.SV_VertexID]; float2 vert = g_quad_verts[input.SV_VertexID];
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.SV_Position = clip_pos; output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1));
output.uv = uv; output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
output.tint_lin = tint_lin; output.tint_lin = linear_from_srgb32(instance.tint_srgb);
return output; return output;
} }

View File

@ -29,7 +29,6 @@
struct exit_callback { struct exit_callback {
app_exit_callback_func *func; app_exit_callback_func *func;
struct exit_callback *next; struct exit_callback *next;
struct sys_thread thread;
}; };
GLOBAL struct { GLOBAL struct {
@ -105,12 +104,6 @@ INTERNAL struct sys_window_settings default_window_settings(struct sys_window *w
* Exit callbacks * Exit callbacks
* ========================== */ * ========================== */
INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(exit_callback_thread_entry_point, vcallback)
{
struct exit_callback *callback = (struct exit_callback *)vcallback;
callback->func();
}
void app_register_exit_callback(app_exit_callback_func *func) void app_register_exit_callback(app_exit_callback_func *func)
{ {
struct sys_lock lock = sys_mutex_lock_e(&G.exit_callbacks_mutex); struct sys_lock lock = sys_mutex_lock_e(&G.exit_callbacks_mutex);
@ -351,36 +344,22 @@ void app_entry_point(struct string args_str)
/* Wait for app_exit() */ /* Wait for app_exit() */
sync_flag_wait(&G.exit_sf); sync_flag_wait(&G.exit_sf);
/* Call exit callbacks */ /* Run exit callbacks */
/* FIXME: Only wait on threads for a certain period of time before /* FIXME: Only wait on shutdown for a certain period of time before
* forcing process exit (to prevent process hanging in the background * forcing process exit (to prevent process hanging in the background
* when a thread gets stuck) */ * if something gets stuck) */
{ {
__profscope(Run exit callbacks);
struct sys_lock lock = sys_mutex_lock_e(&G.exit_callbacks_mutex); struct sys_lock lock = sys_mutex_lock_e(&G.exit_callbacks_mutex);
for (struct exit_callback *callback = G.exit_callbacks_head; callback; callback = callback->next) {
/* Start callback threads */ callback->func();
/* TODO: Create these threads when the callbacks are initially registered and have them wait on exit */
{
__profscope(app_start_exit_callbacks);
for (struct exit_callback *callback = G.exit_callbacks_head; callback; callback = callback->next) {
callback->thread = sys_thread_alloc(&exit_callback_thread_entry_point, callback, LIT("[P1] Exit callback thread"));
}
} }
/* Wait on callback threads */
{
__profscope(app_wait_on_exit_callbacks);
for (struct exit_callback *callback = G.exit_callbacks_head; callback; callback = callback->next) {
sys_thread_wait_release(&callback->thread);
}
}
sys_mutex_unlock(&lock); sys_mutex_unlock(&lock);
} }
/* Write window settings to file */ /* Write window settings to file */
{ {
__profscope(app_write_to_settings_file); __profscope(Write settings file);
struct arena_temp temp = arena_temp_begin(scratch.arena); struct arena_temp temp = arena_temp_begin(scratch.arena);
struct string window_settings_path = app_write_path_cat(temp.arena, settings_file_name); struct string window_settings_path = app_write_path_cat(temp.arena, settings_file_name);

View File

@ -20,14 +20,14 @@ FORCE_INLINE i64 atomic_i64_eval_add(struct atomic_i64 *x, i64 a) { return (i64)
FORCE_INLINE u32 atomic_u32_eval(struct atomic_u32 *x) { return (u32)_InterlockedCompareExchange((volatile long *)&x->_v, 0, 0); } FORCE_INLINE u32 atomic_u32_eval(struct atomic_u32 *x) { return (u32)_InterlockedCompareExchange((volatile long *)&x->_v, 0, 0); }
FORCE_INLINE u32 atomic_u32_eval_exchange(struct atomic_u32 *x, u32 e) { return (u32)_InterlockedExchange((volatile long *)&x->_v, (long)e); } FORCE_INLINE u32 atomic_u32_eval_exchange(struct atomic_u32 *x, u32 e) { return (u32)_InterlockedExchange((volatile long *)&x->_v, (long)e); }
FORCE_INLINE u32 atomic_u32_eval_compare_exchange(struct atomic_u32 *x, u32 c, u32 e) { return (u32)_InterlockedCompareExchange((volatile long *)&x->_v, (long)e, (long)c); } FORCE_INLINE u32 atomic_u32_eval_compare_exchange(struct atomic_u32 *x, u32 c, u32 e) { return (u32)_InterlockedCompareExchange((volatile long *)&x->_v, (long)e, (long)c); }
FORCE_INLINE u32 atomic_u32_eval_xor(struct atomic_u32 *x, u32 c) { return (u32)_InterlockedXor((volatile long *)&x->_v, c); } FORCE_INLINE u32 atomic_u32_eval_xor(struct atomic_u32 *x, u32 c) { return (u32)_InterlockedXor((volatile long *)&x->_v, (long)c); }
FORCE_INLINE u32 atomic_u32_eval_add_u32(struct atomic_u32 *x, u32 a) { return (u32)_InterlockedExchangeAdd((volatile long *)&x->_v, (long)a); } FORCE_INLINE u32 atomic_u32_eval_add_u32(struct atomic_u32 *x, u32 a) { return (u32)_InterlockedExchangeAdd((volatile long *)&x->_v, (long)a); }
FORCE_INLINE u32 atomic_u32_eval_add_i32(struct atomic_u32 *x, i32 a) { return (u32)_InterlockedExchangeAdd((volatile long *)&x->_v, (long)a); } FORCE_INLINE u32 atomic_u32_eval_add_i32(struct atomic_u32 *x, i32 a) { return (u32)_InterlockedExchangeAdd((volatile long *)&x->_v, (long)a); }
FORCE_INLINE u64 atomic_u64_eval(struct atomic_u64 *x) { return (u64)_InterlockedCompareExchange64((volatile i64 *)&x->_v, 0, 0); } FORCE_INLINE u64 atomic_u64_eval(struct atomic_u64 *x) { return (u64)_InterlockedCompareExchange64((volatile i64 *)&x->_v, 0, 0); }
FORCE_INLINE u64 atomic_u64_eval_exchange(struct atomic_u64 *x, u64 e) { return (u64)_InterlockedExchange64((volatile i64 *)&x->_v, (i64)e); } FORCE_INLINE u64 atomic_u64_eval_exchange(struct atomic_u64 *x, u64 e) { return (u64)_InterlockedExchange64((volatile i64 *)&x->_v, (i64)e); }
FORCE_INLINE u64 atomic_u64_eval_compare_exchange(struct atomic_u64 *x, u64 c, u64 e) { return (u64)_InterlockedCompareExchange64((volatile i64 *)&x->_v, (i64)e, (i64)c); } FORCE_INLINE u64 atomic_u64_eval_compare_exchange(struct atomic_u64 *x, u64 c, u64 e) { return (u64)_InterlockedCompareExchange64((volatile i64 *)&x->_v, (i64)e, (i64)c); }
FORCE_INLINE u32 atomic_u64_eval_xor(struct atomic_u64 *x, u64 c) { return (u64)_InterlockedXor64((volatile i64 *)&x->_v, c); } FORCE_INLINE u32 atomic_u64_eval_xor(struct atomic_u64 *x, u64 c) { return (u64)_InterlockedXor64((volatile i64 *)&x->_v, (i64)c); }
FORCE_INLINE u64 atomic_u64_eval_add_u64(struct atomic_u64 *x, u64 a) { return (u64)_InterlockedExchangeAdd64((volatile i64 *)&x->_v, (i64)a); } FORCE_INLINE u64 atomic_u64_eval_add_u64(struct atomic_u64 *x, u64 a) { return (u64)_InterlockedExchangeAdd64((volatile i64 *)&x->_v, (i64)a); }
FORCE_INLINE u64 atomic_u64_eval_add_i64(struct atomic_u64 *x, i64 a) { return (u64)_InterlockedExchangeAdd64((volatile i64 *)&x->_v, (i64)a); } FORCE_INLINE u64 atomic_u64_eval_add_i64(struct atomic_u64 *x, i64 a) { return (u64)_InterlockedExchangeAdd64((volatile i64 *)&x->_v, (i64)a); }

View File

@ -154,8 +154,8 @@ extern "C" {
#if ASAN #if ASAN
void __asan_poison_memory_region(void const volatile *, size_t); void __asan_poison_memory_region(void const volatile *, size_t);
void __asan_unpoison_memory_region(void const volatile *add, size_t); void __asan_unpoison_memory_region(void const volatile *add, size_t);
# define ASAN_POISON(addr, size) __asan_poison_memory_region((addr), (size)); # define ASAN_POISON(addr, size) __asan_poison_memory_region((addr), (size))
# define ASAN_UNPOISON(addr, size) __asan_unpoison_memory_region((addr), (size)); # define ASAN_UNPOISON(addr, size) __asan_unpoison_memory_region((addr), (size))
#else #else
# define ASAN_POISON(addr, size) # define ASAN_POISON(addr, size)
# define ASAN_UNPOISON(addr, size) # define ASAN_UNPOISON(addr, size)
@ -281,25 +281,25 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#endif #endif
/* Color */ /* Color */
#define RGB(r, g, b) RGBA((r), (g), (b), 0xFF) #define RGB32(r, g, b) RGBA32((r), (g), (b), 0xFF)
#define RGBA(r, g, b, a) (u32)((u32)(r) | ((u32)(g) << 8) | ((u32)(b) << 16) | ((u32)(a) << 24)) #define RGBA32(r, g, b, a) (u32)((u32)(r) | ((u32)(g) << 8) | ((u32)(b) << 16) | ((u32)(a) << 24))
#define BGR(rgb) ((((rgb >> 0) & 0xFF) << 16) | (((rgb >> 8) & 0xFF) << 8) | (((rgb >> 16) & 0xFF) << 0)) #define BGR32(rgb) ((((rgb >> 0) & 0xFF) << 16) | (((rgb >> 8) & 0xFF) << 8) | (((rgb >> 16) & 0xFF) << 0))
#define _RGB_U8_FROM_F(fl) ((u8)((fl * 255.0) + 0.5)) #define _RGB32_U8_FROM_F(fl) ((u8)((fl * 255.0) + 0.5))
#define RGBA_F(r, g, b, a) RGBA(_RGB_U8_FROM_F((r)), _RGB_U8_FROM_F((g)), _RGB_U8_FROM_F((b)), _RGB_U8_FROM_F((a))) #define RGBA32_F(r, g, b, a) RGBA32(_RGB32_U8_FROM_F((r)), _RGB32_U8_FROM_F((g)), _RGB32_U8_FROM_F((b)), _RGB32_U8_FROM_F((a)))
#define RGB_F(r, g, b) RGBA_F((r), (g), (b), 1.f) #define RGB32_F(r, g, b) RGBA32_F((r), (g), (b), 1.f)
#define ALPHA_F(color, a) ((color) & 0x00FFFFFF) | (_RGB_U8_FROM_F((a)) << 24) #define ALPHA32_F(color, a) ((color) & 0x00FFFFFF) | (_RGB32_U8_FROM_F((a)) << 24)
/* Color defines */ /* Color defines */
#define COLOR_WHITE RGB(0xFF, 0xFF, 0xFF) #define COLOR_WHITE RGB32(0xFF, 0xFF, 0xFF)
#define COLOR_BLACK RGB(0x00, 0x00, 0x00) #define COLOR_BLACK RGB32(0x00, 0x00, 0x00)
#define COLOR_RED RGB(0xFF, 0x00, 0x00) #define COLOR_RED RGB32(0xFF, 0x00, 0x00)
#define COLOR_GREEN RGB(0x00, 0xFF, 0x00) #define COLOR_GREEN RGB32(0x00, 0xFF, 0x00)
#define COLOR_BLUE RGB(0x00, 0x00, 0xFF) #define COLOR_BLUE RGB32(0x00, 0x00, 0xFF)
#define COLOR_YELLOW RGB(0xFF, 0xFF, 0x00) #define COLOR_YELLOW RGB32(0xFF, 0xFF, 0x00)
#define COLOR_ORANGE RGB(0xFF, 0xA5, 0x00) #define COLOR_ORANGE RGB32(0xFF, 0xA5, 0x00)
#define COLOR_PURPLE RGB(0xFF, 0x00, 0XFF) #define COLOR_PURPLE RGB32(0xFF, 0x00, 0XFF)
/* Barrier */ /* Barrier */
#if COMPILER_MSVC #if COMPILER_MSVC
@ -348,9 +348,9 @@ typedef i32 b32;
#define I64_MAX (0x7FFFFFFFFFFFFFFFLL) #define I64_MAX (0x7FFFFFFFFFFFFFFFLL)
#define I8_MIN ((i8)-0x80) #define I8_MIN ((i8)-0x80)
#define I16_MIN ((i16)-0x8000) #define I16_MIN ((i16)0x8000)
#define I32_MIN ((i32)-0x80000000) #define I32_MIN ((i32)0x80000000)
#define I64_MIN ((i64)-0x8000000000000000ULL) #define I64_MIN ((i64)0x8000000000000000LL)
GLOBAL const u32 _f32_infinity_u32 = 0x7f800000; GLOBAL const u32 _f32_infinity_u32 = 0x7f800000;
GLOBAL const f32 *_f32_infinity = (f32 *)&_f32_infinity_u32; GLOBAL const f32 *_f32_infinity = (f32 *)&_f32_infinity_u32;
@ -648,14 +648,14 @@ INLINE f64 clamp_f64(f64 v, f64 min, f64 max) { return v < min ? min : v > max ?
# define __prof static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin_callstack( &CAT(__tracy_source_location,__LINE__), TRACY_CALLSTACK, true ); # define __prof static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin_callstack( &CAT(__tracy_source_location,__LINE__), TRACY_CALLSTACK, true );
# define __profscope(name) static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin_callstack( &CAT(__tracy_source_location,__LINE__), TRACY_CALLSTACK, true ); # define __profscope(name) static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin_callstack( &CAT(__tracy_source_location,__LINE__), TRACY_CALLSTACK, true );
# endif # endif
# define __profscope_dx11(dx11_ctx, name, color) static const struct ___tracy_source_location_data CAT(__tracy_gpu_d3d11_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, BGR(color) }; __attribute((cleanup(__prof_dx11_zone_cleanup_func))) TracyCD3D11ZoneCtx __tracy_d3d11_zone_ctx; ___tracy_d3d11_emit_zone_begin( dx11_ctx, &__tracy_d3d11_zone_ctx, &CAT(__tracy_gpu_d3d11_source_location,__LINE__), true); # define __profscope_dx11(dx11_ctx, name, color) static const struct ___tracy_source_location_data CAT(__tracy_gpu_d3d11_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, BGR32(color) }; __attribute((cleanup(__prof_dx11_zone_cleanup_func))) TracyCD3D11ZoneCtx __tracy_d3d11_zone_ctx; ___tracy_d3d11_emit_zone_begin( dx11_ctx, &__tracy_d3d11_zone_ctx, &CAT(__tracy_gpu_d3d11_source_location,__LINE__), true);
#endif #endif
INLINE void __prof_zone_cleanup_func(TracyCZoneCtx *ctx) { TracyCZoneEnd(*ctx); } INLINE void __prof_zone_cleanup_func(TracyCZoneCtx *ctx) { TracyCZoneEnd(*ctx); }
INLINE void __prof_dx11_zone_cleanup_func(TracyCD3D11ZoneCtx *ctx) { ___tracy_d3d11_emit_zone_end(*ctx); } INLINE void __prof_dx11_zone_cleanup_func(TracyCD3D11ZoneCtx *ctx) { ___tracy_d3d11_emit_zone_end(*ctx); }
#define __profalloc(ptr, size) TracyCAlloc((ptr), (size)) #define __profalloc(ptr, size) TracyCAlloc((ptr), (size))
#define __proffree(ptr) TracyCFree((ptr)) #define __proffree(ptr) TracyCFree((ptr))
#define __profmsg(txt, len, col) TracyCMessageC((txt), (len), BGR(col)); #define __profmsg(txt, len, col) TracyCMessageC((txt), (len), BGR32(col));
#define __profframe(name) TracyCFrameMarkNamed((name)) #define __profframe(name) TracyCFrameMarkNamed((name))
#define __profthread(name) TracyCSetThreadName((name)) #define __profthread(name) TracyCSetThreadName((name))
@ -684,7 +684,7 @@ enum __prof_plot_type {
__prof_plot_type_percentage = TracyPlotFormatPercentage, __prof_plot_type_percentage = TracyPlotFormatPercentage,
__prof_plot_type_watt = TracyPlotFormatWatt __prof_plot_type_watt = TracyPlotFormatWatt
}; };
#define __prof_plot_init(name, type, step, fill, color) TracyCPlotConfig(name, type, step, fill, BGR(color)) #define __prof_plot_init(name, type, step, fill, color) TracyCPlotConfig(name, type, step, fill, BGR32(color))
#define __prof_plot(name, val) TracyCPlot(name, val) #define __prof_plot(name, val) TracyCPlot(name, val)
#define __prof_plot_i(name, val) TracyCPlotI(name, val) #define __prof_plot_i(name, val) TracyCPlotI(name, val)

View File

@ -80,7 +80,7 @@
#define DX12_TEST 1 #define DX12_TEST 0

View File

@ -119,7 +119,7 @@ struct draw_text_params {
u32 color; u32 color;
enum draw_text_alignment alignment; enum draw_text_alignment alignment;
enum draw_text_offset_x offset_x; enum draw_text_offset_x offset_x;
enum draw_text_offset_x offset_y; enum draw_text_offset_y offset_y;
struct string str; struct string str;
}; };

View File

@ -124,7 +124,7 @@ void gpu_submit_plan(struct gpu_handle gpu_plan);
* ========================== */ * ========================== */
struct gpu_dispatch_params { struct gpu_dispatch_params {
struct gpu_handle_array plans; struct gpu_handle plan;
struct gpu_handle draw_target; struct gpu_handle draw_target;
struct rect draw_target_viewport; struct rect draw_target_viewport;
}; };

View File

@ -968,9 +968,9 @@ INTERNAL void reload_shader(struct dx11_shader *old_shader, struct dx11_shader_d
*old_shader = new_shader; *old_shader = new_shader;
} else { } else {
error_msg = string_format(scratch.arena, error_msg = string_format(scratch.arena,
LIT("Failed to compile shader \"%F\":\n%F"), LIT("Failed to compile shader \"%F\":\n%F"),
FMT_STR(name), FMT_STR(name),
FMT_STR(comp_error)); FMT_STR(comp_error));
shader_release(&new_shader); shader_release(&new_shader);
} }
} else { } else {
@ -1153,9 +1153,9 @@ struct v2i32 gpu_texture_get_size(struct gpu_handle texture)
* Dx11 buffer * Dx11 buffer
* ========================== */ * ========================== */
/* TODO: Buffer caching based on size */ /* TODO: Buffer caching based on size */
/* NOTE: If initial_data is not provided, then ByteWidth will be ignored (set dynamically when buffer grows) */ /* NOTE: If initial_data is not provided, then ByteWidth will be ignored (set dynamically when buffer grows) */
INTERNAL struct dx11_buffer *dx11_buffer_alloc(struct D3D11_BUFFER_DESC desc, D3D11_SUBRESOURCE_DATA *initial_data) INTERNAL struct dx11_buffer *dx11_buffer_alloc(struct D3D11_BUFFER_DESC desc, D3D11_SUBRESOURCE_DATA *initial_data)
{ {
__prof; __prof;
@ -1437,8 +1437,8 @@ void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params)
struct dx11_cmd *cmd = plan->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) ||
(cmd->texture.texture.v != params.texture.texture.v))) { (cmd->texture.texture.v != params.texture.texture.v))) {
/* Cannot batch */ /* Cannot batch */
cmd = NULL; cmd = NULL;
} }
@ -1656,9 +1656,10 @@ INTERNAL void dx11_unbind(u32 flags)
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)
{ {
__prof; __prof;
__profscope_dx11(G.profiling_ctx, Dispatch, RGB_F(0.5, 0.2, 0.2)); __profscope_dx11(G.profiling_ctx, Dispatch, RGB32_F(0.5, 0.2, 0.2));
struct sprite_scope *sprite_scope = sprite_scope_begin(); struct sprite_scope *sprite_scope = sprite_scope_begin();
struct dx11_dispatch_state *state = (struct dx11_dispatch_state *)gpu_dispatch_state.v; struct dx11_dispatch_state *state = (struct dx11_dispatch_state *)gpu_dispatch_state.v;
struct dx11_plan *plan = (struct dx11_plan *)params.plan.v;
struct rect viewport = params.draw_target_viewport; struct rect viewport = params.draw_target_viewport;
@ -1701,141 +1702,91 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
struct mat4x4 vp_matrix = calculate_vp(XFORM_IDENT, viewport.width, viewport.height); struct mat4x4 vp_matrix = calculate_vp(XFORM_IDENT, viewport.width, viewport.height);
{ {
__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, RGB32_F(0.2, 0.5, 0.5));
for (u64 handles_array_index = 0; handles_array_index < params.plans.count; ++handles_array_index) { for (struct dx11_cmd *cmd = plan->gpu_first_cmd; cmd; cmd = cmd->next) {
struct dx11_plan *plan = (struct dx11_plan *)params.plans.handles[handles_array_index]->v; enum gpu_cmd_kind cmd_kind = cmd->kind;
for (struct dx11_cmd *cmd = plan->gpu_first_cmd; cmd; cmd = cmd->next) {
enum gpu_cmd_kind cmd_kind = cmd->kind;
switch (cmd_kind) { switch (cmd_kind) {
default: default:
{ {
/* Unknown cmd kind */ /* Unknown cmd kind */
ASSERT(false); ASSERT(false);
} break; } break;
case GPU_CMD_KIND_DRAW_VIEW: case GPU_CMD_KIND_DRAW_VIEW:
{ {
__profscope(Set draw view); __profscope(Set draw view);
vp_matrix = calculate_vp(cmd->view.xf, viewport.width, viewport.height); vp_matrix = calculate_vp(cmd->view.xf, viewport.width, viewport.height);
} break; } break;
case GPU_CMD_KIND_DRAW_MESH: case GPU_CMD_KIND_DRAW_MESH:
{ {
__profscope(Draw mesh); __profscope(Draw mesh);
__profscope_dx11(G.profiling_ctx, Draw mesh, RGB_F(0.5, 0.2, 0.2)); __profscope_dx11(G.profiling_ctx, Draw mesh, RGB32_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 = plan->buffers.mesh.vertex_buffer; struct dx11_buffer *vertex_buffer = plan->buffers.mesh.vertex_buffer;
struct dx11_buffer *index_buffer = plan->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;
u32 index_count = cmd->mesh.index_count; u32 index_count = cmd->mesh.index_count;
/* Bind shader */ /* Bind shader */
ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0); ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0);
ID3D11DeviceContext_PSSetShader(G.devcon, shader->ps, 0, 0); ID3D11DeviceContext_PSSetShader(G.devcon, shader->ps, 0, 0);
ID3D11DeviceContext_IASetInputLayout(G.devcon, shader->input_layout); ID3D11DeviceContext_IASetInputLayout(G.devcon, shader->input_layout);
/* Fill & bind constant buffer */ /* Fill & bind constant buffer */
{ {
struct dx11_mesh_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_mesh_uniform)); struct dx11_mesh_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_mesh_uniform));
uniform->vp = vp_matrix; uniform->vp = vp_matrix;
dx11_buffer_submit(constant_buffer); dx11_buffer_submit(constant_buffer);
}
ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
ID3D11DeviceContext_PSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
/* Bind vertex buffer */
u32 zero = 0;
u32 stride = sizeof(struct dx11_mesh_vertex);
ID3D11DeviceContext_IASetVertexBuffers(G.devcon, 0, 1, &vertex_buffer->gpu_buffer, &stride, &zero);
ID3D11DeviceContext_IASetIndexBuffer(G.devcon, index_buffer->gpu_buffer, DXGI_FORMAT_R32_UINT, zero);
/* Bind RTVs */
ID3D11RenderTargetView *rtvs[] = { final_tex->rtv };
ID3D11DeviceContext_OMSetRenderTargets(G.devcon, ARRAY_COUNT(rtvs), rtvs, NULL);
/* Draw */
ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3D11DeviceContext_DrawIndexed(G.devcon, index_count, index_offset, vertex_offset);
/* Unbind */
dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_IA | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_RTV);
} }
} break; ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
ID3D11DeviceContext_PSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
case GPU_CMD_KIND_DRAW_TEXTURE: /* Bind vertex buffer */
{ u32 zero = 0;
__profscope(Draw texture); u32 stride = sizeof(struct dx11_mesh_vertex);
__profscope_dx11(G.profiling_ctx, Draw texture, RGB_F(0.2, 0.5, 0.2)); ID3D11DeviceContext_IASetVertexBuffers(G.devcon, 0, 1, &vertex_buffer->gpu_buffer, &stride, &zero);
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEXTURE]; ID3D11DeviceContext_IASetIndexBuffer(G.devcon, index_buffer->gpu_buffer, DXGI_FORMAT_R32_UINT, zero);
if (shader->valid) {
struct dx11_texture *texture = NULL;
if (cmd->texture.texture.v) {
/* Load texture if handle is set */
texture = (struct dx11_texture *)cmd->texture.texture.v;
} else if (cmd->texture.sprite.hash) {
/* Otherwise load sprite */
struct sprite_texture *sprite_texture = sprite_texture_from_tag_async(sprite_scope, cmd->texture.sprite);
if (sprite_texture->loaded) {
texture = (struct dx11_texture *)sprite_texture->texture.v;
}
}
if (texture && texture->srv) { /* Bind RTVs */
struct dx11_buffer *instance_buffer = plan->buffers.texture.instance_buffer; ID3D11RenderTargetView *rtvs[] = { final_tex->rtv };
u32 instance_offset = cmd->texture.instance_offset; ID3D11DeviceContext_OMSetRenderTargets(G.devcon, ARRAY_COUNT(rtvs), rtvs, NULL);
u32 instance_count = cmd->texture.instance_count;
/* Bind shader */ /* Draw */
ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0); ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3D11DeviceContext_PSSetShader(G.devcon, shader->ps, 0, 0); ID3D11DeviceContext_DrawIndexed(G.devcon, index_count, index_offset, vertex_offset);
/* Fill & bind constant buffer */ /* Unbind */
{ dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_IA | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_RTV);
struct dx11_texture_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_texture_uniform)); }
uniform->vp = vp_matrix; } break;
uniform->instance_offset = instance_offset;
dx11_buffer_submit(constant_buffer);
}
ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
ID3D11DeviceContext_PSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
/* Bind dummy vertex buffer */ case GPU_CMD_KIND_DRAW_TEXTURE:
u32 zero = 0; {
ID3D11DeviceContext_IASetVertexBuffers(G.devcon, 0, 1, &G.dummy_vertex_buffer->gpu_buffer, &zero, &zero); __profscope(Draw texture);
ID3D11DeviceContext_IASetIndexBuffer(G.devcon, G.quad_index_buffer->gpu_buffer, DXGI_FORMAT_R16_UINT, zero); __profscope_dx11(G.profiling_ctx, Draw texture, RGB32_F(0.2, 0.5, 0.2));
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEXTURE];
/* Bind SRVs */ if (shader->valid) {
ID3D11ShaderResourceView *srvs[] = { instance_buffer->srv, texture->srv }; struct dx11_texture *texture = NULL;
ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs); if (cmd->texture.texture.v) {
ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs); /* Load texture if handle is set */
texture = (struct dx11_texture *)cmd->texture.texture.v;
/* Bind RTVs */ } else if (cmd->texture.sprite.hash) {
ID3D11RenderTargetView *rtvs[] = { final_tex->rtv }; /* Otherwise load sprite */
ID3D11DeviceContext_OMSetRenderTargets(G.devcon, ARRAY_COUNT(rtvs), rtvs, NULL); struct sprite_texture *sprite_texture = sprite_texture_from_tag_async(sprite_scope, cmd->texture.sprite);
if (sprite_texture->loaded) {
/* Draw */ texture = (struct dx11_texture *)sprite_texture->texture.v;
ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3D11DeviceContext_DrawIndexedInstanced(G.devcon, 6, instance_count, 0, 0, 0);
/* Unbind */
dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_SRV | DX11_UNBIND_RTV);
} }
} }
} break;
case GPU_CMD_KIND_DRAW_GRID: if (texture && texture->srv) {
{ struct dx11_buffer *instance_buffer = plan->buffers.texture.instance_buffer;
__profscope(Draw grid); u32 instance_offset = cmd->texture.instance_offset;
__profscope_dx11(G.profiling_ctx, Draw grid, RGB_F(0.2, 0.2, 0.5)); u32 instance_count = cmd->texture.instance_count;
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_GRID];
if (shader->valid) {
struct dx11_buffer *instance_buffer = plan->buffers.grid.instance_buffer;
u32 instance_offset = cmd->grid.instance_offset;
u32 instance_count = cmd->grid.instance_count;
/* Bind shader */ /* Bind shader */
ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0); ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0);
@ -1843,7 +1794,7 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
/* Fill & bind constant buffer */ /* Fill & bind constant buffer */
{ {
struct dx11_grid_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_grid_uniform)); struct dx11_texture_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_texture_uniform));
uniform->vp = vp_matrix; uniform->vp = vp_matrix;
uniform->instance_offset = instance_offset; uniform->instance_offset = instance_offset;
dx11_buffer_submit(constant_buffer); dx11_buffer_submit(constant_buffer);
@ -1857,7 +1808,7 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
ID3D11DeviceContext_IASetIndexBuffer(G.devcon, G.quad_index_buffer->gpu_buffer, DXGI_FORMAT_R16_UINT, zero); ID3D11DeviceContext_IASetIndexBuffer(G.devcon, G.quad_index_buffer->gpu_buffer, DXGI_FORMAT_R16_UINT, zero);
/* Bind SRVs */ /* Bind SRVs */
ID3D11ShaderResourceView *srvs[] = { instance_buffer->srv }; ID3D11ShaderResourceView *srvs[] = { instance_buffer->srv, texture->srv };
ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs); ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs); ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
@ -1867,60 +1818,110 @@ void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_para
/* Draw */ /* Draw */
ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
/* FIXME: Set StartInstanceLocation parameter here rather than passing instance_offset into CBV */
ID3D11DeviceContext_DrawIndexedInstanced(G.devcon, 6, instance_count, 0, 0, 0); ID3D11DeviceContext_DrawIndexedInstanced(G.devcon, 6, instance_count, 0, 0, 0);
/* Unbind */ /* Unbind */
dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_SRV | DX11_UNBIND_RTV); dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_SRV | DX11_UNBIND_RTV);
} }
} break; }
} break;
case GPU_CMD_KIND_TEST: case GPU_CMD_KIND_DRAW_GRID:
{ {
__profscope(Test); __profscope(Draw grid);
__profscope_dx11(G.profiling_ctx, Test, RGB_F(1, 0.2, 1)); __profscope_dx11(G.profiling_ctx, Draw grid, RGB32_F(0.2, 0.2, 0.5));
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEST]; struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_GRID];
if (shader->valid) { if (shader->valid) {
struct dx11_buffer *instance_buffer = plan->buffers.test.instance_buffer; struct dx11_buffer *instance_buffer = plan->buffers.grid.instance_buffer;
u32 instance_offset = cmd->test.instance_offset; u32 instance_offset = cmd->grid.instance_offset;
u32 instance_count = cmd->test.instance_count; u32 instance_count = cmd->grid.instance_count;
/* Bind shader */ /* Bind shader */
ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0); ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0);
ID3D11DeviceContext_PSSetShader(G.devcon, shader->ps, 0, 0); ID3D11DeviceContext_PSSetShader(G.devcon, shader->ps, 0, 0);
/* Fill & bind constant buffer */ /* Fill & bind constant buffer */
{ {
struct dx11_test_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_test_uniform)); struct dx11_grid_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_grid_uniform));
uniform->vp = vp_matrix; uniform->vp = vp_matrix;
uniform->instance_offset = instance_offset; uniform->instance_offset = instance_offset;
dx11_buffer_submit(constant_buffer); dx11_buffer_submit(constant_buffer);
}
ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
ID3D11DeviceContext_PSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
/* Bind dummy vertex buffer */
u32 zero = 0;
ID3D11DeviceContext_IASetVertexBuffers(G.devcon, 0, 1, &G.dummy_vertex_buffer->gpu_buffer, &zero, &zero);
ID3D11DeviceContext_IASetIndexBuffer(G.devcon, G.quad_index_buffer->gpu_buffer, DXGI_FORMAT_R16_UINT, zero);
/* Bind SRVs */
ID3D11ShaderResourceView *srvs[] = { instance_buffer->srv };
ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
/* Bind RTVs */
ID3D11RenderTargetView *rtvs[] = { final_tex->rtv };
ID3D11DeviceContext_OMSetRenderTargets(G.devcon, ARRAY_COUNT(rtvs), rtvs, NULL);
/* Draw */
ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ID3D11DeviceContext_DrawIndexedInstanced(G.devcon, 6, instance_count, 0, 0, 0);
/* Unbind */
dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_SRV | DX11_UNBIND_RTV);
} }
} break; ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
} ID3D11DeviceContext_PSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
/* Bind dummy vertex buffer */
u32 zero = 0;
ID3D11DeviceContext_IASetVertexBuffers(G.devcon, 0, 1, &G.dummy_vertex_buffer->gpu_buffer, &zero, &zero);
ID3D11DeviceContext_IASetIndexBuffer(G.devcon, G.quad_index_buffer->gpu_buffer, DXGI_FORMAT_R16_UINT, zero);
/* Bind SRVs */
ID3D11ShaderResourceView *srvs[] = { instance_buffer->srv };
ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
/* Bind RTVs */
ID3D11RenderTargetView *rtvs[] = { final_tex->rtv };
ID3D11DeviceContext_OMSetRenderTargets(G.devcon, ARRAY_COUNT(rtvs), rtvs, NULL);
/* Draw */
ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
/* FIXME: Set StartInstanceLocation parameter here rather than passing instance_offset into CBV */
ID3D11DeviceContext_DrawIndexedInstanced(G.devcon, 6, instance_count, 0, 0, 0);
/* Unbind */
dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_SRV | DX11_UNBIND_RTV);
}
} break;
case GPU_CMD_KIND_TEST:
{
__profscope(Test);
__profscope_dx11(G.profiling_ctx, Test, RGB32_F(1, 0.2, 1));
struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEST];
if (shader->valid) {
struct dx11_buffer *instance_buffer = plan->buffers.test.instance_buffer;
u32 instance_offset = cmd->test.instance_offset;
u32 instance_count = cmd->test.instance_count;
/* Bind shader */
ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0);
ID3D11DeviceContext_PSSetShader(G.devcon, shader->ps, 0, 0);
/* Fill & bind constant buffer */
{
struct dx11_test_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_test_uniform));
uniform->vp = vp_matrix;
uniform->instance_offset = instance_offset;
dx11_buffer_submit(constant_buffer);
}
ID3D11DeviceContext_VSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
ID3D11DeviceContext_PSSetConstantBuffers(G.devcon, 0, 1, &constant_buffer->gpu_buffer);
/* Bind dummy vertex buffer */
u32 zero = 0;
ID3D11DeviceContext_IASetVertexBuffers(G.devcon, 0, 1, &G.dummy_vertex_buffer->gpu_buffer, &zero, &zero);
ID3D11DeviceContext_IASetIndexBuffer(G.devcon, G.quad_index_buffer->gpu_buffer, DXGI_FORMAT_R16_UINT, zero);
/* Bind SRVs */
ID3D11ShaderResourceView *srvs[] = { instance_buffer->srv };
ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs);
/* Bind RTVs */
ID3D11RenderTargetView *rtvs[] = { final_tex->rtv };
ID3D11DeviceContext_OMSetRenderTargets(G.devcon, ARRAY_COUNT(rtvs), rtvs, NULL);
/* Draw */
ID3D11DeviceContext_IASetPrimitiveTopology(G.devcon, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
/* FIXME: Set StartInstanceLocation parameter here rather than passing instance_offset into CBV */
ID3D11DeviceContext_DrawIndexedInstanced(G.devcon, 6, instance_count, 0, 0, 0);
/* Unbind */
dx11_unbind(DX11_UNBIND_VS | DX11_UNBIND_PS | DX11_UNBIND_CBUFF | DX11_UNBIND_VBUFF | DX11_UNBIND_IBUFF | DX11_UNBIND_SRV | DX11_UNBIND_RTV);
}
} break;
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -47,12 +47,12 @@ INTERNAL BOOL CALLBACK enum_func(HMODULE module, LPCWSTR type, LPCWSTR wstr_entr
struct string _incbin_get(struct _incbin_rc_resource *inc) struct string _incbin_get(struct _incbin_rc_resource *inc)
{ {
enum inc_state state = atomic_i32_eval(&inc->state); enum _incbin_state state = atomic_i32_eval(&inc->state);
if (state != INCBIN_STATE_SEARCHED) { if (state != INCBIN_STATE_SEARCHED) {
struct arena_temp scratch = scratch_begin_no_conflict(); struct arena_temp scratch = scratch_begin_no_conflict();
if (state == INCBIN_STATE_UNSEARCHED) { if (state == INCBIN_STATE_UNSEARCHED) {
enum inc_state v = atomic_i32_eval_compare_exchange(&inc->state, state, INCBIN_STATE_SEARCHING); enum _incbin_state v = atomic_i32_eval_compare_exchange(&inc->state, state, INCBIN_STATE_SEARCHING);
if (v == state) { if (v == state) {
/* Search RC file for the resource name */ /* Search RC file for the resource name */
struct string name_lower = string_lower(scratch.arena, inc->rc_name); struct string name_lower = string_lower(scratch.arena, inc->rc_name);

View File

@ -136,12 +136,12 @@ INLINE i64 math_fsign64(f64 f)
INLINE u32 math_abs_i32(i32 v) INLINE u32 math_abs_i32(i32 v)
{ {
return v * ((v >= 0) - (v < 0)); return (u32)(v * ((v >= 0) - (v < 0)));
} }
INLINE u64 math_abs_i64(i64 v) INLINE u64 math_abs_i64(i64 v)
{ {
return v * ((v >= 0) - (v < 0)); return (u64)(v * ((v >= 0) - (v < 0)));
} }
/* ========================== * /* ========================== *

View File

@ -5,7 +5,6 @@
__attribute((section(".text.memcpy"))) __attribute((section(".text.memcpy")))
void *memcpy(void *__restrict dst, const void *__restrict src, u64 n) void *memcpy(void *__restrict dst, const void *__restrict src, u64 n)
{ {
/* TODO: Faster memcpy */
for (u64 i = 0; i < n; ++i) { for (u64 i = 0; i < n; ++i) {
((u8 *)dst)[i] = ((u8 *)src)[i]; ((u8 *)dst)[i] = ((u8 *)src)[i];
} }
@ -15,7 +14,6 @@ void *memcpy(void *__restrict dst, const void *__restrict src, u64 n)
__attribute((section(".text.memset"))) __attribute((section(".text.memset")))
void *memset(void *dst, i32 c, u64 n) void *memset(void *dst, i32 c, u64 n)
{ {
/* TODO: Faster memset */
for (u64 i = 0; i < n; ++i) { for (u64 i = 0; i < n; ++i) {
((u8 *)dst)[i] = c; ((u8 *)dst)[i] = c;
} }

View File

@ -46,7 +46,7 @@ void phys_create_and_update_contacts(struct phys_step_ctx *ctx, f32 elapsed_dt,
struct space_iter iter = space_iter_begin_aabb(space, aabb); struct space_iter iter = space_iter_begin_aabb(space, aabb);
struct space_entry *space_entry; struct space_entry *space_entry;
while ((space_entry = space_iter_next(&iter))) { while ((space_entry = space_iter_next(&iter)) != NULL) {
struct sim_ent *check1 = sim_ent_from_id(ss, space_entry->ent); struct sim_ent *check1 = sim_ent_from_id(ss, space_entry->ent);
if (!sim_ent_is_valid_and_active(check1)) continue; if (!sim_ent_is_valid_and_active(check1)) continue;
if (!(sim_ent_has_prop(check1, SEPROP_SOLID) || sim_ent_has_prop(check1, SEPROP_SENSOR))) continue; if (!(sim_ent_has_prop(check1, SEPROP_SOLID) || sim_ent_has_prop(check1, SEPROP_SENSOR))) continue;
@ -1191,7 +1191,7 @@ f32 phys_determine_earliest_toi(struct phys_step_ctx *ctx, f32 step_dt, f32 tole
struct space_iter iter = space_iter_begin_aabb(space, combined_aabb); struct space_iter iter = space_iter_begin_aabb(space, combined_aabb);
struct space_entry *entry; struct space_entry *entry;
while ((entry = space_iter_next(&iter))) { while ((entry = space_iter_next(&iter)) != NULL) {
struct sim_ent *e1 = sim_ent_from_id(ss, entry->ent); struct sim_ent *e1 = sim_ent_from_id(ss, entry->ent);
if (!sim_ent_should_simulate(e1)) continue; if (!sim_ent_should_simulate(e1)) continue;
if (!(sim_ent_has_prop(e1, SEPROP_SOLID) || sim_ent_has_prop(e1, SEPROP_SENSOR))) continue; if (!(sim_ent_has_prop(e1, SEPROP_SOLID) || sim_ent_has_prop(e1, SEPROP_SENSOR))) continue;

View File

@ -12,6 +12,23 @@
#include "atomic.h" #include "atomic.h"
#include "app.h" #include "app.h"
void bla(void);
void bla(void)
{
(UNUSED)bla;
DEBUGBREAKABLE;
}
#define NTDDI_WIN11_DT 0
#define COBJMACROS #define COBJMACROS
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define UNICODE #define UNICODE

View File

@ -262,7 +262,7 @@ INTERNAL void test_spawn_entities2(struct sim_ent *parent, struct v2 pos)
e->sprite = sprite_tag_from_path(LIT("sprite/box.ase")); e->sprite = sprite_tag_from_path(LIT("sprite/box.ase"));
e->layer = SIM_LAYER_SHOULDERS; e->layer = SIM_LAYER_SHOULDERS;
e->sprite_tint = ALPHA_F(COLOR_BLUE, 0.75); e->sprite_tint = ALPHA32_F(COLOR_BLUE, 0.75);
sim_ent_enable_prop(e, SEPROP_SOLID); sim_ent_enable_prop(e, SEPROP_SOLID);
struct quad collider_quad = quad_from_rect(RECT(-0.5, -0.5, 1, 1)); struct quad collider_quad = quad_from_rect(RECT(-0.5, -0.5, 1, 1));
@ -344,7 +344,7 @@ INTERNAL void test_spawn_entities4(struct sim_ent *parent, struct v2 pos)
sim_ent_enable_prop(e, SEPROP_LIGHT_TEST); sim_ent_enable_prop(e, SEPROP_LIGHT_TEST);
e->sprite_tint = RGB_F(1, 0, 1); e->sprite_tint = RGB32_F(1, 0, 1);
} }
INTERNAL void test_spawn_tile(struct sim_snapshot *world, struct v2 world_pos) INTERNAL void test_spawn_tile(struct sim_snapshot *world, struct v2 world_pos)
@ -740,7 +740,7 @@ INTERNAL PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
struct xform xf = XFORM_TRS(.t = point, .r = rand_f64_from_state(&step_ctx->rand, 0, TAU)); struct xform xf = XFORM_TRS(.t = point, .r = rand_f64_from_state(&step_ctx->rand, 0, TAU));
struct sim_ent *decal = sim_ent_alloc_sync_src(root); struct sim_ent *decal = sim_ent_alloc_sync_src(root);
decal->sprite = sprite_tag_from_path(LIT("sprite/blood.ase")); decal->sprite = sprite_tag_from_path(LIT("sprite/blood.ase"));
decal->sprite_tint = RGBA_F(1, 1, 1, 0.25f); decal->sprite_tint = RGBA32_F(1, 1, 1, 0.25f);
decal->layer = SIM_LAYER_FLOOR_DECALS; decal->layer = SIM_LAYER_FLOOR_DECALS;
sim_ent_set_xform(decal, xf); sim_ent_set_xform(decal, xf);

View File

@ -463,7 +463,7 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
span->start = ase_span->start; span->start = ase_span->start;
span->end = ase_span->end; span->end = ase_span->end;
u64 hash = hash_fnv64(HASH_FNV64_BASIS, name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, name);
dict_set(arena, &sheet.spans_dict, hash, span); dict_set(arena, &sheet.spans_dict, hash, (u64)span);
++index; ++index;
} }
} }
@ -498,11 +498,11 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
for (struct ase_slice_key *ase_slice_key = ase.slice_key_head; ase_slice_key; ase_slice_key = ase_slice_key->next) { for (struct ase_slice_key *ase_slice_key = ase.slice_key_head; ase_slice_key; ase_slice_key = ase_slice_key->next) {
struct string name = ase_slice_key->name; struct string name = ase_slice_key->name;
u64 hash = hash_fnv64(HASH_FNV64_BASIS, name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, name);
struct temp_slice_group_node *temp_slice_group_node = dict_get(&temp_slice_dict, hash); struct temp_slice_group_node *temp_slice_group_node = (struct temp_slice_group_node *)dict_get(&temp_slice_dict, hash);
if (!temp_slice_group_node) { if (!temp_slice_group_node) {
temp_slice_group_node = arena_push(scratch.arena, struct temp_slice_group_node); temp_slice_group_node = arena_push(scratch.arena, struct temp_slice_group_node);
temp_slice_group_node->name = name; temp_slice_group_node->name = name;
dict_set(scratch.arena, &temp_slice_dict, hash, temp_slice_group_node); dict_set(scratch.arena, &temp_slice_dict, hash, (u64)temp_slice_group_node);
++num_temp_slice_group_nodes; ++num_temp_slice_group_nodes;
temp_slice_group_node->next = temp_slice_group_head; temp_slice_group_node->next = temp_slice_group_head;
@ -586,7 +586,7 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
temp_slice_group_node->final_slice_group = slice_group; temp_slice_group_node->final_slice_group = slice_group;
u64 hash = hash_fnv64(HASH_FNV64_BASIS, slice_group->name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, slice_group->name);
dict_set(arena, &sheet.slice_groups_dict, hash, slice_group); dict_set(arena, &sheet.slice_groups_dict, hash, (u64)slice_group);
++index; ++index;
} }
@ -635,7 +635,7 @@ INTERNAL struct sprite_sheet init_sheet_from_ase_result(struct arena *arena, str
struct string point_slice_name = ray_slice_name; struct string point_slice_name = ray_slice_name;
point_slice_name.len -= ray_suffix.len; point_slice_name.len -= ray_suffix.len;
u64 hash = hash_fnv64(HASH_FNV64_BASIS, point_slice_name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, point_slice_name);
struct sprite_sheet_slice_group *point_slice_group = dict_get(&sheet.slice_groups_dict, hash); struct sprite_sheet_slice_group *point_slice_group = (struct sprite_sheet_slice_group *)dict_get(&sheet.slice_groups_dict, hash);
if (point_slice_group) { if (point_slice_group) {
u32 point_slices_per_frame = point_slice_group->per_frame_count; u32 point_slices_per_frame = point_slice_group->per_frame_count;
@ -1082,7 +1082,7 @@ struct sprite_sheet_span sprite_sheet_get_span(struct sprite_sheet *sheet, struc
struct sprite_sheet_span res = ZI; struct sprite_sheet_span res = ZI;
if (sheet->spans_count > 0) { if (sheet->spans_count > 0) {
u64 hash = hash_fnv64(HASH_FNV64_BASIS, name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, name);
struct sprite_sheet_span *entry = dict_get(&sheet->spans_dict, hash); struct sprite_sheet_span *entry = (struct sprite_sheet_span *)dict_get(&sheet->spans_dict, hash);
if (entry) { if (entry) {
res = *entry; res = *entry;
} }
@ -1094,7 +1094,7 @@ struct sprite_sheet_slice sprite_sheet_get_slice(struct sprite_sheet *sheet, str
{ {
if (sheet->slice_groups_count > 0) { if (sheet->slice_groups_count > 0) {
u64 hash = hash_fnv64(HASH_FNV64_BASIS, name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, name);
struct sprite_sheet_slice_group *group = dict_get(&sheet->slice_groups_dict, hash); struct sprite_sheet_slice_group *group = (struct sprite_sheet_slice_group *)dict_get(&sheet->slice_groups_dict, hash);
if (group) { if (group) {
return group->frame_slices[frame_index * group->per_frame_count]; return group->frame_slices[frame_index * group->per_frame_count];
} }
@ -1120,7 +1120,7 @@ struct sprite_sheet_slice_array sprite_sheet_get_slices(struct sprite_sheet *she
struct sprite_sheet_slice_array res = ZI; struct sprite_sheet_slice_array res = ZI;
if (sheet->slice_groups_count > 0) { if (sheet->slice_groups_count > 0) {
u64 hash = hash_fnv64(HASH_FNV64_BASIS, name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, name);
struct sprite_sheet_slice_group *group = dict_get(&sheet->slice_groups_dict, hash); struct sprite_sheet_slice_group *group = (struct sprite_sheet_slice_group *)dict_get(&sheet->slice_groups_dict, hash);
if (group) { if (group) {
res.count = group->per_frame_count; res.count = group->per_frame_count;
res.slices = &group->frame_slices[frame_index * group->per_frame_count]; res.slices = &group->frame_slices[frame_index * group->per_frame_count];

View File

@ -133,7 +133,7 @@ struct tar_archive tar_parse(struct arena *arena, struct string data, struct str
archive.lookup = dict_init(arena, (u64)((f64)num_files * ARCHIVE_LOOKUP_TABLE_CAPACITY_FACTOR)); archive.lookup = dict_init(arena, (u64)((f64)num_files * ARCHIVE_LOOKUP_TABLE_CAPACITY_FACTOR));
for (struct tar_entry *entry = archive.head; entry; entry = entry->next) { for (struct tar_entry *entry = archive.head; entry; entry = entry->next) {
u64 hash = hash_fnv64(HASH_FNV64_BASIS, entry->file_name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, entry->file_name);
dict_set(arena, &archive.lookup, hash, entry); dict_set(arena, &archive.lookup, hash, (u64)entry);
} }
/* Build hierarchy */ /* Build hierarchy */
@ -147,7 +147,7 @@ struct tar_archive tar_parse(struct arena *arena, struct string data, struct str
for (struct string parent_dir_name = entry->file_name; parent_dir_name.len > 0; --parent_dir_name.len) { for (struct string parent_dir_name = entry->file_name; parent_dir_name.len > 0; --parent_dir_name.len) {
if (parent_dir_name.text[parent_dir_name.len - 1] == '/') { if (parent_dir_name.text[parent_dir_name.len - 1] == '/') {
u64 hash = hash_fnv64(HASH_FNV64_BASIS, parent_dir_name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, parent_dir_name);
parent_entry = dict_get(&archive.lookup, hash); parent_entry = (struct tar_entry *)dict_get(&archive.lookup, hash);
break; break;
} }
} }
@ -165,5 +165,5 @@ struct tar_archive tar_parse(struct arena *arena, struct string data, struct str
struct tar_entry *tar_get(struct tar_archive *archive, struct string name) struct tar_entry *tar_get(struct tar_archive *archive, struct string name)
{ {
u64 hash = hash_fnv64(HASH_FNV64_BASIS, name); u64 hash = hash_fnv64(HASH_FNV64_BASIS, name);
return dict_get(&archive->lookup, hash); return (struct tar_entry *)dict_get(&archive->lookup, hash);
} }

View File

@ -76,8 +76,8 @@ struct ttf_startup_receipt ttf_startup(void)
struct ttf_decode_result ttf_decode(struct arena *arena, struct string encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count) struct ttf_decode_result ttf_decode(struct arena *arena, struct string encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count)
{ {
COLORREF bg_color = RGB(0,0,0); COLORREF bg_color = RGB32(0,0,0);
COLORREF fg_color = RGB(255,255,255); COLORREF fg_color = RGB32(255,255,255);
IDWriteFactory5 *factory = G.factory; IDWriteFactory5 *factory = G.factory;
@ -259,7 +259,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct string encoded,
u64 in_x = (u64)bounding_box.left + x; u64 in_x = (u64)bounding_box.left + x;
u32 *out_pixel = out_data + (out_x + (out_y * atlas_w)); u32 *out_pixel = out_data + (out_x + (out_y * atlas_w));
u32 *in_pixel = in_data + (in_x + (in_y * in_pitch)); u32 *in_pixel = in_data + (in_x + (in_y * in_pitch));
*out_pixel = RGBA(0xFF, 0xFF, 0xFF, *in_pixel & 0xFF); *out_pixel = RGBA32(0xFF, 0xFF, 0xFF, *in_pixel & 0xFF);
} }
} }
out_offset_x += tex_w; out_offset_x += tex_w;

View File

@ -352,7 +352,7 @@ INTERNAL void debug_draw_xform(struct xform xf, u32 color_x, u32 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, x_ray, thickness, arrowhead_len, color_x);
draw_arrow_ray(G.user_gpu_plan, 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 = RGBA32_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_plan, quad, color); //draw_quad(G.user_gpu_plan, quad, color);
@ -506,16 +506,16 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
LOCAL_PERSIST u32 colors[LOG_LEVEL_COUNT][2] = ZI; LOCAL_PERSIST u32 colors[LOG_LEVEL_COUNT][2] = ZI;
MEMSET(colors, 0xFF, sizeof(colors)); MEMSET(colors, 0xFF, sizeof(colors));
#if 1 #if 1
colors[LOG_LEVEL_DEBUG][0] = RGB_F(0.4, 0.1, 0.4); colors[LOG_LEVEL_DEBUG][1] = RGB_F(0.5, 0.2, 0.5); colors[LOG_LEVEL_DEBUG][0] = RGB32_F(0.4, 0.1, 0.4); colors[LOG_LEVEL_DEBUG][1] = RGB32_F(0.5, 0.2, 0.5);
colors[LOG_LEVEL_INFO][0] = RGB_F(0.4, 0.4, 0.4); colors[LOG_LEVEL_INFO][1] = RGB_F(0.5, 0.5, 0.5); colors[LOG_LEVEL_INFO][0] = RGB32_F(0.4, 0.4, 0.4); colors[LOG_LEVEL_INFO][1] = RGB32_F(0.5, 0.5, 0.5);
colors[LOG_LEVEL_SUCCESS][0] = RGB_F(0.1, 0.3, 0.1); colors[LOG_LEVEL_SUCCESS][1] = RGB_F(0.2, 0.4, 0.2); colors[LOG_LEVEL_SUCCESS][0] = RGB32_F(0.1, 0.3, 0.1); colors[LOG_LEVEL_SUCCESS][1] = RGB32_F(0.2, 0.4, 0.2);
colors[LOG_LEVEL_WARNING][0] = RGB_F(0.4, 0.4, 0.1); colors[LOG_LEVEL_WARNING][1] = RGB_F(0.5, 0.5, 0.2); colors[LOG_LEVEL_WARNING][0] = RGB32_F(0.4, 0.4, 0.1); colors[LOG_LEVEL_WARNING][1] = RGB32_F(0.5, 0.5, 0.2);
colors[LOG_LEVEL_ERROR][0] = RGB_F(0.4, 0.1, 0.1); colors[LOG_LEVEL_ERROR][1] = RGB_F(0.5, 0.2, 0.2); colors[LOG_LEVEL_ERROR][0] = RGB32_F(0.4, 0.1, 0.1); colors[LOG_LEVEL_ERROR][1] = RGB32_F(0.5, 0.2, 0.2);
#else #else
u32 info_colors[2] = { RGB_F(0.4, 0.4, 0.4), RGB_F(0.5, 0.5, 0.5) }; u32 info_colors[2] = { RGB32_F(0.4, 0.4, 0.4), RGB32_F(0.5, 0.5, 0.5) };
u32 success_colors[2] = { RGB_F(0.1, 0.3, 0.1), RGB_F(0.2, 0.4, 0.2) }; u32 success_colors[2] = { RGB32_F(0.1, 0.3, 0.1), RGB32_F(0.2, 0.4, 0.2) };
u32 warning_colors[2] = { RGB_F(0.4, 0.4, 0.1), RGB_F(0.5, 0.5, 0.2) }; u32 warning_colors[2] = { RGB32_F(0.4, 0.4, 0.1), RGB32_F(0.5, 0.5, 0.2) };
u32 error_colors[2] = { RGB_F(0.4, 0.1, 0.1), RGB_F(0.5, 0.2, 0.2) }; u32 error_colors[2] = { RGB32_F(0.4, 0.1, 0.1), RGB32_F(0.5, 0.2, 0.2) };
#endif #endif
struct v2 draw_pos = desired_start_pos; struct v2 draw_pos = desired_start_pos;
@ -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_plan, quad_from_rect(log->bounds), ALPHA_F(color, opacity)); draw_quad(G.user_gpu_plan, quad_from_rect(log->bounds), ALPHA32_F(color, opacity));
/* Draw text */ /* Draw text */
struct string text = log->msg; struct string text = log->msg;
@ -558,7 +558,7 @@ INTERNAL void draw_debug_console(i32 level, b32 minimized)
FMT_STR(text)); FMT_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 draw_text_params params = DRAW_TEXT_PARAMS(.font = font, .pos = draw_pos, .offset_y = DRAW_TEXT_OFFSET_Y_BOTTOM, .color = ALPHA32_F(COLOR_WHITE, opacity), .str = text);
struct rect bounds = draw_text(G.user_gpu_plan, params); struct rect bounds = draw_text(G.user_gpu_plan, params);
struct rect draw_bounds = bounds; struct rect draw_bounds = bounds;
@ -832,7 +832,7 @@ INTERNAL void user_update(void)
struct collider_shape mouse_shape = ZI; struct collider_shape mouse_shape = ZI;
mouse_shape.points[0] = V2(0, 0); mouse_shape.points[0] = V2(0, 0);
mouse_shape.count = 1; mouse_shape.count = 1;
mouse_shape.radius = 0.01; mouse_shape.radius = 0.01f;
for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) { for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) {
struct sim_ent *ent = &G.ss_blended->ents[ent_index]; struct sim_ent *ent = &G.ss_blended->ents[ent_index];
if (!sim_ent_is_valid_and_active(ent)) continue; if (!sim_ent_is_valid_and_active(ent)) continue;
@ -944,7 +944,7 @@ INTERNAL void user_update(void)
G.user_screen_offset = V2(0, 0); G.user_screen_offset = V2(0, 0);
} else { } else {
/* Determine ui size by camera & window dimensions */ /* Determine ui size by camera & window dimensions */
f32 aspect_ratio = DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT; f32 aspect_ratio = (f32)(DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT);
if (local_camera->valid) { if (local_camera->valid) {
struct xform quad_xf = xform_mul(sim_ent_get_xform(local_camera), local_camera->camera_quad_xform); struct xform quad_xf = xform_mul(sim_ent_get_xform(local_camera), local_camera->camera_quad_xform);
struct v2 camera_size = xform_get_scale(quad_xf); struct v2 camera_size = xform_get_scale(quad_xf);
@ -1063,9 +1063,9 @@ INTERNAL void user_update(void)
struct v2 pos = xform_invert_mul_v2(G.world_to_user_xf, V2(0, 0)); struct v2 pos = xform_invert_mul_v2(G.world_to_user_xf, V2(0, 0));
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 = RGBA32_F(0.17f, 0.17f, 0.17f, 1.f);
u32 color1 = RGBA_F(0.15f, 0.15f, 0.15f, 1.f); u32 color1 = RGBA32_F(0.15f, 0.15f, 0.15f, 1.f);
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); draw_grid(G.world_gpu_plan, xform_from_rect(RECT_FROM_V2(pos, size)), color0, color1, RGBA32(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
} }
/* ========================== * /* ========================== *
@ -1256,8 +1256,8 @@ INTERNAL void user_update(void)
} }
f32 thickness = 0.01f; f32 thickness = 0.01f;
u32 color_start = RGBA_F(1, 0.5, 0, opacity_a); u32 color_start = RGBA32_F(1, 0.5, 0, opacity_a);
u32 color_end = RGBA_F(1, 0.8, 0.4, opacity_b); u32 color_end = RGBA32_F(1, 0.8, 0.4, opacity_b);
if (opacity_b > 0.99f) { if (opacity_b > 0.99f) {
draw_circle(G.world_gpu_plan, b, thickness / 2, color_end, 20); draw_circle(G.world_gpu_plan, b, thickness / 2, color_end, 20);
@ -1317,8 +1317,8 @@ INTERNAL void user_update(void)
/* Draw xform */ /* Draw xform */
if (!skip_debug_draw_transform) { if (!skip_debug_draw_transform) {
u32 color_x = RGBA_F(1, 0, 0, 0.5); u32 color_x = RGBA32_F(1, 0, 0, 0.5);
u32 color_y = RGBA_F(0, 1, 0, 0.5); u32 color_y = RGBA32_F(0, 1, 0, 0.5);
debug_draw_xform(xf, color_x, color_y); debug_draw_xform(xf, color_x, color_y);
} }
@ -1326,7 +1326,7 @@ INTERNAL void user_update(void)
if (ent->local_collider.count > 0) { if (ent->local_collider.count > 0) {
struct aabb aabb = collider_aabb_from_collider(&ent->local_collider, xf); struct aabb aabb = collider_aabb_from_collider(&ent->local_collider, xf);
f32 thickness = 1; f32 thickness = 1;
u32 color = RGBA_F(1, 0, 1, 0.5); u32 color = RGBA32_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_plan, quad, thickness, color); draw_quad_line(G.user_gpu_plan, quad, thickness, color);
@ -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_plan, start, end, 3, 10, RGBA_F(1, 1, 1, 0.5)); draw_arrow_line(G.user_gpu_plan, start, end, 3, 10, RGBA32_F(1, 1, 1, 0.5));
} }
#if 0 #if 0
@ -1348,9 +1348,9 @@ INTERNAL void user_update(void)
if (!sprite_tag_is_nil(ent->sprite)) { if (!sprite_tag_is_nil(ent->sprite)) {
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite); struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite);
u32 quad_color = RGBA_F(1, 0, 0.5, 1); u32 quad_color = RGBA32_F(1, 0, 0.5, 1);
u32 point_color = RGBA_F(1, 0, 0, 1); u32 point_color = RGBA32_F(1, 0, 0, 1);
u32 ray_color = RGBA_F(1, 0, 0.5, 1); u32 ray_color = RGBA32_F(1, 0, 0.5, 1);
for (u64 i = 0; i < sheet->slice_groups_count; ++i) { for (u64 i = 0; i < sheet->slice_groups_count; ++i) {
struct sprite_sheet_slice_group *group = &sheet->slice_groups[i]; struct sprite_sheet_slice_group *group = &sheet->slice_groups[i];
@ -1414,7 +1414,7 @@ INTERNAL void user_update(void)
/* Draw collider */ /* Draw collider */
if (ent->local_collider.count > 0) { if (ent->local_collider.count > 0) {
struct collider_shape collider = ent->local_collider; struct collider_shape collider = ent->local_collider;
u32 color = RGBA_F(1, 1, 0, 0.5); u32 color = RGBA32_F(1, 1, 0, 0.5);
f32 thickness = 2; f32 thickness = 2;
{ {
/* Draw collider using support points */ /* Draw collider using support points */
@ -1460,7 +1460,7 @@ INTERNAL void user_update(void)
{ {
f32 radius = 5; f32 radius = 5;
for (u32 i = 0; i < data->num_points; ++i) { for (u32 i = 0; i < data->num_points; ++i) {
u32 color = (data->skip_solve || data->wrong_dir) ? ALPHA_F(COLOR_YELLOW, 0.3) : RGBA_F(0.8, 0.2, 0.2, 1); u32 color = (data->skip_solve || data->wrong_dir) ? ALPHA32_F(COLOR_YELLOW, 0.3) : RGBA32_F(0.8, 0.2, 0.2, 1);
struct phys_contact_point point = data->points[i]; struct phys_contact_point point = data->points[i];
struct v2 dbg_pt = point.dbg_pt; struct v2 dbg_pt = point.dbg_pt;
@ -1531,7 +1531,7 @@ INTERNAL void user_update(void)
#if 0 #if 0
{ {
f32 radius = 4; f32 radius = 4;
u32 color = RGBA_F(1, 1, 0, 0.5); u32 color = RGBA32_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_plan, a, radius, color, 10); draw_circle(G.user_gpu_plan, a, radius, color, 10);
@ -1543,12 +1543,12 @@ INTERNAL void user_update(void)
{ {
f32 thickness = 4; f32 thickness = 4;
f32 radius = 4; f32 radius = 4;
u32 color_line = RGBA_F(1, 0, 1, 0.75); u32 color_line = RGBA32_F(1, 0, 1, 0.75);
u32 color_a = RGBA_F(1, 0, 0, 0.25); u32 color_a = RGBA32_F(1, 0, 0, 0.25);
u32 color_b = RGBA_F(0, 1, 0, 0.25); u32 color_b = RGBA32_F(0, 1, 0, 0.25);
u32 color_line_clipped = RGBA_F(1, 0, 1, 1); u32 color_line_clipped = RGBA32_F(1, 0, 1, 1);
u32 color_a_clipped = RGBA_F(1, 0, 0, 1); u32 color_a_clipped = RGBA32_F(1, 0, 0, 1);
u32 color_b_clipped = RGBA_F(0, 1, 0, 1); u32 color_b_clipped = RGBA32_F(0, 1, 0, 1);
{ {
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);
@ -1622,7 +1622,7 @@ INTERNAL void user_update(void)
/* Draw menkowski */ /* Draw menkowski */
{ {
u32 color = collider_res.solved ? RGBA_F(0, 0, 0.25, 1) : RGBA_F(0, 0.25, 0.25, 1); u32 color = collider_res.solved ? RGBA32_F(0, 0, 0.25, 1) : RGBA32_F(0, 0.25, 0.25, 1);
f32 thickness = 2; f32 thickness = 2;
u32 detail = 512; u32 detail = 512;
(UNUSED)thickness; (UNUSED)thickness;
@ -1636,7 +1636,7 @@ INTERNAL void user_update(void)
/* Draw cloud */ /* Draw cloud */
{ {
u32 color = RGBA_F(1, 1, 1, 1); u32 color = RGBA32_F(1, 1, 1, 1);
f32 radius = 2; f32 radius = 2;
struct v2_array m = cloud(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf); struct v2_array m = cloud(temp.arena, &e0_collider, &e1_collider, e0_xf, e1_xf);
@ -1650,7 +1650,7 @@ INTERNAL void user_update(void)
/* Draw prototype */ /* Draw prototype */
{ {
f32 thickness = 2; f32 thickness = 2;
u32 color = RGBA_F(1, 1, 1, 0.25); u32 color = RGBA32_F(1, 1, 1, 0.25);
struct v2_array m = { struct v2_array m = {
.points = collider_res.prototype.points, .points = collider_res.prototype.points,
@ -1665,9 +1665,9 @@ INTERNAL void user_update(void)
{ {
f32 thickness = 2; f32 thickness = 2;
u32 line_color = COLOR_YELLOW; u32 line_color = COLOR_YELLOW;
u32 color_first = RGBA_F(1, 0, 0, 0.75); u32 color_first = RGBA32_F(1, 0, 0, 0.75);
u32 color_second = RGBA_F(0, 1, 0, 0.75); u32 color_second = RGBA32_F(0, 1, 0, 0.75);
u32 color_third = RGBA_F(0, 0, 1, 0.75); u32 color_third = RGBA32_F(0, 0, 1, 0.75);
struct collider_menkowski_simplex simplex = collider_res.simplex; struct collider_menkowski_simplex simplex = collider_res.simplex;
struct v2 simplex_points[] = { simplex.a.p, simplex.b.p, simplex.c.p }; struct v2 simplex_points[] = { simplex.a.p, simplex.b.p, simplex.c.p };
@ -1708,7 +1708,7 @@ INTERNAL void user_update(void)
/* Draw hierarchy */ /* Draw hierarchy */
if (sim_ent_has_prop(parent, SEPROP_ACTIVE) && !parent->is_root) { if (sim_ent_has_prop(parent, SEPROP_ACTIVE) && !parent->is_root) {
u32 color = RGBA_F(0.6, 0.6, 1, 0.75); u32 color = RGBA32_F(0.6, 0.6, 1, 0.75);
f32 thickness = 2; f32 thickness = 2;
f32 arrow_height = 15; f32 arrow_height = 15;
@ -1719,7 +1719,7 @@ INTERNAL void user_update(void)
/* Draw camera rect */ /* Draw camera rect */
if (sim_ent_has_prop(ent, SEPROP_CAMERA)) { if (sim_ent_has_prop(ent, SEPROP_CAMERA)) {
u32 color = ent == local_camera ? RGBA_F(1, 1, 1, 0.5) : RGBA_F(0, 0.75, 0, 0.5); u32 color = ent == local_camera ? RGBA32_F(1, 1, 1, 0.5) : RGBA32_F(0, 0.75, 0, 0.5);
f32 thickness = 3; f32 thickness = 3;
struct xform quad_xf = xform_mul(xf, ent->camera_quad_xform); struct xform quad_xf = xform_mul(xf, ent->camera_quad_xform);
@ -2111,29 +2111,27 @@ INTERNAL void user_update(void)
/* Clear textures */ /* Clear textures */
gpu_texture_clear(G.user_texture, 0); gpu_texture_clear(G.user_texture, 0);
gpu_texture_clear(G.backbuffer_texture, RGBA_F(0, 0, 0, 1)); gpu_texture_clear(G.backbuffer_texture, RGBA32_F(0, 0, 0, 1));
/* Render to user texture */ /* Render to user texture */
{ {
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.plans.handles = plans; params.plan = G.world_gpu_plan;
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);
} }
#if 0
/* Render to backbuffer texture */ /* Render to backbuffer texture */
{ {
struct gpu_handle *plans[] = { &G.backbuffer_gpu_plan };
struct gpu_dispatch_params params = ZI; struct gpu_dispatch_params params = ZI;
params.plans.handles = plans; params.plan = G.backbuffer_gpu_plan;
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);
} }
#endif
/* Swap backbuffer */ /* Swap backbuffer */
gpu_swap_backbuffer(VSYNC_ENABLED); gpu_swap_backbuffer(VSYNC_ENABLED);