Advertisement

Failing to create shader - help

Started by June 13, 2018 09:25 PM
9 comments, last by Alberth 6 years, 7 months ago

Hi guys, I'm trying to learn this stuff but running into some problems ?

I've compiled my .hlsl into a header file which contains the global variable with the precompiled shader data:


//...

// Approximately 83 instruction slots used
#endif

const BYTE g_vs[] =
{
     68,  88,  66,  67, 143,  82, 
     13, 236, 152, 133, 219, 113, 
    173, 135,  18,  87, 122, 208, 
    124,  76,   1,   0,   0,   0, 
     16,  76,   0,   0,   6,   0, 

//....

And now following the "Compiling at build time to header files" example at this msdn link , I've included the header files in my main.cpp and I'm trying to create the vertex shader like this:


	hr = g_d3dDevice->CreateVertexShader(g_vs, sizeof(g_vs), nullptr, &g_d3dVertexShader);
	if (FAILED(hr))
	{
		return -1;
	}

and this is failing, entering the if and returing -1.

Can someone point out what I'm doing wrong? ? 

Forget about that, I'm trying this way now, and still doesn't work:


	//Load Shaders

	ID3DBlob* vsBlob = nullptr;
	D3DReadFileToBlob(L"../Shaders/SimpleVertexShader.cso", &vsBlob);

	assert(vsBlob);
	assert(g_d3dDevice);

	hr = g_d3dDevice->CreateVertexShader(vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), nullptr, &g_d3dVertexShader);
	SafeRelease(vsBlob);
	if (FAILED(hr))
	{
		return -1;
	}

hr is failing with E_INVALIDARG...what am I doing wrong? ç_ç

Advertisement

Seems it works if I compile using Shader Model 5.0 but not with Shader Model 5.1... why?! o_O

Feature level is D3D_FEATURE_LEVEL_11_0.

I have this vga here and it seems it supports shader model 5.1, so I'm confused ?

 

Hello,

 

From this page : https://msdn.microsoft.com/en-us/library/windows/desktop/dn933277(v=vs.85).aspx

"HLSL Shader Model 5.1, introduced with D3D12 and D3D11.3."

 

You need to create your device with at least a DirectX 11.3 feature level to use shader model 5.1. You are currently on feature level 11.0

there is no option for 11.3 though, the only D3D11 flags are 


        D3D_FEATURE_LEVEL_11_0	= 0xb000,
        D3D_FEATURE_LEVEL_11_1	= 0xb100,

and if I use D3D_FEATURE_LEVEL_11_1, then my app will give error somewhere along the way...shouldn't my VGA be capable of handling D3D_FEATURE_LEVEL_11_1? Why did they make it so confusing? x_x

To leverage the 11.3 feature level you actually have to create your 11.0 device as you actually do and then query the ID3D11Device3 interface on it.

The sample at this link make use of it : https://github.com/walbourn/directx-sdk-samples/blob/master/DXUT/Core/DXUT.cpp

 


#ifdef USE_DIRECT3D11_3
    // Direct3D 11.3
    {
        ID3D11Device3* pd3d11Device3 = nullptr;
        hr = pd3d11Device->QueryInterface( IID_PPV_ARGS(&pd3d11Device3) );
        if (SUCCEEDED(hr) && pd3d11Device3)
        {
            GetDXUTState().SetD3D11Device3(pd3d11Device3);

            ID3D11DeviceContext3* pd3dImmediateContext3 = nullptr;
            hr = pd3dImmediateContext->QueryInterface(IID_PPV_ARGS(&pd3dImmediateContext3));
            if (SUCCEEDED(hr) && pd3dImmediateContext3)
            {
                GetDXUTState().SetD3D11DeviceContext3(pd3dImmediateContext3);
            }
        }
    }
#endif

As you can see the pd3d11Device is the equivalent of your 11.0 device and the ID3D11Device3 interface is retrieved from it. ID3D11Device3 exposes all the new 11.3 methods that weren't there before.

 

Here's the microsoft reference to that interface : https://msdn.microsoft.com/en-us/library/windows/desktop/dn899218(v=vs.85).aspx

 

Also don't be too surprised if the website that you linked mention that it support DX12 and some other feature level while it doesn't. It's a relatively old card after all : https://forums.geforce.com/default/topic/1001222/nvidia-gtx-480-dx-12-/

Advertisement

Thank you @ChuckNovice, you've been most helpful :)

Shader model 5.1 isn't supported by DX11 at all, only DX12. There is no FL11.3, and successfully querying the ID3D11Device3 interface indicates that your OS has "DX11.3" but you don't actually need to query that interface to use those features - unless they're only available on that interface.

Also still on the subject, regarding the first method I was trying to use in this post to load the shader (include the precompiled shader in header form), on MVS it frooze the IDE because I acidentally passed the mouse over the global variable I was trying to use and the IDE attempted to display the content of it (12.000 bytes) in a "popup window" in this form here :

cIUdRYY.png

Happened 3 times, that's why I had to switch method.

Did this happened to you guys too? How do you deal with it?

This topic is closed to new replies.

Advertisement