From f3ca53381760afc791831fdc29b3e864726999e8 Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 3 Jun 2025 15:10:25 -0500 Subject: [PATCH] gpu pass -> dispatch --- src/config.h | 2 +- src/gpu.h | 16 +-- src/gpu_dx11.c | 274 +++++++++++++++++++++---------------------------- src/user.c | 28 ++--- 4 files changed, 141 insertions(+), 179 deletions(-) diff --git a/src/config.h b/src/config.h index 910c37b2..e3bee223 100644 --- a/src/config.h +++ b/src/config.h @@ -83,5 +83,5 @@ /* TODO: Move these to user-configurable settings */ #define AUDIO_ENABLED 0 -#define VSYNC_ENABLED 1 +#define VSYNC_ENABLED 0 #define USER_FPS_LIMIT 300 diff --git a/src/gpu.h b/src/gpu.h index e639b24e..a139e42e 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -111,29 +111,29 @@ void gpu_push_cmd(struct gpu_cmd_store gpu_cmd_store, struct gpu_cmd_params para void gpu_submit_cmds(struct gpu_cmd_store gpu_cmd_store); /* ========================== * - * Pass + * Dispatch * ========================== */ -struct gpu_pass_cmds_array { +struct gpu_dispatch_cmds_array { u64 count; struct gpu_cmd_store **cmds; }; -struct gpu_pass_params { - struct gpu_pass_cmds_array cmds_array; +struct gpu_dispatch_params { + struct gpu_dispatch_cmds_array cmds_array; struct gpu_texture draw_target; struct rect draw_target_viewport; }; -struct gpu_pass_state { +struct gpu_dispatch_state { u64 handle; }; -struct gpu_pass_state gpu_pass_state_alloc(void); +struct gpu_dispatch_state gpu_dispatch_state_alloc(void); -void gpu_pass_state_release(struct gpu_pass_state gpu_pass_state); +void gpu_dispatch_state_release(struct gpu_dispatch_state gpu_dispatch_state); -void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params params); +void gpu_dispatch(struct gpu_dispatch_state gpu_dispatch_state, struct gpu_dispatch_params params); /* ========================== * * Backbuffer diff --git a/src/gpu_dx11.c b/src/gpu_dx11.c index 51bca839..f6cf6999 100644 --- a/src/gpu_dx11.c +++ b/src/gpu_dx11.c @@ -28,7 +28,7 @@ /* FIXME: Enable this and resolve unreleased references */ #if RTC -# define DX11_DEBUG 1 +# define DX11_DEBUG 0 # define DX11_SHADER_DEBUG 1 #else # define DX11_DEBUG 0 @@ -63,9 +63,11 @@ struct dx11_shader { ID3D11PixelShader *ps; }; -struct dx11_pass_state { +struct dx11_dispatch_state { struct dx11_texture *albedo; - struct dx11_pass_state *next_free; + struct dx11_buffer *constant_buffer; + + struct dx11_dispatch_state *next_free; }; struct dx11_buffer { @@ -142,7 +144,6 @@ struct dx11_cmd_store { struct dx11_cmd *gpu_last_cmd; struct { - struct dx11_buffer *constant_buffer; struct { struct dx11_buffer *vertex_buffer; struct dx11_buffer *index_buffer; @@ -219,10 +220,10 @@ GLOBAL struct { struct arena cmd_stores_arena; struct dx11_cmd_store *first_free_cmd_store; - /* Pass state pool */ - struct sys_mutex pass_states_mutex; - struct arena pass_states_arena; - struct dx11_pass_state *first_free_pass_state; + /* Dispatch state pool */ + struct sys_mutex dispatch_states_mutex; + struct arena dispatch_states_arena; + struct dx11_dispatch_state *first_free_dispatch_state; /* Texture pool */ struct sys_mutex textures_mutex; @@ -277,9 +278,9 @@ struct gpu_startup_receipt gpu_startup(struct sys_window *window) G.cmd_stores_mutex = sys_mutex_alloc(); G.cmd_stores_arena = arena_alloc(GIGABYTE(64)); - /* Initialize pass state pool */ - G.pass_states_mutex = sys_mutex_alloc(); - G.pass_states_arena = arena_alloc(GIGABYTE(64)); + /* Initialize dispatch state pool */ + G.dispatch_states_mutex = sys_mutex_alloc(); + G.dispatch_states_arena = arena_alloc(GIGABYTE(64)); /* Initialize texture pool */ G.textures_mutex = sys_mutex_alloc(); @@ -1259,12 +1260,7 @@ struct gpu_cmd_store gpu_cmd_store_alloc(void) arena_reset(&store->gpu_cmds_arena); } - /* Desc templates */ - const D3D11_BUFFER_DESC constant_buffer_desc = { - .Usage = D3D11_USAGE_DYNAMIC, - .BindFlags = D3D11_BIND_CONSTANT_BUFFER, - .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE - }; + /* Desc template */ const D3D11_BUFFER_DESC structured_buffer_desc = { .Usage = D3D11_USAGE_DYNAMIC, .BindFlags = D3D11_BIND_SHADER_RESOURCE, @@ -1274,11 +1270,6 @@ struct gpu_cmd_store gpu_cmd_store_alloc(void) /* Allocate buffers */ { - /* Constant buffer */ - { - store->buffers.constant_buffer = dx11_buffer_alloc(constant_buffer_desc, NULL); - } - /* Mesh buffers */ { D3D11_BUFFER_DESC vdesc = ZI; @@ -1524,21 +1515,21 @@ void gpu_submit_cmds(struct gpu_cmd_store gpu_cmd_store) } /* ========================== * - * Pass state + * Dispatch state * ========================== */ -struct gpu_pass_state gpu_pass_state_alloc(void) +struct gpu_dispatch_state gpu_dispatch_state_alloc(void) { __prof; - struct dx11_pass_state *state = NULL; + struct dx11_dispatch_state *state = NULL; { { - struct sys_lock lock = sys_mutex_lock_e(&G.pass_states_mutex); - if (G.first_free_pass_state) { - state = G.first_free_pass_state; - G.first_free_pass_state = state->next_free; + struct sys_lock lock = sys_mutex_lock_e(&G.dispatch_states_mutex); + if (G.first_free_dispatch_state) { + state = G.first_free_dispatch_state; + G.first_free_dispatch_state = state->next_free; } else { - state = arena_push_no_zero(&G.pass_states_arena, struct dx11_pass_state); + state = arena_push_no_zero(&G.dispatch_states_arena, struct dx11_dispatch_state); } sys_mutex_unlock(&lock); } @@ -1546,21 +1537,21 @@ struct gpu_pass_state gpu_pass_state_alloc(void) } - struct gpu_pass_state res = ZI; + struct gpu_dispatch_state res = ZI; res.handle = (u64)state; return res; } -void gpu_pass_state_release(struct gpu_pass_state gpu_pass_state) +void gpu_dispatch_state_release(struct gpu_dispatch_state gpu_dispatch_state) { /* TODO */ __prof; ASSERT(false); - (UNUSED)gpu_pass_state; + (UNUSED)gpu_dispatch_state; } /* ========================== * - * Pass + * Dispatch * ========================== */ enum dx11_unbind_flags { @@ -1629,13 +1620,13 @@ INTERNAL void dx11_unbind(u32 flags) } } -/* TODO: Lock resources during pass */ -void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params params) +/* TODO: Lock resources during dispatch */ +void gpu_dispatch(struct gpu_dispatch_state gpu_dispatch_state, struct gpu_dispatch_params params) { __prof; - __profscope_dx11(G.profiling_ctx, Run pass, RGB_F(0.5, 0.2, 0.2)); + __profscope_dx11(G.profiling_ctx, Dispatch, RGB_F(0.5, 0.2, 0.2)); struct sprite_scope *sprite_scope = sprite_scope_begin(); - struct dx11_pass_state *state = (struct dx11_pass_state *)gpu_pass_state.handle; + struct dx11_dispatch_state *state = (struct dx11_dispatch_state *)gpu_dispatch_state.handle; struct rect viewport = params.draw_target_viewport; @@ -1649,99 +1640,21 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p d3d11_viewport.TopLeftY = viewport.y; ID3D11DeviceContext_RSSetViewports(G.devcon, 1, &d3d11_viewport); - struct mat4x4 vp_matrix = calculate_vp(XFORM_IDENT, viewport.width, viewport.height); - -#if 0 - /* GI pass */ - { - __profscope(GI pass); - __profscope_dx11(G.profiling_ctx, GI pass, RGB_F(0.5, 0.5, 0.5)); - for (u64 cmd_stores_array_index = 0; cmd_stores_array_index < params.cmds_array.count; ++cmd_stores_array_index) { - struct dx11_cmd_store *store = (struct dx11_cmd_store *)params.cmds_array.cmds[cmd_stores_array_index]->handle; - for (struct dx11_cmd *cmd = store->gpu_first_cmd; cmd; cmd = cmd->next) { - enum gpu_cmd_kind cmd_kind = cmd->kind; - - switch (cmd_kind) { - default: break; - - case GPU_CMD_KIND_DRAW_VIEW: - { - __profscope(Set draw view); - vp_matrix = calculate_vp(cmd->view.xf, viewport.width, viewport.height); - } break; - - case GPU_CMD_KIND_DRAW_TEXTURE: - { - __profscope(Draw texture emittance); - __profscope_dx11(G.profiling_ctx, Draw texture emittance, RGB_F(0.2, 0.5, 0.2)); - struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEXTURE]; - if (shader->valid) { - struct dx11_texture *texture = NULL; - if (cmd->texture.texture.handle) { - /* Load texture if handle is set */ - texture = (struct dx11_texture *)cmd->texture.texture.handle; - } 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.handle; - } - } - - if (texture && texture->srv && shader->valid) { - struct dx11_buffer *constant_buffer = store->buffers.constant_buffer; - struct dx11_buffer *instance_buffer = store->buffers.texture.instance_buffer; - u32 instance_offset = cmd->texture.instance_offset; - u32 instance_count = cmd->texture.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_texture_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_texture_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 instance buffer */ - ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); - ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); - - /* Bind texture */ - ID3D11DeviceContext_VSSetShaderResources(G.devcon, 1, 1, &texture->srv); - ID3D11DeviceContext_PSSetShaderResources(G.devcon, 1, 1, &texture->srv); - - /* Bind RTV */ - ID3D11DeviceContext_OMSetRenderTargets(G.devcon, 1, &draw_target->rtv, 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; - } - } - } - } -#endif - struct dx11_texture *final_tex = (struct dx11_texture *)params.draw_target.handle; struct v2i32 final_tex_size = final_tex->size; + /* Allocate constant buffer */ + struct dx11_buffer *constant_buffer = state->constant_buffer; + if (!constant_buffer) { + const D3D11_BUFFER_DESC desc = { + .Usage = D3D11_USAGE_DYNAMIC, + .BindFlags = D3D11_BIND_CONSTANT_BUFFER, + .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE + }; + constant_buffer = dx11_buffer_alloc(desc, NULL); + state->constant_buffer = constant_buffer; + } + /* Allocate / resize albedo */ struct dx11_texture *albedo_tex = state->albedo; if (!albedo_tex || !v2i32_eq(albedo_tex->size, final_tex->size)) { @@ -1753,6 +1666,7 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p } /* Regular pass */ + struct mat4x4 vp_matrix = calculate_vp(XFORM_IDENT, viewport.width, viewport.height); { __profscope(Regular pass); __profscope_dx11(G.profiling_ctx, Regular pass, RGB_F(0.2, 0.5, 0.5)); @@ -1780,7 +1694,6 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p __profscope_dx11(G.profiling_ctx, Draw mesh, RGB_F(0.5, 0.2, 0.2)); struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_MESH]; if (shader->valid) { - struct dx11_buffer *constant_buffer = store->buffers.constant_buffer; struct dx11_buffer *vertex_buffer = store->buffers.mesh.vertex_buffer; struct dx11_buffer *index_buffer = store->buffers.mesh.index_buffer; @@ -1791,8 +1704,6 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p /* Bind shader */ ID3D11DeviceContext_VSSetShader(G.devcon, shader->vs, 0, 0); ID3D11DeviceContext_PSSetShader(G.devcon, shader->ps, 0, 0); - - /* Bind input layout */ ID3D11DeviceContext_IASetInputLayout(G.devcon, shader->input_layout); /* Fill & bind constant buffer */ @@ -1810,8 +1721,9 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p ID3D11DeviceContext_IASetVertexBuffers(G.devcon, 0, 1, &vertex_buffer->gpu_buffer, &stride, &zero); ID3D11DeviceContext_IASetIndexBuffer(G.devcon, index_buffer->gpu_buffer, DXGI_FORMAT_R16_UINT, zero); - /* Bind RTV */ - ID3D11DeviceContext_OMSetRenderTargets(G.devcon, 1, &final_tex->rtv, NULL); + /* 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); @@ -1840,8 +1752,7 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p } } - if (texture && texture->srv && shader->valid) { - struct dx11_buffer *constant_buffer = store->buffers.constant_buffer; + if (texture && texture->srv) { struct dx11_buffer *instance_buffer = store->buffers.texture.instance_buffer; u32 instance_offset = cmd->texture.instance_offset; u32 instance_count = cmd->texture.instance_count; @@ -1865,16 +1776,14 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p 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 instance buffer */ - ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); - ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); + /* Bind SRVs */ + ID3D11ShaderResourceView *srvs[] = { instance_buffer->srv, texture->srv }; + ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs); + ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, ARRAY_COUNT(srvs), srvs); - /* Bind texture */ - ID3D11DeviceContext_VSSetShaderResources(G.devcon, 1, 1, &texture->srv); - ID3D11DeviceContext_PSSetShaderResources(G.devcon, 1, 1, &texture->srv); - - /* Bind RTV */ - ID3D11DeviceContext_OMSetRenderTargets(G.devcon, 1, &final_tex->rtv, NULL); + /* 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); @@ -1892,7 +1801,6 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p __profscope_dx11(G.profiling_ctx, Draw grid, RGB_F(0.2, 0.2, 0.5)); struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_GRID]; if (shader->valid) { - struct dx11_buffer *constant_buffer = store->buffers.constant_buffer; struct dx11_buffer *instance_buffer = store->buffers.grid.instance_buffer; u32 instance_offset = cmd->grid.instance_offset; u32 instance_count = cmd->grid.instance_count; @@ -1916,12 +1824,14 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p 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 instance buffer */ - ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); - ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); + /* 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 RTV */ - ID3D11DeviceContext_OMSetRenderTargets(G.devcon, 1, &final_tex->rtv, NULL); + /* 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); @@ -1938,7 +1848,6 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p __profscope_dx11(G.profiling_ctx, Test, RGB_F(1, 0.2, 1)); struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEST]; if (shader->valid) { - struct dx11_buffer *constant_buffer = store->buffers.constant_buffer; struct dx11_buffer *instance_buffer = store->buffers.test.instance_buffer; u32 instance_offset = cmd->test.instance_offset; u32 instance_count = cmd->test.instance_count; @@ -1962,12 +1871,14 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p 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 instance buffer */ - ID3D11DeviceContext_VSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); - ID3D11DeviceContext_PSSetShaderResources(G.devcon, 0, 1, &instance_buffer->srv); + /* 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 RTV */ - ID3D11DeviceContext_OMSetRenderTargets(G.devcon, 1, &final_tex->rtv, NULL); + /* 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); @@ -1982,6 +1893,57 @@ void gpu_run_pass(struct gpu_pass_state gpu_pass_state, struct gpu_pass_params p } } + /* Finalize */ +#if 0 + vp_matrix = calculate_vp(XFORM_IDENT, viewport.width, viewport.height); + { + __profscope(Finalize); + __profscope_dx11(G.profiling_ctx, Finalize, RGB_F(0.5, 0.2, 0.5)); + struct dx11_shader *shader = &G.shaders[DX11_SHADER_KIND_TEXTURE]; + if (shader->valid) { + struct dx11_texture *texture = NULL; + + struct dx11_buffer *instance_buffer = store->buffers.texture.instance_buffer; + u32 instance_offset = cmd->texture.instance_offset; + u32 instance_count = cmd->texture.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_texture_uniform *uniform = dx11_buffer_push(constant_buffer, sizeof(struct dx11_texture_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, texture->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); + } +#endif + sprite_scope_end(sprite_scope); } diff --git a/src/user.c b/src/user.c index 38fe0303..8e960154 100644 --- a/src/user.c +++ b/src/user.c @@ -78,8 +78,8 @@ GLOBAL struct { struct gpu_cmd_store user_gpu_cmd_store; struct gpu_cmd_store backbuffer_gpu_cmd_store; - struct gpu_pass_state user_pass_state; - struct gpu_pass_state backbuffer_pass_state; + struct gpu_dispatch_state user_dispatch_state; + struct gpu_dispatch_state backbuffer_dispatch_state; struct xform world_to_user_xf; @@ -261,8 +261,8 @@ struct user_startup_receipt user_startup(struct work_startup_receipt *work_sr, G.world_gpu_cmd_store = gpu_cmd_store_alloc(); G.user_gpu_cmd_store = gpu_cmd_store_alloc(); G.backbuffer_gpu_cmd_store = gpu_cmd_store_alloc(); - G.user_pass_state = gpu_pass_state_alloc(); - G.backbuffer_pass_state = gpu_pass_state_alloc(); + G.user_dispatch_state = gpu_dispatch_state_alloc(); + G.backbuffer_dispatch_state = gpu_dispatch_state_alloc(); //log_register_callback(debug_console_log_callback, LOG_LEVEL_SUCCESS); log_register_callback(debug_console_log_callback, LOG_LEVEL_DEBUG); @@ -2116,24 +2116,24 @@ INTERNAL void user_update(void) /* Render to user texture */ { - struct gpu_cmd_store *pass_cmds[] = { &G.world_gpu_cmd_store, &G.user_gpu_cmd_store }; - struct gpu_pass_params params = ZI; - params.cmds_array.cmds = pass_cmds; - params.cmds_array.count = ARRAY_COUNT(pass_cmds); + struct gpu_cmd_store *dispatch_cmds[] = { &G.world_gpu_cmd_store, &G.user_gpu_cmd_store }; + struct gpu_dispatch_params params = ZI; + params.cmds_array.cmds = dispatch_cmds; + params.cmds_array.count = ARRAY_COUNT(dispatch_cmds); params.draw_target = G.user_texture; params.draw_target_viewport = user_viewport; - gpu_run_pass(G.user_pass_state, params); + gpu_dispatch(G.user_dispatch_state, params); } /* Render to backbuffer texture */ { - struct gpu_cmd_store *pass_cmds[] = { &G.backbuffer_gpu_cmd_store }; - struct gpu_pass_params params = ZI; - params.cmds_array.cmds = pass_cmds; - params.cmds_array.count = ARRAY_COUNT(pass_cmds); + struct gpu_cmd_store *dispatch_cmds[] = { &G.backbuffer_gpu_cmd_store }; + struct gpu_dispatch_params params = ZI; + params.cmds_array.cmds = dispatch_cmds; + params.cmds_array.count = ARRAY_COUNT(dispatch_cmds); params.draw_target = G.backbuffer_texture; params.draw_target_viewport = backbuffer_viewport; - gpu_run_pass(G.backbuffer_pass_state, params); + gpu_dispatch(G.backbuffer_dispatch_state, params); } /* Swap backbuffer */