فهرست منبع

Some renaming

Panagiotis Christopoulos Charitos 2 سال پیش
والد
کامیت
2daa558071

+ 12 - 11
AnKi/Renderer/ClusterBinning.cpp

@@ -411,17 +411,18 @@ void ClusterBinning::writeClustererBuffersTask()
 		unis.m_tileSize = m_r->getTileSize();
 		unis.m_lightVolumeLastZSplit = m_r->getVolumetricLightingAccumulation().getFinalZSplit();
 
-		unis.m_objectCountsUpTo[kClusterObjectTypePointLight].x() = rqueue.m_pointLights.getSize();
-		unis.m_objectCountsUpTo[kClusterObjectTypeSpotLight].x() =
-			unis.m_objectCountsUpTo[kClusterObjectTypeSpotLight - 1].x() + rqueue.m_spotLights.getSize();
-		unis.m_objectCountsUpTo[kClusterObjectTypeDecal].x() =
-			unis.m_objectCountsUpTo[kClusterObjectTypeDecal - 1].x() + rqueue.m_decals.getSize();
-		unis.m_objectCountsUpTo[kClusterObjectTypeFogDensityVolume].x() =
-			unis.m_objectCountsUpTo[kClusterObjectTypeFogDensityVolume - 1].x() + rqueue.m_fogDensityVolumes.getSize();
-		unis.m_objectCountsUpTo[kClusterObjectTypeReflectionProbe].x() =
-			unis.m_objectCountsUpTo[kClusterObjectTypeReflectionProbe - 1].x() + rqueue.m_reflectionProbes.getSize();
-		unis.m_objectCountsUpTo[kClusterObjectTypeGlobalIlluminationProbe].x() =
-			unis.m_objectCountsUpTo[kClusterObjectTypeGlobalIlluminationProbe - 1].x() + rqueue.m_giProbes.getSize();
+		unis.m_objectCountsUpTo[ClusterObjectType::kPointLight].x() = rqueue.m_pointLights.getSize();
+		unis.m_objectCountsUpTo[ClusterObjectType::kSpotLight].x() =
+			unis.m_objectCountsUpTo[ClusterObjectType::kSpotLight - 1].x() + rqueue.m_spotLights.getSize();
+		unis.m_objectCountsUpTo[ClusterObjectType::kDecal].x() =
+			unis.m_objectCountsUpTo[ClusterObjectType::kDecal - 1].x() + rqueue.m_decals.getSize();
+		unis.m_objectCountsUpTo[ClusterObjectType::kFogDensityVolume].x() =
+			unis.m_objectCountsUpTo[ClusterObjectType::kFogDensityVolume - 1].x()
+			+ rqueue.m_fogDensityVolumes.getSize();
+		unis.m_objectCountsUpTo[ClusterObjectType::kReflectionProbe].x() =
+			unis.m_objectCountsUpTo[ClusterObjectType::kReflectionProbe - 1].x() + rqueue.m_reflectionProbes.getSize();
+		unis.m_objectCountsUpTo[ClusterObjectType::kGlobalIlluminationProbe].x() =
+			unis.m_objectCountsUpTo[ClusterObjectType::kGlobalIlluminationProbe - 1].x() + rqueue.m_giProbes.getSize();
 
 		unis.m_reflectionProbesMipCount = F32(m_r->getProbeReflections().getReflectionTextureMipmapCount());
 

+ 13 - 11
AnKi/Shaders/ClusterBinning.ankiprog

