Browse Source

Move DepthAwareBlur to HLSL

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
ce8e15c82b

+ 24 - 7
.clang-format

@@ -3,6 +3,7 @@ Language:        Cpp
 BasedOnStyle:  LLVM
 BasedOnStyle:  LLVM
 AccessModifierOffset: -4
 AccessModifierOffset: -4
 AlignAfterOpenBracket: Align
 AlignAfterOpenBracket: Align
+AlignArrayOfStructures: None
 AlignConsecutiveMacros: None
 AlignConsecutiveMacros: None
 AlignConsecutiveAssignments: None
 AlignConsecutiveAssignments: None
 AlignConsecutiveBitFields: None
 AlignConsecutiveBitFields: None
@@ -11,7 +12,6 @@ AlignEscapedNewlines: DontAlign
 AlignOperands:   Align
 AlignOperands:   Align
 AlignTrailingComments: false
 AlignTrailingComments: false
 AllowAllArgumentsOnNextLine: false
 AllowAllArgumentsOnNextLine: false
-AllowAllConstructorInitializersOnNextLine: true
 AllowAllParametersOfDeclarationOnNextLine: true
 AllowAllParametersOfDeclarationOnNextLine: true
 AllowShortEnumsOnASingleLine: false
 AllowShortEnumsOnASingleLine: false
 AllowShortBlocksOnASingleLine: Never
 AllowShortBlocksOnASingleLine: Never
@@ -59,23 +59,27 @@ BreakAfterJavaFieldAnnotations: false
 BreakStringLiterals: true
 BreakStringLiterals: true
 ColumnLimit:     120
 ColumnLimit:     120
 CommentPragmas:  '^ IWYU pragma:'
 CommentPragmas:  '^ IWYU pragma:'
+QualifierAlignment: Leave
 CompactNamespaces: false
 CompactNamespaces: false
-ConstructorInitializerAllOnOneLineOrOnePerLine: false
 ConstructorInitializerIndentWidth: 4
 ConstructorInitializerIndentWidth: 4
 ContinuationIndentWidth: 4
 ContinuationIndentWidth: 4
 Cpp11BracedListStyle: true
 Cpp11BracedListStyle: true
 DeriveLineEnding: true
 DeriveLineEnding: true
 DerivePointerAlignment: false
 DerivePointerAlignment: false
 DisableFormat:   false
 DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
 EmptyLineBeforeAccessModifier: LogicalBlock
 EmptyLineBeforeAccessModifier: LogicalBlock
 ExperimentalAutoDetectBinPacking: false
 ExperimentalAutoDetectBinPacking: false
+PackConstructorInitializers: BinPack
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+AllowAllConstructorInitializersOnNextLine: false
 FixNamespaceComments: true
 FixNamespaceComments: true
 ForEachMacros:
 ForEachMacros:
   - foreach
   - foreach
   - Q_FOREACH
   - Q_FOREACH
   - BOOST_FOREACH
   - BOOST_FOREACH
-StatementAttributeLikeMacros:
-  - Q_EMIT
+IfMacros:
+  - KJ_IF_MAYBE
 IncludeBlocks:   Preserve
 IncludeBlocks:   Preserve
 IncludeCategories:
 IncludeCategories:
   - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
   - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
@@ -92,6 +96,7 @@ IncludeCategories:
     CaseSensitive:   false
     CaseSensitive:   false
 IncludeIsMainRegex: '(Test)?$'
 IncludeIsMainRegex: '(Test)?$'
 IncludeIsMainSourceRegex: ''
 IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
 IndentCaseLabels: false
 IndentCaseLabels: false
 IndentCaseBlocks: false
 IndentCaseBlocks: false
 IndentGotoLabels: true
 IndentGotoLabels: true
@@ -104,6 +109,7 @@ InsertTrailingCommas: None
 JavaScriptQuotes: Leave
 JavaScriptQuotes: Leave
 JavaScriptWrapImports: true
 JavaScriptWrapImports: true
 KeepEmptyLinesAtTheStartOfBlocks: true
 KeepEmptyLinesAtTheStartOfBlocks: true
+LambdaBodyIndentation: Signature
 MacroBlockBegin: ''
 MacroBlockBegin: ''
 MacroBlockEnd:   ''
 MacroBlockEnd:   ''
 MaxEmptyLinesToKeep: 1
 MaxEmptyLinesToKeep: 1
@@ -117,14 +123,20 @@ PenaltyBreakAssignment: 2
 PenaltyBreakBeforeFirstCallParameter: 19
 PenaltyBreakBeforeFirstCallParameter: 19
 PenaltyBreakComment: 300
 PenaltyBreakComment: 300
 PenaltyBreakFirstLessLess: 120
 PenaltyBreakFirstLessLess: 120
