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

Vulkan up and running on the unified shader platform

BearishSun 8 жил өмнө
parent
commit
775b9c4431

+ 3 - 2
Data/Raw/Engine/Includes/NormalVertexInput.bslinc

@@ -72,8 +72,9 @@ Technique
 				float3x3 tangentToLocal = getTangentToLocal(input, tangentSign);
 				float3x3 tangentToWorld = mul((float3x3)gMatWorldNoScale, tangentToLocal);
 				
-				result.worldNormal = float3(tangentToWorld._m02_m12_m22); // Normal basis vector
-				result.worldTangent = float4(tangentToWorld._m00_m10_m20, tangentSign); // Tangent basis vector
+				// Note: Consider transposing these externally, for easier reads
+				result.worldNormal = float3(tangentToWorld[0][2], tangentToWorld[1][2], tangentToWorld[2][2]); // Normal basis vector
+				result.worldTangent = float4(tangentToWorld[0][0], tangentToWorld[1][0], tangentToWorld[2][0], tangentSign); // Tangent basis vector
 				
 				return result;
 			}

+ 5 - 1
Data/Raw/Engine/Includes/ResolveCommon.bslinc

@@ -47,7 +47,11 @@ Technique =
 		{
 			#ifdef ENABLE_MSAA
 			
-			int gNumSamples;
+			cbuffer FragParams
+			{
+				int gNumSamples;
+			};
+			
 			Texture2DMS<float4> gSource : register(t0);
 			
 			float4 main(VStoFS input) : SV_Target0

+ 3 - 2
Data/Raw/Engine/Includes/SkinnedVertexInput.bslinc

@@ -106,8 +106,9 @@ Technique
 				float3x3 tangentToLocal = getSkinnedTangentToLocal(input, result.blendMatrix, tangentSign);
 				float3x3 tangentToWorld = mul((float3x3)gMatWorldNoScale, tangentToLocal);
 				
-				result.worldNormal = float3(tangentToWorld._m02_m12_m22); // Normal basis vector
-				result.worldTangent = float4(tangentToWorld._m00_m10_m20, tangentSign); // Tangent basis vector
+				// Note: Consider transposing these externally, for easier reads
+				result.worldNormal = float3(tangentToWorld[0][2], tangentToWorld[1][2], tangentToWorld[2][2]); // Normal basis vector
+				result.worldTangent = float4(tangentToWorld[0][0], tangentToWorld[1][0], tangentToWorld[2][0], tangentSign); // Tangent basis vector
 				
 				return result;
 			}

+ 11 - 5
Data/Raw/Engine/Shaders/SpriteLine.bsl

