Skip to content

Commit

Permalink
Fixing minor formatting in shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
Honeybunch committed Sep 5, 2024
1 parent c2b1ad4 commit 808266f
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 214 deletions.
4 changes: 2 additions & 2 deletions include/tb_common.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#define TB_GPU_STRUCT_DECL(name, body) \
_TB_GPU_STRUCT_START name body _TB_GPU_STRUCT_END(name)

#define TB_GPU_STRUCT_DECL_NOPACK(name, body) \
#define TB_GPU_STRUCT_DECL_NOPACK(name, body) \
_TB_GPU_STRUCT_START_NOPACK name body _TB_GPU_STRUCT_END(name)

TB_GPU_STRUCT_DECL(TbCommonObjectData, {float4x4 m;});
TB_GPU_STRUCT_DECL(TbCommonObjectData, { float4x4 m; });

// Common input layout info and permutation settings
#define TB_INPUT_PERM_NONE 0x00000000
Expand Down
24 changes: 12 additions & 12 deletions include/tb_cube_view_lut.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ HLSL.
of the above code when recording it here
*/
static const column_major float4x4 view_proj_lut[6] = {
// X+
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1.001001, -0.00100100099, 0, 0, -1, 0},
// X-
{-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1.001001, -0.00100100099, 0, 0, 1, 0},
// Y+
{0, 0, -1, 0, 1, 0, 0, 0, 0, 1.001001, 0, -0.00100100099, 0, 1, 0, 0},
// Y-
{0, 0, -1, 0, -1, 0, 0, 0, 0, -1.001001, 0, -0.00100100099, 0, -1, 0, 0},
// Z+
{0, 0, -1, 0, 0, 1, 0, 0, -1.001001, 0, 0, -0.00100100099, -1, 0, 0, 0},
// Z-
{0, 0, 1, 0, 0, 1, 0, 0, 1.00010001, 0, 0, -0.00100100099, 1, 0, 0, 0},
// X+
{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1.001001, -0.00100100099, 0, 0, -1, 0 },
// X-
{ -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1.001001, -0.00100100099, 0, 0, 1, 0 },
// Y+
{ 0, 0, -1, 0, 1, 0, 0, 0, 0, 1.001001, 0, -0.00100100099, 0, 1, 0, 0 },
// Y-
{ 0, 0, -1, 0, -1, 0, 0, 0, 0, -1.001001, 0, -0.00100100099, 0, -1, 0, 0 },
// Z+
{ 0, 0, -1, 0, 0, 1, 0, 0, -1.001001, 0, 0, -0.00100100099, -1, 0, 0, 0 },
// Z-
{ 0, 0, 1, 0, 0, 1, 0, 0, 1.00010001, 0, 0, -0.00100100099, 1, 0, 0, 0 },
};
14 changes: 6 additions & 8 deletions include/tb_fullscreenvert.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ struct Interpolators {
#ifdef TB_SHADER
[shader("vertex")]
#endif
Interpolators
vert(uint i
: SV_VERTEXID) {
Interpolators o;
o.uv0 = float2(uint2(i, i << 1) & 2);
o.pos = float4(lerp(float2(-1, 1), float2(1, -1), o.uv0), 0.5f, 1.0f);
return o;
}
Interpolators vert(uint i: SV_VERTEXID) {
Interpolators o;
o.uv0 = float2(uint2(i, i << 1) & 2);
o.pos = float4(lerp(float2(-1, 1), float2(1, -1), o.uv0), 0.5f, 1.0f);
return o;
}
13 changes: 6 additions & 7 deletions include/tb_fxaa.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ TB_GPU_STRUCT_DECL(TbFXAAPushConstants, {
float search_threshold;
});


#ifdef TB_SHADER

#define FXAA_SET(b) \
[[vk::binding(0, b)]]\
Texture2D input; \
[[vk::binding(1, b)]]\
SamplerState in_sampler;\
[[vk::binding(2, b)]]\
#define FXAA_SET(b) \
[[vk::binding(0, b)]] \
Texture2D input; \
[[vk::binding(1, b)]] \
SamplerState in_sampler; \
[[vk::binding(2, b)]] \
[[vk::push_constant]] \
ConstantBuffer<TbFXAAPushConstants> consts;

Expand Down
44 changes: 26 additions & 18 deletions include/tb_gltf.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TB_GPU_STRUCT_DECL(TextureTransform, {
float2 scale;
});

TB_GPU_STRUCT_DECL(PBRMetallicRoughness,{
TB_GPU_STRUCT_DECL(PBRMetallicRoughness, {
float4 base_color_factor;
float4 metal_rough_factors;
});
Expand All @@ -35,7 +35,7 @@ TB_GPU_STRUCT_DECL(PBRSpecularGlossiness, {
float4 spec_gloss_factors;
});

TB_GPU_STRUCT_DECL(TbGLTFMaterialData,{
TB_GPU_STRUCT_DECL(TbGLTFMaterialData, {
TextureTransform tex_transform;
PBRMetallicRoughness pbr_metallic_roughness;
PBRSpecularGlossiness pbr_specular_glossiness;
Expand Down Expand Up @@ -64,10 +64,6 @@ TB_GPU_STRUCT_DECL(TbGLTFDrawData, {

#define ALPHA_CUTOFF(m) m.sheen_alpha.w

#if defined(TB_SHADER) && !defined(TB_SHADER)
#define TB_SHADER 1
#endif

// If a shader, provide some helper functions and macros
#if defined(TB_SHADER)
float2 uv_transform(int2 quant_uv, TextureTransform trans) {
Expand All @@ -82,22 +78,34 @@ float2 uv_transform(int2 quant_uv, TextureTransform trans) {
// by specific systems

#define GLTF_MATERIAL_SET(b) \
[[vk::binding(0, b)]] SamplerState material_sampler; \
[[vk::binding(1, b)]] SamplerComparisonState shadow_sampler; \
[[vk::binding(2, b)]] StructuredBuffer<TbGLTFMaterialData> gltf_data[];
[[vk::binding(0, b)]] \
SamplerState material_sampler; \
[[vk::binding(1, b)]] \
SamplerComparisonState shadow_sampler; \
[[vk::binding(2, b)]] \
StructuredBuffer<TbGLTFMaterialData> gltf_data[];

#define GLTF_DRAW_SET(b) \
[[vk::binding(0, b)]] StructuredBuffer<TbGLTFDrawData> draw_data;
[[vk::binding(0, b)]] \
StructuredBuffer<TbGLTFDrawData> draw_data;

#define GLTF_VIEW_SET(b) \
[[vk::binding(0, b)]] ConstantBuffer<TbViewData> camera_data; \
[[vk::binding(1, b)]] TextureCube irradiance_map; \
[[vk::binding(2, b)]] TextureCube prefiltered_map; \
[[vk::binding(3, b)]] Texture2D brdf_lut; \
[[vk::binding(4, b)]] ConstantBuffer<TbLightData> light_data; \
[[vk::binding(5, b)]] Texture2DArray shadow_map; \
[[vk::binding(6, b)]] SamplerState filtered_env_sampler; \
[[vk::binding(7, b)]] SamplerState brdf_sampler;
[[vk::binding(0, b)]] \
ConstantBuffer<TbViewData> camera_data; \
[[vk::binding(1, b)]] \
TextureCube irradiance_map; \
[[vk::binding(2, b)]] \
TextureCube prefiltered_map; \
[[vk::binding(3, b)]] \
Texture2D brdf_lut; \
[[vk::binding(4, b)]] \
ConstantBuffer<TbLightData> light_data; \
[[vk::binding(5, b)]] \
Texture2DArray shadow_map; \
[[vk::binding(6, b)]] \
SamplerState filtered_env_sampler; \
[[vk::binding(7, b)]] \
SamplerState brdf_sampler;

#define GLTF_OPAQUE_LIGHTING(out, color, normal, view, refl, s_uv, met, rough) \
{ \
Expand Down
9 changes: 5 additions & 4 deletions include/tb_lighting.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "tb_pbr.slangh"

TB_GPU_STRUCT_DECL_NOPACK(TbLightData,{
TB_GPU_STRUCT_DECL_NOPACK(TbLightData, {
float3 color;
float3 light_dir;
float4 cascade_splits;
Expand Down Expand Up @@ -293,9 +293,10 @@ float shadow_visibility(Light l, Surface s) {
}
}

const float3 cascade_colors[TB_CASCADE_COUNT] = {
float3(1.0f, 0.0, 0.0f), float3(0.0f, 1.0f, 0.0f),
float3(0.0f, 0.0f, 1.0f), float3(1.0f, 1.0f, 0.0f)};
const float3 cascade_colors[TB_CASCADE_COUNT] = { float3(1.0f, 0.0, 0.0f),
float3(0.0f, 1.0f, 0.0f),
float3(0.0f, 0.0f, 1.0f),
float3(1.0f, 1.0f, 0.0f) };

// return cascade_colors[cascade_idx];

Expand Down
4 changes: 1 addition & 3 deletions include/tb_luminance.slangh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

#include "tb_common.slangh"

TB_GPU_STRUCT_DECL(TbLuminancePushConstants, {
float4 params;
});
TB_GPU_STRUCT_DECL(TbLuminancePushConstants, { float4 params; });
63 changes: 28 additions & 35 deletions source/tb_blur_h.slangc
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,47 @@ static const int sample_count = radius * 2;
static const int cache_size = GROUP_SIZE + 2 * radius;
static const int load = (cache_size + (GROUP_SIZE - 1)) / GROUP_SIZE;

groupshared float4 cache[cache_size] ;
groupshared float4 cache[cache_size];

[numthreads(GROUP_SIZE, 1, 1)]
[shader("compute")]
void comp(int3 group_id: SV_GroupID, int3 group_thread_id: SV_GroupThreadID,
int3 dispatch_thread_id: SV_DispatchThreadID) {

int2 size;
input.GetDimensions(size.x, size.y);
int2 pixel_coord = dispatch_thread_id.xy;

int origin = int(group_id.x) * GROUP_SIZE - radius;
for (int i = 0; i < load; ++i)
{
int local = int(group_thread_id.x) * load + i;
if (local < cache_size)
{
int pc = origin + local;
if (pc >= 0 && pc < size.x)
{
cache[local] = input[int2(pc, pixel_coord.y)];
input.GetDimensions(size.x, size.y);
int2 pixel_coord = dispatch_thread_id.xy;

int origin = int(group_id.x) * GROUP_SIZE - radius;
for (int i = 0; i < load; ++i) {
int local = int(group_thread_id.x) * load + i;
if (local < cache_size) {
int pc = origin + local;
if (pc >= 0 && pc < size.x) {
cache[local] = input[int2(pc, pixel_coord.y)];
}
}
}
}

DeviceMemoryBarrier();
GroupMemoryBarrierWithGroupSync();
DeviceMemoryBarrier();
GroupMemoryBarrierWithGroupSync();

if (pixel_coord.x < size.x && pixel_coord.y < size.y)
{
float4 result = 0;
if (pixel_coord.x < size.x && pixel_coord.y < size.y) {
float4 result = 0;

for (int i = -radius; i < radius; ++i)
{
int2 pc = pixel_coord + int2(i, 0);
if (pc.x < 0)
{
pc.x = 0;
}
if (pc.x >= size.x)
{
pc.x = size.x - 1;
for (int i = -radius; i < radius; ++i) {
int2 pc = pixel_coord + int2(i, 0);
if (pc.x < 0) {
pc.x = 0;
}
if (pc.x >= size.x) {
pc.x = size.x - 1;
}

int local = pc.x - origin;
result += cache[local];
}

int local = pc.x - origin;
result += cache[local];
output[dispatch_thread_id.xy] = result / sample_count;
}

output[dispatch_thread_id.xy] = result / sample_count;
}
}
63 changes: 28 additions & 35 deletions source/tb_blur_v.slangc
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,47 @@ static const int sample_count = radius * 2;
static const int cache_size = GROUP_SIZE + 2 * radius;
static const int load = (cache_size + (GROUP_SIZE - 1)) / GROUP_SIZE;

groupshared float4 cache[cache_size] ;
groupshared float4 cache[cache_size];

[numthreads(1, GROUP_SIZE, 1)]
[shader("compute")]
void comp(int3 group_id: SV_GroupID, int3 group_thread_id: SV_GroupThreadID,
int3 dispatch_thread_id: SV_DispatchThreadID) {

int2 size;
input.GetDimensions(size.x, size.y);
int2 pixel_coord = dispatch_thread_id.xy;

int origin = int(group_id.y) * GROUP_SIZE - radius;
for (int i = 0; i < load; ++i)
{
int local = int(group_thread_id.y) * load + i;
if (local < cache_size)
{
int pc = origin + local;
if (pc >= 0 && pc < size.x)
{
cache[local] = input[int2(pixel_coord.x, pc)];
input.GetDimensions(size.x, size.y);
int2 pixel_coord = dispatch_thread_id.xy;

int origin = int(group_id.y) * GROUP_SIZE - radius;
for (int i = 0; i < load; ++i) {
int local = int(group_thread_id.y) * load + i;
if (local < cache_size) {
int pc = origin + local;
if (pc >= 0 && pc < size.x) {
cache[local] = input[int2(pixel_coord.x, pc)];
}
}
}
}

DeviceMemoryBarrier();
GroupMemoryBarrierWithGroupSync();
DeviceMemoryBarrier();
GroupMemoryBarrierWithGroupSync();

if (pixel_coord.x < size.x && pixel_coord.y < size.y)
{
float4 result = 0;
if (pixel_coord.x < size.x && pixel_coord.y < size.y) {
float4 result = 0;

for (int i = -radius; i < radius; ++i)
{
int2 pc = pixel_coord + int2(0, i);
if (pc.y < 0)
{
pc.y = 0;
}
if (pc.y >= size.y)
{
pc.y = size.y - 1;
for (int i = -radius; i < radius; ++i) {
int2 pc = pixel_coord + int2(0, i);
if (pc.y < 0) {
pc.y = 0;
}
if (pc.y >= size.y) {
pc.y = size.y - 1;
}

int local = pc.y - origin;
result += cache[local];
}

int local = pc.y - origin;
result += cache[local];
output[dispatch_thread_id.xy] = result / sample_count;
}

output[dispatch_thread_id.xy] = result / sample_count;
}
}
12 changes: 6 additions & 6 deletions source/tb_copy.slangc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ SamplerState static_sampler;
void comp(int3 group_thread_id: SV_GroupThreadID,
int3 dispatch_thread_id: SV_DispatchThreadID) {
float2 resolution;
input.GetDimensions(resolution.x, resolution.y);
float2 tex_offset = 1 / resolution;
input.GetDimensions(resolution.x, resolution.y);
float2 tex_offset = 1 / resolution;

float2 uv = dispatch_thread_id.xy / resolution;
float4 value = input.SampleLevel(static_sampler, uv, 0);
output[dispatch_thread_id.xy] = value;
}
float2 uv = dispatch_thread_id.xy / resolution;
float4 value = input.SampleLevel(static_sampler, uv, 0);
output[dispatch_thread_id.xy] = value;
}
Loading

0 comments on commit 808266f

Please sign in to comment.