Browse Source

Some renaming

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
ff22039048

+ 62 - 58
anki/resource/ShaderProgramResourceSystem.cpp

@@ -223,6 +223,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(CString cacheDir, Gr
 															DynamicArray<ShaderProgramRaytracingLibrary>& outLibs)
 {
 	ANKI_RESOURCE_LOGI("Creating ray tracing programs");
+	U32 rtProgramCount = 0;
 
 	// Gather the RT program fnames
 	StringListAuto rtPrograms(alloc);
@@ -552,85 +553,88 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(CString cacheDir, Gr
 	}
 
 	// Create the libraries
-	if(libs.getSize() == 0)
+	if(libs.getSize() != 0)
 	{
-		return Error::NONE;
-	}
-
-	outLibs.resize(alloc, libs.getSize());
-
-	for(U32 libIdx = 0; libIdx < libs.getSize(); ++libIdx)
-	{
-		ShaderProgramRaytracingLibrary& outLib = outLibs[libIdx];
-		Lib& inLib = libs[libIdx];
+		outLibs.resize(alloc, libs.getSize());
 
-		if(inLib.m_presentStages
-		   != (ShaderTypeBit::RAY_GEN | ShaderTypeBit::MISS | ShaderTypeBit::CLOSEST_HIT | ShaderTypeBit::ANY_HIT))
+		for(U32 libIdx = 0; libIdx < libs.getSize(); ++libIdx)
 		{
-			ANKI_RESOURCE_LOGE("The libray is missing shader shader types: %s", inLib.m_name.cstr());
-			return Error::USER_DATA;
-		}
-
-		// Sort because the expectation is that the miss shaders are organized based on ray type
-		std::sort(inLib.m_rayTypes.getBegin(), inLib.m_rayTypes.getEnd(),
-				  [](const RayType& a, const RayType& b) { return a.m_typeIndex < b.m_typeIndex; });
-
-		outLib.m_libraryName.create(alloc, inLib.m_name);
-		outLib.m_rayTypeCount = inLib.m_rayTypes.getSize();
+			ShaderProgramRaytracingLibrary& outLib = outLibs[libIdx];
+			Lib& inLib = libs[libIdx];
 
-		DynamicArrayAuto<RayTracingHitGroup> initInfoHitGroups(alloc);
-		DynamicArrayAuto<ShaderPtr> missShaders(alloc);
-
-		for(U32 rayTypeIdx = 0; rayTypeIdx < inLib.m_rayTypes.getSize(); ++rayTypeIdx)
-		{
-			const RayType& inRayType = inLib.m_rayTypes[rayTypeIdx];
-
-			if(inRayType.m_typeIndex != rayTypeIdx)
+			if(inLib.m_presentStages
+			   != (ShaderTypeBit::RAY_GEN | ShaderTypeBit::MISS | ShaderTypeBit::CLOSEST_HIT | ShaderTypeBit::ANY_HIT))
 			{
-				ANKI_RESOURCE_LOGE("Ray types are not contiguous for library: %s", inLib.m_name.cstr());
+				ANKI_RESOURCE_LOGE("The libray is missing shader shader types: %s", inLib.m_name.cstr());
 				return Error::USER_DATA;
 			}
 
-			// Add the hitgroups to the init info
-			for(U32 hitGroupIdx = 0; hitGroupIdx < inRayType.m_hitGroups.getSize(); ++hitGroupIdx)
-			{
-				const HitGroup& inHitGroup = inRayType.m_hitGroups[hitGroupIdx];
+			// Sort because the expectation is that the miss shaders are organized based on ray type
+			std::sort(inLib.m_rayTypes.getBegin(), inLib.m_rayTypes.getEnd(),
+					  [](const RayType& a, const RayType& b) { return a.m_typeIndex < b.m_typeIndex; });
 
-				outLib.m_groupHashToGroupIndex.emplace(alloc, inHitGroup.m_hitGroupHash, initInfoHitGroups.getSize());
+			outLib.m_libraryName.create(alloc, inLib.m_name);
+			outLib.m_rayTypeCount = inLib.m_rayTypes.getSize();
 
-				RayTracingHitGroup* infoHitGroup = initInfoHitGroups.emplaceBack();
-				if(inHitGroup.m_ahit != MAX_U32)
+			DynamicArrayAuto<RayTracingHitGroup> initInfoHitGroups(alloc);
+			DynamicArrayAuto<ShaderPtr> missShaders(alloc);
+
+			for(U32 rayTypeIdx = 0; rayTypeIdx < inLib.m_rayTypes.getSize(); ++rayTypeIdx)
+			{
+				const RayType& inRayType = inLib.m_rayTypes[rayTypeIdx];
+
+				if(inRayType.m_typeIndex != rayTypeIdx)
 				{
-					infoHitGroup->m_anyHitShader = inLib.m_shaders[inHitGroup.m_ahit].m_shader;
+					ANKI_RESOURCE_LOGE("Ray types are not contiguous for library: %s", inLib.m_name.cstr());
+					return Error::USER_DATA;
 				}
 
-				if(inHitGroup.m_chit != MAX_U32)
+				// Add the hitgroups to the init info
+				for(U32 hitGroupIdx = 0; hitGroupIdx < inRayType.m_hitGroups.getSize(); ++hitGroupIdx)
 				{
-					infoHitGroup->m_closestHitShader = inLib.m_shaders[inHitGroup.m_chit].m_shader;
+					const HitGroup& inHitGroup = inRayType.m_hitGroups[hitGroupIdx];
+
+					outLib.m_groupHashToGroupIndex.emplace(alloc, inHitGroup.m_hitGroupHash,
+														   initInfoHitGroups.getSize());
+
+					RayTracingHitGroup* infoHitGroup = initInfoHitGroups.emplaceBack();
+					if(inHitGroup.m_ahit != MAX_U32)
+					{
+						infoHitGroup->m_anyHitShader = inLib.m_shaders[inHitGroup.m_ahit].m_shader;
+					}
+
+					if(inHitGroup.m_chit != MAX_U32)
+					{
+						infoHitGroup->m_closestHitShader = inLib.m_shaders[inHitGroup.m_chit].m_shader;
+					}
 				}
+
+				// Add the miss shader
+				ANKI_ASSERT(inRayType.m_miss != MAX_U32);
+				missShaders.emplaceBack(inLib.m_shaders[inRayType.m_miss].m_shader);
 			}
 
-			// Add the miss shader
-			ANKI_ASSERT(inRayType.m_miss != MAX_U32);
-			missShaders.emplaceBack(inLib.m_shaders[inRayType.m_miss].m_shader);
-		}
+			// Program name
+			StringAuto progName(alloc, inLib.m_name);
+			char* cprogName = const_cast<char*>(progName.cstr());
+			if(progName.getLength() > MAX_GR_OBJECT_NAME_LENGTH)
+			{
+				cprogName[MAX_GR_OBJECT_NAME_LENGTH] = '\0';
+			}
 
-		// Program name
-		StringAuto progName(alloc, inLib.m_name);
-		char* cprogName = const_cast<char*>(progName.cstr());
-		if(progName.getLength() > MAX_GR_OBJECT_NAME_LENGTH)
-		{
-			cprogName[MAX_GR_OBJECT_NAME_LENGTH] = '\0';
-		}
+			// Create the program
+			ShaderProgramInitInfo inf(cprogName);
+			inf.m_rayTracingShaders.m_rayGenShader = inLib.m_rayGenShader;
+			inf.m_rayTracingShaders.m_missShaders = missShaders;
+			inf.m_rayTracingShaders.m_hitGroups = initInfoHitGroups;
+			outLib.m_program = gr.newShaderProgram(inf);
 
-		// Create the program
-		ShaderProgramInitInfo inf(cprogName);
-		inf.m_rayTracingShaders.m_rayGenShader = inLib.m_rayGenShader;
-		inf.m_rayTracingShaders.m_missShaders = missShaders;
-		inf.m_rayTracingShaders.m_hitGroups = initInfoHitGroups;
-		outLib.m_program = gr.newShaderProgram(inf);
+			++rtProgramCount;
+		}
 	}
 
+	ANKI_RESOURCE_LOGI("Created %u ray tracing programs", rtProgramCount);
+
 	return Error::NONE;
 }
 

