From 762a7d83fee585721393c6ab68e2ae5495bafe13 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 20 Jul 2025 09:20:14 -0500 Subject: [PATCH] distinguish pipeline warnings from errors --- res/sh/shade.hlsl | 23 +++++-------- src/gp_dx12.c | 85 ++++++++++++++++++++++++++++++++++++----------- src/sim_step.c | 11 +++--- 3 files changed, 81 insertions(+), 38 deletions(-) diff --git a/res/sh/shade.hlsl b/res/sh/shade.hlsl index 6f883c90..53aeef2a 100644 --- a/res/sh/shade.hlsl +++ b/res/sh/shade.hlsl @@ -25,26 +25,18 @@ struct cs_input { * Lighting * ========================== */ -#define SAMPLES 2 +#define SAMPLES 4 #define MARCHES 16 #define AMBIENT float4(0, 0, 0, 0) -float rand_angle(uint2 pos, uint ray_index) { +float rand_angle(int2 pos, uint ray_index) { Texture3D noise_tex = g_noise_textures[SH_BLUE_NOISE_TEX_ID]; - // pos += uint2(g_constants.frame_seed.x % g_constants.tex_width, g_constants.frame_seed.x % g_constants.tex_height); + uint3 noise_coord = uint3(abs(pos.xy), ray_index); + noise_coord += g_constants.frame_seed; + // noise_coord.xy += g_constants.frame_seed.xy; - // pos -= g_constants.camera_offset; - - uint3 noise_coord = uint3(pos.xy, 0); - // noise_coord.xy *= g_constants.frame_seed.xy; - noise_coord.z += ray_index; - // noise_coord.z += ray_index * noise_coord.x ; - // noise_coord.z += g_constants.frame_seed.x; - // noise_coord.z += g_constants.frame_index; - - uint3 noise_size = uint3(SH_BLUE_NOISE_TEX_WIDTH, SH_BLUE_NOISE_TEX_HEIGHT, SH_BLUE_NOISE_TEX_DEPTH); - uint noise = noise_tex[noise_coord % noise_size]; + uint noise = noise_tex[noise_coord % uint3(SH_BLUE_NOISE_TEX_WIDTH, SH_BLUE_NOISE_TEX_HEIGHT, SH_BLUE_NOISE_TEX_DEPTH)]; return ((float)noise / (float)0xFFFF) * TAU; } @@ -72,10 +64,11 @@ INLINE float4 get_light_in_dir(uint2 ray_start, float2 ray_dir) } } } + return result; } -INLINE float4 get_light_at_pos(uint2 pos) +INLINE float4 get_light_at_pos(int2 pos) { float4 result = 0; for (uint i = 0; i < SAMPLES; ++i) { diff --git a/src/gp_dx12.c b/src/gp_dx12.c index 865a8570..45d7c2c8 100644 --- a/src/gp_dx12.c +++ b/src/gp_dx12.c @@ -793,7 +793,13 @@ INTERNAL void dx12_init_pipelines(void) } for (u32 i = 0; i < num_pipelines; ++i) { struct pipeline *pipeline = pipelines[i]; - if (!pipeline->success) { + if (pipeline->success) { + logf_success("Successfully compiled pipeline \"%F\" in %F seconds", FMT_STR(pipeline->name), FMT_FLOAT(SECONDS_FROM_NS(pipeline->compilation_time_ns))); + if (pipeline->first_error) { + struct string msg = string_format(scratch.arena, LIT("Warning while compiling pipeline \"%F\":\n%F"), FMT_STR(pipeline->name), FMT_STR(pipeline->first_error->msg)); + log_warning(msg); + } + } else { struct string error = pipeline->first_error ? pipeline->first_error->msg : LIT("Unknown error"); struct string msg = string_format(scratch.arena, LIT("Error initializing pipeline \"%F\":\n\n%F"), FMT_STR(pipeline->name), FMT_STR(error)); log_error(msg); @@ -1034,7 +1040,7 @@ INTERNAL SYS_JOB_DEF(shader_compile_job, job) { 0, 0 } }; HRESULT hr = D3DCompile(shader_src.text, shader_src.len, friendly_name_cstr, defines, (ID3DInclude *)include_handler, func_cstr, target, d3d_compile_flags, 0, &blob, &error_blob); - success = SUCCEEDED(hr) && !error_blob; + success = SUCCEEDED(hr); } dx12_include_handler_release(include_handler); @@ -1054,6 +1060,50 @@ INTERNAL SYS_JOB_DEF(shader_compile_job, job) scratch_end(scratch); } +/* ========================== * + * Shader error parser + * ========================== */ + +INTERNAL void parse_pipeline_errors(struct pipeline *pipeline, ID3D10Blob *error_blob) +{ + struct string ignored[] = { + LIT("warning X3557") /* Disabled forced loop unrolling warning */ + }; + + if (error_blob) { + struct arena_temp scratch = scratch_begin_no_conflict(); + { + u64 error_blob_cstr_len = ID3D10Blob_GetBufferSize(error_blob); + char *error_blob_cstr = (char *)ID3D10Blob_GetBufferPointer(error_blob); + struct string error_str = string_copy(scratch.arena, string_from_cstr(error_blob_cstr, error_blob_cstr_len)); + if (string_ends_with(error_str, LIT("\n"))) { + /* Remove trailing newline */ + error_str.len -= 1; + } + if (error_str.len > 0) { + b32 is_ignored = 0; + for (u32 i = 0; i < countof(ignored); ++i) { + if (string_contains(error_str, ignored[i])) { + is_ignored = 1; + break; + } + } + if (!is_ignored) { + struct pipeline_error *error = arena_push(pipeline->arena, struct pipeline_error); + error->msg = string_copy(pipeline->arena, error_str); + if (pipeline->last_error) { + pipeline->last_error->next = error; + } else { + pipeline->first_error = error; + } + pipeline->last_error = error; + } + } + } + scratch_end(scratch); + } +} + /* ========================== * * Pipeline * ========================== */ @@ -1085,7 +1135,7 @@ INTERNAL SYS_JOB_DEF(pipeline_alloc_job, job) b32 success = 1; HRESULT hr = 0; - struct string error_str = LIT("Unknown error"); + struct string error_str = ZI; b32 has_cs = desc->cs.file.len > 0; b32 ps_res_is_shared = string_eq(desc->vs.file, desc->ps.file); @@ -1347,27 +1397,20 @@ INTERNAL SYS_JOB_DEF(pipeline_alloc_job, job) } } - /* Copy error */ - if (!success) { - ID3D10Blob *error_blob = cs.error_blob ? cs.error_blob : (vs.error_blob ? vs.error_blob : ps.error_blob); - if (error_blob) { - u64 error_blob_cstr_len = ID3D10Blob_GetBufferSize(error_blob); - char *error_blob_cstr = (char *)ID3D10Blob_GetBufferPointer(error_blob); - struct string error_blob_str = string_copy(scratch.arena, string_from_cstr(error_blob_cstr, error_blob_cstr_len)); - if (string_ends_with(error_blob_str, LIT("\n"))) { - /* Remove trailing newline */ - error_blob_str.len -= 1; - } - if (error_blob_str.len > 0) { - error_str = error_blob_str; - } - } + /* Parse errors */ + parse_pipeline_errors(pipeline, cs.error_blob); + parse_pipeline_errors(pipeline, vs.error_blob); + parse_pipeline_errors(pipeline, ps.error_blob); + if (!success && pipeline->first_error == 0 && error_str.len == 0) { + error_str = LIT("Unknown error"); + } + if (error_str.len > 0) { struct pipeline_error *error = arena_push(pipeline->arena, struct pipeline_error); error->msg = string_copy(pipeline->arena, error_str); if (pipeline->last_error) { pipeline->last_error->next = error; } else { - pipeline->first_error = error; + pipeline->first_error = error; } pipeline->last_error = error; } @@ -1559,6 +1602,10 @@ INTERNAL RESOURCE_WATCH_CALLBACK_FUNC_DEF(pipeline_resource_watch_callback, name struct pipeline *pipeline = pipelines[i]; if (pipeline->success) { logf_success("Successfully compiled pipeline \"%F\" in %F seconds", FMT_STR(pipeline->name), FMT_FLOAT(SECONDS_FROM_NS(pipeline->compilation_time_ns))); + if (pipeline->first_error) { + struct string msg = string_format(scratch.arena, LIT("Warning while compiling pipeline \"%F\":\n%F"), FMT_STR(pipeline->name), FMT_STR(pipeline->first_error->msg)); + log_warning(msg); + } } else { { struct string error = pipeline->first_error ? pipeline->first_error->msg : LIT("Unknown error"); diff --git a/src/sim_step.c b/src/sim_step.c index 1ffd303f..c86f6852 100644 --- a/src/sim_step.c +++ b/src/sim_step.c @@ -255,7 +255,7 @@ INTERNAL void test_spawn_entities2(struct sim_ent *parent, struct v2 pos) struct sim_ent *e = sim_ent_alloc_sync_src(parent); f32 rot = 0; - struct v2 size = V2(1, 1); + struct v2 size = V2(0.1, 0.1); struct xform xf = XFORM_TRS(.t = pos, .r = rot, .s = size); sim_ent_set_xform(e, xf); @@ -263,7 +263,7 @@ INTERNAL void test_spawn_entities2(struct sim_ent *parent, struct v2 pos) e->layer = SIM_LAYER_SHOULDERS; //e->sprite_tint = ALPHA32_F(COLOR_BLUE, 0.75); - e->sprite_tint = ALPHA32_F(COLOR_WHITE, 1); + //e->sprite_tint = ALPHA32_F(COLOR_WHITE, 1); sim_ent_enable_prop(e, SEPROP_SOLID); struct quad collider_quad = quad_from_rect(RECT(-0.5, -0.5, 1, 1)); @@ -278,6 +278,7 @@ INTERNAL void test_spawn_entities2(struct sim_ent *parent, struct v2 pos) f32 g = rand_f64_from_state(&rand, 1, 5); f32 b = rand_f64_from_state(&rand, 1, 5); e->sprite_emittance = V3(r, g, b); + e->sprite_tint = RGBA32_F(r / 5, g / 5, b / 5, 1); } sim_ent_enable_prop(e, SEPROP_DYNAMIC); @@ -351,12 +352,14 @@ INTERNAL void test_spawn_entities4(struct sim_ent *parent, struct v2 pos) struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); sim_ent_set_xform(e, xf); - e->sprite = sprite_tag_from_path(LIT("sprite/box.ase")); + //e->sprite = sprite_tag_from_path(LIT("sprite/box.ase")); + e->sprite = sprite_tag_from_path(LIT("sprite/tile.ase")); e->layer = SIM_LAYER_SHOULDERS; sim_ent_enable_prop(e, SEPROP_LIGHT_TEST); + e->sprite_emittance = V3(2, 2, 2); - e->sprite_tint = RGB32_F(1, 0, 1); + e->sprite_tint = RGB32_F(1, 1, 1); } INTERNAL void test_spawn_tile(struct sim_snapshot *world, struct v2 world_pos)