Browse Source

More work on the cornell box test

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
2998902a30

+ 3 - 2
README.md

@@ -76,7 +76,7 @@ To build the release version open `PowerShell` and type:
 Alternatively, recent Visual Studio versions support building CMake projects from inside the IDE:
 Alternatively, recent Visual Studio versions support building CMake projects from inside the IDE:
 
 
 - Open Visual Studio
 - Open Visual Studio
-- Choose the "open folder" option and navigate to AnKi's checkout
+- Choose the "open a local folder" option and open AnKi's root directory (where this README.md is located)
 - Visual Studio will automatically understand that AnKi is a CMake project and it will populate the CMake cache
 - Visual Studio will automatically understand that AnKi is a CMake project and it will populate the CMake cache
 - Press "build all"
 - Press "build all"
 
 
@@ -97,7 +97,8 @@ On Linux:
 
 
 	$./path/to/build/bin/sponza
 	$./path/to/build/bin/sponza
 
 
-On Windows just find the `sponza.exe` and execute it.
+On Windows just find the `sponza.exe` and execute it. It's preferable to run the samples from a terminal because that
+prints some information, including possible errors.
 
 
 4 Contributing
 4 Contributing
 ==============
 ==============

+ 6 - 0
docs/code_style.md

@@ -61,6 +61,12 @@ All **function and method names** should form a sentence with at least one verb.
 - All member variables have the `m_` prefix.
 - All member variables have the `m_` prefix.
 - All global variables have the `g_` prefix.
 - All global variables have the `g_` prefix.
 
 
+**Variables that act as a measure for quantity** should have the `count` suffix. Not `num` or `numberOf` or similar.
+
+	int appleCount = ...; // YES
+	int appleNum = ...;   // NO
+	int numApples = ...;  // NO
+
 C++ rules
 C++ rules
 =========
 =========
 
 

+ 1 - 1
shaders/GBufferGeneric.ankiprog

@@ -134,7 +134,7 @@ layout(set = 0, binding = 10, row_major, std140) readonly buffer b_ankiPrevFrame
 #if ANKI_INSTANCE_COUNT == 1
 #if ANKI_INSTANCE_COUNT == 1
 #	define INSTANCE_ID 0
 #	define INSTANCE_ID 0
 #else
 #else
-#	define INSTANCE_ID gl_InstanceID
+#	define INSTANCE_ID gl_InstanceIndex
 #endif
 #endif
 
 
 #pragma anki start vert
 #pragma anki start vert

+ 1 - 1
shaders/LensFlareSprite.ankiprog

@@ -25,7 +25,7 @@ void main()
 {
 {
 	const Vec2 position = UV_TO_NDC(Vec2(gl_VertexID & 1, gl_VertexID >> 1));
 	const Vec2 position = UV_TO_NDC(Vec2(gl_VertexID & 1, gl_VertexID >> 1));
 
 
-	const LensFlareSprite sprite = u_sprites[gl_InstanceID];
+	const LensFlareSprite sprite = u_sprites[gl_InstanceIndex];
 
 
 	// Write tex coords of the 2D array texture
 	// Write tex coords of the 2D array texture
 	out_uv = Vec3((position * 0.5) + 0.5, sprite.m_depthPad3.x);
 	out_uv = Vec3((position * 0.5) + 0.5, sprite.m_depthPad3.x);

+ 1 - 1
shaders/SceneDebug.ankiprog

@@ -33,7 +33,7 @@ void main()
 #if COLOR_TEXTURE == 1
 #if COLOR_TEXTURE == 1
 	out_uv = in_uv;
 	out_uv = in_uv;
 #endif
 #endif
-	gl_Position = u_mvp[gl_InstanceID] * Vec4(in_position, 1.0);
+	gl_Position = u_mvp[gl_InstanceIndex] * Vec4(in_position, 1.0);
 }
 }
 #pragma anki end
 #pragma anki end
 
 

+ 6 - 2
src/anki/shader_compiler/ShaderProgramParser.cpp

@@ -26,7 +26,6 @@ static const char* SHADER_HEADER = R"(#version 460 core
 #define ANKI_VENDOR_%s 1
 #define ANKI_VENDOR_%s 1
 
 
 #define gl_VertexID gl_VertexIndex
 #define gl_VertexID gl_VertexIndex
-#define gl_InstanceID gl_InstanceIndex
 
 
 #extension GL_EXT_control_flow_attributes : require
 #extension GL_EXT_control_flow_attributes : require
 #define ANKI_UNROLL [[unroll]]
 #define ANKI_UNROLL [[unroll]]
