Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions 07_StagingAndMultipleQueues/app_resources/comp_shader.hlsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma wave shader_stage(compute)

#include "../app_resources/common.hlsl"

#include "nbl/builtin/hlsl/type_traits.hlsl"
using namespace nbl::hlsl;
[[vk::binding(0,0)]] Texture2D texture;
[[vk::binding(1,0)]] RWStructuredBuffer<uint32_t> histogram;

Expand All @@ -19,11 +20,11 @@ void main(uint32_t3 ID : SV_DispatchThreadID)

const float32_t4 texel = texture.Load(int32_t3(ID.xy,/*miplevel*/0));

const uint32_t redVal = uint32_t(texel.r * 255.f + 0.5f);
const uint32_t greenVal = uint32_t(texel.g * 255.f + 0.5f);
const uint32_t blueVal = uint32_t(texel.b * 255.f + 0.5f);
const uint32_t redVal = _static_cast<uint32_t>(texel.r * 255.f + 0.5f);
const uint32_t greenVal = _static_cast<uint32_t>(texel.g * 255.f + 0.5f);
const uint32_t blueVal = _static_cast<uint32_t>(texel.b * 255.f + 0.5f);

InterlockedAdd(histogram[constants.histogramBufferOffset + RED_OFFSET + redVal], 1);
InterlockedAdd(histogram[constants.histogramBufferOffset + GREEN_OFFSET + greenVal], 1);
InterlockedAdd(histogram[constants.histogramBufferOffset + BLUE_OFFSET + blueVal], 1);
}
}
2 changes: 1 addition & 1 deletion 14_Mortons/app_resources/testCommon.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct TestExecutor
// output.mortonSignedLess_emulated_4 = uint32_t4(morton_emulated_4_signed.lessThan<false>(Vec4BSignedFull));

// Cast to uint16_t which is what left shift for Mortons expect
uint16_t castedShift = uint16_t(input.shift);
uint16_t castedShift = _static_cast<uint16_t>(input.shift);
// Each left shift clamps to correct bits so the result kinda makes sense
// Left-shift
left_shift_operator<morton::code<false, smallBits_2, 2> > leftShiftSmall2;
Expand Down
2 changes: 1 addition & 1 deletion 14_Mortons/app_resources/testCommon2.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct TestExecutor2
output.mortonSignedLess_emulated_3 = uint32_t3(morton_emulated_3_signed.lessThan<false>(Vec3BSignedFull));
output.mortonSignedLess_emulated_4 = uint32_t4(morton_emulated_4_signed.lessThan<false>(Vec4BSignedFull));

uint16_t castedShift = uint16_t(input.shift);
uint16_t castedShift = _static_cast<uint16_t>(input.shift);

arithmetic_right_shift_operator<morton::code<true, fullBits_2, 2, emulated_uint64_t> > rightShiftSignedEmulated2;
output.mortonSignedRightShift_emulated_2 = rightShiftSignedEmulated2(morton_emulated_2_signed, castedShift % fullBits_2);
Expand Down
10 changes: 6 additions & 4 deletions 22_CppCompat/app_resources/test.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void main(uint3 invocationID : SV_DispatchThreadID)
{
static const uint16_t TEST_VALUE_0 = 5;
static const uint32_t TEST_VALUE_1 = 0x80000000u;
static const uint32_t TEST_VALUE_2 = 0x8000000000000000u; // TODO: Przmek is this intended? it warns because its too big from uint32_t
static const uint64_t TEST_VALUE_2 = 0x8000000000000000ull;
static const uint32_t TEST_VALUE_3 = 0x00000001u;
static const uint32_t TEST_VALUE_4 = 0x0000000000000001u; // TODO: Przmek is this intended? it warns because its too big from uint32_t
static const uint64_t TEST_VALUE_4 = 0x0000000000000001ull;


fill(invocationID, 5.01);
Expand All @@ -173,20 +173,22 @@ void main(uint3 invocationID : SV_DispatchThreadID)
fill(invocationID, float4(5.2, compileTimeCountLZero, runTimeCountLZero, 0));
assert(compileTimeCountLZero == runTimeCountLZero);

compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_2>::value;
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint64_t, TEST_VALUE_2>::value;
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_2);
fill(invocationID, float4(5.3, compileTimeCountLZero, runTimeCountLZero, 0));
assert(compileTimeCountLZero == runTimeCountLZero);
assert(runTimeCountLZero == 0);

compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_3>::value;
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_3);
fill(invocationID, float4(5.4, compileTimeCountLZero, runTimeCountLZero, 0));
assert(compileTimeCountLZero == runTimeCountLZero);

compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint32_t, TEST_VALUE_4>::value;
compileTimeCountLZero = nbl::hlsl::mpl::countl_zero<uint64_t, TEST_VALUE_4>::value;
runTimeCountLZero = nbl::hlsl::countl_zero(TEST_VALUE_4);
fill(invocationID, float4(5.5, compileTimeCountLZero, runTimeCountLZero, 0));
assert(compileTimeCountLZero == runTimeCountLZero);
assert(runTimeCountLZero == 63);
}

{
Expand Down
6 changes: 4 additions & 2 deletions 24_ColorSpaceTest/app_resources/present.frag.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

// vertex shader is provided by the fullScreenTriangle extension
#include <nbl/builtin/hlsl/ext/FullScreenTriangle/SVertexAttributes.hlsl>
#include <nbl/builtin/hlsl/type_traits.hlsl>
using namespace nbl::hlsl;
using namespace nbl::hlsl::ext::FullScreenTriangle;

#include "push_constants.hlsl"
Expand All @@ -20,7 +22,7 @@ using namespace nbl::hlsl::ext::FullScreenTriangle;
[[vk::location(0)]] float32_t4 main(SVertexAttributes vxAttr) : SV_Target0
{
const float32_t2 repeatCoord = vxAttr.uv*float32_t2(pc.grid);
const int32_t layer = int32_t(repeatCoord.y)*pc.grid.x+int32_t(repeatCoord.x);
const int32_t layer = _static_cast<int32_t>(repeatCoord.y)*_static_cast<int32_t>(pc.grid.x)+_static_cast<int32_t>(repeatCoord.x);
float4 color = texture.Sample(samplerState,float32_t3(repeatCoord,layer));
return color * color.a;
}
}
6 changes: 3 additions & 3 deletions 27_MPMCScheduler/app_resources/shader.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ void WhittedTask::__impl_call()
if (isGlass)
{
const float32_t F0 = 0.08f;
float32_t fresnel = nbl_glsl_fresnel_dielectric_common(orientedEta*orientedEta,abs(NdotV));
newThroughput *= float16_t(fresnel);
float32_t glassFresnel = nbl_glsl_fresnel_dielectric_common(orientedEta*orientedEta,abs(NdotV));
newThroughput *= _static_cast<float16_t>(glassFresnel);
}
// push reflection ray
{
Expand Down Expand Up @@ -272,7 +272,7 @@ void WhittedTask::__impl_call()
contribution += throughput*color;
}
else // miss
contribution += throughput*(rayDir.y<0.f ? float16_t3(0.1,0.7,0.03):float16_t3(0.05,0.25,1.0));
contribution += throughput*(rayDir.y<0.f ? float16_t3(_static_cast<float16_t>(0.1f),_static_cast<float16_t>(0.7f),_static_cast<float16_t>(0.03f)):float16_t3(_static_cast<float16_t>(0.05f),_static_cast<float16_t>(0.25f),_static_cast<float16_t>(1.0f)));

if (contribution.r+contribution.g+contribution.b<1.f/2047.f)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void runPersistent()
using variant_types = SVariantTypes<PPM>;
typename variant_types::pathtracer_type pathtracer;
pathtracer.scene = scene;
pathtracer.randGen.sequenceSamplesLog2 = renderPushConstants.sequenceSampleCountLog2;
pathtracer.randGen.sequenceSamplesLog2 = _static_cast<uint16_t>(renderPushConstants.sequenceSampleCountLog2);
pathtracer.randGen.pSampleBuffer = renderPushConstants.pSampleSequence;
pathtracer.nee.lights = lights;
pathtracer.materialSystem.bxdfs = bxdfs;
Expand Down
6 changes: 3 additions & 3 deletions 31_HLSLPathTracer/app_resources/hlsl/example_common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ struct Light
static Light<spectral_type> create(uint32_t emissiveMatID, uint32_t objId, ProceduralShapeType shapeType)
{
Light<spectral_type> retval;
retval.emissiveMatID.id = uint16_t(emissiveMatID);
retval.objectID = ObjectID::create(uint16_t(objId), shapeType);
retval.emissiveMatID.id = _static_cast<uint16_t>(emissiveMatID);
retval.objectID = ObjectID::create(_static_cast<uint16_t>(objId), shapeType);
return retval;
}

