-
Notifications
You must be signed in to change notification settings - Fork 16
Envmap sampling test #257
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
2
commits into
master
Choose a base branch
from
envmap_sampling_test
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
Envmap sampling test #257
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| include(common RESULT_VARIABLE RES) | ||
| if(NOT RES) | ||
| message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory") | ||
| endif() | ||
|
|
||
| nbl_create_executable_project("" "" "" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}") | ||
|
|
||
| if(NBL_EMBED_BUILTIN_RESOURCES) | ||
| set(_BR_TARGET_ ${EXECUTABLE_NAME}_builtinResourceData) | ||
| set(RESOURCE_DIR "app_resources") | ||
|
|
||
| get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) | ||
| get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE) | ||
| get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE) | ||
|
|
||
| file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*") | ||
| foreach(RES_FILE ${BUILTIN_RESOURCE_FILES}) | ||
| LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}") | ||
| endforeach() | ||
|
|
||
| ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}") | ||
|
|
||
| LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_}) | ||
| endif() | ||
|
|
||
| add_dependencies(${EXECUTABLE_NAME} argparse) | ||
| target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:argparse,INTERFACE_INCLUDE_DIRECTORIES>) | ||
|
|
||
| enable_testing() | ||
|
|
||
| add_test(NAME NBL_IMAGE_HASH_RUN_TESTS | ||
| COMMAND "$<TARGET_FILE:${EXECUTABLE_NAME}>" --test hash | ||
| WORKING_DIRECTORY "$<TARGET_FILE_DIR:${EXECUTABLE_NAME}>" | ||
| COMMAND_EXPAND_LISTS | ||
| ) | ||
|
|
||
| set(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/auto-gen") | ||
|
|
||
| set(SM 6_8) | ||
| set(JSON [=[ | ||
| [ | ||
| { | ||
| "INPUT": "app_resources/test.comp.hlsl", | ||
| "KEY": "test", | ||
| }] | ||
| ]=]) | ||
| string(CONFIGURE "${JSON}" JSON) | ||
|
|
||
| set(COMPILE_OPTIONS | ||
| -I "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| -T lib_${SM} | ||
| ) | ||
|
|
||
| NBL_CREATE_NSC_COMPILE_RULES( | ||
| TARGET ${EXECUTABLE_NAME}SPIRV | ||
| LINK_TO ${EXECUTABLE_NAME} | ||
| BINARY_DIR ${OUTPUT_DIRECTORY} | ||
| MOUNT_POINT_DEFINE NBL_THIS_EXAMPLE_BUILD_MOUNT_POINT | ||
| COMMON_OPTIONS ${COMPILE_OPTIONS} | ||
| OUTPUT_VAR KEYS | ||
| INCLUDE nbl/this_example/builtin/build/spirv/keys.hpp | ||
| NAMESPACE nbl::this_example::builtin::build | ||
| INPUTS ${JSON} | ||
| ) | ||
|
|
||
| NBL_CREATE_RESOURCE_ARCHIVE( | ||
| NAMESPACE nbl::this_example::builtin::build | ||
| TARGET ${EXECUTABLE_NAME}_builtinsBuild | ||
| LINK_TO ${EXECUTABLE_NAME} | ||
| BIND ${OUTPUT_DIRECTORY} | ||
| BUILTINS ${KEYS} | ||
| ) | ||
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,38 @@ | ||
| #ifndef _ENVMAP_IMPORTANCE_SAMPLING_SEARCH_H_INCLUDED_ | ||
| #define _ENVMAP_IMPORTANCE_SAMPLING_SEARCH_H_INCLUDED_ | ||
|
|
||
| #include <nbl/builtin/hlsl/cpp_compat/basic.h> | ||
| #include <nbl/builtin/hlsl/cpp_compat/vector.hlsl> | ||
|
|
||
| using namespace nbl; | ||
| using namespace nbl::hlsl; | ||
|
|
||
| NBL_CONSTEXPR uint32_t WorkgroupSize = 128; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 64 to be more representative of path tracing workloads |
||
|
|
||
| struct STestPushConstants | ||
| { | ||
| float32_t eps; | ||
| uint64_t outputAddress; | ||
| uint32_t2 warpResolution; | ||
| float32_t avgLuma; | ||
| }; | ||
|
|
||
| struct TestOutput | ||
| { | ||
| float32_t3 L; | ||
| float32_t2 uv; | ||
| float32_t jacobian; | ||
| float32_t pdf; | ||
| float32_t deferredPdf; | ||
| }; | ||
|
|
||
| struct TestSample | ||
| { | ||
| TestOutput directOutput; | ||
| TestOutput cachedOutput; | ||
| float32_t2 xi; | ||
| }; | ||
|
|
||
| using test_sample_t = TestSample; | ||
|
|
||
| #endif // _COOPERATIVE_BINARY_SEARCH_H_INCLUDED_ | ||
24 changes: 24 additions & 0 deletions
24
75_EnvmapImportanceSamplingTest/app_resources/present.frag.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,24 @@ | ||
| // Copyright (C) 2024-2024 - 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 | ||
|
|
||
| #pragma wave shader_stage(fragment) | ||
|
|
||
| // vertex shader is provided by the fullScreenTriangle extension | ||
| #include <nbl/builtin/hlsl/ext/FullScreenTriangle/SVertexAttributes.hlsl> | ||
| using namespace nbl::hlsl::ext::FullScreenTriangle; | ||
|
|
||
| [[vk::binding(0, 3)]] Texture2D<float32_t2> warpMap; | ||
| [[vk::combinedImageSampler]][[vk::binding(1, 3)]] Texture2D<float32_t4> envMap; | ||
| [[vk::combinedImageSampler]][[vk::binding(1, 3)]] SamplerState envMapSampler; | ||
|
|
||
| [[vk::location(0)]] float32_t4 main(SVertexAttributes vxAttr) : SV_Target0 | ||
| { | ||
| uint width; | ||
| uint height; | ||
| warpMap.GetDimensions(width, height); | ||
| float32_t2 uv = warpMap.Load(uint32_t3(width * vxAttr.uv.x, height * vxAttr.uv.y, 0)); | ||
| float32_t4 color = envMap.Sample(envMapSampler, uv); | ||
|
|
||
| return float32_t4(color.xyz, 1.0); | ||
| } |
134 changes: 134 additions & 0 deletions
134
75_EnvmapImportanceSamplingTest/app_resources/test.comp.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,134 @@ | ||
| #include "common.hlsl" | ||
|
|
||
| #include <nbl/builtin/hlsl/sampling/hierarchical_image.hlsl> | ||
| #include <nbl/builtin/hlsl/random/pcg.hlsl> | ||
| #include <nbl/builtin/hlsl/random/dim_adaptor_recursive.hlsl> | ||
| #include <nbl/builtin/hlsl/tgmath.hlsl> | ||
| #include <nbl/builtin/hlsl/sampling/warps/spherical.hlsl> | ||
| #include <nbl/builtin/hlsl/cpp_compat.hlsl> | ||
|
|
||
| [[vk::push_constant]] STestPushConstants pc; | ||
|
|
||
| [[vk::combinedImageSampler]][[vk::binding(0, 0)]] Texture2D<float32_t> lumaMap; | ||
| [[vk::combinedImageSampler]][[vk::binding(0, 0)]] SamplerState lumaSampler; | ||
|
|
||
| [[vk::combinedImageSampler]][[vk::binding(1, 0)]] Texture2D<float32_t2> warpMap; | ||
| [[vk::combinedImageSampler]][[vk::binding(1, 0)]] SamplerState warpSampler; | ||
|
|
||
| using namespace nbl::hlsl::sampling::hierarchical_image; | ||
|
|
||
|
|
||
| struct LuminanceAccessor | ||
| { | ||
| template <typename ValT, typename IndexT | ||
| NBL_FUNC_REQUIRES( | ||
| concepts::same_as<IndexT, float32_t2> && | ||
| concepts::same_as<ValT, float32_t> | ||
| ) | ||
| void get(IndexT index, NBL_REF_ARG(ValT) val) | ||
| { | ||
| val = lumaMap.SampleLevel(lumaSampler, index, 0); | ||
| } | ||
|
|
||
| float32_t texelFetch(uint32_t2 coord, uint32_t level) | ||
| { | ||
| return lumaMap.Load(uint32_t3(coord, level)); | ||
| } | ||
|
|
||
| float32_t4 texelGather(uint32_t2 coord, uint32_t level) | ||
| { | ||
| return float32_t4( | ||
| lumaMap.Load(uint32_t3(coord, level), uint32_t2(0, 1)), | ||
| lumaMap.Load(uint32_t3(coord, level), uint32_t2(1, 1)), | ||
| lumaMap.Load(uint32_t3(coord, level), uint32_t2(1, 0)), | ||
| lumaMap.Load(uint32_t3(coord, level), uint32_t2(0, 0)) | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| struct WarpAccessor | ||
| { | ||
| matrix<float, 4, 2> sampleUvs(uint32_t2 sampleCoord) NBL_CONST_MEMBER_FUNC | ||
| { | ||
| const float32_t2 dir0 = warpMap.Load(int32_t3(sampleCoord + uint32_t2(0, 1), 0)); | ||
| const float32_t2 dir1 = warpMap.Load(int32_t3(sampleCoord + uint32_t2(1, 1), 0)); | ||
| const float32_t2 dir2 = warpMap.Load(int32_t3(sampleCoord + uint32_t2(1, 0), 0)); | ||
| const float32_t2 dir3 = warpMap.Load(int32_t3(sampleCoord, 0)); | ||
| return matrix<float, 4, 2>( | ||
| dir0, | ||
| dir1, | ||
| dir2, | ||
| dir3 | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| template <typename HierarchicalImageT> | ||
| TestOutput GenerateTestOutput(NBL_CONST_REF_ARG(HierarchicalImageT) hImage, float32_t2 xi) | ||
| { | ||
| float pdf; | ||
| float32_t2 uv; | ||
|
|
||
| const float3 L = hImage.generate_and_pdf(pdf, uv, xi); | ||
|
|
||
| float eps_x = pc.eps; | ||
| float eps_y = pc.eps; | ||
|
|
||
| float32_t2 d_uv; | ||
| float32_t d_pdf; | ||
| const float3 L_plus_du = hImage.generate_and_pdf(d_pdf, d_uv, xi + float32_t2(0.5f * eps_x, 0)); | ||
| const float3 L_plus_dv = hImage.generate_and_pdf(d_pdf, d_uv, xi + float32_t2(0, 0.5f * eps_y)); | ||
|
|
||
| const float3 L_minus_du = hImage.generate_and_pdf(d_pdf, d_uv, xi - float32_t2(0.5f * eps_x, 0)); | ||
| const float3 L_minus_dv = hImage.generate_and_pdf(d_pdf, d_uv, xi - float32_t2(0, 0.5f * eps_y)); | ||
|
|
||
| float jacobian = length(cross(L_plus_du - L_minus_du, L_plus_dv - L_minus_dv)) / (eps_x * eps_y); | ||
|
|
||
| TestOutput testOutput; | ||
| testOutput.uv = uv; | ||
| testOutput.L = L; | ||
| testOutput.jacobian = jacobian; | ||
| testOutput.pdf = pdf; | ||
| testOutput.deferredPdf = hImage.deferredPdf(L); | ||
| return testOutput; | ||
| } | ||
|
|
||
| float32_t2 convertToFloat01(uint32_t2 xi_uint) | ||
| { | ||
| return float32_t2(xi_uint) / promote<float32_t2>(float32_t(numeric_limits<uint32_t>::max)); | ||
| } | ||
|
|
||
| [numthreads(WorkgroupSize, 1, 1)] | ||
| [shader("compute")] | ||
| void main(uint32_t3 threadID : SV_DispatchThreadID) | ||
| { | ||
| const LuminanceAccessor luminanceAccessor; | ||
| const WarpAccessor warpAccessor; | ||
| using luminance_sampler_type = nbl::hlsl::sampling::LuminanceMapSampler<float32_t, LuminanceAccessor>; | ||
|
|
||
| using direct_hierarchical_image_type = sampling::HierarchicalImage<float, LuminanceAccessor, luminance_sampler_type, sampling::warp::Spherical<float> >; | ||
|
|
||
| const luminance_sampler_type luminanceSampler = luminance_sampler_type::create(luminanceAccessor, pc.warpResolution, true, pc.warpResolution); | ||
|
|
||
| float32_t eps = pc.eps; | ||
|
|
||
| random::PCG32 pcg = random::PCG32::construct(threadID.x); | ||
| uint32_t2 xi_uint = random::DimAdaptorRecursive<random::PCG32, 2>::__call(pcg); | ||
|
|
||
| float32_t2 xi = convertToFloat01(xi_uint); | ||
|
|
||
| xi.x = hlsl::clamp(xi.x, eps, 1.f - eps); | ||
| xi.y = hlsl::clamp(xi.y, eps, 1.f - eps); | ||
|
|
||
| test_sample_t testSample; | ||
| testSample.xi = xi; | ||
|
|
||
| const direct_hierarchical_image_type directHImage = direct_hierarchical_image_type::create(luminanceAccessor, luminanceSampler, pc.warpResolution, pc.avgLuma); | ||
| testSample.directOutput = GenerateTestOutput(directHImage, xi); | ||
|
|
||
| using cached_hierarchical_image_type = sampling::HierarchicalImage<float, LuminanceAccessor, WarpAccessor, sampling::warp::Spherical<float> >; | ||
| const cached_hierarchical_image_type cachedHImage = cached_hierarchical_image_type::create(luminanceAccessor, warpAccessor, pc.warpResolution, pc.avgLuma); | ||
| testSample.cachedOutput = GenerateTestOutput(cachedHImage, xi); | ||
| vk::RawBufferStore<test_sample_t>(pc.outputAddress + threadID.x * sizeof(test_sample_t), testSample); | ||
| } |
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,28 @@ | ||
| { | ||
| "enableParallelBuild": true, | ||
| "threadsPerBuildProcess" : 2, | ||
| "isExecuted": false, | ||
| "scriptPath": "", | ||
| "cmake": { | ||
| "configurations": [ "Release", "Debug", "RelWithDebInfo" ], | ||
| "buildModes": [], | ||
| "requiredOptions": [] | ||
| }, | ||
| "profiles": [ | ||
| { | ||
| "backend": "vulkan", | ||
| "platform": "windows", | ||
| "buildModes": [], | ||
| "runConfiguration": "Release", | ||
| "gpuArchitectures": [] | ||
| } | ||
| ], | ||
| "dependencies": [], | ||
| "data": [ | ||
| { | ||
| "dependencies": [], | ||
| "command": [""], | ||
| "outputs": [] | ||
| } | ||
| ] | ||
| } |
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,7 @@ | ||
| ; This is the testing suite for various Nabla loaders/writers (JPG/PNG/TGA/BMP/DDS/KTX). | ||
| ; BMP is currently unsupported for now. | ||
| ; 16-bit PNG & 8-bit RLE (compressed) TGA is not supported. | ||
| ; For licensing attribution, see LICENSE. | ||
|
|
||
| ; JPG, colored & 8-bit grayscale | ||
| ../../media/envmap/envmap_1.exr |
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.
@AnastaZIuk review and okay the CMake