-
Notifications
You must be signed in to change notification settings - Fork 70
Created concepts for samplers, added quotient_and_pdf variants to satisfy the concepts #1001
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
karimsayedre
wants to merge
46
commits into
master
Choose a base branch
from
sampler-concepts
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 39 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
f71610b
Created concepts for samplers, added quotient_and_pdf variants to sat…
karimsayedre 0e0b0ad
revert bad formatting for hlsl sampling headers
karimsayedre 3574d83
Separate warp sample types from quotient_and_pdf, add sample density …
karimsayedre 168ca4d
merge master, fix conflicts
keptsecret f1493ed
changes to linear, bilinear, box muller for pdf and backward pdf
keptsecret 5933fe0
changes to solid angle method name, simplified a lot of code in spher…
keptsecret 3ac7b83
removed redundant/unused variables from spherical triangle sample
keptsecret 4ed1cbc
spherical rectangle stores origin, extent, basis and takes observer i…
keptsecret 65ef4b3
added compressed spherical rectangle, comments for info of implementa…
keptsecret 7fc8281
minor fixes to spherical rectangle stuff
keptsecret 855dac4
spherical rectangle constructor for same rectangle and observer
keptsecret 468031f
spherical rectangle create only from compressed, minor fix for spheri…
keptsecret 0f143a0
reduced duplicate methods to only ones matching (close to) concept in…
keptsecret fb0e8a5
spherical rect generate don't divide by extents, let user do that
keptsecret ab5ee78
store only needed members from tri
keptsecret 17c85ba
forward/backward pdfs for spherical triangle/rectangle, projected sph…
keptsecret d95cfa7
copied over fixed linear sampling because merge fucked up, added forw…
keptsecret 0bb7b39
add forward pdf, generate inverse to bilinear
keptsecret 89f6d5f
uniform hemi/sphere samplign make static methods private, added metho…
keptsecret e07ebc1
cosine hemi/sphere sampling make static methods private, added method…
keptsecret c4e63b3
box muller transform add forward pdf, generate wasn't merged from pt …
keptsecret c064b29
`approx_compare` uses abs then relative comparison, better sampler co…
karimsayedre d254d7a
Merge branch 'master' into sampler-concepts
karimsayedre 5bc073f
Merge branch 'master' into sampler-concepts
karimsayedre d2114f8
fixes after merge
karimsayedre 4f390b4
Merge remote-tracking branch 'origin/sampling_refactor_for_pt' into s…
karimsayedre 743575f
update `examples_tests`
karimsayedre 4d266ec
All samplers now conform to concepts
karimsayedre 86fa3f6
Added alias table and cumulative prbability builders and samplers
karimsayedre 6c79011
Merge branch 'master' into sampler-concepts
karimsayedre 254404b
update examples_tests
karimsayedre 2fa32a7
Merge branch 'master' into sampler-concepts
karimsayedre c61a63c
Merge branch 'master' into sampler-concepts
karimsayedre b720bc0
Merge branch 'master' into sampler-concepts
karimsayedre 1fb987a
addressing comments in concepts.hlsl
karimsayedre fc7e174
address comments in concepts.hlsl
karimsayedre 38f73af
Merge branch 'master' into sampler-concepts
devshgraphicsprogramming 04d5a30
Merge branch 'master' into sampler-concepts
karimsayedre edc3c3e
addressed more comments
karimsayedre b52f3c4
addressed more comments
karimsayedre 9b4ee22
update examples_tests
karimsayedre 3b7b596
Merge branch 'master' into sampler-concepts
karimsayedre a07e433
changed forwardPdf/Weight signature to take L, better core::to_string…
karimsayedre 1b46ed9
update examples_tests
karimsayedre d7ad2ce
Merge branch 'master' into sampler-concepts
karimsayedre 05bbf01
forwardPdf should take domain, not codomain
karimsayedre 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
Submodule examples_tests
updated
55 files
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
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
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
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
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
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
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
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,131 @@ | ||
| // 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_ALIAS_TABLE_INCLUDED_ | ||
| #define _NBL_BUILTIN_HLSL_SAMPLING_ALIAS_TABLE_INCLUDED_ | ||
|
|
||
| #include <nbl/builtin/hlsl/cpp_compat.hlsl> | ||
| #include <nbl/builtin/hlsl/bit.hlsl> | ||
| #include <nbl/builtin/hlsl/concepts/accessors/generic_shared_data.hlsl> | ||
|
|
||
| namespace nbl | ||
| { | ||
| namespace hlsl | ||
| { | ||
| namespace sampling | ||
| { | ||
|
|
||
| // Alias Method (Vose/Walker) discrete sampler. | ||
| // | ||
| // Samples a discrete index in [0, N) with probability proportional to | ||
| // precomputed weights in O(1) time per sample, using a prebuilt alias table. | ||
| // | ||
| // Accessor template parameters must satisfy GenericReadAccessor: | ||
| // accessor.template get<V, I>(index, outVal) // void, writes to outVal | ||
| // | ||
| // - ProbabilityAccessor: reads scalar_type threshold in [0, 1] for bin i | ||
| // - AliasIndexAccessor: reads uint32_t redirect index for bin i | ||
| // - PdfAccessor: reads scalar_type weight[i] / totalWeight | ||
| // | ||
| // Satisfies TractableSampler (not BackwardTractableSampler: the mapping is discrete). | ||
| // The cache stores the PDF value looked up during generate, avoiding redundant | ||
| // storage of the codomain (sampled index) which is already the return value. | ||
| template<typename T, typename Domain, typename Codomain, typename ProbabilityAccessor, typename AliasIndexAccessor, typename PdfAccessor | ||
| NBL_PRIMARY_REQUIRES( | ||
| concepts::accessors::GenericReadAccessor<ProbabilityAccessor, T, Codomain> && | ||
| concepts::accessors::GenericReadAccessor<AliasIndexAccessor, Codomain, Codomain> && | ||
| concepts::accessors::GenericReadAccessor<PdfAccessor, T, Codomain>) | ||
devshgraphicsprogramming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| struct AliasTable | ||
| { | ||
| using scalar_type = T; | ||
|
|
||
| using domain_type = Domain; | ||
| using codomain_type = Codomain; | ||
| using density_type = scalar_type; | ||
| using weight_type = density_type; | ||
|
|
||
| struct cache_type | ||
| { | ||
| density_type pdf; | ||
| }; | ||
|
|
||
| static AliasTable create(NBL_CONST_REF_ARG(ProbabilityAccessor) _probAccessor, NBL_CONST_REF_ARG(AliasIndexAccessor) _aliasAccessor, NBL_CONST_REF_ARG(PdfAccessor) _pdfAccessor, codomain_type _size) | ||
| { | ||
| AliasTable retval; | ||
| retval.probAccessor = _probAccessor; | ||
| retval.aliasAccessor = _aliasAccessor; | ||
| retval.pdfAccessor = _pdfAccessor; | ||
| // Precompute tableSize as float minus 1 ULP so that u=1.0 maps to bin N-1 | ||
| const scalar_type exact = scalar_type(_size); | ||
| retval.tableSizeMinusUlp = nbl::hlsl::bit_cast<scalar_type>(nbl::hlsl::bit_cast<uint32_t>(exact) - 1u); | ||
| return retval; | ||
| } | ||
|
|
||
| // BasicSampler interface | ||
| codomain_type generate(const domain_type u) | ||
| { | ||
| const scalar_type scaled = u * tableSizeMinusUlp; | ||
| const codomain_type bin = codomain_type(scaled); | ||
| const scalar_type remainder = scaled - scalar_type(bin); | ||
|
|
||
| scalar_type prob; | ||
| probAccessor.template get<scalar_type, codomain_type>(bin, prob); | ||
|
|
||
| // Use if-statement to avoid select: aliasIndex is a dependent read | ||
| codomain_type result; | ||
| if (remainder < prob) | ||
| { | ||
| result = bin; | ||
| } | ||
| else | ||
| { | ||
| codomain_type alias; | ||
| aliasAccessor.template get<codomain_type, codomain_type>(bin, alias); | ||
| result = alias; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| // TractableSampler interface | ||
| codomain_type generate(const domain_type u, NBL_REF_ARG(cache_type) cache) | ||
| { | ||
| const codomain_type result = generate(u); | ||
| pdfAccessor.template get<scalar_type, codomain_type>(result, cache.pdf); | ||
| return result; | ||
| } | ||
|
|
||
| density_type forwardPdf(NBL_CONST_REF_ARG(cache_type) cache) | ||
| { | ||
| return cache.pdf; | ||
| } | ||
|
|
||
| weight_type forwardWeight(NBL_CONST_REF_ARG(cache_type) cache) | ||
| { | ||
| return cache.pdf; | ||
| } | ||
|
|
||
| density_type backwardPdf(const codomain_type v) | ||
| { | ||
| scalar_type pdf; | ||
| pdfAccessor.template get<scalar_type, codomain_type>(v, pdf); | ||
| return pdf; | ||
| } | ||
|
|
||
| weight_type backwardWeight(const codomain_type v) | ||
| { | ||
| return backwardPdf(v); | ||
| } | ||
|
|
||
| ProbabilityAccessor probAccessor; | ||
| AliasIndexAccessor aliasAccessor; | ||
| PdfAccessor pdfAccessor; | ||
| scalar_type tableSizeMinusUlp; | ||
| }; | ||
|
|
||
| } // namespace sampling | ||
| } // namespace hlsl | ||
| } // namespace nbl | ||
|
|
||
| #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.
Uh oh!
There was an error while loading. Please reload this page.