Skip to content

Commit 74508f2

Browse files
committed
shader updates
1 parent 6a9ee9b commit 74508f2

5 files changed

Lines changed: 52 additions & 73 deletions

File tree

WickedEngine/shaders/ShaderInterop_Renderer.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,11 +1179,6 @@ struct ShaderEntityIterator
11791179
{
11801180
return ~0u >> (31u - (last_item() % 32u));
11811181
}
1182-
// This masks out inactive buckets of the current type based on a whole tile bucket mask
1183-
inline uint mask_type(uint tile_mask)
1184-
{
1185-
return tile_mask & bucket_mask();
1186-
}
11871182
// This masks out inactive entities for the current bucket type when processing either the first or the last bucket in the list
11881183
inline uint mask_entity(uint bucket, uint bucket_bits)
11891184
{
@@ -1558,7 +1553,7 @@ CBUFFER(MiscCB, CBSLOT_RENDERER_MISC)
15581553

15591554
CBUFFER(ForwardEntityMaskCB, CBSLOT_RENDERER_FORWARD_LIGHTMASK)
15601555
{
1561-
uint2 xForwardLightMask; // supports indexing 64 lights
1556+
uint64_t xForwardLightMask; // supports indexing 64 lights
15621557
uint xForwardDecalMask; // supports indexing 32 decals
15631558
uint xForwardEnvProbeMask; // supports indexing 32 environment probes
15641559
};

WickedEngine/shaders/shadingHF.hlsli

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -112,56 +112,47 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting)
112112
}
113113

