Преглед изворни кода

OpenGL fixing scissor/viewport binding for multiple render targets
Fixing matrix transpose when binding to a shader
Removing a nasty CPU-GPU sync point in OpenGL rendering code

BearishSun пре 9 година
родитељ
комит
149981331e

+ 7 - 6
Data/Raw/Editor/Includes/PickingAlphaCull.bslinc

@@ -136,13 +136,14 @@ Technique : base("PickingAlphaCull") =
 		
 		Fragment =
 		{
+			in vec4 normal;
+			in vec2 texcoord0;		
+		
 			uniform sampler2D mainTexture;
 			uniform vec4 colorIndex;
 			uniform float alphaCutoff;
-			in vec4 normal;
-			in vec2 texcoord0;
-			out vec4 normalsColor;
-			out vec4 fragColor;
+
+			out vec4[2] outColor;
 
 			void main()
 			{
@@ -150,8 +151,8 @@ Technique : base("PickingAlphaCull") =
 				if(color.a < alphaCutoff)
 					discard;
 					
-				normalsColor = (normal + vec4(1,1,1,0)) / 2;
-				fragColor = colorIndex;
+				outColor[0] = colorIndex;
+				outColor[1] = (normal + vec4(1,1,1,0)) / 2;	
 			}
 		};
 	};

+ 6 - 5
Data/Raw/Editor/Includes/PickingCull.bslinc

@@ -35,7 +35,7 @@ Technique : base("PickingCull") =
 			float4 main(
 				in float4 inPos : SV_Position,
 				in float4 inNorm : NORMAL,	
-				out float4 oNorm :SV_Target1
+				out float4 oNorm : SV_Target1
 			) : SV_Target0
 			{
 				oNorm = (inNorm + float4(1,1,1,0)) / 2;
@@ -107,14 +107,15 @@ Technique : base("PickingCull") =
 		Fragment =
 		{
 			in vec4 normal;
+
 			uniform vec4 colorIndex;
-			out vec4 normalsColor;
-			out vec4 fragColor;
+			
+			out vec4[2] outColor;
 
 			void main()
 			{
-				normalsColor = (normal + vec4(1,1,1,0)) / 2;
-				fragColor = colorIndex;
+				outColor[0] = colorIndex;
+				outColor[1] = (normal + vec4(1,1,1,0)) / 2;
 			}
 		};
 	};

+ 0 - 39
Data/Raw/Editor/Includes/SolidGizmo.bslinc

@@ -43,45 +43,6 @@ Technique : base("SolidGizmo") =
 	};
 };
 
-Technique : base("SolidGizmo") =
-{
-	Language = "HLSL9";
-	
-	Pass =
-	{
-		Vertex =
-		{
-			float4x4 matViewProj;
-
-			void main(
-				in float3 inPos : POSITION,	
-				in float3 inNormal : NORMAL,
-				in float4 inColor : COLOR0,	
-				out float4 oPosition : POSITION,
-				out float3 oNormal : NORMAL,
-				out float4 oColor : COLOR0)
-			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
-				oNormal = inNormal;
-				oColor = inColor;
-			}
-		};
-		
-		Fragment =
-		{
-			float4 viewDir;
-		
-			float4 main(float3 normal : NORMAL, float4 color : COLOR0) : COLOR0
-			{
-				float4 outColor = color * dot(normalize(normal), -viewDir);
-				outColor.a = color.a;
-				
-				return outColor;
-			}
-		};
-	};
-};
-
 Technique : base("SolidGizmo") =
 {
 	Language = "GLSL";

+ 0 - 5
Data/Raw/Editor/Shaders/SolidGizmo.bsl

@@ -5,11 +5,6 @@ Technique : inherits("SolidGizmo") =
 	Language = "HLSL11";
 };
 
-Technique : inherits("SolidGizmo") =
-{
-	Language = "HLSL9";
-};
-
 Technique : inherits("SolidGizmo") =
 {
 	Language = "GLSL";

+ 0 - 19
Data/Raw/Editor/Shaders/SolidHandle.bsl

@@ -20,25 +20,6 @@ Technique : inherits("SolidGizmo") =
 	};
 };
 
-Technique : inherits("SolidGizmo") =
-{
-	Language = "HLSL9";
-	
-	Pass =
-	{
-		DepthWrite = false;
-		DepthRead = false;
-		Stencil = true;
-		StencilOpFront = { KEEP, KEEP, INC, PASS };
-		
-		Target =
-		{
-			Blend = true;
-			Color = { SRCA, SRCIA, ADD };
-		};
-	};
-};
-
 Technique : inherits("SolidGizmo") =
 {
 	Language = "GLSL";

+ 1 - 1
Data/Raw/Engine/Shaders/PPEyeAdaptHistogram.bsl

@@ -141,7 +141,7 @@ Technique =
 			};
 		
 			uniform sampler2D gSceneColorTex;
-			layout (rgba32f) uniform image2D gOutputTex;
+			layout (rgba16f) uniform image2D gOutputTex;
 			
 			// Keep elements in this order as it ensures coalesced memory operations for non-random ops
 			shared float sharedData[NUM_BUCKETS][THREADGROUP_SIZE_X][THREADGROUP_SIZE_Y];

+ 3 - 3
Source/BansheeCore/Include/BsMultiRenderTexture.h

@@ -36,15 +36,15 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT MultiRenderTextureProperties : public RenderTargetProperties
 	{
 	public:
-		MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_DESC& desc);
-		MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_CORE_DESC& desc);
+		MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_DESC& desc, bool requiresFlipping);
+		MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_CORE_DESC& desc, bool requiresFlipping);
 		virtual ~MultiRenderTextureProperties() { }
 
 	protected:
 		friend class MultiRenderTextureCore;
 		friend class MultiRenderTexture;
 
