Skip to content

Commit

Permalink
Use custom HLSL cross-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Jan 27, 2024
1 parent 4ec4af1 commit 3e68ec2
Show file tree
Hide file tree
Showing 89 changed files with 383 additions and 384 deletions.
Binary file modified first-party/glslx/win32/glslx.exe
Binary file not shown.
Binary file added first-party/linux/glslx
Binary file not shown.
Binary file added first-party/macos/glslx
Binary file not shown.
16 changes: 11 additions & 5 deletions internal/shaders/intersect_scene.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,18 @@ void main() {
const float q = can_terminate_path ? max(0.05, 1.0 - lum) : 0.0;
if (p < q || lum == 0.0 || get_transp_depth(g_rays[index].depth) + 1 >= g_params.max_transp_depth) {
// terminate ray
g_rays[index].c[0] = g_rays[index].c[1] = g_rays[index].c[2] = 0.0;
g_rays[index].c[0] = 0.0;
g_rays[index].c[1] = 0.0;
g_rays[index].c[2] = 0.0;
break;
}

g_rays[index].c[0] *= mat.base_color[0] / (1.0 - q);
g_rays[index].c[1] *= mat.base_color[1] / (1.0 - q);
g_rays[index].c[2] *= mat.base_color[2] / (1.0 - q);
float c[3] = {g_rays[index].c[0] * mat.base_color[0] / (1.0 - q),
g_rays[index].c[1] * mat.base_color[1] / (1.0 - q),
g_rays[index].c[2] * mat.base_color[2] / (1.0 - q)};
g_rays[index].c[0] = c[0];
g_rays[index].c[1] = c[1];
g_rays[index].c[2] = c[2];

const float t = inter.t + HIT_BIAS;
ro += rd * t;
Expand All @@ -318,7 +323,8 @@ void main() {
inter.v = -1.0;
inter.t = t_val - inter.t;

g_rays[index].depth += pack_ray_depth(0, 0, 0, 1);
uint depth = g_rays[index].depth + pack_ray_depth(0, 0, 0, 1);
g_rays[index].depth = depth;
rand_dim += RAND_DIM_BOUNCE_COUNT;
}

Expand Down
6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_112_112_fp16.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_112_112_fp32.comp.cso.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_64_32_fp16.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_64_32_fp32.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_64_64_fp16.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_64_64_fp32.comp.cso.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_80_96_fp16.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_80_96_fp32.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_96_96_fp16.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/convolution_96_96_fp32.comp.cso.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/debug_rt.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/filter_variance.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_area_lights.comp.cso.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/mix_incremental.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/nlm_filter.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/postprocess.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/prepare_indir_args.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/primary_ray_gen_adaptive.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/primary_ray_gen_simple.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_atlas.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_atlas.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_bindless.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_primary_bindless.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_atlas.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_atlas.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_bindless.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_bindless.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_hash_rays.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_init_count_table.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_init_count_table.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_reduce.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_reorder_rays.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_scan.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_scan_add.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_scatter.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/sort_scatter.comp.spv.inl

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions internal/shaders/shade.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -600,17 +600,25 @@ float pop_ior_stack(inout float stack[4], float default_value) {
}

float peek_ior_stack(float stack[4], bool skip_first, float default_value) {
if (stack[3] > 0.0 && !exchange(skip_first, false)) {
return stack[3];
if (stack[3] > 0.0) {
if (!exchange(skip_first, false)) {
return stack[3];
}
}
if (stack[2] > 0.0 && !exchange(skip_first, false)) {
return stack[2];
if (stack[2] > 0.0) {
if (!exchange(skip_first, false)) {
return stack[2];
}
}
if (stack[1] > 0.0 && !exchange(skip_first, false)) {
return stack[1];
if (stack[1] > 0.0) {
if (!exchange(skip_first, false)) {
return stack[1];
}
}
if (stack[0] > 0.0 && !exchange(skip_first, false)) {
return stack[0];
if (stack[0] > 0.0) {
if (!exchange(skip_first, false)) {
return stack[0];
}
}
return default_value;
}
Expand Down Expand Up @@ -909,10 +917,10 @@ void SampleLightSource(vec3 P, vec3 T, vec3 B, vec3 N, const float rand_pick_lig

#if USE_HIERARCHICAL_NEE
float factor = 1.0;
uint i = 0; // start from root
while ((g_light_wnodes[i].child[0] & LEAF_NODE_BIT) == 0) {
light_wbvh_node_t n = g_light_wnodes[0]; // start from root
while ((n.child[0] & LEAF_NODE_BIT) == 0) {
float importance[8];
const float total_importance = calc_lnode_importance(g_light_wnodes[i], P, importance);
const float total_importance = calc_lnode_importance(n, P, importance);
[[dont_flatten]] if (total_importance == 0.0) {
// failed to find lightsource for sampling
return;
Expand Down Expand Up @@ -943,10 +951,10 @@ void SampleLightSource(vec3 P, vec3 T, vec3 B, vec3 N, const float rand_pick_lig
}

u1 = fract((u1 - importance_cdf[next]) / importance[next]);
i = g_light_wnodes[i].child[next];
n = g_light_wnodes[n.child[next]];
factor *= importance[next];
}
const uint light_index = (g_light_wnodes[i].child[0] & PRIM_INDEX_BITS);
const uint light_index = (n.child[0] & PRIM_INDEX_BITS);
factor = (1.0 / factor);
#else
uint light_index = min(uint(u1 * g_params.li_count), uint(g_params.li_count - 1));
Expand Down
18 changes: 9 additions & 9 deletions internal/shaders/sort_init_count_table.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ layout (local_size_x = SORT_THREADGROUP_SIZE, local_size_y = 1, local_size_z = 1

void main() {
const int li = int(gl_LocalInvocationID.x), wi = int(gl_WorkGroupID.x);
for (int i = 0; i < 0x10; ++i) {
g_shared_counters[i * SORT_THREADGROUP_SIZE + li] = 0;
for (int i1 = 0; i1 < 0x10; ++i1) {
g_shared_counters[i1 * SORT_THREADGROUP_SIZE + li] = 0;
}
groupMemoryBarrier(); barrier();

Expand All @@ -40,15 +40,15 @@ void main() {
int data_index = block_start + li;

uint hashes[SORT_ELEMENTS_PER_THREAD];
[[unroll]] for (int i = 0; i < SORT_ELEMENTS_PER_THREAD; ++i) {
if (data_index + i * SORT_THREADGROUP_SIZE < data_count) {
hashes[i] = g_hashes[data_index + i * SORT_THREADGROUP_SIZE].hash;
[[unroll]] for (int i2 = 0; i2 < SORT_ELEMENTS_PER_THREAD; ++i2) {
if (data_index + i2 * SORT_THREADGROUP_SIZE < data_count) {
hashes[i2] = g_hashes[data_index + i2 * SORT_THREADGROUP_SIZE].hash;
}
}

for (int i = 0; i < SORT_ELEMENTS_PER_THREAD; ++i) {
for (int i3 = 0; i3 < SORT_ELEMENTS_PER_THREAD; ++i3) {
if (data_index < data_count) {
uint local_key = (hashes[i] >> g_params.shift) & 0xf;
uint local_key = (hashes[i3] >> g_params.shift) & 0xf;
atomicAdd(g_shared_counters[local_key * SORT_THREADGROUP_SIZE + li], 1u);
data_index += SORT_THREADGROUP_SIZE;
}
Expand All @@ -58,8 +58,8 @@ void main() {

if (li < 0x10) {
uint sum = 0;
for (int i = 0; i < SORT_THREADGROUP_SIZE; ++i) {
sum += g_shared_counters[li * SORT_THREADGROUP_SIZE + i];
for (int i4 = 0; i4 < SORT_THREADGROUP_SIZE; ++i4) {
sum += g_shared_counters[li * SORT_THREADGROUP_SIZE + i4];
}
g_count_table[li * block_count + wi] = sum;
}
Expand Down
5 changes: 4 additions & 1 deletion internal/shaders/sort_scatter.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ void main() {
g_shared_local_counters[li] = 0;
}

ray_hash_t local_key = (data_index < data_count) ? src_keys[i] : ray_hash_t(0xffffffff, 0xffffffff);
ray_hash_t local_key = ray_hash_t(0xffffffff, 0xffffffff);
if (data_index < data_count) {
local_key = src_keys[i];
}

for (uint bit_shift = 0; bit_shift < SORT_BITS_PER_PASS; bit_shift += 2) {
uint key_index = (local_key.hash >> g_params.shift) & 0xf;
Expand Down
Loading

0 comments on commit 3e68ec2

Please sign in to comment.