@@ -41,32 +41,32 @@ groupshared ExtendedClusterObjectMask s_zSplitMasks[kMaxZsplitCount];
 
 Bool isPointLight(U32 objectIdx)
 {
-	return objectIdx < g_unis.m_objectCountsUpTo[kClusterObjectTypePointLight].x;
+	return objectIdx < g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kPointLight].x;
 }
 
 Bool isSpotLight(U32 objectIdx)
 {
-	return objectIdx < g_unis.m_objectCountsUpTo[kClusterObjectTypeSpotLight].x;
+	return objectIdx < g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kSpotLight].x;
 }
 
 Bool isDecal(U32 objectIdx)
 {
-	return objectIdx < g_unis.m_objectCountsUpTo[kClusterObjectTypeDecal].x;
+	return objectIdx < g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kDecal].x;
 }
 
 Bool isFogVolume(U32 objectIdx)
 {
-	return objectIdx < g_unis.m_objectCountsUpTo[kClusterObjectTypeFogDensityVolume].x;
+	return objectIdx < g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kFogDensityVolume].x;
 }
 
 Bool isReflectionProbe(U32 objectIdx)
 {
-	return objectIdx < g_unis.m_objectCountsUpTo[kClusterObjectTypeReflectionProbe].x;
+	return objectIdx < g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kReflectionProbe].x;
 }
 
 Bool isGiProbe(U32 objectIdx)
 {
-	return objectIdx < g_unis.m_objectCountsUpTo[kClusterObjectTypeGlobalIlluminationProbe].x;
+	return objectIdx < g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kGlobalIlluminationProbe].x;
 }
 
 [numthreads(THREADGROUP_SIZE, 1, 1)] void main(UVec3 svDispatchThreadId : SV_DISPATCHTHREADID,
@@ -118,7 +118,7 @@ Bool isGiProbe(U32 objectIdx)
 	// Spot light
 	else if(isSpotLight(clustererObjectIdx))
 	{
-		objectArrayIdx = clustererObjectIdx - g_unis.m_objectCountsUpTo[kClusterObjectTypeSpotLight - 1u].x;
+		objectArrayIdx = clustererObjectIdx - g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kSpotLight - 1u].x;
 		const SpotLightBinning light = g_spotLights[objectArrayIdx];
 
 		t0 = 10000.0;
@@ -156,7 +156,7 @@ Bool isGiProbe(U32 objectIdx)
 	// Decal
 	else if(isDecal(clustererObjectIdx))
 	{
-		objectArrayIdx = clustererObjectIdx - g_unis.m_objectCountsUpTo[kClusterObjectTypeDecal - 1u].x;
+		objectArrayIdx = clustererObjectIdx - g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kDecal - 1u].x;
 		const Decal decal = g_decals[objectArrayIdx];
 
 		collides = testRayObb(rayOrigin, rayDir, decal.m_obbExtend, decal.m_invertedTransform, t0, t1);
@@ -164,7 +164,8 @@ Bool isGiProbe(U32 objectIdx)
 	// Fog volume
 	else if(isFogVolume(clustererObjectIdx))
 	{
-		objectArrayIdx = clustererObjectIdx - g_unis.m_objectCountsUpTo[kClusterObjectTypeFogDensityVolume - 1u].x;
+		objectArrayIdx =
+			clustererObjectIdx - g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kFogDensityVolume - 1u].x;
 		const FogDensityVolume vol = g_fogVolumes[objectArrayIdx];
 
 		if(vol.m_isBox != 0u)
@@ -181,7 +182,8 @@ Bool isGiProbe(U32 objectIdx)
 	// Reflection probe
 	else if(isReflectionProbe(clustererObjectIdx))
 	{
-		objectArrayIdx = clustererObjectIdx - g_unis.m_objectCountsUpTo[kClusterObjectTypeReflectionProbe - 1u].x;
+		objectArrayIdx =
+			clustererObjectIdx - g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kReflectionProbe - 1u].x;
 		const ReflectionProbe probe = g_reflectionProbes[objectArrayIdx];
 
 		collides = testRayAabb(rayOrigin, rayDir, probe.m_aabbMin, probe.m_aabbMax, t0, t1);
@@ -190,7 +192,7 @@ Bool isGiProbe(U32 objectIdx)
 	else
 	{
 		objectArrayIdx =
-			clustererObjectIdx - g_unis.m_objectCountsUpTo[kClusterObjectTypeGlobalIlluminationProbe - 1u].x;
+			clustererObjectIdx - g_unis.m_objectCountsUpTo[(U32)ClusterObjectType::kGlobalIlluminationProbe - 1u].x;
 		const GlobalIlluminationProbe probe = g_giProbes[objectArrayIdx];
 
 		collides = testRayAabb(rayOrigin, rayDir, probe.m_aabbMin, probe.m_aabbMax, t0, t1);

+ 6 - 6
AnKi/Shaders/ClusteredShadingCommon.hlsl

@@ -85,37 +85,37 @@ Vec3 clusterHeatmap(Cluster cluster, U32 objectTypeMask)
 	U32 maxObjects = 0u;
 	I32 count = 0;
 
-	if((objectTypeMask & (1u << kClusterObjectTypePointLight)) != 0u)
+	if((objectTypeMask & (1u << (U32)ClusterObjectType::kPointLight)) != 0u)
 	{
 		maxObjects += kMaxVisiblePointLights;
 		count += I32(countbits(cluster.m_pointLightsMask));
 	}
 
-	if((objectTypeMask & (1u << kClusterObjectTypeSpotLight)) != 0u)
+	if((objectTypeMask & (1u << (U32)ClusterObjectType::kSpotLight)) != 0u)
 	{
 		maxObjects += kMaxVisibleSpotLights;
 		count += I32(countbits(cluster.m_spotLightsMask));
 	}
 
-	if((objectTypeMask & (1u << kClusterObjectTypeDecal)) != 0u)
+	if((objectTypeMask & (1u << (U32)ClusterObjectType::kDecal)) != 0u)
 	{
 		maxObjects += kMaxVisibleDecals;
 		count += I32(countbits(cluster.m_decalsMask));
 	}
 
-	if((objectTypeMask & (1u << kClusterObjectTypeFogDensityVolume)) != 0u)
+	if((objectTypeMask & (1u << (U32)ClusterObjectType::kFogDensityVolume)) != 0u)
 	{
 		maxObjects += kMaxVisibleFogDensityVolumes;
 		count += countbits(cluster.m_fogDensityVolumesMask);
 	}
 
-	if((objectTypeMask & (1u << kClusterObjectTypeReflectionProbe)) != 0u)
+	if((objectTypeMask & (1u << (U32)ClusterObjectType::kReflectionProbe)) != 0u)
 	{
 		maxObjects += kMaxVisibleReflectionProbes;
 		count += countbits(cluster.m_reflectionProbesMask);
 	}
 
-	if((objectTypeMask & (1u << kClusterObjectTypeGlobalIlluminationProbe)) != 0u)
+	if((objectTypeMask & (1u << (U32)ClusterObjectType::kGlobalIlluminationProbe)) != 0u)
 	{
 		maxObjects += kMaxVisibleGlobalIlluminationProbes;
 		count += countbits(cluster.m_giProbesMask);

+ 35 - 25
AnKi/Shaders/Include/ClusteredShadingTypes.h

@@ -12,13 +12,19 @@
 ANKI_BEGIN_NAMESPACE
 
 // Enum of clusterer object types
-constexpr U32 kClusterObjectTypePointLight = 0u;
-constexpr U32 kClusterObjectTypeSpotLight = 1u;
-constexpr U32 kClusterObjectTypeDecal = 2u;
-constexpr U32 kClusterObjectTypeFogDensityVolume = 3u;
-constexpr U32 kClusterObjectTypeReflectionProbe = 4u;
-constexpr U32 kClusterObjectTypeGlobalIlluminationProbe = 5u;
-constexpr U32 kClusterObjectTypeCount = 6u; ///< Point and spot lights, refl and GI probes, decals and fog volumes.
+enum class ClusterObjectType : U32
+{
+	kPointLight,
+	kSpotLight,
+	kDecal,
+	kFogDensityVolume,
+	kReflectionProbe,
+	kGlobalIlluminationProbe,
+
+	kCount,
+	kFirst = 0
+};
+ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(ClusterObjectType)
 
 // Limits
 #if ANKI_CLUSTERED_SHADING_USE_64BIT
@@ -55,7 +61,7 @@ struct PointLight
 	Vec4 m_shadowAtlasTileOffsets[6u]; ///< It's a array of Vec2 but because of padding round it up.
 };
 constexpr U32 kSizeof_PointLight = 9u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(PointLight) == kSizeof_PointLight);
+static_assert(sizeof(PointLight) == kSizeof_PointLight);
 
 /// Spot light.
 struct SpotLight
@@ -79,7 +85,7 @@ struct SpotLight
 	Mat4 m_textureMatrix;
 };
 constexpr U32 kSizeof_SpotLight = 12u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(SpotLight) == kSizeof_SpotLight);
+static_assert(sizeof(SpotLight) == kSizeof_SpotLight);
 
 /// Spot light for binning. This is the same structure as SpotLight (same signature) but it's used for binning.
 struct SpotLightBinning
@@ -100,8 +106,8 @@ struct SpotLightBinning
 	Mat4 m_textureMatrix;
 };
 constexpr U32 kSizeof_SpotLightBinning = kSizeof_SpotLight;
-ANKI_SHADER_STATIC_ASSERT(sizeof(SpotLightBinning) == kSizeof_SpotLightBinning);
-ANKI_SHADER_STATIC_ASSERT(sizeof(SpotLight) == sizeof(SpotLightBinning));
+static_assert(sizeof(SpotLightBinning) == kSizeof_SpotLightBinning);
+static_assert(sizeof(SpotLight) == sizeof(SpotLightBinning));
 
 /// Directional light (sun).
 struct DirectionalLight
@@ -120,8 +126,8 @@ struct DirectionalLight
 	Mat4 m_textureMatrices[kMaxShadowCascades];
 };
 constexpr U32 kSizeof_DirectionalLight = 4u * sizeof(Vec4) + kMaxShadowCascades * sizeof(Mat4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(DirectionalLight) == kSizeof_DirectionalLight);
-ANKI_SHADER_STATIC_ASSERT(kMaxShadowCascades == 4u); // Because m_shadowCascadeDistances is a Vec4
+static_assert(sizeof(DirectionalLight) == kSizeof_DirectionalLight);
+static_assert(kMaxShadowCascades == 4u); // Because m_shadowCascadeDistances is a Vec4
 
 /// Representation of a reflection probe.
 struct ReflectionProbe
