-
Notifications
You must be signed in to change notification settings - Fork 71
Env map importance sampling #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kevyuu
wants to merge
115
commits into
master
Choose a base branch
from
env_map_importance_sampling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 fef5c4e
Fix small bug in GenericDataAccessor definition
9114750
First draft of Warpmap Generation workgroup implementation
afa2459
Add warp concept
d90486a
Add spherical warp
dbc5852
Remove envmap accessors.hlsl
6ebfbff
Hierarchical image sampling implementation
a1e86cd
Merge branch 'master' into env_map_importance_sampling
d225413
Merge branch 'master' into env_map_importance_sampling
aadbbb5
Remove envmap.hlsl
5b6e805
Move to sampling namespace and implement backward density
9ad89b2
Remove private, public from hierarchical_image
ba64dc2
Refactor hierarchical image to keep accessor and common data as member
4f06427
Refactor hierarchical image to separate binarySearch from Hierarchica…
fc59400
Fix Spherical warp indentation
2a9bee5
Add some comment why we add xi to the sample uvs
4571ba0
Merge branch 'master' into env_map_importance_sampling
756f79e
WIP
950fd87
Rename uv to coord for LuminanceAccessor concepts
9af8759
Fix hierarchical_image.hlsl
f459321
Fix typo in spherical.hlsl
b50018a
Implement gen_luma, gen_warpmap and measure_luma shaders
c91d4d1
EnvmapImportanceSampling CMakeLists
5194f7f
Initial implementation of CEnvmapImportanceSampling
edc489a
Initial implementation of CEnvmapImportanceSampling
b94019a
Small fixes
cff237a
Initial implementation of computeWarpMap
8a10dee
Fix arithmetic config no const specifier for method
7b728e4
Define config_t from outside
92202e6
More fixes on computeWarpMap implementation
51cbb81
Fix chose second to be placed inside the loop
200c51f
LuminanceReadAccessor take ScalarT as template parameter
695e667
gen_warpmap to gen_warp
d500e23
Move hierarchical_image concepts to sampling subdirectory
11dd229
Add some comment regarding corner sampling
563343a
Parameterize spherical warp and make sure all literal is in the corre…
99cc8c2
Refactor CEnvmapImportanceSampling to block and calculate avgLuma
a2c52bf
Fix warp concept and add density type to warp concept
c2021ab
Rename luminanceScale to lumaRGBCoefficients
a4e81d1
Remove measure_luma.comp.hlsl
a2362ff
Fix some bug in hierarchical_image.hlsl
d6ed947
Rename luminanceScales to lumaRGBCoefficients
5043062
Move EnvmapImportanceSampling from ext to core
5c159d0
Fix binarySearch implementation. when last is 2x1 we should check for…
6c9c3b2
Rename private member with underscore prefix
e54fc56
Merge branch 'master' into env_map_importance_sampling
5b85c44
Update submodule to follow master branch
108b129
Add missed EnvmapSampler.h and cpp
e8aa426
Rename get and gather to texelFetch and texelGather
e7e2c70
Merge branch 'hlsl_path_tracer_example' into env_map_importance_sampling
8b4a6d0
Include missing files into commit
c0b2eae
Merge branch 'master' into env_map_importance_sampling
f54b77f
Update comment on sampleUvs
f306698
Use bitfield for lumaMapResolution in push constant
0c11ab7
Remove NBL_BUILD_ENVMAP_IMPORTANCE_SAMPLING option
77fb274
Fix worgroup dim for gen_warp
6a9cda4
Use constant workgroup dimension instead of WORKGROUP_DIM define
32cebd4
Remove passing WORKGROUP_DIM to shader
12d4653
Remove passing WORKGROUP_DIM for gen_luma
0b3954b
Add upsscale parameter for EnvmapSampler
65c0e82
Pass warpMap width and height to luminanceSampler. Check For Out of B…
ffb8d69
Small fixes to gen_warp shader
ffddb4a
gen_warp get image dimension from push constant instead of OpImageQue…
5990b90
Rename HierarchicalImage to WarpmapSampler
967094d
Add todo comment for cube map
deb6906
Move EnvmapSampler from core/sampling to video/sampling
34f5872
Rename LuminanceSampler to HierarchicalLuminanceSampler
4b7a984
Fix corner sampling logic in gen_luma and hierarchical_image.hlsl
a6f1704
Fix previous commit
e57c999
Add some todo comment for corner sampling flag
7a8ba14
Add const modifier for binarySearch
9295167
Add some temporary struct from pr #1001
9241d29
Refactor hierarchical_image naming and concepts
8108ca7
Fix indentation of hierarchical_image.hlsl
326544d
Small fixes
6292560
Remove superfluous member from WarpmapSampler
e2b9676
Merge branch 'master' into env_map_importance_sampling
ec6adf0
Fix resolve.hlsl case
97b8439
Merge branch 'master' into env_map_importance_sampling
c23fb61
Rename GenWarpWorkgroupDim and GenLumaWorkgroupDim
kevyuu 345065b
Fix include guard of warps/spherical.hlsl
kevyuu 7c7c30a
Undo Embed built-in resources option to OFF
kevyuu 615c328
Gen Luma now support Texture Array
kevyuu 4988fb2
Remove unused member in HierarchicalWarpGenerator
kevyuu eb47cee
Remove LuminanceReadAccessor concept and support Texture2DArray for g…
kevyuu 0ebe456
Rename _mip2x1 to _lastMipLevel
kevyuu 2676c55
Fix envmapsampler header guard
kevyuu 35469eb
Remove unused defaults in EnvmapSampler
kevyuu b5d4012
Undo cuda interop cmake option
kevyuu cef9494
Improve comment on hierarchical_image
kevyuu a26691d
Using sincos in spherical.hlsl
kevyuu 5a8e7f4
Rework hierarchical_image and sphericalSampling to follow new sampler…
kevyuu 0cdbbec
refactor: Improve `generate` function and sampling logic
kevyuu 22db1dc
refactor: Update backwardPdf and backwardWeight logic
kevyuu 769f5f4
refactor: Improve hierarchical image sampling system
kevyuu 0afcadc
refactor: Implement MipmappedLuminanceReadAccessor
kevyuu 646d165
refactor: Embed value_type inside LuminanceReadAccessor
kevyuu 523b9c0
refactor: embed scalar_type inside WarpAccessor
kevyuu 1d1cb73
fix: Forward Weight calculation in WarpMapSampler
kevyuu 3cfa3c6
fix: Implement bacwardWeight for WarpGenerator
kevyuu bd32b33
refactor: Rename HierarchicalWarpGenerator to HierarchicalLuminanceSa…
kevyuu 504b00b
Rename HierarchicalWarpSampler to ComposedHierarchicalSampler
kevyuu 4b1b52c
Remove deleted hlsl from list of builtin resource in CMake
kevyuu 181a487
Add constraints and improve type consistency for HierarchicalLuminanc…
kevyuu cd42179
Move WarpmapSampler into its own file
kevyuu dafba0a
Fix include guard of hierarchical_image/accesors.hlsl
kevyuu a5194b4
Unify pipelineLayout and descriptorSet for genLuma and genWarp
kevyuu c074e6a
Remove mount method in EnvmapSampler
kevyuu 17a7de7
Implement common pipeline creation function
kevyuu 38b50cf
Added SSession on EnvmapSampler
kevyuu 00e5b4c
Rename EnvmapSampler CEnvmapWarpGenerator
kevyuu 99a8c09
Move LumaRgBCoeffecients as constant in hlsl header
kevyuu 4b53ad5
Implement multi layer gen_luma and gen_warp
kevyuu 2dc25fa
Remove non write access from srcAccessMask in image barriers
kevyuu dbcde57
Update submodule to latest master
kevyuu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
237 changes: 237 additions & 0 deletions
237
include/nbl/builtin/hlsl/sampling/hierarchical_image.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| 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 | ||
96 changes: 96 additions & 0 deletions
96
include/nbl/builtin/hlsl/sampling/hierarchical_image/accessors.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
42
include/nbl/builtin/hlsl/sampling/hierarchical_image/common.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
devshgraphicsprogramming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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