[SlimDX] D3DERR_INVALIDCALL

Started by
6 comments, last by Stormtrooper 15 years, 9 months ago
(Hope its not a problem me asking all these questions, hopefully this one isn't quite as simple as the last one) Ok I'm trying to set up shaders for the first time. I'm getting a D3DERR_INVALIDCALL at this line: _spriteEffect.SetValue("g_samSrcColor", _testSprite); And this shader:
sampler2D g_samSrcColor;

float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 Color;
    
    Color = tex2D( g_samSrcColor, Tex.xy)*10;
    return Color;
}


technique TestShader
{
    pass p1
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 MyShader();
    }

}
When I comment out that line, everything works fine and the texture gets rendered but without the shader. What could be wrong? _testSprite is a Texture.
Advertisement
I don't believe a "sampler2D" is the same thing as a "texture".
Mike Popoloski | Journal | SlimDX
I checked that out and tried using "texture" and "Texture2D" and they both crash at

_spriteEffect = Effect.FromFile(_device, "shader.fx", ShaderFlags.None);

with an E_FAIL: Undetermined error occurred.
Quote:
I checked that out and tried using "texture" and "Texture2D" and they both crash at

_spriteEffect = Effect.FromFile(_device, "shader.fx", ShaderFlags.None);

with an E_FAIL: Undetermined error occurred.

texture g_samSrcColor;float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0{    float4 Color;        Color = tex2D( g_samSrcColor, Tex.xy)*10;    return Color;}technique TestShader{    pass p1    {        VertexShader = null;        PixelShader = compile ps_2_0 MyShader();    }}

This (your original shader with the sampler replaced by texture) is what you tried, yes? This is an invalid shader:
Quote:
> fxc.exe /Tfx_2_0 test.fx
Microsoft (R) D3D10 Shader Compiler 9.23.949.2378
Copyright (C) Microsoft Corporation 2002-2007. All rights reserved.

test.fx(7,13): error X3017: 'tex2D': cannot implicitly convert from 'const texture' t o 'const sampler2D'

compilation failed; no code produced


You need a texture to set from the CPU and a sampler to bind. You might want to look at how some of the shaders that use textures in the DirectX samples are written.
Ok sweet, this worked and didn't return any errors, but the effect doesn't get rendered.

texture myTexture;sampler2D texSampler0 : TEXUNIT0 = sampler_state{	Texture	  = (myTexture);    MIPFILTER = LINEAR;    MAGFILTER = LINEAR;    MINFILTER = LINEAR;};float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0{    float4 Color;        Color = tex2D( texSampler0, Tex.xy)*10;    return Color;}technique TestShader{    pass p1    {        VertexShader = null;        PixelShader = compile ps_2_0 MyShader();    }}


        // Putting draw sprite here just for testing        public void BeginScene()        {            _device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);            _device.BeginScene();            _sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotSaveState);            _spriteEffect.Begin(FX.None);            _spriteEffect.BeginPass(0);            drawSprite(_testSprite, new Rectangle(32, 0, 32, 32), new Point(32, 32), Color.White);        }        /// <summary>        /// Ends the scene        /// </summary>        public void EndScene()        {            _spriteEffect.EndPass();            _spriteEffect.End();            _sprite.End();            _device.EndScene();         }


Got the shader code from here
Mandatory link to the debug runtimes.
Ok I did that and used Debug View and I get quite a bit of errors, unfortunately I don't know what to do about it. It says that "Total of 4 objects still alive" after I close the program. So I assume there are objects that need to be freed or cleaned up upon closing? Right now, my renderer has a Dispose method that calls _device.Dispose()

[2788] Direct3D9: (INFO) :======================= Hal SWVP device selected [2788] [2788] Direct3D9: (INFO) :Using P4 PSGP [2788] [2788] D3D9 Helper: Warning: Default value for D3DRS_POINTSIZE_MAX is 2.19902e+012f, not 1.44115e+017f.  This is ok. [2788] Total of 4 objects still alive.[2788] Direct3D9: (ERROR) :    [0] : Address 0483E4CB[2788] [2788] Direct3D9: (ERROR) :    [1] : Address 0483E59B[2788] [2788] Direct3D9: (ERROR) :    [2] : Address 0483E440[2788] [2788] Direct3D9: (ERROR) :    [3] : Address 04832DB4[2788] [2788] Direct3D9: (ERROR) :    [4] : Address 4FDFAF2E[2788] [2788] Direct3D9: (ERROR) :    [5] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [6] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [7] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [8] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [9] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [10] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [11] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [12] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [13] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [14] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [15] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [0] : Address 048350D4[2788] [2788] Direct3D9: (ERROR) :    [1] : Address 04835EBF[2788] [2788] Direct3D9: (ERROR) :    [2] : Address 048365F8[2788] [2788] Direct3D9: (ERROR) :    [3] : Address 04832DD5[2788] [2788] Direct3D9: (ERROR) :    [4] : Address 4FDFAF2E[2788] [2788] Direct3D9: (ERROR) :    [5] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [6] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [7] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [8] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [9] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [10] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [11] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [12] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [13] : Address 00000000[2788] [2788] Direct3D9: (ERROR) :    [14] : Address 00000000...keeps going with the Direct3D9 ERROR


Ok, I fixed the errors by disposing the effet, the sprite, the texture, and the device. No more DX errors, but still no shader effect. Do I need to compile the shader or something?

EDIT: I also compiled my shader with the fxc.exe and it compiles fine.

This topic is closed to new replies.

Advertisement