Browse Source

Shader unload only callable from render thread

Marko Pintera 13 years ago
parent
commit
fed686f420

+ 5 - 5
CamelotD3D11RenderSystem/Source/CmD3D11GpuProgram.cpp

@@ -31,7 +31,7 @@ namespace CamelotEngine
 	{
 	{
 		// have to call this here reather than in Resource destructor
 		// have to call this here reather than in Resource destructor
 		// since calling virtual methods in base destructors causes crash
 		// since calling virtual methods in base destructors causes crash
-		unload(); 
+		unload_internal(); 
 	}
 	}
 
 
 	void D3D11GpuVertexProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob *  microcode)
 	void D3D11GpuVertexProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob *  microcode)
@@ -76,7 +76,7 @@ namespace CamelotEngine
 
 
 	D3D11GpuFragmentProgram::~D3D11GpuFragmentProgram()
 	D3D11GpuFragmentProgram::~D3D11GpuFragmentProgram()
 	{
 	{
-		unload(); 
+		unload_internal(); 
 	}
 	}
 
 
 	void D3D11GpuFragmentProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
 	void D3D11GpuFragmentProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
@@ -120,7 +120,7 @@ namespace CamelotEngine
 
 
 	D3D11GpuGeometryProgram::~D3D11GpuGeometryProgram()
 	D3D11GpuGeometryProgram::~D3D11GpuGeometryProgram()
 	{
 	{
-		unload(); 
+		unload_internal(); 
 	}
 	}
 
 
 	void D3D11GpuGeometryProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
 	void D3D11GpuGeometryProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
@@ -164,7 +164,7 @@ namespace CamelotEngine
 
 
 	D3D11GpuDomainProgram::~D3D11GpuDomainProgram()
 	D3D11GpuDomainProgram::~D3D11GpuDomainProgram()
 	{
 	{
-		unload(); 
+		unload_internal(); 
 	}
 	}
 
 
 	void D3D11GpuDomainProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
 	void D3D11GpuDomainProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
@@ -208,7 +208,7 @@ namespace CamelotEngine
 
 
 	D3D11GpuHullProgram::~D3D11GpuHullProgram()
 	D3D11GpuHullProgram::~D3D11GpuHullProgram()
 	{
 	{
-		unload(); 
+		unload_internal(); 
 	}
 	}
 
 
 	void D3D11GpuHullProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)
 	void D3D11GpuHullProgram::loadFromMicrocode(D3D11Device& device, ID3D10Blob* microcode)

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11HLSLProgram.cpp

@@ -14,7 +14,7 @@ namespace CamelotEngine
 
 
 	D3D11HLSLProgram::~D3D11HLSLProgram()
 	D3D11HLSLProgram::~D3D11HLSLProgram()
 	{
 	{
-		unload();
+		unload_internal();
 	}
 	}
 
 
 	const String& D3D11HLSLProgram::getLanguage() const
 	const String& D3D11HLSLProgram::getLanguage() const

+ 4 - 2
CamelotD3D9Renderer/Include/CmD3D9HLSLProgram.h