+ 9 - 9
anki/shaders/RtShadowsHit.ankiprog

@@ -9,12 +9,12 @@
 #pragma anki mutator ALPHA_TEXTURE 0 1
 
 #include <anki/shaders/Common.glsl>
-#include <anki/shaders/include/Model.h>
+#include <anki/shaders/include/GpuModel.h>
 
 #if ALPHA_TEXTURE == 1
-layout(set = 0, binding = 0, scalar) buffer b_ankiModelInstances
+layout(set = 0, binding = 0, scalar) buffer b_ankiModels
 {
-	ModelInstance u_ankiModelInstances[];
+	GpuModel u_ankiModels[];
 };
 
 layout(set = 0, binding = 1) uniform sampler u_ankiGlobalSampler;
@@ -29,20 +29,20 @@ layout(location = 0) rayPayloadInEXT F32 g_payload;
 hitAttributeEXT vec2 g_attribs;
 
 ANKI_REF(U16Vec3, 2);
-ANKI_REF(Vertex, 4);
+ANKI_REF(GpuVertex, 4);
 
 void main()
 {
 #if ALPHA_TEXTURE == 1
-	const ModelInstance model = u_ankiModelInstances[nonuniformEXT(gl_InstanceID)];
-	const Mesh mesh = model.m_mesh;
+	const GpuModel model = u_ankiModels[nonuniformEXT(gl_InstanceID)];
+	const GpuMesh mesh = model.m_mesh;
 
 	const U32 offset = gl_PrimitiveID * ANKI_SIZEOF(U16Vec3);
 	const U16Vec3 indices = U16Vec3Ref(nonuniformEXT(mesh.m_indexBufferPtr + offset)).m_value;
 
-	const Vertex vert0 = VertexRef(mesh.m_vertexBufferPtr + indices[0] * SIZEOF_VERTEX).m_value;
-	const Vertex vert1 = VertexRef(mesh.m_vertexBufferPtr + indices[1] * SIZEOF_VERTEX).m_value;
-	const Vertex vert2 = VertexRef(mesh.m_vertexBufferPtr + indices[2] * SIZEOF_VERTEX).m_value;
+	const GpuVertex vert0 = GpuVertexRef(mesh.m_vertexBufferPtr + indices[0] * SIZEOF_GPU_VERTEX).m_value;
+	const GpuVertex vert1 = GpuVertexRef(mesh.m_vertexBufferPtr + indices[1] * SIZEOF_GPU_VERTEX).m_value;
+	const GpuVertex vert2 = GpuVertexRef(mesh.m_vertexBufferPtr + indices[2] * SIZEOF_GPU_VERTEX).m_value;
 
 	const Vec3 barycentrics = Vec3(1.0f - g_attribs.x - g_attribs.y, g_attribs.x, g_attribs.y);
 

+ 0 - 66
anki/shaders/include/Model.h

@@ -1,66 +0,0 @@
-// Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma once
-
-#include <anki/shaders/include/Common.h>
-
-ANKI_BEGIN_NAMESPACE
-
-const U32 UV_CHANNEL_0 = 0;
-const U32 UV_CHANNEL_COUNT = 1;
-
-struct Vertex
-{
-	U32 m_normal; // Packed in R10G10B10A2SNorm
-	U32 m_tangent; // Packed in R10G10B10A2SNorm
-	HVec2 m_uvs[UV_CHANNEL_COUNT];
-};
-
-const U32 SIZEOF_VERTEX = 4 * 3;
-
-struct Mesh
-{
-	U64 m_indexBufferPtr; // Points to a buffer of U16
-	U64 m_positionBufferPtr; // Points to a buffer of Vec3
-	U64 m_vertexBufferPtr; // Points to a buffer of Vertex
-	U32 m_indexCount;
-	U32 m_vertexCount;
-};
-
-const U32 TEXTURE_CHANNEL_DIFFUSE = 0;
-const U32 TEXTURE_CHANNEL_NORMAL = 1;
-const U32 TEXTURE_CHANNEL_ROUGHNESS_METALNESS = 2;
-const U32 TEXTURE_CHANNEL_EMISSION = 3;
-const U32 TEXTURE_CHANNEL_HEIGHT = 4;
-const U32 TEXTURE_CHANNEL_AUX_0 = 5;
-const U32 TEXTURE_CHANNEL_AUX_1 = 6;
-const U32 TEXTURE_CHANNEL_AUX_2 = 7;
-
-const U32 TEXTURE_CHANNEL_COUNT = 8;
-
-struct Material
-{
-	U16 m_textureIds[TEXTURE_CHANNEL_COUNT];
-	Vec3 m_diffuseColor;
-	Vec3 m_specularColor;
-	Vec3 m_emissiveColor;
-	F16 m_roughness;
-	F16 m_metalness;
-};
-
-struct ModelInstance
-{
-	Mesh m_mesh;
-	Material m_material;
-#if defined(__cplusplus)
-	F32 m_worldTransform[12];
-#else
-	Mat3x4 m_worldTransform;
-#endif
-	Mat3 m_worldRotation;
-};
-
-ANKI_END_NAMESPACE