Skip to content

Commit e05e236

Browse files
committed
Port core scan shaders and some other fixes. Missing descirptors for full scan port
1 parent 36473e3 commit e05e236

File tree

5 files changed

+102
-3
lines changed

5 files changed

+102
-3
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef _NBL_HLSL_WORKGROUP_SIZE_
2+
#define _NBL_HLSL_WORKGROUP_SIZE_ 256
3+
#endif
4+
5+
#include <nbl/builtin/hlsl/scan/descriptors.hlsl>
6+
#include <nbl/builtin/hlsl/scan/virtual_workgroup.hlsl>
7+
#include <nbl/builtin/hlsl/scan/default_scheduler.hlsl>
8+
9+
namespace nbl
10+
{
11+
namespace hlsl
12+
{
13+
namespace scan
14+
{
15+
#ifndef _NBL_HLSL_SCAN_PUSH_CONSTANTS_DEFINED_
16+
cbuffer PC // REVIEW: register and packoffset selection
17+
{
18+
Parameters_t scanParams;
19+
DefaultSchedulerParameters_t schedulerParams;
20+
};
21+
#define _NBL_HLSL_SCAN_PUSH_CONSTANTS_DEFINED_
22+
#endif
23+
24+
#ifndef _NBL_HLSL_SCAN_GET_PARAMETERS_DEFINED_
25+
Parameters_t getParameters()
26+
{
27+
return pc.scanParams;
28+
}
29+
#define _NBL_HLSL_SCAN_GET_PARAMETERS_DEFINED_
30+
#endif
31+
32+
#ifndef _NBL_HLSL_SCAN_GET_SCHEDULER_PARAMETERS_DEFINED_
33+
DefaultSchedulerParameters_t getSchedulerParameters()
34+
{
35+
return pc.schedulerParams;
36+
}
37+
#define _NBL_HLSL_SCAN_GET_SCHEDULER_PARAMETERS_DEFINED_
38+
#endif
39+
}
40+
}
41+
}
42+
43+
#ifndef _NBL_HLSL_MAIN_DEFINED_
44+
[numthreads(_NBL_HLSL_WORKGROUP_SIZE_, 1, 1)]
45+
void CSMain()
46+
{
47+
nbl::hlsl::scan::main();
48+
}
49+
#define _NBL_HLSL_MAIN_DEFINED_
50+
#endif
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef _NBL_HLSL_WORKGROUP_SIZE_
2+
#define _NBL_HLSL_WORKGROUP_SIZE_ 256
3+
#define _NBL_HLSL_WORKGROUP_SIZE_LOG2_ 8
4+
#endif
5+
6+
#include <nbl/builtin/hlsl/scan/descriptors.hlsl>
7+
#include <nbl/builtin/hlsl/scan/virtual_workgroup.hlsl>
8+
#include <nbl/builtin/hlsl/scan/default_scheduler.hlsl>
9+
10+
namespace nbl
11+
{
12+
namespace hlsl
13+
{
14+
namespace scan
15+
{
16+
#ifndef _NBL_HLSL_SCAN_GET_PARAMETERS_DEFINED_
17+
Parameters_t scanParams;
18+
Parameters_t getParameters()
19+
{
20+
return scanParams;
21+
}
22+
#define _NBL_HLSL_SCAN_GET_PARAMETERS_DEFINED_
23+
#endif
24+
25+
uint getIndirectElementCount();
26+
27+
#ifndef _NBL_HLSL_SCAN_GET_SCHEDULER_PARAMETERS_DEFINED_
28+
DefaultSchedulerParameters_t schedulerParams;
29+
DefaultSchedulerParameters_t getSchedulerParameters()
30+
{
31+
scheduler::computeParameters(getIndirectElementCount(),scanParams,schedulerParams);
32+
return schedulerParams;
33+
}
34+
#define _NBL_HLSL_SCAN_GET_SCHEDULER_PARAMETERS_DEFINED_
35+
#endif
36+
}
37+
}
38+
}
39+
40+
#ifndef _NBL_HLSL_MAIN_DEFINED_
41+
[numthreads(_NBL_HLSL_WORKGROUP_SIZE_, 1, 1)]
42+
void CSMain()
43+
{
44+
if (bool(nbl::hlsl::scan::getIndirectElementCount()))
45+
nbl::hlsl::scan::main();
46+
}
47+
#define _NBL_HLSL_MAIN_DEFINED_
48+
#endif

include/nbl/builtin/hlsl/scan/parameters_struct.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ namespace hlsl
1313
{
1414
namespace scan
1515
{
16+
// REVIEW: Putting topLevel second allows better alignment for packing of constant variables, assuming lastElement has length 4. (https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules)
1617
struct Parameters_t {
17-
uint topLevel;
1818
uint lastElement[NBL_BUILTIN_MAX_SCAN_LEVELS/2+1];
19+
uint topLevel;
1920
uint temporaryStorageOffset[NBL_BUILTIN_MAX_SCAN_LEVELS/2];
2021
}
2122
}

include/nbl/builtin/hlsl/scan/virtual_workgroup.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace scan
3030

3131
const bool inRange = levelInvocationIndex <= params.lastElement[pseudoLevel];
3232

33-
Storage_t data = binop::identity();
33+
Storage_t data = binop.identity();
3434
if(inRange)
3535
{
3636
getData(data, levelInvocationIndex, localWorkgroupIndex, treeLevel, pseudoLevel);

include/nbl/builtin/hlsl/subgroup/arithmetic_portability_impl.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ struct inclusive_scan : scan_base
318318
// additionally, the first half invocations initialize the padding slots
319319
// with identity values
320320
if (scan_base::pseudoSubgroupInvocation<scan_base::HalfSubgroupSize)
321-
scratchAccessor.set(lastLoadOffset,op::identity());
321+
scratchAccessor.set(lastLoadOffset,op.identity());
322322
}
323323
nbl::hlsl::subgroup::Barrier();
324324
nbl::hlsl::subgroup::MemoryBarrierShared();

0 commit comments

Comments
 (0)