full bindless
This commit is contained in:
parent
1fc534004e
commit
26a64ce1eb
20
build.c
20
build.c
@ -449,6 +449,8 @@ void OnBuild(StringList cli_args)
|
|||||||
* Determine compiler args
|
* Determine compiler args
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
|
String dxc_args_format = { 0 };
|
||||||
|
|
||||||
StringList c_compile_args = { 0 };
|
StringList c_compile_args = { 0 };
|
||||||
StringList cpp_compile_args = { 0 };
|
StringList cpp_compile_args = { 0 };
|
||||||
StringList pch_c_compile_args = { 0 };
|
StringList pch_c_compile_args = { 0 };
|
||||||
@ -519,12 +521,6 @@ void OnBuild(StringList cli_args)
|
|||||||
StringListAppend(&perm, &link_warnings, warnings);
|
StringListAppend(&perm, &link_warnings, warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DXC */
|
|
||||||
{
|
|
||||||
StringListAppend(&perm, &dxc_compile_args, Lit("dxc %F -Fo %F -E %F -T %F -H"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* RTC */
|
/* RTC */
|
||||||
if (arg_rtc) {
|
if (arg_rtc) {
|
||||||
if (!arg_crtlib) {
|
if (!arg_crtlib) {
|
||||||
@ -631,6 +627,13 @@ void OnBuild(StringList cli_args)
|
|||||||
String incbin_dir = StringReplace(&perm, out_inc_dir_path, Lit("\\"), Lit("/"));
|
String incbin_dir = StringReplace(&perm, out_inc_dir_path, Lit("\\"), Lit("/"));
|
||||||
StringListAppend(&perm, &compile_args, StringF(&perm, Lit("-DINCBIN_DIR_RAW=\"%F\""), FmtStr(incbin_dir)));
|
StringListAppend(&perm, &compile_args, StringF(&perm, Lit("-DINCBIN_DIR_RAW=\"%F\""), FmtStr(incbin_dir)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* DXC */
|
||||||
|
{
|
||||||
|
StringListAppend(&perm, &dxc_compile_args, Lit("-H -WX -Ges"));
|
||||||
|
String dxc_args_define = StringFromStringList(&perm, Lit(" "), dxc_compile_args);
|
||||||
|
StringListAppend(&perm, &compile_args, StringF(&perm, Lit("-DDXC_ARGS=\"%F\""), FmtStr(dxc_args_define)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -699,7 +702,8 @@ void OnBuild(StringList cli_args)
|
|||||||
{
|
{
|
||||||
AddSyncPoint();
|
AddSyncPoint();
|
||||||
|
|
||||||
String dxc_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), dxc_compile_args);
|
String dxc_args_bare = StringFromStringLists(&perm, Lit(" "), dxc_compile_args);
|
||||||
|
String dxc_compile_args_fmt = StringF(&perm, Lit("dxc %%F -E %%F -T %%F -Fo %%F %F"), FmtStr(dxc_args_bare));
|
||||||
for (D_TagListNode *n = src_input_files.first; n; n = n->next) {
|
for (D_TagListNode *n = src_input_files.first; n; n = n->next) {
|
||||||
D_Tag file = n->tag;
|
D_Tag file = n->tag;
|
||||||
String path = file.full_path;
|
String path = file.full_path;
|
||||||
@ -747,7 +751,7 @@ void OnBuild(StringList cli_args)
|
|||||||
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(name), FmtStr(D_GetName(dxc_file)));
|
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(name), FmtStr(D_GetName(dxc_file)));
|
||||||
{
|
{
|
||||||
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
|
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
|
||||||
bs_arg->cmd = StringF(&perm, dxc_compile_args_fmt, FmtStr(file.full_path), FmtStr(dxc_file.full_path), FmtStr(entry), FmtStr(profile));
|
bs_arg->cmd = StringF(&perm, dxc_compile_args_fmt, FmtStr(file.full_path), FmtStr(entry), FmtStr(profile), FmtStr(dxc_file.full_path));
|
||||||
bs_arg->failure_flag = &shader_success_flag;
|
bs_arg->failure_flag = &shader_success_flag;
|
||||||
bs_arg->delete_file_on_failure = dxc_file;
|
bs_arg->delete_file_on_failure = dxc_file;
|
||||||
bs_arg->dxc_depfile_dependent = dxc_file;
|
bs_arg->dxc_depfile_dependent = dxc_file;
|
||||||
|
|||||||
@ -15,7 +15,7 @@ extern "C"
|
|||||||
#pragma comment(lib, "dxcompiler")
|
#pragma comment(lib, "dxcompiler")
|
||||||
|
|
||||||
/* https://github.com/microsoft/DirectXShaderCompiler/wiki/Using-dxc.exe-and-dxcompiler.dll */
|
/* https://github.com/microsoft/DirectXShaderCompiler/wiki/Using-dxc.exe-and-dxcompiler.dll */
|
||||||
struct dxc_compile_result dxc_compile(struct arena *arena, string shader_source, i32 num_args, struct string *args)
|
struct dxc_compile_result dxc_compile(struct arena *arena, struct string shader_source, i32 num_args, struct string *args)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct arena_temp scratch = scratch_begin(arena);
|
struct arena_temp scratch = scratch_begin(arena);
|
||||||
|
|||||||
2
src/gp.h
2
src/gp.h
@ -116,7 +116,7 @@ struct gp_render_sig *gp_render_sig_alloc(void);
|
|||||||
/* Returns a cmd id internal to the sig */
|
/* Returns a cmd id internal to the sig */
|
||||||
i32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_desc *desc);
|
i32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_desc *desc);
|
||||||
|
|
||||||
struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params render_params);
|
struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp_render_params render_params);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Memory info
|
* Memory info
|
||||||
|
|||||||
468
src/gp_dx12.c
468
src/gp_dx12.c
@ -106,6 +106,7 @@ struct pipeline {
|
|||||||
struct string name;
|
struct string name;
|
||||||
u64 hash;
|
u64 hash;
|
||||||
b32 success;
|
b32 success;
|
||||||
|
b32 is_gfx;
|
||||||
struct string error;
|
struct string error;
|
||||||
i64 compilation_time_ns;
|
i64 compilation_time_ns;
|
||||||
|
|
||||||
@ -173,6 +174,8 @@ struct command_list {
|
|||||||
struct ID3D12GraphicsCommandList *cl;
|
struct ID3D12GraphicsCommandList *cl;
|
||||||
struct snc_lock global_record_lock;
|
struct snc_lock global_record_lock;
|
||||||
|
|
||||||
|
struct pipeline *cur_pipeline;
|
||||||
|
|
||||||
struct command_descriptor_heap *first_command_descriptor_heap;
|
struct command_descriptor_heap *first_command_descriptor_heap;
|
||||||
struct command_buffer *first_command_buffer;
|
struct command_buffer *first_command_buffer;
|
||||||
|
|
||||||
@ -225,14 +228,6 @@ struct descriptor {
|
|||||||
struct descriptor *next_free;
|
struct descriptor *next_free;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum dx12_resource_view_flags {
|
|
||||||
DX12_RESOURCE_VIEW_FLAG_NONE = 0,
|
|
||||||
DX12_RESOURCE_VIEW_FLAG_CBV = (1 << 1),
|
|
||||||
DX12_RESOURCE_VIEW_FLAG_SRV = (1 << 2),
|
|
||||||
DX12_RESOURCE_VIEW_FLAG_UAV = (1 << 3),
|
|
||||||
DX12_RESOURCE_VIEW_FLAG_RTV = (1 << 4)
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dx12_resource {
|
struct dx12_resource {
|
||||||
enum D3D12_RESOURCE_STATES state;
|
enum D3D12_RESOURCE_STATES state;
|
||||||
ID3D12Resource *resource;
|
ID3D12Resource *resource;
|
||||||
@ -312,7 +307,9 @@ INTERNAL SYS_JOB_DEF(dx12_evictor_job, _);
|
|||||||
|
|
||||||
INTERNAL void fenced_release(void *data, enum fenced_release_kind kind);
|
INTERNAL void fenced_release(void *data, enum fenced_release_kind kind);
|
||||||
|
|
||||||
INTERNAL struct dx12_resource *dx12_resource_alloc(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state, i32 view_flags);
|
INTERNAL struct dx12_resource *dx12_resource_alloc(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state);
|
||||||
|
|
||||||
|
INTERNAL struct descriptor *descriptor_alloc(struct cpu_descriptor_heap *dh);
|
||||||
|
|
||||||
struct command_queue_alloc_job_sig { struct command_queue_desc *descs_in; struct command_queue **cqs_out; };
|
struct command_queue_alloc_job_sig { struct command_queue_desc *descs_in; struct command_queue **cqs_out; };
|
||||||
INTERNAL SYS_JOB_DEF(command_queue_alloc_job, job);
|
INTERNAL SYS_JOB_DEF(command_queue_alloc_job, job);
|
||||||
@ -826,8 +823,6 @@ INTERNAL void dx12_init_noise(void)
|
|||||||
FMT_UINT(expected_size), FMT_UINT(data.len)));
|
FMT_UINT(expected_size), FMT_UINT(data.len)));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
enum dx12_resource_view_flags view_flags = DX12_RESOURCE_VIEW_FLAG_SRV;
|
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES heap_props = { .Type = D3D12_HEAP_TYPE_DEFAULT };
|
D3D12_HEAP_PROPERTIES heap_props = { .Type = D3D12_HEAP_TYPE_DEFAULT };
|
||||||
heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||||
heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||||
@ -847,7 +842,9 @@ INTERNAL void dx12_init_noise(void)
|
|||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
desc.SampleDesc.Quality = 0;
|
desc.SampleDesc.Quality = 0;
|
||||||
|
|
||||||
struct dx12_resource *r = dx12_resource_alloc(heap_props, heap_flags, desc, D3D12_RESOURCE_STATE_COPY_DEST, view_flags);
|
struct dx12_resource *r = dx12_resource_alloc(heap_props, heap_flags, desc, D3D12_RESOURCE_STATE_COPY_DEST);
|
||||||
|
r->srv_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
||||||
|
ID3D12Device_CreateShaderResourceView(G.device, r->resource, 0, r->srv_descriptor->handle);
|
||||||
|
|
||||||
/* Upload texture */
|
/* Upload texture */
|
||||||
{
|
{
|
||||||
@ -907,15 +904,24 @@ INTERNAL SYS_JOB_DEF(shader_compile_job, job)
|
|||||||
{
|
{
|
||||||
__profn("Compile shader");
|
__profn("Compile shader");
|
||||||
logf_info("Compiling shader \"%F:%F\"", FMT_STR(desc->friendly_name), FMT_STR(desc->entry));
|
logf_info("Compiling shader \"%F:%F\"", FMT_STR(desc->friendly_name), FMT_STR(desc->entry));
|
||||||
struct string args[] = {
|
/* NOTE: `DXC_ARGS` is supplied by build system at compile time */
|
||||||
|
char *dxc_args_cstr = STRINGIZE(DXC_ARGS);
|
||||||
|
struct string dxc_args_str = string_from_cstr_no_limit(dxc_args_cstr);
|
||||||
|
struct string_array dxc_args_array = string_split(scratch.arena, dxc_args_str, LIT(" "));
|
||||||
|
struct string shader_args[] = {
|
||||||
desc->friendly_name,
|
desc->friendly_name,
|
||||||
LIT("-E"), desc->entry,
|
LIT("-E"), desc->entry,
|
||||||
LIT("-T"), desc->target,
|
LIT("-T"), desc->target,
|
||||||
LIT("-D SH_CPU=0"),
|
|
||||||
LIT("-Zi"),
|
|
||||||
LIT("-Qembed_debug")
|
|
||||||
};
|
};
|
||||||
dxc_result = dxc_compile(arena, desc->src, countof(args), args);
|
u32 num_args = countof(shader_args) + dxc_args_array.count;
|
||||||
|
struct string *args = arena_push_array(scratch.arena, struct string, num_args);
|
||||||
|
for (u32 i = 0; i < countof(shader_args); ++i) {
|
||||||
|
args[i] = shader_args[i];
|
||||||
|
}
|
||||||
|
for (u32 i = 0; i < dxc_args_array.count; ++i) {
|
||||||
|
args[i + countof(shader_args)] = dxc_args_array.strings[i];
|
||||||
|
}
|
||||||
|
dxc_result = dxc_compile(arena, desc->src, num_args, args);
|
||||||
}
|
}
|
||||||
result->success = dxc_result.success;
|
result->success = dxc_result.success;
|
||||||
result->dxc = dxc_result.dxc;
|
result->dxc = dxc_result.dxc;
|
||||||
@ -1191,6 +1197,7 @@ INTERNAL SYS_JOB_DEF(pipeline_alloc_job, job)
|
|||||||
pipeline->rootsig = rootsig;
|
pipeline->rootsig = rootsig;
|
||||||
pipeline->compilation_time_ns = sys_time_ns() - start_ns;
|
pipeline->compilation_time_ns = sys_time_ns() - start_ns;
|
||||||
pipeline->success = success;
|
pipeline->success = success;
|
||||||
|
pipeline->is_gfx = cs_dxc.len == 0;
|
||||||
pipeline->error = error_str;
|
pipeline->error = error_str;
|
||||||
|
|
||||||
if (rootsig_blob) {
|
if (rootsig_blob) {
|
||||||
@ -1624,7 +1631,7 @@ INTERNAL void fenced_release(void *data, enum fenced_release_kind kind)
|
|||||||
* Resource
|
* Resource
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
INTERNAL struct dx12_resource *dx12_resource_alloc(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state, i32 view_flags)
|
INTERNAL struct dx12_resource *dx12_resource_alloc(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct dx12_resource *r = 0;
|
struct dx12_resource *r = 0;
|
||||||
@ -1654,28 +1661,6 @@ INTERNAL struct dx12_resource *dx12_resource_alloc(D3D12_HEAP_PROPERTIES heap_pr
|
|||||||
r->gpu_address = ID3D12Resource_GetGPUVirtualAddress(r->resource);
|
r->gpu_address = ID3D12Resource_GetGPUVirtualAddress(r->resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view_flags & DX12_RESOURCE_VIEW_FLAG_CBV) {
|
|
||||||
r->cbv_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
|
||||||
D3D12_CONSTANT_BUFFER_VIEW_DESC cbv_desc = ZI;
|
|
||||||
cbv_desc.BufferLocation = r->gpu_address;
|
|
||||||
//cbv_desc.SizeInBytes = desc.ByteWidth;
|
|
||||||
/* FIXME: Get actual size */
|
|
||||||
cbv_desc.SizeInBytes = KIBI(64);
|
|
||||||
ID3D12Device_CreateConstantBufferView(G.device, &cbv_desc, r->cbv_descriptor->handle);
|
|
||||||
}
|
|
||||||
if (view_flags & DX12_RESOURCE_VIEW_FLAG_SRV) {
|
|
||||||
r->srv_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
|
||||||
ID3D12Device_CreateShaderResourceView(G.device, r->resource, 0, r->srv_descriptor->handle);
|
|
||||||
}
|
|
||||||
if (view_flags & DX12_RESOURCE_VIEW_FLAG_UAV) {
|
|
||||||
r->uav_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
|
||||||
ID3D12Device_CreateUnorderedAccessView(G.device, r->resource, 0, 0, r->uav_descriptor->handle);
|
|
||||||
}
|
|
||||||
if (view_flags & DX12_RESOURCE_VIEW_FLAG_RTV) {
|
|
||||||
r->rtv_descriptor = descriptor_alloc(G.rtv_heap);
|
|
||||||
ID3D12Device_CreateRenderTargetView(G.device, r->resource, 0, r->rtv_descriptor->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2100,17 +2085,21 @@ INTERNAL u64 align_up_pow2(u64 v)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl, struct string data)
|
#define command_list_push_buffer(cl, count, elems) _command_list_push_buffer((cl), count * ((elems) ? sizeof(*(elems)) : 0), (elems), (elems) ? sizeof(*(elems)) : 1)
|
||||||
|
INTERNAL struct command_buffer *_command_list_push_buffer(struct command_list *cl, u64 data_len, void *data, u64 data_stride)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
|
|
||||||
|
/* Data length should be a multiple of stride */
|
||||||
|
ASSERT(data_len % data_stride == 0);
|
||||||
|
|
||||||
/* Determine size */
|
/* Determine size */
|
||||||
u64 size = max_u64(DX12_COMMAND_BUFFER_MIN_SIZE, align_up_pow2(data.len));
|
u64 size = max_u64(DX12_COMMAND_BUFFER_MIN_SIZE, align_up_pow2(data_len));
|
||||||
|
|
||||||
/* Allocate buffer */
|
/* Allocate buffer */
|
||||||
struct command_buffer_group *cb_group = 0;
|
struct command_buffer_group *cb_group = 0;
|
||||||
struct command_buffer *cb = 0;
|
struct command_buffer *cb = 0;
|
||||||
struct dx12_resource *resource = 0;
|
struct dx12_resource *r = 0;
|
||||||
{
|
{
|
||||||
struct snc_lock lock = snc_lock_e(&G.command_buffers_mutex);
|
struct snc_lock lock = snc_lock_e(&G.command_buffers_mutex);
|
||||||
|
|
||||||
@ -2135,7 +2124,7 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
|||||||
}
|
}
|
||||||
if (cb) {
|
if (cb) {
|
||||||
/* Remove from submitted list */
|
/* Remove from submitted list */
|
||||||
resource = cb->resource;
|
r = cb->resource;
|
||||||
struct command_buffer *prev = cb->prev_submitted;
|
struct command_buffer *prev = cb->prev_submitted;
|
||||||
struct command_buffer *next = cb->next_submitted;
|
struct command_buffer *next = cb->next_submitted;
|
||||||
if (prev) {
|
if (prev) {
|
||||||
@ -2156,14 +2145,10 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
|||||||
}
|
}
|
||||||
MEMZERO_STRUCT(cb);
|
MEMZERO_STRUCT(cb);
|
||||||
cb->group = cb_group;
|
cb->group = cb_group;
|
||||||
cb->size = data.len;
|
cb->size = data_len;
|
||||||
|
|
||||||
/* Create upload heap */
|
/* Create upload heap */
|
||||||
if (resource) {
|
if (!r) {
|
||||||
cb->resource = resource;
|
|
||||||
} else {
|
|
||||||
enum dx12_resource_view_flags view_flags = DX12_RESOURCE_VIEW_FLAG_NONE;
|
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES heap_props = { .Type = D3D12_HEAP_TYPE_UPLOAD };
|
D3D12_HEAP_PROPERTIES heap_props = { .Type = D3D12_HEAP_TYPE_UPLOAD };
|
||||||
heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||||
heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||||
@ -2171,6 +2156,7 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
|||||||
D3D12_HEAP_FLAGS heap_flags = D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
|
D3D12_HEAP_FLAGS heap_flags = D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
|
||||||
|
|
||||||
D3D12_RESOURCE_DESC desc = ZI;
|
D3D12_RESOURCE_DESC desc = ZI;
|
||||||
|
desc.Flags = 0;
|
||||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
||||||
desc.Format = DXGI_FORMAT_UNKNOWN;
|
desc.Format = DXGI_FORMAT_UNKNOWN;
|
||||||
@ -2183,10 +2169,24 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
|||||||
desc.SampleDesc.Quality = 0;
|
desc.SampleDesc.Quality = 0;
|
||||||
D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_GENERIC_READ;
|
D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_GENERIC_READ;
|
||||||
|
|
||||||
cb->resource = dx12_resource_alloc(heap_props, heap_flags, desc, initial_state, view_flags);
|
r = dx12_resource_alloc(heap_props, heap_flags, desc, initial_state);
|
||||||
|
r->srv_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
||||||
|
}
|
||||||
|
cb->resource = r;
|
||||||
|
|
||||||
|
{
|
||||||
|
struct D3D12_SHADER_RESOURCE_VIEW_DESC desc = ZI;
|
||||||
|
desc.Format = DXGI_FORMAT_UNKNOWN;
|
||||||
|
desc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
|
||||||
|
desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||||
|
desc.Buffer.FirstElement = 0;
|
||||||
|
desc.Buffer.NumElements = max_u32(data_len / data_stride, 1);
|
||||||
|
desc.Buffer.StructureByteStride = data_stride;
|
||||||
|
desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
|
||||||
|
ID3D12Device_CreateShaderResourceView(G.device, r->resource, &desc, r->srv_descriptor->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy data to resource */
|
/* Write data to resource */
|
||||||
{
|
{
|
||||||
D3D12_RANGE read_range = ZI;
|
D3D12_RANGE read_range = ZI;
|
||||||
void *dst = 0;
|
void *dst = 0;
|
||||||
@ -2195,7 +2195,7 @@ INTERNAL struct command_buffer *command_list_push_buffer(struct command_list *cl
|
|||||||
/* TODO: Don't panic */
|
/* TODO: Don't panic */
|
||||||
sys_panic(LIT("Failed to map command buffer resource"));
|
sys_panic(LIT("Failed to map command buffer resource"));
|
||||||
}
|
}
|
||||||
MEMCPY(dst, data.text, data.len);
|
MEMCPY(dst, data, data_len);
|
||||||
ID3D12Resource_Unmap(cb->resource->resource, 0, 0);
|
ID3D12Resource_Unmap(cb->resource->resource, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2255,8 +2255,6 @@ struct gp_resource *gp_texture_alloc(enum gp_texture_format format, u32 flags, s
|
|||||||
sys_panic(LIT("Tried to create texture with unknown format"));
|
sys_panic(LIT("Tried to create texture with unknown format"));
|
||||||
}
|
}
|
||||||
|
|
||||||
enum dx12_resource_view_flags view_flags = DX12_RESOURCE_VIEW_FLAG_SRV;
|
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES heap_props = { .Type = D3D12_HEAP_TYPE_DEFAULT };
|
D3D12_HEAP_PROPERTIES heap_props = { .Type = D3D12_HEAP_TYPE_DEFAULT };
|
||||||
heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||||
heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||||
@ -2274,15 +2272,20 @@ struct gp_resource *gp_texture_alloc(enum gp_texture_format format, u32 flags, s
|
|||||||
desc.MipLevels = 1;
|
desc.MipLevels = 1;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
desc.SampleDesc.Quality = 0;
|
desc.SampleDesc.Quality = 0;
|
||||||
if (flags & GP_TEXTURE_FLAG_TARGETABLE) {
|
|
||||||
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
|
||||||
view_flags |= DX12_RESOURCE_VIEW_FLAG_RTV | DX12_RESOURCE_VIEW_FLAG_UAV;
|
|
||||||
}
|
|
||||||
|
|
||||||
D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_COPY_DEST;
|
D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||||
|
|
||||||
struct dx12_resource *r = dx12_resource_alloc(heap_props, heap_flags, desc, initial_state, view_flags);
|
struct dx12_resource *r = dx12_resource_alloc(heap_props, heap_flags, desc, initial_state);
|
||||||
r->texture_size = size;
|
r->texture_size = size;
|
||||||
|
r->srv_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
||||||
|
ID3D12Device_CreateShaderResourceView(G.device, r->resource, 0, r->srv_descriptor->handle);
|
||||||
|
if (flags & GP_TEXTURE_FLAG_TARGETABLE) {
|
||||||
|
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
||||||
|
r->uav_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
||||||
|
r->rtv_descriptor = descriptor_alloc(G.rtv_heap);
|
||||||
|
ID3D12Device_CreateUnorderedAccessView(G.device, r->resource, 0, 0, r->uav_descriptor->handle);
|
||||||
|
ID3D12Device_CreateRenderTargetView(G.device, r->resource, 0, r->rtv_descriptor->handle);
|
||||||
|
}
|
||||||
|
|
||||||
/* Upload texture */
|
/* Upload texture */
|
||||||
if (initial_data) {
|
if (initial_data) {
|
||||||
@ -2330,8 +2333,6 @@ INTERNAL SYS_JOB_DEF(dx12_upload_job, job)
|
|||||||
/* Create upload heap */
|
/* Create upload heap */
|
||||||
struct dx12_resource *upload = 0;
|
struct dx12_resource *upload = 0;
|
||||||
{
|
{
|
||||||
enum dx12_resource_view_flags upload_view_flags = DX12_RESOURCE_VIEW_FLAG_NONE;
|
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES upload_heap_props = { .Type = D3D12_HEAP_TYPE_UPLOAD };
|
D3D12_HEAP_PROPERTIES upload_heap_props = { .Type = D3D12_HEAP_TYPE_UPLOAD };
|
||||||
upload_heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
upload_heap_props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||||
upload_heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
upload_heap_props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||||
@ -2351,7 +2352,7 @@ INTERNAL SYS_JOB_DEF(dx12_upload_job, job)
|
|||||||
upload_desc.SampleDesc.Quality = 0;
|
upload_desc.SampleDesc.Quality = 0;
|
||||||
D3D12_RESOURCE_STATES upload_initial_state = D3D12_RESOURCE_STATE_GENERIC_READ;
|
D3D12_RESOURCE_STATES upload_initial_state = D3D12_RESOURCE_STATE_GENERIC_READ;
|
||||||
|
|
||||||
upload = dx12_resource_alloc(upload_heap_props, upload_heap_flags, upload_desc, upload_initial_state, upload_view_flags);
|
upload = dx12_resource_alloc(upload_heap_props, upload_heap_flags, upload_desc, upload_initial_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct command_queue *cq = G.command_queues[DX12_QUEUE_COPY_BACKGROUND];
|
struct command_queue *cq = G.command_queues[DX12_QUEUE_COPY_BACKGROUND];
|
||||||
@ -2418,35 +2419,32 @@ INTERNAL SYS_JOB_DEF(dx12_upload_job, job)
|
|||||||
* Run utils
|
* Run utils
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
INTERNAL void command_list_set_graphics_root_constant(struct command_list *cl, void *src, u32 size)
|
INTERNAL void command_list_set_pipeline(struct command_list *cl, struct pipeline *pipeline)
|
||||||
{
|
{
|
||||||
__prof;
|
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, pipeline->pso);
|
||||||
if (size % 4 == 0) {
|
if (pipeline->is_gfx) {
|
||||||
u32 num32bit = size / 4;
|
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, pipeline->rootsig);
|
||||||
for (u32 i = 0; i < num32bit; ++i) {
|
|
||||||
u32 val = 0;
|
|
||||||
MEMCPY(&val, (((u32 *)src) + i), 4);
|
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstant(cl->cl, 0, val, i);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* Root constant structs must pad to 32 bits */
|
ID3D12GraphicsCommandList_SetComputeRootSignature(cl->cl, pipeline->rootsig);
|
||||||
ASSERT(0);
|
|
||||||
}
|
}
|
||||||
|
cl->cur_pipeline = pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void command_list_set_compute_root_constant(struct command_list *cl, void *src, u32 size)
|
INTERNAL void command_list_set_sig(struct command_list *cl, void *src, u32 size)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
if (size % 4 == 0) {
|
ASSERT(size % 16 == 0); /* Root constant structs must pad to 16 bytes */
|
||||||
|
ASSERT(size <= 256); /* Only 64 32-bit root constants allowed in signature */
|
||||||
u32 num32bit = size / 4;
|
u32 num32bit = size / 4;
|
||||||
|
b32 is_gfx = cl->cur_pipeline->is_gfx;
|
||||||
for (u32 i = 0; i < num32bit; ++i) {
|
for (u32 i = 0; i < num32bit; ++i) {
|
||||||
u32 val = 0;
|
u32 val = 0;
|
||||||
MEMCPY(&val, (((u32 *)src) + i), 4);
|
MEMCPY(&val, (((u32 *)src) + i), 4);
|
||||||
|
if (is_gfx) {
|
||||||
|
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstant(cl->cl, 0, val, i);
|
||||||
|
} else {
|
||||||
ID3D12GraphicsCommandList_SetComputeRoot32BitConstant(cl->cl, 0, val, i);
|
ID3D12GraphicsCommandList_SetComputeRoot32BitConstant(cl->cl, 0, val, i);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* Root constant structs must pad to 32 bits */
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2512,7 +2510,14 @@ INTERNAL struct dx12_resource *gbuff_alloc(DXGI_FORMAT format, struct v2i32 size
|
|||||||
desc.SampleDesc.Quality = 0;
|
desc.SampleDesc.Quality = 0;
|
||||||
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
|
||||||
|
|
||||||
struct dx12_resource *r = dx12_resource_alloc(heap_props, heap_flags, desc, initial_state, DX12_RESOURCE_VIEW_FLAG_SRV | DX12_RESOURCE_VIEW_FLAG_UAV | DX12_RESOURCE_VIEW_FLAG_RTV);
|
struct dx12_resource *r = dx12_resource_alloc(heap_props, heap_flags, desc, initial_state);
|
||||||
|
r->srv_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
||||||
|
r->uav_descriptor = descriptor_alloc(G.cbv_srv_uav_heap);
|
||||||
|
r->rtv_descriptor = descriptor_alloc(G.rtv_heap);
|
||||||
|
ID3D12Device_CreateShaderResourceView(G.device, r->resource, 0, r->srv_descriptor->handle);
|
||||||
|
ID3D12Device_CreateUnorderedAccessView(G.device, r->resource, 0, 0, r->uav_descriptor->handle);
|
||||||
|
ID3D12Device_CreateRenderTargetView(G.device, r->resource, 0, r->rtv_descriptor->handle);
|
||||||
|
|
||||||
r->texture_size = size;
|
r->texture_size = size;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -2715,12 +2720,12 @@ i32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_de
|
|||||||
* Render
|
* Render
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_render_params params)
|
struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp_render_params params)
|
||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
struct render_sig *sig = (struct render_sig *)render_sig;
|
struct render_sig *rsig = (struct render_sig *)gp_render_sig;
|
||||||
++sig->frame_index;
|
++rsig->frame_index;
|
||||||
|
|
||||||
struct v2i32 ui_size = V2I32(max_i32(params.ui_size.x, 1), max_i32(params.ui_size.y, 1));
|
struct v2i32 ui_size = V2I32(max_i32(params.ui_size.x, 1), max_i32(params.ui_size.y, 1));
|
||||||
struct v2i32 render_size = V2I32(max_i32(params.render_size.x, 1), max_i32(params.render_size.y, 1));
|
struct v2i32 render_size = V2I32(max_i32(params.render_size.x, 1), max_i32(params.render_size.y, 1));
|
||||||
@ -2732,33 +2737,33 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
|
|
||||||
|
|
||||||
/* Allocate render buffers */
|
/* Allocate render buffers */
|
||||||
if (sig->shade_target && !v2i32_eq(render_size, sig->shade_target->texture_size)) {
|
if (rsig->shade_target && !v2i32_eq(render_size, rsig->shade_target->texture_size)) {
|
||||||
__profn("Release sig resources");
|
__profn("Release sig resources");
|
||||||
fenced_release(sig->albedo, FENCED_RELEASE_KIND_RESOURCE);
|
fenced_release(rsig->albedo, FENCED_RELEASE_KIND_RESOURCE);
|
||||||
fenced_release(sig->emittance, FENCED_RELEASE_KIND_RESOURCE);
|
fenced_release(rsig->emittance, FENCED_RELEASE_KIND_RESOURCE);
|
||||||
fenced_release(sig->emittance_flood_read, FENCED_RELEASE_KIND_RESOURCE);
|
fenced_release(rsig->emittance_flood_read, FENCED_RELEASE_KIND_RESOURCE);
|
||||||
fenced_release(sig->emittance_flood_target, FENCED_RELEASE_KIND_RESOURCE);
|
fenced_release(rsig->emittance_flood_target, FENCED_RELEASE_KIND_RESOURCE);
|
||||||
fenced_release(sig->shade_read, FENCED_RELEASE_KIND_RESOURCE);
|
fenced_release(rsig->shade_read, FENCED_RELEASE_KIND_RESOURCE);
|
||||||
fenced_release(sig->shade_target, FENCED_RELEASE_KIND_RESOURCE);
|
fenced_release(rsig->shade_target, FENCED_RELEASE_KIND_RESOURCE);
|
||||||
sig->shade_target = 0;
|
rsig->shade_target = 0;
|
||||||
}
|
}
|
||||||
if (!sig->shade_target) {
|
if (!rsig->shade_target) {
|
||||||
__profn("Allocate sig resources");
|
__profn("Allocate sig resources");
|
||||||
sig->albedo = gbuff_alloc(DXGI_FORMAT_R8G8B8A8_UNORM, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
rsig->albedo = gbuff_alloc(DXGI_FORMAT_R8G8B8A8_UNORM, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||||
sig->emittance = gbuff_alloc(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
rsig->emittance = gbuff_alloc(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||||
sig->emittance_flood_read = gbuff_alloc(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
rsig->emittance_flood_read = gbuff_alloc(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||||
sig->emittance_flood_target = gbuff_alloc(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
rsig->emittance_flood_target = gbuff_alloc(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||||
sig->shade_read = gbuff_alloc(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
rsig->shade_read = gbuff_alloc(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||||
sig->shade_target = gbuff_alloc(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
rsig->shade_target = gbuff_alloc(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate ui buffers */
|
/* Allocate ui buffers */
|
||||||
if (sig->ui_target && !v2i32_eq(ui_size, sig->ui_target->texture_size)) {
|
if (rsig->ui_target && !v2i32_eq(ui_size, rsig->ui_target->texture_size)) {
|
||||||
fenced_release(sig->ui_target, FENCED_RELEASE_KIND_RESOURCE);
|
fenced_release(rsig->ui_target, FENCED_RELEASE_KIND_RESOURCE);
|
||||||
sig->ui_target = 0;
|
rsig->ui_target = 0;
|
||||||
}
|
}
|
||||||
if (!sig->ui_target) {
|
if (!rsig->ui_target) {
|
||||||
sig->ui_target = gbuff_alloc(DXGI_FORMAT_R8G8B8A8_UNORM, ui_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
rsig->ui_target = gbuff_alloc(DXGI_FORMAT_R8G8B8A8_UNORM, ui_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sprite_scope *sprite_scope = sprite_scope_begin();
|
struct sprite_scope *sprite_scope = sprite_scope_begin();
|
||||||
@ -2788,21 +2793,21 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* TODO: Make these static */
|
/* TODO: Make these static */
|
||||||
/* Dummy vertex buffer */
|
/* Dummy vertex buffer */
|
||||||
LOCAL_PERSIST u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
LOCAL_PERSIST u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
||||||
struct command_buffer *dummy_vertex_buffer = command_list_push_buffer(cl, STRING(0, 0));
|
struct command_buffer *dummy_vertex_buffer = command_list_push_buffer(cl, 0, (u8 *)0);
|
||||||
struct command_buffer *quad_index_buffer = command_list_push_buffer(cl, STRING_FROM_ARRAY(quad_indices));
|
struct command_buffer *quad_index_buffer = command_list_push_buffer(cl, countof(quad_indices), quad_indices);
|
||||||
|
|
||||||
/* Process sig data into uploadable data */
|
/* Process sig data into uploadable data */
|
||||||
struct sh_material_instance *material_instances = arena_push_array_no_zero(scratch.arena, struct sh_material_instance, sig->num_material_instance_descs);
|
struct sh_material_instance *material_instances = arena_push_array_no_zero(scratch.arena, struct sh_material_instance, rsig->num_material_instance_descs);
|
||||||
struct sh_ui_instance *ui_rect_instances = arena_push_array_no_zero(scratch.arena, struct sh_ui_instance, sig->num_ui_rect_instance_descs);
|
struct sh_ui_instance *ui_rect_instances = arena_push_array_no_zero(scratch.arena, struct sh_ui_instance, rsig->num_ui_rect_instance_descs);
|
||||||
struct sh_material_grid *grids = arena_push_array_no_zero(scratch.arena, struct sh_material_grid, sig->num_material_grid_descs);
|
struct sh_material_grid *grids = arena_push_array_no_zero(scratch.arena, struct sh_material_grid, rsig->num_material_grid_descs);
|
||||||
{
|
{
|
||||||
__profn("Process sig data");
|
__profn("Process sig data");
|
||||||
|
|
||||||
/* Process material instances */
|
/* Process material instances */
|
||||||
{
|
{
|
||||||
__profn("Process material instances");
|
__profn("Process material instances");
|
||||||
for (u32 i = 0; i < sig->num_material_instance_descs; ++i) {
|
for (u32 i = 0; i < rsig->num_material_instance_descs; ++i) {
|
||||||
struct material_instance_desc *desc = &((struct material_instance_desc *)arena_base(sig->material_instance_descs_arena))[i];
|
struct material_instance_desc *desc = &((struct material_instance_desc *)arena_base(rsig->material_instance_descs_arena))[i];
|
||||||
struct sh_material_instance *instance = &material_instances[i];
|
struct sh_material_instance *instance = &material_instances[i];
|
||||||
i32 texture_id = -1;
|
i32 texture_id = -1;
|
||||||
if (desc->texture != 0) {
|
if (desc->texture != 0) {
|
||||||
@ -2828,8 +2833,8 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* Process ui rect instances */
|
/* Process ui rect instances */
|
||||||
{
|
{
|
||||||
__profn("Process ui rect instances");
|
__profn("Process ui rect instances");
|
||||||
for (u32 i = 0; i < sig->num_ui_rect_instance_descs; ++i) {
|
for (u32 i = 0; i < rsig->num_ui_rect_instance_descs; ++i) {
|
||||||
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)arena_base(sig->ui_rect_instance_descs_arena))[i];
|
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)arena_base(rsig->ui_rect_instance_descs_arena))[i];
|
||||||
struct sh_ui_instance *instance = &ui_rect_instances[i];
|
struct sh_ui_instance *instance = &ui_rect_instances[i];
|
||||||
i32 texture_id = -1;
|
i32 texture_id = -1;
|
||||||
if (desc->texture != 0) {
|
if (desc->texture != 0) {
|
||||||
@ -2852,8 +2857,8 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* Process grids */
|
/* Process grids */
|
||||||
{
|
{
|
||||||
__profn("Process grids");
|
__profn("Process grids");
|
||||||
for (u32 i = 0; i < sig->num_material_grid_descs; ++i) {
|
for (u32 i = 0; i < rsig->num_material_grid_descs; ++i) {
|
||||||
struct material_grid_desc *desc = &((struct material_grid_desc *)arena_base(sig->material_grid_descs_arena))[i];
|
struct material_grid_desc *desc = &((struct material_grid_desc *)arena_base(rsig->material_grid_descs_arena))[i];
|
||||||
struct sh_material_grid *grid = &grids[i];
|
struct sh_material_grid *grid = &grids[i];
|
||||||
grid->line_thickness = sh_float_from_f32(desc->line_thickness);
|
grid->line_thickness = sh_float_from_f32(desc->line_thickness);
|
||||||
grid->line_spacing = sh_float_from_f32(desc->line_spacing);
|
grid->line_spacing = sh_float_from_f32(desc->line_spacing);
|
||||||
@ -2868,11 +2873,13 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Upload buffers */
|
/* Upload buffers */
|
||||||
struct command_buffer *material_instance_buffer = command_list_push_buffer(cl, STRING(sizeof(*material_instances) * sig->num_material_instance_descs, (u8 *)material_instances));
|
u64 num_ui_shape_verts = rsig->ui_shape_verts_arena->pos / sizeof(struct sh_shape_vert);
|
||||||
struct command_buffer *ui_rect_instance_buffer = command_list_push_buffer(cl, STRING(sizeof(*ui_rect_instances) * sig->num_ui_rect_instance_descs, (u8 *)ui_rect_instances));
|
u64 num_ui_shape_indices = rsig->ui_shape_indices_arena->pos / sizeof(u16);
|
||||||
struct command_buffer *ui_shape_verts_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(sig->ui_shape_verts_arena));
|
struct command_buffer *material_instance_buffer = command_list_push_buffer(cl, rsig->num_material_instance_descs, material_instances);
|
||||||
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, STRING_FROM_ARENA(sig->ui_shape_indices_arena));
|
struct command_buffer *ui_rect_instance_buffer = command_list_push_buffer(cl, rsig->num_ui_rect_instance_descs, ui_rect_instances);
|
||||||
struct command_buffer *grid_buffer = command_list_push_buffer(cl, STRING(sizeof(*grids) * sig->num_material_grid_descs, (u8 *)grids));
|
struct command_buffer *ui_shape_verts_buffer = command_list_push_buffer(cl, num_ui_shape_verts, (struct sh_shape_vert *)arena_base(rsig->ui_shape_verts_arena));
|
||||||
|
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u16 *)arena_base(rsig->ui_shape_indices_arena));
|
||||||
|
struct command_buffer *grid_buffer = command_list_push_buffer(cl, rsig->num_material_grid_descs, grids);
|
||||||
|
|
||||||
/* 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);
|
||||||
@ -2884,12 +2891,12 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* Barrier */
|
/* Barrier */
|
||||||
{
|
{
|
||||||
struct dx12_resource_barrier_desc barriers[] = {
|
struct dx12_resource_barrier_desc barriers[] = {
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->albedo, D3D12_RESOURCE_STATE_RENDER_TARGET },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->albedo, D3D12_RESOURCE_STATE_RENDER_TARGET },
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance, D3D12_RESOURCE_STATE_RENDER_TARGET }
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->emittance, D3D12_RESOURCE_STATE_RENDER_TARGET }
|
||||||
};
|
};
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvs[] = {
|
D3D12_CPU_DESCRIPTOR_HANDLE rtvs[] = {
|
||||||
sig->albedo->rtv_descriptor->handle,
|
rsig->albedo->rtv_descriptor->handle,
|
||||||
sig->emittance->rtv_descriptor->handle,
|
rsig->emittance->rtv_descriptor->handle,
|
||||||
};
|
};
|
||||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||||
ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, countof(rtvs), rtvs, 0, 0);
|
ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, countof(rtvs), rtvs, 0, 0);
|
||||||
@ -2899,8 +2906,8 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profn("Clear gbuffers");
|
__profn("Clear gbuffers");
|
||||||
__profnc_dx12(cl->cq->prof, cl->cl, "Clear gbuffers", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "Clear gbuffers", RGB32_F(0.5, 0.2, 0.2));
|
||||||
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, sig->albedo->rtv_descriptor->handle, clear_color, 0, 0);
|
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, rsig->albedo->rtv_descriptor->handle, clear_color, 0, 0);
|
||||||
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, sig->emittance->rtv_descriptor->handle, clear_color, 0, 0);
|
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, rsig->emittance->rtv_descriptor->handle, clear_color, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2910,8 +2917,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profnc_dx12(cl->cq->prof, cl->cl, "Material pass", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "Material pass", RGB32_F(0.5, 0.2, 0.2));
|
||||||
|
|
||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, material_pipeline->pso);
|
command_list_set_pipeline(cl, material_pipeline);
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, material_pipeline->rootsig);
|
|
||||||
|
|
||||||
/* Set Rasterizer State */
|
/* Set Rasterizer State */
|
||||||
D3D12_VIEWPORT viewport = viewport_from_rect(render_viewport);
|
D3D12_VIEWPORT viewport = viewport_from_rect(render_viewport);
|
||||||
@ -2919,15 +2925,12 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set constants */
|
/* Set sig */
|
||||||
struct sh_material_constants constants = ZI;
|
struct sh_material_sig sig = ZI;
|
||||||
constants.projection = sh_float4x4_from_mat4x4(world_to_render_vp_matrix);
|
sig.projection = sh_float4x4_from_mat4x4(world_to_render_vp_matrix);
|
||||||
|
sig.instances_urid = sh_uint_from_u32(material_instance_buffer->resource->srv_descriptor->index);
|
||||||
/* Set parameters */
|
sig.grids_urid = sh_uint_from_u32(grid_buffer->resource->srv_descriptor->index);
|
||||||
command_list_set_graphics_root_constant(cl, &constants, sizeof(constants));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle);
|
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 2, material_instance_buffer->resource->gpu_address);
|
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootShaderResourceView(cl->cl, 3, grid_buffer->resource->gpu_address);
|
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
u32 instance_count = material_instance_buffer->size / sizeof(struct sh_material_instance);
|
u32 instance_count = material_instance_buffer->size / sizeof(struct sh_material_instance);
|
||||||
@ -2944,12 +2947,12 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* Barrier */
|
/* Barrier */
|
||||||
{
|
{
|
||||||
struct dx12_resource_barrier_desc barriers[] = {
|
struct dx12_resource_barrier_desc barriers[] = {
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->emittance, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
||||||
|
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance_flood_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->emittance_flood_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, sig->emittance_flood_read, 0 },
|
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, rsig->emittance_flood_read, 0 },
|
||||||
|
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance_flood_target, D3D12_RESOURCE_STATE_UNORDERED_ACCESS }
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->emittance_flood_target, D3D12_RESOURCE_STATE_UNORDERED_ACCESS }
|
||||||
};
|
};
|
||||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||||
}
|
}
|
||||||
@ -2961,8 +2964,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profnc_dx12(cl->cq->prof, cl->cl, "Flood pass", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "Flood pass", RGB32_F(0.5, 0.2, 0.2));
|
||||||
|
|
||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, flood_pipeline->pso);
|
command_list_set_pipeline(cl, flood_pipeline);
|
||||||
ID3D12GraphicsCommandList_SetComputeRootSignature(cl->cl, flood_pipeline->rootsig);
|
|
||||||
|
|
||||||
i32 step_length = -1;
|
i32 step_length = -1;
|
||||||
|
|
||||||
@ -2976,32 +2978,28 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* UAV barrier */
|
/* UAV barrier */
|
||||||
{
|
{
|
||||||
struct dx12_resource_barrier_desc barriers[] = {
|
struct dx12_resource_barrier_desc barriers[] = {
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, sig->emittance_flood_read, 0 }
|
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, rsig->emittance_flood_read, 0 }
|
||||||
};
|
};
|
||||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set constants */
|
/* Set sig */
|
||||||
struct sh_flood_constants constants = ZI;
|
struct sh_flood_sig sig = ZI;
|
||||||
constants.step_len = sh_int_from_i32(step_length);
|
sig.step_len = sh_int_from_i32(step_length);
|
||||||
constants.emittance_tex_urid = sh_uint_from_u32(sig->emittance->srv_descriptor->index);
|
sig.emittance_tex_urid = sh_uint_from_u32(rsig->emittance->srv_descriptor->index);
|
||||||
constants.read_flood_tex_urid = sh_uint_from_u32(sig->emittance_flood_read->uav_descriptor->index);
|
sig.read_flood_tex_urid = sh_uint_from_u32(rsig->emittance_flood_read->uav_descriptor->index);
|
||||||
constants.target_flood_tex_urid = sh_uint_from_u32(sig->emittance_flood_target->uav_descriptor->index);
|
sig.target_flood_tex_urid = sh_uint_from_u32(rsig->emittance_flood_target->uav_descriptor->index);
|
||||||
constants.tex_width = sh_uint_from_u32(render_size.x);
|
sig.tex_width = sh_uint_from_u32(render_size.x);
|
||||||
constants.tex_height = sh_uint_from_u32(render_size.y);
|
sig.tex_height = sh_uint_from_u32(render_size.y);
|
||||||
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
/* Set parameters */
|
|
||||||
command_list_set_compute_root_constant(cl, &constants, sizeof(constants));
|
|
||||||
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle);
|
|
||||||
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(cl->cl, 2, descriptor_heap->start_gpu_handle);
|
|
||||||
|
|
||||||
/* Dispatch */
|
/* Dispatch */
|
||||||
ID3D12GraphicsCommandList_Dispatch(cl->cl, (render_size.x + 7) / 8, (render_size.y + 7) / 8, 1);
|
ID3D12GraphicsCommandList_Dispatch(cl->cl, (render_size.x + 7) / 8, (render_size.y + 7) / 8, 1);
|
||||||
|
|
||||||
/* Swap buffers */
|
/* Swap buffers */
|
||||||
struct dx12_resource *swp = sig->emittance_flood_read;
|
struct dx12_resource *swp = rsig->emittance_flood_read;
|
||||||
sig->emittance_flood_read = sig->emittance_flood_target;
|
rsig->emittance_flood_read = rsig->emittance_flood_target;
|
||||||
sig->emittance_flood_target = swp;
|
rsig->emittance_flood_target = swp;
|
||||||
|
|
||||||
/* Update step */
|
/* Update step */
|
||||||
if (step_length == -1) {
|
if (step_length == -1) {
|
||||||
@ -3018,16 +3016,16 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* Barrier */
|
/* Barrier */
|
||||||
{
|
{
|
||||||
struct dx12_resource_barrier_desc barriers[] = {
|
struct dx12_resource_barrier_desc barriers[] = {
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->albedo, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->albedo, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->emittance, D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE },
|
||||||
|
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->emittance_flood_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->emittance_flood_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, sig->emittance_flood_read, 0 },
|
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, rsig->emittance_flood_read, 0 },
|
||||||
|
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->shade_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->shade_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, sig->shade_read, 0 },
|
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, rsig->shade_read, 0 },
|
||||||
|
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->shade_target, D3D12_RESOURCE_STATE_UNORDERED_ACCESS }
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->shade_target, D3D12_RESOURCE_STATE_UNORDERED_ACCESS }
|
||||||
};
|
};
|
||||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||||
}
|
}
|
||||||
@ -3036,7 +3034,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profn("Clear shade target");
|
__profn("Clear shade target");
|
||||||
__profnc_dx12(cl->cq->prof, cl->cl, "Clear shade target", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "Clear shade target", RGB32_F(0.5, 0.2, 0.2));
|
||||||
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
ID3D12GraphicsCommandList_ClearUnorderedAccessViewFloat(cl->cl, gpu_handle_from_descriptor(sig->shade_target->uav_descriptor, descriptor_heap), sig->shade_target->uav_descriptor->handle, sig->shade_target->resource, clear_color, 0, 0);
|
ID3D12GraphicsCommandList_ClearUnorderedAccessViewFloat(cl->cl, gpu_handle_from_descriptor(rsig->shade_target->uav_descriptor, descriptor_heap), rsig->shade_target->uav_descriptor->handle, rsig->shade_target->resource, clear_color, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3046,45 +3044,38 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profnc_dx12(cl->cq->prof, cl->cl, "Shade pass", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "Shade pass", RGB32_F(0.5, 0.2, 0.2));
|
||||||
|
|
||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, shade_pipeline->pso);
|
command_list_set_pipeline(cl, shade_pipeline);
|
||||||
ID3D12GraphicsCommandList_SetComputeRootSignature(cl->cl, shade_pipeline->rootsig);
|
|
||||||
|
|
||||||
u32 shade_flags = SH_SHADE_FLAG_NONE;
|
u32 shade_flags = SH_SHADE_FLAG_NONE;
|
||||||
if (params.effects_disabled) {
|
if (params.effects_disabled) {
|
||||||
shade_flags |= SH_SHADE_FLAG_DISABLE_EFFECTS;
|
shade_flags |= SH_SHADE_FLAG_DISABLE_EFFECTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set constants */
|
/* Set sig */
|
||||||
struct sh_shade_constants constants = ZI;
|
struct sh_shade_sig sig = ZI;
|
||||||
constants.flags = sh_uint_from_u32(shade_flags);
|
sig.flags = sh_uint_from_u32(shade_flags);
|
||||||
constants.tex_width = sh_uint_from_u32(render_size.x);
|
sig.tex_width = sh_uint_from_u32(render_size.x);
|
||||||
constants.tex_height = sh_uint_from_u32(render_size.y);
|
sig.tex_height = sh_uint_from_u32(render_size.y);
|
||||||
constants.frame_seed = sh_uint4_from_u32((u32)(rand_u64_from_state(&sig->rand) & 0xFFFFFFFF),
|
sig.frame_seed = sh_uint4_from_u32((u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(rand_u64_from_state(&sig->rand) & 0xFFFFFFFF),
|
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(rand_u64_from_state(&sig->rand) & 0xFFFFFFFF),
|
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(rand_u64_from_state(&sig->rand) & 0xFFFFFFFF));
|
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF));
|
||||||
constants.frame_index = sh_uint_from_u32(sig->frame_index);
|
sig.frame_index = sh_uint_from_u32(rsig->frame_index);
|
||||||
constants.camera_offset = sh_float2_from_v2(world_to_render_xf.og);
|
sig.camera_offset = sh_float2_from_v2(world_to_render_xf.og);
|
||||||
constants.albedo_tex_urid = sh_uint_from_u32(sig->albedo->srv_descriptor->index);
|
sig.albedo_tex_urid = sh_uint_from_u32(rsig->albedo->srv_descriptor->index);
|
||||||
constants.emittance_tex_urid = sh_uint_from_u32(sig->emittance->srv_descriptor->index);
|
sig.emittance_tex_urid = sh_uint_from_u32(rsig->emittance->srv_descriptor->index);
|
||||||
constants.emittance_flood_tex_urid = sh_uint_from_u32(sig->emittance_flood_read->srv_descriptor->index);
|
sig.emittance_flood_tex_urid = sh_uint_from_u32(rsig->emittance_flood_read->srv_descriptor->index);
|
||||||
constants.read_tex_urid = sh_uint_from_u32(sig->shade_read->uav_descriptor->index);
|
sig.read_tex_urid = sh_uint_from_u32(rsig->shade_read->uav_descriptor->index);
|
||||||
constants.target_tex_urid = sh_uint_from_u32(sig->shade_target->uav_descriptor->index);
|
sig.target_tex_urid = sh_uint_from_u32(rsig->shade_target->uav_descriptor->index);
|
||||||
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
/* Set parameters */
|
|
||||||
command_list_set_compute_root_constant(cl, &constants, sizeof(constants));
|
|
||||||
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle);
|
|
||||||
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(cl->cl, 2, descriptor_heap->start_gpu_handle);
|
|
||||||
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(cl->cl, 3, descriptor_heap->start_gpu_handle);
|
|
||||||
ID3D12GraphicsCommandList_SetComputeRootDescriptorTable(cl->cl, 4, descriptor_heap->start_gpu_handle);
|
|
||||||
|
|
||||||
/* Dispatch */
|
/* Dispatch */
|
||||||
ID3D12GraphicsCommandList_Dispatch(cl->cl, (render_size.x + 7) / 8, (render_size.y + 7) / 8, 1);
|
ID3D12GraphicsCommandList_Dispatch(cl->cl, (render_size.x + 7) / 8, (render_size.y + 7) / 8, 1);
|
||||||
|
|
||||||
/* Swap */
|
/* Swap */
|
||||||
struct dx12_resource *swp = sig->shade_read;
|
struct dx12_resource *swp = rsig->shade_read;
|
||||||
sig->shade_read = sig->shade_target;
|
rsig->shade_read = rsig->shade_target;
|
||||||
sig->shade_target = swp;
|
rsig->shade_target = swp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prep for UI pass */
|
/* Prep for UI pass */
|
||||||
@ -3092,19 +3083,19 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
/* Barrier */
|
/* Barrier */
|
||||||
{
|
{
|
||||||
struct dx12_resource_barrier_desc barriers[] = {
|
struct dx12_resource_barrier_desc barriers[] = {
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->shade_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->shade_read, D3D12_RESOURCE_STATE_UNORDERED_ACCESS },
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, sig->shade_read, 0 },
|
{ D3D12_RESOURCE_BARRIER_TYPE_UAV, rsig->shade_read, 0 },
|
||||||
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, sig->ui_target, D3D12_RESOURCE_STATE_RENDER_TARGET }
|
{ D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, rsig->ui_target, D3D12_RESOURCE_STATE_RENDER_TARGET }
|
||||||
};
|
};
|
||||||
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
dx12_resource_barriers(cl->cl, countof(barriers), barriers);
|
||||||
ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, 1, &sig->ui_target->rtv_descriptor->handle, 0, 0);
|
ID3D12GraphicsCommandList_OMSetRenderTargets(cl->cl, 1, &rsig->ui_target->rtv_descriptor->handle, 0, 0);
|
||||||
}
|
}
|
||||||
/* Clear */
|
/* Clear */
|
||||||
{
|
{
|
||||||
__profn("Clear ui target");
|
__profn("Clear ui target");
|
||||||
__profnc_dx12(cl->cq->prof, cl->cl, "Clear ui target", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "Clear ui target", RGB32_F(0.5, 0.2, 0.2));
|
||||||
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
f32 clear_color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, sig->ui_target->rtv_descriptor->handle, clear_color, 0, 0);
|
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, rsig->ui_target->rtv_descriptor->handle, clear_color, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3114,8 +3105,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profnc_dx12(cl->cq->prof, cl->cl, "UI blit pass", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "UI blit pass", RGB32_F(0.5, 0.2, 0.2));
|
||||||
|
|
||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, blit_pipeline->pso);
|
command_list_set_pipeline(cl, blit_pipeline);
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, blit_pipeline->rootsig);
|
|
||||||
|
|
||||||
/* Set Rasterizer State */
|
/* Set Rasterizer State */
|
||||||
D3D12_VIEWPORT viewport = viewport_from_rect(ui_viewport);
|
D3D12_VIEWPORT viewport = viewport_from_rect(ui_viewport);
|
||||||
@ -3123,17 +3113,14 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set constants */
|
/* Set sig */
|
||||||
struct sh_blit_constants constants = ZI;
|
struct sh_blit_sig sig = ZI;
|
||||||
constants.projection = sh_float4x4_from_mat4x4(blit_vp_matrix);
|
sig.projection = sh_float4x4_from_mat4x4(blit_vp_matrix);
|
||||||
constants.flags = sh_uint_from_u32(SH_BLIT_FLAG_TONE_MAP | SH_BLIT_FLAG_GAMMA_CORRECT);
|
sig.flags = sh_uint_from_u32(SH_BLIT_FLAG_TONE_MAP | SH_BLIT_FLAG_GAMMA_CORRECT);
|
||||||
constants.exposure = sh_float_from_f32(2.0);
|
sig.exposure = sh_float_from_f32(2.0);
|
||||||
constants.gamma = sh_float_from_f32((f32)2.2);
|
sig.gamma = sh_float_from_f32((f32)2.2);
|
||||||
constants.tex_urid = sh_uint_from_u32(sig->shade_read->uav_descriptor->index);
|
sig.tex_urid = sh_uint_from_u32(rsig->shade_read->uav_descriptor->index);
|
||||||
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
/* Set parameters */
|
|
||||||
command_list_set_graphics_root_constant(cl, &constants, sizeof(constants));
|
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle);
|
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0);
|
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0);
|
||||||
@ -3150,8 +3137,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profnc_dx12(cl->cq->prof, cl->cl, "UI rect pass", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "UI rect pass", RGB32_F(0.5, 0.2, 0.2));
|
||||||
|
|
||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, ui_pipeline->pso);
|
command_list_set_pipeline(cl, ui_pipeline);
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, ui_pipeline->rootsig);
|
|
||||||
|
|
||||||
/* Set Rasterizer State */
|
/* Set Rasterizer State */
|
||||||
D3D12_VIEWPORT viewport = viewport_from_rect(ui_viewport);
|
D3D12_VIEWPORT viewport = viewport_from_rect(ui_viewport);
|
||||||
@ -3159,14 +3145,11 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set constants */
|
/* Set sig */
|
||||||
struct sh_ui_constants constants = ZI;
|
struct sh_ui_sig sig = ZI;
|
||||||
constants.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
sig.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
||||||
|
sig.instances_urid = sh_uint_from_u32(ui_rect_instance_buffer->resource->srv_descriptor->index);
|
||||||
/* Set parameters */
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
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_rect_instance_buffer->resource->gpu_address);
|
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
u32 instance_count = ui_rect_instance_buffer->size / sizeof(struct sh_ui_instance);
|
u32 instance_count = ui_rect_instance_buffer->size / sizeof(struct sh_ui_instance);
|
||||||
@ -3184,8 +3167,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
__profnc_dx12(cl->cq->prof, cl->cl, "UI shape pass", RGB32_F(0.5, 0.2, 0.2));
|
__profnc_dx12(cl->cq->prof, cl->cl, "UI shape pass", RGB32_F(0.5, 0.2, 0.2));
|
||||||
|
|
||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, shape_pipeline->pso);
|
command_list_set_pipeline(cl, shape_pipeline);
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, shape_pipeline->rootsig);
|
|
||||||
|
|
||||||
/* Set Rasterizer State */
|
/* Set Rasterizer State */
|
||||||
D3D12_VIEWPORT viewport = viewport_from_rect(ui_viewport);
|
D3D12_VIEWPORT viewport = viewport_from_rect(ui_viewport);
|
||||||
@ -3193,12 +3175,10 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set constants */
|
/* Set sig */
|
||||||
struct sh_shape_constants constants = ZI;
|
struct sh_shape_sig sig = ZI;
|
||||||
constants.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
sig.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
||||||
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
/* Set parameters */
|
|
||||||
command_list_set_graphics_root_constant(cl, &constants, sizeof(constants));
|
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
u32 index_count = ui_shape_indices_buffer->size / sizeof(u32);
|
u32 index_count = ui_shape_indices_buffer->size / sizeof(u32);
|
||||||
@ -3214,10 +3194,10 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
|||||||
pipeline_scope_end(pipeline_scope);
|
pipeline_scope_end(pipeline_scope);
|
||||||
sprite_scope_end(sprite_scope);
|
sprite_scope_end(sprite_scope);
|
||||||
|
|
||||||
render_sig_reset(sig);
|
render_sig_reset(rsig);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
|
|
||||||
return (struct gp_resource *)sig->ui_target;
|
return (struct gp_resource *)rsig->ui_target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -3425,8 +3405,8 @@ INTERNAL void present_blit(struct swapchain_buffer *dst, struct dx12_resource *s
|
|||||||
/* TODO: Make these static */
|
/* TODO: Make these static */
|
||||||
/* Dummy vertex buffer */
|
/* Dummy vertex buffer */
|
||||||
LOCAL_PERSIST u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
LOCAL_PERSIST u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
|
||||||
struct command_buffer *dummy_vertex_buffer = command_list_push_buffer(cl, STRING(0, 0));
|
struct command_buffer *dummy_vertex_buffer = command_list_push_buffer(cl, 0, (u8 *)0);
|
||||||
struct command_buffer *quad_index_buffer = command_list_push_buffer(cl, STRING_FROM_ARRAY(quad_indices));
|
struct command_buffer *quad_index_buffer = command_list_push_buffer(cl, countof(quad_indices), quad_indices);
|
||||||
|
|
||||||
/* 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);
|
||||||
@ -3466,22 +3446,18 @@ INTERNAL void present_blit(struct swapchain_buffer *dst, struct dx12_resource *s
|
|||||||
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, dst->rtv_descriptor->handle, clear_color, 0, 0);
|
ID3D12GraphicsCommandList_ClearRenderTargetView(cl->cl, dst->rtv_descriptor->handle, clear_color, 0, 0);
|
||||||
|
|
||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
ID3D12GraphicsCommandList_SetPipelineState(cl->cl, blit_pipeline->pso);
|
command_list_set_pipeline(cl, blit_pipeline);
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, blit_pipeline->rootsig);
|
|
||||||
|
|
||||||
/* Set Rasterizer State */
|
/* Set Rasterizer State */
|
||||||
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
|
||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set constants */
|
/* Set sig */
|
||||||
struct sh_blit_constants constants = ZI;
|
struct sh_blit_sig sig = ZI;
|
||||||
constants.projection = sh_float4x4_from_mat4x4(vp_matrix);
|
sig.projection = sh_float4x4_from_mat4x4(vp_matrix);
|
||||||
constants.flags = sh_uint_from_u32(SH_BLIT_FLAG_NONE);
|
sig.flags = sh_uint_from_u32(SH_BLIT_FLAG_NONE);
|
||||||
constants.tex_urid = sh_uint_from_u32(src->srv_descriptor->index);
|
sig.tex_urid = sh_uint_from_u32(src->srv_descriptor->index);
|
||||||
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
/* Set parameters */
|
|
||||||
command_list_set_graphics_root_constant(cl, &constants, sizeof(constants));
|
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootDescriptorTable(cl->cl, 1, descriptor_heap->start_gpu_handle);
|
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0);
|
D3D12_VERTEX_BUFFER_VIEW vbv = vbv_from_command_buffer(dummy_vertex_buffer, 0);
|
||||||
|
|||||||
@ -1,24 +1,6 @@
|
|||||||
#include "common.hlsl"
|
#include "common.hlsl"
|
||||||
|
|
||||||
/* ========================== *
|
ConstantBuffer<struct sh_blit_sig> sig : register(b0);
|
||||||
* Root signature
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define ROOTSIG \
|
|
||||||
"RootConstants(num32BitConstants = 20, b0), " \
|
|
||||||
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
\
|
|
||||||
"StaticSampler(s0, " \
|
|
||||||
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
|
||||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"maxAnisotropy = 1)"
|
|
||||||
|
|
||||||
ConstantBuffer<struct sh_blit_constants> g_constants : register(b0);
|
|
||||||
Texture2D g_textures[] : register(t0);
|
|
||||||
|
|
||||||
SamplerState g_sampler : register(s0);
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -33,7 +15,7 @@ struct vs_output {
|
|||||||
DECLS(float2, uv);
|
DECLS(float2, uv);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
SH_ENTRY struct vs_output vs(struct vs_input input)
|
||||||
{
|
{
|
||||||
static const float2 unit_quad_verts[4] = {
|
static const float2 unit_quad_verts[4] = {
|
||||||
float2(-0.5f, -0.5f),
|
float2(-0.5f, -0.5f),
|
||||||
@ -45,7 +27,7 @@ SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
|||||||
float2 vert = unit_quad_verts[input.SV_VertexID];
|
float2 vert = unit_quad_verts[input.SV_VertexID];
|
||||||
|
|
||||||
struct vs_output output;
|
struct vs_output output;
|
||||||
output.SV_Position = mul(g_constants.projection, float4(vert, 0, 1));
|
output.SV_Position = mul(sig.projection, float4(vert, 0, 1));
|
||||||
output.uv = vert + 0.5;
|
output.uv = vert + 0.5;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -73,21 +55,22 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target);
|
DECLS(float4, SV_Target);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct ps_output ps(struct ps_input input)
|
SH_ENTRY struct ps_output ps(struct ps_input input)
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
struct ps_output output;
|
||||||
float4 color = g_textures[g_constants.tex_urid].Sample(g_sampler, input.vs.uv);
|
Texture2D<float4> tex = resource_from_urid(sig.tex_urid);
|
||||||
|
float4 color = tex.Sample(s_point_clamp, input.vs.uv);
|
||||||
|
|
||||||
/* Apply tone map */
|
/* Apply tone map */
|
||||||
if (g_constants.flags & SH_BLIT_FLAG_TONE_MAP) {
|
if (sig.flags & SH_BLIT_FLAG_TONE_MAP) {
|
||||||
/* TODO: Dynamic exposure based on average scene luminance */
|
/* TODO: Dynamic exposure based on average scene luminance */
|
||||||
color.rgb *= g_constants.exposure;
|
color.rgb *= sig.exposure;
|
||||||
color.rgb = tone_map(color.rgb);
|
color.rgb = tone_map(color.rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply gamma correction */
|
/* Apply gamma correction */
|
||||||
if (g_constants.flags & SH_BLIT_FLAG_GAMMA_CORRECT) {
|
if (sig.flags & SH_BLIT_FLAG_GAMMA_CORRECT) {
|
||||||
color = pow(abs(color), 1/g_constants.gamma);
|
color = pow(abs(color), 1/sig.gamma);
|
||||||
}
|
}
|
||||||
|
|
||||||
output.SV_Target = color;
|
output.SV_Target = color;
|
||||||
|
|||||||
@ -5,7 +5,9 @@
|
|||||||
#define GOLDEN 1.61803398875
|
#define GOLDEN 1.61803398875
|
||||||
|
|
||||||
#define DECLS(t, n) t n : n
|
#define DECLS(t, n) t n : n
|
||||||
#define NURID(i) NonUniformResourceIndex(i)
|
|
||||||
|
#define resource_from_urid(urid) ResourceDescriptorHeap[(urid)]
|
||||||
|
#define resource_from_nurid(nurid) ResourceDescriptorHeap[NonUniformResourceIndex(nurid)]
|
||||||
|
|
||||||
#if !SH_CPU
|
#if !SH_CPU
|
||||||
# define INLINE /* For intellisense */
|
# define INLINE /* For intellisense */
|
||||||
@ -32,3 +34,22 @@ INLINE float4 linear_from_srgb32(uint srgb32)
|
|||||||
{
|
{
|
||||||
return linear_from_srgb(float4_norm_from_uint(srgb32));
|
return linear_from_srgb(float4_norm_from_uint(srgb32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Root signature
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
#define ROOTSIG \
|
||||||
|
"RootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | SAMPLER_HEAP_DIRECTLY_INDEXED | ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
|
||||||
|
"RootConstants(b0, num32BitConstants = 64), " \
|
||||||
|
\
|
||||||
|
"StaticSampler(s0, " \
|
||||||
|
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
||||||
|
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
||||||
|
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
||||||
|
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
||||||
|
"maxAnisotropy = 1)"
|
||||||
|
|
||||||
|
SamplerState s_point_clamp: register(s0);
|
||||||
|
|
||||||
|
#define SH_ENTRY [RootSignature(ROOTSIG)]
|
||||||
|
|||||||
@ -1,27 +1,6 @@
|
|||||||
#include "common.hlsl"
|
#include "common.hlsl"
|
||||||
|
|
||||||
/* ========================== *
|
ConstantBuffer<struct sh_flood_sig> sig : register(b0);
|
||||||
* Root signature
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define ROOTSIG \
|
|
||||||
"RootConstants(num32BitConstants = 8, b0), " \
|
|
||||||
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
"DescriptorTable(UAV(u0, space = 1, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
\
|
|
||||||
\
|
|
||||||
"StaticSampler(s0, " \
|
|
||||||
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
|
||||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"maxAnisotropy = 1)"
|
|
||||||
|
|
||||||
ConstantBuffer<struct sh_flood_constants> g_constants : register(b0);
|
|
||||||
Texture2D<float4> g_emittance_textures[] : register(t0, space0);
|
|
||||||
RWTexture2D<uint2> g_flood_textures[]: register(u0, space1);
|
|
||||||
|
|
||||||
SamplerState g_sampler : register(s0);
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Entry point
|
* Entry point
|
||||||
@ -32,15 +11,15 @@ struct cs_input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
[numthreads(8, 8, 1)]
|
||||||
SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
SH_ENTRY void cs(struct cs_input input)
|
||||||
{
|
{
|
||||||
uint2 id = input.SV_DispatchThreadID.xy;
|
uint2 id = input.SV_DispatchThreadID.xy;
|
||||||
uint2 tex_size = uint2(g_constants.tex_width, g_constants.tex_height);
|
uint2 tex_size = uint2(sig.tex_width, sig.tex_height);
|
||||||
if (id.x < tex_size.x && id.y < tex_size.y) {
|
if (id.x < tex_size.x && id.y < tex_size.y) {
|
||||||
Texture2D<float4> emittance_tex = g_emittance_textures[g_constants.emittance_tex_urid];
|
Texture2D<float4> emittance_tex = resource_from_urid(sig.emittance_tex_urid);
|
||||||
RWTexture2D<uint2> read_flood_tex = g_flood_textures[g_constants.read_flood_tex_urid];
|
RWTexture2D<uint2> read_flood_tex = resource_from_urid(sig.read_flood_tex_urid);
|
||||||
RWTexture2D<uint2> target_flood_tex = g_flood_textures[g_constants.target_flood_tex_urid];
|
RWTexture2D<uint2> target_flood_tex = resource_from_urid(sig.target_flood_tex_urid);
|
||||||
int step_len = g_constants.step_len;
|
int step_len = sig.step_len;
|
||||||
if (step_len == -1) {
|
if (step_len == -1) {
|
||||||
/* Seed */
|
/* Seed */
|
||||||
float4 emittance = emittance_tex[id];
|
float4 emittance = emittance_tex[id];
|
||||||
|
|||||||
@ -1,28 +1,6 @@
|
|||||||
#include "common.hlsl"
|
#include "common.hlsl"
|
||||||
|
|
||||||
/* ========================== *
|
ConstantBuffer<struct sh_material_sig> sig : register(b0);
|
||||||
* Root signature
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define ROOTSIG \
|
|
||||||
"RootConstants(num32BitConstants = 16, b0), " \
|
|
||||||
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
"SRV(t0, space = 1), " \
|
|
||||||
"SRV(t0, space = 2), " \
|
|
||||||
\
|
|
||||||
"StaticSampler(s0, " \
|
|
||||||
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
|
||||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"maxAnisotropy = 1)"
|
|
||||||
|
|
||||||
ConstantBuffer<struct sh_material_constants> g_constants : register(b0);
|
|
||||||
Texture2D g_textures[] : register(t0, space0);
|
|
||||||
StructuredBuffer<struct sh_material_instance> g_instances : register(t0, space1);
|
|
||||||
StructuredBuffer<struct sh_material_grid> g_grids : register(t0, space2);
|
|
||||||
|
|
||||||
SamplerState g_sampler : register(s0);
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -42,7 +20,7 @@ struct vs_output {
|
|||||||
DECLS(float4, SV_Position);
|
DECLS(float4, SV_Position);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
SH_ENTRY struct vs_output vs(struct vs_input input)
|
||||||
{
|
{
|
||||||
static const float2 unit_quad_verts[4] = {
|
static const float2 unit_quad_verts[4] = {
|
||||||
float2(-0.5f, -0.5f),
|
float2(-0.5f, -0.5f),
|
||||||
@ -50,12 +28,12 @@ SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
|||||||
float2(0.5f, 0.5f),
|
float2(0.5f, 0.5f),
|
||||||
float2(-0.5f, 0.5f)
|
float2(-0.5f, 0.5f)
|
||||||
};
|
};
|
||||||
|
StructuredBuffer<struct sh_material_instance> instances = resource_from_urid(sig.instances_urid);
|
||||||
struct sh_material_instance instance = g_instances[input.SV_InstanceID];
|
struct sh_material_instance instance = instances[input.SV_InstanceID];
|
||||||
float2 vert = unit_quad_verts[input.SV_VertexID];
|
float2 vert = unit_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;
|
||||||
struct vs_output output;
|
struct vs_output output;
|
||||||
output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1));
|
output.SV_Position = mul(sig.projection, float4(world_pos, 0, 1));
|
||||||
output.tex_nurid = instance.tex_nurid;
|
output.tex_nurid = instance.tex_nurid;
|
||||||
output.grid_id = instance.grid_id;
|
output.grid_id = instance.grid_id;
|
||||||
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
|
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
|
||||||
@ -77,20 +55,21 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target1); /* Emittance */
|
DECLS(float4, SV_Target1); /* Emittance */
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct ps_output ps(struct ps_input input)
|
SH_ENTRY struct ps_output ps(struct ps_input input)
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
struct ps_output output;
|
||||||
float4 albedo = input.vs.tint_lin;
|
float4 albedo = input.vs.tint_lin;
|
||||||
|
|
||||||
/* Texture */
|
/* Texture */
|
||||||
if (input.vs.tex_nurid >= 0) {
|
if (input.vs.tex_nurid >= 0) {
|
||||||
Texture2D<float4> tex = g_textures[NURID(input.vs.tex_nurid)];
|
Texture2D<float4> tex = resource_from_nurid(input.vs.tex_nurid);
|
||||||
albedo *= tex.Sample(g_sampler, input.vs.uv);
|
albedo *= tex.Sample(s_point_clamp, input.vs.uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grid */
|
/* Grid */
|
||||||
if (input.vs.grid_id >= 0) {
|
if (input.vs.grid_id >= 0) {
|
||||||
struct sh_material_grid grid = g_grids[input.vs.grid_id];
|
StructuredBuffer<struct sh_material_grid> grids = resource_from_urid(sig.grids_urid);
|
||||||
|
struct sh_material_grid grid = grids[input.vs.grid_id];
|
||||||
float2 grid_pos = input.vs.SV_Position.xy + grid.offset;
|
float2 grid_pos = input.vs.SV_Position.xy + grid.offset;
|
||||||
float half_thickness = grid.line_thickness / 2;
|
float half_thickness = grid.line_thickness / 2;
|
||||||
float spacing = grid.line_spacing;
|
float spacing = grid.line_spacing;
|
||||||
|
|||||||
@ -3,10 +3,6 @@
|
|||||||
#define SH_STRUCT(s) PACK(struct s)
|
#define SH_STRUCT(s) PACK(struct s)
|
||||||
#define SH_DECL(t, n) struct CAT(sh_, t) n
|
#define SH_DECL(t, n) struct CAT(sh_, t) n
|
||||||
#define SH_DECLS(t, n) SH_DECL(t, n)
|
#define SH_DECLS(t, n) SH_DECL(t, n)
|
||||||
#define SH_ENTRY(rootsig) static
|
|
||||||
#define SH_ASSERT_ROOT_CONST(s, n) STATIC_ASSERT((sizeof(s) % 16 == 0) && /* Root constant struct should pad to 16 byte alignment */ \
|
|
||||||
((sizeof(s) / 4) == n) && /* Root constant struct size should match the specified 32-bit-constant count */ \
|
|
||||||
(sizeof(s) <= 256)) /* Root constant struct can only fit 64 DWORDS */
|
|
||||||
|
|
||||||
struct sh_uint { u32 v; };
|
struct sh_uint { u32 v; };
|
||||||
INLINE struct sh_uint sh_uint_from_u32(u32 v)
|
INLINE struct sh_uint sh_uint_from_u32(u32 v)
|
||||||
@ -79,8 +75,6 @@ INLINE struct sh_float2x3 sh_float2x3_from_xform(struct xform v)
|
|||||||
#define SH_STRUCT(s) struct s
|
#define SH_STRUCT(s) struct s
|
||||||
#define SH_DECL(t, n) t n
|
#define SH_DECL(t, n) t n
|
||||||
#define SH_DECLS(t, n) t n : n
|
#define SH_DECLS(t, n) t n : n
|
||||||
#define SH_ENTRY(rootsig) [RootSignature(rootsig)]
|
|
||||||
#define SH_ASSERT_ROOT_CONST(s, n)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -95,16 +89,18 @@ INLINE struct sh_float2x3 sh_float2x3_from_xform(struct xform v)
|
|||||||
#define SH_BLUE_NOISE_TEX_DEPTH 64
|
#define SH_BLUE_NOISE_TEX_DEPTH 64
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Material shader structures
|
* Material shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
SH_STRUCT(sh_material_constants {
|
SH_STRUCT(sh_material_sig {
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
SH_DECL(float4x4, projection); /* 16 consts */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
|
SH_DECL(uint, instances_urid); /* 01 consts */
|
||||||
|
SH_DECL(uint, grids_urid); /* 01 consts */
|
||||||
|
SH_DECL(uint2, _pad0); /* 02 consts (padding) */
|
||||||
|
/* ---------------------------------------------------- */
|
||||||
});
|
});
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_material_constants, 16); /* Expected to match num32BitConstants in shader's root signature */
|
|
||||||
|
|
||||||
SH_STRUCT(sh_material_instance {
|
SH_STRUCT(sh_material_instance {
|
||||||
SH_DECL(int, tex_nurid);
|
SH_DECL(int, tex_nurid);
|
||||||
@ -129,10 +125,10 @@ SH_STRUCT(sh_material_grid {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Flood shader structures
|
* Flood shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
SH_STRUCT(sh_flood_constants {
|
SH_STRUCT(sh_flood_sig {
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
SH_DECL(int, step_len); /* 01 consts */
|
SH_DECL(int, step_len); /* 01 consts */
|
||||||
SH_DECL(uint, emittance_tex_urid); /* 01 consts */
|
SH_DECL(uint, emittance_tex_urid); /* 01 consts */
|
||||||
@ -144,16 +140,15 @@ SH_STRUCT(sh_flood_constants {
|
|||||||
SH_DECL(uint2, _pad0); /* 02 consts (padding) */
|
SH_DECL(uint2, _pad0); /* 02 consts (padding) */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
});
|
});
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_flood_constants, 8); /* Expected to match num32BitConstants in shader's root signature */
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Shade shader structures
|
* Shade shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
#define SH_SHADE_FLAG_NONE (0 << 0)
|
#define SH_SHADE_FLAG_NONE (0 << 0)
|
||||||
#define SH_SHADE_FLAG_DISABLE_EFFECTS (1 << 0)
|
#define SH_SHADE_FLAG_DISABLE_EFFECTS (1 << 0)
|
||||||
|
|
||||||
SH_STRUCT(sh_shade_constants {
|
SH_STRUCT(sh_shade_sig {
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
SH_DECL(uint4, frame_seed); /* 04 consts */
|
SH_DECL(uint4, frame_seed); /* 04 consts */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
@ -172,18 +167,16 @@ SH_STRUCT(sh_shade_constants {
|
|||||||
SH_DECL(uint, target_tex_urid); /* 01 consts */
|
SH_DECL(uint, target_tex_urid); /* 01 consts */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
});
|
});
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_shade_constants, 16); /* Expected to match num32BitConstants in shader's root signature */
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Shape shader structures
|
* Shape shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
SH_STRUCT(sh_shape_constants {
|
SH_STRUCT(sh_shape_sig {
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
SH_DECL(float4x4, projection); /* 16 consts */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
});
|
});
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_shape_constants, 16); /* Expected to match num32BitConstants in shader's root signature */
|
|
||||||
|
|
||||||
SH_STRUCT(sh_shape_vert {
|
SH_STRUCT(sh_shape_vert {
|
||||||
SH_DECLS(float2, pos);
|
SH_DECLS(float2, pos);
|
||||||
@ -191,15 +184,17 @@ SH_STRUCT(sh_shape_vert {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* UI shader structures
|
* UI shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
SH_STRUCT(sh_ui_constants {
|
SH_STRUCT(sh_ui_sig {
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
SH_DECL(float4x4, projection); /* 16 consts */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
|
SH_DECL(uint, instances_urid); /* 01 consts */
|
||||||
|
SH_DECL(uint3, _pad0); /* 03 consts (padding) */
|
||||||
|
/* ---------------------------------------------------- */
|
||||||
});
|
});
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_ui_constants, 16); /* Expected to match num32BitConstants in shader's root signature */
|
|
||||||
|
|
||||||
SH_STRUCT(sh_ui_instance {
|
SH_STRUCT(sh_ui_instance {
|
||||||
SH_DECL(int, tex_nurid);
|
SH_DECL(int, tex_nurid);
|
||||||
@ -211,14 +206,14 @@ SH_STRUCT(sh_ui_instance {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Blit shader structures
|
* Blit shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
#define SH_BLIT_FLAG_NONE (0 << 0)
|
#define SH_BLIT_FLAG_NONE (0 << 0)
|
||||||
#define SH_BLIT_FLAG_TONE_MAP (1 << 0)
|
#define SH_BLIT_FLAG_TONE_MAP (1 << 0)
|
||||||
#define SH_BLIT_FLAG_GAMMA_CORRECT (1 << 1)
|
#define SH_BLIT_FLAG_GAMMA_CORRECT (1 << 1)
|
||||||
|
|
||||||
SH_STRUCT(sh_blit_constants {
|
SH_STRUCT(sh_blit_sig {
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
SH_DECL(float4x4, projection); /* 16 consts */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
@ -228,4 +223,3 @@ SH_STRUCT(sh_blit_constants {
|
|||||||
SH_DECL(float, gamma); /* 01 consts */
|
SH_DECL(float, gamma); /* 01 consts */
|
||||||
/* ---------------------------------------------------- */
|
/* ---------------------------------------------------- */
|
||||||
});
|
});
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_blit_constants, 20); /* Expected to match num32BitConstants in shader's root signature */
|
|
||||||
|
|||||||
@ -1,25 +1,6 @@
|
|||||||
#include "common.hlsl"
|
#include "common.hlsl"
|
||||||
|
|
||||||
/* ========================== *
|
ConstantBuffer<struct sh_shade_sig> sig : register(b0);
|
||||||
* Root signature
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define ROOTSIG \
|
|
||||||
"RootConstants(num32BitConstants = 16, b0), " \
|
|
||||||
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
"DescriptorTable(SRV(t0, space = 1, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
"DescriptorTable(SRV(t0, space = 2, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
"DescriptorTable(UAV(u0, space = 3, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), "
|
|
||||||
|
|
||||||
ConstantBuffer<struct sh_shade_constants> g_constants : register(b0);
|
|
||||||
Texture2D<float4> g_textures_float4[] : register(t0, space0);
|
|
||||||
Texture2D<uint2> g_textures_uint2[] : register(t0, space1);
|
|
||||||
Texture3D<uint> g_noise_textures[] : register(t0, space2);
|
|
||||||
RWTexture2D<float4> g_target_textures[]: register(u0, space3);
|
|
||||||
|
|
||||||
struct cs_input {
|
|
||||||
DECLS(uint3, SV_DispatchThreadID);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Lighting
|
* Lighting
|
||||||
@ -30,12 +11,12 @@ struct cs_input {
|
|||||||
#define EDGE_FALLOFF 100
|
#define EDGE_FALLOFF 100
|
||||||
|
|
||||||
float rand_angle(uint2 pos, uint ray_index) {
|
float rand_angle(uint2 pos, uint ray_index) {
|
||||||
Texture3D<uint> noise_tex = g_noise_textures[SH_BLUE_NOISE_TEX_ID];
|
Texture3D<uint> noise_tex = resource_from_urid(SH_BLUE_NOISE_TEX_ID);
|
||||||
|
|
||||||
int3 noise_coord = int3(1, 1, 1);
|
int3 noise_coord = int3(1, 1, 1);
|
||||||
noise_coord += int3(pos.xy, ray_index);
|
noise_coord += int3(pos.xy, ray_index);
|
||||||
noise_coord.xyz += g_constants.frame_seed.xyz;
|
noise_coord.xyz += sig.frame_seed.xyz;
|
||||||
// noise_coord.xy -= g_constants.camera_offset;
|
// noise_coord.xy -= sig.camera_offset;
|
||||||
|
|
||||||
uint noise = noise_tex[noise_coord % uint3(SH_BLUE_NOISE_TEX_WIDTH, SH_BLUE_NOISE_TEX_HEIGHT, SH_BLUE_NOISE_TEX_DEPTH)];
|
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;
|
return ((float)noise / (float)0xFFFF) * TAU;
|
||||||
@ -43,8 +24,8 @@ float rand_angle(uint2 pos, uint ray_index) {
|
|||||||
|
|
||||||
INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
||||||
{
|
{
|
||||||
Texture2D<uint2> flood_tex = g_textures_uint2[g_constants.emittance_flood_tex_urid];
|
Texture2D<uint2> flood_tex = resource_from_urid(sig.emittance_flood_tex_urid);
|
||||||
Texture2D<float4> emittance_tex = g_textures_float4[g_constants.emittance_tex_urid];
|
Texture2D<float4> emittance_tex = resource_from_urid(sig.emittance_tex_urid);
|
||||||
|
|
||||||
float3 result = float3(0, 0, 0);
|
float3 result = float3(0, 0, 0);
|
||||||
float2 at_float = ray_start;
|
float2 at_float = ray_start;
|
||||||
@ -55,15 +36,15 @@ INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
|||||||
float dist = length(dist_vec);
|
float dist = length(dist_vec);
|
||||||
if (dist < 1) {
|
if (dist < 1) {
|
||||||
/* Scale light by distance from edge so that offscreen-lights fade in/out rather than popping in */
|
/* Scale light by distance from edge so that offscreen-lights fade in/out rather than popping in */
|
||||||
float dist_x = min(abs(g_constants.tex_width - at_float.x), at_float.x);
|
float dist_x = min(abs(sig.tex_width - at_float.x), at_float.x);
|
||||||
float dist_y = min(abs(g_constants.tex_height - at_float.y), at_float.y);
|
float dist_y = min(abs(sig.tex_height - at_float.y), at_float.y);
|
||||||
float dist_scale = min(min(dist_x, dist_y) / EDGE_FALLOFF, 1);
|
float dist_scale = min(min(dist_x, dist_y) / EDGE_FALLOFF, 1);
|
||||||
result = emittance_tex[flood].rgb * dist_scale;
|
result = emittance_tex[flood].rgb * dist_scale;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
at_float += ray_dir * dist;
|
at_float += ray_dir * dist;
|
||||||
at_uint = round(at_float);
|
at_uint = round(at_float);
|
||||||
if (at_uint.x < 0 || at_uint.x >= g_constants.tex_width || at_uint.y < 0 || at_uint.y >= g_constants.tex_height) {
|
if (at_uint.x < 0 || at_uint.x >= sig.tex_width || at_uint.y < 0 || at_uint.y >= sig.tex_height) {
|
||||||
/* Ray hit edge of screen */
|
/* Ray hit edge of screen */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -89,21 +70,25 @@ INLINE float3 get_light_at_pos(uint2 pos)
|
|||||||
* Entry point
|
* Entry point
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
|
struct cs_input {
|
||||||
|
DECLS(uint3, SV_DispatchThreadID);
|
||||||
|
};
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
[numthreads(8, 8, 1)]
|
||||||
SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
SH_ENTRY void cs(struct cs_input input)
|
||||||
{
|
{
|
||||||
uint2 id = input.SV_DispatchThreadID.xy;
|
uint2 id = input.SV_DispatchThreadID.xy;
|
||||||
if (id.x < g_constants.tex_width && id.y < g_constants.tex_height) {
|
if (id.x < sig.tex_width && id.y < sig.tex_height) {
|
||||||
Texture2D<float4> albedo_tex = g_textures_float4[g_constants.albedo_tex_urid];
|
Texture2D<float4> albedo_tex = resource_from_urid(sig.albedo_tex_urid);
|
||||||
Texture2D<float4> read_tex = g_textures_float4[g_constants.read_tex_urid];
|
Texture2D<float4> read_tex = resource_from_urid(sig.read_tex_urid);
|
||||||
RWTexture2D<float4> target_tex = g_target_textures[g_constants.target_tex_urid];
|
RWTexture2D<float4> target_tex = resource_from_urid(sig.target_tex_urid);
|
||||||
float4 color = float4(1, 1, 1, 1);
|
float4 color = float4(1, 1, 1, 1);
|
||||||
|
|
||||||
/* Apply albedo */
|
/* Apply albedo */
|
||||||
color *= albedo_tex[id];
|
color *= albedo_tex[id];
|
||||||
|
|
||||||
/* Apply lighting */
|
/* Apply lighting */
|
||||||
if (!(g_constants.flags & SH_SHADE_FLAG_DISABLE_EFFECTS)) {
|
if (!(sig.flags & SH_SHADE_FLAG_DISABLE_EFFECTS)) {
|
||||||
color.rgb *= get_light_at_pos(id);
|
color.rgb *= get_light_at_pos(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,6 @@
|
|||||||
#include "common.hlsl"
|
#include "common.hlsl"
|
||||||
|
|
||||||
/* ========================== *
|
ConstantBuffer<struct sh_material_sig> sig : register(b0);
|
||||||
* Root signature
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define ROOTSIG \
|
|
||||||
"RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
|
|
||||||
"RootConstants(num32BitConstants=16, b0)"
|
|
||||||
|
|
||||||
ConstantBuffer<struct sh_material_constants> g_constants : register(b0);
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -24,10 +16,10 @@ struct vs_output {
|
|||||||
DECLS(float4, color_srgb);
|
DECLS(float4, color_srgb);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
SH_ENTRY struct vs_output vs(struct vs_input input)
|
||||||
{
|
{
|
||||||
struct vs_output output;
|
struct vs_output output;
|
||||||
output.SV_Position = mul(g_constants.projection, float4(input.pos.xy, 0, 1));
|
output.SV_Position = mul(sig.projection, float4(input.pos.xy, 0, 1));
|
||||||
output.color_srgb = input.color_srgb;
|
output.color_srgb = input.color_srgb;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -44,7 +36,7 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target);
|
DECLS(float4, SV_Target);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct ps_output ps(struct ps_input input)
|
SH_ENTRY struct ps_output ps(struct ps_input input)
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
struct ps_output output;
|
||||||
output.SV_Target = input.vs.color_srgb;
|
output.SV_Target = input.vs.color_srgb;
|
||||||
|
|||||||
@ -1,26 +1,6 @@
|
|||||||
#include "common.hlsl"
|
#include "common.hlsl"
|
||||||
|
|
||||||
/* ========================== *
|
ConstantBuffer<struct sh_ui_sig> sig : register(b0);
|
||||||
* Root signature
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define ROOTSIG \
|
|
||||||
"RootConstants(num32BitConstants = 16, b0), " \
|
|
||||||
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
||||||
"SRV(t0, space = 1), " \
|
|
||||||
\
|
|
||||||
"StaticSampler(s0, " \
|
|
||||||
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
|
||||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"maxAnisotropy = 1)"
|
|
||||||
|
|
||||||
ConstantBuffer<struct sh_ui_constants> g_constants : register(b0);
|
|
||||||
Texture2D<float4> g_textures[] : register(t0, space0);
|
|
||||||
StructuredBuffer<struct sh_ui_instance> g_instances : register(t0, space1);
|
|
||||||
|
|
||||||
SamplerState g_sampler : register(s0);
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -38,7 +18,7 @@ struct vs_output {
|
|||||||
DECLS(float4, SV_Position);
|
DECLS(float4, SV_Position);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
SH_ENTRY struct vs_output vs(struct vs_input input)
|
||||||
{
|
{
|
||||||
static const float2 unit_quad_verts[4] = {
|
static const float2 unit_quad_verts[4] = {
|
||||||
float2(-0.5f, -0.5f),
|
float2(-0.5f, -0.5f),
|
||||||
@ -47,12 +27,13 @@ SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
|
|||||||
float2(-0.5f, 0.5f)
|
float2(-0.5f, 0.5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sh_ui_instance instance = g_instances[input.SV_InstanceID];
|
StructuredBuffer<struct sh_ui_instance> instances = resource_from_urid(sig.instances_urid);
|
||||||
|
struct sh_ui_instance instance = instances[input.SV_InstanceID];
|
||||||
float2 vert = unit_quad_verts[input.SV_VertexID];
|
float2 vert = unit_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;
|
||||||
|
|
||||||
struct vs_output output;
|
struct vs_output output;
|
||||||
output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1));
|
output.SV_Position = mul(sig.projection, float4(world_pos, 0, 1));
|
||||||
output.tex_nurid = instance.tex_nurid;
|
output.tex_nurid = instance.tex_nurid;
|
||||||
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
|
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
|
||||||
output.tint_srgb = float4_norm_from_uint(instance.tint_srgb);
|
output.tint_srgb = float4_norm_from_uint(instance.tint_srgb);
|
||||||
@ -71,15 +52,15 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target0);
|
DECLS(float4, SV_Target0);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY(ROOTSIG) struct ps_output ps(struct ps_input input)
|
SH_ENTRY struct ps_output ps(struct ps_input input)
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
struct ps_output output;
|
||||||
float4 color = input.vs.tint_srgb;
|
float4 color = input.vs.tint_srgb;
|
||||||
|
|
||||||
/* Texture */
|
/* Texture */
|
||||||
if (input.vs.tex_nurid >= 0) {
|
if (input.vs.tex_nurid >= 0) {
|
||||||
Texture2D<float4> tex = g_textures[NURID(input.vs.tex_nurid)];
|
Texture2D<float4> tex = resource_from_nurid(input.vs.tex_nurid);
|
||||||
color *= tex.Sample(g_sampler, input.vs.uv);
|
color *= tex.Sample(s_point_clamp, input.vs.uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
output.SV_Target0 = color;
|
output.SV_Target0 = color;
|
||||||
|
|||||||
@ -1375,7 +1375,7 @@ INTERNAL THREAD_DEF(job_worker_entry, worker_ctx_arg)
|
|||||||
//__profnc("Wait for job", RGB32_F(0.75, 0.75, 0));
|
//__profnc("Wait for job", RGB32_F(0.75, 0.75, 0));
|
||||||
tm_lock(&pool->workers_wake_lock);
|
tm_lock(&pool->workers_wake_lock);
|
||||||
{
|
{
|
||||||
i64 num_jobs_in_queue = atomic64_fetch(&pool->num_jobs_in_queue.v);
|
num_jobs_in_queue = atomic64_fetch(&pool->num_jobs_in_queue.v);
|
||||||
shutdown = atomic32_fetch(&pool->workers_shutdown.v);
|
shutdown = atomic32_fetch(&pool->workers_shutdown.v);
|
||||||
while (num_jobs_in_queue <= 0 && !shutdown) {
|
while (num_jobs_in_queue <= 0 && !shutdown) {
|
||||||
{
|
{
|
||||||
|
|||||||
@ -176,7 +176,7 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = {
|
|||||||
[SYS_BTN_F1] = USER_BIND_KIND_DEBUG_PAUSE,
|
[SYS_BTN_F1] = USER_BIND_KIND_DEBUG_PAUSE,
|
||||||
[SYS_BTN_F2] = USER_BIND_KIND_DEBUG_CAMERA,
|
[SYS_BTN_F2] = USER_BIND_KIND_DEBUG_CAMERA,
|
||||||
[SYS_BTN_F3] = USER_BIND_KIND_DEBUG_DRAW,
|
[SYS_BTN_F3] = USER_BIND_KIND_DEBUG_DRAW,
|
||||||
[SYS_BTN_F5] = USER_BIND_KIND_DEBUG_TOGGLE_TOPMOST,
|
[SYS_BTN_F4] = USER_BIND_KIND_DEBUG_TOGGLE_TOPMOST,
|
||||||
[SYS_BTN_GRAVE_ACCENT] = USER_BIND_KIND_DEBUG_CONSOLE,
|
[SYS_BTN_GRAVE_ACCENT] = USER_BIND_KIND_DEBUG_CONSOLE,
|
||||||
[SYS_BTN_ALT] = USER_BIND_KIND_FULLSCREEN_MOD,
|
[SYS_BTN_ALT] = USER_BIND_KIND_FULLSCREEN_MOD,
|
||||||
[SYS_BTN_ENTER] = USER_BIND_KIND_FULLSCREEN,
|
[SYS_BTN_ENTER] = USER_BIND_KIND_FULLSCREEN,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user