static Light<spectral_type> create(uint32_t emissiveMatID, NBL_CONST_REF_ARG(ObjectID) objectID)
{
Light<spectral_type> retval;
retval.emissiveMatID.id = uint16_t(emissiveMatID);
retval.emissiveMatID.id = _static_cast<uint16_t>(emissiveMatID);
retval.objectID = objectID;
return retval;
}
Expand Down
12 changes: 6 additions & 6 deletions 31_HLSLPathTracer/app_resources/hlsl/intersector.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Intersector
objectID.id = object_handle_type::INVALID_ID;

// prodedural shapes
NBL_UNROLL for (int i = 0; i < scene_type::SphereCount; i++)
NBL_UNROLL for (uint32_t i = 0; i < scene_type::SphereCount; i++)
{
float t = scene.getSphere(i).intersect(ray.origin, ray.direction);

Expand All @@ -58,7 +58,7 @@ struct Intersector
objectID.shapeType = PST_SPHERE;
}
}
NBL_UNROLL for (int i = 0; i < scene_type::TriangleCount; i++)
NBL_UNROLL for (uint32_t i = 0; i < scene_type::TriangleCount; i++)
{
float t = scene.getTriangle(i).intersect(ray.origin, ray.direction);

Expand All @@ -71,7 +71,7 @@ struct Intersector
objectID.shapeType = PST_TRIANGLE;
}
}
NBL_UNROLL for (int i = 0; i < scene_type::RectangleCount; i++)
NBL_UNROLL for (uint32_t i = 0; i < scene_type::RectangleCount; i++)
{
float t = scene.getRectangle(i).intersect(ray.origin, ray.direction);

Expand Down Expand Up @@ -99,23 +99,23 @@ struct Intersector
static scalar_type traceShadowRay(NBL_CONST_REF_ARG(scene_type) scene, NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(object_handle_type) objectID)
{
// prodedural shapes
NBL_UNROLL for (int i = 0; i < scene_type::SphereCount; i++)
NBL_UNROLL for (uint32_t i = 0; i < scene_type::SphereCount; i++)
{
float t = scene.getSphere(i).intersect(ray.origin, ray.direction);
bool closerIntersection = t > 0.0 && t < ray.intersectionT;

if (closerIntersection)
return 0.0;
}
NBL_UNROLL for (int i = 0; i < scene_type::TriangleCount; i++)
NBL_UNROLL for (uint32_t i = 0; i < scene_type::TriangleCount; i++)
{
float t = scene.getTriangle(i).intersect(ray.origin, ray.direction);
bool closerIntersection = t > 0.0 && t < ray.intersectionT;

if (closerIntersection)
return 0.0;
}
NBL_UNROLL for (int i = 0; i < scene_type::RectangleCount; i++)
NBL_UNROLL for (uint32_t i = 0; i < scene_type::RectangleCount; i++)
{
float t = scene.getRectangle(i).intersect(ray.origin, ray.direction);
bool closerIntersection = t > 0.0 && t < ray.intersectionT;
Expand Down
4 changes: 2 additions & 2 deletions 31_HLSLPathTracer/app_resources/hlsl/resolve.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SCascadeAccessor
SCascadeAccessor retval;
uint32_t imgWidth, imgHeight, layers;
cascade.GetDimensions(imgWidth, imgHeight, layers);
retval.cascadeImageDimension = int16_t2(imgWidth, imgHeight);
retval.cascadeImageDimension = int16_t2(_static_cast<int16_t>(imgWidth), _static_cast<int16_t>(imgHeight));
return retval;
}

Expand Down Expand Up @@ -60,7 +60,7 @@ void resolve(uint32_t3 threadID : SV_DispatchThreadID)
SResolveAccessorAdaptorType accessor = { SCascadeAccessor::create() };
SResolverType resolve = SResolverType::create(pc.resolveParameters);

float32_t3 color = resolve(accessor, uint16_t2(coords.x, coords.y));
float32_t3 color = resolve(accessor, uint16_t2(_static_cast<uint16_t>(coords.x), _static_cast<uint16_t>(coords.y)));

outImage[uint3(coords.x, coords.y, 0)] = float32_t4(color, 1.0f);
}
6 changes: 3 additions & 3 deletions 70_FLIPFluids/app_resources/compute/diffusion.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ void iterateDiffusion(uint32_t3 ID : SV_DispatchThreadID)
// TODO: THOU SHALT NOT USE INTEGER DIVISION AND MODULO IN SHADERS! STOP USING `flatIdxToLocalGridID`
int3 lid = flatIdxToLocalGridID(virtualIdx, 14);

int3 cellIdx = clampToGrid(lid + int3(-3, -3, -3) + gid * WorkgroupGridDim, gridData.gridSize);
sAxisCellMat[lid.x][lid.y][lid.z] = uint16_t3(axisCellMaterialIn[cellIdx].xyz);
sDiffusion[lid.x][lid.y][lid.z] = float16_t3(gridDiffusion[cellIdx].xyz);
int3 sharedCellIdx = clampToGrid(lid + int3(-3, -3, -3) + gid * WorkgroupGridDim, gridData.gridSize);
sAxisCellMat[lid.x][lid.y][lid.z] = uint16_t3(axisCellMaterialIn[sharedCellIdx].xyz);
sDiffusion[lid.x][lid.y][lid.z] = float16_t3(gridDiffusion[sharedCellIdx].xyz);
}
GroupMemoryBarrierWithGroupSync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID)
uint32_t pid = ID.x;
Particle p;

