Kaynağa Gözat

VRS bug fixes

Panagiotis Christopoulos Charitos 4 yıl önce
ebeveyn
işleme
7e450866d2

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

@@ -830,7 +830,7 @@ void CommandBufferImpl::rebindDynamicState()
 		const VkExtent2D extend = convertVrsShadingRate(m_vrsRate);
 		Array<VkFragmentShadingRateCombinerOpKHR, 2> combiner;
 		combiner[0] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR; // Keep pipeline rating over primitive
-		combiner[1] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR; // Keep pipeline rating over attachment
+		combiner[1] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_KHR; // Max of attachment and pipeline rates
 		vkCmdSetFragmentShadingRateKHR(m_handle, &extend, &combiner[0]);
 	}
 }

+ 1 - 1
AnKi/Gr/Vulkan/CommandBufferImpl.inl.h

@@ -962,7 +962,7 @@ inline void CommandBufferImpl::setVrsRateInternal(VrsRate rate)
 		const VkExtent2D extend = convertVrsShadingRate(rate);
 		Array<VkFragmentShadingRateCombinerOpKHR, 2> combiner;
 		combiner[0] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR; // Keep pipeline rating over primitive
-		combiner[1] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR; // Keep pipeline rating over attachment
+		combiner[1] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_KHR; // Max of attachment and pipeline rates
 		vkCmdSetFragmentShadingRateKHR(m_handle, &extend, &combiner[0]);
 
 		m_vrsRate = rate;

+ 8 - 2
AnKi/Renderer/Bloom.cpp

@@ -48,7 +48,10 @@ Error Bloom::initExposure()
 												 m_exposure.m_prog));
 
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_exposure.m_prog);
-	variantInitInfo.addConstant("FB_SIZE", UVec2(m_exposure.m_width, m_exposure.m_height));
+	if(getConfig().getRPreferCompute())
+	{
+		variantInitInfo.addConstant("FB_SIZE", UVec2(m_exposure.m_width, m_exposure.m_height));
+	}
 
 	const ShaderProgramResourceVariant* variant;
 	m_exposure.m_prog->getOrCreateVariant(variantInitInfo, variant);
@@ -74,8 +77,11 @@ Error Bloom::initUpscale()
 												 m_upscale.m_prog));
 
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_upscale.m_prog);
-	variantInitInfo.addConstant("FB_SIZE", UVec2(m_upscale.m_width, m_upscale.m_height));
 	variantInitInfo.addConstant("INPUT_TEX_SIZE", UVec2(m_exposure.m_width, m_exposure.m_height));
+	if(getConfig().getRPreferCompute())
+	{
+		variantInitInfo.addConstant("FB_SIZE", UVec2(m_upscale.m_width, m_upscale.m_height));
+	}
 
 	const ShaderProgramResourceVariant* variant;
 	m_upscale.m_prog->getOrCreateVariant(variantInitInfo, variant);

+ 7 - 0
AnKi/Renderer/GBuffer.cpp

@@ -112,6 +112,13 @@ void GBuffer::runInThread(const RenderingContext& ctx, RenderPassWorkContext& rg
 
 	cmdb->setRasterizationOrder(RasterizationOrder::RELAXED);
 
+	const Bool enableVrs = getGrManager().getDeviceCapabilities().m_vrs && getConfig().getRVrs();
+	if(enableVrs)
+	{
+		// Just set some low value, the attachment will take over
+		cmdb->setVrsRate(VrsRate::_1x1);
+	}
+
 	// First do early Z (if needed)
 	if(earlyZStart < earlyZEnd)
 	{

+ 5 - 1
AnKi/Renderer/MotionVectors.cpp

@@ -35,7 +35,11 @@ Error MotionVectors::initInternal()
 													 : "Shaders/MotionVectorsRaster.ankiprog",
 												 m_prog));
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
-	variantInitInfo.addConstant("FB_SIZE", UVec2(m_r->getInternalResolution().x(), m_r->getInternalResolution().y()));
+	if(getConfig().getRPreferCompute())
+	{
+		variantInitInfo.addConstant("FB_SIZE",
+									UVec2(m_r->getInternalResolution().x(), m_r->getInternalResolution().y()));
+	}
 	const ShaderProgramResourceVariant* variant;
 	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_grProg = variant->getProgram();

+ 12 - 8
AnKi/Shaders/VrsSriGeneration.glsl

@@ -19,17 +19,18 @@ layout(set = 0, binding = 1) uniform writeonly uimage2D u_sriImg;
 layout(location = 0) out U32 out_shadingRate;
 #endif
 
-shared Vec2 s_lumas[WORKGROUP_SIZE.y * WORKGROUP_SIZE.x];
+shared F32 s_lumaMin[WORKGROUP_SIZE.y * WORKGROUP_SIZE.x];
+shared F32 s_lumaMax[WORKGROUP_SIZE.y * WORKGROUP_SIZE.x];
 
 void main()
 {
 	// Get luminance
 	const Vec3 color = invertibleTonemap(texelFetch(u_inputTex, IVec2(gl_GlobalInvocationID.xy), 0).xyz);
 	const F32 luma = computeLuminance(color);
-	const F32 lumaSquared = luma * luma;
 
 	// Store luminance
-	s_lumas[gl_LocalInvocationIndex] = Vec2(luma, lumaSquared);
+	s_lumaMin[gl_LocalInvocationIndex] = luma;
+	s_lumaMax[gl_LocalInvocationIndex] = luma;
 	memoryBarrierShared();
 	barrier();
 
@@ -38,7 +39,10 @@ void main()
 	{
 		if(gl_LocalInvocationIndex < s)
 		{
-			s_lumas[gl_LocalInvocationIndex] += s_lumas[gl_LocalInvocationIndex + s];
+			s_lumaMin[gl_LocalInvocationIndex] =
+				min(s_lumaMin[gl_LocalInvocationIndex], s_lumaMin[gl_LocalInvocationIndex + s]);
+			s_lumaMax[gl_LocalInvocationIndex] =
+				max(s_lumaMax[gl_LocalInvocationIndex], s_lumaMax[gl_LocalInvocationIndex + s]);
 		}
 
 		memoryBarrierShared();
@@ -48,11 +52,11 @@ void main()
 	// Write the result
 	ANKI_BRANCH if(gl_LocalInvocationIndex == 0u)
 	{
-		const F32 variance = abs(s_lumas[0].y - s_lumas[0].x * s_lumas[0].x);
-		const F32 maxVariance = 100.0;
+		const F32 diff = s_lumaMax[0] - s_lumaMin[0];
+		const F32 maxLumaDiff = 1.0 / 32.0;
 
-		const F32 factor = 1.0 - min(1.0, variance / maxVariance);
-		const U32 rate = 1u << U32(factor * 2.0);
+		const F32 factor = min(1.0, diff / maxLumaDiff);
+		const U32 rate = 1u << (2u - U32(factor * 2.0));
 
 		const UVec2 inputTexelCoord = gl_WorkGroupID.xy;
 		imageStore(u_sriImg, IVec2(inputTexelCoord), UVec4(encodeVrsRate(UVec2(rate))));

+ 3 - 4
Samples/Common/Framework.cpp → Samples/Common/SampleApp.cpp

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include <Samples/Common/Framework.h>
+#include <Samples/Common/SampleApp.h>
 
 using namespace anki;
 
@@ -68,7 +68,7 @@ Error SampleApp::userMainLoop(Bool& quit, Second elapsedTime)
 	if(in.getKey(KeyCode::Y) == 1)
 	{
 		renderer.setCurrentDebugRenderTarget(
-			(renderer.getCurrentDebugRenderTarget() == "GBuffer_velocity") ? "" : "GBuffer_velocity");
+			(renderer.getCurrentDebugRenderTarget() == "GBuffer_albedo") ? "" : "GBuffer_albedo");
 	}
 
 	if(in.getKey(KeyCode::U) == 1)
@@ -124,8 +124,7 @@ Error SampleApp::userMainLoop(Bool& quit, Second elapsedTime)
 
 	if(in.getKey(KeyCode::J) == 1)
 	{
-		renderer.setCurrentDebugRenderTarget(
-			(renderer.getCurrentDebugRenderTarget() == "MotionVectorsRejection") ? "" : "MotionVectorsRejection");
+		m_config.setRVrs(!m_config.getRVrs());
 	}
 
 	if(!getDisplayDeveloperConsole())

+ 0 - 0
Samples/Common/Framework.h → Samples/Common/SampleApp.h


+ 1 - 1
Samples/PhysicsPlayground/CMakeLists.txt

@@ -1,2 +1,2 @@
-anki_new_executable(PhysicsPlayground Main.cpp ../Common/Framework.cpp)
+anki_new_executable(PhysicsPlayground Main.cpp ../Common/SampleApp.cpp)
 target_link_libraries(PhysicsPlayground AnKi)

+ 1 - 1
Samples/PhysicsPlayground/Main.cpp

@@ -4,7 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include <cstdio>
-#include <Samples/Common/Framework.h>
+#include <Samples/Common/SampleApp.h>
 
 using namespace anki;
 

+ 1 - 1
Samples/SimpleScene/CMakeLists.txt

@@ -1,2 +1,2 @@
-anki_new_executable(SimpleScene Main.cpp ../Common/Framework.cpp)
+anki_new_executable(SimpleScene Main.cpp ../Common/SampleApp.cpp)
 target_link_libraries(SimpleScene AnKi)

+ 1 - 1
Samples/SimpleScene/Main.cpp

@@ -4,7 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include <cstdio>
-#include <Samples/Common/Framework.h>
+#include <Samples/Common/SampleApp.h>
 
 using namespace anki;
 

+ 1 - 1
Samples/SkeletalAnimation/CMakeLists.txt

@@ -1,2 +1,2 @@
-anki_new_executable(SkeletalAnimation Main.cpp ../Common/Framework.cpp)
+anki_new_executable(SkeletalAnimation Main.cpp ../Common/SampleApp.cpp)
 target_link_libraries(SkeletalAnimation AnKi)

+ 1 - 1
Samples/SkeletalAnimation/Main.cpp

@@ -4,7 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include <cstdio>
-#include <Samples/Common/Framework.h>
+#include <Samples/Common/SampleApp.h>
 
 using namespace anki;
 

+ 1 - 1
Samples/Sponza/CMakeLists.txt

@@ -1,2 +1,2 @@
-anki_new_executable(Sponza Main.cpp ../Common/Framework.cpp)
+anki_new_executable(Sponza Main.cpp ../Common/SampleApp.cpp)
 target_link_libraries(Sponza AnKi)

+ 1 - 1
Samples/Sponza/Main.cpp

@@ -4,7 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include <cstdio>
-#include <Samples/Common/Framework.h>
+#include <Samples/Common/SampleApp.h>
 
 using namespace anki;