Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
58c9c13
merge master, fix conflicts
keptsecret Feb 19, 2026
fef5c4e
Fix small bug in GenericDataAccessor definition
Nov 11, 2025
9114750
First draft of Warpmap Generation workgroup implementation
Nov 11, 2025
afa2459
Add warp concept
Nov 18, 2025
d90486a
Add spherical warp
Nov 18, 2025
dbc5852
Remove envmap accessors.hlsl
Nov 18, 2025
6ebfbff
Hierarchical image sampling implementation
Nov 18, 2025
a1e86cd
Merge branch 'master' into env_map_importance_sampling
Dec 19, 2025
d225413
Merge branch 'master' into env_map_importance_sampling
Dec 20, 2025
aadbbb5
Remove envmap.hlsl
Dec 20, 2025
5b6e805
Move to sampling namespace and implement backward density
Dec 22, 2025
9ad89b2
Remove private, public from hierarchical_image
Dec 22, 2025
ba64dc2
Refactor hierarchical image to keep accessor and common data as member
Dec 22, 2025
4f06427
Refactor hierarchical image to separate binarySearch from Hierarchica…
Dec 26, 2025
fc59400
Fix Spherical warp indentation
Dec 26, 2025
2a9bee5
Add some comment why we add xi to the sample uvs
Dec 26, 2025
4571ba0
Merge branch 'master' into env_map_importance_sampling
Dec 30, 2025
756f79e
WIP
Jan 6, 2026
950fd87
Rename uv to coord for LuminanceAccessor concepts
Jan 9, 2026
9af8759
Fix hierarchical_image.hlsl
Jan 9, 2026
f459321
Fix typo in spherical.hlsl
Jan 9, 2026
b50018a
Implement gen_luma, gen_warpmap and measure_luma shaders
Jan 9, 2026
c91d4d1
EnvmapImportanceSampling CMakeLists
Jan 9, 2026
5194f7f
Initial implementation of CEnvmapImportanceSampling
Jan 9, 2026
edc489a
Initial implementation of CEnvmapImportanceSampling
Jan 12, 2026
b94019a
Small fixes
Jan 12, 2026
cff237a
Initial implementation of computeWarpMap
Jan 20, 2026
8a10dee
Fix arithmetic config no const specifier for method
Jan 30, 2026
7b728e4
Define config_t from outside
Jan 30, 2026
92202e6
More fixes on computeWarpMap implementation
Jan 30, 2026
51cbb81
Fix chose second to be placed inside the loop
Jan 30, 2026
200c51f
LuminanceReadAccessor take ScalarT as template parameter
Jan 30, 2026
695e667
gen_warpmap to gen_warp
Jan 30, 2026
d500e23
Move hierarchical_image concepts to sampling subdirectory
Feb 18, 2026
11dd229
Add some comment regarding corner sampling
Feb 18, 2026
563343a
Parameterize spherical warp and make sure all literal is in the corre…
Feb 18, 2026
99cc8c2
Refactor CEnvmapImportanceSampling to block and calculate avgLuma
Feb 18, 2026
a2c52bf
Fix warp concept and add density type to warp concept
Feb 19, 2026
c2021ab
Rename luminanceScale to lumaRGBCoefficients
Feb 19, 2026
a4e81d1
Remove measure_luma.comp.hlsl
Feb 19, 2026
a2362ff
Fix some bug in hierarchical_image.hlsl
Feb 19, 2026
d6ed947
Rename luminanceScales to lumaRGBCoefficients
Feb 19, 2026
5043062
Move EnvmapImportanceSampling from ext to core
Feb 21, 2026
5c159d0
Fix binarySearch implementation. when last is 2x1 we should check for…
Feb 21, 2026
6c9c3b2
Rename private member with underscore prefix
Feb 21, 2026
e54fc56
Merge branch 'master' into env_map_importance_sampling
Feb 22, 2026
5b85c44
Update submodule to follow master branch
Feb 22, 2026
108b129
Add missed EnvmapSampler.h and cpp
Feb 23, 2026
e8aa426
Rename get and gather to texelFetch and texelGather
Feb 23, 2026
e7e2c70
Merge branch 'hlsl_path_tracer_example' into env_map_importance_sampling
Feb 23, 2026
8b4a6d0
Include missing files into commit
Feb 23, 2026
c0b2eae
Merge branch 'master' into env_map_importance_sampling
Feb 23, 2026
f54b77f
Update comment on sampleUvs
Mar 3, 2026
f306698
Use bitfield for lumaMapResolution in push constant
Mar 3, 2026
0c11ab7
Remove NBL_BUILD_ENVMAP_IMPORTANCE_SAMPLING option
Mar 3, 2026
77fb274
Fix worgroup dim for gen_warp
Mar 3, 2026
6a9cda4
Use constant workgroup dimension instead of WORKGROUP_DIM define
Mar 3, 2026
32cebd4
Remove passing WORKGROUP_DIM to shader
Mar 3, 2026
12d4653
Remove passing WORKGROUP_DIM for gen_luma
Mar 4, 2026
0b3954b
Add upsscale parameter for EnvmapSampler
Mar 4, 2026
65c0e82
Pass warpMap width and height to luminanceSampler. Check For Out of B…
Mar 4, 2026
ffb8d69
Small fixes to gen_warp shader
Mar 4, 2026
ffddb4a
gen_warp get image dimension from push constant instead of OpImageQue…
Mar 4, 2026
5990b90
Rename HierarchicalImage to WarpmapSampler
Mar 4, 2026
967094d
Add todo comment for cube map
Mar 4, 2026
deb6906
Move EnvmapSampler from core/sampling to video/sampling
Mar 5, 2026
34f5872
Rename LuminanceSampler to HierarchicalLuminanceSampler
Mar 5, 2026
4b7a984
Fix corner sampling logic in gen_luma and hierarchical_image.hlsl
Mar 6, 2026
a6f1704
Fix previous commit
Mar 6, 2026
e57c999
Add some todo comment for corner sampling flag
Mar 6, 2026
7a8ba14
Add const modifier for binarySearch
Mar 7, 2026
9295167
Add some temporary struct from pr #1001
Mar 7, 2026
9241d29
Refactor hierarchical_image naming and concepts
Mar 10, 2026
8108ca7
Fix indentation of hierarchical_image.hlsl
Mar 10, 2026
326544d
Small fixes
Mar 10, 2026
6292560
Remove superfluous member from WarpmapSampler
Mar 11, 2026
e2b9676
Merge branch 'master' into env_map_importance_sampling
Mar 11, 2026
ec6adf0
Fix resolve.hlsl case
Mar 12, 2026
97b8439
Merge branch 'master' into env_map_importance_sampling
Mar 26, 2026
c23fb61
Rename GenWarpWorkgroupDim and GenLumaWorkgroupDim
kevyuu Mar 26, 2026
345065b
Fix include guard of warps/spherical.hlsl
kevyuu Mar 26, 2026
7c7c30a
Undo Embed built-in resources option to OFF
kevyuu Mar 27, 2026
615c328
Gen Luma now support Texture Array
kevyuu Mar 27, 2026
4988fb2
Remove unused member in HierarchicalWarpGenerator
kevyuu Mar 27, 2026
eb47cee
Remove LuminanceReadAccessor concept and support Texture2DArray for g…
kevyuu Mar 27, 2026
0ebe456
Rename _mip2x1 to _lastMipLevel
kevyuu Mar 27, 2026
2676c55
Fix envmapsampler header guard
kevyuu Mar 28, 2026
35469eb
Remove unused defaults in EnvmapSampler
kevyuu Mar 28, 2026
b5d4012
Undo cuda interop cmake option
kevyuu Mar 28, 2026
cef9494
Improve comment on hierarchical_image
kevyuu Mar 30, 2026
a26691d
Using sincos in spherical.hlsl
kevyuu Mar 30, 2026
5a8e7f4
Rework hierarchical_image and sphericalSampling to follow new sampler…
kevyuu Mar 30, 2026
0cdbbec
refactor: Improve `generate` function and sampling logic
kevyuu Mar 31, 2026
22db1dc
refactor: Update backwardPdf and backwardWeight logic
kevyuu Mar 31, 2026
769f5f4
refactor: Improve hierarchical image sampling system
kevyuu Mar 31, 2026
0afcadc
refactor: Implement MipmappedLuminanceReadAccessor
kevyuu Mar 31, 2026
646d165
refactor: Embed value_type inside LuminanceReadAccessor
kevyuu Mar 31, 2026
523b9c0
refactor: embed scalar_type inside WarpAccessor
kevyuu Mar 31, 2026
1d1cb73
fix: Forward Weight calculation in WarpMapSampler
kevyuu Mar 31, 2026
3cfa3c6
fix: Implement bacwardWeight for WarpGenerator
kevyuu Mar 31, 2026
bd32b33
refactor: Rename HierarchicalWarpGenerator to HierarchicalLuminanceSa…
kevyuu Apr 1, 2026
504b00b
Rename HierarchicalWarpSampler to ComposedHierarchicalSampler
kevyuu Apr 1, 2026
4b1b52c
Remove deleted hlsl from list of builtin resource in CMake
kevyuu Apr 1, 2026
181a487
Add constraints and improve type consistency for HierarchicalLuminanc…
kevyuu Apr 1, 2026
cd42179
Move WarpmapSampler into its own file
kevyuu Apr 1, 2026
dafba0a
Fix include guard of hierarchical_image/accesors.hlsl
kevyuu Apr 1, 2026
a5194b4
Unify pipelineLayout and descriptorSet for genLuma and genWarp
kevyuu Apr 1, 2026
c074e6a
Remove mount method in EnvmapSampler
kevyuu Apr 1, 2026
17a7de7
Implement common pipeline creation function
kevyuu Apr 1, 2026
38b50cf
Added SSession on EnvmapSampler
kevyuu Apr 2, 2026
00e5b4c
Rename EnvmapSampler CEnvmapWarpGenerator
kevyuu Apr 2, 2026
99a8c09
Move LumaRgBCoeffecients as constant in hlsl header
kevyuu Apr 2, 2026
4b53ad5
Implement multi layer gen_luma and gen_warp
kevyuu Apr 2, 2026
2dc25fa
Remove non write access from srcAccessMask in image barriers
kevyuu Apr 2, 2026
dbcde57
Update submodule to latest master
kevyuu Apr 6, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ NBL_CONCEPT_END(
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

template<typename T, typename V, typename I=uint32_t>
NBL_BOOL_CONCEPT GenericDataAccessor = GenericWriteAccessor<T,V,I> && GenericWriteAccessor<T,V,I>;
NBL_BOOL_CONCEPT GenericDataAccessor = GenericReadAccessor<T,V,I> && GenericWriteAccessor<T,V,I>;

}
}
Expand Down
237 changes: 237 additions & 0 deletions include/nbl/builtin/hlsl/sampling/hierarchical_image.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h

