简体   繁体   中英

DirectX: What will happen if you bind index buffer but not vertex buffer?

Let's suppose you have a non empty index buffer but no vertex buffer.

When you bind this index buffer containing indices that don't exist (since there is no vertex buffer), will it create those vertices for you or will it ignore all invalid indices?

In your vertex shader you could calculate all the positions of your indexed vertices, so that you actually see something on screen.

Is this possible?

Performing a draw using an Index buffer without any Vertex Buffer bounds is allowed, but then only two semantics are allowed as input of your vertex shader:

SV_VertexID and SV_InstanceID (see SV Semantics here )

Any other input will have it's value set to 0

One use case I often have for those is to use StructuredBuffers as vertex buffers (vertices being processed in Compute Shader), and fetching being done manually as per the (mini) example here :

StructuredBuffer<float3> sbPosition : register(t0);
void VS(uint iv : SV_VertexID, out float4 posScreen : SV_Position)
{
    //Fetch vertex
    float3 p = sbPosition[iv];

    posScreen = // mul p by world view projection
}

In another case you can also procedurally generate positions bases on vertex ID.

Once vetex shader is done, the vertex indices will be consumed by the index buffer to form primitives set by your topology).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM