-
Notifications
You must be signed in to change notification settings - Fork 329
Description
This is for security, let me explain why.
Why Normal Draws are insecure
This is because the GPU hardware consumes an index buffer which usually sits in device-local memory, now that index buffer tells which offsets in the vertex buffers to fetch as input data.
This stage is not programmable, hence its impossible to prevent out-of-buffer-bound vertex data to be fetched.
In webGL this is not a problem because the intermediate layer actually checks each index buffer whether it contains out-of-range indices and modifies them while rendering.
However if you plan to allow SSBOs/UAVs and using these outputs as index buffers then the possibility of checking the index buffer validity on the CPU is gone (unless you want to pull the index buffer data before EVERY draw from device local memory, and completely kill perfomance by a factor of >100x).
What I propose
The compute shader can validate the index buffer, create a copy with only valid offsets and use that copy for drawing (GPU2GPU validation).
That way the data stays in device local memory and no unnecessary performance tradeoff happens (unmodified buffers can be not validated).
P.S. Similar applies to Indirect Draw Buffers