Explorar o código

Dropping support for rendering to arbitrary ranges within a 3D texture, since Vulkan doesn't support it

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

+ 2 - 2
Source/BansheeCore/Include/BsRenderTarget.h

@@ -72,8 +72,8 @@ namespace bs
         UINT32 getHeight() const { return mHeight; }
 
 		/** 
-		 * Returns the number of three dimensional slices of the render target. This will be the depth for 3D textures,
-		 * or number of layers for array textures.
+		 * Returns the number of three dimensional slices of the render target. This will be number of layers for array
+		 * textures or number of faces cube textures.
 		 */
         UINT32 getNumSlices() const { return mNumSlices; }
 

+ 1 - 8
Source/BansheeCore/Source/BsTexture.cpp

@@ -244,16 +244,9 @@ namespace bs
 
 		const TextureProperties& texProps = texture->getProperties();
 		if(numArraySlices == 0) // Automatically determine slice count
-		{
-			if(texProps.getTextureType() == TEX_TYPE_3D)
-				key.numArraySlices = texProps.getDepth();
-			else
-				key.numArraySlices = texProps.getNumFaces();
-		}
+			key.numArraySlices = texProps.getNumFaces();
 		else
-		{
 			key.numArraySlices = numArraySlices;
-		}
 
 		auto iterFind = texture->mTextureViews.find(key);
 		if (iterFind == texture->mTextureViews.end())

+ 9 - 4
Source/BansheeD3D11RenderAPI/Source/BsD3D11TextureView.cpp

@@ -195,8 +195,8 @@ namespace bs
 		case TEX_TYPE_3D:
 			desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
 			desc.Texture3D.MipSlice = mipSlice;
-			desc.Texture3D.FirstWSlice = firstArraySlice;
-			desc.Texture3D.WSize = numArraySlices;
+			desc.Texture3D.FirstWSlice = 0;
+			desc.Texture3D.WSize = texProps.getDepth();
 			break;
 		case TEX_TYPE_CUBE_MAP:
 			desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
@@ -266,8 +266,8 @@ namespace bs
 		case TEX_TYPE_3D:
 			desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
 			desc.Texture3D.MipSlice = mipSlice;
-			desc.Texture3D.FirstWSlice = firstArraySlice;
-			desc.Texture3D.WSize = numArraySlices;
+			desc.Texture3D.FirstWSlice = 0;
+			desc.Texture3D.WSize = texProps.getDepth();
 			break;
 		case TEX_TYPE_CUBE_MAP:
 			desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
@@ -351,6 +351,11 @@ namespace bs
 			}
 			break;
 		case TEX_TYPE_3D:
+			desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
+			desc.Texture2DArray.FirstArraySlice = 0;
+			desc.Texture2DArray.ArraySize = texProps.getDepth();
+			desc.Texture2DArray.MipSlice = mipSlice;
+			break;
 		case TEX_TYPE_CUBE_MAP:
 			desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
 			desc.Texture2DArray.FirstArraySlice = firstArraySlice;

+ 1 - 4
Source/BansheeGLRenderAPI/Source/BsGLRenderTexture.cpp

@@ -61,7 +61,7 @@ namespace bs
 					}
 					else
 					{
-						surfaceDesc.zoffset = mColorSurfaces[i]->getFirstArraySlice();
+						surfaceDesc.zoffset = 0;
 						surfaceDesc.buffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
 					}
 				}
@@ -79,9 +79,6 @@ namespace bs
 					}
 					else
 					{
-						if (mColorSurfaces[i]->getNumArraySlices() != glColorSurface->getProperties().getDepth())
-							LOGWRN("OpenGL doesn't support binding of arbitrary ranges for array textures. The entire range will be bound instead.");
-
 						surfaceDesc.zoffset = 0;
 						surfaceDesc.buffer = glColorSurface->getBuffer(0, mColorSurfaces[i]->getMostDetailedMip());
 					}

+ 23 - 12
Source/BansheeVulkanRenderAPI/Source/BsVulkanCommandBuffer.cpp

@@ -695,7 +695,9 @@ namespace bs
 
 			setGpuParams(nullptr);
 
-			registerResource(mFramebuffer, VulkanUseFlag::Write);
+			if(mFramebuffer != nullptr)
+				registerResource(mFramebuffer, VulkanUseFlag::Write);
+
 			mGfxPipelineRequiresBind = true;
 		}
 	}
@@ -1077,11 +1079,14 @@ namespace bs
 
 		if (mDescriptorSetsBindState.isSet(DescriptorSetBindFlag::Graphics))
 		{
-			UINT32 deviceIdx = mDevice.getIndex();
-			VkPipelineLayout pipelineLayout = mGraphicsPipeline->getPipelineLayout(deviceIdx);
+			if (mNumBoundDescriptorSets > 0)
+			{
+				UINT32 deviceIdx = mDevice.getIndex();
+				VkPipelineLayout pipelineLayout = mGraphicsPipeline->getPipelineLayout(deviceIdx);
 
-			vkCmdBindDescriptorSets(mCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0,
-									mNumBoundDescriptorSets, mDescriptorSetsTemp, 0, nullptr);
+				vkCmdBindDescriptorSets(mCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0,
+										mNumBoundDescriptorSets, mDescriptorSetsTemp, 0, nullptr);
+			}
 
 			mDescriptorSetsBindState.unset(DescriptorSetBindFlag::Graphics);
 		}
