Advertisement Jump to content
Sign in to follow this  

OpenGL D3D alternative for OpenGL gl_BaseInstanceARB

This topic is 1016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



In the article mentioned above (slides 35, 36), they explain how MutiDrawInderect could be use to render multiple meshes with the single CPU call.

In particular, they utilize baseInstance from DrawElementsIndirect struct to encode transform and material indices for the mesh.

Then, this data is exposed in the vertex shader as gl_BaseInstanceARB variable and used to fetch transform for the specific mesh.


It seems that there is no alternative system variable in D3D for gl_BaseInstanceARB. I am thinking how I could work around this.

The first thing that comes to my mind is having a structured buffer, each element of which contains transform and material index for each vertex from the compound mesh vertex buffer. There will be data duplication but it should not be problematic, I gather. After, I could read the data through SV_VertexID in the vertex shader.


Edit: another way would be to add mesh id on vertex object itself. 


Do you have any other ideas?

Edited by _void_

Share this post

Link to post
Share on other sites

No, I am not really talking about the instancing. The instance will be always 1. I am interested in D3D12 ExecuteIndirect.

I am having a massive vertex/index buffer with all meshes merged data.


In the compute shader, I am planning to apply view frustum culling of the geometry and generate IndirectDraw arguments for each submesh that have survived culling.

I have a structured buffer that specifies vertex/index offset, index count, material/transform index for each submesh. Each submesh is distinguished by the material.


Then, I am going to ExecuteIndirect on the list of generated arguments to render GBuffer.

Essentially, I was asking how I could transfer material/transform index for each submesh from the culling pass to the GBuffer pass

Share this post

Link to post
Share on other sites

In D3D12, the D3D12_DRAW_INDEXED_ARGUMENTS struct does have a StartInstanceLocation field like GL's BaseInstance.


BTW there's a multi-draw extension for D3D11 too  :) and the D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS struct also has that field.

However, D3D doesn't pass this value through to SV_InstanceID properly :( So, if you want to access it, you've got to make a buffer containing {0,1,2,3,...} and bind it as per-instance data :lol:

Alternatively if you just want material data, just put it into a buffer, bind it as per-instance data, and then have your culling job fill in the StartInstanceLocation field properly. The indirect draw call's vertex shader will then receive materialBuffer[StartInstanceLocation] from the IA stage.

Edited by Hodgman

Share this post

Link to post
Share on other sites

I will probably go for D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT as MJP suggested.

Many thanks guys! I am really feeling appreciative for the help.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!