+PenaltyBreakOpenParenthesis: 0
 PenaltyBreakString: 1000
 PenaltyBreakString: 1000
 PenaltyBreakTemplateDeclaration: 10
 PenaltyBreakTemplateDeclaration: 10
 PenaltyExcessCharacter: 1000000
 PenaltyExcessCharacter: 1000000
 PenaltyReturnTypeOnItsOwnLine: 60
 PenaltyReturnTypeOnItsOwnLine: 60
 PenaltyIndentedWhitespace: 0
 PenaltyIndentedWhitespace: 0
 PointerAlignment: Left
 PointerAlignment: Left
+PPIndentWidth:   -1
+ReferenceAlignment: Pointer
 ReflowComments:  true
 ReflowComments:  true
-SortIncludes:    false
+RemoveBracesLLVM: false
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes:    Never
 SortJavaStaticImport: Before
 SortJavaStaticImport: Before
 SortUsingDeclarations: false
 SortUsingDeclarations: false
 SpaceAfterCStyleCast: false
 SpaceAfterCStyleCast: false
@@ -141,15 +153,20 @@ SpaceBeforeRangeBasedForLoopColon: true
 SpaceInEmptyBlock: false
 SpaceInEmptyBlock: false
 SpaceInEmptyParentheses: false
 SpaceInEmptyParentheses: false
 SpacesBeforeTrailingComments: 1
 SpacesBeforeTrailingComments: 1
-SpacesInAngles:  false
+SpacesInAngles:  Never
 SpacesInConditionalStatement: false
 SpacesInConditionalStatement: false
 SpacesInContainerLiterals: true
 SpacesInContainerLiterals: true
 SpacesInCStyleCastParentheses: false
 SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+  Minimum:         1
+  Maximum:         -1
 SpacesInParentheses: false
 SpacesInParentheses: false
 SpacesInSquareBrackets: false
 SpacesInSquareBrackets: false
 SpaceBeforeSquareBrackets: false
 SpaceBeforeSquareBrackets: false
 BitFieldColonSpacing: Both
 BitFieldColonSpacing: Both
 Standard:        Latest
 Standard:        Latest
+StatementAttributeLikeMacros:
+  - Q_EMIT
 StatementMacros:
 StatementMacros:
   - Q_UNUSED
   - Q_UNUSED
   - QT_REQUIRE_VERSION
   - QT_REQUIRE_VERSION
@@ -164,6 +181,6 @@ WhitespaceSensitiveMacros:
   - CF_SWIFT_NAME
   - CF_SWIFT_NAME
 ---
 ---
 Language: ObjC
 Language: ObjC
-BasedOnStyle: Mozilla
+BasedOnStyle: Microsoft
 ...
 ...
 
 

+ 186 - 0
.clang-format-hlsl

@@ -0,0 +1,186 @@
+---
+Language:        Cpp
+BasedOnStyle:  LLVM
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignArrayOfStructures: None
+AlignConsecutiveMacros: None
+AlignConsecutiveAssignments: None
+AlignConsecutiveBitFields: None
+AlignConsecutiveDeclarations: None
+AlignEscapedNewlines: DontAlign
+AlignOperands:   Align
+AlignTrailingComments: false
+AllowAllArgumentsOnNextLine: false
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortEnumsOnASingleLine: false
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortLambdasOnASingleLine: Empty
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+AttributeMacros:
+  - __capability
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterCaseLabel:  true
+  AfterClass:      true
+  AfterControlStatement: true
+  AfterEnum:       true
+  AfterFunction:   true
+  AfterNamespace:  false
+  AfterObjCDeclaration: true
+  AfterStruct:     true
+  AfterUnion:      true
+  AfterExternBlock: false
+  BeforeCatch:     true
+  BeforeElse:      true
+  BeforeLambdaBody: false
+  BeforeWhile:     false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeConceptDeclarations: true
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: AfterColon
+BreakBeforeTernaryOperators: true
+#BreakConstructorInitializersBeforeComma: true
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit:     120
+CommentPragmas:  '^ IWYU pragma:'
+QualifierAlignment: Leave
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+PackConstructorInitializers: BinPack
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+AllowAllConstructorInitializersOnNextLine: false
+FixNamespaceComments: true
+ForEachMacros:
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IfMacros:
+  - KJ_IF_MAYBE
+IncludeBlocks:   Preserve
+IncludeCategories:
+  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
+    Priority:        2
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '.*'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseLabels: false
+IndentCaseBlocks: false
+IndentGotoLabels: true
+IndentPPDirectives: AfterHash
+IndentExternBlock: NoIndent
+IndentRequires:  false
+IndentWidth:     4
+IndentWrappedFunctionNames: false
+InsertTrailingCommas: None
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+LambdaBodyIndentation: Signature
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+PointerAlignment: Left
+PPIndentWidth:   -1
+ReferenceAlignment: Pointer
+ReflowComments:  true
+RemoveBracesLLVM: false
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes:    Never
+SortJavaStaticImport: Before
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: false
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: Never
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  Never
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+  Minimum:         1
+  Maximum:         -1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+BitFieldColonSpacing: Both
+Standard:        Latest
+StatementAttributeLikeMacros:
+  - Q_EMIT
+StatementMacros:
+  - Q_UNUSED
+  - QT_REQUIRE_VERSION
+TabWidth:        4
+UseCRLF:         false
+UseTab:          ForContinuationAndIndentation
+WhitespaceSensitiveMacros:
+  - STRINGIZE
+  - PP_STRINGIZE
+  - BOOST_PP_STRINGIZE
+  - NS_SWIFT_NAME
+  - CF_SWIFT_NAME
+---
+Language: ObjC
+BasedOnStyle: Microsoft
+...
+

