瀏覽代碼

DirectX 11: Fixing texture leak due to circular dependencies

BearishSun 9 年之前
父節點
當前提交
dee5d3b4a2

+ 5 - 5
Source/BansheeCore/Include/BsTexture.h

@@ -413,15 +413,15 @@ namespace bs
 		 *
 		 * @note	Core thread only.
 		 */
-		static SPtr<TextureView> requestView(const SPtr<Texture>& texture, UINT32 mostDetailMip, UINT32 numMips,
-			UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage);
+		SPtr<TextureView> requestView(UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices, 
+									  GpuViewUsage usage);
 
 		/**
 		 * Releases the view. View won't actually get destroyed until all references to it are released.
 		 *
 		 * @note	Core thread only.
 		 */
-		static void releaseView(const SPtr<TextureView>& view);
+		void releaseView(const SPtr<TextureView>& view);
 
 		/** Returns a plain white texture. */
 		static SPtr<Texture> WHITE;
@@ -455,8 +455,8 @@ namespace bs
 		/* 								TEXTURE VIEW                      		*/
 		/************************************************************************/
 
-		/**	Creates a new empty/undefined texture view. */
-		virtual SPtr<TextureView> createView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& desc);
+		/**	Creates a view of a specific subresource in a texture. */
+		virtual SPtr<TextureView> createView(const TEXTURE_VIEW_DESC& desc);
 
 		/**
 		 * Releases all internal texture view references. Views won't get destroyed if there are external references still 

+ 1 - 5
Source/BansheeCore/Include/BsTextureView.h

@@ -83,17 +83,13 @@ namespace bs
 		/**	Returns the descriptor structure used for initializing the view. */
 		const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; }
 
-		/**	Gets the owner texture the view is referencing. */
-		SPtr<Texture> getTexture() const { return mOwnerTexture; }
-
 	protected:
-		TextureView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& _desc);
+		TextureView(const TEXTURE_VIEW_DESC& _desc);
 
 	protected:
 		friend class Texture;
 
 		TEXTURE_VIEW_DESC mDesc;
-		SPtr<Texture> mOwnerTexture;
 	};
 
 	/** @} */

+ 18 - 17
Source/BansheeCore/Source/BsRenderTexture.cpp

@@ -142,11 +142,11 @@ namespace bs
 		for (UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
 		{
 			if (mColorSurfaces[i] != nullptr)
-				Texture::releaseView(mColorSurfaces[i]);
+				mDesc.colorSurfaces[i].texture->releaseView(mColorSurfaces[i]);
 		}
 
 		if (mDepthStencilSurface != nullptr)
-			Texture::releaseView(mDepthStencilSurface);
+			mDesc.depthStencilSurface.texture->releaseView(mDepthStencilSurface);
 	}
 
 	void RenderTexture::initialize()
@@ -162,7 +162,7 @@ namespace bs
 				if ((texture->getProperties().getUsage() & TU_RENDERTARGET) == 0)
 					BS_EXCEPT(InvalidParametersException, "Provided texture is not created with render target usage.");
 
-				mColorSurfaces[i] = Texture::requestView(texture, mDesc.colorSurfaces[i].mipLevel, 1,
+				mColorSurfaces[i] = texture->requestView(mDesc.colorSurfaces[i].mipLevel, 1,
 					mDesc.colorSurfaces[i].face, mDesc.colorSurfaces[i].numFaces, GVU_RENDERTARGET);
 			}
 		}
@@ -174,7 +174,7 @@ namespace bs
 			if ((texture->getProperties().getUsage() & TU_DEPTHSTENCIL) == 0)
 				BS_EXCEPT(InvalidParametersException, "Provided texture is not created with depth stencil usage.");
 
