Selaa lähdekoodia

Some compute support

Panagiotis Christopoulos Charitos 10 vuotta sitten
vanhempi
sitoutus
5ce5fd358e

+ 2 - 0
include/anki/gr/CommandBufferHandle.h

@@ -137,6 +137,8 @@ public:
 	void drawArraysConditional(OcclusionQueryHandle& query,
 	void drawArraysConditional(OcclusionQueryHandle& query,
 		GLenum mode, U32 count, U32 instanceCount = 1,
 		GLenum mode, U32 count, U32 instanceCount = 1,
 		U32 first = 0, U32 baseInstance = 0);
 		U32 first = 0, U32 baseInstance = 0);
+
+	void dispatchCompute(U32 groupCountX, U32 groupCountY, U32 groupCountZ);
 	/// @}
 	/// @}
 
 
 	/// @name Other operations
 	/// @name Other operations

+ 3 - 3
include/anki/gr/Common.h

@@ -36,9 +36,10 @@ class ShaderImpl;
 class ShaderHandle;
 class ShaderHandle;
 class PipelineImpl;
 class PipelineImpl;
 class PipelineHandle;
 class PipelineHandle;
-struct PipelineInitializer;
+class PipelineInitializer;
 class FramebufferImpl;
 class FramebufferImpl;
 class FramebufferHandle;
 class FramebufferHandle;
+class FramebufferInitializer;
 class TextureImpl;
 class TextureImpl;
 class TextureHandle;
 class TextureHandle;
 class SamplerImpl;
 class SamplerImpl;
@@ -51,10 +52,9 @@ class ResourceGroupImpl;
 class ResourceGroupHandle;
 class ResourceGroupHandle;
 class GrManager;
 class GrManager;
 class GrManagerImpl;
 class GrManagerImpl;
-struct FramebufferInitializer;
 class TextureInitializer;
 class TextureInitializer;
 class SamplerInitializer;
 class SamplerInitializer;
-struct GrManagerInitializer;
+class GrManagerInitializer;
 
 
 /// @addtogroup graphics_private
 /// @addtogroup graphics_private
 /// @{
 /// @{

+ 9 - 8
include/anki/gr/GrManager.h

@@ -15,17 +15,18 @@ namespace anki {
 /// @{
 /// @{
 
 
 /// Manager initializer.
 /// Manager initializer.
-struct GrManagerInitializer
+class GrManagerInitializer
 {
 {
-	AllocAlignedCallback m_allocCallback; 
-	void* m_allocCallbackUserData;
+public:
+	AllocAlignedCallback m_allocCallback = nullptr; 
+	void* m_allocCallbackUserData = nullptr;
 
 
-	MakeCurrentCallback m_makeCurrentCallback;
-	void* m_makeCurrentCallbackData;
-	void* m_ctx;
+	MakeCurrentCallback m_makeCurrentCallback = nullptr;
+	void* m_makeCurrentCallbackData = nullptr;
+	void* m_ctx = nullptr;
 
 
-	SwapBuffersCallback m_swapBuffersCallback;
-	void* m_swapBuffersCallbackData;
+	SwapBuffersCallback m_swapBuffersCallback = nullptr;
+	void* m_swapBuffersCallbackData = nullptr;
 
 
 	CString m_cacheDirectory;
 	CString m_cacheDirectory;
 	Bool m_registerDebugMessages = false;
 	Bool m_registerDebugMessages = false;

+ 2 - 1
include/anki/gr/PipelineCommon.h

@@ -98,8 +98,9 @@ enum class SubStateBit: U16
 ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(SubStateBit, inline)
 ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(SubStateBit, inline)
 
 
 /// Pipeline initializer.
 /// Pipeline initializer.
-struct PipelineInitializer
+class PipelineInitializer
 {
 {
+public:
 	VertexStateInfo m_vertex;
 	VertexStateInfo m_vertex;
 	InputAssemblerStateInfo m_inputAssembler;
 	InputAssemblerStateInfo m_inputAssembler;
 	TessellationStateInfo m_tessellation;
 	TessellationStateInfo m_tessellation;

+ 7 - 4
include/anki/gr/gl/PipelineImpl.h

@@ -39,22 +39,25 @@ public:
 	void bind();
 	void bind();
 
 
 private:
 private:
-	struct Attribute
+	class Attribute
 	{
 	{
+	public:
+		GLenum m_type = 0;
 		U8 m_compCount = 0;
 		U8 m_compCount = 0;
 		Bool8 m_normalized = false;
 		Bool8 m_normalized = false;
-		GLenum m_type = 0;
 	};
 	};
 
 
-	struct Attachment
+	class Attachment
 	{
 	{
+	public:
 		GLenum m_srcBlendMethod = GL_ONE;
 		GLenum m_srcBlendMethod = GL_ONE;
 		GLenum m_dstBlendMethod = GL_ZERO;
 		GLenum m_dstBlendMethod = GL_ZERO;
 		GLenum m_blendFunction = GL_ADD;
 		GLenum m_blendFunction = GL_ADD;
 		Array<Bool8, 4> m_channelWriteMask;
 		Array<Bool8, 4> m_channelWriteMask;
 	};
 	};
 
 
-	Bool m_complete;
+	Bool8 m_complete;
+	Bool8 m_compute = false; ///< Is compute
 
 
 	// Cached values
 	// Cached values
 	Array<Attribute, MAX_VERTEX_ATTRIBUTES> m_attribs;
 	Array<Attribute, MAX_VERTEX_ATTRIBUTES> m_attribs;

+ 1 - 1
shaders/PpsHdr.frag.glsl

@@ -45,7 +45,7 @@ void main()
 	color += readTexture(MIPMAP - 1);
 	color += readTexture(MIPMAP - 1);
 	color += readTexture(MIPMAP - 2);
 	color += readTexture(MIPMAP - 2);
 	
 	
-	color /= 2.0;
+	color /= 3.0;
 
 
 #if 1
 #if 1
 	float luminance = dot(vec3(0.30, 0.59, 0.11), color);
 	float luminance = dot(vec3(0.30, 0.59, 0.11), color);

+ 24 - 0
src/gr/gl/CommandBufferHandle.cpp

@@ -654,4 +654,28 @@ void CommandBufferHandle::copyTextureToBuffer(
 	get().pushBackNewCommand<CopyBuffTex>(from, to);
 	get().pushBackNewCommand<CopyBuffTex>(from, to);
 }
 }
 
 
+//==============================================================================
+class DispatchCommand: public GlCommand
+{
+public:
+	Array<U32, 3> m_size;
+
+	DispatchCommand(U32 x, U32 y, U32 z)
+	:	m_size({x, y, z})
+	{}
+
+	Error operator()(CommandBufferImpl*)
+	{
+		glDispatchCompute(m_size[0], m_size[1], m_size[2]);
+		return ErrorCode::NONE;
+	}
+};
+
+void CommandBufferHandle::dispatchCompute(
+	U32 groupCountX, U32 groupCountY, U32 groupCountZ)
+{
+	get().pushBackNewCommand<DispatchCommand>(
+		groupCountX, groupCountY, groupCountZ);
+}
+
 } // end namespace anki
 } // end namespace anki

+ 13 - 5
src/gr/gl/PipelineImpl.cpp

@@ -123,11 +123,14 @@ Error PipelineImpl::create(const Initializer& init)
 	}
 	}
 
 
 	ANKI_CHECK(createGlPipeline());
 	ANKI_CHECK(createGlPipeline());
