[D3D11] HLSL, StructuredBuffer and System Values

Started by
11 comments, last by MJP 11 years, 11 months ago

Is binding a resource very time consuming? I assume they are already on the GPU so shouldn't be much right?


It depends very, very much on the hardware, but in general you should minimize state changes. E.g. when binding a resource the caches are invalidated and several things are validated (are all mipmaps available (for textures), have the formats changed etc). Probably even worth is changing a shader, since it internally changes much more states, potentially invalidating various caches (including the texture cache) as well as inlining of functions in case you use dynamic shader linkage etc.

Writing a system that keeps on the CPU side track of the states and binds them when you submit a draw or dispatch call, isn’t worth it btw, since the GPU already does that for you. smile.png

We have many experts here in the forum, so if you open up a new topic, you can get much more (and better smile.png) information on this.
Advertisement

[quote name='RyxiaN' timestamp='1336126144' post='4937333']
Is binding a resource very time consuming? I assume they are already on the GPU so shouldn't be much right?


It depends very, very much on the hardware, but in general you should minimize state changes. E.g. when binding a resource the caches are invalidated and several things are validated (are all mipmaps available (for textures), have the formats changed etc). Probably even worth is changing a shader, since it internally changes much more states, potentially invalidating various caches (including the texture cache) as well as inlining of functions in case you use dynamic shader linkage etc.

Writing a system that keeps on the CPU side track of the states and binds them when you submit a draw or dispatch call, isn’t worth it btw, since the GPU already does that for you. smile.png

We have many experts here in the forum, so if you open up a new topic, you can get much more (and better smile.png) information on this.
[/quote]

Allright. :) I think I'll just leave it to the experts for now. x) Doubt it will make a difference anyway. My biggest thought were more if it was worth binding the StructuredBuffer to both the vertex shader and the pixel shader, or just send along the variables from the vertex shader to the pixel shader through parameters with semantics, which I think I'll end up doing instead. :)
Binding a resource is going to be almost entirely CPU overhead. You'll pay some cost for the managed/native transition, for making the underlying D3D call, and possibly some driver overhead. In terms of GPU performance, it's likely that accessing the color in the vertex shader will be cheaper than accessing it in the pixel shader. This is because doing it in the vertex shader means you'll only pay for the memory access 4 times, instead of once for each pixel rendered.

At any rate, these performance differences are going to be very small unless you render a LOT of sprites.

This topic is closed to new replies.

Advertisement