-
Notifications
You must be signed in to change notification settings - Fork 12
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
Autoexposure example restoration #137
Open
devshgraphicsprogramming
wants to merge
48
commits into
master
Choose a base branch
from
autoexposure_ex
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
48 commits
Select commit
Hold shift + click to select a range
345ac7b
Add 26_Autoexposure
nipunG314 87d4794
Change 26_Autoexposure to SimpleWindowedApplication
nipunG314 7a5ea7c
Build a staging buffer and upload exr image
nipunG314 5026a64
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
nipunG314 5d63d04
Init surface and create the swapchain
nipunG314 640e6a3
Load shaders and create the pipeline for full screen triagnle
nipunG314 0148f60
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
nipunG314 d69a111
Set window size according to loaded image
nipunG314 54bf38f
Stop running if window is closed
nipunG314 461efd3
Acquire swapchain image and present uploaded image to it
nipunG314 734fea9
Set window size directly and use that for swapchain rendering
nipunG314 fc9b0bb
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
nipunG314 4a11724
m_computeSubgroupSize
nipunG314 734b887
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
nipunG314 7d4895a
Allocate buffer for gathered luma values
nipunG314 0e3e125
Create gpu resources for all passes
nipunG314 cef80b3
Create shaders and pipelines
nipunG314 15e489f
Allocate and create texture for tonemapping
nipunG314 c646c7d
Create separate ds for luma and present
nipunG314 36d7097
Record luma meter commands
nipunG314 3a70977
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
nipunG314 6addbf1
fix layout issues with compute pipeline in 26_Autoexposure example + …
AnastaZIuk 8434f20
Create two sets from common lumaPresentLayout correctly
nipunG314 bf08caa
Create compute and graphics resources separately and finish luma meter
nipunG314 b342c6c
Fix descriptor binding for luma_meter
nipunG314 817c4a7
Create separate pipeline layouts for luma and present
nipunG314 7f89542
Setup luma_meter.comp.hlsl
nipunG314 defd45e
Pass push constants
nipunG314 f6f8154
Record draw pass correctly
nipunG314 64eb610
Add a pipeline barrier to transition image layout
nipunG314 3d3d646
Record tonemapping pass
nipunG314 b4102dc
Revert "Record tonemapping pass"
nipunG314 8307e92
Remove separate tonemapping pass
nipunG314 7b5ca05
Compute final EV value on CPU
nipunG314 edbf8d1
Compute EV correctly and tonemap in fragment shader
nipunG314 dca49d2
Separate LumaMeteringWindow into a common header
nipunG314 9e28395
Simplify luma_meter naming
nipunG314 8b6675b
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla-…
nipunG314 18fae9f
Update luma examples to shared accessor api
nipunG314 9b31c2c
Refactor tonemapping operators
nipunG314 e987452
Simplify push constants and remove explicit sample counts
nipunG314 e135e43
Infer sample count from viewportSize and simplify userspace HLSL
nipunG314 57e49ae
Templatize float type and add toXYZ method to TexAccessor
nipunG314 f8d50e8
Refactor the example into using a 2-compute, 1-fragment architecture
nipunG314 d3b5765
Handle image layouts correctly
nipunG314 612f0f6
Simplify type
nipunG314 cb46d82
Wait for correct semaphore value
nipunG314 1996cf3
Remove unnecessary data members
nipunG314 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,25 @@ | ||
|
||
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() |
This file contains 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 @@ | ||
// Copyright (C) 2018-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 | ||
|
||
#ifndef _AUTOEXPOSURE_COMMON_INCLUDED_ | ||
#define _AUTOEXPOSURE_COMMON_INCLUDED_ | ||
|
||
#include "nbl/builtin/hlsl/cpp_compat.hlsl" | ||
#include "nbl/builtin/hlsl/luma_meter/common.hlsl" | ||
|
||
namespace nbl | ||
{ | ||
namespace hlsl | ||
{ | ||
|
||
struct AutoexposurePushData | ||
{ | ||
luma_meter::MeteringWindow window; | ||
float32_t2 lumaMinMax; | ||
float32_t sampleCount; | ||
uint32_t2 viewportSize; | ||
uint64_t lumaMeterBDA; | ||
}; | ||
|
||
} | ||
} | ||
|
||
#endif |
This file contains 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,89 @@ | ||
// 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 | ||
|
||
#include "nbl/builtin/hlsl/luma_meter/luma_meter.hlsl" | ||
#include "nbl/builtin/hlsl/bda/bda_accessor.hlsl" | ||
#include "nbl/builtin/hlsl/colorspace/EOTF.hlsl" | ||
#include "nbl/builtin/hlsl/colorspace/encodeCIEXYZ.hlsl" | ||
#include "nbl/builtin/hlsl/colorspace/decodeCIEXYZ.hlsl" | ||
#include "nbl/builtin/hlsl/colorspace/OETF.hlsl" | ||
#include "nbl/builtin/hlsl/tonemapper/operators.hlsl" | ||
#include "app_resources/common.hlsl" | ||
|
||
[[vk::combinedImageSampler]] [[vk::binding(0, 0)]] Texture2D textureIn; | ||
[[vk::combinedImageSampler]] [[vk::binding(0, 0)]] SamplerState samplerStateIn; | ||
[[vk::binding(0, 3)]] RWTexture2D<float32_t4> textureOut; | ||
|
||
using namespace nbl::hlsl; | ||
using Ptr = bda::__ptr < uint32_t >; | ||
using PtrAccessor = BdaAccessor < uint32_t >; | ||
|
||
[[vk::push_constant]] AutoexposurePushData pushData; | ||
|
||
groupshared float32_t sdata[WorkgroupSize]; | ||
struct SharedAccessor | ||
{ | ||
using type = float32_t; | ||
void get(const uint32_t index, NBL_REF_ARG(uint32_t) value) | ||
{ | ||
value = sdata[index]; | ||
} | ||
|
||
void set(const uint32_t index, const uint32_t value) | ||
{ | ||
sdata[index] = value; | ||
} | ||
|
||
void workgroupExecutionAndMemoryBarrier() | ||
{ | ||
glsl::barrier(); | ||
} | ||
}; | ||
|
||
struct TexAccessor | ||
{ | ||
static float32_t3 toXYZ(float32_t3 srgbColor) { | ||
return dot(colorspace::sRGBtoXYZ[1], srgbColor); | ||
} | ||
|
||
float32_t3 get(float32_t2 uv) { | ||
return textureIn.Sample(samplerStateIn, uv).rgb; | ||
} | ||
}; | ||
|
||
uint32_t3 glsl::gl_WorkGroupSize() | ||
{ | ||
return uint32_t3(WorkgroupSize, 1, 1); | ||
} | ||
|
||
[numthreads(DeviceSubgroupSize, DeviceSubgroupSize, 1)] | ||
void main(uint32_t3 ID : SV_GroupThreadID, uint32_t3 GroupID : SV_GroupID) | ||
{ | ||
const Ptr val_ptr = Ptr::create(pushData.lumaMeterBDA); | ||
PtrAccessor val_accessor = PtrAccessor::create(val_ptr); | ||
|
||
SharedAccessor sdata; | ||
TexAccessor tex; | ||
|
||
using LumaMeter = luma_meter::geom_meter< WorkgroupSize, PtrAccessor, SharedAccessor, TexAccessor>; | ||
LumaMeter meter = LumaMeter::create(pushData.lumaMinMax, pushData.sampleCount); | ||
|
||
float32_t EV = meter.gatherLuma(val_accessor); | ||
|
||
uint32_t tid = workgroup::SubgroupContiguousIndex(); | ||
uint32_t2 coord = { | ||
morton2d_decode_x(tid), | ||
morton2d_decode_y(tid) | ||
}; | ||
|
||
uint32_t2 pos = glsl::gl_WorkGroupID() * glsl::gl_WorkGroupSize() + coord; | ||
|
||
float32_t2 uv = (float32_t2)(pos) / pushData.viewportSize; | ||
float32_t3 color = colorspace::oetf::sRGB(tex.get(uv).rgb); | ||
float32_t3 CIEColor = mul(colorspace::sRGBtoXYZ, color); | ||
tonemapper::Reinhard<float32_t> reinhard = tonemapper::Reinhard<float32_t>::create(EV); | ||
float32_t3 tonemappedColor = mul(colorspace::decode::XYZtoscRGB, reinhard(CIEColor)); | ||
|
||
textureOut[pos] = float32_t4(colorspace::eotf::sRGB(tonemappedColor), 1.0f); | ||
} |
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.
shouldn't a struct for push constants shared between your Luma Meter and Tonemapper supposed to be in the extension headers?