-	initVertexState();
-	initInputAssemblerState();
-	initRasterizerState();
-	initDepthStencilState();
-	initColorState();
+	if(!m_compute)
+	{
+		initVertexState();
+		initInputAssemblerState();
+		initRasterizerState();
+		initDepthStencilState();
+		initColorState();
+	}
 
 
 	return ErrorCode::NONE;
 	return ErrorCode::NONE;
 }
 }
@@ -164,11 +167,15 @@ Error PipelineImpl::createGlPipeline()
 	{
 	{
 		// Is compute
 		// Is compute
 
 
+		m_compute = true;
+
 		ANKI_ASSERT((mask & (1 << 5)) == (1 << 5) 
 		ANKI_ASSERT((mask & (1 << 5)) == (1 << 5) 
 			&& "Compute should be alone in the pipeline");
 			&& "Compute should be alone in the pipeline");
 	}
 	}
 	else
 	else
 	{
 	{
+		m_compute = false;
+
 		const U fragVert = (1 << 0) | (1 << 4);
 		const U fragVert = (1 << 0) | (1 << 4);
 		ANKI_ASSERT((mask & fragVert) && "Should contain vert and frag");
 		ANKI_ASSERT((mask & fragVert) && "Should contain vert and frag");
 		(void)fragVert;
 		(void)fragVert;
@@ -234,6 +241,7 @@ void PipelineImpl::bind()
 	ANKI_ASSERT(isCreated());
 	ANKI_ASSERT(isCreated());
 	glBindProgramPipeline(m_glName);
 	glBindProgramPipeline(m_glName);
 #else
 #else
+	// TODO check compute
 	ANKI_ASSERT(m_complete && "Should be complete");
 	ANKI_ASSERT(m_complete && "Should be complete");
 
 
 	// Get last pipeline
 	// Get last pipeline

+ 1 - 0
src/gr/gl/ShaderImpl.cpp

@@ -93,6 +93,7 @@ Error ShaderImpl::create(ShaderType type, const CString& source)
 
 
 		File file;
 		File file;
 		ANKI_CHECK(file.open(fname.toCString(), File::OpenFlag::WRITE));
 		ANKI_CHECK(file.open(fname.toCString(), File::OpenFlag::WRITE));
+		ANKI_CHECK(file.writeText("%s", &fname[0]));
 	}
 	}
 #endif
 #endif