int offset = sizeof(float32_t3) * pid;
uint32_t offset = sizeof(float32_t3) * pid;
p.position = vk::RawBufferLoad<float32_t3>(pc.particlePosAddress + offset);
p.velocity = vk::RawBufferLoad<float32_t3>(pc.particleVelAddress + offset);

Expand Down
11 changes: 7 additions & 4 deletions 70_FLIPFluids/app_resources/compute/particlesInit.comp.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "../gridUtils.hlsl"
#include "../descriptor_bindings.hlsl"

using namespace nbl::hlsl;

struct SPushConstants
{
uint64_t particlePosAddress;
Expand All @@ -24,16 +26,17 @@ void main(uint32_t3 ID : SV_DispatchThreadID)

Particle p;

int x = pid % (gridData.particleInitSize.x * 2);
int y = pid / (gridData.particleInitSize.x * 2) % (gridData.particleInitSize.y * 2);
int z = pid / ((gridData.particleInitSize.x * 2) * (gridData.particleInitSize.y * 2));
const int pidSigned = _static_cast<int>(pid);
int x = pidSigned % (gridData.particleInitSize.x * 2);
int y = pidSigned / (gridData.particleInitSize.x * 2) % (gridData.particleInitSize.y * 2);
int z = pidSigned / ((gridData.particleInitSize.x * 2) * (gridData.particleInitSize.y * 2));
float3 position = gridPosToWorldPos(gridData.particleInitMin.xyz + 0.25f + float3(x, y, z) * 0.5f, gridData);
position = clampPosition(position, gridData.worldMin, gridData.worldMax);

p.position = position;
p.velocity = (float3)0;

int offset = sizeof(float32_t3) * pid;
uint32_t offset = sizeof(float32_t3) * pid;
vk::RawBufferStore<float32_t3>(pc.particlePosAddress + offset, p.position);
vk::RawBufferStore<float32_t3>(pc.particleVelAddress + offset, p.velocity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void main(uint32_t3 ID : SV_DispatchThreadID)
uint pid = ID.x;
Particle p;

int offset = sizeof(float32_t3) * pid;
uint32_t offset = sizeof(float32_t3) * pid;
p.position = vk::RawBufferLoad<float32_t3>(pc.particlePosAddress + offset);
p.velocity = vk::RawBufferLoad<float32_t3>(pc.particleVelAddress + offset);

Expand Down
41 changes: 30 additions & 11 deletions 70_FLIPFluids/app_resources/gridUtils.hlsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef _FLIP_EXAMPLE_GRID_UTILS_HLSL
#define _FLIP_EXAMPLE_GRID_UTILS_HLSL

#include "nbl/builtin/hlsl/type_traits.hlsl"

using namespace nbl::hlsl;

// TODO: Use `float32_t3` for 3D quantities, don't waste the W coordinate
struct SGridData
{
Expand Down Expand Up @@ -35,18 +39,29 @@ int3 clampToGrid(int3 index, int4 gridSize)
inline uint cellIdxToFlatIdx(int3 index, int4 gridSize)
{
uint3 idxClamp = clamp(index, (int3)0, gridSize.xyz - (int3)1);
return idxClamp.x + idxClamp.y * gridSize.x + idxClamp.z * gridSize.x * gridSize.y;
const uint3 gs = uint3(
_static_cast<uint>(gridSize.x),
_static_cast<uint>(gridSize.y),
_static_cast<uint>(gridSize.z));
return idxClamp.x + idxClamp.y * gs.x + idxClamp.z * gs.x * gs.y;
}

// INTEGER DIVISION AND MODULO ARE EXPENSIVE!!!
// TODO: try to compile without it and see how many places we die
// TODO: when absolutely necessary, use a variant that uses 16-bit ints instead of 32-bit because maybe final compiler will use float32_t for the short-int math
inline int3 flatIdxToCellIdx(uint id, int4 gridSize)
{
int x = id % gridSize.x;
int y = id / gridSize.x % gridSize.y;
int z = id / (gridSize.x * gridSize.y);
return int3(x, y, z);
const uint3 gs = uint3(
_static_cast<uint>(gridSize.x),
_static_cast<uint>(gridSize.y),
_static_cast<uint>(gridSize.z));
uint x = id % gs.x;
uint y = id / gs.x % gs.y;
uint z = id / (gs.x * gs.y);
return int3(
_static_cast<int>(x),
_static_cast<int>(y),
_static_cast<int>(z));
}

inline float3 cellIdxToWorldPos(int3 index, SGridData data)
Expand Down Expand Up @@ -78,14 +93,18 @@ inline float3 gridPosToWorldPos(float3 position, SGridData data)
// TODO: try to compile without it and see how many places we die
int3 flatIdxToLocalGridID(uint idx, int size)
{
uint a = size * size;
int3 b;
const uint s = _static_cast<uint>(size);
uint a = s * s;
uint3 b;
b.z = idx / a;
b.x = idx - b.z * a;
b.y = b.x / size;
b.x = b.x - b.y * size;
return b;
b.y = b.x / s;
b.x = b.x - b.y * s;
return int3(
_static_cast<int>(b.x),
_static_cast<int>(b.y),
_static_cast<int>(b.z));
}
#endif

#endif
#endif
10 changes: 6 additions & 4 deletions 71_RayTracingPipeline/app_resources/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
#include "nbl/builtin/hlsl/random/pcg.hlsl"
#include "nbl/builtin/hlsl/type_traits.hlsl"

using namespace nbl::hlsl;

NBL_CONSTEXPR uint32_t WorkgroupSize = 16;
NBL_CONSTEXPR uint32_t MAX_UNORM_10 = 1023;
NBL_CONSTEXPR uint32_t MAX_UNORM_22 = 4194303;

inline uint32_t packUnorm10(float32_t v)
{
return trunc(v * float32_t(MAX_UNORM_10) + 0.5f);
return _static_cast<uint32_t>(trunc(v * float32_t(MAX_UNORM_10) + 0.5f));
}

inline float32_t unpackUnorm10(uint32_t packed)
Expand All @@ -23,7 +25,7 @@ inline float32_t unpackUnorm10(uint32_t packed)
inline uint32_t packUnorm22(float32_t v)
{
const float maxValue = float32_t(MAX_UNORM_22);
return trunc(v * maxValue + 0.5f);
return _static_cast<uint32_t>(trunc(v * maxValue + 0.5f));
}

inline float32_t unpackUnorm22(uint32_t packed)
Expand Down Expand Up @@ -189,7 +191,7 @@ struct [raypayload] OcclusionPayload

struct MaterialId
{
const static uint32_t PROCEDURAL_FLAG = (1 << 31);
const static uint32_t PROCEDURAL_FLAG = (1u << 31);
const static uint32_t PROCEDURAL_MASK = ~PROCEDURAL_FLAG;

uint32_t data;
Expand Down Expand Up @@ -275,7 +277,7 @@ float3 unpackNormals3x10(uint32_t v)
{
// host side changes float32_t3 to EF_A2B10G10R10_SNORM_PACK32
// follows unpacking scheme from https://github.com/KhronosGroup/SPIRV-Cross/blob/main/reference/shaders-hlsl/frag/unorm-snorm-packing.frag
int signedValue = int(v);
int signedValue = _static_cast<int>(v);
int3 pn = int3(signedValue << 22, signedValue << 12, signedValue << 2) >> 22;
return clamp(float3(pn) / 511.0, -1.0, 1.0);
}
Expand Down
Loading