Skip to content

Commit

Permalink
Fix all warnings when compiling with HLSL202x due to microsoft/Direct…
Browse files Browse the repository at this point in the history
…XShaderCompiler#6867 (Conforming Literals proposal 0017 change in HLSL)
  • Loading branch information
devsh committed Aug 17, 2024
1 parent 2ebb287 commit 89ebb85
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions include/nbl/builtin/hlsl/sort/counting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template<
typename ValueAccessor,
typename HistogramAccessor,
typename SharedAccessor,
typename key_t = decltype(impl::declval < KeyAccessor > ().get(0)),
typename key_t = decltype(impl::declval<KeyAccessor>().get(0)),
bool robust=false
>
struct counting
Expand Down Expand Up @@ -88,8 +88,8 @@ struct counting
uint32_t sum = inclusive_scan(histogram_value, sdata);
histogram.atomicAdd(tid, sum);

const bool is_last_wg_invocation = tid == (GroupSize - 1);
const static uint16_t RoundedKeyBucketCount = (KeyBucketCount - 1) / GroupSize + 1;
const bool is_last_wg_invocation = tid == (GroupSize-_static_cast<uint16_t>(1));
const static uint16_t RoundedKeyBucketCount = (KeyBucketCount-_static_cast<uint16_t>(1))/GroupSize+_static_cast<uint16_t>(1);

for (int i = 1; i < RoundedKeyBucketCount; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions include/nbl/builtin/hlsl/workgroup/arithmetic.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ uint16_t ballotCountedBitDWORD(NBL_REF_ARG(BallotAccessor) ballotAccessor)
uint32_t bitfield;
ballotAccessor.get(index, bitfield);
// strip unwanted bits from bitfield of the last item
const uint16_t Remainder = ItemCount&31;
const uint16_t Remainder = ItemCount&_static_cast<uint16_t>(31);
if (Remainder!=0 && index==DWORDCount-1)
bitfield &= (0x1u<<Remainder)-1;
bitfield &= (0x1<<Remainder)-1;
return uint16_t(countbits(bitfield));
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/builtin/hlsl/workgroup/ballot.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uint16_t getDWORD(uint16_t invocation)
// essentially means 'how many DWORDs are needed to store ballots in bitfields, for each invocation of `itemCount`
uint16_t BallotDWORDCount(const uint16_t itemCount)
{
return getDWORD(itemCount+31); // round up, in case all items don't fit in even number of DWORDs
return getDWORD(itemCount+_static_cast<uint16_t>(31)); // round up, in case all items don't fit in even number of DWORDs
}

// this silly thing exists only because we can't make the above `constexpr`
Expand Down
2 changes: 1 addition & 1 deletion include/nbl/builtin/hlsl/workgroup/scratch_size.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct trunc_geom_series<N,K,W,true> : integral_constant<uint32_t,0> {};
template<uint16_t ContiguousItemCount>
struct scratch_size_ballot
{
NBL_CONSTEXPR_STATIC_INLINE uint16_t value = (ContiguousItemCount+31)>>5;
NBL_CONSTEXPR_STATIC_INLINE uint16_t value = (ContiguousItemCount+uint16_t(31))>>5;
};

// you're only writing one element
Expand Down
16 changes: 8 additions & 8 deletions include/nbl/builtin/hlsl/workgroup/shared_scan.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct reduce
template<class Accessor>
void __call(NBL_CONST_REF_ARG(type_t) value, NBL_REF_ARG(Accessor) scratchAccessor)
{
const uint16_t lastInvocation = ItemCount-1;
const uint16_t subgroupMask = uint16_t(glsl::gl_SubgroupSize()-1u);
const uint16_t lastInvocation = ItemCount-_static_cast<uint16_t>(1);
const uint16_t subgroupMask = _static_cast<uint16_t>(glsl::gl_SubgroupSize()-1u);

subgroup::inclusive_scan<BinOp,device_capabilities> subgroupOp;

Expand All @@ -47,16 +47,16 @@ struct reduce
// Consequently, those first gl_SubgroupSz^2 invocations will store their results on gl_SubgroupSz scratch slots
// and the next level will follow the same + the previous as an `offset`.

const uint16_t loadStoreIndexDiff = scanLoadIndex-uint16_t(glsl::gl_SubgroupID());
const uint16_t loadStoreIndexDiff = scanLoadIndex-_static_cast<uint16_t>(glsl::gl_SubgroupID());

// to cancel out the index shift on the first iteration
if (lastInvocationInLevel>subgroupMask)
scanLoadIndex -= lastInvocationInLevel-1;
scanLoadIndex -= lastInvocationInLevel-_static_cast<uint16_t>(1);
// TODO: later [unroll(scan_levels<ItemCount,subgroup::MinSubgroupSize>::value-1)]
[unroll(1)]
while (lastInvocationInLevel>subgroupMask)
{
scanLoadIndex += lastInvocationInLevel+1;
scanLoadIndex += lastInvocationInLevel+_static_cast<uint16_t>(1);
// only invocations that have the final value of the subgroupOp (inclusive scan) store their results
if (participate && (SubgroupContiguousIndex()==lastInvocationInLevel || isLastSubgroupInvocation))
scratchAccessor.set(scanLoadIndex-loadStoreIndexDiff,scan); // For subgroupSz = 32, first 512 invocations store index is [0,15], 512-1023 [16,31] etc.
Expand Down Expand Up @@ -93,10 +93,10 @@ struct scan// : reduce<BinOp,ItemCount> https://github.com/microsoft/DirectXShad

const uint16_t subgroupID = uint16_t(glsl::gl_SubgroupID());
// abuse integer wraparound to map 0 to 0xffffu
const uint16_t prevSubgroupID = subgroupID-1;
const uint16_t prevSubgroupID = subgroupID-_static_cast<uint16_t>(1);

// important check to prevent weird `firstbithigh` overlflows
const uint16_t lastInvocation = ItemCount-1;
const uint16_t lastInvocation = ItemCount-_static_cast<uint16_t>(1);
if(lastInvocation>=uint16_t(glsl::gl_SubgroupSize()))
{
const uint16_t subgroupSizeLog2 = uint16_t(glsl::gl_SubgroupSizeLog2());
Expand All @@ -121,7 +121,7 @@ struct scan// : reduce<BinOp,ItemCount> https://github.com/microsoft/DirectXShad
if (logShift!=initialLogShift) // but the top level doesn't have any level above itself
{
// this is fine if on the way up you also += under `if (participate)`
scanStoreIndex -= __base.lastInvocationInLevel+1;
scanStoreIndex -= __base.lastInvocationInLevel+_static_cast<uint16_t>(1);
type_t higherLevelEPS;
scratchAccessor.get(scanStoreIndex, higherLevelEPS);
__base.lastLevelScan = binop(__base.lastLevelScan,higherLevelEPS);
Expand Down

0 comments on commit 89ebb85

Please sign in to comment.