Unable to compile shader

Started by
7 comments, last by Bacterius 11 years, 10 months ago
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.
Advertisement
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);
}
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"
Yeah ps_1_1 is only supported with the legacy compiler, which requires the D3DXSHADER_USE_LEGACY_D3DX9_31_DLL flag.
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.

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.
Ancient chipsets are a huge pain to work with. This is 2012, I think a hardware [s]overhaul[/s] [s]upgrade[/s] renovation is called for unsure.png

I understand that vertex shaders can be emulated in software but I thought pixel shaders were ALWAYS hardware nowadays.[/quote]
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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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?
Or is this system really no longer worth upgrading?[/quote]
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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

This topic is closed to new replies.

Advertisement