bjornbytes / lovr

Lua Virtual Reality Framework
https://lovr.org
MIT License
2k stars 138 forks source link

Sampling from multisampled texture should error #717

Closed bjornbytes closed 11 months ago

bjornbytes commented 1 year ago

e.g.

tex = lovr.graphics.newTexture(1, 1, { samples = 4 })
pass:fill(tex) -- or lovr.graphics.newMaterial(tex), pass:setMaterial(tex), etc.
bjornbytes commented 1 year ago

It might not be possible to properly validate this due to texture binding aliasing. It's possible to use a shader that declares a texture2DMS variable that aliases the ColorTexture of the Material and uses that to do a custom resolve via pass:fill(multisampledTexture).

It's not really possible to statically validate this since the exact texture type accessed by the shader could be impacted by dynamic control flow, specialization constants, etc.

Multisampled/non-2D textures could be banned from Materials but this cuts off some use cases. For example cubemap skyboxes are currently using texture aliasing.

bjornbytes commented 1 year ago

I guess the SPIR-V parser could use a bitmask to track the union of all the types of texture binding aliases for a slot, and then lovr could at least validate that your texture is compatible with at least one of the aliases declared in the shader. That would reliably solve the common case where you accidentally pass a non-2D or MSAA texture to a regular non-aliased 2D texture variable. If someone decides to use aliased texture bindings and uses them improperly then they're subjected to the UB.

bjornbytes commented 11 months ago

Merging this with #718 since I think their solution is the same now