begin gpu layer refactor
This commit is contained in:
parent
b56b9182ec
commit
0ba8ca3538
@ -112,7 +112,7 @@ extern "C" {
|
|||||||
//~ Debug
|
//~ Debug
|
||||||
|
|
||||||
//- Static assert
|
//- Static assert
|
||||||
#if CompilerIsMsvc || (LanguageIsC && __STDC_VERSION__ < 202311L)
|
#if CompilerIsMsvc || (LanguageIsC && __STDC_VERSION__ < 202311L) || LanguageIsGpu
|
||||||
# if CompilerIsMsvc
|
# if CompilerIsMsvc
|
||||||
# define StaticAssert2(cond, line) struct STATIC_ASSERT_____##line {int foo[(cond) ? 1 : -1];}
|
# define StaticAssert2(cond, line) struct STATIC_ASSERT_____##line {int foo[(cond) ? 1 : -1];}
|
||||||
# define StaticAssert1(cond, line) StaticAssert2(cond, line)
|
# define StaticAssert1(cond, line) StaticAssert2(cond, line)
|
||||||
@ -138,6 +138,12 @@ extern "C" {
|
|||||||
# define Assert(cond) (void)(0)
|
# define Assert(cond) (void)(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//- Root constant assert
|
||||||
|
#define AssertRootConst(s, n) StaticAssert((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 */
|
||||||
|
|
||||||
|
|
||||||
//- Debug alias
|
//- Debug alias
|
||||||
/* TODO: Remove this */
|
/* TODO: Remove this */
|
||||||
#if CompilerIsMsvc
|
#if CompilerIsMsvc
|
||||||
@ -354,6 +360,18 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
|
|||||||
#define ColorOrange Rgb32(0xFF, 0xA5, 0x00)
|
#define ColorOrange Rgb32(0xFF, 0xA5, 0x00)
|
||||||
#define ColorPurple Rgb32(0xFF, 0x00, 0XFF)
|
#define ColorPurple Rgb32(0xFF, 0x00, 0XFF)
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Gpu helpers
|
||||||
|
|
||||||
|
#if LanguageIsGpu
|
||||||
|
//- Resource heap index
|
||||||
|
# define GpuResourceFromUrid(urid) ResourceDescriptorHeap[urid]
|
||||||
|
# define GpuResourceFromNurid(nurid) ResourceDescriptorHeap[NonUniformResourceIndex(nurid)]
|
||||||
|
|
||||||
|
//- Semantic declaration
|
||||||
|
# define Semantic(t, n) t n : n
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Intrinsic headers
|
//~ Intrinsic headers
|
||||||
|
|
||||||
|
|||||||
@ -59,6 +59,15 @@ Struct(Vec3I32) {
|
|||||||
};
|
};
|
||||||
#define VEC3I32(x, y, z) CppCompatInitListType(Vec3I32) { (x), (y), (z) }
|
#define VEC3I32(x, y, z) CppCompatInitListType(Vec3I32) { (x), (y), (z) }
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Integer vector4 types
|
||||||
|
|
||||||
|
Struct(Vec4I32)
|
||||||
|
{
|
||||||
|
i32 x, y, z, w;
|
||||||
|
};
|
||||||
|
#define VEC4I32(x, y, z, w) CppCompatInitListType(Vec4I32) { (x), (y), (z), (w) }
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ Xform types
|
//~ Xform types
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,50 @@
|
|||||||
|
////////////////////////////////
|
||||||
|
//~ Gpu math constants
|
||||||
|
|
||||||
#define Pi ((f32)3.14159265358979323846)
|
#define Pi ((f32)3.14159265358979323846)
|
||||||
#define Tau ((f32)6.28318530717958647693)
|
#define Tau ((f32)6.28318530717958647693)
|
||||||
#define GoldenRatio ((f32)1.61803398874989484820)
|
#define GoldenRatio ((f32)1.61803398874989484820)
|
||||||
|
|
||||||
#if LanguageIsC || LanguageIsCpp || !LanguageIsGpu
|
////////////////////////////////
|
||||||
# error AAA
|
//~ Gpu math types
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef float2 Vec2;
|
typedef float2 Vec2;
|
||||||
typedef float3 Vec3;
|
typedef float3 Vec3;
|
||||||
typedef float4 Vec4;
|
typedef float4 Vec4;
|
||||||
typedef int2 Vec2I32;
|
typedef int2 Vec2I32;
|
||||||
typedef int3 Vec3I32;
|
typedef int3 Vec3I32;
|
||||||
|
typedef int4 Vec4I32;
|
||||||
typedef float2x3 Xform;
|
typedef float2x3 Xform;
|
||||||
typedef float4 Rect;
|
typedef float4 Rect;
|
||||||
typedef float2 ClipRect;
|
typedef float4 ClipRect;
|
||||||
typedef float2 Aabb;
|
typedef float4 Aabb;
|
||||||
typedef float4 Quad;
|
typedef float4 Quad;
|
||||||
typedef float4x4 Mat4x4;
|
typedef float4x4 Mat4x4;
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Integer -> float
|
||||||
|
|
||||||
|
Vec4 Vec4NormFromU32(u32 v)
|
||||||
|
{
|
||||||
|
Vec4 result;
|
||||||
|
result.r = ((v >> 0) & 0xFF) / 255.0;
|
||||||
|
result.g = ((v >> 8) & 0xFF) / 255.0;
|
||||||
|
result.b = ((v >> 16) & 0xFF) / 255.0;
|
||||||
|
result.a = ((v >> 24) & 0xFF) / 255.0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Srgb -> linear
|
||||||
|
|
||||||
|
/* Linear color from normalized sRGB */
|
||||||
|
Vec4 LinearFromSrgbVec4(Vec4 srgb)
|
||||||
|
{
|
||||||
|
return Vec4(pow(abs(srgb.rgb), 2.2), srgb.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Linear color from R8G8B8A8 sRGB */
|
||||||
|
Vec4 LinearFromSrgbU32(u32 srgb32)
|
||||||
|
{
|
||||||
|
return LinearFromSrgbVec4(Vec4NormFromU32(srgb32));
|
||||||
|
}
|
||||||
|
|||||||
@ -2658,14 +2658,14 @@ u32 gp_push_render_cmd(GPU_RenderSig *render_sig, GPU_RenderCmdDesc *cmd_desc)
|
|||||||
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 k_shape_vert *verts = PushStructsNoZero(sig->ui_shape_verts_arena, struct k_shape_vert, cmd_desc->ui_shape.vertices.count);
|
K_ShapeVert *verts = PushStructsNoZero(sig->ui_shape_verts_arena, K_ShapeVert, cmd_desc->ui_shape.vertices.count);
|
||||||
u32 *indices = PushStructsNoZero(sig->ui_shape_indices_arena, u32, cmd_desc->ui_shape.indices.count);
|
u32 *indices = PushStructsNoZero(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 k_shape_vert *v = &verts[i];
|
K_ShapeVert *v = &verts[i];
|
||||||
v->pos = K_Float2FromV2(cmd_desc->ui_shape.vertices.points[i]);
|
v->pos = cmd_desc->ui_shape.vertices.points[i];
|
||||||
v->color_srgb = K_UintFromU32(color);
|
v->color_srgb = color;
|
||||||
}
|
}
|
||||||
u32 vert_offset = verts - (struct k_shape_vert *)ArenaBase(sig->ui_shape_verts_arena);
|
u32 vert_offset = verts - (K_ShapeVert *)ArenaBase(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;
|
||||||
}
|
}
|
||||||
@ -2769,9 +2769,9 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
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 k_material_instance *material_instances = PushStructsNoZero(scratch.arena, struct k_material_instance, rsig->num_material_instance_descs);
|
K_MaterialInstance *material_instances = PushStructsNoZero(scratch.arena, K_MaterialInstance, rsig->num_material_instance_descs);
|
||||||
struct k_ui_instance *ui_rect_instances = PushStructsNoZero(scratch.arena, struct k_ui_instance, rsig->num_ui_rect_instance_descs);
|
K_UiInstance *ui_rect_instances = PushStructsNoZero(scratch.arena, K_UiInstance, rsig->num_ui_rect_instance_descs);
|
||||||
struct k_material_grid *grids = PushStructsNoZero(scratch.arena, struct k_material_grid, rsig->num_material_grid_descs);
|
K_MaterialGrid *grids = PushStructsNoZero(scratch.arena, K_MaterialGrid, rsig->num_material_grid_descs);
|
||||||
{
|
{
|
||||||
__profn("Process sig data");
|
__profn("Process sig data");
|
||||||
|
|
||||||
@ -2780,15 +2780,15 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
__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 *)ArenaBase(rsig->material_instance_descs_arena))[i];
|
struct material_instance_desc *desc = &((struct material_instance_desc *)ArenaBase(rsig->material_instance_descs_arena))[i];
|
||||||
struct k_material_instance *instance = &material_instances[i];
|
K_MaterialInstance *instance = &material_instances[i];
|
||||||
instance->tex_nurid = K_UintFromU32(desc->texture_id);
|
instance->tex_nurid = desc->texture_id;
|
||||||
instance->grid_id = K_UintFromU32(desc->grid_id);
|
instance->grid_id = desc->grid_id;
|
||||||
instance->xf = K_Float2x3FromXform(desc->xf);
|
instance->xf = desc->xf;
|
||||||
instance->uv0 = K_Float2FromV2(desc->clip.p0);
|
instance->uv0 = desc->clip.p0;
|
||||||
instance->uv1 = K_Float2FromV2(desc->clip.p1);
|
instance->uv1 = desc->clip.p1;
|
||||||
instance->tint_srgb = K_UintFromU32(desc->tint);
|
instance->tint_srgb = desc->tint;
|
||||||
instance->is_light = K_UintFromU32(desc->is_light);
|
instance->is_light = desc->is_light;
|
||||||
instance->light_emittance_srgb = K_Float3FromV3(desc->light_emittance);
|
instance->light_emittance_srgb = desc->light_emittance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2797,12 +2797,12 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
__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 *)ArenaBase(rsig->ui_rect_instance_descs_arena))[i];
|
struct ui_rect_instance_desc *desc = &((struct ui_rect_instance_desc *)ArenaBase(rsig->ui_rect_instance_descs_arena))[i];
|
||||||
struct k_ui_instance *instance = &ui_rect_instances[i];
|
K_UiInstance *instance = &ui_rect_instances[i];
|
||||||
instance->tex_nurid = K_UintFromU32(desc->texture_id);
|
instance->tex_nurid = desc->texture_id;
|
||||||
instance->xf = K_Float2x3FromXform(desc->xf);
|
instance->xf = desc->xf;
|
||||||
instance->uv0 = K_Float2FromV2(desc->clip.p0);
|
instance->uv0 = desc->clip.p0;
|
||||||
instance->uv1 = K_Float2FromV2(desc->clip.p1);
|
instance->uv1 = desc->clip.p1;
|
||||||
instance->tint_srgb = K_UintFromU32(desc->tint);
|
instance->tint_srgb = desc->tint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2811,25 +2811,25 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
__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 *)ArenaBase(rsig->material_grid_descs_arena))[i];
|
struct material_grid_desc *desc = &((struct material_grid_desc *)ArenaBase(rsig->material_grid_descs_arena))[i];
|
||||||
struct k_material_grid *grid = &grids[i];
|
K_MaterialGrid *grid = &grids[i];
|
||||||
grid->line_thickness = K_FloatFromF32(desc->line_thickness);
|
grid->line_thickness = desc->line_thickness;
|
||||||
grid->line_spacing = K_FloatFromF32(desc->line_spacing);
|
grid->line_spacing = desc->line_spacing;
|
||||||
grid->offset = K_Float2FromV2(desc->offset);
|
grid->offset = desc->offset;
|
||||||
grid->bg0_srgb = K_UintFromU32(desc->bg0_color);
|
grid->bg0_srgb = desc->bg0_color;
|
||||||
grid->bg1_srgb = K_UintFromU32(desc->bg1_color);
|
grid->bg1_srgb = desc->bg1_color;
|
||||||
grid->line_srgb = K_UintFromU32(desc->line_color);
|
grid->line_srgb = desc->line_color;
|
||||||
grid->x_srgb = K_UintFromU32(desc->x_color);
|
grid->x_srgb = desc->x_color;
|
||||||
grid->y_srgb = K_UintFromU32(desc->y_color);
|
grid->y_srgb = desc->y_color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Upload buffers */
|
/* Upload buffers */
|
||||||
u64 num_ui_shape_verts = rsig->ui_shape_verts_arena->pos / sizeof(struct k_shape_vert);
|
u64 num_ui_shape_verts = rsig->ui_shape_verts_arena->pos / sizeof(K_ShapeVert);
|
||||||
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 k_shape_vert *)ArenaBase(rsig->ui_shape_verts_arena));
|
struct command_buffer *ui_shape_verts_buffer = command_list_push_buffer(cl, num_ui_shape_verts, (K_ShapeVert *)ArenaBase(rsig->ui_shape_verts_arena));
|
||||||
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u32 *)ArenaBase(rsig->ui_shape_indices_arena));
|
struct command_buffer *ui_shape_indices_buffer = command_list_push_buffer(cl, num_ui_shape_indices, (u32 *)ArenaBase(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);
|
||||||
|
|
||||||
@ -2878,14 +2878,14 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct k_material_sig sig = ZI;
|
K_MaterialSig sig = ZI;
|
||||||
sig.projection = world_to_render_vp_matrix;
|
sig.projection = world_to_render_vp_matrix;
|
||||||
sig.instances_urid = material_instance_buffer->resource->srv_descriptor->index;
|
sig.instances_urid = material_instance_buffer->resource->srv_descriptor->index;
|
||||||
sig.grids_urid = grid_buffer->resource->srv_descriptor->index;
|
sig.grids_urid = 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 k_material_instance);
|
u32 instance_count = material_instance_buffer->size / sizeof(K_MaterialInstance);
|
||||||
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);
|
||||||
@ -2936,13 +2936,13 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct k_flood_sig sig = ZI;
|
K_FloodSig sig = ZI;
|
||||||
sig.step_len = K_IntFromI32(step_length);
|
sig.step_len = step_length;
|
||||||
sig.emittance_tex_urid = K_UintFromU32(rsig->emittance->srv_descriptor->index);
|
sig.emittance_tex_urid = rsig->emittance->srv_descriptor->index;
|
||||||
sig.read_flood_tex_urid = K_UintFromU32(rsig->emittance_flood_read->uav_descriptor->index);
|
sig.read_flood_tex_urid = rsig->emittance_flood_read->uav_descriptor->index;
|
||||||
sig.target_flood_tex_urid = K_UintFromU32(rsig->emittance_flood_target->uav_descriptor->index);
|
sig.target_flood_tex_urid = rsig->emittance_flood_target->uav_descriptor->index;
|
||||||
sig.tex_width = K_UintFromU32(render_size.x);
|
sig.tex_width = render_size.x;
|
||||||
sig.tex_height = K_UintFromU32(render_size.y);
|
sig.tex_height = render_size.y;
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Dispatch */
|
/* Dispatch */
|
||||||
@ -3004,21 +3004,21 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct k_shade_sig sig = ZI;
|
K_ShadeSig sig = ZI;
|
||||||
sig.flags = K_UintFromU32(shade_flags);
|
sig.flags = shade_flags;
|
||||||
sig.tex_width = K_UintFromU32(render_size.x);
|
sig.tex_width = render_size.x;
|
||||||
sig.tex_height = K_UintFromU32(render_size.y);
|
sig.tex_height = render_size.y;
|
||||||
sig.frame_seed = K_Uint4FromU32((u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF),
|
sig.frame_seed = VEC4I32((u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF),
|
(u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF),
|
(u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF),
|
||||||
(u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF));
|
(u32)(RandU64FromState(&rsig->rand) & 0xFFFFFFFF));
|
||||||
sig.frame_index = K_UintFromU32(rsig->frame_index);
|
sig.frame_index = rsig->frame_index;
|
||||||
sig.camera_offset = K_Float2FromV2(world_to_render_xf.og);
|
sig.camera_offset = world_to_render_xf.og;
|
||||||
sig.albedo_tex_urid = K_UintFromU32(rsig->albedo->srv_descriptor->index);
|
sig.albedo_tex_urid = rsig->albedo->srv_descriptor->index;
|
||||||
sig.emittance_tex_urid = K_UintFromU32(rsig->emittance->srv_descriptor->index);
|
sig.emittance_tex_urid = rsig->emittance->srv_descriptor->index;
|
||||||
sig.emittance_flood_tex_urid = K_UintFromU32(rsig->emittance_flood_read->srv_descriptor->index);
|
sig.emittance_flood_tex_urid = rsig->emittance_flood_read->srv_descriptor->index;
|
||||||
sig.read_tex_urid = K_UintFromU32(rsig->shade_read->uav_descriptor->index);
|
sig.read_tex_urid = rsig->shade_read->uav_descriptor->index;
|
||||||
sig.target_tex_urid = K_UintFromU32(rsig->shade_target->uav_descriptor->index);
|
sig.target_tex_urid = rsig->shade_target->uav_descriptor->index;
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Dispatch */
|
/* Dispatch */
|
||||||
@ -3066,12 +3066,12 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct k_blit_sig sig = ZI;
|
K_BlitSig sig = ZI;
|
||||||
sig.projection = K_Float4x4FromMat4x4(blit_vp_matrix);
|
sig.projection = blit_vp_matrix;
|
||||||
sig.flags = K_UintFromU32(K_BLIT_FLAG_TONE_MAP | K_BLIT_FLAG_GAMMA_CORRECT);
|
sig.flags = K_BLIT_FLAG_TONE_MAP | K_BLIT_FLAG_GAMMA_CORRECT;
|
||||||
sig.exposure = K_FloatFromF32(2.0);
|
sig.exposure = 2.0;
|
||||||
sig.gamma = K_FloatFromF32((f32)2.2);
|
sig.gamma = (f32)2.2;
|
||||||
sig.tex_urid = K_UintFromU32(rsig->shade_read->uav_descriptor->index);
|
sig.tex_urid = rsig->shade_read->uav_descriptor->index;
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
@ -3098,13 +3098,13 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct k_ui_sig sig = ZI;
|
K_UiSig sig = ZI;
|
||||||
sig.projection = K_Float4x4FromMat4x4(ui_vp_matrix);
|
sig.projection = ui_vp_matrix;
|
||||||
sig.instances_urid = K_UintFromU32(ui_rect_instance_buffer->resource->srv_descriptor->index);
|
sig.instances_urid = 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 k_ui_instance);
|
u32 instance_count = ui_rect_instance_buffer->size / sizeof(K_UiInstance);
|
||||||
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);
|
||||||
@ -3128,9 +3128,9 @@ GPU_Resource *gp_run_render(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
|
|||||||
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);
|
||||||
|
|
||||||
/* Set sig */
|
/* Set sig */
|
||||||
struct k_shape_sig sig = ZI;
|
K_ShapeSig sig = ZI;
|
||||||
sig.projection = K_Float4x4FromMat4x4(ui_vp_matrix);
|
sig.projection = ui_vp_matrix;
|
||||||
sig.verts_urid = K_UintFromU32(ui_shape_verts_buffer->resource->srv_descriptor->index);
|
sig.verts_urid = 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 */
|
||||||
@ -3405,10 +3405,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 k_blit_sig sig = ZI;
|
K_BlitSig sig = ZI;
|
||||||
sig.projection = K_Float4x4FromMat4x4(vp_matrix);
|
sig.projection = vp_matrix;
|
||||||
sig.flags = K_UintFromU32(K_BLIT_FLAG_NONE);
|
sig.flags = K_BLIT_FLAG_NONE;
|
||||||
sig.tex_urid = K_UintFromU32(src->srv_descriptor->index);
|
sig.tex_urid = src->srv_descriptor->index;
|
||||||
command_list_set_sig(cl, &sig, sizeof(sig));
|
command_list_set_sig(cl, &sig, sizeof(sig));
|
||||||
|
|
||||||
/* Draw */
|
/* Draw */
|
||||||
|
|||||||
@ -1,33 +1,35 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct k_blit_sig> sig : register(b0);
|
ConstantBuffer<K_BlitSig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct vs_input {
|
Struct(VsInput)
|
||||||
DECLS(uint, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct vs_output {
|
|
||||||
DECLS(float4, SV_Position);
|
|
||||||
DECLS(float2, uv);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct vs_output vs(struct vs_input input)
|
|
||||||
{
|
{
|
||||||
static const float2 unit_quad_verts[4] = {
|
Semantic(u32, SV_VertexID);
|
||||||
float2(-0.5f, -0.5f),
|
};
|
||||||
float2(0.5f, -0.5f),
|
|
||||||
float2(0.5f, 0.5f),
|
Struct(VSOutput)
|
||||||
float2(-0.5f, 0.5f)
|
{
|
||||||
|
Semantic(Vec4, SV_Position);
|
||||||
|
Semantic(Vec2, uv);
|
||||||
|
};
|
||||||
|
|
||||||
|
K_ENTRY VSOutput vs(VsInput input)
|
||||||
|
{
|
||||||
|
static const Vec2 unit_quad_verts[4] = {
|
||||||
|
Vec2(-0.5f, -0.5f),
|
||||||
|
Vec2(0.5f, -0.5f),
|
||||||
|
Vec2(0.5f, 0.5f),
|
||||||
|
Vec2(-0.5f, 0.5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
float2 vert = unit_quad_verts[input.SV_VertexID];
|
Vec2 vert = unit_quad_verts[input.SV_VertexID];
|
||||||
|
|
||||||
struct vs_output output;
|
VSOutput output;
|
||||||
output.SV_Position = mul(sig.projection, float4(vert, 0, 1));
|
output.SV_Position = mul(sig.projection, Vec4(vert, 0, 1));
|
||||||
output.uv = vert + 0.5;
|
output.uv = vert + 0.5;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -38,7 +40,7 @@ K_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/ */
|
||||||
float3 tone_map(float3 v)
|
Vec3 tone_map(Vec3 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));
|
||||||
}
|
}
|
||||||
@ -47,19 +49,21 @@ float3 tone_map(float3 v)
|
|||||||
* Pixel shader
|
* Pixel shader
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct ps_input {
|
Struct(PsInput)
|
||||||
struct vs_output vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ps_output {
|
|
||||||
DECLS(float4, SV_Target);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct ps_output ps(struct ps_input input)
|
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
VSOutput vs;
|
||||||
Texture2D<float4> tex = resource_from_urid(sig.tex_urid);
|
};
|
||||||
float4 color = tex.Sample(s_point_clamp, input.vs.uv);
|
|
||||||
|
Struct(PSOutput)
|
||||||
|
{
|
||||||
|
Semantic(Vec4, SV_Target);
|
||||||
|
};
|
||||||
|
|
||||||
|
K_ENTRY PSOutput ps(PsInput input)
|
||||||
|
{
|
||||||
|
PSOutput output;
|
||||||
|
Texture2D<Vec4> tex = GpuResourceFromUrid(sig.tex_urid);
|
||||||
|
Vec4 color = tex.Sample(s_point_clamp, input.vs.uv);
|
||||||
|
|
||||||
/* Apply tone map */
|
/* Apply tone map */
|
||||||
if (sig.flags & K_BLIT_FLAG_TONE_MAP) {
|
if (sig.flags & K_BLIT_FLAG_TONE_MAP) {
|
||||||
|
|||||||
@ -5,121 +5,7 @@
|
|||||||
# define K_IS_CPU 0
|
# define K_IS_CPU 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if K_IS_CPU
|
#if !K_IS_CPU
|
||||||
|
|
||||||
#define K_STRUCT(s) Packed(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) StaticAssert(c)
|
|
||||||
|
|
||||||
typedef struct K_uint K_uint;
|
|
||||||
struct K_uint { u32 v; };
|
|
||||||
Inline struct K_uint K_UintFromU32(u32 v)
|
|
||||||
{
|
|
||||||
return (struct K_uint) { .v = v };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_int K_int;
|
|
||||||
struct K_int { i32 v; };
|
|
||||||
Inline struct K_int K_IntFromI32(i32 v)
|
|
||||||
{
|
|
||||||
return (struct K_int) { .v = v };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_uint2 K_uint2;
|
|
||||||
struct K_uint2 { u32 v[2]; };
|
|
||||||
Inline struct K_uint2 K_Uint2FromU32(u32 x, u32 y)
|
|
||||||
{
|
|
||||||
return (struct K_uint2) { .v[0] = x, .v[1] = y };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_uint3 K_uint3;
|
|
||||||
struct K_uint3 { u32 v[3]; };
|
|
||||||
Inline struct K_uint3 K_Uint3FromU32(u32 x, u32 y, u32 z)
|
|
||||||
{
|
|
||||||
return (struct K_uint3) { .v[0] = x, .v[1] = y, .v[2] = z };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_uint4 K_uint4;
|
|
||||||
struct K_uint4 { u32 v[4]; };
|
|
||||||
Inline struct K_uint4 K_Uint4FromU32(u32 x, u32 y, u32 z, u32 w)
|
|
||||||
{
|
|
||||||
return (struct K_uint4) { .v[0] = x, .v[1] = y, .v[2] = z, .v[3] = w };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_float K_float;
|
|
||||||
struct K_float { f32 v; };
|
|
||||||
Inline struct K_float K_FloatFromF32(f32 v)
|
|
||||||
{
|
|
||||||
return (struct K_float) { .v = v };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_float2 K_float2;
|
|
||||||
struct K_float2 { f32 v[2]; };
|
|
||||||
Inline struct K_float2 K_Float2FromV2(Vec2 v)
|
|
||||||
{
|
|
||||||
return (struct K_float2) { .v[0] = v.x, .v[1] = v.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_float3 K_float3;
|
|
||||||
struct K_float3 { f32 v[3]; };
|
|
||||||
Inline struct K_float3 K_Float3FromV3(Vec3 v)
|
|
||||||
{
|
|
||||||
return (struct K_float3) { .v[0] = v.x, .v[1] = v.y, .v[2] = v.z };
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct K_float4x4 K_float4x4;
|
|
||||||
struct K_float4x4 { f32 v[4][4]; };
|
|
||||||
Inline struct K_float4x4 K_Float4x4FromMat4x4(Mat4x4 v)
|
|
||||||
{
|
|
||||||
struct K_float4x4 result;
|
|
||||||
StaticAssert(sizeof(result) == sizeof(v));
|
|
||||||
CopyBytes(&result, v.e, sizeof(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct K_float2x3 { f32 v[2][3]; };
|
|
||||||
Inline struct K_float2x3 K_Float2x3FromXform(Xform v)
|
|
||||||
{
|
|
||||||
struct K_float2x3 result;
|
|
||||||
StaticAssert(sizeof(result) == sizeof(v));
|
|
||||||
CopyBytes(&result, &v, sizeof(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#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 resource_from_urid(urid) ResourceDescriptorHeap[urid]
|
|
||||||
#define resource_from_nurid(nurid) ResourceDescriptorHeap[NonUniformResourceIndex(nurid)]
|
|
||||||
|
|
||||||
float4 float4_from_uint_norm(uint v)
|
|
||||||
{
|
|
||||||
float4 result;
|
|
||||||
result.r = ((v >> 0) & 0xFF) / 255.0;
|
|
||||||
result.g = ((v >> 8) & 0xFF) / 255.0;
|
|
||||||
result.b = ((v >> 16) & 0xFF) / 255.0;
|
|
||||||
result.a = ((v >> 24) & 0xFF) / 255.0;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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
|
* Root signature
|
||||||
@ -143,10 +29,6 @@ SamplerState s_point_clamp : register(s0);
|
|||||||
|
|
||||||
#endif
|
#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
|
* Global textures
|
||||||
* ========================== */
|
* ========================== */
|
||||||
@ -161,20 +43,7 @@ SamplerState s_point_clamp : register(s0);
|
|||||||
* Material shader structs
|
* Material shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
#if 0
|
Struct(K_MaterialSig)
|
||||||
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);
|
|
||||||
#else
|
|
||||||
Struct(k_material_sig)
|
|
||||||
{
|
{
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
Mat4x4 projection; /* 16 consts */
|
Mat4x4 projection; /* 16 consts */
|
||||||
@ -185,49 +54,51 @@ Struct(k_material_sig)
|
|||||||
u32 _pad1; /* 01 consts (padding) */
|
u32 _pad1; /* 01 consts (padding) */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
};
|
};
|
||||||
K_ASSERT_ROOT_CONST(struct k_material_sig, 20);
|
AssertRootConst(K_MaterialSig, 20);
|
||||||
#endif
|
|
||||||
|
|
||||||
K_STRUCT(k_material_instance {
|
Struct(K_MaterialInstance)
|
||||||
K_DECL(uint, tex_nurid);
|
{
|
||||||
K_DECL(uint, grid_id);
|
u32 tex_nurid;
|
||||||
K_DECL(float2x3, xf);
|
u32 grid_id;
|
||||||
K_DECL(float2, uv0);
|
Xform xf;
|
||||||
K_DECL(float2, uv1);
|
Vec2 uv0;
|
||||||
K_DECL(uint, tint_srgb);
|
Vec2 uv1;
|
||||||
K_DECL(uint, is_light);
|
u32 tint_srgb;
|
||||||
K_DECL(float3, light_emittance_srgb);
|
u32 is_light;
|
||||||
});
|
Vec3 light_emittance_srgb;
|
||||||
|
};
|
||||||
|
|
||||||
K_STRUCT(k_material_grid {
|
Struct(K_MaterialGrid)
|
||||||
K_DECL(float, line_thickness);
|
{
|
||||||
K_DECL(float, line_spacing);
|
f32 line_thickness;
|
||||||
K_DECL(float2, offset);
|
f32 line_spacing;
|
||||||
K_DECL(uint, bg0_srgb);
|
Vec2 offset;
|
||||||
K_DECL(uint, bg1_srgb);
|
u32 bg0_srgb;
|
||||||
K_DECL(uint, line_srgb);
|
u32 bg1_srgb;
|
||||||
K_DECL(uint, x_srgb);
|
u32 line_srgb;
|
||||||
K_DECL(uint, y_srgb);
|
u32 x_srgb;
|
||||||
});
|
u32 y_srgb;
|
||||||
|
};
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Flood shader structs
|
* Flood shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
K_STRUCT(k_flood_sig {
|
Struct(K_FloodSig)
|
||||||
|
{
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(int, step_len); /* 01 consts */
|
i32 step_len; /* 01 consts */
|
||||||
K_DECL(uint, emittance_tex_urid); /* 01 consts */
|
u32 emittance_tex_urid; /* 01 consts */
|
||||||
K_DECL(uint, read_flood_tex_urid); /* 01 consts */
|
u32 read_flood_tex_urid; /* 01 consts */
|
||||||
K_DECL(uint, target_flood_tex_urid); /* 01 consts */
|
u32 target_flood_tex_urid; /* 01 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(uint, tex_width); /* 01 consts */
|
u32 tex_width; /* 01 consts */
|
||||||
K_DECL(uint, tex_height); /* 01 consts */
|
u32 tex_height; /* 01 consts */
|
||||||
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
u32 _pad0; /* 01 consts (padding) */
|
||||||
K_DECL(uint, _pad1); /* 01 consts (padding) */
|
u32 _pad1; /* 01 consts (padding) */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
});
|
};
|
||||||
K_ASSERT_ROOT_CONST(struct k_flood_sig, 8);
|
AssertRootConst(K_FloodSig, 8);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Shade shader structs
|
* Shade shader structs
|
||||||
@ -236,89 +107,95 @@ K_ASSERT_ROOT_CONST(struct k_flood_sig, 8);
|
|||||||
#define K_SHADE_FLAG_NONE (0 << 0)
|
#define K_SHADE_FLAG_NONE (0 << 0)
|
||||||
#define K_SHADE_FLAG_DISABLE_EFFECTS (1 << 0)
|
#define K_SHADE_FLAG_DISABLE_EFFECTS (1 << 0)
|
||||||
|
|
||||||
K_STRUCT(k_shade_sig {
|
Struct(K_ShadeSig)
|
||||||
|
{
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(uint4, frame_seed); /* 04 consts */
|
Vec4I32 frame_seed; /* 04 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(uint, flags); /* 01 consts */
|
u32 flags; /* 01 consts */
|
||||||
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
u32 _pad0; /* 01 consts (padding) */
|
||||||
K_DECL(uint, tex_width); /* 01 consts */
|
u32 tex_width; /* 01 consts */
|
||||||
K_DECL(uint, tex_height); /* 01 consts */
|
u32 tex_height; /* 01 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(float2, camera_offset); /* 02 consts */
|
Vec2 camera_offset; /* 02 consts */
|
||||||
K_DECL(uint, frame_index); /* 01 consts */
|
u32 frame_index; /* 01 consts */
|
||||||
K_DECL(uint, albedo_tex_urid); /* 01 consts */
|
u32 albedo_tex_urid; /* 01 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(uint, emittance_tex_urid); /* 01 consts */
|
u32 emittance_tex_urid; /* 01 consts */
|
||||||
K_DECL(uint, emittance_flood_tex_urid); /* 01 consts */
|
u32 emittance_flood_tex_urid; /* 01 consts */
|
||||||
K_DECL(uint, read_tex_urid); /* 01 consts */
|
u32 read_tex_urid; /* 01 consts */
|
||||||
K_DECL(uint, target_tex_urid); /* 01 consts */
|
u32 target_tex_urid; /* 01 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
});
|
};
|
||||||
K_ASSERT_ROOT_CONST(struct k_shade_sig, 16);
|
AssertRootConst(K_ShadeSig, 16);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Shape shader structs
|
* Shape shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
K_STRUCT(k_shape_sig {
|
Struct(K_ShapeSig)
|
||||||
|
{
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(float4x4, projection); /* 16 consts */
|
Mat4x4 projection; /* 16 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(uint, verts_urid); /* 01 consts */
|
u32 verts_urid; /* 01 consts */
|
||||||
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
u32 _pad0; /* 01 consts (padding) */
|
||||||
K_DECL(uint, _pad1); /* 01 consts (padding) */
|
u32 _pad1; /* 01 consts (padding) */
|
||||||
K_DECL(uint, _pad2); /* 01 consts (padding) */
|
u32 _pad2; /* 01 consts (padding) */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
});
|
};
|
||||||
K_ASSERT_ROOT_CONST(struct k_shape_sig, 20);
|
AssertRootConst(K_ShapeSig, 20);
|
||||||
|
|
||||||
K_STRUCT(k_shape_vert {
|
Struct(K_ShapeVert)
|
||||||
K_DECL(float2, pos);
|
{
|
||||||
K_DECL(uint, color_srgb);
|
Vec2 pos;
|
||||||
});
|
u32 color_srgb;
|
||||||
|
};
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* UI shader structs
|
* UI shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
K_STRUCT(k_ui_sig {
|
Struct(K_UiSig)
|
||||||
|
{
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(float4x4, projection); /* 16 consts */
|
Mat4x4 projection; /* 16 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(uint, instances_urid); /* 01 consts */
|
u32 instances_urid; /* 01 consts */
|
||||||
K_DECL(uint, _pad0); /* 01 consts (padding) */
|
u32 _pad0; /* 01 consts (padding) */
|
||||||
K_DECL(uint, _pad1); /* 01 consts (padding) */
|
u32 _pad1; /* 01 consts (padding) */
|
||||||
K_DECL(uint, _pad2); /* 01 consts (padding) */
|
u32 _pad2; /* 01 consts (padding) */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
});
|
};
|
||||||
K_ASSERT_ROOT_CONST(struct k_ui_sig, 20);
|
AssertRootConst(K_UiSig, 20);
|
||||||
|
|
||||||
K_STRUCT(k_ui_instance {
|
Struct(K_UiInstance)
|
||||||
K_DECL(uint, tex_nurid);
|
{
|
||||||
K_DECL(uint, grid_id);
|
u32 tex_nurid;
|
||||||
K_DECL(float2x3, xf);
|
u32 grid_id;
|
||||||
K_DECL(float2, uv0);
|
Xform xf;
|
||||||
K_DECL(float2, uv1);
|
Vec2 uv0;
|
||||||
K_DECL(uint, tint_srgb);
|
Vec2 uv1;
|
||||||
});
|
u32 tint_srgb;
|
||||||
|
};
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Blit shader structs
|
* Blit shader structs
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
#define K_BLIT_FLAG_NONE (0 << 0)
|
#define K_BLIT_FLAG_NONE (0 << 0)
|
||||||
#define K_BLIT_FLAG_TONE_MAP (1 << 0)
|
#define K_BLIT_FLAG_TONE_MAP (1 << 0)
|
||||||
#define K_BLIT_FLAG_GAMMA_CORRECT (1 << 1)
|
#define K_BLIT_FLAG_GAMMA_CORRECT (1 << 1)
|
||||||
|
|
||||||
K_STRUCT(k_blit_sig {
|
Struct(K_BlitSig)
|
||||||
|
{
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(float4x4, projection); /* 16 consts */
|
Mat4x4 projection; /* 16 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
K_DECL(uint, flags); /* 01 consts */
|
u32 flags; /* 01 consts */
|
||||||
K_DECL(uint, tex_urid); /* 01 consts */
|
u32 tex_urid; /* 01 consts */
|
||||||
K_DECL(float, exposure); /* 01 consts */
|
f32 exposure; /* 01 consts */
|
||||||
K_DECL(float, gamma); /* 01 consts */
|
f32 gamma; /* 01 consts */
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
});
|
};
|
||||||
K_ASSERT_ROOT_CONST(struct k_blit_sig, 20);
|
AssertRootConst(K_BlitSig, 20);
|
||||||
|
|||||||
@ -1,28 +1,29 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct k_flood_sig> sig : register(b0);
|
ConstantBuffer<K_FloodSig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Entry point
|
* Entry point
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct cs_input {
|
Struct(CsInput)
|
||||||
DECLS(uint3, SV_DispatchThreadID);
|
{
|
||||||
|
Semantic(uint3, SV_DispatchThreadID);
|
||||||
};
|
};
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
[numthreads(8, 8, 1)]
|
||||||
K_ENTRY void cs(struct cs_input input)
|
K_ENTRY void cs(CsInput 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);
|
||||||
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 = resource_from_urid(sig.emittance_tex_urid);
|
Texture2D<Vec4> emittance_tex = GpuResourceFromUrid(sig.emittance_tex_urid);
|
||||||
RWTexture2D<uint2> read_flood_tex = resource_from_urid(sig.read_flood_tex_urid);
|
RWTexture2D<uint2> read_flood_tex = GpuResourceFromUrid(sig.read_flood_tex_urid);
|
||||||
RWTexture2D<uint2> target_flood_tex = resource_from_urid(sig.target_flood_tex_urid);
|
RWTexture2D<uint2> target_flood_tex = GpuResourceFromUrid(sig.target_flood_tex_urid);
|
||||||
int step_len = sig.step_len;
|
int step_len = sig.step_len;
|
||||||
if (step_len == -1) {
|
if (step_len == -1) {
|
||||||
/* Seed */
|
/* Seed */
|
||||||
float4 emittance = emittance_tex[id];
|
Vec4 emittance = emittance_tex[id];
|
||||||
uint2 seed = uint2(0xFFFF, 0xFFFF);
|
uint2 seed = uint2(0xFFFF, 0xFFFF);
|
||||||
if (emittance.a > 0) {
|
if (emittance.a > 0) {
|
||||||
seed = id;
|
seed = id;
|
||||||
@ -30,25 +31,25 @@ K_ENTRY void cs(struct cs_input input)
|
|||||||
target_flood_tex[id] = seed;
|
target_flood_tex[id] = seed;
|
||||||
} else {
|
} else {
|
||||||
/* Flood */
|
/* Flood */
|
||||||
int2 read_coords[9] = {
|
Vec2I32 read_coords[9] = {
|
||||||
(int2)id + int2(-step_len, -step_len), /* top left */
|
(Vec2I32)id + Vec2I32(-step_len, -step_len), /* top left */
|
||||||
(int2)id + int2(0 , -step_len), /* top center */
|
(Vec2I32)id + Vec2I32(0 , -step_len), /* top center */
|
||||||
(int2)id + int2(+step_len, -step_len), /* top right */
|
(Vec2I32)id + Vec2I32(+step_len, -step_len), /* top right */
|
||||||
(int2)id + int2(-step_len, 0 ), /* center left */
|
(Vec2I32)id + Vec2I32(-step_len, 0 ), /* center left */
|
||||||
(int2)id + int2(0 , 0 ), /* center center */
|
(Vec2I32)id + Vec2I32(0 , 0 ), /* center center */
|
||||||
(int2)id + int2(+step_len, 0 ), /* center right */
|
(Vec2I32)id + Vec2I32(+step_len, 0 ), /* center right */
|
||||||
(int2)id + int2(-step_len, +step_len), /* bottom left */
|
(Vec2I32)id + Vec2I32(-step_len, +step_len), /* bottom left */
|
||||||
(int2)id + int2(0 , +step_len), /* bottom center */
|
(Vec2I32)id + Vec2I32(0 , +step_len), /* bottom center */
|
||||||
(int2)id + int2(+step_len, +step_len) /* bottom right */
|
(Vec2I32)id + Vec2I32(+step_len, +step_len) /* bottom right */
|
||||||
};
|
};
|
||||||
uint2 closest_seed = uint2(0xFFFF, 0xFFFF);
|
uint2 closest_seed = uint2(0xFFFF, 0xFFFF);
|
||||||
uint closest_seed_len_sq = 0xFFFFFFFF;
|
u32 closest_seed_len_sq = 0xFFFFFFFF;
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
int2 coord = read_coords[i];
|
Vec2I32 coord = read_coords[i];
|
||||||
if (coord.x >= 0 && coord.x < (int)tex_size.x && coord.y >= 0 && coord.y < (int)tex_size.y) {
|
if (coord.x >= 0 && coord.x < (int)tex_size.x && coord.y >= 0 && coord.y < (int)tex_size.y) {
|
||||||
uint2 seed = read_flood_tex[coord];
|
uint2 seed = read_flood_tex[coord];
|
||||||
int2 dist_vec = (int2)id - (int2)seed;
|
Vec2I32 dist_vec = (Vec2I32)id - (Vec2I32)seed;
|
||||||
uint dist_len_sq = dot(dist_vec, dist_vec);
|
u32 dist_len_sq = dot(dist_vec, dist_vec);
|
||||||
if (dist_len_sq < closest_seed_len_sq) {
|
if (dist_len_sq < closest_seed_len_sq) {
|
||||||
closest_seed = seed;
|
closest_seed = seed;
|
||||||
closest_seed_len_sq = dist_len_sq;
|
closest_seed_len_sq = dist_len_sq;
|
||||||
|
|||||||
@ -1,44 +1,46 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct k_material_sig> sig : register(b0);
|
ConstantBuffer<K_MaterialSig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct vs_input {
|
Struct(VsInput)
|
||||||
DECLS(uint, SV_InstanceID);
|
|
||||||
DECLS(uint, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct vs_output {
|
|
||||||
nointerpolation DECLS(uint, tex_nurid);
|
|
||||||
nointerpolation DECLS(uint, grid_id);
|
|
||||||
DECLS(float2, uv);
|
|
||||||
DECLS(float4, tint_lin);
|
|
||||||
DECLS(float4, emittance_lin);
|
|
||||||
DECLS(float4, SV_Position);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct vs_output vs(struct vs_input input)
|
|
||||||
{
|
{
|
||||||
static const float2 unit_quad_verts[4] = {
|
Semantic(u32, SV_InstanceID);
|
||||||
float2(-0.5f, -0.5f),
|
Semantic(u32, SV_VertexID);
|
||||||
float2(0.5f, -0.5f),
|
};
|
||||||
float2(0.5f, 0.5f),
|
|
||||||
float2(-0.5f, 0.5f)
|
Struct(VSOutput)
|
||||||
|
{
|
||||||
|
nointerpolation Semantic(u32, tex_nurid);
|
||||||
|
nointerpolation Semantic(u32, grid_id);
|
||||||
|
Semantic(Vec2, uv);
|
||||||
|
Semantic(Vec4, tint_lin);
|
||||||
|
Semantic(Vec4, emittance_lin);
|
||||||
|
Semantic(Vec4, SV_Position);
|
||||||
|
};
|
||||||
|
|
||||||
|
K_ENTRY VSOutput vs(VsInput input)
|
||||||
|
{
|
||||||
|
static const Vec2 unit_quad_verts[4] = {
|
||||||
|
Vec2(-0.5f, -0.5f),
|
||||||
|
Vec2(0.5f, -0.5f),
|
||||||
|
Vec2(0.5f, 0.5f),
|
||||||
|
Vec2(-0.5f, 0.5f)
|
||||||
};
|
};
|
||||||
StructuredBuffer<struct k_material_instance> instances = resource_from_urid(sig.instances_urid);
|
StructuredBuffer<K_MaterialInstance> instances = GpuResourceFromUrid(sig.instances_urid);
|
||||||
struct k_material_instance instance = instances[input.SV_InstanceID];
|
K_MaterialInstance instance = instances[input.SV_InstanceID];
|
||||||
float2 vert = unit_quad_verts[input.SV_VertexID];
|
Vec2 vert = unit_quad_verts[input.SV_VertexID];
|
||||||
float2 world_pos = mul(instance.xf, float3(vert, 1)).xy;
|
Vec2 world_pos = mul(instance.xf, Vec3(vert, 1)).xy;
|
||||||
struct vs_output output;
|
VSOutput output;
|
||||||
output.SV_Position = mul(sig.projection, float4(world_pos, 0, 1));
|
output.SV_Position = mul(sig.projection, Vec4(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));
|
||||||
output.tint_lin = linear_from_srgb32(instance.tint_srgb);
|
output.tint_lin = LinearFromSrgbU32(instance.tint_srgb);
|
||||||
output.emittance_lin = linear_from_srgb(float4(instance.light_emittance_srgb, instance.is_light));
|
output.emittance_lin = LinearFromSrgbVec4(Vec4(instance.light_emittance_srgb, instance.is_light));
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,35 +48,37 @@ K_ENTRY struct vs_output vs(struct vs_input input)
|
|||||||
* Pixel shader
|
* Pixel shader
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct ps_input {
|
Struct(PsInput)
|
||||||
struct vs_output vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ps_output {
|
|
||||||
DECLS(float4, SV_Target0); /* Albedo */
|
|
||||||
DECLS(float4, SV_Target1); /* Emittance */
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct ps_output ps(struct ps_input input)
|
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
VSOutput vs;
|
||||||
float4 albedo = input.vs.tint_lin;
|
};
|
||||||
|
|
||||||
|
Struct(PSOutput)
|
||||||
|
{
|
||||||
|
Semantic(Vec4, SV_Target0); /* Albedo */
|
||||||
|
Semantic(Vec4, SV_Target1); /* Emittance */
|
||||||
|
};
|
||||||
|
|
||||||
|
K_ENTRY PSOutput ps(PsInput input)
|
||||||
|
{
|
||||||
|
PSOutput output;
|
||||||
|
Vec4 albedo = input.vs.tint_lin;
|
||||||
|
|
||||||
/* Texture */
|
/* Texture */
|
||||||
if (input.vs.tex_nurid < 0xFFFFFFFF) {
|
if (input.vs.tex_nurid < 0xFFFFFFFF) {
|
||||||
Texture2D<float4> tex = resource_from_nurid(input.vs.tex_nurid);
|
Texture2D<Vec4> tex = GpuResourceFromNurid(input.vs.tex_nurid);
|
||||||
albedo *= tex.Sample(s_point_clamp, input.vs.uv);
|
albedo *= tex.Sample(s_point_clamp, input.vs.uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grid */
|
/* Grid */
|
||||||
if (input.vs.grid_id < 0xFFFFFFFF) {
|
if (input.vs.grid_id < 0xFFFFFFFF) {
|
||||||
StructuredBuffer<struct k_material_grid> grids = resource_from_urid(sig.grids_urid);
|
StructuredBuffer<K_MaterialGrid> grids = GpuResourceFromUrid(sig.grids_urid);
|
||||||
struct k_material_grid grid = grids[input.vs.grid_id];
|
K_MaterialGrid grid = grids[input.vs.grid_id];
|
||||||
float2 grid_pos = input.vs.SV_Position.xy + grid.offset;
|
Vec2 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;
|
||||||
uint color_srgb = grid.bg0_srgb;
|
u32 color_srgb = grid.bg0_srgb;
|
||||||
float2 v = abs(round(grid_pos / spacing) * spacing - grid_pos);
|
Vec2 v = abs(round(grid_pos / spacing) * spacing - grid_pos);
|
||||||
float dist = min(v.x, v.y);
|
float dist = min(v.x, v.y);
|
||||||
if (grid_pos.y <= half_thickness && grid_pos.y >= -half_thickness) {
|
if (grid_pos.y <= half_thickness && grid_pos.y >= -half_thickness) {
|
||||||
color_srgb = grid.x_srgb;
|
color_srgb = grid.x_srgb;
|
||||||
@ -84,8 +88,8 @@ K_ENTRY struct ps_output ps(struct ps_input input)
|
|||||||
color_srgb = grid.line_srgb;
|
color_srgb = grid.line_srgb;
|
||||||
} else {
|
} else {
|
||||||
bool checker = 0;
|
bool checker = 0;
|
||||||
uint cell_x = (uint)(abs(grid_pos.x) / spacing) + (grid_pos.x < 0);
|
u32 cell_x = (u32)(abs(grid_pos.x) / spacing) + (grid_pos.x < 0);
|
||||||
uint cell_y = (uint)(abs(grid_pos.y) / spacing) + (grid_pos.y < 0);
|
u32 cell_y = (u32)(abs(grid_pos.y) / spacing) + (grid_pos.y < 0);
|
||||||
if (cell_x % 2 == 0) {
|
if (cell_x % 2 == 0) {
|
||||||
checker = cell_y % 2 == 0;
|
checker = cell_y % 2 == 0;
|
||||||
} else {
|
} else {
|
||||||
@ -95,10 +99,10 @@ K_ENTRY struct ps_output ps(struct ps_input input)
|
|||||||
color_srgb = grid.bg1_srgb;
|
color_srgb = grid.bg1_srgb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
albedo = linear_from_srgb32(color_srgb);
|
albedo = LinearFromSrgbU32(color_srgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
float4 emittance = input.vs.emittance_lin * albedo.a;
|
Vec4 emittance = input.vs.emittance_lin * albedo.a;
|
||||||
|
|
||||||
output.SV_Target0 = albedo;
|
output.SV_Target0 = albedo;
|
||||||
output.SV_Target1 = emittance;
|
output.SV_Target1 = emittance;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct k_shade_sig> sig : register(b0);
|
ConstantBuffer<K_ShadeSig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Lighting
|
* Lighting
|
||||||
@ -10,29 +10,29 @@ ConstantBuffer<struct k_shade_sig> sig : register(b0);
|
|||||||
#define MARCHES 16
|
#define MARCHES 16
|
||||||
#define EDGE_FALLOFF 100
|
#define EDGE_FALLOFF 100
|
||||||
|
|
||||||
float rand_angle(uint2 pos, uint ray_index) {
|
float rand_angle(uint2 pos, u32 ray_index) {
|
||||||
Texture3D<uint> noise_tex = resource_from_urid(K_BLUE_NOISE_TEX_ID);
|
Texture3D<u32> noise_tex = GpuResourceFromUrid(K_BLUE_NOISE_TEX_ID);
|
||||||
|
|
||||||
int3 noise_coord = int3(1, 1, 1);
|
Vec3I32 noise_coord = Vec3I32(1, 1, 1);
|
||||||
noise_coord += int3(pos.xy, ray_index);
|
noise_coord += Vec3I32(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(K_BLUE_NOISE_TEX_WIDTH, K_BLUE_NOISE_TEX_HEIGHT, K_BLUE_NOISE_TEX_DEPTH)];
|
u32 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
Vec3 get_light_in_dir(uint2 ray_start, Vec2 ray_dir)
|
||||||
{
|
{
|
||||||
Texture2D<uint2> flood_tex = resource_from_urid(sig.emittance_flood_tex_urid);
|
Texture2D<uint2> flood_tex = GpuResourceFromUrid(sig.emittance_flood_tex_urid);
|
||||||
Texture2D<float4> emittance_tex = resource_from_urid(sig.emittance_tex_urid);
|
Texture2D<Vec4> emittance_tex = GpuResourceFromUrid(sig.emittance_tex_urid);
|
||||||
|
|
||||||
float3 result = float3(0, 0, 0);
|
Vec3 result = Vec3(0, 0, 0);
|
||||||
float2 at_float = ray_start;
|
Vec2 at_float = ray_start;
|
||||||
uint2 at_uint = ray_start;
|
uint2 at_uint = ray_start;
|
||||||
for (uint i = 0; i < MARCHES; ++i) {
|
for (u32 i = 0; i < MARCHES; ++i) {
|
||||||
uint2 flood = flood_tex[at_uint];
|
uint2 flood = flood_tex[at_uint];
|
||||||
float2 dist_vec = at_float - (float2)flood;
|
Vec2 dist_vec = at_float - (Vec2)flood;
|
||||||
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 */
|
||||||
@ -53,13 +53,13 @@ float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 get_light_at_pos(uint2 pos)
|
Vec3 get_light_at_pos(uint2 pos)
|
||||||
{
|
{
|
||||||
float3 result = 0;
|
Vec3 result = 0;
|
||||||
for (uint i = 0; i < SAMPLES; ++i) {
|
for (u32 i = 0; i < SAMPLES; ++i) {
|
||||||
float angle = rand_angle(pos, i);
|
float angle = rand_angle(pos, i);
|
||||||
float2 dir = float2(cos(angle), sin(angle));
|
Vec2 dir = Vec2(cos(angle), sin(angle));
|
||||||
float3 light_in_dir = get_light_in_dir(pos, dir);
|
Vec3 light_in_dir = get_light_in_dir(pos, dir);
|
||||||
result += light_in_dir;
|
result += light_in_dir;
|
||||||
}
|
}
|
||||||
result /= SAMPLES;
|
result /= SAMPLES;
|
||||||
@ -70,19 +70,20 @@ float3 get_light_at_pos(uint2 pos)
|
|||||||
* Entry point
|
* Entry point
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct cs_input {
|
Struct(CsInput)
|
||||||
DECLS(uint3, SV_DispatchThreadID);
|
{
|
||||||
|
Semantic(uint3, SV_DispatchThreadID);
|
||||||
};
|
};
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
[numthreads(8, 8, 1)]
|
||||||
K_ENTRY void cs(struct cs_input input)
|
K_ENTRY void cs(CsInput 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) {
|
||||||
Texture2D<float4> albedo_tex = resource_from_urid(sig.albedo_tex_urid);
|
Texture2D<Vec4> albedo_tex = GpuResourceFromUrid(sig.albedo_tex_urid);
|
||||||
Texture2D<float4> read_tex = resource_from_urid(sig.read_tex_urid);
|
Texture2D<Vec4> read_tex = GpuResourceFromUrid(sig.read_tex_urid);
|
||||||
RWTexture2D<float4> target_tex = resource_from_urid(sig.target_tex_urid);
|
RWTexture2D<Vec4> target_tex = GpuResourceFromUrid(sig.target_tex_urid);
|
||||||
float4 color = float4(1, 1, 1, 1);
|
Vec4 color = Vec4(1, 1, 1, 1);
|
||||||
|
|
||||||
/* Apply albedo */
|
/* Apply albedo */
|
||||||
color *= albedo_tex[id];
|
color *= albedo_tex[id];
|
||||||
|
|||||||
@ -1,27 +1,29 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct k_shape_sig> sig : register(b0);
|
ConstantBuffer<K_ShapeSig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Vertex shader
|
* Vertex shader
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct vs_input {
|
Struct(VsInput)
|
||||||
DECLS(uint, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct vs_output {
|
|
||||||
DECLS(float4, SV_Position);
|
|
||||||
DECLS(float4, color_srgb);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct vs_output vs(struct vs_input input)
|
|
||||||
{
|
{
|
||||||
StructuredBuffer<struct k_shape_vert> verts = resource_from_urid(sig.verts_urid);
|
Semantic(u32, SV_VertexID);
|
||||||
struct k_shape_vert vert = verts[input.SV_VertexID];
|
};
|
||||||
struct vs_output output;
|
|
||||||
output.SV_Position = mul(sig.projection, float4(vert.pos.xy, 0, 1));
|
Struct(VSOutput)
|
||||||
output.color_srgb = float4_from_uint_norm(vert.color_srgb);
|
{
|
||||||
|
Semantic(Vec4, SV_Position);
|
||||||
|
Semantic(Vec4, color_srgb);
|
||||||
|
};
|
||||||
|
|
||||||
|
K_ENTRY VSOutput vs(VsInput input)
|
||||||
|
{
|
||||||
|
StructuredBuffer<K_ShapeVert> verts = GpuResourceFromUrid(sig.verts_urid);
|
||||||
|
K_ShapeVert vert = verts[input.SV_VertexID];
|
||||||
|
VSOutput output;
|
||||||
|
output.SV_Position = mul(sig.projection, Vec4(vert.pos.xy, 0, 1));
|
||||||
|
output.color_srgb = Vec4NormFromU32(vert.color_srgb);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,17 +31,19 @@ K_ENTRY struct vs_output vs(struct vs_input input)
|
|||||||
* Pixel shader
|
* Pixel shader
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
struct ps_input {
|
Struct(PsInput)
|
||||||
struct vs_output vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ps_output {
|
|
||||||
DECLS(float4, SV_Target);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct ps_output ps(struct ps_input input)
|
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
VSOutput vs;
|
||||||
|
};
|
||||||
|
|
||||||
|
Struct(PSOutput)
|
||||||
|
{
|
||||||
|
Semantic(Vec4, SV_Target);
|
||||||
|
};
|
||||||
|
|
||||||
|
K_ENTRY PSOutput ps(PsInput input)
|
||||||
|
{
|
||||||
|
PSOutput output;
|
||||||
output.SV_Target = input.vs.color_srgb;
|
output.SV_Target = input.vs.color_srgb;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,65 +1,73 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
ConstantBuffer<struct k_ui_sig> sig : register(b0);
|
ConstantBuffer<K_UiSig> sig : register(b0);
|
||||||
|
|
||||||
/* ========================== *
|
////////////////////////////////
|
||||||
* Vertex shader
|
//~ Shader types
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
struct vs_input {
|
//- Vertex shader in/out
|
||||||
DECLS(uint, SV_InstanceID);
|
Struct(VsInput)
|
||||||
DECLS(uint, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct vs_output {
|
|
||||||
nointerpolation DECLS(uint, tex_nurid);
|
|
||||||
DECLS(float2, uv);
|
|
||||||
DECLS(float4, tint_srgb);
|
|
||||||
DECLS(float4, SV_Position);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct vs_output vs(struct vs_input input)
|
|
||||||
{
|
{
|
||||||
static const float2 unit_quad_verts[4] = {
|
Semantic(u32, SV_InstanceID);
|
||||||
float2(-0.5f, -0.5f),
|
Semantic(u32, SV_VertexID);
|
||||||
float2(0.5f, -0.5f),
|
};
|
||||||
float2(0.5f, 0.5f),
|
|
||||||
float2(-0.5f, 0.5f)
|
Struct(VSOutput)
|
||||||
|
{
|
||||||
|
nointerpolation Semantic(u32, tex_nurid);
|
||||||
|
Semantic(Vec2, uv);
|
||||||
|
Semantic(Vec4, tint_srgb);
|
||||||
|
Semantic(Vec4, SV_Position);
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Pixel shader in/out
|
||||||
|
Struct(PsInput)
|
||||||
|
{
|
||||||
|
VSOutput vs;
|
||||||
|
};
|
||||||
|
|
||||||
|
Struct(PSOutput)
|
||||||
|
{
|
||||||
|
Semantic(Vec4, SV_Target0);
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
//~ Vertex shader
|
||||||
|
|
||||||
|
K_ENTRY VSOutput vs(VsInput input)
|
||||||
|
{
|
||||||
|
static const Vec2 unit_quad_verts[4] = {
|
||||||
|
Vec2(-0.5f, -0.5f),
|
||||||
|
Vec2(0.5f, -0.5f),
|
||||||
|
Vec2(0.5f, 0.5f),
|
||||||
|
Vec2(-0.5f, 0.5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
StructuredBuffer<struct k_ui_instance> instances = resource_from_urid(sig.instances_urid);
|
StructuredBuffer<K_UiInstance> instances = GpuResourceFromUrid(sig.instances_urid);
|
||||||
struct k_ui_instance instance = instances[input.SV_InstanceID];
|
K_UiInstance instance = instances[input.SV_InstanceID];
|
||||||
float2 vert = unit_quad_verts[input.SV_VertexID];
|
Vec2 vert = unit_quad_verts[input.SV_VertexID];
|
||||||
float2 world_pos = mul(instance.xf, float3(vert, 1)).xy;
|
Vec2 world_pos = mul(instance.xf, Vec3(vert, 1)).xy;
|
||||||
|
|
||||||
struct vs_output output;
|
VSOutput output;
|
||||||
output.SV_Position = mul(sig.projection, float4(world_pos, 0, 1));
|
output.SV_Position = mul(sig.projection, Vec4(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_from_uint_norm(instance.tint_srgb);
|
output.tint_srgb = Vec4NormFromU32(instance.tint_srgb);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
////////////////////////////////
|
||||||
* Pixel shader
|
//~ Pixel shader
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
struct ps_input {
|
K_ENTRY PSOutput ps(PsInput input)
|
||||||
struct vs_output vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ps_output {
|
|
||||||
DECLS(float4, SV_Target0);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY struct ps_output ps(struct ps_input input)
|
|
||||||
{
|
{
|
||||||
struct ps_output output;
|
PSOutput output;
|
||||||
float4 color = input.vs.tint_srgb;
|
Vec4 color = input.vs.tint_srgb;
|
||||||
|
|
||||||
/* Texture */
|
/* Texture */
|
||||||
if (input.vs.tex_nurid < 0xFFFFFFFF) {
|
if (input.vs.tex_nurid < 0xFFFFFFFF)
|
||||||
Texture2D<float4> tex = resource_from_nurid(input.vs.tex_nurid);
|
{
|
||||||
|
Texture2D<Vec4> tex = GpuResourceFromNurid(input.vs.tex_nurid);
|
||||||
color *= tex.Sample(s_point_clamp, input.vs.uv);
|
color *= tex.Sample(s_point_clamp, input.vs.uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user