Results 1 to 7 of 7

Thread: Speed (textures, shaders and vertex buffers)

  1. #1
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Speed (textures, shaders and vertex buffers)

    Again a speed question. This time about batching render calls.

    When rendering a scene, I can have multiple shaders, textures and vertex buffers. These thins need to switch several times like

    Code:
    SetTexture 1
    SetShader 1
    SetVertexBuffer 1
    DrawPrimitive (D3D render call)
    
    SetTexture 2
    SetShader 1
    SetVertexBuffer 1
    DrawPrimitive (D3D render call)
    
    SetTexture 1
    SetShader 1
    SetVertexBuffer 1
    DrawPrimitive (D3D render call)
    Here the textures is set 3 times, and can be reduced to 2. But what is global the best way to batch? sort by texture, shader of vertex buffer? I personally would say shaders, cause you sometimes need to a matrix or some other stuff. (Im not asking whats best for my app, but just in global ways!)
    NecroSOFT - End of line -

  2. #2

    Speed (textures, shaders and vertex buffers)

    I sort my rendering queue based on these tests:

    http://www.circlesoft.org/pages.php?pg=kbasepage&id=12

    So vertex shaders have priority in the sorting, reducing their amount of calls.

  3. #3
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Speed (textures, shaders and vertex buffers)

    Thanx, thats just what I needed . I guess I need also to sort on vertex/pixel shaders, then vertex buffers and finally textures.
    NecroSOFT - End of line -

  4. #4

    Speed (textures, shaders and vertex buffers)

    I'm glad You can sort all of them in a single pass, just defining a comparison function (for the sorting algorithm) that deals with their priority.

  5. #5
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Speed (textures, shaders and vertex buffers)

    I was thinking of automatically sorting every frame. This way I can just and and remove object from the world and still have minimum performance lost.

    More like this
    Render 1 2 1 2
    Sort 1 1 2 2
    Render 1 1 2 2
    Sort (its all sorted, so we can skip here)
    Add new object 1
    Render 1 1 2 2 1
    Sort 1 1 1 2 2
    Render 1 1 1 2 2
    Sort (its all sorted, so we can skip here)

    etc...
    NecroSOFT - End of line -

  6. #6

    Speed (textures, shaders and vertex buffers)

    These timings are from the article "Accurately Profiling Direct3D API Calls" which can be found in Direct9 SDK help file.

    If you read it you'll see that the timings are CPU clocks needed to queue commands. They tell us nothing about GPU clocks needed to actually perform the commands. If you change a shader, GPU will stall (GPU probably will need to clear its conveyor). When you switch a texture its only a pointer change.

    More accurate priority (based on tests) you can find here:
    http://tomsdxfaq.blogspot.com/
    ------
    -Pixel shader changes.
    -Pixel shader constant changes.
    -Vertex shader changes.
    -Vertex shader constant changes.
    -Render target changes.
    -Vertex format changes (SetVertexDeclaration).
    -Sampler state changes.
    -Vertex and index buffer changes (without changing the format).
    -Texture changes.
    -Misc. render state changes (alpha-blend mode, etc)
    -DrawPrim calls.
    ------

    I think on SM3 hardware shader constant changes should be less expensive as there is no need to internally replace a shader with a new one (on old GPU's shader constants is a part of a shader).

  7. #7
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Speed (textures, shaders and vertex buffers)

    Cool, thanx for the information!!
    NecroSOFT - End of line -

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •