Browse Source

Moving Blit shader to HLSL

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
8bc2972db5

+ 4 - 1
.clang-format

@@ -1,6 +1,6 @@
 ---
 Language:        Cpp
-# BasedOnStyle:  LLVM
+BasedOnStyle:  LLVM
 AccessModifierOffset: -4
 AlignAfterOpenBracket: Align
 AlignConsecutiveMacros: None
@@ -162,5 +162,8 @@ WhitespaceSensitiveMacros:
   - BOOST_PP_STRINGIZE
   - NS_SWIFT_NAME
   - CF_SWIFT_NAME
+---
+Language: ObjC
+BasedOnStyle: Mozilla
 ...
 

+ 1 - 1
AnKi/Renderer/Scale.cpp

@@ -77,7 +77,7 @@ Error Scale::init()
 	static constexpr Array<const Char*, U32(SharpenMethod::kCount)> sharpenMethodNames = {"none", "RCAS"};
 
 	ANKI_R_LOGV("Initializing upscaling. Upscaling method %s, sharpenning method %s",
-				upscalingMethodNames[U32(m_upscalingMethod)], sharpenMethodNames[U32(m_sharpenMethod)]);
+				upscalingMethodNames[m_upscalingMethod], sharpenMethodNames[m_sharpenMethod]);
 
 	// Scale programs
 	if(m_upscalingMethod == UpscalingMethod::kBilinear)

+ 0 - 52
AnKi/Shaders/Blit.glsl

@@ -1,52 +0,0 @@
-// Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#include <AnKi/Shaders/Functions.glsl>
-
-layout(set = 0, binding = 0) uniform sampler u_linearAnyClampSampler;
-layout(set = 0, binding = 1) uniform texture2D u_tex;
-
-#if defined(ANKI_COMPUTE_SHADER)
-#	define USE_COMPUTE 1
-#else
-#	define USE_COMPUTE 0
-#endif
-
-#if USE_COMPUTE
-layout(set = 0, binding = 2) uniform writeonly image2D u_outImage;
-
-layout(push_constant, std140) uniform b_pc
-{
-	Vec2 u_viewportSize;
-	UVec2 u_viewportSizeU;
-};
-
-layout(local_size_x = 8, local_size_y = 8) in;
-#else
-layout(location = 0) in Vec2 in_uv;
-layout(location = 0) out Vec3 out_col;
-#endif
-
-void main()
-{
-#if USE_COMPUTE
-	if(skipOutOfBoundsInvocations(UVec2(8u), u_viewportSizeU))
-	{
-		return;
-	}
-
-	const Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / u_viewportSize;
-#else
-	const Vec2 uv = in_uv;
-#endif
-
-	const Vec3 color = textureLod(u_tex, u_linearAnyClampSampler, uv, 0.0).rgb;
-
-#if USE_COMPUTE
-	imageStore(u_outImage, IVec2(gl_GlobalInvocationID.xy), Vec4(color, 0.0));
-#else
-	out_col = color;
-#endif
-}

+ 4 - 2
AnKi/Shaders/BlitCompute.ankiprog

@@ -3,6 +3,8 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma anki hlsl
+
 #pragma anki start comp
-#include <AnKi/Shaders/Blit.glsl>
-#pragma anki end
+#include <AnKi/Shaders/Blit.hlsl>
+#pragma anki end

+ 4 - 2
AnKi/Shaders/BlitRaster.ankiprog

@@ -3,10 +3,12 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma anki hlsl
+
 #pragma anki start vert
-#include <AnKi/Shaders/QuadVert.glsl>
+#include <AnKi/Shaders/QuadVert.hlsl>
 #pragma anki end
 
 #pragma anki start frag
-#include <AnKi/Shaders/Blit.glsl>
+#include <AnKi/Shaders/Blit.hlsl>
 #pragma anki end

+ 4 - 7
AnKi/Shaders/Functions.hlsl

@@ -415,14 +415,12 @@ F32 cubeCoordSolidAngle(Vec2 norm, F32 cubeFaceSize)
 	return areaElement(v0.x, v0.y) - areaElement(v0.x, v1.y) - areaElement(v1.x, v0.y) + areaElement(v1.x, v1.y);
 }
 
-// A convenience function to skip out of bounds invocations on post-process compute shaders. Both the arguments should
-// be constexpr.
-#if defined(ANKI_COMPUTE_SHADER) && ANKI_GLSL
-Bool skipOutOfBoundsInvocations(UVec2 workgroupSize, UVec2 globalInvocationCount)
+/// A convenience function to skip out of bounds invocations on post-process compute shaders.
+Bool skipOutOfBoundsInvocations(UVec2 groupSize, UVec2 threadCount, UVec2 svDispatchThreadId)
 {
-	if((globalInvocationCount.x % workgroupSize.x) != 0u || (globalInvocationCount.y % workgroupSize.y) != 0u)
+	if((threadCount.x % groupSize.x) != 0u || (threadCount.y % groupSize.y) != 0u)
 	{
-		if(gl_GlobalInvocationID.x >= globalInvocationCount.x || gl_GlobalInvocationID.y >= globalInvocationCount.y)
+		if(svDispatchThreadId.x >= threadCount.x || svDispatchThreadId.y >= threadCount.y)
 		{
 			return true;
 		}
@@ -430,7 +428,6 @@ Bool skipOutOfBoundsInvocations(UVec2 workgroupSize, UVec2 globalInvocationCount
 
 	return false;
 }
-#endif
 
 // Create a matrix from some direction.
 Mat3 rotationFromDirection(Vec3 zAxis)

+ 4 - 0
AnKi/Shaders/Include/Common.h

@@ -60,6 +60,10 @@ void maybeUnused(T a)
 }
 #	define ANKI_MAYBE_UNUSED(x) maybeUnused(x)
 
+// Use a define because the [] annoyes clang-format
+#	define _ANKI_NUMTHREADS
+#	define ANKI_NUMTHREADS(x, y, z) _ANKI_NUMTHREADS[numthreads(x, y, z)]
+
 #	define _ANKI_CONCATENATE(a, b) a##b
 #	define ANKI_CONCATENATE(a, b) _ANKI_CONCATENATE(a, b)