@@ -52,6 +51,10 @@ static const char* SHADER_HEADER = R"(#version 460 core
 #define ANKI_MAX_BINDLESS_TEXTURES %u
 #define ANKI_MAX_BINDLESS_TEXTURES %u
 #define ANKI_MAX_BINDLESS_IMAGES %u
 #define ANKI_MAX_BINDLESS_IMAGES %u
 
 
+#if %u
+#	extension GL_EXT_ray_tracing : enable
+#endif
+
 #define ANKI_BINDLESS_SET(set_) \
 #define ANKI_BINDLESS_SET(set_) \
 	layout(set = set_, binding = 0) uniform utexture2D u_bindlessTextures2dU32[ANKI_MAX_BINDLESS_TEXTURES]; \
 	layout(set = set_, binding = 0) uniform utexture2D u_bindlessTextures2dU32[ANKI_MAX_BINDLESS_TEXTURES]; \
 	layout(set = set_, binding = 0) uniform itexture2D u_bindlessTextures2dI32[ANKI_MAX_BINDLESS_TEXTURES]; \
 	layout(set = set_, binding = 0) uniform itexture2D u_bindlessTextures2dI32[ANKI_MAX_BINDLESS_TEXTURES]; \
@@ -755,7 +758,8 @@ void ShaderProgramParser::generateAnkiShaderHeader(const GpuDeviceCapabilities&
 												   StringAuto& header)
 												   StringAuto& header)
 {
 {
 	header.sprintf(SHADER_HEADER, caps.m_minorApiVersion, caps.m_majorApiVersion,
 	header.sprintf(SHADER_HEADER, caps.m_minorApiVersion, caps.m_majorApiVersion,
-				   GPU_VENDOR_STR[caps.m_gpuVendor].cstr(), limits.m_bindlessTextureCount, limits.m_bindlessImageCount);
+				   GPU_VENDOR_STR[caps.m_gpuVendor].cstr(), limits.m_bindlessTextureCount, limits.m_bindlessImageCount,
+				   U(caps.m_rayTracingEnabled));
 }
 }
 
 
 Error ShaderProgramParser::generateVariant(ConstWeakArray<MutatorValue> mutation,
 Error ShaderProgramParser::generateVariant(ConstWeakArray<MutatorValue> mutation,

+ 113 - 2
tests/gr/Gr.cpp

@@ -2728,13 +2728,13 @@ ANKI_TEST(Gr, RayGen)
 {
 {
 	COMMON_BEGIN();
 	COMMON_BEGIN();
 
 
-	const Bool useRayTracing = false; // gr->getDeviceCapabilities().m_rayTracingEnabled;
+	const Bool useRayTracing = gr->getDeviceCapabilities().m_rayTracingEnabled;
 	if(!useRayTracing)
 	if(!useRayTracing)
 	{
 	{
 		ANKI_TEST_LOGW("Ray tracing not supported");
 		ANKI_TEST_LOGW("Ray tracing not supported");
 	}
 	}
 
 
-	HeapAllocator<U8> alloc = {allocAligned, nullptr};
+	HeapAllocator<U8> alloc(allocAligned, nullptr);
 
 
 	// Create the raster programs
 	// Create the raster programs
 	ShaderProgramPtr rasterProg;
 	ShaderProgramPtr rasterProg;
@@ -2770,6 +2770,115 @@ void main()
 		rasterProg = createProgram(vertSrc, fragSrc, *gr);
 		rasterProg = createProgram(vertSrc, fragSrc, *gr);
 	}
 	}
 
 
+	ShaderProgramPtr rtProg;
+	if(useRayTracing)
+	{
+		const CString commonSrc = R"(
+struct PayLoad
+{
+	Vec3 m_color;
+};
+
+struct Material
+{
+	Vec3 m_diffuseColor;
+};
+
+struct Mesh
+{
+	U64 m_indexBufferPtr;
+	U64 m_positionBufferPtr;
+};
+
+struct Model
+{
+	Material m_mtl;
+	Mesh m_mesh;
+};
+
+layout(set = 0, binding = 0, scalar) buffer u_00
+{
+	Model m_models[];
+};
+)";
+
+		const CString chit0Src = R"(
+layout(location = 0) rayPayloadInEXT PayLoad payLoad;
+
+void main()
+{
+	payLoad.m_color = m_models[gl_InstanceID].m_mtl.m_diffuseColor;
+}
+)";
+
+		const CString chit1Src = R"(
+layout(location = 0) rayPayloadInEXT PayLoad payLoad;
+
+void main()
+{
+	Vec3 col;
+	switch(gl_PrimitiveID)
+	{
+	case 0:
+		col = Vec3(1.0, 0.0, 0.0);
+		break;
+	case 1:
+		col = Vec3(0.0, 1.0, 0.0);
+		break;
+	case 2:
+		col = Vec3(0.0, 0.0, 1.0);
+		break;
+	default:
+		col = Vec3(1.0, 0.0, 1.0);
+	}
+
+	payLoad.m_color = col;
+}
+)";
+
+		const CString missSrc = R"(
+layout(location = 0) rayPayloadInEXT PayLoad payLoad;
+
+void main()
+{
+	payLoad.m_color = Vec3(0.0);
+}
+)";
+
+		const CString rayGenSrc = R"(
+layout(set = 0, binding = 1) uniform accelerationStructureEXT u_tlas;
+layout(set = 0, binding = 2, rgba8) uniform image2D u_outImg;
+
+void main()
+{
+	imageStore(u_outImg, IVec2(gl_LaunchIDEXT.xy), Vec4(0.0));
+}
+		)";
+
+		ShaderPtr chit0Shader = createShader(StringAuto(alloc).sprintf("%s\n%s", commonSrc.cstr(), chit0Src.cstr()),
+											 ShaderType::CLOSEST_HIT, *gr);
+		ShaderPtr chit1Shader = createShader(StringAuto(alloc).sprintf("%s\n%s", commonSrc.cstr(), chit1Src.cstr()),
+											 ShaderType::CLOSEST_HIT, *gr);
+		ShaderPtr missShader =
+			createShader(StringAuto(alloc).sprintf("%s\n%s", commonSrc.cstr(), missSrc.cstr()), ShaderType::MISS, *gr);
+
+		ShaderPtr rayGenShader = createShader(StringAuto(alloc).sprintf("%s\n%s", commonSrc.cstr(), rayGenSrc.cstr()),
+											  ShaderType::RAY_GEN, *gr);
+
+		Array<RayTracingHitGroup, 2> hitGroups;
+		hitGroups[0].m_closestHitShader = chit0Shader;
+		hitGroups[1].m_closestHitShader = chit1Shader;
+
+		Array<ShaderPtr, 1> missShaders = {missShader};
+
+		ShaderProgramInitInfo inf;
+		inf.m_rayTracingShaders.m_hitGroups = hitGroups;
+		inf.m_rayTracingShaders.m_rayGenShader = rayGenShader;
+		inf.m_rayTracingShaders.m_missShaders = missShaders;
+
+		rtProg = gr->newShaderProgram(inf);
+	}
+
 	// Create geometry
 	// Create geometry
 	BufferPtr smallBoxVertBuffer, smallBoxIndexBuffer;
 	BufferPtr smallBoxVertBuffer, smallBoxIndexBuffer;
 	BufferPtr bigBoxVertBuffer, bigBoxIndexBuffer;
 	BufferPtr bigBoxVertBuffer, bigBoxIndexBuffer;
