d3d11: draw several rectangles with a single drawIndexed*() call for performance ?

Started by
12 comments, last by Aerodactyl55 1 year, 9 months ago

Hello

I have a program that renders 2 rectangles with solid color. I create the vertex and index buffers, and I call 2 times DrawIndexed() for both rectangles. It works

My question is about performance:i want to display the fastest possible rectangles with solid colors (only this shape). So I was wondering if it was possible to display these rectangles with a single DrawIndexed() call (or another Draw*() call), and if it could be the fastest rendering of solid colored rectangles.

thank you

Advertisement
  1. Use Triangle Strip instead of Triangle list
  2. Use SV_VertexID instead of Index/Vertex Buffer, Vertex data can be stored inside Vertex Shader.

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

AndreyVK_D3D said:

  1. Use Triangle Strip instead of Triangle list
  2. Use SV_VertexID instead of Index/Vertex Buffer, Vertex data can be stored inside Vertex Shader.

I am already using strip instead of list

But i have never used SV_VertexID.I've searched a bit but no simple example in the web. Do you know any ?

My final purpose is to add a d3d11 engine to a toolkit (in C), so i'm using d3d11 for 2D in C for fast rendering (i don't want to use d2d, nor dependencies). So I have begun to write a serie of codes for a tutorial. My last code (display of a triangle and a rectangle) is here:

https://git.enlightenment.org/vtorri/Direct3D/src/branch/master/src/d3d_5.c

adding a rectangle is easy (in d3dscenebegin() line 789)

thank you

I suggest you use a triangle list instead of strip, then put the 8 vertices of both rectangles in the same vertex buffer and set the index buffer values appropriately. Then bind the buffers and draw them with a single draw call. I think this method is simple to understand and the performance shouldn't be bad (unless you have some specific requirement).

The SV_VertexID trick requires you to store the rectangles attributes (size, color, position) in the shader (or send it to the shader), and then you reconstruct the vertex data based on the ID (index) of the vertex.

And that link leads to a 404 error…

vtorri said:
But i have never used SV_VertexID.I've searched a bit but no simple example in the web. Do you know any ?

for example https://www.gdcvault.com/play/1020624/Advanced-Visual-Effects-with-DirectX

3DGraphics,Direct3D12,Vulkan,OpenCL,Algorithms

@Aerodactyl55 Which draw call ? DrawIndexed() with BaseVertexLocation equal to 6 ?

btw, the link is not dead when i click on it

AndreyVK_D3D said:

vtorri said:
But i have never used SV_VertexID.I've searched a bit but no simple example in the web. Do you know any ?

for example https://www.gdcvault.com/play/1020624/Advanced-Visual-Effects-with-DirectX

@andreyvk_d3d thank you, I'll look at this video

vtorri said:

@Aerodactyl55 Which draw call ? DrawIndexed() with BaseVertexLocation equal to 6 ?

btw, the link is not dead when i click on it

I get a “page not found” when I click on that link.

Call DrawIndex with the IndexCount parameter set to the number of required indices (for 2 rectangles it should be 12), the rest can be set to zero.

I get a “page not found” when I click on that link.

Call DrawIndex with the IndexCount parameter set to the number of required indices (for 2 rectangles it should be 12), the rest can be set to zero.

then try to copy the address `https://git.enlightenment.org/vtorri/Direct3D/src/branch/master/src/d3d_5.c​`​ and paste it in the browser. It works for me

ok for DrawIndexed(), I'll try, thank you

vtorri said:

I get a “page not found” when I click on that link.

Call DrawIndex with the IndexCount parameter set to the number of required indices (for 2 rectangles it should be 12), the rest can be set to zero.

then try to copy the address `https://git.enlightenment.org/vtorri/Direct3D/src/branch/master/src/d3d_5.c​`​ and paste it in the browser. It works for me

Still doesn't work. Maybe you should post the relevant code.

This topic is closed to new replies.

Advertisement