-			mDepthStencilSurface = Texture::requestView(texture, mDesc.depthStencilSurface.mipLevel, 1,
+			mDepthStencilSurface = texture->requestView(mDesc.depthStencilSurface.mipLevel, 1,
 				mDesc.depthStencilSurface.face, 0, GVU_DEPTHSTENCIL);
 		}
 
@@ -199,26 +199,26 @@ namespace bs
 
 	void RenderTexture::throwIfBuffersDontMatch() const
 	{
-		SPtr<TextureView> firstSurfaceDesc = nullptr;
+		UINT32 firstSurfaceIdx = -1;
 		for (UINT32 i = 0; i < BS_MAX_MULTIPLE_RENDER_TARGETS; i++)
 		{
 			if (mColorSurfaces[i] == nullptr)
 				continue;
 
-			if (firstSurfaceDesc == nullptr)
+			if (firstSurfaceIdx == -1)
 			{
-				firstSurfaceDesc = mColorSurfaces[i];
+				firstSurfaceIdx = i;
 				continue;
 			}
 
-			const TextureProperties& curTexProps = mColorSurfaces[i]->getTexture()->getProperties();
-			const TextureProperties& firstTexProps = firstSurfaceDesc->getTexture()->getProperties();
+			const TextureProperties& curTexProps = mDesc.colorSurfaces[i].texture->getProperties();
+			const TextureProperties& firstTexProps = mDesc.colorSurfaces[firstSurfaceIdx].texture->getProperties();
 
 			UINT32 curMsCount = curTexProps.getNumSamples();
 			UINT32 firstMsCount = firstTexProps.getNumSamples();
 
 			UINT32 curNumSlices = mColorSurfaces[i]->getNumArraySlices();
-			UINT32 firstNumSlices = firstSurfaceDesc->getNumArraySlices();
+			UINT32 firstNumSlices = mColorSurfaces[firstSurfaceIdx]->getNumArraySlices();
 
 			if (curMsCount == 0)
 				curMsCount = 1;
@@ -242,9 +242,10 @@ namespace bs
 			}
 		}
 
-		if (firstSurfaceDesc != nullptr)
+		if (firstSurfaceIdx != -1)
 		{
-			const TextureProperties& firstTexProps = firstSurfaceDesc->getTexture()->getProperties();
+			const TextureProperties& firstTexProps = mDesc.colorSurfaces[firstSurfaceIdx].texture->getProperties();
+			SPtr<TextureView> firstSurfaceView = mColorSurfaces[firstSurfaceIdx];
 
 			UINT32 numSlices;
 			if (firstTexProps.getTextureType() == TEX_TYPE_3D)
@@ -252,22 +253,22 @@ namespace bs
 			else
 				numSlices = firstTexProps.getNumFaces();
 
-			if ((firstSurfaceDesc->getFirstArraySlice() + firstSurfaceDesc->getNumArraySlices()) > numSlices)
+			if ((firstSurfaceView->getFirstArraySlice() + firstSurfaceView->getNumArraySlices()) > numSlices)
 			{
 				BS_EXCEPT(InvalidParametersException, "Provided number of faces is out of range. Face: " +
-					toString(firstSurfaceDesc->getFirstArraySlice() + firstSurfaceDesc->getNumArraySlices()) + ". Max num faces: " + toString(numSlices));
+					toString(firstSurfaceView->getFirstArraySlice() + firstSurfaceView->getNumArraySlices()) + ". Max num faces: " + toString(numSlices));
 			}
 
-			if (firstSurfaceDesc->getMostDetailedMip() > firstTexProps.getNumMipmaps())
+			if (firstSurfaceView->getMostDetailedMip() > firstTexProps.getNumMipmaps())
 			{
 				BS_EXCEPT(InvalidParametersException, "Provided number of mip maps is out of range. Mip level: " +
-					toString(firstSurfaceDesc->getMostDetailedMip()) + ". Max num mipmaps: " + toString(firstTexProps.getNumMipmaps()));
+					toString(firstSurfaceView->getMostDetailedMip()) + ". Max num mipmaps: " + toString(firstTexProps.getNumMipmaps()));
 			}
 
 			if (mDepthStencilSurface == nullptr)
 				return;
 
