Jump to content
  • Advertisement
Sign in to follow this  
Woodchuck

HLSL constant table problem

This topic is 4834 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 a problem with the JUN 2005 SDK Update that i haven't with the SUMMER 2004 one. I compile shader from file (.fx) and want to use the constant table of a vertex shader to set a matrix. My problem is that the handle return by GetConstantByName is NULL. Here is the code of shader compilation :
void JOYFX_Init(LPDIRECT3DDEVICE9 d3ddevice,char fx_name[], s_JOYFx &fx)
{
	DWORD dwShaderFlags = 0;
	LPD3DXBUFFER pCode   = NULL;
    LPD3DXBUFFER pErrors = NULL;
	HRESULT hr;
	char name[200];
	HANDLE hFile, hMap;	
	DWORD* dwpVS;

	strcpy(name,JOYFXPATH);
	strcat(name,fx_name);
	strcat(name,".fx");

	fx.isinitiate = false;

	hr = D3DXCompileShaderFromFile(name,NULL,NULL,"VS",/*D3DXGetVertexShaderProfile(d3ddevice)*/"vs_2_a",dwShaderFlags,&pCode,&pErrors,&fx.fx_vconstants);
	if(FAILED(hr))
	{
		LOG_Writenl("D3DXCompileShaderFromFile failled : fx.");
		LOG_Writenl((char*)pErrors->GetBufferPointer());
		pErrors->Release();
			
		strcpy(name,JOYFXPATH);
		strcat(name,fx_name);
		strcat(name,".vso");
		
		hFile = CreateFile(name, GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

		if(hFile != INVALID_HANDLE_VALUE) 
		{
			if(GetFileSize(hFile,0) > 0) 
				hMap = CreateFileMapping(hFile,0,PAGE_READONLY,0,0,0);
			else
			{
				CloseHandle(hFile);
				return;		
			}
		}	
		else
		{
			return;	
		}
		
		dwpVS = (DWORD *)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);

		hr = d3ddevice->CreateVertexShader(dwpVS,&fx.fx_vshader);
		if(FAILED(hr))
		{
			CloseHandle(hFile);
			LOG_Writenl("CreateVertexShader failled : fx.");
			LOG_Writenl(name);
			return;
		}

		unsigned char *function;
		unsigned int size;

		fx.fx_vshader->GetFunction(NULL,&size);
		function = new unsigned char[size];
		fx.fx_vshader->GetFunction(function,&size);
		hr = D3DXGetShaderConstantTable((DWORD*)function,&fx.fx_vconstants);
		if(FAILED(hr))
		{
			delete [] function;
			CloseHandle(hFile);
			LOG_Write("D3DXGetShaderConstantTable failled : fx.");
			LOG_Writenl(name);
			return;
		}
		delete [] function;

		CloseHandle(hFile);
	}
	else
	{
		hr = d3ddevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(),&fx.fx_vshader);
		if(FAILED(hr))
		{
			LOG_Writenl("D3DXCompileShaderFromFile failled : fx.");
			LOG_Writenl((char*)pErrors->GetBufferPointer());
			pErrors->Release();

			return;
		}
		pCode->Release();
	}

	strcpy(name,JOYFXPATH);
	strcat(name,fx_name);
	strcat(name,".fx");

	hr = D3DXCompileShaderFromFile(name,NULL,NULL,"PS",/*D3DXGetPixelShaderProfile(d3ddevice)*/"ps_2_b",dwShaderFlags,&pCode,&pErrors,&fx.fx_pconstants);
	if(FAILED(hr))
	{
		LOG_Write("D3DXCompileShaderFromFile failled : ");LOG_Write(name);LOG_Writenl(".");
		LOG_Writenl((char*)pErrors->GetBufferPointer());
		pErrors->Release();

		strcpy(name,JOYFXPATH);
		strcat(name,fx_name);
		strcat(name,".pso");

		hFile = CreateFile(name, GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
		if(hFile != INVALID_HANDLE_VALUE) 
		{
			if(GetFileSize(hFile,0) > 0) 
				hMap = CreateFileMapping(hFile,0,PAGE_READONLY,0,0,0);
			else
			{
				CloseHandle(hFile);
				return;		
			}
		}	
		else
		{
			return;	
		}

		dwpVS = (DWORD *)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);

		hr = d3ddevice->CreatePixelShader(dwpVS,&fx.fx_pshader);
		if(FAILED(hr))
		{
			CloseHandle(hFile);
			LOG_Writenl("CreatePixelShader failled : fx.");
			LOG_Writenl(name);
			return;
		}

		unsigned char *function;
		unsigned int size;

		fx.fx_pshader->GetFunction(NULL,&size);
		function = new unsigned char[size];
		fx.fx_pshader->GetFunction(function,&size);
		hr = D3DXGetShaderConstantTable((DWORD*)function,&fx.fx_pconstants);
		if(FAILED(hr))
		{
			delete [] function;
			CloseHandle(hFile);
			LOG_Write("D3DXGetShaderConstantTable failled : fx.");
			LOG_Writenl(name);
			return;
		}
		delete [] function;

		CloseHandle(hFile);
	}
	else
	{
		hr = d3ddevice->CreatePixelShader((DWORD*)pCode->GetBufferPointer(),&fx.fx_pshader);
		if(FAILED(hr))
		{
			LOG_Writenl("CreatePixelShader failled : ");LOG_Write(name);LOG_Writenl(".");
			LOG_Writenl((char*)pErrors->GetBufferPointer());
			pErrors->Release();

			return;
		}
		pCode->Release();
	}

	fx.isinitiate = true;
}
and the matrix setting one :
handle = fx_morphlet.fx_vconstants->GetConstantByName(NULL,("scale_matrix"));
		if(handle)hr = fx_morphlet.fx_vconstants->SetMatrix(lp_d3ddevice,handle,&mat);
		else LOG_Writenl((int)handle);
It really works with the summer 2004 sdk update and not with the jun 2005 one. Note that there is no error returned by the JOYFX_Init() function. Any help is welcome Thanks Chuck

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!