114114
[branch]
115-
if (any(xForwardLightMask))
115+
if (xForwardLightMask != 0)
116116
{
117117
// Loop through light buckets for the draw call:
118-
const uint first_item = 0;
119-
const uint last_item = first_item + lights().item_count() - 1;
120-
const uint first_bucket = first_item / 32;
121-
const uint last_bucket = min(last_item / 32, 1); // only 2 buckets max (uint2) for forward pass!
118+
uint bucket_bits = xForwardLightMask;
119+
122120
[loop]
123-
for (uint bucket = first_bucket; bucket <= last_bucket; ++bucket)
121+
while (bucket_bits != 0)
124122
{
125-
uint bucket_bits = xForwardLightMask[bucket];
126-
127-
[loop]
128-
while (bucket_bits != 0)
129-
{
130-
// Retrieve global entity index from local bucket, then remove bit from local bucket:
131-
const uint bucket_bit_index = firstbitlow(bucket_bits);
132-
const uint entity_index = bucket * 32 + bucket_bit_index;
133-
bucket_bits ^= 1u << bucket_bit_index;
123+
// Retrieve global entity index from local bucket, then remove bit from local bucket:
124+
const uint entity_index = firstbitlow(bucket_bits);
125+
bucket_bits ^= 1u << entity_index;
134126

135-
ShaderEntity light = load_entity(lights().first_item() + entity_index);
127+
ShaderEntity light = load_entity(lights().first_item() + entity_index);
136128

137129
#ifndef INCLUDE_STATIC_LIGHTS
138-
if (light.IsStaticLight())
139-
continue; // static lights will be skipped here (they are used at lightmap baking)
130+
if (light.IsStaticLight())
131+
continue; // static lights will be skipped here (they are used at lightmap baking)
140132
#endif // INCLUDE_STATIC_LIGHTS
141133

142-
switch (light.GetType())
143-
{
144-
case ENTITY_TYPE_DIRECTIONALLIGHT:
145-
{
146-
light_directional(light, surface, lighting);
147-
}
148-
break;
149-
case ENTITY_TYPE_POINTLIGHT:
150-
{
151-
light_point(light, surface, lighting);
152-
}
153-
break;
154-
case ENTITY_TYPE_SPOTLIGHT:
155-
{
156-
light_spot(light, surface, lighting);
157-
}
158-
break;
159-
case ENTITY_TYPE_RECTLIGHT:
160-
{
161-
light_rect(light, surface, lighting);
162-
}
163-
break;
164-
}
134+
switch (light.GetType())
135+
{
136+
case ENTITY_TYPE_DIRECTIONALLIGHT:
137+
{
138+
light_directional(light, surface, lighting);
139+
}
140+
break;
141+
case ENTITY_TYPE_POINTLIGHT:
142+
{
143+
light_point(light, surface, lighting);
144+
}
145+
break;
146+
case ENTITY_TYPE_SPOTLIGHT:
147+
{
148+
light_spot(light, surface, lighting);
149+
}
150+
break;
151+
case ENTITY_TYPE_RECTLIGHT:
152+
{
153+
light_rect(light, surface, lighting);
154+
}
155+
break;
165156
}
166157
}
167158
}
@@ -298,7 +289,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
298289
{
299290
// Loop through envmap buckets in the tile:
300291
ShaderEntityIterator iterator = probes();
301-
for(uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
292+
for (uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
302293
{
303294
uint bucket_bits = load_entitytile(flatTileIndex + bucket);
304295
bucket_bits = iterator.mask_entity(bucket, bucket_bits);
@@ -403,7 +394,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
403394
{
404395
// Directional lights are not culled, so simply iterate through each one:
405396
ShaderEntityIterator iterator = directional_lights();
406-
for(uint entity_index = iterator.first_item(); entity_index < iterator.end_item(); ++entity_index)
397+
for (uint entity_index = iterator.first_item(); entity_index < iterator.end_item(); ++entity_index)
407398
{
408399
ShaderEntity light = load_entity(entity_index);
409400

@@ -434,7 +425,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
434425
{
435426
// Loop through light buckets in the tile:
436427
ShaderEntityIterator iterator = spotlights();
437-
for(uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
428+
for (uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
438429
{
439430
uint bucket_bits = load_entitytile(flatTileIndex + bucket);
440431
bucket_bits = iterator.mask_entity(bucket, bucket_bits);
@@ -476,7 +467,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
476467
{
477468
// Loop through light buckets in the tile:
478469
ShaderEntityIterator iterator = pointlights();
479-
for(uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
470+
for (uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
480471
{
481472
uint bucket_bits = load_entitytile(flatTileIndex + bucket);
482473
bucket_bits = iterator.mask_entity(bucket, bucket_bits);
@@ -518,7 +509,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
518509
{
519510
// Loop through light buckets in the tile:
520511
ShaderEntityIterator iterator = rectlights();
521-
for(uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
512+
for (uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
522513
{
523514
uint bucket_bits = load_entitytile(flatTileIndex + bucket);
524515
bucket_bits = iterator.mask_entity(bucket, bucket_bits);
@@ -564,9 +555,9 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
564555
half capsuleshadow = 1;
565556
half capsulereflection = 1;
566557

567-
// Loop through light buckets in the tile:
558+
// Loop through entity buckets in the tile:
568559
ShaderEntityIterator iterator = forces();
569-
for (uint bucket = iterator.first_bucket(); (bucket <= iterator.last_bucket()) && (capsuleshadow > 0 || capsulereflection > 0); ++bucket)
560+
for (uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
570561
{
571562
uint bucket_bits = load_entitytile(flatTileIndex + bucket);
572563
bucket_bits = iterator.mask_entity(bucket, bucket_bits);
@@ -641,7 +632,7 @@ inline void TiledDecals(inout Surface surface, uint flatTileIndex, inout half4 s
641632

642633
// Loop through decal buckets in the tile:
643634
ShaderEntityIterator iterator = decals();
644-
for(uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
635+
for (uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
645636
{
646637
uint bucket_bits = load_entitytile(flatTileIndex + bucket);
647638
bucket_bits = iterator.mask_entity(bucket, bucket_bits);

WickedEngine/shaders/surfaceHF.hlsli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ struct Surface
782782

783783
// Loop through decal buckets in the tile:
784784
ShaderEntityIterator iterator = decals();
785-
for(uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
785+
for (uint bucket = iterator.first_bucket(); bucket <= iterator.last_bucket(); ++bucket)
786786
{
787787
uint bucket_bits = load_entitytile(flatTileIndex + bucket);
788788
bucket_bits = iterator.mask_entity(bucket, bucket_bits);

WickedEngine/wiRenderer.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,35 +3113,28 @@ ForwardEntityMaskCB ForwardEntityCullingCPU(const Visibility& vis, const AABB& b
31133113
// Performs CPU light culling for a renderable batch:
31143114
// Similar to GPU-based tiled light culling, but this is only for simple forward passes (drawcall-granularity)
31153115

3116-
ForwardEntityMaskCB cb;
3117-
cb.xForwardLightMask.x = 0;
3118-
cb.xForwardLightMask.y = 0;
3119-
cb.xForwardDecalMask = 0;
3120-
cb.xForwardEnvProbeMask = 0;
3116+
ForwardEntityMaskCB cb = {};
31213117

3122-
uint32_t buckets[2] = { 0,0 };
3123-
for (size_t i = 0; i < std::min(size_t(64), vis.visibleLights.size()); ++i) // only support indexing 64 lights at max for now
3118+
for (size_t i = 0; i < std::min(size_t(64), vis.visibleLights.size()); ++i) // only support indexing 64 lights at max in this mode
31243119
{
31253120
const uint32_t lightIndex = vis.visibleLights[i];
31263121
const AABB& light_aabb = vis.scene->aabb_lights[lightIndex];
31273122
if (light_aabb.intersects(batch_aabb))
31283123
{
3129-
const uint8_t bucket_index = uint8_t(i / 32);
3130-
const uint8_t bucket_place = uint8_t(i % 32);
3131-
buckets[bucket_index] |= 1 << bucket_place;
3124+
const uint64_t bucket_index = uint64_t(i / 64);
3125+
const uint64_t bucket_place = uint64_t(i % 64);
3126+
cb.xForwardLightMask |= uint64_t(1) << bucket_place;
31323127
}
31333128
}
3134-
cb.xForwardLightMask.x = buckets[0];
3135-
cb.xForwardLightMask.y = buckets[1];
31363129

31373130
for (size_t i = 0; i < std::min(size_t(32), vis.visibleDecals.size()); ++i)
31383131
{
31393132
const uint32_t decalIndex = vis.visibleDecals[vis.visibleDecals.size() - 1 - i]; // note: reverse order, for correct blending!
31403133
const AABB& decal_aabb = vis.scene->aabb_decals[decalIndex];
31413134
if (decal_aabb.intersects(batch_aabb))
31423135
{
3143-
const uint8_t bucket_place = uint8_t(i % 32);
3144-
cb.xForwardDecalMask |= 1 << bucket_place;
3136+
const uint32_t bucket_place = uint32_t(i % 32);
3137+
cb.xForwardDecalMask |= uint32_t(1) << bucket_place;
31453138
}
31463139
}
31473140

@@ -3151,8 +3144,8 @@ ForwardEntityMaskCB ForwardEntityCullingCPU(const Visibility& vis, const AABB& b
31513144
const AABB& probe_aabb = vis.scene->aabb_probes[probeIndex];
31523145
if (probe_aabb.intersects(batch_aabb))
31533146
{
3154-
const uint8_t bucket_place = uint8_t(i % 32);
3155-
cb.xForwardEnvProbeMask |= 1 << bucket_place;
3147+
const uint32_t bucket_place = uint32_t(i % 32);
3148+
cb.xForwardEnvProbeMask |= uint32_t(1) << bucket_place;
31563149
}
31573150
}
31583151

WickedEngine/wiVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace wi::version
99
// minor features, major updates, breaking compatibility changes
1010
const int minor = 72;
1111
// minor bug fixes, alterations, refactors, updates
12-
const int revision = 80;
12+
const int revision = 81;
1313

1414
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
1515

0 commit comments

Comments
 (0)