-			const TextureProperties& depthTexProps = mDepthStencilSurface->getTexture()->getProperties();
+			const TextureProperties& depthTexProps = mDesc.depthStencilSurface.texture->getProperties();
 			UINT32 depthMsCount = depthTexProps.getNumSamples();
 			UINT32 colorMsCount = firstTexProps.getNumSamples();
 

+ 17 - 19
Source/BansheeCore/Source/BsTexture.cpp

@@ -340,6 +340,8 @@ namespace bs
 			mInitData->_unlock();
 			mInitData = nullptr;
 		}
+
+		CoreObject::initialize();
 	}
 
 	void Texture::writeData(const PixelData& src, UINT32 mipLevel, UINT32 face, bool discardEntireBuffer,
@@ -473,9 +475,9 @@ namespace bs
 	/* 								TEXTURE VIEW                      		*/
 	/************************************************************************/
 
-	SPtr<TextureView> Texture::createView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& desc)
+	SPtr<TextureView> Texture::createView(const TEXTURE_VIEW_DESC& desc)
 	{
-		return bs_shared_ptr<TextureView>(new (bs_alloc<TextureView>()) TextureView(texture, desc));
+		return bs_shared_ptr<TextureView>(new (bs_alloc<TextureView>()) TextureView(desc));
 	}
 
 	void Texture::clearBufferViews()
@@ -483,32 +485,30 @@ namespace bs
 		mTextureViews.clear();
 	}
 
-	SPtr<TextureView> Texture::requestView(const SPtr<Texture>& texture, UINT32 mostDetailMip, UINT32 numMips,
-											   UINT32 firstArraySlice, UINT32 numArraySlices, GpuViewUsage usage)
+	SPtr<TextureView> Texture::requestView(UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, 
+										   UINT32 numArraySlices, GpuViewUsage usage)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		assert(texture != nullptr);
-
 		TEXTURE_VIEW_DESC key;
 		key.mostDetailMip = mostDetailMip;
 		key.numMips = numMips;
 		key.firstArraySlice = firstArraySlice;
 		key.usage = usage;
 
-		const TextureProperties& texProps = texture->getProperties();
+		const TextureProperties& texProps = getProperties();
 		if(numArraySlices == 0) // Automatically determine slice count
 			key.numArraySlices = texProps.getNumFaces();
 		else
 			key.numArraySlices = numArraySlices;
 
-		auto iterFind = texture->mTextureViews.find(key);
-		if (iterFind == texture->mTextureViews.end())
+		auto iterFind = mTextureViews.find(key);
+		if (iterFind == mTextureViews.end())
 		{
-			SPtr<TextureView> newView = texture->createView(texture, key);
-			texture->mTextureViews[key] = new (bs_alloc<TextureViewReference>()) TextureViewReference(newView);
+			SPtr<TextureView> newView = createView(key);
+			mTextureViews[key] = new (bs_alloc<TextureViewReference>()) TextureViewReference(newView);
 
-			iterFind = texture->mTextureViews.find(key);
+			iterFind = mTextureViews.find(key);
 		}
 
 		iterFind->second->refCount++;
@@ -521,12 +521,11 @@ namespace bs
 
 		assert(view != nullptr);
 
-		SPtr<Texture> texture = view->getTexture();
-
-		auto iterFind = texture->mTextureViews.find(view->getDesc());
-		if (iterFind == texture->mTextureViews.end())
+		auto iterFind = mTextureViews.find(view->getDesc());
+		if (iterFind == mTextureViews.end())
 		{
-			BS_EXCEPT(InternalErrorException, "Trying to release a texture view that doesn't exist!");
+			LOGERR("Trying to release a texture view that doesn't exist!");
+			return;
 		}
 
 		iterFind->second->refCount--;
