mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 02:29:17 +02:00
fix gtao glitches; add timer to measure animation phase
This commit is contained in:
1
Timer.h
1
Timer.h
@@ -58,6 +58,7 @@ struct subsystem_stopwatches {
|
|||||||
stopwatch gfx_reflections;
|
stopwatch gfx_reflections;
|
||||||
stopwatch gfx_swap;
|
stopwatch gfx_swap;
|
||||||
stopwatch gfx_gui;
|
stopwatch gfx_gui;
|
||||||
|
stopwatch gfx_animate;
|
||||||
stopwatch sim_total;
|
stopwatch sim_total;
|
||||||
stopwatch sim_dynamics;
|
stopwatch sim_dynamics;
|
||||||
stopwatch sim_events;
|
stopwatch sim_events;
|
||||||
|
|||||||
@@ -161,21 +161,21 @@ namespace XeGTAO
|
|||||||
template<class T> inline T clamp( T const & v, T const & min, T const & max ) { assert( max >= min ); if( v < min ) return min; if( v > max ) return max; return v; }
|
template<class T> inline T clamp( T const & v, T const & min, T const & max ) { assert( max >= min ); if( v < min ) return min; if( v > max ) return max; return v; }
|
||||||
|
|
||||||
// If using TAA then set noiseIndex to frameIndex % 64 - otherwise use 0
|
// If using TAA then set noiseIndex to frameIndex % 64 - otherwise use 0
|
||||||
inline void GTAOUpdateConstants( XeGTAO::GTAOConstants& consts, int viewportWidth, int viewportHeight, const XeGTAO::GTAOSettings & settings, const float projMatrix[16], bool rowMajor, unsigned int frameCounter )
|
inline void GTAOUpdateConstants( XeGTAO::GTAOConstants& consts, int viewportWidth, int viewportHeight, const XeGTAO::GTAOSettings & settings, const glm::mat4& projMatrix, bool rowMajor, unsigned int frameCounter )
|
||||||
{
|
{
|
||||||
consts.ViewportSize = { viewportWidth, viewportHeight };
|
consts.ViewportSize = { viewportWidth, viewportHeight };
|
||||||
consts.ViewportPixelSize = { 1.0f / (float)viewportWidth, 1.0f / (float)viewportHeight };
|
consts.ViewportPixelSize = { 1.0f / (float)viewportWidth, 1.0f / (float)viewportHeight };
|
||||||
|
|
||||||
float depthLinearizeMul = (rowMajor)?(-projMatrix[3 * 4 + 2]):(-projMatrix[3 + 2 * 4]); // float depthLinearizeMul = ( clipFar * clipNear ) / ( clipFar - clipNear );
|
float depthLinearizeMul = -projMatrix[3][2]; // float depthLinearizeMul = ( clipFar * clipNear ) / ( clipFar - clipNear );
|
||||||
float depthLinearizeAdd = (rowMajor)?( projMatrix[2 * 4 + 2]):( projMatrix[2 + 2 * 4]); // float depthLinearizeAdd = clipFar / ( clipFar - clipNear );
|
float depthLinearizeAdd = -projMatrix[2][2]; // float depthLinearizeAdd = clipFar / ( clipFar - clipNear );
|
||||||
|
|
||||||
// correct the handedness issue. need to make sure this below is correct, but I think it is.
|
// correct the handedness issue. need to make sure this below is correct, but I think it is.
|
||||||
if( depthLinearizeMul * depthLinearizeAdd < 0 )
|
if( depthLinearizeMul * depthLinearizeAdd < 0 )
|
||||||
depthLinearizeAdd = -depthLinearizeAdd;
|
depthLinearizeAdd = -depthLinearizeAdd;
|
||||||
consts.DepthUnpackConsts = { -depthLinearizeMul, depthLinearizeAdd };
|
consts.DepthUnpackConsts = { depthLinearizeMul, depthLinearizeAdd };
|
||||||
|
|
||||||
float tanHalfFOVY = 1.0f / ((rowMajor)?(projMatrix[1 * 4 + 1]):(projMatrix[1 + 1 * 4])); // = tanf( drawContext.Camera.GetYFOV( ) * 0.5f );
|
float tanHalfFOVY = 1.0f / projMatrix[1][1]; // = tanf( drawContext.Camera.GetYFOV( ) * 0.5f );
|
||||||
float tanHalfFOVX = 1.0F / ((rowMajor)?(projMatrix[0 * 4 + 0]):(projMatrix[0 + 0 * 4])); // = tanHalfFOVY * drawContext.Camera.GetAspect( );
|
float tanHalfFOVX = 1.0F / projMatrix[0][0]; // = tanHalfFOVY * drawContext.Camera.GetAspect( );
|
||||||
consts.CameraTanHalfFOV = { tanHalfFOVX, tanHalfFOVY };
|
consts.CameraTanHalfFOV = { tanHalfFOVX, tanHalfFOVY };
|
||||||
|
|
||||||
consts.NDCToViewMul = { consts.CameraTanHalfFOV.x * 2.0f, consts.CameraTanHalfFOV.y * -2.0f };
|
consts.NDCToViewMul = { consts.CameraTanHalfFOV.x * 2.0f, consts.CameraTanHalfFOV.y * -2.0f };
|
||||||
|
|||||||
@@ -1321,6 +1321,8 @@ void NvRenderer::DebugUi() {
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Bloom Config")) m_bloom->ShowGui();
|
if (ImGui::Button("Bloom Config")) m_bloom->ShowGui();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
m_ssao->OnGui(ImGui::Button("GTAO Config"));
|
||||||
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Take Screenshot")) MakeScreenshot();
|
if (ImGui::Button("Take Screenshot")) MakeScreenshot();
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
@@ -129,6 +129,27 @@ void NvSsao::Init() {
|
|||||||
.addBindingLayout(blPrefilterDepths));
|
.addBindingLayout(blPrefilterDepths));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
BindingLayoutHandle blPrefilterDepths;
|
||||||
|
BindingSetDesc bsDescPrefilter =
|
||||||
|
BindingSetDesc()
|
||||||
|
.addItem(BindingSetItem::ConstantBuffer(0, m_constantBuffer))
|
||||||
|
.addItem(BindingSetItem::Texture_SRV(0, m_gbuffer->m_gbuffer_depth))
|
||||||
|
.addItem(BindingSetItem::Sampler(0, sampler_point));
|
||||||
|
for (int i = 0; i < XE_GTAO_DEPTH_MIP_LEVELS; ++i) {
|
||||||
|
bsDescPrefilter.addItem(
|
||||||
|
BindingSetItem::Texture_UAV(i, m_workingDepths, Format::UNKNOWN,
|
||||||
|
TextureSubresourceSet(i, 1, 0, 1)));
|
||||||
|
}
|
||||||
|
utils::CreateBindingSetAndLayout(m_backend->GetDevice(),
|
||||||
|
ShaderType::Compute, 0, bsDescPrefilter,
|
||||||
|
blPrefilterDepths, m_BSPrefilterDepths);
|
||||||
|
m_PSOPrefilterDepths = m_backend->GetDevice()->createComputePipeline(
|
||||||
|
ComputePipelineDesc()
|
||||||
|
.setComputeShader(m_CSPrefilterDepths16x16)
|
||||||
|
.addBindingLayout(blPrefilterDepths));
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
BindingLayoutHandle blGTAO;
|
BindingLayoutHandle blGTAO;
|
||||||
utils::CreateBindingSetAndLayout(
|
utils::CreateBindingSetAndLayout(
|
||||||
@@ -187,12 +208,8 @@ void NvSsao::Render(nvrhi::ICommandList* command_list,
|
|||||||
command_list->beginMarker("XeGTAO");
|
command_list->beginMarker("XeGTAO");
|
||||||
|
|
||||||
XeGTAO::GTAOConstants constants{};
|
XeGTAO::GTAOConstants constants{};
|
||||||
XeGTAO::GTAOSettings settings{};
|
|
||||||
settings.QualityLevel = 2;
|
|
||||||
settings.Radius = 10.f;
|
|
||||||
settings.ThinOccluderCompensation = .7f;
|
|
||||||
XeGTAO::GTAOUpdateConstants(constants, m_width, m_height, settings,
|
XeGTAO::GTAOUpdateConstants(constants, m_width, m_height, settings,
|
||||||
glm::value_ptr(projection), false, frame_index);
|
projection, false, frame_index);
|
||||||
command_list->writeBuffer(m_constantBuffer, &constants, sizeof(constants));
|
command_list->writeBuffer(m_constantBuffer, &constants, sizeof(constants));
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -222,7 +239,7 @@ void NvSsao::Render(nvrhi::ICommandList* command_list,
|
|||||||
|
|
||||||
{
|
{
|
||||||
command_list->beginMarker("Denoise Pass");
|
command_list->beginMarker("Denoise Pass");
|
||||||
int num_passes = 4;
|
int num_passes = settings.DenoisePasses;
|
||||||
nvrhi::ITexture* ping = m_workingAOTerm;
|
nvrhi::ITexture* ping = m_workingAOTerm;
|
||||||
nvrhi::ITexture* pong = m_workingAOTermPong;
|
nvrhi::ITexture* pong = m_workingAOTermPong;
|
||||||
for (int i = 0; i < num_passes; ++i) {
|
for (int i = 0; i < num_passes; ++i) {
|
||||||
@@ -260,3 +277,22 @@ void NvSsao::Render(nvrhi::ICommandList* command_list,
|
|||||||
}
|
}
|
||||||
command_list->endMarker();
|
command_list->endMarker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NvSsao::OnGui(bool const open_now) {
|
||||||
|
static bool open = false;
|
||||||
|
open |= open_now;
|
||||||
|
if(open && ImGui::Begin("GTAO Settings", &open)) {
|
||||||
|
ImGui::InputInt("Quality level", &settings.QualityLevel);
|
||||||
|
ImGui::InputInt("Denoise passes", &settings.DenoisePasses);
|
||||||
|
ImGui::InputFloat("Radius", &settings.Radius);
|
||||||
|
if(ImGui::CollapsingHeader("Advanced")) {
|
||||||
|
ImGui::InputFloat("Radius multiplier", &settings.RadiusMultiplier);
|
||||||
|
ImGui::InputFloat("Falloff range", &settings.FalloffRange);
|
||||||
|
ImGui::InputFloat("Sample distribution power", &settings.SampleDistributionPower);
|
||||||
|
ImGui::InputFloat("Thin occluder compensation", &settings.ThinOccluderCompensation);
|
||||||
|
ImGui::InputFloat("Final value power", &settings.FinalValuePower);
|
||||||
|
ImGui::InputFloat("Depth MIP sampling offset", &settings.DepthMIPSamplingOffset);
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <nvrhi/nvrhi.h>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <nvrhi/nvrhi.h>
|
#include "XeGTAO.h"
|
||||||
|
|
||||||
struct NvSsao {
|
struct NvSsao {
|
||||||
NvSsao(class NvRenderer* renderer);
|
NvSsao(class NvRenderer* renderer);
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
XeGTAO::GTAOSettings settings{};
|
||||||
|
|
||||||
class NvRendererBackend* m_backend;
|
class NvRendererBackend* m_backend;
|
||||||
struct NvGbuffer* m_gbuffer;
|
struct NvGbuffer* m_gbuffer;
|
||||||
|
|
||||||
@@ -52,4 +55,6 @@ struct NvSsao {
|
|||||||
|
|
||||||
void Render(nvrhi::ICommandList* command_list, const glm::mat4& projection,
|
void Render(nvrhi::ICommandList* command_list, const glm::mat4& projection,
|
||||||
size_t frame_index);
|
size_t frame_index);
|
||||||
|
|
||||||
|
void OnGui(bool open_now);
|
||||||
};
|
};
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "nvrenderer/nvrenderer.h"
|
#include "nvrenderer/nvrenderer.h"
|
||||||
#include "nvrendererbackend.h"
|
#include "nvrendererbackend.h"
|
||||||
|
|
||||||
|
#include <Timer.h>
|
||||||
#include <AnimModel.h>
|
#include <AnimModel.h>
|
||||||
#include <simulation.h>
|
#include <simulation.h>
|
||||||
|
|
||||||
@@ -1057,6 +1058,7 @@ void NvRenderer::Render(const Renderable& renderable, const RenderPass& pass,
|
|||||||
|
|
||||||
void NvRenderer::Animate(const glm::dvec3& origin, double radius,
|
void NvRenderer::Animate(const glm::dvec3& origin, double radius,
|
||||||
uint64_t frame) {
|
uint64_t frame) {
|
||||||
|
Timer::subsystem.gfx_animate.start();
|
||||||
{
|
{
|
||||||
auto motion_scope = m_motion_cache->SetInstance(nullptr);
|
auto motion_scope = m_motion_cache->SetInstance(nullptr);
|
||||||
auto& motion_cache = m_motion_cache->Get(nullptr);
|
auto& motion_cache = m_motion_cache->Get(nullptr);
|
||||||
@@ -1095,6 +1097,7 @@ void NvRenderer::Animate(const glm::dvec3& origin, double radius,
|
|||||||
if (!instance.m_animatable && instance.m_was_once_animated) return;
|
if (!instance.m_animatable && instance.m_was_once_animated) return;
|
||||||
Animate(instance, origin, frame);
|
Animate(instance, origin, frame);
|
||||||
});
|
});
|
||||||
|
Timer::subsystem.gfx_animate.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NvRenderer::GatherSpotLights(const RenderPass& pass) {
|
void NvRenderer::GatherSpotLights(const RenderPass& pass) {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ SamplerState g_samplerPointClamp : register( s0 );
|
|||||||
// Engine-specific normal map loader
|
// Engine-specific normal map loader
|
||||||
lpfloat3 LoadNormal( int2 pos )
|
lpfloat3 LoadNormal( int2 pos )
|
||||||
{
|
{
|
||||||
|
return (float3)0.;
|
||||||
#if 0
|
#if 0
|
||||||
// special decoding for external normals stored in 11_11_10 unorm - modify appropriately to support your own encoding
|
// special decoding for external normals stored in 11_11_10 unorm - modify appropriately to support your own encoding
|
||||||
uint packedInput = g_srcNormalmap.Load( int3(pos, 0) ).x;
|
uint packedInput = g_srcNormalmap.Load( int3(pos, 0) ).x;
|
||||||
|
|||||||
@@ -111,11 +111,10 @@ float3 XeGTAO_ComputeViewspacePosition( const float2 screenPos, const float view
|
|||||||
|
|
||||||
float XeGTAO_ScreenSpaceToViewSpaceDepth( const float screenDepth, const GTAOConstants consts )
|
float XeGTAO_ScreenSpaceToViewSpaceDepth( const float screenDepth, const GTAOConstants consts )
|
||||||
{
|
{
|
||||||
float depthLinearizeMul = consts.DepthUnpackConsts.x;
|
float depthLinearizeMul = consts.DepthUnpackConsts.x;
|
||||||
float depthLinearizeAdd = consts.DepthUnpackConsts.y;
|
float depthLinearizeAdd = consts.DepthUnpackConsts.y;
|
||||||
// Optimised version of "-cameraClipNear / (cameraClipFar - projDepth * (cameraClipFar - cameraClipNear)) * cameraClipFar"
|
// Optimised version of "-cameraClipNear / (cameraClipFar - projDepth * (cameraClipFar - cameraClipNear)) * cameraClipFar"
|
||||||
//return 2500. / (.1 - screenDepth * (.1 - 2500.)) * .1;
|
return depthLinearizeMul / (depthLinearizeAdd - screenDepth);
|
||||||
return depthLinearizeMul / (depthLinearizeAdd - screenDepth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lpfloat4 XeGTAO_CalculateEdges( const lpfloat centerZ, const lpfloat leftZ, const lpfloat rightZ, const lpfloat topZ, const lpfloat bottomZ )
|
lpfloat4 XeGTAO_CalculateEdges( const lpfloat centerZ, const lpfloat leftZ, const lpfloat rightZ, const lpfloat topZ, const lpfloat bottomZ )
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
templates:
|
templates:
|
||||||
# Partially pre-filled containers to avoid excessive copypasta
|
# Partially pre-filled containers to avoid excessive copypasta
|
||||||
XeGTAO:
|
XeGTAO:
|
||||||
# TODO Depth conversion is broken since converting to reversed depth buffer
|
|
||||||
# after attempting to fix it, it is still broken but with hardcoded values
|
|
||||||
source: XeGTAO/GTAO
|
source: XeGTAO/GTAO
|
||||||
target: compute
|
target: compute
|
||||||
definitions: # TODO (mostly) move to shader file I guess
|
definitions: # TODO (mostly) move to shader file I guess
|
||||||
@@ -14,6 +12,7 @@ templates:
|
|||||||
XE_GTAO_USE_HALF_FLOAT_PRECISION: 0
|
XE_GTAO_USE_HALF_FLOAT_PRECISION: 0
|
||||||
VA_COMPILED_AS_SHADER_CODE: 1
|
VA_COMPILED_AS_SHADER_CODE: 1
|
||||||
VA_SATURATE: saturate
|
VA_SATURATE: saturate
|
||||||
|
XE_GTAO_GENERATE_NORMALS_INPLACE: 1
|
||||||
envmap:
|
envmap:
|
||||||
source: envmap
|
source: envmap
|
||||||
target: compute
|
target: compute
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ void perfgraph_panel::render_contents() {
|
|||||||
stopwatch = &Timer::subsystem.gfx_swap;
|
stopwatch = &Timer::subsystem.gfx_swap;
|
||||||
else if (current_timer == gfx_gui)
|
else if (current_timer == gfx_gui)
|
||||||
stopwatch = &Timer::subsystem.gfx_gui;
|
stopwatch = &Timer::subsystem.gfx_gui;
|
||||||
|
else if (current_timer == gfx_animate)
|
||||||
|
stopwatch = &Timer::subsystem.gfx_animate;
|
||||||
else if (current_timer == sim_total)
|
else if (current_timer == sim_total)
|
||||||
stopwatch = &Timer::subsystem.sim_total;
|
stopwatch = &Timer::subsystem.sim_total;
|
||||||
else if (current_timer == sim_dynamics)
|
else if (current_timer == sim_dynamics)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class perfgraph_panel : public ui_panel
|
|||||||
gfx_reflections,
|
gfx_reflections,
|
||||||
gfx_swap,
|
gfx_swap,
|
||||||
gfx_gui,
|
gfx_gui,
|
||||||
|
gfx_animate,
|
||||||
sim_total,
|
sim_total,
|
||||||
sim_dynamics,
|
sim_dynamics,
|
||||||
sim_events,
|
sim_events,
|
||||||
@@ -31,6 +32,7 @@ class perfgraph_panel : public ui_panel
|
|||||||
"gfx_reflections",
|
"gfx_reflections",
|
||||||
"gfx_swap",
|
"gfx_swap",
|
||||||
"gfx_gui",
|
"gfx_gui",
|
||||||
|
"gfx_animate",
|
||||||
"sim_total",
|
"sim_total",
|
||||||
"sim_dynamics",
|
"sim_dynamics",
|
||||||
"sim_events",
|
"sim_events",
|
||||||
|
|||||||
Reference in New Issue
Block a user