2

When I am trying to load a Shader result from memory the compiler says: one or more arguments are invalid. Shader compiling successfully but it seems after D3DCompileFromFile() command in memory is something not correct and ID3DBlob interface does not get correct values for some reason.

ID3DBlob*  pBlobFX = NULL;
ID3DBlob*  pErrorBlob = NULL;
hr = D3DCompileFromFile(str, NULL, NULL, NULL, "fx_5_0", NULL, NULL,  &pBlobFX, &pErrorBlob);  //  OK
if (FAILED(hr))
{
    if (pErrorBlob != NULL)
        OutputDebugStringA((char *)pErrorBlob->GetBufferPointer());
    SAFE_RELEASE(pErrorBlob);
    return hr;
}

//  Create the  effect
hr = D3DX11CreateEffectFromMemory(pBlobFX->GetBufferPointer(), pBlobFX->GetBufferSize(), 0, pd3dDevice, ppEffect); //  Error:  E_INVALIDARG One or more arguments are invalid
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90

1 Answers1

0

The legacy DirectX SDK version of Effects for Direct3D 11 only included D3DX11CreateEffectFromMemory for creating effects which required using a compiled shader binary blob loaded by the application.

The latest GitHub version includes the other expected functions:

  • D3DX11CreateEffectFromFile which loads a compiled binary blob from disk and then creates an effect from it.

  • D3DX11CompileEffectFromMemory which uses the D3DCompile API to compile a fx file in memory and then create an effect from it.

  • D3DX11CompileEffectFromFile which uses the D3DCompile API to compile a provided fx file and then create an effect from it.

Using D3DX11CompileEffectFromFile instead of trying to do it manually as the original poster tried is the easiest solution here.

The original library wanted to strongly encourage using build-time rather than run-time compilation of effects. Given that the primary use of Effects 11 today is developer education, this was unnecessarily difficult for new developers to use so the GitHub version now includes all four possible options for creating effects.

Note: The fx_5_0 profile in the HLSL compiler is deprecated, and is required to use Effects 11.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Chuck did i understand correctly ?! i mustn't point shader flag in function "fx_5_0" or what ? :) – Achiko Mezvrishvili Feb 16 '16 at 06:18
  • I'm saying that you can use Effects 11 and the latest HLSL compiler still supports the required ``fx_5_0`` profile, *however* it is considered a deprecated feature. See [this thread](https://fx11.codeplex.com/discussions/450240) for more details. – Chuck Walbourn Feb 17 '16 at 01:13