@@ -535,8 +534,7 @@ namespace bs
 		{
 			TextureViewReference* toRemove = iterFind->second;
 
-			texture->mTextureViews.erase(iterFind);
-
+			mTextureViews.erase(iterFind);
 			bs_delete(toRemove);
 		}
 	}

+ 2 - 2
Source/BansheeCore/Source/BsTextureView.cpp

@@ -27,8 +27,8 @@ namespace bs { namespace ct
 	TextureView::~TextureView()
 	{ }
 
-	TextureView::TextureView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& desc)
-		:mDesc(desc), mOwnerTexture(texture)
+	TextureView::TextureView(const TEXTURE_VIEW_DESC& desc)
+		:mDesc(desc)
 	{
 
 	}

+ 1 - 1
Source/BansheeD3D11RenderAPI/Include/BsD3D11Texture.h

@@ -124,7 +124,7 @@ namespace bs { namespace ct
 		void unmapstaticbuffer();
 
 		/**	Creates an empty and uninitialized texture view object. */
-		SPtr<TextureView> createView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& desc) override;
+		SPtr<TextureView> createView(const TEXTURE_VIEW_DESC& desc) override;
 
 	protected:
 		ID3D11Texture1D* m1DTex;

+ 5 - 5
Source/BansheeD3D11RenderAPI/Include/BsD3D11TextureView.h

@@ -47,7 +47,7 @@ namespace bs { namespace ct
 	protected:
 		friend class D3D11Texture;
 
-		D3D11TextureView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& desc);
+		D3D11TextureView(const D3D11Texture* texture, const TEXTURE_VIEW_DESC& desc);
 	private:
 		/**
 		 * Creates a shader resource view that allows the provided surfaces to be bound as normal shader resources.
@@ -62,7 +62,7 @@ namespace bs { namespace ct
 		 *								for 1D and 2D array textures, number of slices for 3D textures, and number of cubes
 		 *								for cube textures.
 		 */