@@ -2791,6 +2900,7 @@ void main()
 	}
 	}
 
 
 	// Draw
 	// Draw
+#if 0
 	constexpr U32 ITERATIONS = 200;
 	constexpr U32 ITERATIONS = 200;
 	for(U i = 0; i < ITERATIONS; ++i)
 	for(U i = 0; i < ITERATIONS; ++i)
 	{
 	{
@@ -2870,6 +2980,7 @@ void main()
 			HighRezTimer::sleep(TICK - timer.getElapsedTime());
 			HighRezTimer::sleep(TICK - timer.getElapsedTime());
 		}
 		}
 	}
 	}
+#endif
 
 
 	COMMON_END();
 	COMMON_END();
 }
 }

+ 1 - 1
tests/shader_compiler/ShaderProgramCompiler.cpp

@@ -50,7 +50,7 @@ out gl_PerVertex
 
 
 void main()
 void main()
 {
 {
-	gl_Position = u_ankiPerInstance[gl_InstanceID].m_ankiMvp * u_mats[gl_InstanceID].m_mat * Vec4(gl_VertexID);
+	gl_Position = u_ankiPerInstance[gl_InstanceIndex].m_ankiMvp * u_mats[gl_InstanceIndex].m_mat * Vec4(gl_VertexID);
 }
 }
 #pragma anki end
 #pragma anki end