Sign in to follow this  

Strange Effect problem

This topic is 2843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I've got another problem: The Effect-File, made by my Shader-Editor, can get compiled without any problems. I do it with D3D10PreprocessShader(), which precompiles the Shader and puts the data into a Blob-Interface. This Blob is saved to a Package file, but this has nothing to do with the problem. Right after precompiling, I want to create the Effect via D3DX10CreateEffectFromMemory(). DirectX10 returns S_OK here, but then, those strange things appear: I have only 1 technique in that shader, but some other are using 2. So I allways try to get both:
NormalRenderTechnique=MyShader->GetTechniqueByName("RenderTechnique");
SelectedRenderTechnique=MyShader->GetTechniqueByName("RenderSelected");

As they both were NULL before that, they both got now the memory-address! And thats not all: I want to create the Input layout after this, but when I try to get the pass (Only 1 in the shader), DX10 doesn't find it, I think, because all members of the PassDesc structure are the same as before the call. And so, the CreateInputLayout() call fails. Here is the sourcecode of all that:
SaveScintillaToFile("TempShader.fx",ShaderEditor.Scintillahw);  //Save the Editor-Contents to a textfile
			
			Pck=NULL;
			TheScene.PckHandler->FindPackageByName(LPS ShaderEditor.FilePackage,&Pck); //Find the right Package
			
			if(Pck)
			{
				WCHAR Source[MAX_PATH];

				wcscpy(LPS Source,LPS ShaderEditor.LoadedFile);
				wcscat(LPS Source,L".Source"); //Apply .Source, for the Package-version of the shader

				

				ID3D10Blob* ShaderBlob;
				ID3D10Blob*	Blob_Errors;
				Blob_Errors=NULL;
				ShaderBlob=NULL;
				
				//First try to precompile, I don't think, that this was the right function
				//D3DX10CompileFromFile(L"TempShader.fx", NULL, NULL,NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, NULL, NULL, &ShaderBlob,&Blob_Errors,NULL);
				
				byte* Data;
				UINT Size;

				//Get the Data of the TempShader.fx file (from disk)
				Pck->GetFileData(L"TempShader.fx",&Data,&Size);

				WShaderInclude Inc; //Include Interface
				D3D10PreprocessShader((LPCSTR)Data,Size,NULL,NULL,&Inc,&ShaderBlob,&Blob_Errors); //Precompile it!

				delete[] Data;
				char* Errors;
				if(Blob_Errors) //I get no error messages...
				{
					Errors=(char *)Blob_Errors->GetBufferPointer();

					CHAR Msg[1024];

					strcpy((char *)&Msg,Errors);

					MessageBoxA(NULL,(char *)&Msg,"There are errors in that file!",MB_OK | MB_ICONERROR);

					Blob_Errors->Release();
				}else
				{
					InfoBox(L"Compilation succeeded!"); //... so the compilation succeeds
					Pck->AppendMemory(LPS ShaderEditor.LoadedFile,ShaderBlob->GetBufferPointer(),ShaderBlob->GetBufferSize()); //Append the precompiled shader to the package
					

					Pck->AppendFile(L"TempShader.fx",LPS Source); //Append the sourcecode for later editing

					TreeInfo* TI;
					Browser.GetTreeInfoByTreeItem(ShaderEditor.TreeItem,&TI); //Get the TargetShader

					WShader* Shd=(WShader *)TI->Target;
					Shd->CreateShaderFromFile(NULL,NULL,NULL,ShaderBlob->GetBufferPointer(),ShaderBlob->GetBufferSize(),true); //Compile it

					ShaderBlob->Release();
				
				}
			
			}