@@ -136,7 +142,7 @@ struct ReflectionProbe
 	F32 m_padding1;
 };
 constexpr U32 kSizeof_ReflectionProbe = 3u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(ReflectionProbe) == kSizeof_ReflectionProbe);
+static_assert(sizeof(ReflectionProbe) == kSizeof_ReflectionProbe);
 
 /// Decal.
 struct Decal
@@ -154,7 +160,7 @@ struct Decal
 	F32 m_padding0;
 };
 constexpr U32 kSizeof_Decal = 2u * sizeof(Vec4) + 2u * sizeof(Mat4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(Decal) == kSizeof_Decal);
+static_assert(sizeof(Decal) == kSizeof_Decal);
 
 /// Fog density volume.
 struct FogDensityVolume
@@ -166,7 +172,7 @@ struct FogDensityVolume
 	RF32 m_density;
 };
 constexpr U32 kSizeof_FogDensityVolume = 2u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(FogDensityVolume) == kSizeof_FogDensityVolume);
+static_assert(sizeof(FogDensityVolume) == kSizeof_FogDensityVolume);
 
 /// Global illumination probe
 struct GlobalIlluminationProbe
@@ -184,7 +190,7 @@ struct GlobalIlluminationProbe
 	F32 m_padding2;
 };
 constexpr U32 kSizeof_GlobalIlluminationProbe = 3u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(GlobalIlluminationProbe) == kSizeof_GlobalIlluminationProbe);
+static_assert(sizeof(GlobalIlluminationProbe) == kSizeof_GlobalIlluminationProbe);
 
 /// Common matrices.
 struct CommonMatrices
@@ -217,7 +223,7 @@ struct CommonMatrices
 	Vec4 m_unprojectionParameters;
 };
 constexpr U32 kSizeof_CommonMatrices = 43u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(CommonMatrices) == kSizeof_CommonMatrices);
+static_assert(sizeof(CommonMatrices) == kSizeof_CommonMatrices);
 
 /// Common uniforms for light shading passes.
 struct ClusteredShadingUniforms
@@ -239,7 +245,7 @@ struct ClusteredShadingUniforms
 	U32 m_tileSize;
 	U32 m_lightVolumeLastZSplit;
 
-	Vec2 m_padding0;
+	UVec2 m_padding0;
 	F32 m_near;
 	F32 m_far;
 
@@ -248,12 +254,16 @@ struct ClusteredShadingUniforms
 	CommonMatrices m_matrices;
 	CommonMatrices m_previousMatrices;
 
