sh -> kernel
This commit is contained in:
parent
809994ebd4
commit
d544a55f0e
143
build.c
143
build.c
@ -453,8 +453,6 @@ void OnBuild(StringList cli_args)
|
|||||||
|
|
||||||
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_cpp_compile_args = { 0 };
|
|
||||||
StringList compile_and_link_args = { 0 };
|
StringList compile_and_link_args = { 0 };
|
||||||
StringList compile_args = { 0 };
|
StringList compile_args = { 0 };
|
||||||
StringList compile_warnings = { 0 };
|
StringList compile_warnings = { 0 };
|
||||||
@ -467,8 +465,6 @@ void OnBuild(StringList cli_args)
|
|||||||
/* Msvc */
|
/* Msvc */
|
||||||
StringListAppend(&perm, &c_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes"));
|
StringListAppend(&perm, &c_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\" /FS /showIncludes"));
|
||||||
StringListAppend(&perm, &cpp_compile_args, Lit("cl.exe /nologo /std:c++20 /c \"%F\" /Fo\"%F\" /FS /showIncludes"));
|
StringListAppend(&perm, &cpp_compile_args, Lit("cl.exe /nologo /std:c++20 /c \"%F\" /Fo\"%F\" /FS /showIncludes"));
|
||||||
StringListAppend(&perm, &pch_c_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\" /FS /showIncludes"));
|
|
||||||
StringListAppend(&perm, &pch_cpp_compile_args, Lit("cl.exe /nologo /std:c++20 /c /Yc\"%F\" \"%F\" /FS /showIncludes"));
|
|
||||||
StringListAppend(&perm, &rc_compile_args, Lit("rc /fo\"%F\" \"%F\""));
|
StringListAppend(&perm, &rc_compile_args, Lit("rc /fo\"%F\" \"%F\""));
|
||||||
|
|
||||||
StringListAppend(&perm, &link_args, Lit("link.exe /nologo %F /OUT:\"%F\" /DEBUG:FULL /OPT:REF /OPT:ICF"));
|
StringListAppend(&perm, &link_args, Lit("link.exe /nologo %F /OUT:\"%F\" /DEBUG:FULL /OPT:REF /OPT:ICF"));
|
||||||
@ -484,8 +480,6 @@ void OnBuild(StringList cli_args)
|
|||||||
/* Clang */
|
/* Clang */
|
||||||
StringListAppend(&perm, &c_compile_args, Lit("clang -xc -std=c99 -c \"%F\" -o \"%F\" -MD"));
|
StringListAppend(&perm, &c_compile_args, Lit("clang -xc -std=c99 -c \"%F\" -o \"%F\" -MD"));
|
||||||
StringListAppend(&perm, &cpp_compile_args, Lit("clang -xc++ -std=c++20 -c \"%F\" -o \"%F\" -MD"));
|
StringListAppend(&perm, &cpp_compile_args, Lit("clang -xc++ -std=c++20 -c \"%F\" -o \"%F\" -MD"));
|
||||||
StringListAppend(&perm, &pch_c_compile_args, Lit("clang -xc-header -std=c99 -c \"%F\" -o \"%F\" -MD"));
|
|
||||||
StringListAppend(&perm, &pch_cpp_compile_args, Lit("clang -xc++-header -std=c++20 -c \"%F\" -o \"%F\" -MD"));
|
|
||||||
StringListAppend(&perm, &rc_compile_args, Lit("llvm-rc /fo\"%F\" \"%F\""));
|
StringListAppend(&perm, &rc_compile_args, Lit("llvm-rc /fo\"%F\" \"%F\""));
|
||||||
|
|
||||||
StringListAppend(&perm, &link_args, Lit("clang %F -o \"%F\""));
|
StringListAppend(&perm, &link_args, Lit("clang %F -o \"%F\""));
|
||||||
@ -682,9 +676,9 @@ void OnBuild(StringList cli_args)
|
|||||||
{
|
{
|
||||||
D_TagList src_input_files = { 0 };
|
D_TagList src_input_files = { 0 };
|
||||||
{
|
{
|
||||||
D_Tag src_dir = D_TagFromPath(&perm, Lit("src/sh"), D_TagKind_Dir);
|
D_Tag src_dir = D_TagFromPath(&perm, Lit("src"), D_TagKind_Dir);
|
||||||
D_TagList src_files = { 0 };
|
D_TagList src_files = { 0 };
|
||||||
D_GetDirContents(&perm, &src_files, src_dir, 0);
|
D_GetDirContents(&perm, &src_files, src_dir, 1);
|
||||||
|
|
||||||
for (D_TagListNode *n = src_files.first; n; n = n->next) {
|
for (D_TagListNode *n = src_files.first; n; n = n->next) {
|
||||||
D_Tag file = n->tag;
|
D_Tag file = n->tag;
|
||||||
@ -692,9 +686,9 @@ void OnBuild(StringList cli_args)
|
|||||||
String name = D_GetName(file);
|
String name = D_GetName(file);
|
||||||
String extension = StringPathExtension(name);
|
String extension = StringPathExtension(name);
|
||||||
Bool is_dir = file.kind == D_TagKind_Dir;
|
Bool is_dir = file.kind == D_TagKind_Dir;
|
||||||
Bool is_rs = !is_dir && StringEqual(extension, Lit("hlsl_rs"));
|
Bool is_rst = !is_dir && StringEqual(extension, Lit("rst"));
|
||||||
Bool is_cs = !is_dir && StringEqual(extension, Lit("hlsl_cs"));
|
Bool is_knl = !is_dir && StringEqual(extension, Lit("knl"));
|
||||||
if (is_rs || is_cs) {
|
if (is_rst || is_knl) {
|
||||||
D_TagListAppend(&perm, &src_input_files, file);
|
D_TagListAppend(&perm, &src_input_files, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,32 +705,32 @@ void OnBuild(StringList cli_args)
|
|||||||
String name = D_GetName(file);
|
String name = D_GetName(file);
|
||||||
String name_no_extension = StringPathNoExtension(name);
|
String name_no_extension = StringPathNoExtension(name);
|
||||||
String extension = StringPathExtension(name);
|
String extension = StringPathExtension(name);
|
||||||
Bool is_rs = StringEqual(extension, Lit("hlsl_rs"));
|
Bool is_rst = StringEqual(extension, Lit("rst"));
|
||||||
Bool is_cs = !is_rs && StringEqual(extension, Lit("hlsl_cs"));
|
Bool is_knl = !is_rst && StringEqual(extension, Lit("knl"));
|
||||||
for (I32 kind = 0; kind < 3; ++kind) {
|
for (I32 kind = 0; kind < 3; ++kind) {
|
||||||
String out_file_extension = { 0 };
|
String out_file_extension = { 0 };
|
||||||
String entry = { 0 };
|
String entry = { 0 };
|
||||||
String profile = { 0 };
|
String profile = { 0 };
|
||||||
if (kind == 0 && is_rs) {
|
if (kind == 0 && is_rst) {
|
||||||
/* Vertex shader */
|
/* Vertex shader */
|
||||||
out_file_extension = Lit("dxc_vs");
|
out_file_extension = Lit("vs");
|
||||||
entry = Lit("vs");
|
entry = Lit("vs");
|
||||||
profile = Lit("vs_6_6");
|
profile = Lit("vs_6_6");
|
||||||
} else if (kind == 1 && is_rs) {
|
} else if (kind == 1 && is_rst) {
|
||||||
/* Pixel shader */
|
/* Pixel shader */
|
||||||
out_file_extension = Lit("dxc_ps");
|
out_file_extension = Lit("ps");
|
||||||
entry = Lit("ps");
|
entry = Lit("ps");
|
||||||
profile = Lit("ps_6_6");
|
profile = Lit("ps_6_6");
|
||||||
} else if (kind == 2 && is_cs) {
|
} else if (kind == 2 && is_knl) {
|
||||||
/* Compute shader */
|
/* Compute shader */
|
||||||
out_file_extension = Lit("dxc_cs");
|
out_file_extension = Lit("cs");
|
||||||
entry = Lit("cs");
|
entry = Lit("cs");
|
||||||
profile = Lit("cs_6_6");
|
profile = Lit("cs_6_6");
|
||||||
}
|
}
|
||||||
if (entry.len > 0) {
|
if (entry.len > 0) {
|
||||||
D_Tag dep_file;
|
D_Tag dep_file;
|
||||||
{
|
{
|
||||||
String dep_file_path = StringF(&perm, Lit("%F/%F.%F"), FmtStr(out_dxc_dir_path), FmtStr(name_no_extension), FmtStr(dep_file_extension));
|
String dep_file_path = StringF(&perm, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(dep_file_extension));
|
||||||
dep_file = D_TagFromPath(&perm, dep_file_path, D_TagKind_DepFile);
|
dep_file = D_TagFromPath(&perm, dep_file_path, D_TagKind_DepFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,110 +838,6 @@ void OnBuild(StringList cli_args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Build step: Compile pch files
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Atomic32 pch_success_flag = { 0 };
|
|
||||||
D_TagList depfile_force_includes = { 0 };
|
|
||||||
{
|
|
||||||
AddSyncPoint();
|
|
||||||
|
|
||||||
D_Tag pch_header_file = D_TagFromPath(&perm, Lit("src/common.h"), D_TagKind_File);
|
|
||||||
D_Tag dep_file;
|
|
||||||
{
|
|
||||||
String name = D_GetName(pch_header_file);
|
|
||||||
String dep_file_path = StringF(&perm, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name), FmtStr(dep_file_extension));
|
|
||||||
dep_file = D_TagFromPath(&perm, dep_file_path, D_TagKind_DepFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
D_Tag pch_c_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/%F.c_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File);
|
|
||||||
D_AddDependency(&store, pch_c_file, pch_header_file);
|
|
||||||
D_AddDependency(&store, pch_c_file, dep_file);
|
|
||||||
|
|
||||||
D_Tag pch_cpp_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/%F.cpp_pch"), FmtStr(out_obj_dir_path), FmtStr(D_GetName(pch_header_file))), D_TagKind_File);
|
|
||||||
D_AddDependency(&store, pch_cpp_file, pch_header_file);
|
|
||||||
D_AddDependency(&store, pch_cpp_file, dep_file);
|
|
||||||
|
|
||||||
if (arg_msvc) {
|
|
||||||
D_TagListAppend(&perm, &depfile_force_includes, pch_header_file);
|
|
||||||
|
|
||||||
D_Tag pch_c_src_gen_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.c"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
|
||||||
D_Tag pch_c_src_gen_obj_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
|
||||||
D_Tag pch_cpp_src_gen_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
|
||||||
D_Tag pch_cpp_src_gen_obj_file = D_TagFromPath(&perm, StringF(&perm, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path)), D_TagKind_File);
|
|
||||||
|
|
||||||
StringListAppend(&perm, &c_compile_args, StringF(&perm, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path)));
|
|
||||||
StringListAppend(&perm, &cpp_compile_args, StringF(&perm, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path)));
|
|
||||||
StringListAppend(&perm, &pch_c_compile_args, StringF(&perm, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path), FmtStr(pch_c_src_gen_obj_file.full_path)));
|
|
||||||
StringListAppend(&perm, &pch_cpp_compile_args, StringF(&perm, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path), FmtStr(pch_cpp_src_gen_obj_file.full_path)));
|
|
||||||
|
|
||||||
D_TagListAppend(&perm, &link_files, pch_c_src_gen_obj_file);
|
|
||||||
D_TagListAppend(&perm, &link_files, pch_cpp_src_gen_obj_file);
|
|
||||||
|
|
||||||
String pch_c_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args);
|
|
||||||
String pch_cpp_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
|
|
||||||
|
|
||||||
/* C */
|
|
||||||
D_AddDependency(&store, pch_c_src_gen_obj_file, pch_c_src_gen_file);
|
|
||||||
D_AddDependency(&store, pch_c_file, pch_c_src_gen_obj_file);
|
|
||||||
if (IsDirty(pch_c_file)) {
|
|
||||||
D_ClearWrite(pch_c_src_gen_file, Lit(""));
|
|
||||||
BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&perm, BuildStepMsvcCompileCommandArg);
|
|
||||||
bs_arg->cmd = StringF(&perm, pch_c_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_c_src_gen_file.full_path));
|
|
||||||
bs_arg->depfile_dependent = pch_header_file;
|
|
||||||
bs_arg->output_depfile = dep_file;
|
|
||||||
bs_arg->skip_flag = &rc_success_flag;
|
|
||||||
bs_arg->failure_flag = &pch_success_flag;
|
|
||||||
bs_arg->delete_file_on_failure = pch_c_file;
|
|
||||||
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_c_file)));
|
|
||||||
AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Cpp */
|
|
||||||
D_AddDependency(&store, pch_cpp_src_gen_obj_file, pch_cpp_src_gen_file);
|
|
||||||
D_AddDependency(&store, pch_cpp_file, pch_cpp_src_gen_obj_file);
|
|
||||||
if (IsDirty(pch_cpp_file)) {
|
|
||||||
D_ClearWrite(pch_cpp_src_gen_file, Lit(""));
|
|
||||||
BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&perm, BuildStepMsvcCompileCommandArg);
|
|
||||||
bs_arg->cmd = StringF(&perm, pch_cpp_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_src_gen_file.full_path));
|
|
||||||
bs_arg->depfile_dependent = pch_header_file;
|
|
||||||
bs_arg->output_depfile = dep_file;
|
|
||||||
bs_arg->skip_flag = &rc_success_flag;
|
|
||||||
bs_arg->failure_flag = &pch_success_flag;
|
|
||||||
bs_arg->delete_file_on_failure = pch_cpp_file;
|
|
||||||
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_cpp_file)));
|
|
||||||
AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
StringListAppend(&perm, &c_compile_args, StringF(&perm, Lit("-include-pch %F"), FmtStr(pch_c_file.full_path)));
|
|
||||||
StringListAppend(&perm, &cpp_compile_args, StringF(&perm, Lit("-include-pch %F"), FmtStr(pch_cpp_file.full_path)));
|
|
||||||
|
|
||||||
String pch_c_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args);
|
|
||||||
String pch_cpp_compile_args_fmt = StringFromStringLists(&perm, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
|
|
||||||
|
|
||||||
/* C */
|
|
||||||
if (IsDirty(pch_c_file)) {
|
|
||||||
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
|
|
||||||
bs_arg->cmd = StringF(&perm, pch_c_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_c_file.full_path));
|
|
||||||
bs_arg->skip_flag = &rc_success_flag;
|
|
||||||
bs_arg->failure_flag = &pch_success_flag;
|
|
||||||
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_c_file)));
|
|
||||||
AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Cpp */
|
|
||||||
if (IsDirty(pch_cpp_file)) {
|
|
||||||
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
|
|
||||||
bs_arg->cmd = StringF(&perm, pch_cpp_compile_args_fmt, FmtStr(pch_header_file.full_path), FmtStr(pch_cpp_file.full_path));
|
|
||||||
bs_arg->skip_flag = &rc_success_flag;
|
|
||||||
bs_arg->failure_flag = &pch_success_flag;
|
|
||||||
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(D_GetName(pch_header_file)), FmtStr(D_GetName(pch_cpp_file)));
|
|
||||||
AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Build step: Compile src files
|
* Build step: Compile src files
|
||||||
* ========================== */
|
* ========================== */
|
||||||
@ -1056,20 +946,21 @@ void OnBuild(StringList cli_args)
|
|||||||
if (IsDirty(obj_file)) {
|
if (IsDirty(obj_file)) {
|
||||||
String comp_cmd_fmt = is_c ? c_compile_args_fmt : cpp_compile_args_fmt;
|
String comp_cmd_fmt = is_c ? c_compile_args_fmt : cpp_compile_args_fmt;
|
||||||
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(name), FmtStr(D_GetName(obj_file)));
|
String step_name = StringF(&perm, Lit("%F -> %F"), FmtStr(name), FmtStr(D_GetName(obj_file)));
|
||||||
|
D_TagList depfile_force_includes = { 0 };
|
||||||
if (arg_msvc) {
|
if (arg_msvc) {
|
||||||
BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&perm, BuildStepMsvcCompileCommandArg);
|
BuildStepMsvcCompileCommandArg *bs_arg = ArenaPush(&perm, BuildStepMsvcCompileCommandArg);
|
||||||
bs_arg->cmd = StringF(&perm, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path));
|
bs_arg->cmd = StringF(&perm, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path));
|
||||||
bs_arg->depfile_dependent = obj_file;
|
bs_arg->depfile_dependent = obj_file;
|
||||||
bs_arg->output_depfile = dep_file;
|
bs_arg->output_depfile = dep_file;
|
||||||
bs_arg->depfile_force_includes = depfile_force_includes;
|
bs_arg->depfile_force_includes = depfile_force_includes;
|
||||||
bs_arg->skip_flag = &pch_success_flag;
|
bs_arg->skip_flag = &rc_success_flag;
|
||||||
bs_arg->failure_flag = &src_success_flag;
|
bs_arg->failure_flag = &src_success_flag;
|
||||||
bs_arg->delete_file_on_failure = obj_file;
|
bs_arg->delete_file_on_failure = obj_file;
|
||||||
AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg);
|
AddStep(step_name, &BuildStepMsvcCompileCommand, bs_arg);
|
||||||
} else {
|
} else {
|
||||||
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
|
BuildStepSimpleCommandArg *bs_arg = ArenaPush(&perm, BuildStepSimpleCommandArg);
|
||||||
bs_arg->cmd = StringF(&perm, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path));
|
bs_arg->cmd = StringF(&perm, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file.full_path));
|
||||||
bs_arg->skip_flag = &pch_success_flag;
|
bs_arg->skip_flag = &rc_success_flag;
|
||||||
bs_arg->failure_flag = &src_success_flag;
|
bs_arg->failure_flag = &src_success_flag;
|
||||||
AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
|
AddStep(step_name, &BuildStepSimpleCommand, bs_arg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "../prof/prof.h"
|
#include "../prof/prof.h"
|
||||||
|
|
||||||
|
#include "base_core.h"
|
||||||
#include "base_intrinsics.h"
|
#include "base_intrinsics.h"
|
||||||
#include "base_atomic.h"
|
#include "base_atomic.h"
|
||||||
#include "base_fiber.h"
|
#include "base_fiber.h"
|
||||||
|
|||||||
@ -678,7 +678,7 @@ INLINE f64 clamp_f64(f64 v, f64 min, f64 max) { return v < min ? min : v > max ?
|
|||||||
* Configurable constants
|
* Configurable constants
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
#include "config.h"
|
#include "../config.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -9,6 +9,7 @@
|
|||||||
#include "../inc/inc.h"
|
#include "../inc/inc.h"
|
||||||
#include "../resource/resource.h"
|
#include "../resource/resource.h"
|
||||||
#include "../watch/watch.h"
|
#include "../watch/watch.h"
|
||||||
|
#include "../kernel/kernel.h"
|
||||||
|
|
||||||
#include "gp_core.h"
|
#include "gp_core.h"
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
/* TODO: Remove this */
|
/* TODO: Remove this */
|
||||||
#include "../sprite/sprite.h"
|
#include "../sprite/sprite.h"
|
||||||
|
|
||||||
/* Include common shader types */
|
|
||||||
#define SH_CPU 1
|
|
||||||
#include "../sh/sh_common.h"
|
|
||||||
|
|
||||||
#pragma warning(push, 0)
|
#pragma warning(push, 0)
|
||||||
# define UNICODE
|
# define UNICODE
|
||||||
# define COBJMACROS
|
# define COBJMACROS
|
||||||
@ -700,7 +696,7 @@ INTERNAL void dx12_init_pipelines(void)
|
|||||||
/* Material pipeline */
|
/* Material pipeline */
|
||||||
{
|
{
|
||||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||||
desc->name = LIT("material");
|
desc->name = LIT("kernel_material");
|
||||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
desc->rtvs[0].blending = 1;
|
desc->rtvs[0].blending = 1;
|
||||||
desc->rtvs[1].format = DXGI_FORMAT_R16G16B16A16_FLOAT;
|
desc->rtvs[1].format = DXGI_FORMAT_R16G16B16A16_FLOAT;
|
||||||
@ -710,19 +706,19 @@ INTERNAL void dx12_init_pipelines(void)
|
|||||||
/* Flood pipeline */
|
/* Flood pipeline */
|
||||||
{
|
{
|
||||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||||
desc->name = LIT("flood");
|
desc->name = LIT("kernel_flood");
|
||||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||||
}
|
}
|
||||||
/* Shade pipeline */
|
/* Shade pipeline */
|
||||||
{
|
{
|
||||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||||
desc->name = LIT("shade");
|
desc->name = LIT("kernel_shade");
|
||||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||||
}
|
}
|
||||||
/* Shape pipeline */
|
/* Shape pipeline */
|
||||||
{
|
{
|
||||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||||
desc->name = LIT("shape");
|
desc->name = LIT("kernel_shape");
|
||||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
desc->rtvs[0].blending = 1;
|
desc->rtvs[0].blending = 1;
|
||||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||||
@ -730,7 +726,7 @@ INTERNAL void dx12_init_pipelines(void)
|
|||||||
/* UI pipeline */
|
/* UI pipeline */
|
||||||
{
|
{
|
||||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||||
desc->name = LIT("ui");
|
desc->name = LIT("kernel_ui");
|
||||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
desc->rtvs[0].blending = 1;
|
desc->rtvs[0].blending = 1;
|
||||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||||
@ -738,7 +734,7 @@ INTERNAL void dx12_init_pipelines(void)
|
|||||||
/* Blit pipeilne */
|
/* Blit pipeilne */
|
||||||
{
|
{
|
||||||
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
struct pipeline_desc *desc = arena_push(G.pipelines_arena, struct pipeline_desc);
|
||||||
desc->name = LIT("blit");
|
desc->name = LIT("kernel_blit");
|
||||||
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
desc->rtvs[0].format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
desc->rtvs[0].blending = 1;
|
desc->rtvs[0].blending = 1;
|
||||||
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
dict_set(G.pipelines_arena, G.pipeline_descs, hash_fnv64(HASH_FNV64_BASIS, desc->name), (u64)desc);
|
||||||
@ -795,14 +791,14 @@ INTERNAL void dx12_init_noise(void)
|
|||||||
struct string noise_res_name = LIT("noise_128x128x64_16.dat");
|
struct string noise_res_name = LIT("noise_128x128x64_16.dat");
|
||||||
struct resource noise_res = resource_open(noise_res_name);
|
struct resource noise_res = resource_open(noise_res_name);
|
||||||
DXGI_FORMAT format = DXGI_FORMAT_R16_UINT;
|
DXGI_FORMAT format = DXGI_FORMAT_R16_UINT;
|
||||||
//u32 expected_size = SH_BLUE_NOISE_TEX_WIDTH * SH_BLUE_NOISE_TEX_HEIGHT * SH_BLUE_NOISE_TEX_DEPTH * 2;
|
//u32 expected_size = K_BLUE_NOISE_TEX_WIDTH * K_BLUE_NOISE_TEX_HEIGHT * K_BLUE_NOISE_TEX_DEPTH * 2;
|
||||||
u32 expected_size = SH_BLUE_NOISE_TEX_WIDTH * SH_BLUE_NOISE_TEX_HEIGHT * SH_BLUE_NOISE_TEX_DEPTH * 2;
|
u32 expected_size = K_BLUE_NOISE_TEX_WIDTH * K_BLUE_NOISE_TEX_HEIGHT * K_BLUE_NOISE_TEX_DEPTH * 2;
|
||||||
if (resource_exists(&noise_res)) {
|
if (resource_exists(&noise_res)) {
|
||||||
struct string data = resource_get_data(&noise_res);
|
struct string data = resource_get_data(&noise_res);
|
||||||
if (data.len != expected_size) {
|
if (data.len != expected_size) {
|
||||||
sys_panic(string_format(scratch.arena,
|
sys_panic(string_format(scratch.arena,
|
||||||
LIT("Noise texture has unexpected size for a %Fx%Fx%F texture (expected %F, got %F)"),
|
LIT("Noise texture has unexpected size for a %Fx%Fx%F texture (expected %F, got %F)"),
|
||||||
FMT_UINT(SH_BLUE_NOISE_TEX_WIDTH), FMT_UINT(SH_BLUE_NOISE_TEX_HEIGHT), FMT_UINT(SH_BLUE_NOISE_TEX_DEPTH),
|
FMT_UINT(K_BLUE_NOISE_TEX_WIDTH), FMT_UINT(K_BLUE_NOISE_TEX_HEIGHT), FMT_UINT(K_BLUE_NOISE_TEX_DEPTH),
|
||||||
FMT_UINT(expected_size), FMT_UINT(data.len)));
|
FMT_UINT(expected_size), FMT_UINT(data.len)));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -818,9 +814,9 @@ INTERNAL void dx12_init_noise(void)
|
|||||||
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
desc.Format = format;
|
desc.Format = format;
|
||||||
desc.Alignment = 0;
|
desc.Alignment = 0;
|
||||||
desc.Width = SH_BLUE_NOISE_TEX_WIDTH;
|
desc.Width = K_BLUE_NOISE_TEX_WIDTH;
|
||||||
desc.Height = SH_BLUE_NOISE_TEX_HEIGHT;
|
desc.Height = K_BLUE_NOISE_TEX_HEIGHT;
|
||||||
desc.DepthOrArraySize = SH_BLUE_NOISE_TEX_DEPTH;
|
desc.DepthOrArraySize = K_BLUE_NOISE_TEX_DEPTH;
|
||||||
desc.MipLevels = 1;
|
desc.MipLevels = 1;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
desc.SampleDesc.Quality = 0;
|
desc.SampleDesc.Quality = 0;
|
||||||
@ -957,9 +953,9 @@ INTERNAL SYS_JOB_DEF(pipeline_alloc_job, job)
|
|||||||
|
|
||||||
struct string error_str = ZI;
|
struct string error_str = ZI;
|
||||||
|
|
||||||
struct string vs_dxc = desc->vs_dxc.len > 0 ? desc->vs_dxc : tar_get(&G.dxc_archive, string_cat(scratch.arena, pipeline_name, LIT(".dxc_vs")))->data;
|
struct string vs_dxc = desc->vs_dxc.len > 0 ? desc->vs_dxc : tar_get(&G.dxc_archive, string_cat(scratch.arena, pipeline_name, LIT(".vs")))->data;
|
||||||
struct string ps_dxc = desc->ps_dxc.len > 0 ? desc->ps_dxc : tar_get(&G.dxc_archive, string_cat(scratch.arena, pipeline_name, LIT(".dxc_ps")))->data;
|
struct string ps_dxc = desc->ps_dxc.len > 0 ? desc->ps_dxc : tar_get(&G.dxc_archive, string_cat(scratch.arena, pipeline_name, LIT(".ps")))->data;
|
||||||
struct string cs_dxc = desc->cs_dxc.len > 0 ? desc->cs_dxc : tar_get(&G.dxc_archive, string_cat(scratch.arena, pipeline_name, LIT(".dxc_cs")))->data;
|
struct string cs_dxc = desc->cs_dxc.len > 0 ? desc->cs_dxc : tar_get(&G.dxc_archive, string_cat(scratch.arena, pipeline_name, LIT(".cs")))->data;
|
||||||
if (success && vs_dxc.len > 0 && ps_dxc.len <= 0) {
|
if (success && vs_dxc.len > 0 && ps_dxc.len <= 0) {
|
||||||
error_str = LIT("Pipeline has vertex shader without pixel shader");
|
error_str = LIT("Pipeline has vertex shader without pixel shader");
|
||||||
success = 0;
|
success = 0;
|
||||||
@ -1318,12 +1314,12 @@ INTERNAL WATCH_CALLBACK_FUNC_DEF(pipeline_watch_callback, name)
|
|||||||
__prof;
|
__prof;
|
||||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||||
|
|
||||||
struct string rs_extension = LIT(".hlsl_rs");
|
struct string rst_extension = LIT(".rst");
|
||||||
struct string cs_extension = LIT(".hlsl_cs");
|
struct string knl_extension = LIT(".knl");
|
||||||
|
|
||||||
b32 is_src = string_starts_with(name, LIT("src/"));
|
b32 is_src = string_starts_with(name, LIT("src/"));
|
||||||
b32 is_rs = is_src && string_ends_with(name, rs_extension);
|
b32 is_rs = is_src && string_ends_with(name, rst_extension);
|
||||||
b32 is_cs = is_src && !is_rs && string_ends_with(name, cs_extension);
|
b32 is_cs = is_src && !is_rs && string_ends_with(name, knl_extension);
|
||||||
b32 success = 0;
|
b32 success = 0;
|
||||||
|
|
||||||
/* Recompile shaders */
|
/* Recompile shaders */
|
||||||
@ -2662,14 +2658,14 @@ u32 gp_push_render_cmd(struct gp_render_sig *render_sig, struct gp_render_cmd_de
|
|||||||
case GP_RENDER_CMD_KIND_DRAW_UI_SHAPE:
|
case GP_RENDER_CMD_KIND_DRAW_UI_SHAPE:
|
||||||
{
|
{
|
||||||
u32 color = cmd_desc->ui_shape.color;
|
u32 color = cmd_desc->ui_shape.color;
|
||||||
struct sh_shape_vert *verts = arena_push_array_no_zero(sig->ui_shape_verts_arena, struct sh_shape_vert, cmd_desc->ui_shape.vertices.count);
|
struct k_shape_vert *verts = arena_push_array_no_zero(sig->ui_shape_verts_arena, struct k_shape_vert, cmd_desc->ui_shape.vertices.count);
|
||||||
u32 *indices = arena_push_array_no_zero(sig->ui_shape_indices_arena, u32, cmd_desc->ui_shape.indices.count);
|
u32 *indices = arena_push_array_no_zero(sig->ui_shape_indices_arena, u32, cmd_desc->ui_shape.indices.count);
|
||||||
for (u32 i = 0; i < cmd_desc->ui_shape.vertices.count; ++i) {
|
for (u32 i = 0; i < cmd_desc->ui_shape.vertices.count; ++i) {
|
||||||
struct sh_shape_vert *v = &verts[i];
|
struct k_shape_vert *v = &verts[i];
|
||||||
v->pos = sh_float2_from_v2(cmd_desc->ui_shape.vertices.points[i]);
|
v->pos = k_float2_from_v2(cmd_desc->ui_shape.vertices.points[i]);
|
||||||
v->color_srgb = sh_uint_from_u32(color);
|
v->color_srgb = k_uint_from_u32(color);
|
||||||
}
|
}
|
||||||
u32 vert_offset = verts - (struct sh_shape_vert *)arena_base(sig->ui_shape_verts_arena);
|
u32 vert_offset = verts - (struct k_shape_vert *)arena_base(sig->ui_shape_verts_arena);
|
||||||
for (u32 i = 0; i < cmd_desc->ui_shape.indices.count; ++i) {
|
for (u32 i = 0; i < cmd_desc->ui_shape.indices.count; ++i) {
|
||||||
indices[i] = cmd_desc->ui_shape.indices.indices[i] + vert_offset;
|
indices[i] = cmd_desc->ui_shape.indices.indices[i] + vert_offset;
|
||||||
}
|
}
|
||||||
@ -2745,12 +2741,12 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
|
|
||||||
struct sprite_scope *sprite_scope = sprite_scope_begin();
|
struct sprite_scope *sprite_scope = sprite_scope_begin();
|
||||||
struct pipeline_scope *pipeline_scope = pipeline_scope_begin();
|
struct pipeline_scope *pipeline_scope = pipeline_scope_begin();
|
||||||
struct pipeline *material_pipeline = pipeline_from_name(pipeline_scope, LIT("material"));
|
struct pipeline *material_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_material"));
|
||||||
struct pipeline *flood_pipeline = pipeline_from_name(pipeline_scope, LIT("flood"));
|
struct pipeline *flood_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_flood"));
|
||||||
struct pipeline *shade_pipeline = pipeline_from_name(pipeline_scope, LIT("shade"));
|
struct pipeline *shade_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_shade"));
|
||||||
struct pipeline *blit_pipeline = pipeline_from_name(pipeline_scope, LIT("blit"));
|
struct pipeline *blit_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_blit"));
|
||||||
struct pipeline *ui_pipeline = pipeline_from_name(pipeline_scope, LIT("ui"));
|
struct pipeline *ui_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_ui"));
|
||||||
struct pipeline *shape_pipeline = pipeline_from_name(pipeline_scope, LIT("shape"));
|
struct pipeline *shape_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_shape"));
|
||||||
struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT];
|
struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT];
|
||||||
struct command_list *cl = command_list_open(cq->cl_pool);
|
struct command_list *cl = command_list_open(cq->cl_pool);
|
||||||
{
|
{
|
||||||
@ -2774,9 +2770,9 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
struct command_buffer *quad_index_buffer = command_list_push_buffer(cl, countof(quad_indices), 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, rsig->num_material_instance_descs);
|
struct k_material_instance *material_instances = arena_push_array_no_zero(scratch.arena, struct k_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, rsig->num_ui_rect_instance_descs);
|
struct k_ui_instance *ui_rect_instances = arena_push_array_no_zero(scratch.arena, struct k_ui_instance, rsig->num_ui_rect_instance_descs);
|
||||||
struct sh_material_grid *grids = arena_push_array_no_zero(scratch.arena, struct sh_material_grid, rsig->num_material_grid_descs);
|
struct k_material_grid *grids = arena_push_array_no_zero(scratch.arena, struct k_material_grid, rsig->num_material_grid_descs);
|
||||||
{
|
{
|
||||||
__profn("Process sig data");
|
__profn("Process sig data");
|
||||||
|
|
||||||
@ -2785,7 +2781,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
__profn("Process material instances");
|
__profn("Process material instances");
|
||||||
for (u32 i = 0; i < rsig->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(rsig->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 k_material_instance *instance = &material_instances[i];
|
||||||
u32 texture_id = 0xFFFFFFFF;
|
u32 texture_id = 0xFFFFFFFF;
|
||||||
if (desc->texture != 0) {
|
if (desc->texture != 0) {
|
||||||
texture_id = desc->texture->srv_descriptor->index;
|
texture_id = desc->texture->srv_descriptor->index;
|
||||||
@ -2796,14 +2792,14 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
texture_id = texture->srv_descriptor->index;
|
texture_id = texture->srv_descriptor->index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance->tex_nurid = sh_uint_from_u32(texture_id);
|
instance->tex_nurid = k_uint_from_u32(texture_id);
|
||||||
instance->grid_id = sh_uint_from_u32(desc->grid_id);
|
instance->grid_id = k_uint_from_u32(desc->grid_id);
|
||||||
instance->xf = sh_float2x3_from_xform(desc->xf);
|
instance->xf = k_float2x3_from_xform(desc->xf);
|
||||||
instance->uv0 = sh_float2_from_v2(desc->clip.p0);
|
instance->uv0 = k_float2_from_v2(desc->clip.p0);
|
||||||
instance->uv1 = sh_float2_from_v2(desc->clip.p1);
|
instance->uv1 = k_float2_from_v2(desc->clip.p1);
|
||||||
instance->tint_srgb = sh_uint_from_u32(desc->tint);
|
instance->tint_srgb = k_uint_from_u32(desc->tint);
|
||||||
instance->is_light = sh_uint_from_u32(desc->is_light);
|
instance->is_light = k_uint_from_u32(desc->is_light);
|
||||||
instance->light_emittance_srgb = sh_float3_from_v3(desc->light_emittance);
|
instance->light_emittance_srgb = k_float3_from_v3(desc->light_emittance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2812,7 +2808,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
__profn("Process ui rect instances");
|
__profn("Process ui rect instances");
|
||||||
for (u32 i = 0; i < rsig->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(rsig->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 k_ui_instance *instance = &ui_rect_instances[i];
|
||||||
u32 texture_id = 0xFFFFFFFF;
|
u32 texture_id = 0xFFFFFFFF;
|
||||||
if (desc->texture != 0) {
|
if (desc->texture != 0) {
|
||||||
texture_id = desc->texture->srv_descriptor->index;
|
texture_id = desc->texture->srv_descriptor->index;
|
||||||
@ -2823,11 +2819,11 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
texture_id = texture->srv_descriptor->index;
|
texture_id = texture->srv_descriptor->index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance->tex_nurid = sh_uint_from_u32(texture_id);
|
instance->tex_nurid = k_uint_from_u32(texture_id);
|
||||||
instance->xf = sh_float2x3_from_xform(desc->xf);
|
instance->xf = k_float2x3_from_xform(desc->xf);
|
||||||
instance->uv0 = sh_float2_from_v2(desc->clip.p0);
|
instance->uv0 = k_float2_from_v2(desc->clip.p0);
|
||||||
instance->uv1 = sh_float2_from_v2(desc->clip.p1);
|
instance->uv1 = k_float2_from_v2(desc->clip.p1);
|
||||||
instance->tint_srgb = sh_uint_from_u32(desc->tint);
|
instance->tint_srgb = k_uint_from_u32(desc->tint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2836,25 +2832,25 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
__profn("Process grids");
|
__profn("Process grids");
|
||||||
for (u32 i = 0; i < rsig->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(rsig->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 k_material_grid *grid = &grids[i];
|
||||||
grid->line_thickness = sh_float_from_f32(desc->line_thickness);
|
grid->line_thickness = k_float_from_f32(desc->line_thickness);
|
||||||
grid->line_spacing = sh_float_from_f32(desc->line_spacing);
|
grid->line_spacing = k_float_from_f32(desc->line_spacing);
|
||||||
grid->offset = sh_float2_from_v2(desc->offset);
|
grid->offset = k_float2_from_v2(desc->offset);
|
||||||
grid->bg0_srgb = sh_uint_from_u32(desc->bg0_color);
|
grid->bg0_srgb = k_uint_from_u32(desc->bg0_color);
|
||||||
grid->bg1_srgb = sh_uint_from_u32(desc->bg1_color);
|
grid->bg1_srgb = k_uint_from_u32(desc->bg1_color);
|
||||||
grid->line_srgb = sh_uint_from_u32(desc->line_color);
|
grid->line_srgb = k_uint_from_u32(desc->line_color);
|
||||||
grid->x_srgb = sh_uint_from_u32(desc->x_color);
|
grid->x_srgb = k_uint_from_u32(desc->x_color);
|
||||||
grid->y_srgb = sh_uint_from_u32(desc->y_color);
|
grid->y_srgb = k_uint_from_u32(desc->y_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Upload buffers */
|
/* Upload buffers */
|
||||||
u64 num_ui_shape_verts = rsig->ui_shape_verts_arena->pos / sizeof(struct sh_shape_vert);
|
u64 num_ui_shape_verts = rsig->ui_shape_verts_arena->pos / sizeof(struct k_shape_vert);
|
||||||
u64 num_ui_shape_indices = rsig->ui_shape_indices_arena->pos / sizeof(u32);
|
u64 num_ui_shape_indices = rsig->ui_shape_indices_arena->pos / sizeof(u32);
|
||||||
struct command_buffer *material_instance_buffer = command_list_push_buffer(cl, rsig->num_material_instance_descs, material_instances);
|
struct command_buffer *material_instance_buffer = command_list_push_buffer(cl, rsig->num_material_instance_descs, material_instances);
|
||||||
struct command_buffer *ui_rect_instance_buffer = command_list_push_buffer(cl, rsig->num_ui_rect_instance_descs, ui_rect_instances);
|
struct command_buffer *ui_rect_instance_buffer = command_list_push_buffer(cl, rsig->num_ui_rect_instance_descs, ui_rect_instances);
|
||||||
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_verts_buffer = command_list_push_buffer(cl, num_ui_shape_verts, (struct k_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, (u32 *)arena_base(rsig->ui_shape_indices_arena));
|
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u32 *)arena_base(rsig->ui_shape_indices_arena));
|
||||||
struct command_buffer *grid_buffer = command_list_push_buffer(cl, rsig->num_material_grid_descs, grids);
|
struct command_buffer *grid_buffer = command_list_push_buffer(cl, rsig->num_material_grid_descs, grids);
|
||||||
|
|
||||||
@ -2903,14 +2899,14 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct sh_material_sig sig = ZI;
|
struct k_material_sig sig = ZI;
|
||||||
sig.projection = sh_float4x4_from_mat4x4(world_to_render_vp_matrix);
|
sig.projection = k_float4x4_from_mat4x4(world_to_render_vp_matrix);
|
||||||
sig.instances_urid = sh_uint_from_u32(material_instance_buffer->resource->srv_descriptor->index);
|
sig.instances_urid = k_uint_from_u32(material_instance_buffer->resource->srv_descriptor->index);
|
||||||
sig.grids_urid = sh_uint_from_u32(grid_buffer->resource->srv_descriptor->index);
|
sig.grids_urid = k_uint_from_u32(grid_buffer->resource->srv_descriptor->index);
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
u32 instance_count = material_instance_buffer->size / sizeof(struct sh_material_instance);
|
u32 instance_count = material_instance_buffer->size / sizeof(struct k_material_instance);
|
||||||
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);
|
||||||
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(quad_index_buffer, DXGI_FORMAT_R16_UINT);
|
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(quad_index_buffer, DXGI_FORMAT_R16_UINT);
|
||||||
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
@ -2961,13 +2957,13 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct sh_flood_sig sig = ZI;
|
struct k_flood_sig sig = ZI;
|
||||||
sig.step_len = sh_int_from_i32(step_length);
|
sig.step_len = k_int_from_i32(step_length);
|
||||||
sig.emittance_tex_urid = sh_uint_from_u32(rsig->emittance->srv_descriptor->index);
|
sig.emittance_tex_urid = k_uint_from_u32(rsig->emittance->srv_descriptor->index);
|
||||||
sig.read_flood_tex_urid = sh_uint_from_u32(rsig->emittance_flood_read->uav_descriptor->index);
|
sig.read_flood_tex_urid = k_uint_from_u32(rsig->emittance_flood_read->uav_descriptor->index);
|
||||||
sig.target_flood_tex_urid = sh_uint_from_u32(rsig->emittance_flood_target->uav_descriptor->index);
|
sig.target_flood_tex_urid = k_uint_from_u32(rsig->emittance_flood_target->uav_descriptor->index);
|
||||||
sig.tex_width = sh_uint_from_u32(render_size.x);
|
sig.tex_width = k_uint_from_u32(render_size.x);
|
||||||
sig.tex_height = sh_uint_from_u32(render_size.y);
|
sig.tex_height = k_uint_from_u32(render_size.y);
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Dispatch */
|
/* Dispatch */
|
||||||
@ -3023,27 +3019,27 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
/* Bind pipeline */
|
/* Bind pipeline */
|
||||||
command_list_set_pipeline(cl, shade_pipeline);
|
command_list_set_pipeline(cl, shade_pipeline);
|
||||||
|
|
||||||
u32 shade_flags = SH_SHADE_FLAG_NONE;
|
u32 shade_flags = K_SHADE_FLAG_NONE;
|
||||||
if (params.effects_disabled) {
|
if (params.effects_disabled) {
|
||||||
shade_flags |= SH_SHADE_FLAG_DISABLE_EFFECTS;
|
shade_flags |= K_SHADE_FLAG_DISABLE_EFFECTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct sh_shade_sig sig = ZI;
|
struct k_shade_sig sig = ZI;
|
||||||
sig.flags = sh_uint_from_u32(shade_flags);
|
sig.flags = k_uint_from_u32(shade_flags);
|
||||||
sig.tex_width = sh_uint_from_u32(render_size.x);
|
sig.tex_width = k_uint_from_u32(render_size.x);
|
||||||
sig.tex_height = sh_uint_from_u32(render_size.y);
|
sig.tex_height = k_uint_from_u32(render_size.y);
|
||||||
sig.frame_seed = sh_uint4_from_u32((u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
sig.frame_seed = k_uint4_from_u32((u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF));
|
(u32)(rand_u64_from_state(&rsig->rand) & 0xFFFFFFFF));
|
||||||
sig.frame_index = sh_uint_from_u32(rsig->frame_index);
|
sig.frame_index = k_uint_from_u32(rsig->frame_index);
|
||||||
sig.camera_offset = sh_float2_from_v2(world_to_render_xf.og);
|
sig.camera_offset = k_float2_from_v2(world_to_render_xf.og);
|
||||||
sig.albedo_tex_urid = sh_uint_from_u32(rsig->albedo->srv_descriptor->index);
|
sig.albedo_tex_urid = k_uint_from_u32(rsig->albedo->srv_descriptor->index);
|
||||||
sig.emittance_tex_urid = sh_uint_from_u32(rsig->emittance->srv_descriptor->index);
|
sig.emittance_tex_urid = k_uint_from_u32(rsig->emittance->srv_descriptor->index);
|
||||||
sig.emittance_flood_tex_urid = sh_uint_from_u32(rsig->emittance_flood_read->srv_descriptor->index);
|
sig.emittance_flood_tex_urid = k_uint_from_u32(rsig->emittance_flood_read->srv_descriptor->index);
|
||||||
sig.read_tex_urid = sh_uint_from_u32(rsig->shade_read->uav_descriptor->index);
|
sig.read_tex_urid = k_uint_from_u32(rsig->shade_read->uav_descriptor->index);
|
||||||
sig.target_tex_urid = sh_uint_from_u32(rsig->shade_target->uav_descriptor->index);
|
sig.target_tex_urid = k_uint_from_u32(rsig->shade_target->uav_descriptor->index);
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Dispatch */
|
/* Dispatch */
|
||||||
@ -3091,12 +3087,12 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct sh_blit_sig sig = ZI;
|
struct k_blit_sig sig = ZI;
|
||||||
sig.projection = sh_float4x4_from_mat4x4(blit_vp_matrix);
|
sig.projection = k_float4x4_from_mat4x4(blit_vp_matrix);
|
||||||
sig.flags = sh_uint_from_u32(SH_BLIT_FLAG_TONE_MAP | SH_BLIT_FLAG_GAMMA_CORRECT);
|
sig.flags = k_uint_from_u32(K_BLIT_FLAG_TONE_MAP | K_BLIT_FLAG_GAMMA_CORRECT);
|
||||||
sig.exposure = sh_float_from_f32(2.0);
|
sig.exposure = k_float_from_f32(2.0);
|
||||||
sig.gamma = sh_float_from_f32((f32)2.2);
|
sig.gamma = k_float_from_f32((f32)2.2);
|
||||||
sig.tex_urid = sh_uint_from_u32(rsig->shade_read->uav_descriptor->index);
|
sig.tex_urid = k_uint_from_u32(rsig->shade_read->uav_descriptor->index);
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
@ -3123,13 +3119,13 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct sh_ui_sig sig = ZI;
|
struct k_ui_sig sig = ZI;
|
||||||
sig.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
sig.projection = k_float4x4_from_mat4x4(ui_vp_matrix);
|
||||||
sig.instances_urid = sh_uint_from_u32(ui_rect_instance_buffer->resource->srv_descriptor->index);
|
sig.instances_urid = k_uint_from_u32(ui_rect_instance_buffer->resource->srv_descriptor->index);
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* 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 k_ui_instance);
|
||||||
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);
|
||||||
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(quad_index_buffer, DXGI_FORMAT_R16_UINT);
|
D3D12_INDEX_BUFFER_VIEW ibv = ibv_from_command_buffer(quad_index_buffer, DXGI_FORMAT_R16_UINT);
|
||||||
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
ID3D12GraphicsCommandList_IASetPrimitiveTopology(cl->cl, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
@ -3153,9 +3149,9 @@ struct gp_resource *gp_run_render(struct gp_render_sig *gp_render_sig, struct gp
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct sh_shape_sig sig = ZI;
|
struct k_shape_sig sig = ZI;
|
||||||
sig.projection = sh_float4x4_from_mat4x4(ui_vp_matrix);
|
sig.projection = k_float4x4_from_mat4x4(ui_vp_matrix);
|
||||||
sig.verts_urid = sh_uint_from_u32(ui_shape_verts_buffer->resource->srv_descriptor->index);
|
sig.verts_urid = k_uint_from_u32(ui_shape_verts_buffer->resource->srv_descriptor->index);
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
@ -3370,7 +3366,7 @@ INTERNAL void present_blit(struct swapchain_buffer *dst, struct dx12_resource *s
|
|||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
struct pipeline_scope *pipeline_scope = pipeline_scope_begin();
|
struct pipeline_scope *pipeline_scope = pipeline_scope_begin();
|
||||||
struct pipeline *blit_pipeline = pipeline_from_name(pipeline_scope, LIT("blit"));
|
struct pipeline *blit_pipeline = pipeline_from_name(pipeline_scope, LIT("kernel_blit"));
|
||||||
if (blit_pipeline->success) {
|
if (blit_pipeline->success) {
|
||||||
struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT];
|
struct command_queue *cq = G.command_queues[DX12_QUEUE_DIRECT];
|
||||||
struct command_list *cl = command_list_open(cq->cl_pool);
|
struct command_list *cl = command_list_open(cq->cl_pool);
|
||||||
@ -3431,10 +3427,10 @@ INTERNAL void present_blit(struct swapchain_buffer *dst, struct dx12_resource *s
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct sh_blit_sig sig = ZI;
|
struct k_blit_sig sig = ZI;
|
||||||
sig.projection = sh_float4x4_from_mat4x4(vp_matrix);
|
sig.projection = k_float4x4_from_mat4x4(vp_matrix);
|
||||||
sig.flags = sh_uint_from_u32(SH_BLIT_FLAG_NONE);
|
sig.flags = k_uint_from_u32(K_BLIT_FLAG_NONE);
|
||||||
sig.tex_urid = sh_uint_from_u32(src->srv_descriptor->index);
|
sig.tex_urid = k_uint_from_u32(src->srv_descriptor->index);
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
|
|||||||
6
src/kernel/kernel.h
Normal file
6
src/kernel/kernel.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef KERNEL_H
|
||||||
|
#define KERNEL_H
|
||||||
|
|
||||||
|
#include "kernel_core.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "sh/common.hlsl"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct sh_blit_sig> sig : register(b0);
|
ConstantBuffer<struct k_blit_sig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -15,7 +15,7 @@ struct vs_output {
|
|||||||
DECLS(float2, uv);
|
DECLS(float2, uv);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct vs_output vs(struct vs_input input)
|
K_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),
|
||||||
@ -38,7 +38,7 @@ SH_ENTRY struct vs_output vs(struct vs_input input)
|
|||||||
|
|
||||||
/* ACES approximation by Krzysztof Narkowicz
|
/* ACES approximation by Krzysztof Narkowicz
|
||||||
* https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ */
|
* https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ */
|
||||||
INLINE float3 tone_map(float3 v)
|
float3 tone_map(float3 v)
|
||||||
{
|
{
|
||||||
return saturate((v * (2.51f * v + 0.03f)) / (v * (2.43f * v + 0.59f) + 0.14f));
|
return saturate((v * (2.51f * v + 0.03f)) / (v * (2.43f * v + 0.59f) + 0.14f));
|
||||||
}
|
}
|
||||||
@ -55,21 +55,21 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target);
|
DECLS(float4, SV_Target);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct ps_output ps(struct ps_input input)
|
K_ENTRY struct ps_output ps(struct ps_input input)
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
struct ps_output output;
|
||||||
Texture2D<float4> tex = resource_from_urid(sig.tex_urid);
|
Texture2D<float4> tex = resource_from_urid(sig.tex_urid);
|
||||||
float4 color = tex.Sample(s_point_clamp, input.vs.uv);
|
float4 color = tex.Sample(s_point_clamp, input.vs.uv);
|
||||||
|
|
||||||
/* Apply tone map */
|
/* Apply tone map */
|
||||||
if (sig.flags & SH_BLIT_FLAG_TONE_MAP) {
|
if (sig.flags & K_BLIT_FLAG_TONE_MAP) {
|
||||||
/* TODO: Dynamic exposure based on average scene luminance */
|
/* TODO: Dynamic exposure based on average scene luminance */
|
||||||
color.rgb *= sig.exposure;
|
color.rgb *= sig.exposure;
|
||||||
color.rgb = tone_map(color.rgb);
|
color.rgb = tone_map(color.rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply gamma correction */
|
/* Apply gamma correction */
|
||||||
if (sig.flags & SH_BLIT_FLAG_GAMMA_CORRECT) {
|
if (sig.flags & K_BLIT_FLAG_GAMMA_CORRECT) {
|
||||||
color = pow(abs(color), 1/sig.gamma);
|
color = pow(abs(color), 1/sig.gamma);
|
||||||
}
|
}
|
||||||
|
|
||||||
305
src/kernel/kernel_core.h
Normal file
305
src/kernel/kernel_core.h
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
/* Determine if file was included from C or from HLSL */
|
||||||
|
#if defined(LANGUAGE_C) || defined(LANGUAGE_CPP)
|
||||||
|
# define K_IS_CPU 1
|
||||||
|
#else
|
||||||
|
# define K_IS_CPU 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if K_IS_CPU
|
||||||
|
|
||||||
|
#define K_STRUCT(s) PACK(struct s)
|
||||||
|
#define K_DECL(t, n) struct CAT(k_, t) n
|
||||||
|
#define K_DECLS(t, n) K_DECL(t, n)
|
||||||
|
#define K_STATIC_ASSERT(c) STATIC_ASSERT(c)
|
||||||
|
|
||||||
|
struct k_uint { u32 v; };
|
||||||
|
INLINE struct k_uint k_uint_from_u32(u32 v)
|
||||||
|
{
|
||||||
|
return (struct k_uint) { .v = v };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_int { i32 v; };
|
||||||
|
INLINE struct k_int k_int_from_i32(i32 v)
|
||||||
|
{
|
||||||
|
return (struct k_int) { .v = v };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_uint2 { u32 v[2]; };
|
||||||
|
INLINE struct k_uint2 k_uint2_from_u32(u32 x, u32 y)
|
||||||
|
{
|
||||||
|
return (struct k_uint2) { .v[0] = x, .v[1] = y };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_uint3 { u32 v[3]; };
|
||||||
|
INLINE struct k_uint3 k_uint3_from_u32(u32 x, u32 y, u32 z)
|
||||||
|
{
|
||||||
|
return (struct k_uint3) { .v[0] = x, .v[1] = y, .v[2] = z };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_uint4 { u32 v[4]; };
|
||||||
|
INLINE struct k_uint4 k_uint4_from_u32(u32 x, u32 y, u32 z, u32 w)
|
||||||
|
{
|
||||||
|
return (struct k_uint4) { .v[0] = x, .v[1] = y, .v[2] = z, .v[3] = w };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_float { f32 v; };
|
||||||
|
INLINE struct k_float k_float_from_f32(f32 v)
|
||||||
|
{
|
||||||
|
return (struct k_float) { .v = v };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_float2 { f32 v[2]; };
|
||||||
|
INLINE struct k_float2 k_float2_from_v2(struct v2 v)
|
||||||
|
{
|
||||||
|
return (struct k_float2) { .v[0] = v.x, .v[1] = v.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_float3 { f32 v[3]; };
|
||||||
|
INLINE struct k_float3 k_float3_from_v3(struct v3 v)
|
||||||
|
{
|
||||||
|
return (struct k_float3) { .v[0] = v.x, .v[1] = v.y, .v[2] = v.z };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_float4x4 { f32 v[4][4]; };
|
||||||
|
INLINE struct k_float4x4 k_float4x4_from_mat4x4(struct mat4x4 v)
|
||||||
|
{
|
||||||
|
struct k_float4x4 res;
|
||||||
|
STATIC_ASSERT(sizeof(res) == sizeof(v));
|
||||||
|
MEMCPY(&res, v.e, sizeof(res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct k_float2x3 { f32 v[2][3]; };
|
||||||
|
INLINE struct k_float2x3 k_float2x3_from_xform(struct xform v)
|
||||||
|
{
|
||||||
|
struct k_float2x3 res;
|
||||||
|
STATIC_ASSERT(sizeof(res) == sizeof(v));
|
||||||
|
MEMCPY(&res, &v, sizeof(res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define K_STRUCT(s) struct s
|
||||||
|
#define K_DECL(t, n) t n
|
||||||
|
#define K_DECLS(t, n) t n : n
|
||||||
|
#define K_STATIC_ASSERT(c) _Static_assert(c, "")
|
||||||
|
|
||||||
|
#define DECLS(t, n) t n : n
|
||||||
|
|
||||||
|
#define TAU 6.28318530718
|
||||||
|
#define PI 3.14159265359
|
||||||
|
#define GOLDEN 1.61803398875
|
||||||
|
|
||||||
|
|
||||||
|
#define resource_from_urid(urid) ResourceDescriptorHeap[urid]
|
||||||
|
#define resource_from_nurid(nurid) ResourceDescriptorHeap[NonUniformResourceIndex(nurid)]
|
||||||
|
|
||||||
|
float4 float4_from_uint_norm(uint v)
|
||||||
|
{
|
||||||
|
float4 res;
|
||||||
|
res.r = ((v >> 0) & 0xFF) / 255.0;
|
||||||
|
res.g = ((v >> 8) & 0xFF) / 255.0;
|
||||||
|
res.b = ((v >> 16) & 0xFF) / 255.0;
|
||||||
|
res.a = ((v >> 24) & 0xFF) / 255.0;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Linear color from normalized sRGB */
|
||||||
|
float4 linear_from_srgb(float4 srgb)
|
||||||
|
{
|
||||||
|
return float4(pow(abs(srgb.rgb), 2.2), srgb.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Linear color from R8G8B8A8 sRGB */
|
||||||
|
float4 linear_from_srgb32(uint srgb32)
|
||||||
|
{
|
||||||
|
return linear_from_srgb(float4_from_uint_norm(srgb32));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Root signature
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
#define K_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 K_ENTRY [RootSignature(K_ROOTSIG)]
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define K_ASSERT_ROOT_CONST(s, n) K_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 */
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Global textures
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
/* Blue noise */
|
||||||
|
#define K_BLUE_NOISE_TEX_ID 0
|
||||||
|
#define K_BLUE_NOISE_TEX_WIDTH 128
|
||||||
|
#define K_BLUE_NOISE_TEX_HEIGHT 128
|
||||||
|
#define K_BLUE_NOISE_TEX_DEPTH 64
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Material shader structs
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
K_STRUCT(k_material_sig {
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(float4x4, projection); /* 16 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint, instances_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, grids_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
||||||
|
K_DECL(uint, _pad1); /* 01 consts (padding) */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
});
|
||||||
|
K_ASSERT_ROOT_CONST(struct k_material_sig, 20);
|
||||||
|
|
||||||
|
K_STRUCT(k_material_instance {
|
||||||
|
K_DECL(uint, tex_nurid);
|
||||||
|
K_DECL(uint, grid_id);
|
||||||
|
K_DECL(float2x3, xf);
|
||||||
|
K_DECL(float2, uv0);
|
||||||
|
K_DECL(float2, uv1);
|
||||||
|
K_DECL(uint, tint_srgb);
|
||||||
|
K_DECL(uint, is_light);
|
||||||
|
K_DECL(float3, light_emittance_srgb);
|
||||||
|
});
|
||||||
|
|
||||||
|
K_STRUCT(k_material_grid {
|
||||||
|
K_DECL(float, line_thickness);
|
||||||
|
K_DECL(float, line_spacing);
|
||||||
|
K_DECL(float2, offset);
|
||||||
|
K_DECL(uint, bg0_srgb);
|
||||||
|
K_DECL(uint, bg1_srgb);
|
||||||
|
K_DECL(uint, line_srgb);
|
||||||
|
K_DECL(uint, x_srgb);
|
||||||
|
K_DECL(uint, y_srgb);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Flood shader structs
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
K_STRUCT(k_flood_sig {
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(int, step_len); /* 01 consts */
|
||||||
|
K_DECL(uint, emittance_tex_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, read_flood_tex_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, target_flood_tex_urid); /* 01 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint, tex_width); /* 01 consts */
|
||||||
|
K_DECL(uint, tex_height); /* 01 consts */
|
||||||
|
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
||||||
|
K_DECL(uint, _pad1); /* 01 consts (padding) */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
});
|
||||||
|
K_ASSERT_ROOT_CONST(struct k_flood_sig, 8);
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Shade shader structs
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
#define K_SHADE_FLAG_NONE (0 << 0)
|
||||||
|
#define K_SHADE_FLAG_DISABLE_EFFECTS (1 << 0)
|
||||||
|
|
||||||
|
K_STRUCT(k_shade_sig {
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint4, frame_seed); /* 04 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint, flags); /* 01 consts */
|
||||||
|
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
||||||
|
K_DECL(uint, tex_width); /* 01 consts */
|
||||||
|
K_DECL(uint, tex_height); /* 01 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(float2, camera_offset); /* 02 consts */
|
||||||
|
K_DECL(uint, frame_index); /* 01 consts */
|
||||||
|
K_DECL(uint, albedo_tex_urid); /* 01 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint, emittance_tex_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, emittance_flood_tex_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, read_tex_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, target_tex_urid); /* 01 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
});
|
||||||
|
K_ASSERT_ROOT_CONST(struct k_shade_sig, 16);
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Shape shader structs
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
K_STRUCT(k_shape_sig {
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(float4x4, projection); /* 16 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint, verts_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
||||||
|
K_DECL(uint, _pad1); /* 01 consts (padding) */
|
||||||
|
K_DECL(uint, _pad2); /* 01 consts (padding) */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
});
|
||||||
|
K_ASSERT_ROOT_CONST(struct k_shape_sig, 20);
|
||||||
|
|
||||||
|
K_STRUCT(k_shape_vert {
|
||||||
|
K_DECL(float2, pos);
|
||||||
|
K_DECL(uint, color_srgb);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* UI shader structs
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
K_STRUCT(k_ui_sig {
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(float4x4, projection); /* 16 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint, instances_urid); /* 01 consts */
|
||||||
|
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
||||||
|
K_DECL(uint, _pad1); /* 01 consts (padding) */
|
||||||
|
K_DECL(uint, _pad2); /* 01 consts (padding) */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
});
|
||||||
|
K_ASSERT_ROOT_CONST(struct k_ui_sig, 20);
|
||||||
|
|
||||||
|
K_STRUCT(k_ui_instance {
|
||||||
|
K_DECL(uint, tex_nurid);
|
||||||
|
K_DECL(uint, grid_id);
|
||||||
|
K_DECL(float2x3, xf);
|
||||||
|
K_DECL(float2, uv0);
|
||||||
|
K_DECL(float2, uv1);
|
||||||
|
K_DECL(uint, tint_srgb);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ========================== *
|
||||||
|
* Blit shader structs
|
||||||
|
* ========================== */
|
||||||
|
|
||||||
|
#define K_BLIT_FLAG_NONE (0 << 0)
|
||||||
|
#define K_BLIT_FLAG_TONE_MAP (1 << 0)
|
||||||
|
#define K_BLIT_FLAG_GAMMA_CORRECT (1 << 1)
|
||||||
|
|
||||||
|
K_STRUCT(k_blit_sig {
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(float4x4, projection); /* 16 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
K_DECL(uint, flags); /* 01 consts */
|
||||||
|
K_DECL(uint, tex_urid); /* 01 consts */
|
||||||
|
K_DECL(float, exposure); /* 01 consts */
|
||||||
|
K_DECL(float, gamma); /* 01 consts */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
});
|
||||||
|
K_ASSERT_ROOT_CONST(struct k_blit_sig, 20);
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "sh/common.hlsl"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct sh_flood_sig> sig : register(b0);
|
ConstantBuffer<struct k_flood_sig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Entry point
|
* Entry point
|
||||||
@ -11,7 +11,7 @@ struct cs_input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
[numthreads(8, 8, 1)]
|
||||||
SH_ENTRY void cs(struct cs_input input)
|
K_ENTRY void cs(struct cs_input input)
|
||||||
{
|
{
|
||||||
uint2 id = input.SV_DispatchThreadID.xy;
|
uint2 id = input.SV_DispatchThreadID.xy;
|
||||||
uint2 tex_size = uint2(sig.tex_width, sig.tex_height);
|
uint2 tex_size = uint2(sig.tex_width, sig.tex_height);
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "sh/common.hlsl"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct sh_material_sig> sig : register(b0);
|
ConstantBuffer<struct k_material_sig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -20,7 +20,7 @@ struct vs_output {
|
|||||||
DECLS(float4, SV_Position);
|
DECLS(float4, SV_Position);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct vs_output vs(struct vs_input input)
|
K_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),
|
||||||
@ -28,8 +28,8 @@ SH_ENTRY 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);
|
StructuredBuffer<struct k_material_instance> instances = resource_from_urid(sig.instances_urid);
|
||||||
struct sh_material_instance instance = instances[input.SV_InstanceID];
|
struct k_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;
|
||||||
@ -55,7 +55,7 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target1); /* Emittance */
|
DECLS(float4, SV_Target1); /* Emittance */
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct ps_output ps(struct ps_input input)
|
K_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;
|
||||||
@ -68,8 +68,8 @@ SH_ENTRY struct ps_output ps(struct ps_input input)
|
|||||||
|
|
||||||
/* Grid */
|
/* Grid */
|
||||||
if (input.vs.grid_id < 0xFFFFFFFF) {
|
if (input.vs.grid_id < 0xFFFFFFFF) {
|
||||||
StructuredBuffer<struct sh_material_grid> grids = resource_from_urid(sig.grids_urid);
|
StructuredBuffer<struct k_material_grid> grids = resource_from_urid(sig.grids_urid);
|
||||||
struct sh_material_grid grid = grids[input.vs.grid_id];
|
struct k_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;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "sh/common.hlsl"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct sh_shade_sig> sig : register(b0);
|
ConstantBuffer<struct k_shade_sig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Lighting
|
* Lighting
|
||||||
@ -11,18 +11,18 @@ ConstantBuffer<struct sh_shade_sig> sig : register(b0);
|
|||||||
#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 = resource_from_urid(SH_BLUE_NOISE_TEX_ID);
|
Texture3D<uint> noise_tex = resource_from_urid(K_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 += sig.frame_seed.xyz;
|
noise_coord.xyz += sig.frame_seed.xyz;
|
||||||
// noise_coord.xy -= sig.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(K_BLUE_NOISE_TEX_WIDTH, K_BLUE_NOISE_TEX_HEIGHT, K_BLUE_NOISE_TEX_DEPTH)];
|
||||||
return ((float)noise / (float)0xFFFF) * TAU;
|
return ((float)noise / (float)0xFFFF) * TAU;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
||||||
{
|
{
|
||||||
Texture2D<uint2> flood_tex = resource_from_urid(sig.emittance_flood_tex_urid);
|
Texture2D<uint2> flood_tex = resource_from_urid(sig.emittance_flood_tex_urid);
|
||||||
Texture2D<float4> emittance_tex = resource_from_urid(sig.emittance_tex_urid);
|
Texture2D<float4> emittance_tex = resource_from_urid(sig.emittance_tex_urid);
|
||||||
@ -53,7 +53,7 @@ INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE float3 get_light_at_pos(uint2 pos)
|
float3 get_light_at_pos(uint2 pos)
|
||||||
{
|
{
|
||||||
float3 result = 0;
|
float3 result = 0;
|
||||||
for (uint i = 0; i < SAMPLES; ++i) {
|
for (uint i = 0; i < SAMPLES; ++i) {
|
||||||
@ -75,7 +75,7 @@ struct cs_input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
[numthreads(8, 8, 1)]
|
||||||
SH_ENTRY void cs(struct cs_input input)
|
K_ENTRY void cs(struct cs_input input)
|
||||||
{
|
{
|
||||||
uint2 id = input.SV_DispatchThreadID.xy;
|
uint2 id = input.SV_DispatchThreadID.xy;
|
||||||
if (id.x < sig.tex_width && id.y < sig.tex_height) {
|
if (id.x < sig.tex_width && id.y < sig.tex_height) {
|
||||||
@ -88,7 +88,7 @@ SH_ENTRY void cs(struct cs_input input)
|
|||||||
color *= albedo_tex[id];
|
color *= albedo_tex[id];
|
||||||
|
|
||||||
/* Apply lighting */
|
/* Apply lighting */
|
||||||
if (!(sig.flags & SH_SHADE_FLAG_DISABLE_EFFECTS)) {
|
if (!(sig.flags & K_SHADE_FLAG_DISABLE_EFFECTS)) {
|
||||||
color.rgb *= get_light_at_pos(id);
|
color.rgb *= get_light_at_pos(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "sh/common.hlsl"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct sh_shape_sig> sig : register(b0);
|
ConstantBuffer<struct k_shape_sig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -15,10 +15,10 @@ struct vs_output {
|
|||||||
DECLS(float4, color_srgb);
|
DECLS(float4, color_srgb);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct vs_output vs(struct vs_input input)
|
K_ENTRY struct vs_output vs(struct vs_input input)
|
||||||
{
|
{
|
||||||
StructuredBuffer<struct sh_shape_vert> verts = resource_from_urid(sig.verts_urid);
|
StructuredBuffer<struct k_shape_vert> verts = resource_from_urid(sig.verts_urid);
|
||||||
struct sh_shape_vert vert = verts[input.SV_VertexID];
|
struct k_shape_vert vert = verts[input.SV_VertexID];
|
||||||
struct vs_output output;
|
struct vs_output output;
|
||||||
output.SV_Position = mul(sig.projection, float4(vert.pos.xy, 0, 1));
|
output.SV_Position = mul(sig.projection, float4(vert.pos.xy, 0, 1));
|
||||||
output.color_srgb = float4_from_uint_norm(vert.color_srgb);
|
output.color_srgb = float4_from_uint_norm(vert.color_srgb);
|
||||||
@ -37,7 +37,7 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target);
|
DECLS(float4, SV_Target);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct ps_output ps(struct ps_input input)
|
K_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,6 +1,6 @@
|
|||||||
#include "sh/common.hlsl"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct sh_ui_sig> sig : register(b0);
|
ConstantBuffer<struct k_ui_sig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
@ -18,7 +18,7 @@ struct vs_output {
|
|||||||
DECLS(float4, SV_Position);
|
DECLS(float4, SV_Position);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct vs_output vs(struct vs_input input)
|
K_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),
|
||||||
@ -27,8 +27,8 @@ SH_ENTRY struct vs_output vs(struct vs_input input)
|
|||||||
float2(-0.5f, 0.5f)
|
float2(-0.5f, 0.5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
StructuredBuffer<struct sh_ui_instance> instances = resource_from_urid(sig.instances_urid);
|
StructuredBuffer<struct k_ui_instance> instances = resource_from_urid(sig.instances_urid);
|
||||||
struct sh_ui_instance instance = instances[input.SV_InstanceID];
|
struct k_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;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ struct ps_output {
|
|||||||
DECLS(float4, SV_Target0);
|
DECLS(float4, SV_Target0);
|
||||||
};
|
};
|
||||||
|
|
||||||
SH_ENTRY struct ps_output ps(struct ps_input input)
|
K_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;
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
#if defined(PROFILING) && PROFILING == 1
|
||||||
|
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Weverything"
|
||||||
|
#define TRACY_FIBERS
|
||||||
|
# include TRACY_CLIENT_SRC_PATH
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#if PROFILING
|
#if defined(PROFILING) && PROFILING == 1
|
||||||
|
|
||||||
#if COMPILER_MSVC
|
#ifndef __clang__
|
||||||
# error MSVC not supported for profiling (cleanup attributes are required for profiling markup)
|
# error Only clang is supported when compiling with PROFILING=1 (cleanup attributes are required for profiling markup)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PROFILING_SYSTEM_TRACE 0
|
#define PROFILING_SYSTEM_TRACE 0
|
||||||
|
|||||||
@ -1,55 +0,0 @@
|
|||||||
#include "sh/sh_common.h"
|
|
||||||
|
|
||||||
#define TAU 6.28318530718
|
|
||||||
#define PI 3.14159265359
|
|
||||||
#define GOLDEN 1.61803398875
|
|
||||||
|
|
||||||
#define DECLS(t, n) t n : n
|
|
||||||
|
|
||||||
#define resource_from_urid(urid) ResourceDescriptorHeap[urid]
|
|
||||||
#define resource_from_nurid(nurid) ResourceDescriptorHeap[NonUniformResourceIndex(nurid)]
|
|
||||||
|
|
||||||
#if !SH_CPU
|
|
||||||
# define INLINE /* For intellisense */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
INLINE float4 float4_from_uint_norm(uint v)
|
|
||||||
{
|
|
||||||
float4 res;
|
|
||||||
res.r = ((v >> 0) & 0xFF) / 255.0;
|
|
||||||
res.g = ((v >> 8) & 0xFF) / 255.0;
|
|
||||||
res.b = ((v >> 16) & 0xFF) / 255.0;
|
|
||||||
res.a = ((v >> 24) & 0xFF) / 255.0;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Linear color from normalized sRGB */
|
|
||||||
INLINE float4 linear_from_srgb(float4 srgb)
|
|
||||||
{
|
|
||||||
return float4(pow(abs(srgb.rgb), 2.2), srgb.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Linear color from R8G8B8A8 sRGB */
|
|
||||||
INLINE float4 linear_from_srgb32(uint srgb32)
|
|
||||||
{
|
|
||||||
return linear_from_srgb(float4_from_uint_norm(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,246 +0,0 @@
|
|||||||
#if SH_CPU
|
|
||||||
|
|
||||||
#define SH_STRUCT(s) PACK(struct s)
|
|
||||||
#define SH_DECL(t, n) struct CAT(sh_, t) n
|
|
||||||
#define SH_DECLS(t, n) SH_DECL(t, n)
|
|
||||||
#define SH_STATIC_ASSERT(c) STATIC_ASSERT(c)
|
|
||||||
|
|
||||||
struct sh_uint { u32 v; };
|
|
||||||
INLINE struct sh_uint sh_uint_from_u32(u32 v)
|
|
||||||
{
|
|
||||||
return (struct sh_uint) { .v = v };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_int { i32 v; };
|
|
||||||
INLINE struct sh_int sh_int_from_i32(i32 v)
|
|
||||||
{
|
|
||||||
return (struct sh_int) { .v = v };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_uint2 { u32 v[2]; };
|
|
||||||
INLINE struct sh_uint2 sh_uint2_from_u32(u32 x, u32 y)
|
|
||||||
{
|
|
||||||
return (struct sh_uint2) { .v[0] = x, .v[1] = y };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_uint3 { u32 v[3]; };
|
|
||||||
INLINE struct sh_uint3 sh_uint3_from_u32(u32 x, u32 y, u32 z)
|
|
||||||
{
|
|
||||||
return (struct sh_uint3) { .v[0] = x, .v[1] = y, .v[2] = z };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_uint4 { u32 v[4]; };
|
|
||||||
INLINE struct sh_uint4 sh_uint4_from_u32(u32 x, u32 y, u32 z, u32 w)
|
|
||||||
{
|
|
||||||
return (struct sh_uint4) { .v[0] = x, .v[1] = y, .v[2] = z, .v[3] = w };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_float { f32 v; };
|
|
||||||
INLINE struct sh_float sh_float_from_f32(f32 v)
|
|
||||||
{
|
|
||||||
return (struct sh_float) { .v = v };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_float2 { f32 v[2]; };
|
|
||||||
INLINE struct sh_float2 sh_float2_from_v2(struct v2 v)
|
|
||||||
{
|
|
||||||
return (struct sh_float2) { .v[0] = v.x, .v[1] = v.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_float3 { f32 v[3]; };
|
|
||||||
INLINE struct sh_float3 sh_float3_from_v3(struct v3 v)
|
|
||||||
{
|
|
||||||
return (struct sh_float3) { .v[0] = v.x, .v[1] = v.y, .v[2] = v.z };
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_float4x4 { f32 v[4][4]; };
|
|
||||||
INLINE struct sh_float4x4 sh_float4x4_from_mat4x4(struct mat4x4 v)
|
|
||||||
{
|
|
||||||
struct sh_float4x4 res;
|
|
||||||
STATIC_ASSERT(sizeof(res) == sizeof(v));
|
|
||||||
MEMCPY(&res, v.e, sizeof(res));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sh_float2x3 { f32 v[2][3]; };
|
|
||||||
INLINE struct sh_float2x3 sh_float2x3_from_xform(struct xform v)
|
|
||||||
{
|
|
||||||
struct sh_float2x3 res;
|
|
||||||
STATIC_ASSERT(sizeof(res) == sizeof(v));
|
|
||||||
MEMCPY(&res, &v, sizeof(res));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define SH_STRUCT(s) struct s
|
|
||||||
#define SH_DECL(t, n) t n
|
|
||||||
#define SH_DECLS(t, n) t n : n
|
|
||||||
#define SH_STATIC_ASSERT(c) _Static_assert(c, "")
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SH_ASSERT_ROOT_CONST(s, n) SH_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 */
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Global textures
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
/* Blue noise */
|
|
||||||
#define SH_BLUE_NOISE_TEX_ID 0
|
|
||||||
#define SH_BLUE_NOISE_TEX_WIDTH 128
|
|
||||||
#define SH_BLUE_NOISE_TEX_HEIGHT 128
|
|
||||||
#define SH_BLUE_NOISE_TEX_DEPTH 64
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Material shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
SH_STRUCT(sh_material_sig {
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint, instances_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, grids_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, _pad0); /* 01 consts (padding) */
|
|
||||||
SH_DECL(uint, _pad1); /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
});
|
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_material_sig, 20);
|
|
||||||
|
|
||||||
SH_STRUCT(sh_material_instance {
|
|
||||||
SH_DECL(uint, tex_nurid);
|
|
||||||
SH_DECL(uint, grid_id);
|
|
||||||
SH_DECL(float2x3, xf);
|
|
||||||
SH_DECL(float2, uv0);
|
|
||||||
SH_DECL(float2, uv1);
|
|
||||||
SH_DECL(uint, tint_srgb);
|
|
||||||
SH_DECL(uint, is_light);
|
|
||||||
SH_DECL(float3, light_emittance_srgb);
|
|
||||||
});
|
|
||||||
|
|
||||||
SH_STRUCT(sh_material_grid {
|
|
||||||
SH_DECL(float, line_thickness);
|
|
||||||
SH_DECL(float, line_spacing);
|
|
||||||
SH_DECL(float2, offset);
|
|
||||||
SH_DECL(uint, bg0_srgb);
|
|
||||||
SH_DECL(uint, bg1_srgb);
|
|
||||||
SH_DECL(uint, line_srgb);
|
|
||||||
SH_DECL(uint, x_srgb);
|
|
||||||
SH_DECL(uint, y_srgb);
|
|
||||||
});
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Flood shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
SH_STRUCT(sh_flood_sig {
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(int, step_len); /* 01 consts */
|
|
||||||
SH_DECL(uint, emittance_tex_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, read_flood_tex_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, target_flood_tex_urid); /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint, tex_width); /* 01 consts */
|
|
||||||
SH_DECL(uint, tex_height); /* 01 consts */
|
|
||||||
SH_DECL(uint, _pad0); /* 01 consts (padding) */
|
|
||||||
SH_DECL(uint, _pad1); /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
});
|
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_flood_sig, 8);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Shade shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define SH_SHADE_FLAG_NONE (0 << 0)
|
|
||||||
#define SH_SHADE_FLAG_DISABLE_EFFECTS (1 << 0)
|
|
||||||
|
|
||||||
SH_STRUCT(sh_shade_sig {
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint4, frame_seed); /* 04 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint, flags); /* 01 consts */
|
|
||||||
SH_DECL(uint, _pad0); /* 01 consts (padding) */
|
|
||||||
SH_DECL(uint, tex_width); /* 01 consts */
|
|
||||||
SH_DECL(uint, tex_height); /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(float2, camera_offset); /* 02 consts */
|
|
||||||
SH_DECL(uint, frame_index); /* 01 consts */
|
|
||||||
SH_DECL(uint, albedo_tex_urid); /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint, emittance_tex_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, emittance_flood_tex_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, read_tex_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, target_tex_urid); /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
});
|
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_shade_sig, 16);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Shape shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
SH_STRUCT(sh_shape_sig {
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint, verts_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, _pad0); /* 01 consts (padding) */
|
|
||||||
SH_DECL(uint, _pad1); /* 01 consts (padding) */
|
|
||||||
SH_DECL(uint, _pad2); /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
});
|
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_shape_sig, 20);
|
|
||||||
|
|
||||||
SH_STRUCT(sh_shape_vert {
|
|
||||||
SH_DECL(float2, pos);
|
|
||||||
SH_DECL(uint, color_srgb);
|
|
||||||
});
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* UI shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
SH_STRUCT(sh_ui_sig {
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint, instances_urid); /* 01 consts */
|
|
||||||
SH_DECL(uint, _pad0); /* 01 consts (padding) */
|
|
||||||
SH_DECL(uint, _pad1); /* 01 consts (padding) */
|
|
||||||
SH_DECL(uint, _pad2); /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
});
|
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_ui_sig, 20);
|
|
||||||
|
|
||||||
SH_STRUCT(sh_ui_instance {
|
|
||||||
SH_DECL(uint, tex_nurid);
|
|
||||||
SH_DECL(uint, grid_id);
|
|
||||||
SH_DECL(float2x3, xf);
|
|
||||||
SH_DECL(float2, uv0);
|
|
||||||
SH_DECL(float2, uv1);
|
|
||||||
SH_DECL(uint, tint_srgb);
|
|
||||||
});
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Blit shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define SH_BLIT_FLAG_NONE (0 << 0)
|
|
||||||
#define SH_BLIT_FLAG_TONE_MAP (1 << 0)
|
|
||||||
#define SH_BLIT_FLAG_GAMMA_CORRECT (1 << 1)
|
|
||||||
|
|
||||||
SH_STRUCT(sh_blit_sig {
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(float4x4, projection); /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
SH_DECL(uint, flags); /* 01 consts */
|
|
||||||
SH_DECL(uint, tex_urid); /* 01 consts */
|
|
||||||
SH_DECL(float, exposure); /* 01 consts */
|
|
||||||
SH_DECL(float, gamma); /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
});
|
|
||||||
SH_ASSERT_ROOT_CONST(struct sh_blit_sig, 20);
|
|
||||||
Loading…
Reference in New Issue
Block a user