-		ID3D11ShaderResourceView* createSRV(D3D11Texture* texture, 
+		ID3D11ShaderResourceView* createSRV(const D3D11Texture* texture, 
 			UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices);
 
 		/**
@@ -77,7 +77,7 @@ namespace bs { namespace ct
 		 *								for 1D and 2D array textures, number of slices for 3D textures, and number of cubes
 		 *								for cube textures.
 		 */
-		ID3D11RenderTargetView* createRTV(D3D11Texture* texture, 
+		ID3D11RenderTargetView* createRTV(const D3D11Texture* texture,
 			UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices);
 
 		/**
@@ -92,7 +92,7 @@ namespace bs { namespace ct
 		 *								for 1D and 2D array textures, number of slices for 3D textures, and number of cubes
 		 *								for cube textures.
 		 */
-		ID3D11UnorderedAccessView* createUAV(D3D11Texture* texture, 
+		ID3D11UnorderedAccessView* createUAV(const D3D11Texture* texture,
 			UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices);
 
 		/**
@@ -109,7 +109,7 @@ namespace bs { namespace ct
 		 * @param[in]	readOnly		Should the depth stencil view only support read operations (allows the bound texture
 		 *								to be also used as a shader resource view while bound as a depth stencil target).
 		 */
-		ID3D11DepthStencilView* createDSV(D3D11Texture* texture, 
+		ID3D11DepthStencilView* createDSV(const D3D11Texture* texture,
 			UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices, bool readOnly);
 
 		ID3D11ShaderResourceView* mSRV;

+ 9 - 1
Source/BansheeD3D11RenderAPI/Source/BsD3D11RenderAPI.cpp

@@ -449,7 +449,7 @@ namespace bs { namespace ct
 
 						if (texture != nullptr)
 						{
-							SPtr<TextureView> texView = Texture::requestView(texture, surface.mipLevel, 1,
+							SPtr<TextureView> texView = texture->requestView(surface.mipLevel, 1,
 								surface.arraySlice, surface.numArraySlices, GVU_RANDOMWRITE);
 
 							D3D11TextureView* d3d11texView = static_cast<D3D11TextureView*>(texView.get());
@@ -1246,6 +1246,14 @@ namespace bs { namespace ct
 
 	void D3D11RenderAPI::determineMultisampleSettings(UINT32 multisampleCount, DXGI_FORMAT format, DXGI_SAMPLE_DESC* outputSampleDesc)
 	{
+		if(multisampleCount == 0 || multisampleCount == 1)
+		{
+			outputSampleDesc->Count = 1;
+			outputSampleDesc->Quality = 0;
+
+			return;
+		}
+
 		bool tryCSAA = false; // Note: Disabled for now, but leaving the code for later so it might be useful
 		enum CSAAMode { CSAA_Normal, CSAA_Quality };
 		CSAAMode csaaMode = CSAA_Normal;

+ 3 - 3
Source/BansheeD3D11RenderAPI/Source/BsD3D11RenderWindow.cpp

@@ -105,7 +105,7 @@ namespace bs
 		}
 
 		if (mDepthStencilView != nullptr)
-			Texture::releaseView(mDepthStencilView);
+			mDepthStencilBuffer->releaseView(mDepthStencilView);
 
 		destroySizeDependedD3DResources();
 	}
@@ -695,7 +695,7 @@ namespace bs
 
 		if (mDepthStencilView != nullptr)
 		{
-			Texture::releaseView(mDepthStencilView);
+			mDepthStencilBuffer->releaseView(mDepthStencilView);
 			mDepthStencilView = nullptr;
 		}
 
@@ -710,7 +710,7 @@ namespace bs
 			texDesc.numSamples = getProperties().getMultisampleCount();
 
 			mDepthStencilBuffer = Texture::create(texDesc);
-			mDepthStencilView = Texture::requestView(mDepthStencilBuffer, 0, 1, 0, 1, GVU_DEPTHSTENCIL);
+			mDepthStencilView = mDepthStencilBuffer->requestView(0, 1, 0, 1, GVU_DEPTHSTENCIL);
 		}
 		else
 			mDepthStencilBuffer = nullptr;

+ 5 - 18
Source/BansheeD3D11RenderAPI/Source/BsD3D11Texture.cpp

@@ -335,8 +335,7 @@ namespace bs { namespace ct
 			viewDesc.numArraySlices = desc.ArraySize;
 			viewDesc.usage = GVU_DEFAULT;
 
-			SPtr<Texture> thisPtr = std::static_pointer_cast<Texture>(getThisPtr());
-			mShaderResourceView = bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(thisPtr, viewDesc));
+			mShaderResourceView = bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(this, viewDesc));
 		}
 	}
 
@@ -391,11 +390,6 @@ namespace bs { namespace ct
 			D3D11RenderAPI* rs = static_cast<D3D11RenderAPI*>(RenderAPI::instancePtr());
 			rs->determineMultisampleSettings(sampleCount, d3dPF, &sampleDesc);
 			desc.SampleDesc		= sampleDesc;
-
-			if (texType == TEX_TYPE_CUBE_MAP)
-			{
-				BS_EXCEPT(NotImplementedException, "Cube map not yet supported as a render target."); // TODO: Will be once I add proper texture array support
-			}
 		}
 		else if((usage & TU_DEPTHSTENCIL) != 0)
 		{
@@ -414,11 +408,6 @@ namespace bs { namespace ct
 			rs->determineMultisampleSettings(sampleCount, d3dPF, &sampleDesc);
 			desc.SampleDesc		= sampleDesc;
 
-			if (texType == TEX_TYPE_CUBE_MAP)
-			{
-				BS_EXCEPT(NotImplementedException, "Cube map not yet supported as a depth stencil target."); // TODO: Will be once I add proper texture array support
-			}
-
 			mDXGIColorFormat = D3D11Mappings::getShaderResourceDepthStencilPF(closestFormat);
 			mDXGIDepthStencilFormat = d3dPF;
 		}
@@ -483,8 +472,7 @@ namespace bs { namespace ct
 			viewDesc.numArraySlices = desc.ArraySize;
 			viewDesc.usage = GVU_DEFAULT;
 
-			SPtr<Texture> thisPtr = std::static_pointer_cast<Texture>(getThisPtr());
-			mShaderResourceView = bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(thisPtr, viewDesc));
+			mShaderResourceView = bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(this, viewDesc));
 		}
 	}
 
@@ -601,8 +589,7 @@ namespace bs { namespace ct
 			viewDesc.numArraySlices = 1;
 			viewDesc.usage = GVU_DEFAULT;
 
-			SPtr<Texture> thisPtr = std::static_pointer_cast<Texture>(getThisPtr());
-			mShaderResourceView = bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(thisPtr, viewDesc));
+			mShaderResourceView = bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(this, viewDesc));
 		}
 	}
 