+ 0 - 146
AnKi/Shaders/DepthAwareBlur.glsl

@@ -1,146 +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/Common.glsl>
-
-#pragma anki mutator ORIENTATION 0 1 2 // 0: VERTICAL, 1: HORIZONTAL, 2: BOX
-#pragma anki mutator SAMPLE_COUNT 3 5 7 9 11 13 15
-#pragma anki mutator COLOR_COMPONENTS 4 3 1
-
-ANKI_SPECIALIZATION_CONSTANT_UVEC2(kTextureSize, 0u);
-
-#if ORIENTATION == 0
-#	define VERTICAL 1
-#elif ORIENTATION == 1
-#	define HORIZONTAL 1
-#else
-#	define BOX 1
-#endif
-
-#if SAMPLE_COUNT < 3
-#	error See file
-#endif
-
-#if defined(ANKI_COMPUTE_SHADER)
-#	define USE_COMPUTE 1
-const UVec2 kWorkgroupSize = UVec2(8u, 8u);
-#else
-#	define USE_COMPUTE 0
-#endif
-
-// Define some macros depending on the number of components
-#if COLOR_COMPONENTS == 4
-#	define COL_TYPE Vec4
-#	define TEX_FETCH rgba
-#	define TO_VEC4(x_) x_
-#elif COLOR_COMPONENTS == 3
-#	define COL_TYPE Vec3
-#	define TEX_FETCH rgb
-#	define TO_VEC4(x_) Vec4(x_, 0.0)
-#elif COLOR_COMPONENTS == 1
-#	define COL_TYPE F32
-#	define TEX_FETCH r
-#	define TO_VEC4(x_) Vec4(x_, 0.0, 0.0, 0.0)
-#else
-#	error See file
-#endif
-
-layout(set = 0, binding = 0) uniform sampler u_linearAnyClampSampler;
-layout(set = 0, binding = 1) uniform texture2D u_inTex;
-layout(set = 0, binding = 2) uniform texture2D u_depthTex;
-
-#if USE_COMPUTE
-layout(local_size_x = kWorkgroupSize.x, local_size_y = kWorkgroupSize.y, local_size_z = 1) in;
-layout(set = 0, binding = 3) writeonly uniform image2D u_outImg;
-#else
-layout(location = 0) in Vec2 in_uv;
-layout(location = 0) out COL_TYPE out_color;
-#endif
-
-F32 computeDepthWeight(F32 refDepth, F32 depth)
-{
-	const F32 diff = abs(refDepth - depth);
-	const F32 weight = 1.0 / (kEpsilonf + diff);
-	return sqrt(weight);
-}
-
-F32 readDepth(Vec2 uv)
-{
-	return textureLod(u_depthTex, u_linearAnyClampSampler, uv, 0.0).r;
-}
-
-void sampleTex(Vec2 uv, F32 refDepth, inout COL_TYPE col, inout F32 weight)
-{
-	const COL_TYPE color = textureLod(u_inTex, u_linearAnyClampSampler, uv, 0.0).TEX_FETCH;
-	F32 w = computeDepthWeight(refDepth, readDepth(uv));
-	col += color * w;
-	weight += w;
-}
-
-void main()
-{
-	// Set UVs
-#if USE_COMPUTE
-	[[branch]] if(gl_GlobalInvocationID.x >= kTextureSize.x || gl_GlobalInvocationID.y >= kTextureSize.y)
-	{
-		// Out of bounds
-		return;
-	}
-
-	const Vec2 uv = (Vec2(gl_GlobalInvocationID.xy) + 0.5) / Vec2(kTextureSize);
-#else
-	const Vec2 uv = in_uv;
-#endif
-
-	const Vec2 TEXEL_SIZE = 1.0 / Vec2(kTextureSize);
-
-	// Sample
-	COL_TYPE color = textureLod(u_inTex, u_linearAnyClampSampler, uv, 0.0).TEX_FETCH;
-	const F32 refDepth = readDepth(uv);
-	F32 weight = 1.0;
-
-#if !defined(BOX)
-	// Do seperable
-
-#	if defined(HORIZONTAL)
-#		define X_OR_Y x
-#	else
-#		define X_OR_Y y
-#	endif
-
-	Vec2 uvOffset = Vec2(0.0);
-	uvOffset.X_OR_Y = 1.5 * TEXEL_SIZE.X_OR_Y;
-
-	[[unroll]] for(U32 i = 0u; i < (U32(SAMPLE_COUNT) - 1u) / 2u; ++i)
-	{
-		sampleTex(uv + uvOffset, refDepth, color, weight);
-		sampleTex(uv - uvOffset, refDepth, color, weight);
-
-		uvOffset.X_OR_Y += 2.0 * TEXEL_SIZE.X_OR_Y;
-	}
-#else
-	// Do box
-
-	const Vec2 OFFSET = 1.5 * TEXEL_SIZE;
-
-	sampleTex(uv + Vec2(+OFFSET.x, +OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + Vec2(+OFFSET.x, -OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + Vec2(-OFFSET.x, +OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + Vec2(-OFFSET.x, -OFFSET.y), refDepth, color, weight);
-
-	sampleTex(uv + Vec2(OFFSET.x, 0.0), refDepth, color, weight);
-	sampleTex(uv + Vec2(0.0, OFFSET.y), refDepth, color, weight);
-	sampleTex(uv + Vec2(-OFFSET.x, 0.0), refDepth, color, weight);
-	sampleTex(uv + Vec2(0.0, -OFFSET.y), refDepth, color, weight);
-#endif
-	color = color / weight;
-
-	// Write value
-#if USE_COMPUTE
-	imageStore(u_outImg, IVec2(gl_GlobalInvocationID.xy), TO_VEC4(color));
-#else
-	out_color = color;
-#endif
-}

+ 132 - 0
AnKi/Shaders/DepthAwareBlur.hlsl

@@ -0,0 +1,132 @@
+// 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/Common.hlsl>
+
+#pragma anki mutator ORIENTATION 0 1 2 // 0: VERTICAL, 1: HORIZONTAL, 2: BOX
+#pragma anki mutator SAMPLE_COUNT 3 5 7 9 11 13 15
+#pragma anki mutator COLOR_COMPONENTS 4 3 1
+
+#define ORIENTATION_VERTICAL 0
+#define ORIENTATION_HORIZONTAL 1
+#define ORIENTATION_BOX 2
+
+#if SAMPLE_COUNT < 3
+#	error See file
+#endif
+
+// Define some macros depending on the number of components
+#if COLOR_COMPONENTS == 4
+typedef Vec4 ColorType;
+#elif COLOR_COMPONENTS == 3
+typedef Vec3 ColorType;
+#elif COLOR_COMPONENTS == 1
+typedef F32 ColorType;
+#else
+#	error See file
+#endif
+
+[[vk::binding(0)]] SamplerState g_linearAnyClampSampler;
+[[vk::binding(1)]] Texture2D<ColorType> g_inTex;
+[[vk::binding(2)]] Texture2D g_depthTex;
+
+#if defined(ANKI_COMPUTE_SHADER)
+#	define THREADGROUP_SQRT_SIZE 8
+[[vk::binding(2)]] RWTexture2D<ColorType> g_outImg;
+#endif
+
+F32 computeDepthWeight(F32 refDepth, F32 depth)
+{
+	const F32 diff = abs(refDepth - depth);
+	const F32 weight = 1.0 / (kEpsilonF32 + diff);
+	return sqrt(weight);
+}
+
+F32 readDepth(Vec2 uv)
+{
+	return g_depthTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0).r;
+}
+
+void sampleTex(Vec2 uv, F32 refDepth, inout ColorType col, inout F32 weight)
+{
+	const ColorType color = g_inTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0);
+	const F32 w = computeDepthWeight(refDepth, readDepth(uv));
+	col += color * w;
+	weight += w;
+}
+
+#if defined(ANKI_COMPUTE_SHADER)
+ANKI_NUMTHREADS(THREADGROUP_SQRT_SIZE, THREADGROUP_SQRT_SIZE, 1)
+void main(UVec3 svDispatchThreadId : SV_DISPATCHTHREADID)
+#else
+ColorType main([[vk::location(0)]] Vec2 uv : TEXCOORD): SV_TARGET0
+#endif
+{
+	UVec2 textureSize;
+	U32 mipCount;
+	g_inTex.GetDimensions(0, textureSize.x, textureSize.y, mipCount);
+
+	// Set UVs
+#if defined(ANKI_COMPUTE_SHADER)
+	[[branch]] if(svDispatchThreadId.x >= textureSize.x || svDispatchThreadId.y >= textureSize.y)
+	{
+		// Out of bounds
+		return;
+	}
+
+	const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5) / Vec2(textureSize);
+#endif
+
+	const Vec2 texelSize = 1.0 / Vec2(textureSize);
+
+	// Sample
+	ColorType color = g_inTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0);
+	const F32 refDepth = readDepth(uv);
+	F32 weight = 1.0;
+
+#if ORIENTATION != ORIENTATION_BOX
+	// Do seperable
+
+#	if ORIENTATION == ORIENTATION_HORIZONTAL
+#		define X_OR_Y x
+#	else
+#		define X_OR_Y y
+#	endif
+
+	Vec2 uvOffset = Vec2(0.0, 0.0);
+	uvOffset.X_OR_Y = 1.5 * texelSize.X_OR_Y;
+
+	[[unroll]] for(U32 i = 0u; i < (SAMPLE_COUNT - 1u) / 2u; ++i)
+	{
+		sampleTex(uv + uvOffset, refDepth, color, weight);
+		sampleTex(uv - uvOffset, refDepth, color, weight);
+
+		uvOffset.X_OR_Y += 2.0 * texelSize.X_OR_Y;
+	}
+#else
+	// Do box
+
+	const Vec2 offset = 1.5 * texelSize;
+
+	sampleTex(uv + Vec2(+offset.x, +offset.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(+offset.x, -offset.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(-offset.x, +offset.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(-offset.x, -offset.y), refDepth, color, weight);
+
+	sampleTex(uv + Vec2(offset.x, 0.0), refDepth, color, weight);
+	sampleTex(uv + Vec2(0.0, offset.y), refDepth, color, weight);
+	sampleTex(uv + Vec2(-offset.x, 0.0), refDepth, color, weight);
+	sampleTex(uv + Vec2(0.0, -offset.y), refDepth, color, weight);
+#endif
+
+	color /= weight;
+
+	// Write value
+#if defined(ANKI_COMPUTE_SHADER)
+	g_outImg[svDispatchThreadId.xy] = color;
+#else
+	return color;
+#endif
+}

+ 3 - 1
AnKi/Shaders/DepthAwareBlurCompute.ankiprog

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

+ 4 - 2
AnKi/Shaders/DepthAwareBlur.ankiprog → AnKi/Shaders/DepthAwareBlurRaster.ankiprog

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

+ 9 - 1
Tools/FormatSource.py

@@ -9,6 +9,7 @@ import glob
 import subprocess
 import subprocess
 import threading
 import threading
 import multiprocessing
 import multiprocessing
+import os
 
 
 file_extensions = ["h", "hpp", "c", "cpp", "glsl", "hlsl", "ankiprog"]
 file_extensions = ["h", "hpp", "c", "cpp", "glsl", "hlsl", "ankiprog"]
 directories = ["AnKi", "Tests", "Sandbox", "Tools", "Samples"]
 directories = ["AnKi", "Tests", "Sandbox", "Tools", "Samples"]
@@ -30,7 +31,14 @@ def thread_callback(tid):
         if file_name is None:
         if file_name is None:
             break
             break
 
 
-        subprocess.check_call(["./ThirdParty/Bin/Windows64/clang-format.exe", "-sort-includes=false", "-i", file_name])
+        unused, file_extension = os.path.splitext(file_name)
+        if file_extension == ".hlsl" or file_extension == ".ankiprog":
+            style_file = "--style=file:.clang-format-hlsl"
+        else:
+            style_file = "--style=file:.clang-format"
+
+        subprocess.check_call(["./ThirdParty/Bin/Windows64/clang-format.exe",
+                              "-sort-includes=false", style_file, "-i", file_name])
 
 
 
 
 # Gather the filenames
 # Gather the filenames