Description
From QTBUG-82624.
layout(binding = 42) uniform sampler2D shadowMaps[8]; layout(binding = 43) uniform sampler2D somethingElse;
maps to
Texture2D<float4> shadowMaps[4] : register(t0); SamplerState _shadowMaps_sampler[4] : register(s0); Texture2D<float4> somethingElse : register(t8); SamplerState _somethingElse_sampler : register(s8);
meaning shadowMaps textures use t0, t1, t2, .., t7, while shadowMaps_sampler uses s0, s1, .., s7.
This means we will quickly run out of sampler slots with Quick3D custom materials, where there are two arrays of textures (shadowMaps, shadowCubes), each with 8 elements. There are 128 SRV slots but 16 sampler slots in D3D. (OpenGL has 16 texture units at minimum too, but the binding model is different, with no separate sampler objects so we do not run into the same issue that easily)
A workaround could be to use one (non-array) sampler, because it is likely that each of the 8 slots will contain the same sample object anyway, but this is not possible to do without altering either the SPIRV-Cross generated output, or hack SPIRV-Cross itself. (then again, the SPIR-V - HLSL translator's behavior is correct: we declare combined image samplers of N elements, that then maps to N textures and N samplers. Rather, perhaps we should look for an alternative approach that does not rely on large, mostly unused arrays?)
As a temporary workaround, the shadow map arrays have been reduced to size 4. (so cannot have more than 4 directional and 4 non-directional shadow casting light) but this can still be a problem with certain custom materials that use more than 8 other texture maps.
Also note that https://codereview.qt-project.org/c/qt/qtquick3d/+/293262 fixes a bug where unused sampler were declared, ignoring the feature set conditions like QSSG_ENABLE_SSM. This will fix examples like custommaterials so this problem won't occur there anymore. But that does not solve the core problem.
Could be this is something to be postponed to revisit in the future, while for now we just document that a custom material should not have more than 8 custom textures.
Attachments
Issue Links
- is required for
-
QTBUG-82245 Quick3D custom materials with RHI (excl. blits/multipass)
- Closed
For Gerrit Dashboard: QTBUG-82719 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
293217,6 | rhi: d3d11: Honor resource/sampler slot limits | 5.15 | qt/qtbase | Status: MERGED | +2 | 0 |