@@ -1107,11 +1112,14 @@ namespace bs
 
 		if (mDescriptorSetsBindState.isSet(DescriptorSetBindFlag::Graphics))
 		{
-			UINT32 deviceIdx = mDevice.getIndex();
-			VkPipelineLayout pipelineLayout = mGraphicsPipeline->getPipelineLayout(deviceIdx);
+			if (mNumBoundDescriptorSets > 0)
+			{
+				UINT32 deviceIdx = mDevice.getIndex();
+				VkPipelineLayout pipelineLayout = mGraphicsPipeline->getPipelineLayout(deviceIdx);
 
-			vkCmdBindDescriptorSets(mCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0,
-									mNumBoundDescriptorSets, mDescriptorSetsTemp, 0, nullptr);
+				vkCmdBindDescriptorSets(mCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0,
+										mNumBoundDescriptorSets, mDescriptorSetsTemp, 0, nullptr);
+			}
 
 			mDescriptorSetsBindState.unset(DescriptorSetBindFlag::Graphics);
 		}
@@ -1143,9 +1151,12 @@ namespace bs
 
 		if(mDescriptorSetsBindState.isSet(DescriptorSetBindFlag::Compute))
 		{
-			VkPipelineLayout pipelineLayout = mComputePipeline->getPipelineLayout(deviceIdx);
-			vkCmdBindDescriptorSets(mCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0,
-				mNumBoundDescriptorSets, mDescriptorSetsTemp, 0, nullptr);
+			if (mNumBoundDescriptorSets > 0)
+			{
+				VkPipelineLayout pipelineLayout = mComputePipeline->getPipelineLayout(deviceIdx);
+				vkCmdBindDescriptorSets(mCmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0,
+										mNumBoundDescriptorSets, mDescriptorSetsTemp, 0, nullptr);
+			}
 
 			mDescriptorSetsBindState.unset(DescriptorSetBindFlag::Compute);
 		}

+ 47 - 6
Source/BansheeVulkanRenderAPI/Source/BsVulkanRenderTexture.cpp

@@ -27,7 +27,7 @@ namespace bs
 		VULKAN_FRAMEBUFFER_DESC fbDesc;
 		fbDesc.width = mProperties.getWidth();
 		fbDesc.height = mProperties.getHeight();
-		fbDesc.layers = mProperties.getNumSlices();
+		fbDesc.layers = 1;
 		fbDesc.numSamples = mProperties.getMultisampleCount() > 1 ? mProperties.getMultisampleCount() : 1;
 		fbDesc.offscreen = true;
 
@@ -44,15 +44,35 @@ namespace bs
 				continue;
 
 			TextureSurface surface;
-			surface.arraySlice = view->getFirstArraySlice();
-			surface.numArraySlices = view->getNumArraySlices();
 			surface.mipLevel = view->getMostDetailedMip();
 			surface.numMipLevels = view->getNumMips();
 
+			if (texture->getProperties().getTextureType() == TEX_TYPE_3D)
+			{
+				if(view->getFirstArraySlice() > 0)
+					LOGERR("Non-zero array slice offset not supported when rendering to a 3D texture.");
+
+				if (view->getNumArraySlices() > 1)
+					LOGERR("Cannot specify array slices when rendering to a 3D texture.");
+
+				surface.arraySlice = 0;
+				surface.numArraySlices = 1;
+
+				fbDesc.color[i].baseLayer = 0;
+				fbDesc.layers = 1;
+			}
+			else
+			{
+				surface.arraySlice = view->getFirstArraySlice();
+				surface.numArraySlices = view->getNumArraySlices();
+
+				fbDesc.color[i].baseLayer = view->getFirstArraySlice();
+				fbDesc.layers = view->getNumArraySlices();
+			}
+
 			fbDesc.color[i].image = image;
 			fbDesc.color[i].view = image->getView(surface);
 			fbDesc.color[i].format = VulkanUtility::getPixelFormat(texture->getProperties().getFormat());
-			fbDesc.color[i].baseLayer = view->getFirstArraySlice();
 		}
 
 		if(mDepthStencilSurface != nullptr)
@@ -64,11 +84,32 @@ namespace bs
 			if (image != nullptr)
 			{
 				TextureSurface surface;
-				surface.arraySlice = view->getFirstArraySlice();
-				surface.numArraySlices = view->getNumArraySlices();
 				surface.mipLevel = view->getMostDetailedMip();
 				surface.numMipLevels = view->getNumMips();
 
+				if (texture->getProperties().getTextureType() == TEX_TYPE_3D)
+				{
+					if (view->getFirstArraySlice() > 0)
+						LOGERR("Non-zero array slice offset not supported when rendering to a 3D texture.");
+
+					if (view->getNumArraySlices() > 1)
+						LOGERR("Cannot specify array slices when rendering to a 3D texture.");
+
+					surface.arraySlice = 0;
+					surface.numArraySlices = 1;
+
+					fbDesc.depth.baseLayer = 0;
+					fbDesc.layers = 1;
+				}
+				else
+				{
+					surface.arraySlice = view->getFirstArraySlice();
+					surface.numArraySlices = view->getNumArraySlices();
+
+					fbDesc.depth.baseLayer = view->getFirstArraySlice();
+					fbDesc.layers = view->getNumArraySlices();
+				}
+
 				fbDesc.depth.image = image;
 				fbDesc.depth.view = image->getView(surface);
 				fbDesc.depth.format = VulkanUtility::getPixelFormat(texture->getProperties().getFormat());

+ 1 - 1
Source/RenderBeast/Source/BsRenderTexturePool.cpp

@@ -65,7 +65,7 @@ namespace bs
 			{
 				rtDesc.colorSurfaces[0].texture = newTextureData->texture;
 				rtDesc.colorSurfaces[0].face = 0;
-				rtDesc.colorSurfaces[0].numFaces = desc.depth;
+				rtDesc.colorSurfaces[0].numFaces = 1;
 				rtDesc.colorSurfaces[0].mipLevel = 0;
 			}