-		void construct(const TextureProperties* props);
+		void construct(const TextureProperties* props, bool requiresFlipping);
 	};
 
 	/**

+ 1 - 1
Source/BansheeCore/Source/BsGpuParamsSet.cpp

@@ -869,7 +869,7 @@ namespace BansheeEngine
 					{
 						UINT32 arrayOffset = i * paramSize;
 						memcpy(&temp, data + arrayOffset, paramSize);
-						temp.transpose();
+						temp = temp.transpose();
 
 						paramBlock->write((paramInfo.offset + arrayOffset) * sizeof(UINT32), &temp, paramSize);
 					}

+ 7 - 6
Source/BansheeCore/Source/BsMultiRenderTexture.cpp

@@ -11,7 +11,7 @@
 
 namespace BansheeEngine
 {
-	MultiRenderTextureProperties::MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_DESC& desc)
+	MultiRenderTextureProperties::MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_DESC& desc, bool requiresFlipping)
 	{
 		for (size_t i = 0; i < desc.colorSurfaces.size(); i++)
 		{
@@ -20,14 +20,15 @@ namespace BansheeEngine
 			if (texture != nullptr)
 			{
 				const TextureProperties& texProps = texture->getProperties();
-				construct(&texProps);
+				construct(&texProps, requiresFlipping);
 
 				break;
 			}
 		}
 	}
 
-	MultiRenderTextureProperties::MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
+	MultiRenderTextureProperties::MultiRenderTextureProperties(const MULTI_RENDER_TEXTURE_CORE_DESC& desc, 
+		bool requiresFlipping)
 	{
 		for (size_t i = 0; i < desc.colorSurfaces.size(); i++)
 		{
@@ -36,14 +37,14 @@ namespace BansheeEngine
 			if (texture != nullptr)
 			{
 				const TextureProperties& texProps = texture->getProperties();
-				construct(&texProps);
+				construct(&texProps, requiresFlipping);
 
 				break;
 			}
 		}
 	}
 
-	void MultiRenderTextureProperties::construct(const TextureProperties* props)
+	void MultiRenderTextureProperties::construct(const TextureProperties* props, bool requiresFlipping)
 	{
 		if (props == nullptr)
 			return;
@@ -55,7 +56,7 @@ namespace BansheeEngine
 		mHwGamma = props->isHardwareGammaEnabled();
 		mMultisampleCount = props->getMultisampleCount();
 		mIsWindow = false;
-		mRequiresTextureFlipping = requiresTextureFlipping();
+		mRequiresTextureFlipping = requiresFlipping;
 	}
 
 	MultiRenderTextureCore::MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)

+ 2 - 2
Source/BansheeD3D11RenderAPI/Source/BsD3D11MultiRenderTexture.cpp

@@ -8,7 +8,7 @@
 namespace BansheeEngine
 {
 	D3D11MultiRenderTextureCore::D3D11MultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
-		:MultiRenderTextureCore(desc), mProperties(desc)
+		:MultiRenderTextureCore(desc), mProperties(desc, false)
 	{
 
 	}
@@ -49,6 +49,6 @@ namespace BansheeEngine
 	}
 
 	D3D11MultiRenderTexture::D3D11MultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
-		:MultiRenderTexture(desc), mProperties(desc)
+		:MultiRenderTexture(desc), mProperties(desc, false)
 	{ }
 }

+ 1 - 1
Source/BansheeEditor/Source/BsScenePicking.cpp

@@ -404,7 +404,7 @@ namespace BansheeEngine
 
 		if (rtProps.requiresTextureFlipping())
 		{
-			UINT32 vertOffset = outputPixelData->getHeight() - 1;
+			UINT32 vertOffset = outputPixelData->getHeight();
 
 			for (UINT32 y = maxHeight; y > (UINT32)position.y; y--)
 			{

+ 2 - 2
Source/BansheeGLRenderAPI/Source/BsGLMultiRenderTexture.cpp

@@ -6,7 +6,7 @@
 namespace BansheeEngine
 {
 	GLMultiRenderTextureCore::GLMultiRenderTextureCore(const MULTI_RENDER_TEXTURE_CORE_DESC& desc)
-		:MultiRenderTextureCore(desc), mFB(nullptr), mProperties(desc)
+		:MultiRenderTextureCore(desc), mFB(nullptr), mProperties(desc, true)
 	{ }
 
 	GLMultiRenderTextureCore::~GLMultiRenderTextureCore()
@@ -112,6 +112,6 @@ namespace BansheeEngine
 	}
 
 	GLMultiRenderTexture::GLMultiRenderTexture(const MULTI_RENDER_TEXTURE_DESC& desc)
-		:MultiRenderTexture(desc), mProperties(desc)
+		:MultiRenderTexture(desc), mProperties(desc, true)
 	{ }
 }

+ 3 - 3
Source/BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -245,7 +245,7 @@ namespace BansheeEngine
 		if (slot == 0)
 		{
 			UINT8* uniformBufferData = (UINT8*)bs_stack_alloc(buffer->getSize());
-			buffer->readFromGPU(uniformBufferData); // TODO - Don't read from GPU!? Just read the cached version
+			buffer->read(0, uniformBufferData, buffer->getSize());
 
 			bool hasBoundAtLeastOne = false;
 			for (auto iter = paramDesc.params.begin(); iter != paramDesc.params.end(); ++iter)
@@ -1154,7 +1154,7 @@ namespace BansheeEngine
 			x = mScissorLeft;
 
 			if (flipping)
-				y = targetHeight - mScissorBottom - 1;
+				y = targetHeight - mScissorBottom;
 			else
 				y = mScissorTop;
 
@@ -2250,7 +2250,7 @@ namespace BansheeEngine
 		if (rtProps.requiresTextureFlipping())
 		{
 			// Convert "upper-left" corner to "lower-left"
-			mViewportTop = rtProps.getHeight() - (mViewportTop + mViewportHeight) - 1;
+			mViewportTop = rtProps.getHeight() - (mViewportTop + mViewportHeight);
 		}
 
 		glViewport(mViewportLeft, mViewportTop, mViewportWidth, mViewportHeight);