#ifndef _NBL_BUILTIN_HLSL_SAMPLING_HIERARCHICAL_IMAGE_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_HIERARCHICAL_IMAGE_INCLUDED_

#include <nbl/builtin/hlsl/concepts/accessors/loadable_image.hlsl>
#include <nbl/builtin/hlsl/sampling/basic.hlsl>
#include <nbl/builtin/hlsl/sampling/hierarchical_image/accessors.hlsl>
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>

namespace nbl
{
namespace hlsl
{
namespace sampling
{

// TODO: Implement corner sampling or centered sampling based on the type of LuminanceAccessor
template <typename LuminanceAccessorT
NBL_PRIMARY_REQUIRES(
hierarchical_image::MipmappedLuminanceReadAccessor<LuminanceAccessorT>
)
struct HierarchicalLuminanceSampler
{
using this_type = HierarchicalLuminanceSampler<LuminanceAccessorT>;
using scalar_type = typename LuminanceAccessorT::value_type;
using vector2_type = vector<scalar_type, 2>;
using vector4_type = vector<scalar_type, 4>;
using domain_type = vector2_type;
using codomain_type = vector2_type;
using weight_type = scalar_type;
using density_type = scalar_type;
struct cache_type
{
scalar_type rcpPmf;
};

LuminanceAccessorT _map;
uint16_t2 _lastTexel;
uint16_t _lastMipLevel : 15;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not the last, its the penultimate (one minus last) because you're not after the last one which is 1x1, you're tapping 2x1 or 2x2

uint16_t _aspect2x1 : 1;

static this_type create(NBL_CONST_REF_ARG(LuminanceAccessorT) lumaMap)
{
this_type result;
result._map = lumaMap;
const uint16_t2 mapSize = lumaMap.resolution();
result._lastTexel = mapSize - uint16_t2(1, 1);
// Note: We use mapSize.y here because currently the map aspect ratio can only be 1x1 or 2x1
result._lastMipLevel = _static_cast<uint16_t>(findMSB(_static_cast<uint32_t>(mapSize.y)));
result._aspect2x1 = mapSize.x != mapSize.y;
return result;
}

static bool __choseSecond(scalar_type first, scalar_type second, NBL_REF_ARG(scalar_type) xi, NBL_REF_ARG(scalar_type) rcpPmf)
{
// numerical resilience against IEEE754
scalar_type rcpChoiceProb = scalar_type(0);
PartitionRandVariable<scalar_type> partition;
partition.leftProb = scalar_type(1) / (scalar_type(1) + (second / first));
bool choseSecond = partition(xi, rcpChoiceProb);
rcpPmf *= rcpChoiceProb;
return choseSecond;
}

// Cannot use textureGather since we need to pass the mipLevel
vector4_type __texelGather(uint16_t2 coord, uint16_t level) NBL_CONST_MEMBER_FUNC
{
assert(coord.x < _lastTexel.x && coord.y < _lastTexel.y);
scalar_type p0, p1, p2, p3;
_map.get(p0, coord + uint16_t2(0, 1), level);
_map.get(p1, coord + uint16_t2(1, 1), level);
_map.get(p2, coord + uint16_t2(1, 0), level);
_map.get(p3, coord + uint16_t2(0, 0), level);
return vector4_type(p0, p1, p2, p3);
}

codomain_type generate(const domain_type v, NBL_REF_ARG(cache_type) cache) NBL_CONST_MEMBER_FUNC
{
uint16_t2 p = uint16_t2(0, 0);

domain_type xi = v;
scalar_type rcpPmf = 1;
if (_aspect2x1) {
scalar_type p0, p1;
// do one split in the X axis first cause penultimate full mip would have been 2x1
_map.get(p0, uint16_t2(0, 0), _lastMipLevel);
_map.get(p1, uint16_t2(1, 0), _lastMipLevel);
p.x = __choseSecond(p0, p1, xi.x, rcpPmf) ? 1 : 0;
}

for (int i = _lastMipLevel - 1; i >= 0; i--)
{
p <<= 1;
const vector4_type values = __texelGather(p, i);
scalar_type wx_0, wx_1;
{
const scalar_type wy_0 = values[3] + values[2];
const scalar_type wy_1 = values[1] + values[0];
if (__choseSecond(wy_0, wy_1, xi.y, rcpPmf))
{
p.y |= 1;
wx_0 = values[0];
wx_1 = values[1];
}
else
{
wx_0 = values[3];
wx_1 = values[2];
}
}
if (__choseSecond(wx_0, wx_1, xi.x, rcpPmf))
p.x |= 1;
}


// If we don`t add xi, the sample will clump to the lowest corner of environment map texel. Each time we call PartitionRandVariable(), the output xi is the new xi that determines how left and right(or top and bottom for y axis) to choose the child partition. It means that if for some input xi, the output xi = 0, then the input xi is the edge of choosing this partition and the previous partition, and vice versa, if output xi = 1, then the input xi is the edge of choosing this partition and the next partition. Hence, by adding xi to the lower corner of the texel, we create a gradual transition from one pixel to another. Without adding output xi, the calculation of jacobian using the difference of sample value would not work.
// Since we want to do corner sampling. We have to handle edge texels as corner cases. Remember, in corner sampling we map uv [0,1] to [center of first texel, center of last texel]. So when p is an edge texel, we have to remap xi. [0.5, 1] when p == 0, and [0.5, 1] when p == length - 1.
if (p.x == 0)
xi.x = xi.x * scalar_type(0.5) + scalar_type(0.5);
if (p.y == 0)
xi.y = xi.y * scalar_type(0.5) + scalar_type(0.5);
if (p.x == _lastTexel.x)
xi.x = xi.x * scalar_type(0.5);
if (p.y == _lastTexel.y)
xi.y = xi.y * scalar_type(0.5);

// We reduce by 0.5 and divide with _lastTexel instead of map size to normalize the cornered sampling coordinate
const vector2_type directionUV = (vector2_type(p.x, p.y) + xi - domain_type(0.5, 0.5)) / _lastTexel;

cache.rcpPmf = rcpPmf;

return directionUV;
}

density_type forwardPdf(const domain_type xi, const cache_type cache) NBL_CONST_MEMBER_FUNC
{
return (_lastTexel.x * _lastTexel.y) / cache.rcpPmf;
}

weight_type forwardWeight(const domain_type xi, const cache_type cache) NBL_CONST_MEMBER_FUNC
{
return forwardPdf(xi, cache);
}

// Doesn't comply with sampler concept. This class is extracted so can be used on warpmap generation without passing in unnecessary information like avgLuma. So, need to pass in avgLuma when calculating backwardPdf.
density_type backwardPdf(codomain_type codomainVal) NBL_CONST_MEMBER_FUNC
{
return _map.load(codomainVal) * _map.getAvgLuma();
}

weight_type backwardWeight(const codomain_type codomainVal) NBL_CONST_MEMBER_FUNC
{
return backwardPdf(codomainVal);
}

};

// TODO(kevinyu): Add constraint for PostWarpT
template <typename LuminanceAccessorT, typename PostWarpT
NBL_PRIMARY_REQUIRES(
hierarchical_image::MipmappedLuminanceReadAccessor<LuminanceAccessorT>
)
struct ComposedHierarchicalSampler
{
using this_type = ComposedHierarchicalSampler<LuminanceAccessorT, PostWarpT>;
using warp_generator_type = HierarchicalLuminanceSampler<LuminanceAccessorT>;
using scalar_type = typename LuminanceAccessorT::value_type;
using density_type = scalar_type;
using weight_type = scalar_type;
using vector2_type = vector<scalar_type, 2>;
using vector3_type = vector<scalar_type, 3>;
using vector4_type = vector<scalar_type, 4>;
using domain_type = typename warp_generator_type::domain_type;
using codomain_type = typename PostWarpT::codomain_type;

static_assert(is_same_v<typename PostWarpT::domain_type, typename warp_generator_type::codomain_type> && is_same_v<typename PostWarpT::density_type, density_type> && is_same_v<typename PostWarpT::weight_type, weight_type>);

struct cache_type
{
typename warp_generator_type::cache_type warpGeneratorCache;
typename PostWarpT::density_type postWarpPdf;
};

warp_generator_type _warpGenerator;
PostWarpT _postWarp;

static this_type create(NBL_CONST_REF_ARG(LuminanceAccessorT) lumaMap)
{
this_type result;
result._warpGenerator = warp_generator_type::create(lumaMap);
return result;
}

codomain_type generate(const domain_type xi, NBL_REF_ARG(cache_type) cache) NBL_CONST_MEMBER_FUNC
{
const typename warp_generator_type::codomain_type warpSample = _warpGenerator.generate(xi, cache.warpGeneratorCache);
typename PostWarpT::cache_type postWarpCache;
const codomain_type postWarpSample = _postWarp.generate(warpSample, postWarpCache);

// I have to store the postWarpDensity here, so I don't have to call generate on warpGenerator again just to feed it to PostWarpT, even though for spherical it is unused.
cache.postWarpPdf = _postWarp.forwardPdf(warpSample, postWarpCache);

return postWarpSample;
}

density_type forwardPdf(const domain_type xi, const cache_type cache) NBL_CONST_MEMBER_FUNC
{
return _warpGenerator.forwardPdf(xi, cache.warpGeneratorCache) * cache.postWarpPdf;
}

weight_type forwardWeight(const domain_type xi, const cache_type cache) NBL_CONST_MEMBER_FUNC
{
return forwardPdf(xi, cache);
}

density_type backwardPdf(const codomain_type codomainVal) NBL_CONST_MEMBER_FUNC
{
typename PostWarpT::domain_type postWarpDomain = _postWarp.generateInverse(codomainVal);
return _postWarp.backwardPdf(codomainVal) * _warpGenerator.backwardPdf(postWarpDomain, _warpGenerator._map.getAvgLuma());
}

weight_type backwardWeight(const codomain_type codomainVal) NBL_CONST_MEMBER_FUNC
{
return backwardPdf(codomainVal);
}
};



}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#ifndef _NBL_BUILTIN_HLSL_SAMPLING_HIERARCHICAL_IMAGE_ACCESSORS_INCLUDED_
#define _NBL_BUILTIN_HLSL_SAMPLING_HIERARCHICAL_IMAGE_ACCESSORS_INCLUDED_

#include "nbl/builtin/hlsl/concepts/accessors/generic_shared_data.hlsl"

namespace nbl
{
namespace hlsl
{
namespace sampling
{
namespace hierarchical_image
{

// declare concept
#define NBL_CONCEPT_NAME MipmappedLuminanceReadAccessor
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (AccessorT)
// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (accessor,AccessorT)
#define NBL_CONCEPT_PARAM_1 (pixelCoord,uint16_t2)
#define NBL_CONCEPT_PARAM_2 (level,uint16_t)
#define NBL_CONCEPT_PARAM_3 (outVal,typename AccessorT::value_type)
// start concept
NBL_CONCEPT_BEGIN(4)
// need to be defined AFTER the concept begins
#define accessor NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define pixelCoord NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define level NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define outVal NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(AccessorT::value_type))
// Note(kevin): I don't use MipmappedLoadableImage here, since that concept require layer as parameter. So the sampler have to store the layerIndex. The logic is similar across all layer. So the accessor should be the one that store the layerIndex
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((accessor.template get(outVal,pixelCoord,level)) , ::nbl::hlsl::is_same_v, void))
// Ask(kevin): Should getAvgLuma follow get, where the outVal is the first parameter instead of the return value?
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((accessor.getAvgLuma()), ::nbl::hlsl::is_same_v, typename AccessorT::value_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((accessor.resolution()), ::nbl::hlsl::is_same_v, uint16_t2))
);
#undef accessor
#undef pixelCoord
#undef level
#undef outVal
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

// declare concept
#define NBL_CONCEPT_NAME LuminanceReadAccessor
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (AccessorT)
// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (accessor, AccessorT)
// start concept
NBL_CONCEPT_BEGIN(1)
// need to be defined AFTER the concept begins
#define accessor NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(AccessorT::value_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(concepts::accessors::GenericReadAccessor, AccessorT, typename AccessorT::value_type, float32_t2))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((accessor.getAvgLuma()), ::nbl::hlsl::is_same_v, typename AccessorT::value_type))
);
#undef accessor
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

// gatherUvs return 4 UVs in a square for manual bilinear interpolation with differentiability
// declare concept
#define NBL_CONCEPT_NAME WarpAccessor
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (WarpAccessorT)
// not the greatest syntax but works
#define NBL_CONCEPT_PARAM_0 (accessor,WarpAccessorT)
#define NBL_CONCEPT_PARAM_1 (coord,vector<float32_t, 2>)
#define NBL_CONCEPT_PARAM_2 (val, matrix<typename WarpAccessorT::scalar_type, 4, 2>)
#define NBL_CONCEPT_PARAM_3 (interpolant, vector<typename WarpAccessorT::scalar_type, 2>)
// start concept
NBL_CONCEPT_BEGIN(4)
// need to be defined AFTER the concept begins
#define accessor NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define coord NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define val NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define interpolant NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(WarpAccessorT::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((accessor.gatherUv(coord, val)), ::nbl::hlsl::is_same_v, void))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((accessor.resolution()), ::nbl::hlsl::is_same_v, uint16_t2))
);
#undef accessor
#undef coord
#undef val
#undef interpolant
#include <nbl/builtin/hlsl/concepts/__end.hlsl>

}
}
}
}

#endif
42 changes: 42 additions & 0 deletions include/nbl/builtin/hlsl/sampling/hierarchical_image/common.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef _NBL_HLSL_SAMPLING_HIERARCHICAL_IMAGE_COMMON_INCLUDED_
#define _NBL_HLSL_SAMPLING_HIERARCHICAL_IMAGE_COMMON_INCLUDED_

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

namespace nbl
{
namespace hlsl
{
namespace sampling
{
namespace hierarchical_image
{

NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float32_t3 LumaRgbCoefficients = { 0.2126729f, 0.7151522f, 0.0721750f };

struct SLumaGenPushConstants
{
uint32_t lumaMapWidth : 16;
uint32_t lumaMapHeight : 16;
uint16_t lumaMapLayer;
};

struct SWarpGenPushConstants
{
uint32_t lumaMapWidth : 16;
uint32_t lumaMapHeight : 16;
uint32_t warpMapWidth : 16;
uint32_t warpMapHeight : 16;
// Both warpMap and lumaMap should have the same layer count
uint16_t lumaMapLayer;
};

NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR uint32_t GenWarpWorkgroupDim = 16;
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR uint32_t GenLumaWorkgroupDim = 16;

}
}
}
}

#endif
Loading
Loading