2
0
Эх сурвалжийг харах

Extended GPU params with a "set" field to match the Vulkan descriptor format better

BearishSun 9 жил өмнө
parent
commit
474d810214

+ 6 - 3
Source/BansheeCore/Include/BsGpuParamDesc.h

@@ -20,6 +20,7 @@ namespace BansheeEngine
 		GpuParamDataType type;
 
 		UINT32 paramBlockSlot;
+		UINT32 paramBlockSet;
 		UINT32 gpuMemOffset; /**< In multiples of 4 bytes, or index for parameters not in a buffer. */
 		UINT32 cpuMemOffset; /**< In multiples of 4 bytes. */
 	};
@@ -30,16 +31,18 @@ namespace BansheeEngine
 		String name;
 		GpuParamObjectType type;
 
-		UINT32 slot;
+		UINT32 slot; /** Slot within a set. Uniquely identifies bind location in the GPU pipeline, together with the set. */
+		UINT32 set; /** Uniquely identifies the bind location in the GPU pipeline, together with the slot. */
 	};
 
 	/**	Describes a GPU program parameter block (collection of GPU program data parameters). */
 	struct GpuParamBlockDesc
 	{
 		String name;
-		UINT32 slot;
+		UINT32 slot; /** Slot within a set. Uniquely identifies bind location in the GPU pipeline, together with the set. */
+		UINT32 set; /** Uniquely identifies the bind location in the GPU pipeline, together with the slot. */
 		UINT32 blockSize; /**< In multiples of 4 bytes. */
-		bool isShareable;
+		bool isShareable; /** True for blocks that can be shared between different GPU pipeline stages. */
 	};
 
 	/** Contains all parameter information for a GPU program, including data and object parameters, plus parameter blocks. */

+ 4 - 4
Source/BansheeCore/Source/BsAnimationManager.cpp

@@ -20,7 +20,7 @@ namespace BansheeEngine
 	{
 		mAnimationWorker = Task::create("Animation", std::bind(&AnimationManager::evaluateAnimation, this));
 
-		mDataReadyCount.store(0, std::memory_order_release);
+		mDataReadyCount.store(0);
 		mWorkerState.store(WorkerState::Inactive, std::memory_order_release);
 
 		mBlendShapeVertexDesc = VertexDataDesc::create();
@@ -468,7 +468,7 @@ namespace BansheeEngine
 
 		// Increments counter and ensures all writes are recorded
 		mWorkerState.store(WorkerState::DataReady, std::memory_order_release);
-		mDataReadyCount.fetch_add(1, std::memory_order_acq_rel);
+		mDataReadyCount.fetch_add(1);
 	}
 
 	void AnimationManager::waitUntilComplete()
@@ -476,7 +476,7 @@ namespace BansheeEngine
 		mAnimationWorker->wait();
 
 		// Read counter, and ensure all reads are done after writes on anim thread complete
-		INT32 dataReadyCount = mDataReadyCount.load(std::memory_order_acquire);
+		INT32 dataReadyCount = mDataReadyCount.load();
 
 		if (dataReadyCount > CoreThread::NUM_SYNC_BUFFERS)
 		{
@@ -488,7 +488,7 @@ namespace BansheeEngine
 		if (!mDataReady)
 			return;
 
-		mDataReadyCount.fetch_add(-1, std::memory_order_release);
+		mDataReadyCount.fetch_sub(1);
 		mPoseReadBufferIdx = (mPoseReadBufferIdx + 1) % CoreThread::NUM_SYNC_BUFFERS;
 	}
 

+ 5 - 4
Source/BansheeD3D11RenderAPI/Include/BsD3D11HLSLParamParser.h

@@ -20,11 +20,12 @@ namespace BansheeEngine
 		 * a set of input parameters.
 		 *
 		 * @param[in]	microcode	Compiled GPU program microcode to parse.
-		 * @param[in]	desc		Output object that will contain parameter descriptions.
-		 * @param[in]	inputParams	Output object that will contain a set of program input parameters. Can be null if not 
+		 * @param[in]	type		Type of the GPU program.
+		 * @param[out]	desc		Output object that will contain parameter descriptions.
+		 * @param[out]	inputParams	Output object that will contain a set of program input parameters. Can be null if not 
 		 *							required. Only relevant for vertex programs.
 		 */
-		void parse(ID3DBlob* microcode, GpuParamDesc& desc, List<VertexElement>* inputParams);
+		void parse(ID3DBlob* microcode, GpuProgramType type, GpuParamDesc& desc, List<VertexElement>* inputParams);
 
 	private:
 		/**
@@ -34,7 +35,7 @@ namespace BansheeEngine
 		void parseBuffer(ID3D11ShaderReflectionConstantBuffer* bufferReflection, GpuParamDesc& desc);
 
 		/**	Parses the resource description structure and stores it in the provided GPU params description object. */
-		void parseResource(D3D11_SHADER_INPUT_BIND_DESC& resourceDesc, GpuParamDesc& desc);
+		void parseResource(D3D11_SHADER_INPUT_BIND_DESC& resourceDesc, GpuProgramType type, GpuParamDesc& desc);
 
 		/**
 		 * Parses a variable with the specified type and variable description. Adds the variable in the provided GPU params

+ 12 - 9
Source/BansheeD3D11RenderAPI/Source/BsD3D11HLSLParamParser.cpp

@@ -8,7 +8,8 @@
 
 namespace BansheeEngine
 {
-	void D3D11HLSLParamParser::parse(ID3DBlob* microcode, GpuParamDesc& desc, List<VertexElement>* inputParams)
+	void D3D11HLSLParamParser::parse(ID3DBlob* microcode, GpuProgramType type, GpuParamDesc& desc, 
+		List<VertexElement>* inputParams)
 	{
 		const char* commentString = nullptr;
 		ID3DBlob* pIDisassembly = nullptr;
@@ -62,7 +63,7 @@ namespace BansheeEngine
 			if (FAILED(hr))
 				BS_EXCEPT(RenderingAPIException, "Cannot get resource binding desc with index: " + toString(i));
 
-			parseResource(bindingDesc, desc);
+			parseResource(bindingDesc, type, desc);
 		}
 
 		for(UINT32 i = 0; i < shaderDesc.ConstantBuffers; i++)
@@ -73,14 +74,11 @@ namespace BansheeEngine
 			parseBuffer(shaderReflectionConstantBuffer, desc);
 		}
 
-		// TODO - Parse:
-		//  - Tex arrays, RW tex arrays and MS textures
-		//	- UINT8, UINT and double values
-
 		shaderReflection->Release();
 	}
 
-	void D3D11HLSLParamParser::parseResource(D3D11_SHADER_INPUT_BIND_DESC& resourceDesc, GpuParamDesc& desc)
+	void D3D11HLSLParamParser::parseResource(D3D11_SHADER_INPUT_BIND_DESC& resourceDesc, GpuProgramType type, 
+		GpuParamDesc& desc)
 	{
 		for(UINT32 i = 0; i < resourceDesc.BindCount; i++)
 		{
@@ -89,6 +87,7 @@ namespace BansheeEngine
 				GpuParamBlockDesc blockDesc;
 				blockDesc.name = resourceDesc.Name;
 				blockDesc.slot = resourceDesc.BindPoint + i;
+				blockDesc.set = (UINT32)type;
 				blockDesc.blockSize = 0; // Calculated manually as we add parameters
 
 				if(strcmp(resourceDesc.Name, "$Globals") == 0 || strcmp(resourceDesc.Name, "$Param") == 0) // Special buffers, as defined by DX11 docs
@@ -103,6 +102,7 @@ namespace BansheeEngine
 				GpuParamObjectDesc memberDesc;
 				memberDesc.name = resourceDesc.Name;
 				memberDesc.slot = resourceDesc.BindPoint + i;
+				memberDesc.set = (UINT32)type;
 				memberDesc.type = GPOT_UNKNOWN;
 
 				switch(resourceDesc.Type)
@@ -202,7 +202,8 @@ namespace BansheeEngine
 		}
 	}
 
-	void D3D11HLSLParamParser::parseBuffer(ID3D11ShaderReflectionConstantBuffer* bufferReflection, GpuParamDesc& desc)
+	void D3D11HLSLParamParser::parseBuffer(ID3D11ShaderReflectionConstantBuffer* bufferReflection, 
+		GpuParamDesc& desc)
 	{
 		D3D11_SHADER_BUFFER_DESC constantBufferDesc;
 		HRESULT hr = bufferReflection->GetDesc(&constantBufferDesc);
@@ -238,11 +239,13 @@ namespace BansheeEngine
 		blockDesc.blockSize = constantBufferDesc.Size / 4;
 	}
 
-	void D3D11HLSLParamParser::parseVariable(D3D11_SHADER_TYPE_DESC& varTypeDesc, D3D11_SHADER_VARIABLE_DESC& varDesc, GpuParamDesc& desc, GpuParamBlockDesc& paramBlock)
+	void D3D11HLSLParamParser::parseVariable(D3D11_SHADER_TYPE_DESC& varTypeDesc, D3D11_SHADER_VARIABLE_DESC& varDesc, 
+		GpuParamDesc& desc, GpuParamBlockDesc& paramBlock)
 	{
 		GpuParamDataDesc memberDesc;
 		memberDesc.name = varDesc.Name;
 		memberDesc.paramBlockSlot = paramBlock.slot;
+		memberDesc.paramBlockSet = paramBlock.set;
 		memberDesc.arraySize = varTypeDesc.Elements == 0 ? 1 : varTypeDesc.Elements;
 		memberDesc.gpuMemOffset = varDesc.StartOffset / 4;
 		memberDesc.cpuMemOffset = varDesc.StartOffset / 4;

+ 2 - 0
Source/BansheeD3D11RenderAPI/Source/BsD3D11RenderAPI.cpp

@@ -1451,6 +1451,7 @@ namespace BansheeEngine
 		block.isShareable = true;
 		block.name = name;
 		block.slot = 0;
+		block.set = 0;
 
 		for (auto& param : params)
 		{
@@ -1500,6 +1501,7 @@ namespace BansheeEngine
 			}
 
 			param.paramBlockSlot = 0;
+			param.paramBlockSet = 0;
 		}
 
 		// Constant buffer size must always be a multiple of 16

+ 2 - 0
Source/BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -2610,6 +2610,7 @@ namespace BansheeEngine
 		block.isShareable = true;
 		block.name = name;
 		block.slot = 0;
+		block.set = 0;
 
 		for (auto& param : params)
 		{
@@ -2660,6 +2661,7 @@ namespace BansheeEngine
 			}
 
 			param.paramBlockSlot = 0;
+			param.paramBlockSet = 0;
 		}
 
 		// Constant buffer size must always be a multiple of 16

+ 10 - 2
Source/BansheeGLRenderAPI/Source/BsGLSLParamParser.cpp

@@ -122,7 +122,7 @@ namespace BansheeEngine
 		return false;
 	}
 
-	void GLSLParamParser::buildUniformDescriptions(GLuint glProgram, GpuParamDesc& returnParamDesc)
+	void GLSLParamParser::buildUniformDescriptions(GLuint glProgram, GpuProgramType type, GpuParamDesc& returnParamDesc)
 	{
 		// scan through the active uniforms and add them to the reference list
 		GLint maxBufferSize = 0;
@@ -138,6 +138,7 @@ namespace BansheeEngine
 
 		GpuParamBlockDesc newGlobalBlockDesc;
 		newGlobalBlockDesc.slot = 0;
+		newGlobalBlockDesc.set = (UINT32)type;
 		newGlobalBlockDesc.name = "BS_INTERNAL_Globals";
 		newGlobalBlockDesc.blockSize = 0;
 		newGlobalBlockDesc.isShareable = false;
@@ -157,6 +158,7 @@ namespace BansheeEngine
 
 			GpuParamBlockDesc newBlockDesc;
 			newBlockDesc.slot = index + 1;
+			newBlockDesc.set = (UINT32)type;
 			newBlockDesc.name = uniformName;
 			newBlockDesc.blockSize = 0;
 			newBlockDesc.isShareable = true;
@@ -311,10 +313,12 @@ namespace BansheeEngine
 				GpuParamObjectDesc samplerParam;
 				samplerParam.name = paramName;
 				samplerParam.slot = glGetUniformLocation(glProgram, uniformName);
+				samplerParam.set = (UINT32)type;
 
 				GpuParamObjectDesc textureParam;
 				textureParam.name = paramName;
 				textureParam.slot = samplerParam.slot;
+				textureParam.set = (UINT32)type;
 
 				switch (uniformType)
 				{
@@ -348,6 +352,7 @@ namespace BansheeEngine
 				GpuParamObjectDesc textureParam;
 				textureParam.name = paramName;
 				textureParam.slot = glGetUniformLocation(glProgram, uniformName);
+				textureParam.set = (UINT32)type;
 
 				switch (uniformType)
 				{
@@ -372,6 +377,7 @@ namespace BansheeEngine
 				GpuParamObjectDesc bufferParam;
 				bufferParam.name = paramName;
 				bufferParam.slot = glGetUniformLocation(glProgram, uniformName);
+				bufferParam.set = (UINT32)type;
 
 				if (uniformType == GL_IMAGE_BUFFER)
 					bufferParam.type = GPOT_RWSTRUCTURED_BUFFER;
@@ -406,8 +412,8 @@ namespace BansheeEngine
 					blockOffset = blockOffset / 4;
 
 					gpuParam.gpuMemOffset = blockOffset;
-
 					gpuParam.paramBlockSlot = blockIndex + 1; // 0 is reserved for globals
+					gpuParam.paramBlockSet = (UINT32)type;
 
 					String& blockName = blockSlotToName[gpuParam.paramBlockSlot];
 					GpuParamBlockDesc& curBlockDesc = returnParamDesc.paramBlocks[blockName];
@@ -419,6 +425,7 @@ namespace BansheeEngine
 				{
 					gpuParam.gpuMemOffset = glGetUniformLocation(glProgram, uniformName);
 					gpuParam.paramBlockSlot = 0;
+					gpuParam.paramBlockSet = (UINT32)type;
 					gpuParam.cpuMemOffset = globalBlockDesc.blockSize;
 
 					globalBlockDesc.blockSize = std::max(globalBlockDesc.blockSize, gpuParam.cpuMemOffset + gpuParam.arrayElementStride * gpuParam.arraySize);
@@ -447,6 +454,7 @@ namespace BansheeEngine
 					structDesc.gpuMemOffset = gpuParam.gpuMemOffset;
 					structDesc.cpuMemOffset = gpuParam.cpuMemOffset;
 					structDesc.paramBlockSlot = gpuParam.paramBlockSlot;
+					structDesc.paramBlockSet = gpuParam.paramBlockSet;
 				}
 
 				// Update struct with size of the new parameter

+ 3 - 2
Source/BansheeGLRenderAPI/Source/GLSL/include/BsGLSLParamParser.h

@@ -46,9 +46,10 @@ namespace BansheeEngine
 		 * uniforms.
 		 *
 		 * @param[in]	glProgram		OpenGL handle to the GPU program.
-		 * @param[in]	returnParamDesc	Output structure containing the parsed data.
+		 * @param[in]	type			Type of the GPU program we're parsing.
+		 * @param[out]	returnParamDesc	Output structure containing the parsed data.
 		 */
-		void buildUniformDescriptions(GLuint glProgram, GpuParamDesc& returnParamDesc);
+		void buildUniformDescriptions(GLuint glProgram, GpuProgramType type, GpuParamDesc& returnParamDesc);
 
 		/**
 		 * Parses a compiled OpenGL program and outputs vertex element list that describes input attributes to the program.

+ 1 - 1
Source/BansheeGLRenderAPI/Source/GLSL/src/BsGLSLGpuProgram.cpp

@@ -191,7 +191,7 @@ namespace BansheeEngine
 		if (mIsCompiled)
 		{
 			GLSLParamParser paramParser;
-			paramParser.buildUniformDescriptions(mGLHandle, *mParametersDesc);
+			paramParser.buildUniformDescriptions(mGLHandle, mProperties.getType(), *mParametersDesc);
 
 			if (mProperties.getType() == GPT_VERTEX_PROGRAM)
 			{