@@ -34,10 +34,13 @@ Technique =
 		
 		Vertex =
 		{
-			float invViewportWidth;
-			float invViewportHeight;
-			float4x4 worldTransform;
-
+			cbuffer VertParams
+			{
+				float invViewportWidth;
+				float invViewportHeight;
+				float4x4 worldTransform;
+			};
+			
 			struct VertexInput
 			{
 				float2 position : POSITION;
@@ -59,7 +62,10 @@ Technique =
 		
 		Fragment =
 		{
-			float4 tint;
+			cbuffer VertParams
+			{
+				float4 tint;
+			};
 			
 			float4 main(VStoFS input) : SV_Target
 			{

+ 13 - 6
Data/Raw/Engine/Shaders/TestFX.bsl

@@ -145,10 +145,13 @@ Technique =
 		
 		Vertex = 
 		{
-			float invViewportWidth;
-			float invViewportHeight;
-			float4x4 worldTransform;
-
+			cbuffer VertParams
+			{
+				float invViewportWidth;
+				float invViewportHeight;
+				float4x4 worldTransform;
+			};
+			
 			void main(
 			in float3 inPos : POSITION,
 			in float2 uv : TEXCOORD0,
@@ -169,8 +172,12 @@ Technique =
 		{
 			SamplerState mainTexSamp : register(s0);
 			Texture2D mainTexture : register(t0);
-			float4 tint;
-
+			
+			cbuffer FragParams
+			{
+				float4 tint;
+			};
+			
 			float4 main(in float4 inPos : SV_Position, float2 uv : TEXCOORD0) : SV_Target
 			{
 				float4 color = mainTexture.Sample(mainTexSamp, uv);

+ 6 - 5
Documentation/GitHub/features.md

@@ -10,14 +10,15 @@ All features listed here are the ones currently available (implemented). If you
   * Clean layered design
   * Fully documented
   * Modular & plugin based
-  * Minimal third-party dependencies
   * Multiplatform ready
 * __Renderer__
-  * Vulkan, DX11 and OpenGL 4.5 render systems
+  * Vulkan, DX11 and OpenGL 4.5 render backends
   * Multi-threaded rendering
-  * Powerful material system
-    * BansheeFX language for material definitions
-    * Shader parsing for HLSL9, HLSL11 and GLSL
+  * Banshee Shading Language
+    * Unified shader code across all render backends
+	* Complete material definition in a single file
+	* High level concepts like mixins and overloads
+    * Low level shader parsing and reflection for HLSL and GLSL
 * __Asset pipeline__
   * Asynchronous resource loading
   * Extensible importer system

+ 0 - 1
Documentation/GitHub/roadmap.md

@@ -17,7 +17,6 @@ Following 1.0 release the focus will be on following features (in no specific or
  - High level networking (replication, RPCs)
  - Effects/Particle editor
  - Terrain system
- - Unified shading language
  - Visual GUI editor 
  
 And more to come after that:

+ 3 - 3
Source/BansheeSL/Source/BsSLFXCompiler.cpp

@@ -82,13 +82,13 @@ namespace bs
 		{
 			switch (report.Type())
 			{
-			case Xsc::Report::Types::Info:
+			case Xsc::ReportTypes::Info:
 				mInfos.push_back({ FullIndent(), report });
 				break;
-			case Xsc::Report::Types::Warning:
+			case Xsc::ReportTypes::Warning:
 				mWarnings.push_back({ FullIndent(), report });
 				break;
-			case Xsc::Report::Types::Error:
+			case Xsc::ReportTypes::Error:
 				mErrors.push_back({ FullIndent(), report });
 				break;
 			}

+ 2 - 2
Source/BansheeVulkanRenderAPI/Source/BsVulkanGLSLProgramFactory.cpp

@@ -8,7 +8,7 @@
 
 namespace bs { namespace ct
 {
-    const String VulkanGLSLProgramFactory::LANGUAGE_NAME = "glsl";
+    const String VulkanGLSLProgramFactory::LANGUAGE_NAME = "vksl";
 
 	VulkanGLSLProgramFactory::VulkanGLSLProgramFactory()
 	{
@@ -20,7 +20,7 @@ namespace bs { namespace ct
 		glslang::FinalizeProcess();
 	}
 
-    const String& VulkanGLSLProgramFactory::getLanguage(void) const
+    const String& VulkanGLSLProgramFactory::getLanguage() const
     {
         return LANGUAGE_NAME;
     }

+ 4 - 4
Source/BansheeVulkanRenderAPI/Source/BsVulkanGpuBuffer.cpp

@@ -31,12 +31,12 @@ namespace bs { namespace ct
 		const GpuBufferProperties& props = getProperties();
 
 		VulkanHardwareBuffer::BufferType bufferType;
-		if (props.getRandomGpuWrite())
-			bufferType = VulkanHardwareBuffer::BT_STORAGE;
+		if (props.getType() == GBT_STRUCTURED)
+			bufferType = VulkanHardwareBuffer::BT_STRUCTURED;
 		else
 		{
-			if(props.getType() == GBT_STRUCTURED)
-				bufferType = VulkanHardwareBuffer::BT_STRUCTURED;
+			if (props.getRandomGpuWrite())
+				bufferType = VulkanHardwareBuffer::BT_STORAGE;
 			else
 				bufferType = VulkanHardwareBuffer::BT_GENERIC;
 		}

+ 10 - 1
Source/BansheeVulkanRenderAPI/Source/BsVulkanGpuParams.cpp

@@ -302,7 +302,16 @@ namespace bs { namespace ct
 			PerSetData& perSetData = mPerDeviceData[i].perSetData[set];
 			if (imageRes != nullptr)
 			{
-				perSetData.writeInfos[bindingIdx].image.imageView = imageRes->getView(surface, false);
+				auto& texProps = texture->getProperties();
+
+				TextureSurface actualSurface = surface;
+				if (surface.numMipLevels == 0)
+					actualSurface.numMipLevels = texProps.getNumMipmaps() + 1;
+				
+				if(surface.numArraySlices == 0)
+					actualSurface.numArraySlices = texProps.getNumFaces();
+
+				perSetData.writeInfos[bindingIdx].image.imageView = imageRes->getView(actualSurface, false);
 				mPerDeviceData[i].sampledImages[sequentialIdx] = imageRes->getHandle();
 			}
 			else

+ 10 - 2
Source/BansheeVulkanRenderAPI/Source/BsVulkanGpuProgram.cpp

@@ -301,7 +301,15 @@ namespace bs { namespace ct
 			GLSLAttribute("bs_texcoord", VES_TEXCOORD),
 			GLSLAttribute("bs_color", VES_COLOR),
 			GLSLAttribute("bs_blendweights", VES_BLEND_WEIGHTS),
-			GLSLAttribute("bs_blendindices", VES_BLEND_INDICES)
+			GLSLAttribute("bs_blendindices", VES_BLEND_INDICES),
+			GLSLAttribute("POSITION", VES_POSITION),
+			GLSLAttribute("NORMAL", VES_NORMAL),
+			GLSLAttribute("TANGENT", VES_TANGENT),
+			GLSLAttribute("BITANGENT", VES_BITANGENT),
+			GLSLAttribute("TEXCOORD", VES_TEXCOORD),
+			GLSLAttribute("COLOR", VES_COLOR),
+			GLSLAttribute("BLENDWEIGHT", VES_BLEND_WEIGHTS),
+			GLSLAttribute("BLENDINDICES", VES_BLEND_INDICES)
 		};
 
 		static const UINT32 numAttribs = sizeof(attributes) / sizeof(attributes[0]);
@@ -492,7 +500,7 @@ namespace bs { namespace ct
 			else
 			{
 				// We don't parse individual members of shared storage buffers
-				if (qualifier.storage == glslang::EvqBuffer)
+				if (qualifier.storage != glslang::EvqUniform)
 					continue;
 
 				if(ttype->getBasicType() == glslang::EbtStruct)

+ 1 - 1
Source/BansheeVulkanRenderAPI/Source/BsVulkanRenderAPI.cpp

@@ -98,7 +98,7 @@ namespace bs { namespace ct
 
 	const String& VulkanRenderAPI::getShadingLanguageName() const
 	{
-		static String strName("glsl");
+		static String strName("vksl");
 		return strName;
 	}
 

+ 6 - 8
Source/BansheeVulkanRenderAPI/Source/BsVulkanTexture.cpp

@@ -608,7 +608,7 @@ namespace bs { namespace ct
 		// Note: I force rendertarget and depthstencil types to be readable in shader. Depending on performance impact
 		// it might be beneficial to allow the user to enable this explicitly only when needed.
 		
-		mImageCI.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
+		mImageCI.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
 
 		int usage = props.getUsage();
 		if ((usage & TU_RENDERTARGET) != 0)
@@ -621,8 +621,6 @@ namespace bs { namespace ct
 			mImageCI.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
 			mSupportsGPUWrites = true;
 		}
-		else
-			mImageCI.usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
 		
 		if ((usage & TU_LOADSTORE) != 0)
 		{
@@ -910,14 +908,14 @@ namespace bs { namespace ct
 		VulkanRenderAPI& rapi = static_cast<VulkanRenderAPI&>(RenderAPI::instance());
 		for(UINT32 i = 0; i < BS_MAX_DEVICES; i++)
 		{
-			VulkanDevice& device = *rapi._getDevice(i);
-
 			VulkanImage* srcImage = mImages[i];
 			VulkanImage* dstImage = other->getResource(i);
 
 			if (srcImage == nullptr || dstImage == nullptr)
 				continue;
 
+			VulkanDevice& device = *rapi._getDevice(i);
+
 			VulkanImageSubresource* srcSubresource = srcImage->getSubresource(srcFace, srcMipLevel);
 			VulkanImageSubresource* dstSubresource = dstImage->getSubresource(destFace, destMipLevel);
 
@@ -935,7 +933,7 @@ namespace bs { namespace ct
 			bool isBoundWithoutUse = boundCount > useCount;
 			if (isBoundWithoutUse)
 			{
-				VulkanImage* newImage = createImage(device, mInternalFormats[i]);
+				VulkanImage* newImage = other->createImage(device, other->mInternalFormats[i]);
 
 				// Avoid copying original contents if the image only has one sub-resource, which we'll overwrite anyway
 				if (dstProps.getNumMipmaps() > 0 || dstProps.getNumFaces() > 1)
@@ -943,12 +941,12 @@ namespace bs { namespace ct
 					VkImageLayout oldDstLayout = dstImage->getOptimalLayout();
 
 					dstLayout = newImage->getOptimalLayout();
-					copyImage(transferCB, dstImage, newImage, oldDstLayout, dstLayout);
+					other->copyImage(transferCB, dstImage, newImage, oldDstLayout, dstLayout);
 				}
 
 				dstImage->destroy();
 				dstImage = newImage;
-				mImages[i] = dstImage;
+				other->mImages[i] = dstImage;
 			}
 
 			VkAccessFlags srcAccessMask = srcImage->getAccessFlags(srcLayout);

+ 1 - 1
Source/CMakeLists.txt

@@ -6,7 +6,7 @@ set (BS_VERSION_MAJOR 0)
 set (BS_VERSION_MINOR 4)
 
 set (BS_PREBUILT_DEPENDENCIES_VERSION 1)
-set (BS_SRC_DEPENDENCIES_VERSION 5)
+set (BS_SRC_DEPENDENCIES_VERSION 6)
 
 # Configuration types
 if(CMAKE_CONFIGURATION_TYPES) # Multiconfig generator?

+ 1 - 1
Source/External/XShaderCompiler

@@ -1 +1 @@
-Subproject commit 1b9e760aa9e08b069240bb70d77ccd05b23feb9c
+Subproject commit 204c358af4d4185cef729022681259602711d1ef