-	/// This are some additive counts used to map a flat index to the index of the specific object.
-	UVec4 m_objectCountsUpTo[kClusterObjectTypeCount];
+	/// This are some additive counts used to map a flat index to the index of the specific object
+#if defined(__cplusplus)
+	Array<UVec4, U32(ClusterObjectType::kCount)> m_objectCountsUpTo;
+#else
+	UVec4 m_objectCountsUpTo[(U32)ClusterObjectType::kCount];
+#endif
 };
 constexpr U32 kSizeof_ClusteredShadingUniforms =
-	(6u + kClusterObjectTypeCount) * sizeof(Vec4) + 2u * sizeof(CommonMatrices) + sizeof(DirectionalLight);
-ANKI_SHADER_STATIC_ASSERT(sizeof(ClusteredShadingUniforms) == kSizeof_ClusteredShadingUniforms);
+	(6u + (U32)ClusterObjectType::kCount) * sizeof(Vec4) + 2u * sizeof(CommonMatrices) + sizeof(DirectionalLight);
+static_assert(sizeof(ClusteredShadingUniforms) == kSizeof_ClusteredShadingUniforms);
 
 // Define the type of some cluster object masks
 #if ANKI_GLSL
@@ -293,10 +303,10 @@ struct Cluster
 
 #if ANKI_CLUSTERED_SHADING_USE_64BIT
 constexpr U32 kSizeof_Cluster = 3u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(Cluster) == kSizeof_Cluster);
+static_assert(sizeof(Cluster) == kSizeof_Cluster);
 #else
 constexpr U32 kSizeof_Cluster = 2u * sizeof(Vec4);
-ANKI_SHADER_STATIC_ASSERT(sizeof(Cluster) == kSizeof_Cluster);
+static_assert(sizeof(Cluster) == kSizeof_Cluster);
 #endif
 
 ANKI_END_NAMESPACE

+ 9 - 9
AnKi/Shaders/LightShading.ankiprog

@@ -24,17 +24,17 @@ ANKI_SPECIALIZATION_CONSTANT_U32(kTileSize, 3u);
 #define CLUSTERED_SHADING_CLUSTERS_BINDING 4u
 #include <AnKi/Shaders/ClusteredShadingCommon.hlsl>
 
-[[vk::binding(5)]] uniform SamplerState g_nearestAnyClampSampler;
-[[vk::binding(6)]] uniform SamplerState g_trilinearClampSampler;
+[[vk::binding(5)]] SamplerState g_nearestAnyClampSampler;
+[[vk::binding(6)]] SamplerState g_trilinearClampSampler;
 
-[[vk::binding(7)]] uniform Texture2D<RVec4> g_gbuffer0Tex;
-[[vk::binding(8)]] uniform Texture2D<RVec4> g_gbuffer1Tex;
-[[vk::binding(9)]] uniform Texture2D<RVec4> g_gbuffer2Tex;
-[[vk::binding(10)]] uniform Texture2D g_depthTex;
+[[vk::binding(7)]] Texture2D<RVec4> g_gbuffer0Tex;
+[[vk::binding(8)]] Texture2D<RVec4> g_gbuffer1Tex;
+[[vk::binding(9)]] Texture2D<RVec4> g_gbuffer2Tex;
+[[vk::binding(10)]] Texture2D g_depthTex;
 #if USE_SHADOW_LAYERS
-[[vk::binding(11)]] uniform Texture2D<UVec4> g_shadowLayersTex;
+[[vk::binding(11)]] Texture2D<UVec4> g_shadowLayersTex;
 #else
-[[vk::binding(12)]] uniform Texture2D<RVec4> g_resolvedShadowsTex;
+[[vk::binding(12)]] Texture2D<RVec4> g_resolvedShadowsTex;
 #endif
 
 // Common code for lighting
@@ -64,7 +64,7 @@ RVec3 main(Vec4 svPosition : SV_POSITION, Vec2 uv : TEXCOORD) : SV_TARGET0
 	Cluster cluster = getClusterFragCoord(Vec3(svPosition.xy, depth), kTileSize, kTileCount, kZSplitCount,
 										  g_clusteredShading.m_zSplitMagic.x, g_clusteredShading.m_zSplitMagic.y);
 
-	// return clusterHeatmap(cluster, 1u << kClusterObjectTypePointLight);
+	// return clusterHeatmap(cluster, 1u << (U32)ClusterObjectType::kPointLight);
 
 	// Decode GBuffer
 	GbufferInfo gbuffer = (GbufferInfo)0;