Explorar o código

Vulkan: Example project now mostly functional on Vulkan

BearishSun %!s(int64=9) %!d(string=hai) anos
pai
achega
585ee02f70

+ 4 - 2
Data/Examples/Example.bsl

@@ -49,16 +49,18 @@ Technique : base("Surface") =
 		
 			layout(binding = 4) uniform sampler2D tex;
 
+			layout(location = 0) out vec4 fragColor[3];
+			
 			void main()
 			{
 				GBufferData gbufferData;
 				gbufferData.albedo = texture(tex, uv0);
 				gbufferData.worldNormal.xyz = tangentToWorldZ;
 				
-				encodeGBuffer(gbufferData, gl_FragData[1], gl_FragData[2]);
+				encodeGBuffer(gbufferData, fragColor[1], fragColor[2]);
 				
 				// TODO - Just returning a simple ambient term, use better environment lighting later
-				gl_FragData[0] = vec4(gbufferData.albedo.rgb, 1.0f) * 0.2f; 
+				fragColor[0] = vec4(gbufferData.albedo.rgb, 1.0f) * 0.2f; 
 			}	
 		};
 	};

BIN=BIN
Data/Examples/Example.bsl.asset


+ 4 - 2
Data/Raw/Engine/Shaders/Diffuse.bsl

@@ -59,6 +59,8 @@ Technique : base("Surface") =
 			layout(binding = 4) uniform sampler2D gAlbedoTex;
 			layout(binding = 5) uniform sampler2D gNormalTex;
 
+			layout(location = 0) out vec4 fragColor[3];
+			
 			void main()
 			{
 				vec3 normal = normalize(texture(gNormalTex, uv0).xyz * 2.0f - vec3(1, 1, 1));
@@ -68,10 +70,10 @@ Technique : base("Surface") =
 				gbufferData.albedo = texture(gAlbedoTex, uv0);
 				gbufferData.worldNormal.xyz = worldNormal;
 				
-				encodeGBuffer(gbufferData, gl_FragData[1], gl_FragData[2]);
+				encodeGBuffer(gbufferData, fragColor[1], fragColor[2]);
 				
 				// TODO - Just returning a simple ambient term, use better environment lighting later
-				gl_FragData[0] = vec4(gbufferData.albedo.rgb, 1.0f) * 0.01f; 
+				fragColor[0] = vec4(gbufferData.albedo.rgb, 1.0f) * 0.01f; 
 			}	
 		};
 	};

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

@@ -441,7 +441,12 @@ namespace bs
 
 			PerSetData& perSetData = mPerDeviceData[i].perSetData[set];
 
-			VulkanSampler* samplerRes = vulkanSampler->getResource(i);
+			VulkanSampler* samplerRes;
+			if (vulkanSampler != nullptr)
+				samplerRes = vulkanSampler->getResource(i);
+			else
+				samplerRes = nullptr;
+
 			if (samplerRes != nullptr)
 			{
 				VkSampler vkSampler = samplerRes->getHandle();

+ 8 - 2
Source/BansheeVulkanRenderAPI/Source/BsVulkanGpuPipelineState.cpp

@@ -138,6 +138,8 @@ namespace bs
 		mInputAssemblyInfo.primitiveRestartEnable = false;
 
 		mTesselationInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
+		mTesselationInfo.pNext = nullptr;
+		mTesselationInfo.flags = 0;
 		mTesselationInfo.patchControlPoints = 3; // Assigned at runtime
 
 		mViewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
@@ -372,9 +374,13 @@ namespace bs
 		mInputAssemblyInfo.topology = VulkanUtility::getDrawOp(drawOp);
 		mTesselationInfo.patchControlPoints = 3; // Not provided by our shaders for now
 		mMultiSampleInfo.rasterizationSamples = framebuffer->getSampleFlags();
-		mColorBlendStateInfo.attachmentCount = framebuffer->getNumAttachments();
+		mColorBlendStateInfo.attachmentCount = framebuffer->getNumColorAttachments();
 
-		const DepthStencilProperties dsProps = getDepthStencilState()->getProperties();
+		DepthStencilStateCore* dsState = getDepthStencilState().get();
+		if (dsState == nullptr)
+			dsState = DepthStencilStateCore::getDefault().get();
+
+		const DepthStencilProperties dsProps = dsState->getProperties();
 		bool enableDepthWrites = dsProps.getDepthWriteEnable() && !readOnlyDepth;
 
 		mDepthStencilInfo.depthWriteEnable = enableDepthWrites; // If depth stencil attachment is read only, depthWriteEnable must be VK_FALSE

+ 3 - 0
Source/BansheeVulkanRenderAPI/Source/BsVulkanRenderAPI.cpp

@@ -539,6 +539,9 @@ namespace bs
 	{
 		dest = matrix;
 
+		// Flip Y axis
+		dest[1][1] = -dest[1][1];
+
 		// Convert depth range from [-1,1] to [0,1]
 		dest[2][0] = (dest[2][0] + dest[3][0]) / 2;
 		dest[2][1] = (dest[2][1] + dest[3][1]) / 2;

+ 5 - 4
Source/BansheeVulkanRenderAPI/Source/BsVulkanVertexInputManager.cpp

@@ -118,10 +118,11 @@ namespace bs
 			VkVertexInputBindingDescription& binding = newEntry.bindings[i];
 			binding.binding = i;
 			binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
-			binding.stride = 0;
+			binding.stride = vbDecl->getProperties().getVertexSize(i);
 		}
 
 		UINT32 attribIdx = 0;
+		bool isFirstInBinding = true;
 		for (auto& vbElem : vbElements)
 		{
 			VkVertexInputAttributeDescription& attribute = newEntry.attributes[attribIdx];
@@ -147,9 +148,11 @@ namespace bs
 			VkVertexInputBindingDescription& binding = newEntry.bindings[attribute.binding];
 
 			bool isPerVertex = vbElem.getInstanceStepRate() == 0;
-			bool isFirstInBinding = binding.stride == 0;
 			if (isFirstInBinding)
+			{
 				binding.inputRate = isPerVertex ? VK_VERTEX_INPUT_RATE_VERTEX : VK_VERTEX_INPUT_RATE_INSTANCE;
+				isFirstInBinding = false;
+			}
 			else
 			{
 				if ((binding.inputRate == VK_VERTEX_INPUT_RATE_VERTEX && !isPerVertex) ||
@@ -160,8 +163,6 @@ namespace bs
 				}
 			}
 
-			binding.stride += vbElem.getSize();
-
 			attribIdx++;
 		}