Jump to content

  • Log In with Google      Sign In   
  • Create Account

Unable to compile shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Fredericvo   Members   -  Reputation: 378

Like
0Likes
Like

Posted 15 June 2012 - 11:13 AM

OK so I'm trying to move away from the FFP and step into the world of shaders and the first thing I get is an error LOL.
I'm trying to get www.two-kings.de 's tutorial #18 to work but the pixel shader doesn't seem to compile. The executable they delivered worked on my computer but if I compile myself and run the program then the pixel shader fails)

I'm trying to isolate the problem so I made the following little C program

#include <d3dx9.h>
#include <stdio.h>
#include <D3DX9Shader.h>

#pragma comment (lib, "d3dx9.lib")

LPDIRECT3DPIXELSHADER9 pixelShader = NULL;			
LPD3DXBUFFER code = NULL;

int main() {

HRESULT result;
result = D3DXCompileShaderFromFile( "pixel.psh",   //filepath
										NULL,		  //macro's			
										NULL,		  //includes		  
										"ps_main",	 //main function	  
										"ps_1_1",	  //shader profile	
										0,			 //flags			  
										&code,		 //compiled operations
										NULL,		  //errors
										NULL);		 //constants
	if(FAILED(result))
		printf("failed: %p %d %d\n",result,result,D3DERR_INVALIDCALL);
	printf("failed: %p %d %d\n",result,result,D3DXERR_INVALIDDATA);
	printf("failed: %p %d %d\n",result,result,E_OUTOFMEMORY);
	Return 0;

}

Here is the supposed pixel shader

// Pixel shader input structure
struct PS_INPUT
{
	float4 Position   : POSITION;
	float2 Texture	: TEXCOORD0;
};


// Pixel shader output structure
struct PS_OUTPUT
{
	float4 Color   : COLOR0;
};


// Global variables
sampler2D Tex0;


// Name: Simple Pixel Shader
// Type: Pixel shader
// Desc: Fetch texture and blend with constant color
//
PS_OUTPUT ps_main( in PS_INPUT In )
{
	PS_OUTPUT Out;							   //create an output pixel

	Out.Color = tex2D(Tex0, In.Texture);		 //do a texture lookup
	Out.Color *= float4(0.9f, 0.8f, 0.4, 1);	 //do a simple effect

	return Out;								  //return output pixel
}

And sure enough it fails but with none of the standard error values sch as D3DXERR_INVALIDDATA or something like that.

The vertex shader compiles fine.

Sponsor:

#2 MJP   Moderators   -  Reputation: 11315

Like
0Likes
Like

Posted 15 June 2012 - 11:38 AM

The compilation errors are returned to you in the ppErrorMsgs parameter. It will be in an ID3DXBuffer object, so you just need to call GetBufferPointer and cast the pointer to char* to read it as a string.

HRESULT result;
ID3DXBuffer* errors = NULL;
result = D3DXCompileShaderFromFile( "pixel.psh",	 //filepath
								    NULL,		    //macro's
								    NULL,		    //includes
								    "ps_main",	   //main function
								    "ps_1_1",	    //shader profile
								    0,			   //flags
								    &code,		   //compiled operations
								    &errors,		 //errors
								    NULL);		   //constants
if(FAILED(result)) {
    const char* errstring = "";
    if(errors != NULL)
	    errstring = reinterpret_cast<const char*>(errors->GetBufferPointer());
    printf("failed: %s", errstring);
}

Edited by MJP, 15 June 2012 - 11:41 AM.


#3 turch   Members   -  Reputation: 590

Like
0Likes
Like

Posted 15 June 2012 - 12:32 PM

Try compiling it with fxc.exe, it should be in your <Microsoft DirectX SDK dir>/Utilities/bin/x86 directory.

With my version of fxc, I get "ps_1_x is no longer supported" (the vertex shader compiles with vs_1_1), so try using "ps_2_0"

Edited by turch, 15 June 2012 - 12:41 PM.


#4 MJP   Moderators   -  Reputation: 11315

Like
0Likes
Like

Posted 15 June 2012 - 01:18 PM

Yeah ps_1_1 is only supported with the legacy compiler, which requires the D3DXSHADER_USE_LEGACY_D3DX9_31_DLL flag.

#5 Fredericvo   Members   -  Reputation: 378

