Finally, a DirectX 10 video driver for Irrlicht

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Granyte »

I would say i'm setting to much constant and i'm setting lots of them several time a frame

And I found that pesky memory leak around line 270 the current unlock method looks like this

Code: Select all

 
//! unlock function
void CD3D11Texture::unlock()
{
    if (!Texture)
        return;
 
    // unlock texture buffer
    if (TextureType == ETT_3D)
    {
 
 
        Context->Unmap(TextureBuffer, 0);
    }
    else
    {
        Context->Unmap(TextureBuffer, D3D11CalcSubresource(MipLevelLocked, ArraySliceLocked, NumberOfMipLevels));
    }
    // copy texture buffer to main texture ONLY if buffer was write
    if (LastMapDirection & D3D11_MAP_WRITE)
    {
        Context->CopyResource( Texture, TextureBuffer );
    }
 
}
when it should be like this

Code: Select all

 
//! unlock function
void CD3D11Texture::unlock()
{
    if (!Texture)
        return;
 
    // unlock texture buffer
    if (TextureType == ETT_3D)
    {
 
 
        Context->Unmap(TextureBuffer, 0);
    }
    else
    {
        Context->Unmap(TextureBuffer, D3D11CalcSubresource(MipLevelLocked, ArraySliceLocked, NumberOfMipLevels));
    }
    // copy texture buffer to main texture ONLY if buffer was write
    if (LastMapDirection & D3D11_MAP_WRITE)
    {
        Context->CopyResource( Texture, TextureBuffer );
    }
    TextureBuffer->Release();
    TextureBuffer = NULL;
}
EDIT: oups forgot my version has 3d texture but the method should still be quite similar


EDIT 2 : and I found the performance hog the gui is killing every bit of performance
with the gui enabeled dx9 beat dx11 by nearly 50% with dx 9 hovering around 90 fps and dx11 around 45
and with the gui disabeled dx 11 beat dx 9 by about 10 % with dx 9 around 110 and dx 11 around 120

(and dx11 was probably at a disadvantage while It ran this because one of my shader is to complex for dx 9)

So something need to be done about the gui ill figure what can be done tomorrow

EDIT 3 : I have ye to do something about the gui but until then I have this to show
Image
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Granyte »

I fixed the Blending issue on dx11

it was due to all the fixed pipeline material renderers setting their blending property after setting the blend state wich ment their actual blendstate was only applied to the next node

Code: Select all

virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
        bool resetAllRenderstates, IMaterialRendererServices* services)
    {
        CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
        if (material.MaterialType != lastMaterial.MaterialType ||
            material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
            resetAllRenderstates)
        {
            D3D11_BLEND_DESC& blendDesc = static_cast<CD3D11Driver*>(Driver)->getBlendDesc();
 
            E_BLEND_FACTOR srcFact,dstFact;
            E_MODULATE_FUNC modulate;
            u32 alphaSource;
            unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
 
            if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO)
            {
                blendDesc.RenderTarget[0].BlendEnable = FALSE;
            }
            else
            {
                blendDesc.RenderTarget[0].BlendEnable = TRUE;
                blendDesc.RenderTarget[0].SrcBlend = getD3DBlend ( srcFact );   
                blendDesc.RenderTarget[0].DestBlend = getD3DBlend ( dstFact );  
 
                blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
            }
        }
 
    }
instead of doing this

Code: Select all

virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
        bool resetAllRenderstates, IMaterialRendererServices* services)
    {
 
        if (material.MaterialType != lastMaterial.MaterialType ||
            material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
            resetAllRenderstates)
        {
            D3D11_BLEND_DESC& blendDesc = static_cast<CD3D11Driver*>(Driver)->getBlendDesc();
 
            E_BLEND_FACTOR srcFact,dstFact;
            E_MODULATE_FUNC modulate;
            u32 alphaSource;
            unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
 
            if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO)
            {
                blendDesc.RenderTarget[0].BlendEnable = FALSE;
            }
            else
            {
                blendDesc.RenderTarget[0].BlendEnable = TRUE;
                blendDesc.RenderTarget[0].SrcBlend = getD3DBlend ( srcFact );   
                blendDesc.RenderTarget[0].DestBlend = getD3DBlend ( dstFact );  
 
                blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
            }
        }
        CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
    }
but upon digging I found an other issue

currently the default material renderer wich is the one you get when you create your own shaders looks like this

Code: Select all

 
void CD3D11MaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial,
                                                bool resetAllRenderstates, video::IMaterialRendererServices* services)
{
    if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
    {
        if (BaseRenderer)
            BaseRenderer->OnSetMaterial(material, material, resetAllRenderstates, services);
    }
 
    //let callback know used material
    if (CallBack)
        CallBack->OnSetMaterial(material);
 
    services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
notice the

Code: Select all

        if (BaseRenderer)
            BaseRenderer->OnSetMaterial(material, material, resetAllRenderstates, services);
 

wich in turn calls

Code: Select all

virtual void OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial,
        bool resetAllRenderstates, IMaterialRendererServices* services)
    {
        CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
        if (material.MaterialType != lastMaterial.MaterialType ||
            material.MaterialTypeParam != lastMaterial.MaterialTypeParam ||
            resetAllRenderstates)
        {
            D3D11_BLEND_DESC& blendDesc = static_cast<CD3D11Driver*>(Driver)->getBlendDesc();
 
            E_BLEND_FACTOR srcFact,dstFact;
            E_MODULATE_FUNC modulate;
            u32 alphaSource;
            unpack_textureBlendFunc ( srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam );
 
            if (srcFact == EBF_SRC_COLOR && dstFact == EBF_ZERO)
            {
                blendDesc.RenderTarget[0].BlendEnable = FALSE;
            }
            else
            {
                blendDesc.RenderTarget[0].BlendEnable = TRUE;
                blendDesc.RenderTarget[0].SrcBlend = getD3DBlend ( srcFact );   
                blendDesc.RenderTarget[0].DestBlend = getD3DBlend ( dstFact );  
 
                blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
            }
        }
 
    }
notice this here

Code: Select all

        CD3D11MaterialRenderer::OnSetMaterial(material, lastMaterial, resetAllRenderstates, services);
 
guess what that's calling?

that self recursive calling isn't good at all we are looping back on our selves and setting the blend state twice and befor I caught it we were setting the blend state twice and not even for our current draw
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Granyte »

This version should be able to reproduce most of the scene other drivers can

change list:
-fixed material blendstate the material should set their blendstate properly
-removed useless calls mainly due to the recursive calling a custom material would have the shader set to it's base renderer shader and then have to overwrite it with it's own the useless call were putting their toll for more complex scenes others have been removed to with these modification dx11 is actualy faster then dx9 in most scenes even with the gui holding it back
-correct memleak in dx11 texture
-expose hull and domain shaders they were there all along but not exposed
- expose prototype streamoutput


and as usual the other addition I made
-SSE matrice and vector3df
-Volume cube and texture array











https://www.dropbox.com/s/i30cqu0o9dxja ... VF.7z?dl=0
airc
Posts: 25
Joined: Wed Jan 08, 2014 8:17 am

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by airc »

this is great thanks
there is an issue with demo example , there is no sphere mapping on sydney.md2

Image
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Granyte »

The sphere mapping works but the reflection shader is unimplemented with the shader code integrated in the .cpp file it's way to hard to fix them so i gave up long ago
airc
Posts: 25
Joined: Wed Jan 08, 2014 8:17 am

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by airc »

also bump mapping & parallax mapping does not work .
when do you think d3d11 driver would be stable ?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Nadro »

I hope to find some free time, so I will be able to integrate shared fixed pipeline emulation callback (it's already available in ogl-es for OGLES2). This change will make that code related to fixed pipeline emulation will be easier to maintain (IShaderConstantSetCallBack will be shared across few drivers).
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Granyte »

airc wrote:also bump mapping & parallax mapping does not work .
when do you think d3d11 driver would be stable ?

When some one find the time to write those shaders

but as i told the shaders are a long string inside a .cpp file so every time you try a new change you have to recompile the whole thing

now that nadro talks about it i might be able to copy the shaders from the ogl-es branch we will see
Nadro wrote:I hope to find some free time, so I will be able to integrate shared fixed pipeline emulation callback (it's already available in ogl-es for OGLES2). This change will make that code related to fixed pipeline emulation will be easier to maintain (IShaderConstantSetCallBack will be shared across few drivers).
cool but it might reduce the performance of dx11 ill cheq how it works
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by mongoose7 »

Why not strip the shaders out and put them in the file system. Creating a 'shaders' directory in the distribution would be a good idea for the future.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by hendu »

It would be a PITA for users having to ship extra files, the usual issues with working dirs...
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by zerochen »

yes that was my intention. so i put them into the engine. maybe it was just to early for that.
in my current working solution i have an extra flag. if that is defined the shaders are loaded from files. i can push it out in the next days.

currently i m working on steam output buffers and it is almost done. has anybody an idea how the user should access them?
i m thinking of an special method in IMaterialRendererServices like

Code: Select all

 
s32 getXXXBufferId(const c8 *name); // XXX for Pixel, GS,...
 

Code: Select all

 
IHardwareBuffer* getXXXBuffer(const s32 id);
 
or

Code: Select all

 
IHardwareBuffer* getBuffer(E_SHADER_TYPE type, const s32 id);
 
or just a method in videodriver
has anybody other ideas?

regards
zerochen
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Granyte »

I Have implemented stream Output Buffers in my last upload how ever while my implementation works it's hacky.

I would need a deeper look at your code to see.


And for the materials it was way to early I recall specifying that I had not put them in the cpp file because they where not ready.
I haven't touched them since.

but ya having them out of the cpp file and not having to re write the hack every time a new patch is up would greatly help.


Also while we are at it we will also need to expose the set Constant buffer method through IMaterialRendererServices because the Shader reflexion method has been deprecated on dx11 and just compiling irrlicht to properly link against the previous version is wishfully painfull

it's also just not supported on winRT idealy a way to load compiled shaders directly
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by zerochen »

hi,

here is the patch.
Irrlicht.patch


changes:
+ fixed multiply video card support
+ split 2tcoords, tangends and standard in seperate buffers
+ define NO_IRR_D3D_NO_SHADER_DEBUGGING to load shaders from files (located in media/shaders). files are created if they doesnt exist
+ set constant buffers only if they needed eg fog, light buffers
+ fix culling and add clear method in instancescenenode

regards
zerochen
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by Granyte »

What was wrong with the multiple gpu support? I ran a CFX setup for ages and i have 85-90% scaling

does this include any of the changes i made in my upload or should i get on the merge?
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: Finally, a DirectX 10 video driver for Irrlicht

Post by zerochen »

hi,

i had the chance to test irrlicht with two video cards and if i select another vcard it crashed. that is fixed now...
the patch is based on the lastest svn, so nadro can easily add the patch to svn.

cya
zerochen
Post Reply