Supporting Multiple DirectX Versions

Started by
14 comments, last by ryan20fun 9 years, 2 months ago

Right now there is a problem:

vs_4_0 is working in DX11 but NOT working in DX9

vs_3_0 is NOT working in DX11 but working in DX9

NOT working means HRESULT (E_FAIL) When calling Device::CreateVertexBuffer()

Why?

Those are Vertex Shader versions, I do not see how that is affecting the creation of a Vertex Buffer.

Can you show the some code on how you are creating the resources?

If you have further issues I can post the relevent (sections of) code that I use.

HTH

Ryan.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

Advertisement

@ryan20fun: The following doesn't work, if I changed LPCSTR pProfile parameter from vs_3_0 to vs_4_0 it will work


 ID3D10Blob *VS, *PS;
 D3DX11CompileFromFile("shader.fx", 0, 0, "VS", "vs_3_0", 0, 0, 0, &VS, 0, 0);
 D3DX11CompileFromFile("shader.fx", 0, 0, "PS", "ps_3_0", 0, 0, 0, &PS, 0, 0);

 device->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
 device->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

@ryan20fun: The following doesn't work, if I changed LPCSTR pProfile parameter from vs_3_0 to vs_4_0 it will work


 ID3D10Blob *VS, *PS;
 D3DX11CompileFromFile("shader.fx", 0, 0, "VS", "vs_3_0", 0, 0, 0, &VS, 0, 0);
 D3DX11CompileFromFile("shader.fx", 0, 0, "PS", "ps_3_0", 0, 0, 0, &PS, 0, 0);

 device->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
 device->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

Hmm, I think it has to do with feature level( I have never tried using vs_3_0 before).

What happens if you use downleveled feature level like D3D_FEATURE_LEVEL_9_3?

Would it hurt to just use vs_4_0 when using D3D10+ ?

Unfortunetly I only used the Fixed Funciton Pipeline with D3D9, So I can not help you with any pointers with making a interface that would require minimal changes to use D3D9.

HTH

Ryan.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

I guess D3D11 doesn't support vs_3_0 / ps_3_0.

There is something I'm not sure if I'm doing correctly.

For vertex buffers, D3D9 uses IDirect3DVertexBuffer9 while D3D11 uses ID3D11Buffer

What is the correct way to create a struct that handle both so I can use it in IRenderer?

Here is what I have right now:


struct EngineVertexBuffer
{
       ID3D11Buffer *D3D9_VB;
       IDirect3DVertexBuffer9 *D3D11_VB;
};

@ryan20fun: The following doesn't work, if I changed LPCSTR pProfile parameter from vs_3_0 to vs_4_0 it will work


 ID3D10Blob *VS, *PS;
 D3DX11CompileFromFile("shader.fx", 0, 0, "VS", "vs_3_0", 0, 0, 0, &VS, 0, 0);
 D3DX11CompileFromFile("shader.fx", 0, 0, "PS", "ps_3_0", 0, 0, 0, &PS, 0, 0);

 device->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
 device->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);


@ryan20fun: The following doesn't work, if I changed LPCSTR pProfile parameter from vs_3_0 to vs_4_0 it will work


 ID3D10Blob *VS, *PS;
 D3DX11CompileFromFile("shader.fx", 0, 0, "VS", "vs_3_0", 0, 0, 0, &VS, 0, 0);
 D3DX11CompileFromFile("shader.fx", 0, 0, "PS", "ps_3_0", 0, 0, 0, &PS, 0, 0);

 device->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
 device->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);
Hmm, I think it has to do with feature level( I have never tried using vs_3_0 before).
What happens if you use downleveled feature level like D3D_FEATURE_LEVEL_9_3?

Would it hurt to just use vs_4_0 when using D3D10+ ?

Unfortunetly I only used the Fixed Funciton Pipeline with D3D9, So I can not help you with any pointers with making a interface that would require minimal changes to use D3D9.

HTH
Ryan.


D3D_FEATURE_LEVEL_9_3 does NOT support shader model 3, only SM 2.x.

Here are the correct shader compiler targets for Direct3D10Level9 feature levels (applies to DX10.1 and DX11.x, and I can guess the upcoming DX12): https://msdn.microsoft.com/en-us/library/jj215820.aspx#direct3d_9.1__9.2__and_9.3_feature_levels

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

For vertex buffers, D3D9 uses IDirect3DVertexBuffer9 while D3D11 uses ID3D11Buffer

What is the correct way to create a struct that handle both so I can use it in IRenderer?

Here is what I have right now:

struct EngineVertexBuffer
{
ID3D11Buffer *D3D9_VB;
IDirect3DVertexBuffer9 *D3D11_VB;
};

I would use two different implementations, But if you want to have one implementation to hold both versions for some reason then I would use a union and some type of global variable denotating which one to use.

So it would be:


class VertexBuffer : public GraphicsResource
{
  public:
     void*           GetObject() const;
     SomeVariable    GetVersion() const;

  private:
     union
     {
          ID3D11Buffer*             VB11;
          IDirect3DVertexBuffer9*   VB9;
     } u;
     SomeVariable     m_DirectXVersion;
}

HTH

Ryan.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

This topic is closed to new replies.

Advertisement