Bladeren bron

Fix DLSS bugs

Panagiotis Christopoulos Charitos 3 jaren geleden
bovenliggende
commit
c631a0b6f1

+ 3 - 3
AnKi/Gr/CMakeLists.txt

@@ -141,15 +141,15 @@ target_link_libraries(AnKiGr AnKiCore AnKiSpirvCross AnKiGrCommon ${extra_libs})
 
 # Copy DLSS files to Bin
 if(ANKI_DLSS)
-	get_target_property(lib_type AnkiNgx TYPE)
+	get_target_property(lib_type AnKiNgx TYPE)
 	if("${lib_type}" STREQUAL "SHARED_LIBRARY")
-		get_target_property(ANKINGX_DLL AnkiNgx IMPORTED_LOCATION)
+		get_target_property(ANKINGX_DLL AnKiNgx IMPORTED_LOCATION)
 		add_custom_command(
 			TARGET AnKiGr
 			COMMENT "Dependant DLLs copy ${ANKINGX_DLL} ${CMAKE_BINARY_DIR}/Bin"
 			COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ANKINGX_DLL}" "${CMAKE_BINARY_DIR}/Bin")
 	else()
-		get_property(__NGX_DLLS_LIST TARGET AnkiNgx PROPERTY ANKINGX_EXTRA_DLLS)
+		get_property(__NGX_DLLS_LIST TARGET AnKiNgx PROPERTY ANKINGX_EXTRA_DLLS)
 		foreach(dll_path ${__NGX_DLLS_LIST})
 			file(GLOB dll_files "${dll_path}")
 			foreach(dll_file ${dll_files})

+ 4 - 1
AnKi/Gr/Enums.h

@@ -242,7 +242,10 @@ enum class TextureUsageBit : U32
 	ALL_WRITE = IMAGE_GEOMETRY_WRITE | IMAGE_FRAGMENT_WRITE | IMAGE_COMPUTE_WRITE | IMAGE_TRACE_RAYS_WRITE
 				| FRAMEBUFFER_ATTACHMENT_WRITE | TRANSFER_DESTINATION | GENERATE_MIPMAPS,
 
-	GR_UPSCALING = ALL_IMAGE
+	/// Make GR upscaling usage equal to ALL_IMAGE to force GENERAL layout because who knows.
+	ALL_GR_UPSCALING = ALL_IMAGE,
+	ALL_GR_UPSCALING_READ = ALL_GR_UPSCALING & ALL_READ,
+	ALL_GR_UPSCALING_WRITE = ALL_GR_UPSCALING & ALL_WRITE,
 };
 ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(TextureUsageBit)
 

+ 0 - 1
AnKi/Gr/Vulkan/CommandBufferImpl.cpp

