2 Replies Latest reply on Apr 1, 2017 10:45 PM by ronniko

    New GPU render method.

    ronniko

      I love programing 3d graphic render.

      But all API use many CPU functions. Its not good.

      In Vulkan API i sow DrawIndirect and NVIDIA use VK_NVX_device_generated_commands !

      It pushed me to write my idea for new method GPU render.

       

      I propose create on GPU new shader. Shader call GPU-manager. This shader work with struct(this struct describe how render meshes).

      All work do GPU-manager (set textures, render targets,shaders,meshes,MSAA,depth,culling,Blending) without CPU !

      And GPU-manager shader for each drawed mesh get int32 value(lets say MeshNum) to Vertex shader and other shaders. Somthing like Instancing_ID.

      It`s need for keep in second GPU buffer matrices and some values for each mesh.

      In Vertex shader we use MeshNum to get from second GPU buffer matrices and some values for current mesh.

       

      New shader (GPU-manager) will allow run old games for Directx 9\10\11(as usual whitout GPU-manager) and run new games (this new games using new GPU-manager shader)

      GPU-manager shader give more freedom ! We can get something like Directx 13 right now in all OS (Linux\Windows\Mac) !

      Driver for Videocard Will be small !

      And CPU does not fit GPU into the hard conditions and rules !

       

      For one mesh struct (for example 64 bytes) in this struct we describe all states for render.

      Struct Will relieve us from many CPU functions !

       

      For example.

      How look struct for GPU-manager ( One this struct for one mesh. If we need draw 10 different meshes  then we write 10 this structs):

       

      1-GPU pointer to Vertex Buffer

      2-GPU pointer to Index Buffer

      3-GPU pointer to RenderTarget

      4-GPU pointer to TextureA

      5-GPU pointer to TextureB

      6-GPU pointer to TextureC

      7-GPU pointer to TextureD

      8-GPU pointer to TextureE

      9-GPU pointer to Vertex shader

      10-GPU pointer to Pixel shader

      11-GPU pointer to Blending

      12-MSAA flag 0=1 1=2xMSAA 2=4xMSAA 3=8xMSAA

      13- Cull mode 0=None 1=BackFaces 2=Front

      14-Depth 0=off 1=On

      15-int32 how many draw triangles for this mesh

      16-int32 how many draw this mesh

      17-GPU feature flag (for example boolean operation whit meshes,occlusion queries,copy meshes\data\textures,etc)

      18-GPU describe layout vertices data.

      19- GPU pointer to second buffer (whear is keep matrices and some values for this mesh)

      20-Number mesh over which will occur operations(it`s mean next or prevision struct).

       

       

      Then send this struct to GPU-manager shader and do DrawList();

      In code main render look like this:

       

      1-Fill for each mesh Struct

      2-SendGPUList(&pStructs,NumObjects);//Only one call !

      3-DrawGPUList();//Only one call ! And GPU-manager draw all meshes structs for one DIP !

      4-Present(swap chain back buffer,color key,pRect);

       

      Now we can for one dip, draw all 3d world !

      And draw shadowmap and meshes with shadow map.

      This method relieve GPU from sending many CPU commands.

      And GPU work more effective\faster and not wait next command from CPU !

       

      We can have in render meshes with different MSAA !

      I think many CPU commands\functions for GPU it's ballast. And code overgrown unnecessary functions.

      Code becoming big and not comfortable and not readable.

       

      About function Present. Work only on GPU !

      Function Present(Any texture ! Not only swap chain back buffer !)

      It is convenient to see how render look in somes textures.

      And more practical.

       

      Now we can presetns many textures without excess\unnecessary render on plane and set shaders.

      Present(swap chain back buffer,color key,pRect); // lets say it`s main render

      Present(Character Icons,color key,pRect);//lets say it`s couple small icons draw like png with alpha.

      Present(MainMenu,color key,pRect);//lets says it`s main menu draw at the center of the monitor, draw like png with alpha.

       

      color key for blend or alpha images.

      pRect need for better control the output texture on screen, or part of texture !

      pRect it`s struct {

      ScreenX DWORD 0

      ScreenY DWORD 0

      left DWORD 0

      top DWORD 0

      right DWORD 0

      bottom DWORD 0

      }

       

      If we want draw many textures. Lets say 40 textures.

      Good solution use PresentList(pPointerFirstTexture,HowManyTextures flip); GPU fast flip and blending\alpha all textures on screen

        • Re: New GPU render method.
          ronniko

          And init and create render look like this:

          1) hr = InitGPUManeger(pDevice);// if hr = 1 its ok or bad

          2) pDevice->CreateSwapChain(SizeX,SizeY,FlagMode,V-sync);

          3) pDevice->CreateBlend(Blenddesc,&pGPUBlendMem);//pGPUBlendMem as 64 bit for GPU-memory. This we write to GPU-meneger struct for mesh.

          4) pDevice->LoadShader(FileName,ShaderName,&pShader);//pShader as 64 bit for GPU-memory. This we write to GPU-meneger struct for mesh.

          5) pDevice->LoadTexture(FileName,&pTexture);//pTexture as 64 bit for GPU-memory. This we write to GPU-meneger struct for mesh.

          6) pDevice->CreateVertexBuffer(CPUmem,desc,&pGPUVertexmem);//pGPUVertexmem as 64 bit for GPU-memory. This we write to GPU-meneger struct for mesh.

          7) pDevice->CreateIndexBuffer(CPUmem,desc,&pGPUIndxmem);//pGPUIndxmem as 64 bit for GPU-memory. This we write to GPU-meneger struct for mesh.

          8) pDevice->CreateStorageBuffer(FlagRead\Write,size*16,pData);// pData as 64 bit for GPU-memory. For matrices(View\Proj\World) or data.

          9) pDevice->GetFeatures(&pDescFeatuares);// Get all features flags. Need for GPU-meneger structs for boolean operation,occlusion querys , copy data etc

          10) pDevice->CreateVerticesLayout(desc,&pGPULayout);//pGPULayout as 64 bit for GPU-memory. This we write to GPU-meneger struct for mesh.

          11) Do on CPU frustum culling for meshes and for passed meshes we write arrays GPU-meneger structs

          12) SendGPUList(&pStruct,NumObjects);

          13) DrawGPUList();

          14) Present(swap chain back buffer,color key,pRect);

           

          Thats all ! Simple and faster write simple render for big 3d world with shadows\lightings and animated meshes !

           

          If we want get data from GPU mem. Do:

          pDevice->GetGPUData(pGPUresource its texture or buffer or mesh,&pCPUmemory);//pCPUmemory mean big array data not 8 bytes pointer ! And we indicate CPU memory place for storage GPU data !

          Then if we want changed data and send back to GPU do:

          pDevice->SendGPUData(&pCPUmemory,pGPUresource,how many bytes send);