The Create-Effect function:
HRESULT WShader::CreateShaderFromFile(LPWSTR Path,LPWSTR Package,LPWSTR File,LPVOID Memory,long MemSize,bool bIKnowWhatIAmDoingWhenIPassNoPackageInformation,bool bPooled)
{
	HRESULT hr;

	WCHAR Dir[256];

	if(bIKnowWhatIAmDoingWhenIPassNoPackageInformation==false)
	{
		if(Path!=NULL)
		{
			WarnBox(L"Warning! [w]tech is about to load a Shader from a file! This is NOT recommend!");
			if(wcslen(Path)<=0)
			{
				ErrorBox(L"Error! You passed a path without any characters to CreateShaderFromFile()!");
				return E_FAIL;
			}
		}
		
		if(Package!=NULL)
		{
			if(wcslen(Package)<=0)
			{
				ErrorBox(L"Error! You passed a Package-Name without any characters to CreateShaderFromFile()!");
				return E_FAIL;
			}
		}

		if(File!=NULL)
		{
			if(wcslen(File)<=0)
			{
				ErrorBox(L"Error! You passed a File-Name in a package without any characters to CreateShaderFromFile()!");
				return E_FAIL;
			}
		}
		CheckNULL(Package)wcscpy(LPS ShaderFileInfo.Package,Package); //Save, where we found the Shader
		CheckNULL(File)wcscpy(LPS ShaderFileInfo.File,File);
		CheckNULL(Path)wcscpy(LPS ImportPath,Path);
	}
	GetCurrentDirectory(256,LPS Dir); //Debuging

	Cleanup(); //if we already have some data
	DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
	
	ID3D10EffectPool* Pool=NULL;

	if(SharedParams && bPooled==true)
	{
		Pool=(ID3D10EffectPool*)(*SharedParams->EffectPool); //Use a pool, if we want to
	}
	

	if(Path!=NULL)
	{
		wcscpy(LPS ImportPackage,Path); //Create one from a file, THATS NOT GOOD!
		V_RETURN(D3DX10CreateEffectFromFile( Path, NULL, NULL, "fx_4_0", dwShaderFlags, 0, DXUTGetD3D10Device(), Pool,
                                              NULL, &MyShader, NULL, NULL ) );
	}else
	{
		if(bPooled) //Pooled or not?
		{
			WShaderInclude Inc;

			//void* ShaderData;
			//UINT DataSize;
			//Inc.Open(D3D10_INCLUDE_LOCAL,"wTechBaseShader.fx",Memory,(LPCVOID *)&ShaderData,&DataSize);
			V_RETURN(D3DX10CreateEffectFromMemory(Memory,MemSize,"None",0,&Inc, "fx_4_0", dwShaderFlags, 0, DXUTGetD3D10Device(), Pool,
												  NULL, &MyShader, NULL, NULL ) );

			//Inc.Close(ShaderData);
			
		}else
		{//Not pooled
			V_RETURN(D3DX10CreateEffectFromMemory(Memory,MemSize,"None",0,0, "fx_4_0", dwShaderFlags, 0, DXUTGetD3D10Device(), Pool,
												  NULL, &MyShader, NULL, NULL ) ); //Succeeds!
		}
	}
	
	NormalRenderTechnique=NULL;
	SelectedRenderTechnique=NULL;
	RenderTechnique=NULL;
	NormalRenderTechnique=MyShader->GetTechniqueByName("RenderTechnique"); //Get the techniques <--- seems to fail
	SelectedRenderTechnique=MyShader->GetTechniqueByName("RenderSelected");

	RenderTechnique=NormalRenderTechnique;

	UINT numElements = sizeof( BasicVertexLayout ) / sizeof( BasicVertexLayout[0] );

    // Create the input layout
    D3D10_PASS_DESC PassDesc;
    RenderTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc ); //<--- Seems to fail!
    V_RETURN( DXUTGetD3D10Device()->CreateInputLayout( BasicVertexLayout, numElements, PassDesc.pIAInputSignature,
                                             PassDesc.IAInputSignatureSize, &VertexLayout ) ); //Create the layout

//....

Any suggestions?

Share this post


Link to post
Share on other sites

This topic is 2843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this