dx12 cmd test
This commit is contained in:
parent
15b4ca9442
commit
9de72dceba
@ -68,6 +68,7 @@ SH_STRUCT(sh_material_instance {
|
|||||||
SH_DECL(float2x3, xf);
|
SH_DECL(float2x3, xf);
|
||||||
SH_DECL(float2, uv0);
|
SH_DECL(float2, uv0);
|
||||||
SH_DECL(float2, uv1);
|
SH_DECL(float2, uv1);
|
||||||
|
SH_DECL(uint, texture_nuri);
|
||||||
SH_DECL(uint, tint_srgb);
|
SH_DECL(uint, tint_srgb);
|
||||||
SH_DECL(float, emittance);
|
SH_DECL(float, emittance);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "atomic.h"
|
#include "atomic.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
|
||||||
/* Include common shader types */
|
/* Include common shader types */
|
||||||
#define SH_CPU 1
|
#define SH_CPU 1
|
||||||
@ -146,6 +147,8 @@ struct command_buffer_group {
|
|||||||
|
|
||||||
struct descriptor {
|
struct descriptor {
|
||||||
struct cpu_descriptor_heap *heap;
|
struct cpu_descriptor_heap *heap;
|
||||||
|
|
||||||
|
u32 index;
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE handle;
|
D3D12_CPU_DESCRIPTOR_HANDLE handle;
|
||||||
|
|
||||||
struct descriptor *next_free;
|
struct descriptor *next_free;
|
||||||
@ -397,16 +400,18 @@ INTERNAL struct handle_entry *handle_get_entry(struct gp_handle handle, struct s
|
|||||||
INTERNAL void *handle_get_data(struct gp_handle handle, enum handle_kind kind)
|
INTERNAL void *handle_get_data(struct gp_handle handle, enum handle_kind kind)
|
||||||
{
|
{
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
struct sys_lock lock = sys_mutex_lock_s(G.handle_entries_mutex);
|
if (handle.gen) {
|
||||||
{
|
struct sys_lock lock = sys_mutex_lock_s(G.handle_entries_mutex);
|
||||||
struct handle_entry *entry = handle_get_entry(handle, &lock);
|
{
|
||||||
data = entry->data;
|
struct handle_entry *entry = handle_get_entry(handle, &lock);
|
||||||
|
data = entry->data;
|
||||||
#if RTC
|
#if RTC
|
||||||
/* Handle should match expected kind */
|
/* Handle should match expected kind */
|
||||||
ASSERT(entry->kind == kind);
|
ASSERT(entry->kind == kind);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
sys_mutex_unlock(&lock);
|
||||||
}
|
}
|
||||||
sys_mutex_unlock(&lock);
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1159,19 +1164,22 @@ INTERNAL void pipeline_release(struct pipeline *pipeline)
|
|||||||
INTERNAL struct descriptor *descriptor_alloc(struct cpu_descriptor_heap *dh)
|
INTERNAL struct descriptor *descriptor_alloc(struct cpu_descriptor_heap *dh)
|
||||||
{
|
{
|
||||||
struct descriptor *d = NULL;
|
struct descriptor *d = NULL;
|
||||||
|
u32 index = 0;
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = ZI;
|
D3D12_CPU_DESCRIPTOR_HANDLE handle = ZI;
|
||||||
{
|
{
|
||||||
struct sys_lock lock = sys_mutex_lock_e(dh->mutex);
|
struct sys_lock lock = sys_mutex_lock_e(dh->mutex);
|
||||||
if (dh->first_free_descriptor) {
|
if (dh->first_free_descriptor) {
|
||||||
d = dh->first_free_descriptor;
|
d = dh->first_free_descriptor;
|
||||||
handle = d->handle;
|
handle = d->handle;
|
||||||
|
index = d->index;
|
||||||
} else {
|
} else {
|
||||||
if (dh->num_descriptors_reserved >= dh->num_descriptors_capacity) {
|
if (dh->num_descriptors_reserved >= dh->num_descriptors_capacity) {
|
||||||
sys_panic(LIT("Max descriptors reached in heap"));
|
sys_panic(LIT("Max descriptors reached in heap"));
|
||||||
}
|
}
|
||||||
|
|
||||||
d = arena_push_no_zero(dh->arena, struct descriptor);
|
d = arena_push_no_zero(dh->arena, struct descriptor);
|
||||||
handle.ptr = dh->handle.ptr + (dh->num_descriptors_reserved * dh->descriptor_size);
|
index = dh->num_descriptors_reserved;
|
||||||
|
handle.ptr = dh->handle.ptr + (index * dh->descriptor_size);
|
||||||
++dh->num_descriptors_reserved;
|
++dh->num_descriptors_reserved;
|
||||||
}
|
}
|
||||||
sys_mutex_unlock(&lock);
|
sys_mutex_unlock(&lock);
|
||||||
@ -1233,10 +1241,11 @@ INTERNAL void cpu_descriptor_heap_release(struct cpu_descriptor_heap *dh)
|
|||||||
* Flow
|
* Flow
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
/* TODO: Move command list out of flow struct */
|
|
||||||
struct flow {
|
struct flow {
|
||||||
struct arena *arena;
|
struct arena *arena;
|
||||||
|
|
||||||
|
/* Below fields are reset each dispatch */
|
||||||
|
struct sprite_scope *sprite_scope;
|
||||||
struct arena *material_instances_arena;
|
struct arena *material_instances_arena;
|
||||||
|
|
||||||
struct flow *next_free;
|
struct flow *next_free;
|
||||||
@ -1251,6 +1260,7 @@ INTERNAL struct flow *flow_alloc(void)
|
|||||||
flow->arena = arena;
|
flow->arena = arena;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flow->sprite_scope = sprite_scope_begin();
|
||||||
flow->material_instances_arena = arena_alloc(GIGABYTE(1));
|
flow->material_instances_arena = arena_alloc(GIGABYTE(1));
|
||||||
|
|
||||||
return flow;
|
return flow;
|
||||||
@ -1264,8 +1274,32 @@ struct gp_handle gp_flow_alloc(void)
|
|||||||
|
|
||||||
void gp_push_cmd(struct gp_handle gp_flow, struct gp_cmd_params params)
|
void gp_push_cmd(struct gp_handle gp_flow, struct gp_cmd_params params)
|
||||||
{
|
{
|
||||||
(UNUSED)gp_flow;
|
struct flow *flow = handle_get_data(gp_flow, DX12_HANDLE_KIND_FLOW);
|
||||||
(UNUSED)params;
|
if (flow) {
|
||||||
|
switch (params.kind) {
|
||||||
|
default: break;
|
||||||
|
|
||||||
|
case GP_CMD_KIND_DRAW_TEXTURE:
|
||||||
|
{
|
||||||
|
struct dx12_resource *texture = NULL;
|
||||||
|
if (params.texture.texture.gen != 0) {
|
||||||
|
texture = handle_get_data(params.texture.texture, DX12_HANDLE_KIND_RESOURCE);
|
||||||
|
} else if (params.texture.sprite.hash != 0) {
|
||||||
|
struct sprite_texture *st = sprite_texture_from_tag_async(flow->sprite_scope, params.texture.sprite);
|
||||||
|
texture = handle_get_data(st->texture, DX12_HANDLE_KIND_RESOURCE);
|
||||||
|
}
|
||||||
|
if (texture) {
|
||||||
|
struct sh_material_instance *instance = arena_push(flow->material_instances_arena, struct sh_material_instance);
|
||||||
|
instance->xf = sh_float2x3_from_xform(params.texture.xf);
|
||||||
|
instance->uv0 = sh_float2_from_v2(params.texture.clip.p0);
|
||||||
|
instance->uv1 = sh_float2_from_v2(params.texture.clip.p1);
|
||||||
|
instance->texture_nuri = sh_uint_from_u32(texture->srv_descriptor->index);
|
||||||
|
instance->tint_srgb = sh_uint_from_u32(params.texture.tint);
|
||||||
|
instance->emittance = sh_float_from_f32(params.texture.emittance);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -1877,7 +1911,6 @@ void gp_dispatch(struct gp_dispatch_params params)
|
|||||||
|
|
||||||
/* Upload instance buffer */
|
/* Upload instance buffer */
|
||||||
struct command_buffer *instance_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(flow->material_instances_arena));
|
struct command_buffer *instance_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(flow->material_instances_arena));
|
||||||
arena_reset(flow->material_instances_arena);
|
|
||||||
|
|
||||||
/* Upload descriptor heap */
|
/* Upload descriptor heap */
|
||||||
struct command_descriptor_heap *descriptor_heap = command_list_push_descriptor_heap(cl, G.cbv_srv_uav_heap);
|
struct command_descriptor_heap *descriptor_heap = command_list_push_descriptor_heap(cl, G.cbv_srv_uav_heap);
|
||||||
@ -1951,6 +1984,11 @@ void gp_dispatch(struct gp_dispatch_params params)
|
|||||||
|
|
||||||
/* Execute command list */
|
/* Execute command list */
|
||||||
command_list_close(cl);
|
command_list_close(cl);
|
||||||
|
|
||||||
|
/* Reset flow */
|
||||||
|
sprite_scope_end(flow->sprite_scope);
|
||||||
|
flow->sprite_scope = sprite_scope_begin();
|
||||||
|
arena_reset(flow->material_instances_arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user