Browse Source

Minor RT additions

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
6dd0f75015

+ 1 - 0
src/anki/gr/AccelerationStructure.h

@@ -67,6 +67,7 @@ class AccelerationStructureInstance
 public:
 	AccelerationStructurePtr m_bottomLevel;
 	Mat3x4 m_transform = Mat3x4::getIdentity();
+	U32 m_stbRecordIndex = 0; ///< Points to the STB record.
 };
 
 /// @memberof AccelerationStructureInitInfo

+ 14 - 10
src/anki/gr/Common.h

@@ -38,17 +38,15 @@ class AccelerationStructureInitInfo;
 #define ANKI_GR_LOGF(...) ANKI_LOG("GR  ", FATAL, __VA_ARGS__)
 
 // Some constants
-const U32 MAX_VERTEX_ATTRIBUTES = 8;
-const U32 MAX_COLOR_ATTACHMENTS = 4;
-const U32 MAX_DESCRIPTOR_SETS = 2; ///< Groups that can be bound at the same time.
-const U32 MAX_BINDINGS_PER_DESCRIPTOR_SET = 32;
-
-const U32 MAX_FRAMES_IN_FLIGHT = 3; ///< Triple buffering.
-
-const U32 MAX_GR_OBJECT_NAME_LENGTH = 31;
+constexpr U32 MAX_VERTEX_ATTRIBUTES = 8;
+constexpr U32 MAX_COLOR_ATTACHMENTS = 4;
+constexpr U32 MAX_DESCRIPTOR_SETS = 2; ///< Groups that can be bound at the same time.
+constexpr U32 MAX_BINDINGS_PER_DESCRIPTOR_SET = 32;
+constexpr U32 MAX_FRAMES_IN_FLIGHT = 3; ///< Triple buffering.
+constexpr U32 MAX_GR_OBJECT_NAME_LENGTH = 31;
 
 /// The number of commands in a command buffer that make it a small batch command buffer.
-const U32 COMMAND_BUFFER_SMALL_BATCH_MAX_COMMANDS = 100;
+constexpr U32 COMMAND_BUFFER_SMALL_BATCH_MAX_COMMANDS = 100;
 
 /// Smart pointer for resources.
 template<typename T>
@@ -136,6 +134,12 @@ public:
 	/// Max push constant size.
 	PtrSize m_pushConstantsSize = 128;
 
+	/// The size and alignment of an STB record.
+	U32 m_stbRecordSize = 0;
+
+	/// The size of a shader group handle that will be placed inside an STB record.
+	U32 m_shaderGroupHandleSize = 0;
+
 	/// GPU vendor.
 	GpuVendor m_gpuVendor = GpuVendor::UNKNOWN;
 
@@ -149,7 +153,7 @@ public:
 	Bool m_rayTracingEnabled = false;
 };
 ANKI_END_PACKED_STRUCT
-static_assert(sizeof(GpuDeviceCapabilities) == sizeof(PtrSize) * 4 + sizeof(U32) * 3 + sizeof(U8) * 3 + sizeof(Bool),
+static_assert(sizeof(GpuDeviceCapabilities) == sizeof(PtrSize) * 4 + sizeof(U32) * 5 + sizeof(U8) * 3 + sizeof(Bool),
 			  "Should be packed");
 
 /// Bindless related info.

+ 1 - 1
src/anki/gr/Enums.h

@@ -612,7 +612,7 @@ enum class BufferUsageBit : U64
 	TRANSFER_SOURCE = 1ull << 25ull,
 	TRANSFER_DESTINATION = 1ull << 26ull,
 
-	ACCELERATION_STRUCTURE_BUILD = 1ull << 27ull,
+	ACCELERATION_STRUCTURE_BUILD = 1ull << 27ull, ///< Will be used as a position or index buffer in a BLAS build.
 
 	// Derived
 	ALL_UNIFORM = UNIFORM_GEOMETRY | UNIFORM_FRAGMENT | UNIFORM_COMPUTE | UNIFORM_TRACE_RAYS,

+ 1 - 1
src/anki/gr/vulkan/AccelerationStructureImpl.cpp

@@ -193,7 +193,7 @@ void AccelerationStructureImpl::initBuildInfo()
 				memcpy(&outInst.transform.matrix[0][0], &inInst.m_transform, sizeof(inInst.m_transform));
 				outInst.instanceCustomIndex = i & 0xFFFFFF;
 				outInst.mask = 0xFF;
-				outInst.instanceShaderBindingTableRecordOffset = 0;
+				outInst.instanceShaderBindingTableRecordOffset = inInst.m_stbRecordIndex & 0xFFFFFF;
 				outInst.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_KHR;
 				outInst.accelerationStructureReference =
 					static_cast<const AccelerationStructureImpl&>(*inInst.m_bottomLevel).m_bottomLevelInfo.m_gpuAddress;

+ 3 - 0
src/anki/gr/vulkan/GrManagerImpl.cpp

@@ -429,6 +429,9 @@ Error GrManagerImpl::initInstance(const GrManagerInitInfo& init)
 	m_capabilities.m_majorApiVersion = vulkanMajor;
 	m_capabilities.m_minorApiVersion = vulkanMinor;
 
+	m_capabilities.m_shaderGroupHandleSize = m_rtProps.shaderGroupHandleSize;
+	m_capabilities.m_stbRecordSize = m_rtProps.shaderGroupBaseAlignment;
+
 	return Error::NONE;
 }