Browse Source

Added compute dispatch flags.

Branimir Karadžić 11 years ago
parent
commit
1be040f2ab
6 changed files with 49 additions and 31 deletions
  1. 1 1
      include/bgfx.c99.h
  2. 1 1
      include/bgfx.h
  3. 6 0
      include/bgfxdefines.h
  4. 8 6
      src/bgfx.cpp
  5. 27 23
      src/bgfx_p.h
  6. 6 0
      src/renderer_d3d11.cpp

+ 1 - 1
include/bgfx.c99.h

@@ -1364,7 +1364,7 @@ BGFX_C_API void bgfx_set_image_from_frame_buffer(uint8_t _stage, bgfx_uniform_ha
 /**
  * Dispatch compute.
  */
-BGFX_C_API void bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ);
+BGFX_C_API void bgfx_dispatch(uint8_t _id, bgfx_program_handle_t _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags);
 
 /**
  *  Discard all previously set state for draw call.

+ 1 - 1
include/bgfx.h

@@ -1257,7 +1257,7 @@ namespace bgfx
 	void setImage(uint8_t _stage, UniformHandle _sampler, FrameBufferHandle _handle, uint8_t _attachment, TextureFormat::Enum _format, Access::Enum _access);
 
 	/// Dispatch compute.
-	void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX = 1, uint16_t _numY = 1, uint16_t _numZ = 1);
+	void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX = 1, uint16_t _numY = 1, uint16_t _numZ = 1, uint8_t _flags = BGFX_SUBMIT_EYE_FIRST);
 
 	/// Discard all previously set state for draw or compute call.
 	void discard();

+ 6 - 0
include/bgfxdefines.h

@@ -293,4 +293,10 @@
 #define BGFX_VIEW_NONE   UINT8_C(0x00)
 #define BGFX_VIEW_STEREO UINT8_C(0x01)
 
+///
+#define BGFX_SUBMIT_EYE_LEFT  UINT8_C(0x01)
+#define BGFX_SUBMIT_EYE_RIGHT UINT8_C(0x02)
+#define BGFX_SUBMIT_EYE_MASK  UINT8_C(0x03)
+#define BGFX_SUBMIT_EYE_FIRST BGFX_SUBMIT_EYE_LEFT
+
 #endif // BGFX_DEFINES_H_HEADER_GUARD

+ 8 - 6
src/bgfx.cpp

@@ -734,7 +734,7 @@ namespace bgfx
 		return m_num;
 	}
 
-	uint32_t Frame::dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ)
+	uint32_t Frame::dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags)
 	{
 		if (m_discard)
 		{
@@ -752,9 +752,11 @@ namespace bgfx
 
 		m_compute.m_matrix = m_draw.m_matrix;
 		m_compute.m_num    = m_draw.m_num;
-		m_compute.m_numX = bx::uint16_max(_numX, 1);
-		m_compute.m_numY = bx::uint16_max(_numY, 1);
-		m_compute.m_numZ = bx::uint16_max(_numZ, 1);
+		m_compute.m_numX   = bx::uint16_max(_numX, 1);
+		m_compute.m_numY   = bx::uint16_max(_numY, 1);
+		m_compute.m_numZ   = bx::uint16_max(_numZ, 1);
+		m_compute.m_submitFlags = _flags;
+
 		m_key.m_program = _handle.idx;
 		if (invalidHandle != m_key.m_program)
 		{
@@ -2782,10 +2784,10 @@ again:
 		s_ctx->setImage(_stage, _sampler, _handle, _attachment, _format, _access);
 	}
 
-	void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ)
+	void dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags)
 	{
 		BGFX_CHECK_MAIN_THREAD();
-		s_ctx->dispatch(_id, _handle, _numX, _numY, _numZ);
+		s_ctx->dispatch(_id, _handle, _numX, _numY, _numZ, _flags);
 	}
 
 	void discard()

+ 27 - 23
src/bgfx_p.h

@@ -1035,24 +1035,25 @@ namespace bgfx
 	{
 		void clear()
 		{
-			m_constBegin = 0;
-			m_constEnd   = 0;
-			m_flags = BGFX_STATE_DEFAULT;
-			m_stencil = packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT);
-			m_rgba = 0;
-			m_matrix = 0;
-			m_startIndex = 0;
-			m_numIndices = UINT32_MAX;
+			m_constBegin  = 0;
+			m_constEnd    = 0;
+			m_flags       = BGFX_STATE_DEFAULT;
+			m_stencil     = packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT);
+			m_rgba        = 0;
+			m_matrix      = 0;
+			m_startIndex  = 0;
+			m_numIndices  = UINT32_MAX;
 			m_startVertex = 0;
 			m_numVertices = UINT32_MAX;
 			m_instanceDataOffset = 0;
 			m_instanceDataStride = 0;
-			m_numInstances = 1;
-			m_num = 1;
+			m_numInstances       = 1;
+			m_num     = 1;
+			m_flags   = BGFX_SUBMIT_EYE_FIRST;
 			m_scissor = UINT16_MAX;
-			m_vertexBuffer.idx = invalidHandle;
-			m_vertexDecl.idx = invalidHandle;
-			m_indexBuffer.idx = invalidHandle;
+			m_vertexBuffer.idx       = invalidHandle;
+			m_vertexDecl.idx         = invalidHandle;
+			m_indexBuffer.idx        = invalidHandle;
 			m_instanceDataBuffer.idx = invalidHandle;
 
 			for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii)
@@ -1077,6 +1078,7 @@ namespace bgfx
 		uint16_t m_numInstances;
 		uint16_t m_num;
 		uint16_t m_scissor;
+		uint8_t  m_submitFlags;
 
 		VertexBufferHandle m_vertexBuffer;
 		VertexDeclHandle   m_vertexDecl;
@@ -1106,13 +1108,14 @@ namespace bgfx
 	{
 		void clear()
 		{
-			m_constBegin = 0;
-			m_constEnd   = 0;
-			m_matrix     = 0;
-			m_numX = 0;
-			m_numY = 0;
-			m_numZ = 0;
-			m_num  = 0;
+			m_constBegin  = 0;
+			m_constEnd    = 0;
+			m_matrix      = 0;
+			m_numX        = 0;
+			m_numY        = 0;
+			m_numZ        = 0;
+			m_num         = 0;
+			m_submitFlags = BGFX_SUBMIT_EYE_FIRST;
 
 			for (uint32_t ii = 0; ii < BGFX_MAX_COMPUTE_BINDINGS; ++ii)
 			{
@@ -1128,6 +1131,7 @@ namespace bgfx
 		uint16_t m_numY;
 		uint16_t m_numZ;
 		uint16_t m_num;
+		uint8_t  m_submitFlags;
 
 		ComputeBinding m_bind[BGFX_MAX_COMPUTE_BINDINGS];
 	};
@@ -1419,7 +1423,7 @@ namespace bgfx
 		}
 
 		uint32_t submit(uint8_t _id, int32_t _depth);
-		uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _ngx, uint16_t _ngy, uint16_t _ngz);
+		uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _ngx, uint16_t _ngy, uint16_t _ngz, uint8_t _flags);
 		void sort();
 
 		bool checkAvailTransientIndexBuffer(uint32_t _num)
@@ -3047,9 +3051,9 @@ namespace bgfx
 			setImage(_stage, _sampler, textureHandle, 0, _format, _access);
 		}
 
-		BGFX_API_FUNC(uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ) )
+		BGFX_API_FUNC(uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _numX, uint16_t _numY, uint16_t _numZ, uint8_t _flags) )
 		{
-			return m_submit->dispatch(_id, _handle, _numX, _numY, _numZ);
+			return m_submit->dispatch(_id, _handle, _numX, _numY, _numZ, _flags);
 		}
 
 		BGFX_API_FUNC(void discard() )

+ 6 - 0
src/renderer_d3d11.cpp

@@ -3157,6 +3157,12 @@ namespace bgfx
 
 					const RenderCompute& compute = renderItem.compute;
 
+					if (0 != eye
+					&&  BGFX_SUBMIT_EYE_LEFT == (compute.m_submitFlags&BGFX_SUBMIT_EYE_MASK) )
+					{
+						continue;
+					}
+
 					bool programChanged = false;
 					bool constantsChanged = compute.m_constBegin < compute.m_constEnd;
 					rendererUpdateUniforms(this, _render->m_constantBuffer, compute.m_constBegin, compute.m_constEnd);