@@ -94,8 +94,10 @@ namespace CamelotEngine {
         /** Internal load implementation, must be implemented by subclasses.
         /** Internal load implementation, must be implemented by subclasses.
         */
         */
         void loadFromSource(void);
         void loadFromSource(void);
-        /// Internal unload implementation, must be implemented by subclasses
-        void unload(void);
+		/**
+		 * @copydoc GpuProgram::unload_internal()
+		 */
+        void unload_internal(void);
         /// Populate the passed parameters with name->index map, must be overridden
         /// Populate the passed parameters with name->index map, must be overridden
         void buildConstantDefinitions() const;
         void buildConstantDefinitions() const;
 
 

+ 3 - 3
CamelotD3D9Renderer/Source/CmD3D9HLSLProgram.cpp

@@ -242,12 +242,12 @@ namespace CamelotEngine {
 		}
 		}
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    void D3D9HLSLProgram::unload(void)
+    void D3D9HLSLProgram::unload_internal(void)
     {
     {
         SAFE_RELEASE(mpMicroCode);
         SAFE_RELEASE(mpMicroCode);
         SAFE_RELEASE(mpConstTable);
         SAFE_RELEASE(mpConstTable);
 
 
-		HighLevelGpuProgram::unload();
+		HighLevelGpuProgram::unload_internal();
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     void D3D9HLSLProgram::buildConstantDefinitions() const
     void D3D9HLSLProgram::buildConstantDefinitions() const
@@ -524,7 +524,7 @@ namespace CamelotEngine {
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     D3D9HLSLProgram::~D3D9HLSLProgram()
     D3D9HLSLProgram::~D3D9HLSLProgram()
     {
     {
-        unload();
+        unload_internal();
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     bool D3D9HLSLProgram::isSupported(void) const
     bool D3D9HLSLProgram::isSupported(void) const

+ 2 - 2
CamelotGLRenderer/Source/CmGLGpuProgram.cpp

@@ -59,7 +59,7 @@ GLGpuProgram::~GLGpuProgram()
 {
 {
     // have to call this here reather than in Resource destructor
     // have to call this here reather than in Resource destructor
     // since calling virtual methods in base destructors causes crash
     // since calling virtual methods in base destructors causes crash
-    unload(); 
+    unload_internal(); 
 }
 }
 
 
 GLuint GLGpuProgram::getAttributeIndex(VertexElementSemantic semantic, CamelotEngine::UINT32 index)
 GLuint GLGpuProgram::getAttributeIndex(VertexElementSemantic semantic, CamelotEngine::UINT32 index)
@@ -149,7 +149,7 @@ GLArbGpuProgram::~GLArbGpuProgram()
 {
 {
     // have to call this here reather than in Resource destructor
     // have to call this here reather than in Resource destructor
     // since calling virtual methods in base destructors causes crash
     // since calling virtual methods in base destructors causes crash
-    unload(); 
+    unload_internal(); 
 }
 }
 
 
 void GLArbGpuProgram::bindProgram(void)
 void GLArbGpuProgram::bindProgram(void)

+ 5 - 7
CamelotGLRenderer/Source/GLSL/include/CmGLSLProgram.h

@@ -115,13 +115,11 @@ namespace CamelotEngine {
         /** Internal load implementation, must be implemented by subclasses.
         /** Internal load implementation, must be implemented by subclasses.
         */
         */
         void loadFromSource(void);
         void loadFromSource(void);
-        /** Internal method for creating a dummy low-level program for this
-        high-level program.	GLSL does not give access to the low level implementation of the
-		shader so this method creates an object sub-classed from GLGpuProgram just to be
-		compatible with	GLRenderSystem.
-		*/
-		/// Overridden from HighLevelGpuProgram
-		void unload();
+
+		/**
+		 * @copydoc GpuProgram::unload_internal()
+		 */
+		void unload_internal();
 
 
         /// Populate the passed parameters with name->index map
         /// Populate the passed parameters with name->index map
         void populateParameterNames(GpuProgramParametersSharedPtr params);
         void populateParameterNames(GpuProgramParametersSharedPtr params);

+ 1 - 1
CamelotGLRenderer/Source/GLSL/src/CmGLSLGpuProgram.cpp

@@ -64,7 +64,7 @@ namespace CamelotEngine {
     {
     {
         // have to call this here reather than in Resource destructor
         // have to call this here reather than in Resource destructor
         // since calling virtual methods in base destructors causes crash
         // since calling virtual methods in base destructors causes crash
-        unload(); 
+        unload_internal(); 
     }
     }
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
     void GLSLGpuProgram::initialize_internal(void)
     void GLSLGpuProgram::initialize_internal(void)

+ 3 - 3
CamelotGLRenderer/Source/GLSL/src/CmGLSLProgram.cpp

@@ -44,7 +44,7 @@ namespace CamelotEngine {
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
     GLSLProgram::~GLSLProgram()
     GLSLProgram::~GLSLProgram()
     {
     {
-        unload();
+        unload_internal();
     }
     }
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
 	GLSLProgram::GLSLProgram(const String& source, const String& entryPoint, const String& language, 
 	GLSLProgram::GLSLProgram(const String& source, const String& entryPoint, const String& language, 
@@ -191,7 +191,7 @@ namespace CamelotEngine {
 
 
 	}
 	}
 	//---------------------------------------------------------------------------
 	//---------------------------------------------------------------------------
-	void GLSLProgram::unload()
+	void GLSLProgram::unload_internal()
 	{   
 	{   
 		// We didn't create mAssemblerProgram through a manager, so override this
 		// We didn't create mAssemblerProgram through a manager, so override this
 		// implementation so that we don't try to remove it from one. Since getCreator()
 		// implementation so that we don't try to remove it from one. Since getCreator()
@@ -203,7 +203,7 @@ namespace CamelotEngine {
 			glDeleteObjectARB(mGLHandle);
 			glDeleteObjectARB(mGLHandle);
 		}
 		}
 
 
-		HighLevelGpuProgram::unload();
+		HighLevelGpuProgram::unload_internal();
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
 	void GLSLProgram::populateParameterNames(GpuProgramParametersSharedPtr params)
 	void GLSLProgram::populateParameterNames(GpuProgramParametersSharedPtr params)

+ 1 - 1
CamelotGLRenderer/Source/atifs/src/ATI_FS_GLGpuProgram.cpp

@@ -47,7 +47,7 @@ ATI_FS_GLGpuProgram::~ATI_FS_GLGpuProgram()
 {
 {
     // have to call this here reather than in Resource destructor
     // have to call this here reather than in Resource destructor
     // since calling virtual methods in base destructors causes crash
     // since calling virtual methods in base destructors causes crash
-    unload(); 
+    unload_internal(); 
 }
 }
 
 
 void ATI_FS_GLGpuProgram::bindProgram(void)
 void ATI_FS_GLGpuProgram::bindProgram(void)

+ 4 - 2
CamelotRenderer/Include/CmCgProgram.h

@@ -75,8 +75,10 @@ namespace CamelotEngine {
         /** Internal load implementation, must be implemented by subclasses.
         /** Internal load implementation, must be implemented by subclasses.
         */
         */
         void loadFromSource(void);
         void loadFromSource(void);
-        /// Internal unload implementation, must be implemented by subclasses
-        void unload(void);
+		/**
+		 * @copydoc GpuProgram::unload_internal()
+		 */
+        void unload_internal(void);
         /// Populate the passed parameters with name->index map, must be overridden
         /// Populate the passed parameters with name->index map, must be overridden
         void buildConstantDefinitions() const;
         void buildConstantDefinitions() const;
 
 

+ 5 - 1
CamelotRenderer/Include/CmGpuProgram.h

@@ -132,7 +132,11 @@ namespace CamelotEngine {
 		 * @brief	Performs GpuProgram initialization. Only callable from the render thread.
 		 * @brief	Performs GpuProgram initialization. Only callable from the render thread.
 		 */
 		 */
 		virtual void initialize_internal();
 		virtual void initialize_internal();
-		virtual void unload() {}
+
+		/**
+		 * @brief	Unloads the GpuProgram. Only callable from the render thread.
+		 */
+		virtual void unload_internal();
 
 
         /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
         /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
         virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }

+ 4 - 1
CamelotRenderer/Include/CmHighLevelGpuProgram.h

@@ -78,7 +78,10 @@ namespace CamelotEngine {
 		 */
 		 */
 		virtual void initialize_internal();
 		virtual void initialize_internal();
 
 
-		virtual void unload();
+		/**
+		 * @copydoc GpuProgram::unload_internal()
+		 */
+		virtual void unload_internal();
 
 
         /** Creates a new parameters object compatible with this program definition. 
         /** Creates a new parameters object compatible with this program definition. 
         @remarks
         @remarks

+ 3 - 3
CamelotRenderer/Source/CmCgProgram.cpp

@@ -186,7 +186,7 @@ namespace CamelotEngine {
 		}
 		}
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    void CgProgram::unload(void)
+    void CgProgram::unload_internal(void)
     {
     {
         // Unload Cg Program
         // Unload Cg Program
         // Lowlevel program will get unloaded elsewhere
         // Lowlevel program will get unloaded elsewhere
@@ -199,7 +199,7 @@ namespace CamelotEngine {
             mCgProgram = 0;
             mCgProgram = 0;
         }
         }
 
 
-		HighLevelGpuProgram::unload();
+		HighLevelGpuProgram::unload_internal();
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     void CgProgram::buildConstantDefinitions() const
     void CgProgram::buildConstantDefinitions() const
@@ -474,7 +474,7 @@ namespace CamelotEngine {
     {
     {
         freeCgArgs();
         freeCgArgs();
 
 
-        unload();
+        unload_internal();
     }
     }
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
     bool CgProgram::isSupported(void) const
     bool CgProgram::isSupported(void) const

+ 5 - 0
CamelotRenderer/Source/CmGpuProgram.cpp

@@ -82,6 +82,11 @@ namespace CamelotEngine
 			mCompileError = true;
 			mCompileError = true;
 		}
 		}
     }
     }
+	//-----------------------------------------------------------------------------
+	void GpuProgram::unload_internal()
+	{
+		THROW_IF_NOT_RENDER_THREAD;
+	}
     //-----------------------------------------------------------------------------
     //-----------------------------------------------------------------------------
     bool GpuProgram::isSupported(void) const
     bool GpuProgram::isSupported(void) const
     {
     {

+ 3 - 1
CamelotRenderer/Source/CmHighLevelGpuProgram.cpp

@@ -72,7 +72,7 @@ namespace CamelotEngine
 		}
 		}
     }
     }
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
-    void HighLevelGpuProgram::unload()
+    void HighLevelGpuProgram::unload_internal()
     {   
     {   
         if (mAssemblerProgram != nullptr && mAssemblerProgram.get() != this)
         if (mAssemblerProgram != nullptr && mAssemblerProgram.get() != this)
         {
         {
@@ -82,6 +82,8 @@ namespace CamelotEngine
 		mConstantDefsBuilt = false;
 		mConstantDefsBuilt = false;
 		createParameterMappingStructures(true);
 		createParameterMappingStructures(true);
 		resetCompileError();
 		resetCompileError();
+
+		GpuProgram::unload_internal();
     }
     }
     //---------------------------------------------------------------------------
     //---------------------------------------------------------------------------
     HighLevelGpuProgram::~HighLevelGpuProgram()
     HighLevelGpuProgram::~HighLevelGpuProgram()