@@ -800,7 +800,6 @@ static NVSDK_NGX_Resource_VK getNGXResourceFromAnkiTexture(const TextureViewImpl
 {
 	const TextureImpl& tex = view.getTextureImpl();
 
-	NVSDK_NGX_Resource_VK resourceVK = {};
 	const VkImageView imageView = view.getHandle();
 	const VkFormat format = tex.m_vkFormat;
 	const VkImage image = tex.m_imageHandle;

+ 4 - 3
AnKi/Gr/Vulkan/GrUpscalerImpl.cpp

@@ -6,6 +6,7 @@
 #include <AnKi/Gr/Vulkan/GrUpscalerImpl.h>
 #include <AnKi/Gr/Vulkan/GrManagerImpl.h>
 #include <AnKi/Gr/CommandBuffer.h>
+#include <AnKi/Gr/Fence.h>
 #include <AnKi/Gr/Vulkan/CommandBufferImpl.h>
 
 // Ngx specific
@@ -67,8 +68,6 @@ static NVSDK_NGX_PerfQuality_Value getDlssQualityModeToNVQualityMode(GrUpscalerQ
 
 Error GrUpscalerImpl::initDlss(const GrUpscalerInitInfo& initInfo)
 {
-	NVSDK_NGX_Result result = NVSDK_NGX_Result_Fail;
-
 	const VkDevice vkdevice = getGrManagerImpl().getDevice();
 	const VkPhysicalDevice vkphysicaldevice = getGrManagerImpl().getPhysicalDevice();
 	const VkInstance vkinstance = getGrManagerImpl().getInstance();
@@ -146,7 +145,9 @@ Error GrUpscalerImpl::createDlssFeature(const UVec2& srcRes, const UVec2& dstRes
 	const U32 visibilityNodeMask = 1;
 	ANKI_NGX_CHECK(NGX_VULKAN_CREATE_DLSS_EXT(cmdbImpl.getHandle(), creationNodeMask, visibilityNodeMask,
 											  &m_dlssFeature, m_ngxParameters, &dlssCreateParams));
-	cmdb->flush();
+	FencePtr fence;
+	cmdb->flush({}, &fence);
+	fence->clientWait(60.0_sec);
 
 	return Error::NONE;
 }

+ 1 - 1
AnKi/Renderer/ConfigVars.defs.h

@@ -89,5 +89,5 @@ ANKI_CONFIG_VAR_U8(RRtShadowsSvgfAtrousPassCount, 3, 1, 20, "Number of atrous pa
 ANKI_CONFIG_VAR_U32(RRtShadowsRaysPerPixel, 1, 1, 8, "Number of shadow rays per pixel")
 
 ANKI_CONFIG_VAR_U8(RFsr, 1, 0, 2, "0: Use bilinear, 1: FSR low quality, 2: FSR high quality")
-ANKI_CONFIG_VAR_U8(RDlss, 0, 0, 3, "0: Disabled, 1: Performance, 2: Balanced, 3: Quality")
+ANKI_CONFIG_VAR_U8(RDlss, 2, 0, 3, "0: Disabled, 1: Performance, 2: Balanced, 3: Quality")
 ANKI_CONFIG_VAR_BOOL(RSharpen, true, "Sharpen the image")

+ 5 - 3
AnKi/Renderer/GBuffer.cpp

@@ -7,6 +7,7 @@
 #include <AnKi/Renderer/Renderer.h>
 #include <AnKi/Renderer/RenderQueue.h>
 #include <AnKi/Renderer/VrsSriGeneration.h>
+#include <AnKi/Renderer/Scale.h>
 #include <AnKi/Util/Logger.h>
 #include <AnKi/Util/Tracer.h>
 #include <AnKi/Core/ConfigSet.h>
@@ -37,9 +38,10 @@ Error GBuffer::initInternal()
 	static const Array<const char*, 2> depthRtNames = {{"GBuffer depth #0", "GBuffer depth #1"}};
 	for(U32 i = 0; i < 2; ++i)
 	{
-		TextureInitInfo texinit = m_r->create2DRenderTargetInitInfo(
-			m_r->getInternalResolution().x(), m_r->getInternalResolution().y(), m_r->getDepthNoStencilFormat(),
-			TextureUsageBit::ALL_SAMPLED | TextureUsageBit::ALL_FRAMEBUFFER_ATTACHMENT, depthRtNames[i]);
+		const TextureUsageBit usage = TextureUsageBit::ALL_SAMPLED | TextureUsageBit::ALL_FRAMEBUFFER_ATTACHMENT;
+		TextureInitInfo texinit =
+			m_r->create2DRenderTargetInitInfo(m_r->getInternalResolution().x(), m_r->getInternalResolution().y(),
+											  m_r->getDepthNoStencilFormat(), usage, depthRtNames[i]);
 
 		m_depthRts[i] = m_r->createAndClearRenderTarget(texinit, TextureUsageBit::SAMPLED_FRAGMENT);
 	}

+ 3 - 3
AnKi/Renderer/Renderer.cpp

@@ -152,6 +152,9 @@ Error Renderer::initInternal(UVec2 swapchainResolution)
 	m_vrsSriGeneration.reset(m_alloc.newInstance<VrsSriGeneration>(this));
 	ANKI_CHECK(m_vrsSriGeneration->init());
 
+	m_scale.reset(m_alloc.newInstance<Scale>(this));
+	ANKI_CHECK(m_scale->init());
+
 	m_gbuffer.reset(m_alloc.newInstance<GBuffer>(this));
 	ANKI_CHECK(m_gbuffer->init());
 
@@ -200,9 +203,6 @@ Error Renderer::initInternal(UVec2 swapchainResolution)
 	m_uiStage.reset(m_alloc.newInstance<UiStage>(this));
 	ANKI_CHECK(m_uiStage->init());
 
-	m_scale.reset(m_alloc.newInstance<Scale>(this));
-	ANKI_CHECK(m_scale->init());
-
 	m_indirectDiffuse.reset(m_alloc.newInstance<IndirectDiffuse>(this));
 	ANKI_CHECK(m_indirectDiffuse->init());
 

+ 10 - 7
AnKi/Renderer/Scale.cpp

@@ -125,7 +125,7 @@ Error Scale::init()
 	}
 
 	// Sharpen programs
-	if(needsSharpening)
+	if(m_sharpenMethod == SharpenMethod::RCAS)
 	{
 		ANKI_CHECK(getResourceManager().loadResource((preferCompute) ? "ShaderBinaries/FsrCompute.ankiprogbin"
 																	 : "ShaderBinaries/FsrRaster.ankiprogbin",
@@ -181,13 +181,16 @@ void Scale::populateRenderGraph(RenderingContext& ctx)
 		m_runCtx.m_scaledRt = rgraph.newRenderTarget(m_rtDesc);
 
 		ComputeRenderPassDescription& pass = ctx.m_renderGraphDescr.newComputeRenderPass("DLSS");
-		pass.newDependency(RenderPassDependency(m_r->getLightShading().getRt(), TextureUsageBit::ALL_READ));
-		pass.newDependency(
-			RenderPassDependency(m_r->getMotionVectors().getMotionVectorsRt(), TextureUsageBit::ALL_READ));
-		pass.newDependency(RenderPassDependency(m_r->getTonemapping().getRt(), TextureUsageBit::ALL_READ));
-		pass.newDependency(RenderPassDependency(m_r->getGBuffer().getDepthRt(), TextureUsageBit::ALL_READ,
+
+		// TODO: No idea about the usage flags
+		const TextureUsageBit readUsage = TextureUsageBit::ALL_SAMPLED & TextureUsageBit::ALL_COMPUTE;
+		const TextureUsageBit writeUsage = TextureUsageBit::ALL_IMAGE & TextureUsageBit::ALL_COMPUTE;
+
+		pass.newDependency(RenderPassDependency(m_r->getLightShading().getRt(), readUsage));
+		pass.newDependency(RenderPassDependency(m_r->getMotionVectors().getMotionVectorsRt(), readUsage));
+		pass.newDependency(RenderPassDependency(m_r->getGBuffer().getDepthRt(), readUsage,
 												TextureSubresourceInfo(DepthStencilAspectBit::DEPTH)));
-		pass.newDependency(RenderPassDependency(m_runCtx.m_scaledRt, TextureUsageBit::ALL_WRITE));
+		pass.newDependency(RenderPassDependency(m_runCtx.m_scaledRt, writeUsage));
 
 		pass.setWork([this, &ctx](RenderPassWorkContext& rgraphCtx) {
 			runGrUpscaling(ctx, rgraphCtx);

+ 2 - 1
AnKi/Renderer/Tonemapping.h

@@ -39,7 +39,8 @@ private:
 	ShaderProgramPtr m_grProg;
 	U32 m_inputTexMip;
 
-	/// This is a 1x1 2 component texture where R is the exposure and G the average luminance
+	/// This is a 1x1 2 component texture where R is the exposure and G the average luminance. It's not tracked in
+	/// rendergraph depedencies. We don't care to track it because it affects the eye adaptation.
 	TexturePtr m_exposureAndAvgLuminance1x1;
 
 	class

+ 1 - 1
CMakeLists.txt

@@ -415,7 +415,7 @@ if(LINUX)
 endif()
 
 if(ANKI_DLSS)
-	set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} AnkiNgx)
+	set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} AnKiNgx)
 endif()
 
 # AnKi compiler flags (Mainly warnings)

+ 13 - 13
ThirdParty/DlssSdk/CMakeLists.txt

@@ -1,28 +1,28 @@
-# Create AnkiNgx. Inspired by the DLSS example
+# Create AnKiNgx. Inspired by the DLSS example
 if(ANKI_DLSS)
 	set(NGX_SDK_ROOT "${CMAKE_CURRENT_LIST_DIR}/sdk")
 	# Only Linux and Windows support working with Nvidia SDK (NGX)
 	if(WINDOWS)
-		add_library(AnkiNgx IMPORTED SHARED GLOBAL)
-		set_property(TARGET AnkiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
-		set_property(TARGET AnkiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
-		set_target_properties(AnkiNgx PROPERTIES IMPORTED_IMPLIB_DEBUG ${NGX_SDK_ROOT}/lib/Windows_x86_64/x86_64/nvsdk_ngx_d_dbg.lib)
-		set_target_properties(AnkiNgx PROPERTIES IMPORTED_IMPLIB_RELEASE ${NGX_SDK_ROOT}/lib/Windows_x86_64/x86_64/nvsdk_ngx_d.lib)
-		set_target_properties(AnkiNgx PROPERTIES
+		add_library(AnKiNgx IMPORTED SHARED GLOBAL)
+		set_property(TARGET AnKiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+		set_property(TARGET AnKiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+		set_target_properties(AnKiNgx PROPERTIES IMPORTED_IMPLIB_DEBUG ${NGX_SDK_ROOT}/lib/Windows_x86_64/x86_64/nvsdk_ngx_d_dbg.lib)
+		set_target_properties(AnKiNgx PROPERTIES IMPORTED_IMPLIB_RELEASE ${NGX_SDK_ROOT}/lib/Windows_x86_64/x86_64/nvsdk_ngx_d.lib)
+		set_target_properties(AnKiNgx PROPERTIES
 			MAP_IMPORTED_CONFIG_MINSIZEREL Release
 			MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
 		)
-		set_target_properties(AnkiNgx PROPERTIES IMPORTED_LOCATION "${NGX_SDK_ROOT}/lib/Windows_x86_64/rel/nvngx_dlss.dll")
+		set_target_properties(AnKiNgx PROPERTIES IMPORTED_LOCATION "${NGX_SDK_ROOT}/lib/Windows_x86_64/rel/nvngx_dlss.dll")
 	elseif(LINUX)
-		add_library(AnkiNgx IMPORTED STATIC GLOBAL)
-		set_property(TARGET AnkiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
-		set_property(TARGET AnkiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
-		set_property(TARGET AnkiNgx PROPERTY IMPORTED_LOCATION ${NGX_SDK_ROOT}/lib/Linux_x86_64/libnvsdk_ngx.a)
+		add_library(AnKiNgx IMPORTED STATIC GLOBAL)
+		set_property(TARGET AnKiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+		set_property(TARGET AnKiNgx APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+		set_property(TARGET AnKiNgx PROPERTY IMPORTED_LOCATION ${NGX_SDK_ROOT}/lib/Linux_x86_64/libnvsdk_ngx.a)
 		# set the list of DLLs that need copying to target folder of application
 		set(__NGX_DLLS_LIST "${NGX_SDK_ROOT}/lib/Linux_x86_64/rel/libnvidia-ngx-*.so.*")
 	else()
 		message(FATAL_ERROR "Trying to use NGX for invalid platform")
 	endif()
 
-	set_property(TARGET AnkiNgx APPEND PROPERTY ANKINGX_EXTRA_DLLS "${__NGX_DLLS_LIST}")
+	set_property(TARGET AnKiNgx APPEND PROPERTY ANKINGX_EXTRA_DLLS "${__NGX_DLLS_LIST}")
 endif()

+ 2 - 2
ThirdParty/DlssSdk/sdk/include/nvsdk_ngx_helpers_vk.h

@@ -28,7 +28,7 @@
 
 static inline NVSDK_NGX_Resource_VK NVSDK_NGX_Create_ImageView_Resource_VK(VkImageView imageView, VkImage image, VkImageSubresourceRange subresourceRange, VkFormat format, unsigned int width, unsigned int height, bool readWrite)
 {
-    NVSDK_NGX_Resource_VK resourceVK = {0};
+    NVSDK_NGX_Resource_VK resourceVK = {};
     resourceVK.Type = NVSDK_NGX_RESOURCE_VK_TYPE_VK_IMAGEVIEW;
     resourceVK.Resource.ImageViewInfo.ImageView = imageView;
     resourceVK.Resource.ImageViewInfo.Image = image;
@@ -42,7 +42,7 @@ static inline NVSDK_NGX_Resource_VK NVSDK_NGX_Create_ImageView_Resource_VK(VkIma
 
 static inline NVSDK_NGX_Resource_VK NVSDK_NGX_Create_Buffer_Resource_VK(VkBuffer buffer, unsigned int sizeInBytes, bool readWrite)
 {
-    NVSDK_NGX_Resource_VK resourceVK = {0};
+    NVSDK_NGX_Resource_VK resourceVK = {};
     resourceVK.Type = NVSDK_NGX_RESOURCE_VK_TYPE_VK_BUFFER;
     resourceVK.Resource.BufferInfo.Buffer = buffer;
     resourceVK.Resource.BufferInfo.SizeInBytes = sizeInBytes;