@@ -755,8 +742,8 @@ namespace bs { namespace ct
 		}
 	}
 
-	SPtr<TextureView> D3D11Texture::createView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& desc)
+	SPtr<TextureView> D3D11Texture::createView(const TEXTURE_VIEW_DESC& desc)
 	{
-		return bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(texture, desc));
+		return bs_shared_ptr<D3D11TextureView>(new (bs_alloc<D3D11TextureView>()) D3D11TextureView(this, desc));
 	}
 }}

+ 11 - 13
Source/BansheeD3D11RenderAPI/Source/BsD3D11TextureView.cpp

@@ -10,22 +10,20 @@
 
 namespace bs { namespace ct
 {
-	D3D11TextureView::D3D11TextureView(const SPtr<Texture>& texture, const TEXTURE_VIEW_DESC& desc)
-		:TextureView(texture, desc), mSRV(nullptr), mUAV(nullptr), mDSV(nullptr), mRTV(nullptr), mRODSV(nullptr)
+	D3D11TextureView::D3D11TextureView(const D3D11Texture* texture, const TEXTURE_VIEW_DESC& desc)
+		:TextureView(desc), mSRV(nullptr), mUAV(nullptr), mDSV(nullptr), mRTV(nullptr), mRODSV(nullptr)
 	{
-		D3D11Texture* d3d11Texture = static_cast<D3D11Texture*>(mOwnerTexture.get());
-
 		if ((mDesc.usage & GVU_RANDOMWRITE) != 0)
-			mUAV = createUAV(d3d11Texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices);
+			mUAV = createUAV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices);
 		else if ((mDesc.usage & GVU_RENDERTARGET) != 0)
-			mRTV = createRTV(d3d11Texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices);
+			mRTV = createRTV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices);
 		else if ((mDesc.usage & GVU_DEPTHSTENCIL) != 0)
 		{
-			mDSV = createDSV(d3d11Texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, false);
-			mRODSV = createDSV(d3d11Texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, true);
+			mDSV = createDSV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, false);
+			mRODSV = createDSV(texture, mDesc.mostDetailMip, mDesc.firstArraySlice, mDesc.numArraySlices, true);
 		}
 		else
-			mSRV = createSRV(d3d11Texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);
+			mSRV = createSRV(texture, mDesc.mostDetailMip, mDesc.numMips, mDesc.firstArraySlice, mDesc.numArraySlices);
 	}
 
 	D3D11TextureView::~D3D11TextureView()
@@ -37,7 +35,7 @@ namespace bs { namespace ct
 		SAFE_RELEASE(mRTV);
 	}
 