Like
0Likes
Like

Posted 16 June 2012 - 09:46 AM

Thanks guys it worked. I had to either compile as ps 2.0 or use the following flag D3DXSHADER_USE_LEGACY_D3DX9_31_DLL

This being said I'm very surprised that it runs on my computer because I have no graphics adapter and use a built-in S3 Unichrome Pro IGP. (about the lamest video chip you can have for 3D)
I understand that vertex shaders can be emulated in software but I thought pixel shaders were ALWAYS hardware nowadays.
I haven't created a REF device but a D3DDEVTYPE_HAL.

Edited by Fredericvo, 16 June 2012 - 10:01 AM.


#6 Fredericvo   Members   -  Reputation: 378

Like
0Likes
Like

Posted 16 June 2012 - 10:09 AM

Thanks guys it worked. I had to either compile as ps 2.0 or use the following flag D3DXSHADER_USE_LEGACY_D3DX9_31_DLL

This being said I'm very surprised that it runs on my computer because I have no graphics adapter and use a built-in S3 Unichrome Pro IGP. (about the lamest video chip you can have for 3D)
I understand that vertex shaders can be emulated in software but I thought pixel shaders were ALWAYS hardware nowadays.
I haven't created a REF device but a D3DDEVTYPE_HAL.


My bad I realise that the program runs (rather than crashes) but the pixel shader has no effect. Only if I DO use a REF device does it really work (painfully slow though as expected) so my S3 card is as bad as I thought LOL.

#7 Bacterius   Crossbones+   -  Reputation: 8852

Like
0Likes
Like

Posted 16 June 2012 - 11:05 AM

Ancient chipsets are a huge pain to work with. This is 2012, I think a hardware overhaul upgrade renovation is called for Posted Image

I understand that vertex shaders can be emulated in software but I thought pixel shaders were ALWAYS hardware nowadays.

The REF device emulates everything, I believe - it simply ignores whatever graphics hardware you have. It basically behaves as if you had a fully featured, correctly working graphics card (minus the speed). The "software" device (i.e. HAL device with software assistance) however only emulates rasterization and vertex shading. As it should, anyway, I mean if the CPU starts texturing pixels you may as well plug the DVI cable in it and call it a day.

Edited by Bacterius, 16 June 2012 - 11:09 AM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#8 Fredericvo   Members   -  Reputation: 378

Like
0Likes
Like

Posted 16 June 2012 - 11:30 AM

Talking about HW overhaul I'm on a budget.
Since I still have a lot to learn I believe that even an older card with vs/ps model 3.0 or so might suffice and if I were to market a game I'd want a larger audience anyway and I don't think I could wow hardcore gamers who want the greatest and the latest before long. What AGP8x card would be good? I have an AMD Sempron 3200+ on a k8m400 mobo. Or is this system really no longer worth upgrading? Maybe an i3 is the least I should consider?

#9 Bacterius   Crossbones+   -  Reputation: 8852

Like
0Likes
Like

Posted 17 June 2012 - 07:01 AM

Or is this system really no longer worth upgrading?

That would be my opinion. It has fallen too far behind, "upgrading" would basically mean replacing:
- the processor
- the graphics card
- the motherboard to go with the new processor and possibly graphics card (often overlooked)
- the power supply unit as your new hardware may require more power and possibly more cables
- any accessories no longer compatible with the new motherboard
In short, everything.

It is true that you don't need the greatest and latest to make games, however working on obsolete hardware is something I simply cannot recommend to anyone. It's not so much the performance itself, which is probably fine, but it's the compatibility and relevance to modern techniques that's the issue here. It's annoying, painful, and ultimately a waste of time as you will not have access to the more recent API's, and some graphics algorithms may require specific manipulations impossible to achieve on your side without hacks (think vertex shader texture lookup, depth buffer manipulation, etc...)

A card like the GeForce 210 is dirt cheap nowadays and while it's not exactly mainstream anymore, it is plenty fast enough for comfortable game development and actually has shader model 4 (DX10), which means you would be able to use most if not all state-of-the-art graphics techniques, for instance. Of course, if you don't have a PCI-E interface on your k8m400, you'll need an AGP graphics card and those have started to become collector material, if you get my drift.

Let's not get off topic, though. A Lounge topic would be more appropriate to discuss hardware upgrade considerations.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS