diff --git a/res/sh/shade.hlsl b/res/sh/shade.hlsl index 882f6019..1457a301 100644 --- a/res/sh/shade.hlsl +++ b/res/sh/shade.hlsl @@ -44,7 +44,7 @@ INLINE float4 get_light_in_dir(uint2 pos, float2 dir) uint2 flood = g_emittance_flood_textures[g_constants.emittance_flood_tex_urid][at]; int2 dist_vec = (int2)at - (int2)flood; float dist = length(dist_vec); - if (dist <= 1) { + if (dist <= 2) { result = g_gbuff_textures[g_constants.emittance_tex_urid][flood]; break; } else { diff --git a/src/gp_dx12.c b/src/gp_dx12.c index aa1ab93d..a14a907e 100644 --- a/src/gp_dx12.c +++ b/src/gp_dx12.c @@ -714,7 +714,7 @@ INTERNAL void dx12_init_pipelines(void) desc->rtvs[0].blending = 1; dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc); } - /* Material pipeline */ + /* UI pipeline */ { struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc); desc->name = LIT("ui"); @@ -2667,7 +2667,8 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT]; struct command_list *cl = command_list_open(cq->cl_pool); { - __profnc_dx12(cl->cq->prof, cl->cl, "Run", RGB32_F(0.5, 0.2, 0.2)); + __profn("Run render"); + __profnc_dx12(cl->cq->prof, cl->cl, "Run render", RGB32_F(0.5, 0.2, 0.2)); struct mat4x4 vp_matrix = calculate_vp(params.draw_target_view, params.draw_target_viewport.width, params.draw_target_viewport.height); /* Upload dummmy vert & index buffer */ @@ -2764,10 +2765,6 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par __profn("Material pass"); __profnc_dx12(cl->cq->prof, cl->cl, "Material pass", RGB32_F(0.5, 0.2, 0.2)); - /* Dispatch */ - __profn("Material pass run"); - __profnc_dx12(cl->cq->prof, cl->cl, "Material pass run", RGB32_F(0.5, 0.2, 0.2)); - /* Bind pipeline */ ID3D12GraphicsCommandList_SetPipelineState(cl->cl, material_pipeline->pso); ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, material_pipeline->rootsig); @@ -2894,10 +2891,6 @@ void gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params par __profn("Shade pass"); __profnc_dx12(cl->cq->prof, cl->cl, "Shade pass", RGB32_F(0.5, 0.2, 0.2)); - /* Dispatch */ - __profn("Shade pass run"); - __profnc_dx12(cl->cq->prof, cl->cl, "Shade pass run", RGB32_F(0.5, 0.2, 0.2)); - /* Bind pipeline */ ID3D12GraphicsCommandList_SetPipelineState(cl->cl, shade_pipeline->pso); ID3D12GraphicsCommandList_SetComputeRootSignature(cl->cl, shade_pipeline->rootsig); @@ -3050,7 +3043,8 @@ void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params params) struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT]; struct command_list *cl = command_list_open(cq->cl_pool); { - __profnc_dx12(cl->cq->prof, cl->cl, "Run", RGB32_F(0.5, 0.2, 0.2)); + __profn("Run ui"); + __profnc_dx12(cl->cq->prof, cl->cl, "Run ui", RGB32_F(0.5, 0.2, 0.2)); struct mat4x4 vp_matrix = calculate_vp(params.draw_target_view, params.draw_target_viewport.width, params.draw_target_viewport.height); /* Upload dummmy vert & index buffer */ @@ -3118,81 +3112,69 @@ void gp_run_ui(struct gp_ui_sig *ui_sig, struct gp_ui_params params) } /* UI rect pass */ - { - __profn("UI rect"); - __profnc_dx12(cl->cq->prof, cl->cl, "UI rect", RGB32_F(0.5, 0.2, 0.2)); + if (ui_pipeline->success) { + __profn("UI rect pass"); + __profnc_dx12(cl->cq->prof, cl->cl, "UI rect pass", RGB32_F(0.5, 0.2, 0.2)); - /* Dispatch */ - if (ui_pipeline->success) { - __profn("UI rect run"); - __profnc_dx12(cl->cq->prof, cl->cl, "UI rect run", RGB32_F(0.5, 0.2, 0.2)); + /* Bind pipeline */ + ID3D12GraphicsCommandList_SetPipelineState(cl->cl, ui_pipeline->pso); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, ui_pipeline->rootsig); - /* Bind pipeline */ - ID3D12GraphicsCommandList_SetPipelineState(cl->cl, ui_pipeline->pso); - ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, ui_pipeline->rootsig); + /* Set Rasterizer State */ + D3D12_VIEWPORT viewport = viewport_from_rect(params.draw_target_viewport); + D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport); + ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor); - /* Set Rasterizer State */ - D3D12_VIEWPORT viewport = viewport_from_rect(params.draw_target_viewport); - D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport); - ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport); - ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor); + /* Set constants */ + struct sh_ui_constants constants = ZI; + constants.projection = sh_float4x4_from_mat4x4(vp_matrix); - /* Set constants */ - struct sh_ui_constants constants = ZI; - constants.projection = sh_float4x4_from_mat4x4(vp_matrix); + /* Set parameters */ + command_list_set_graphics_root_constant(cl, &constants, sizeof(constants)); + ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle); + ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 2, ui_instance_buffer->resource->gpu_address); - /* Set parameters */ - command_list_set_graphics_root_constant(cl, &constants, sizeof(constants)); - ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle); - ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 2, ui_instance_buffer->resource->gpu_address); - - /* Draw */ - u32 instance_count = ui_instance_buffer->size / sizeof(struct sh_ui_instance); - D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0); - D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(quad_index_buffer, DXGI_FORMAT_R16_UINT); - ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D12GraphicsCommandList_IASetVertexBuffers(cl->cl, 0, 1, &vbv); - ID3D12GraphicsCommandList_IASetIndexBuffer(cl->cl, &ibv); - ID3D12GraphicsCommandList_DrawIndexedInstanced(cl->cl, 6, instance_count, 0, 0, 0); - } + /* Draw */ + u32 instance_count = ui_instance_buffer->size / sizeof(struct sh_ui_instance); + D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0); + D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(quad_index_buffer, DXGI_FORMAT_R16_UINT); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_IASetVertexBuffers(cl->cl, 0, 1, &vbv); + ID3D12GraphicsCommandList_IASetIndexBuffer(cl->cl, &ibv); + ID3D12GraphicsCommandList_DrawIndexedInstanced(cl->cl, 6, instance_count, 0, 0, 0); } /* Shape pass */ - { + if (shape_pipeline->success) { __profn("Shape pass"); __profnc_dx12(cl->cq->prof, cl->cl, "Shape pass", RGB32_F(0.5, 0.2, 0.2)); - /* Dispatch */ - if (shape_pipeline->success) { - __profn("Shape pass run"); - __profnc_dx12(cl->cq->prof, cl->cl, "Shape pass run", RGB32_F(0.5, 0.2, 0.2)); + /* Bind pipeline */ + ID3D12GraphicsCommandList_SetPipelineState(cl->cl, shape_pipeline->pso); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, shape_pipeline->rootsig); - /* Bind pipeline */ - ID3D12GraphicsCommandList_SetPipelineState(cl->cl, shape_pipeline->pso); - ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, shape_pipeline->rootsig); + /* Set Rasterizer State */ + D3D12_VIEWPORT viewport = viewport_from_rect(params.draw_target_viewport); + D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport); + ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor); - /* Set Rasterizer State */ - D3D12_VIEWPORT viewport = viewport_from_rect(params.draw_target_viewport); - D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport); - ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport); - ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor); + /* Set constants */ + struct sh_shape_constants constants = ZI; + constants.projection = sh_float4x4_from_mat4x4(vp_matrix); - /* Set constants */ - struct sh_shape_constants constants = ZI; - constants.projection = sh_float4x4_from_mat4x4(vp_matrix); + /* Set parameters */ + command_list_set_graphics_root_constant(cl, &constants, sizeof(constants)); - /* Set parameters */ - command_list_set_graphics_root_constant(cl, &constants, sizeof(constants)); - - /* Draw */ - u32 index_count = shape_indices_buffer->size / sizeof(u32); - D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(shape_verts_buffer, sizeof(struct sh_shape_vert)); - D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(shape_indices_buffer, DXGI_FORMAT_R32_UINT); - ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D12GraphicsCommandList_IASetVertexBuffers(cl->cl, 0, 1, &vbv); - ID3D12GraphicsCommandList_IASetIndexBuffer(cl->cl, &ibv); - ID3D12GraphicsCommandList_DrawIndexedInstanced(cl->cl, index_count, 1, 0, 0, 0); - } + /* Draw */ + u32 index_count = shape_indices_buffer->size / sizeof(u32); + D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(shape_verts_buffer, sizeof(struct sh_shape_vert)); + D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(shape_indices_buffer, DXGI_FORMAT_R32_UINT); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_IASetVertexBuffers(cl->cl, 0, 1, &vbv); + ID3D12GraphicsCommandList_IASetIndexBuffer(cl->cl, &ibv); + ID3D12GraphicsCommandList_DrawIndexedInstanced(cl->cl, index_count, 1, 0, 0, 0); } } command_list_close(cl); @@ -3400,6 +3382,7 @@ INTERNAL void present_blit(struct swapchain_buffer *dst, struct dx12_resource *s struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT]; struct command_list *cl = command_list_open(cq->cl_pool); { + __profn("Blit"); __profnc_dx12(cl->cq->prof, cl->cl, "Blit", RGB32_F(0.5, 0.2, 0.2)); struct swapchain *swapchain = dst->swapchain;