-	ID3D11ShaderResourceView* D3D11TextureView::createSRV(D3D11Texture* texture, 
+	ID3D11ShaderResourceView* D3D11TextureView::createSRV(const D3D11Texture* texture,
 		UINT32 mostDetailMip, UINT32 numMips, UINT32 firstArraySlice, UINT32 numArraySlices)
 	{
 		D3D11_SHADER_RESOURCE_VIEW_DESC desc;
@@ -137,7 +135,7 @@ namespace bs { namespace ct
 		return srv;
 	}
 
-	ID3D11RenderTargetView* D3D11TextureView::createRTV(D3D11Texture* texture,
+	ID3D11RenderTargetView* D3D11TextureView::createRTV(const D3D11Texture* texture,
 		UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices)
 	{
 		D3D11_RENDER_TARGET_VIEW_DESC desc;
@@ -224,7 +222,7 @@ namespace bs { namespace ct
 		return rtv;
 	}
 
-	ID3D11UnorderedAccessView* D3D11TextureView::createUAV(D3D11Texture* texture,
+	ID3D11UnorderedAccessView* D3D11TextureView::createUAV(const D3D11Texture* texture,
 		UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices)
 	{
 		D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
@@ -295,7 +293,7 @@ namespace bs { namespace ct
 		return uav;
 	}
 
-	ID3D11DepthStencilView* D3D11TextureView::createDSV(D3D11Texture* texture,
+	ID3D11DepthStencilView* D3D11TextureView::createDSV(const D3D11Texture* texture,
 		UINT32 mipSlice, UINT32 firstArraySlice, UINT32 numArraySlices, bool readOnly)
 	{
 		D3D11_DEPTH_STENCIL_VIEW_DESC desc;

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

@@ -53,7 +53,7 @@ namespace bs
 		{
 			if (mColorSurfaces[i] != nullptr)
 			{
-				GLTexture* glColorSurface = static_cast<GLTexture*>(mColorSurfaces[i]->getTexture().get());
+				GLTexture* glColorSurface = static_cast<GLTexture*>(mDesc.colorSurfaces[i].texture.get());
 				GLSurfaceDesc surfaceDesc;
 				surfaceDesc.numSamples = getProperties().getMultisampleCount();
 
@@ -100,9 +100,9 @@ namespace bs
 			}
 		}
 
-		if (mDepthStencilSurface != nullptr && mDepthStencilSurface->getTexture() != nullptr)
+		if (mDepthStencilSurface != nullptr && mDesc.depthStencilSurface.texture != nullptr)
 		{
-			GLTexture* glDepthStencilTexture = static_cast<GLTexture*>(mDepthStencilSurface->getTexture().get());
+			GLTexture* glDepthStencilTexture = static_cast<GLTexture*>(mDesc.depthStencilSurface.texture.get());
 			SPtr<GLPixelBuffer> depthStencilBuffer = nullptr;
 
 			if (glDepthStencilTexture->getProperties().getTextureType() != TEX_TYPE_3D)

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

@@ -45,7 +45,7 @@ namespace bs
 				continue;
 
 			const SPtr<TextureView>& view = mColorSurfaces[i];
-			VulkanTexture* texture = static_cast<VulkanTexture*>(view->getTexture().get());
+			VulkanTexture* texture = static_cast<VulkanTexture*>(mDesc.colorSurfaces[i].texture.get());
 
 			VulkanImage* image = texture->getResource(mDeviceIdx);
 			if (image == nullptr)
@@ -86,7 +86,7 @@ namespace bs
 		if(mDepthStencilSurface != nullptr)
 		{
 			const SPtr<TextureView>& view = mDepthStencilSurface;
-			VulkanTexture* texture = static_cast<VulkanTexture*>(view->getTexture().get());
+			VulkanTexture* texture = static_cast<VulkanTexture*>(mDesc.depthStencilSurface.texture.get());
 
 			VulkanImage* image = texture->getResource(mDeviceIdx);
 			if (image != nullptr)