Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-82719

rhi: There is a limit of 16 combined image samplers per shader which can be problematic for custom materials

    XMLWordPrintable

Details

    • Task
    • Resolution: Invalid
    • P3: Somewhat important
    • 6.x
    • None
    • Qt RHI, Quick: 3D
    • None
    • 5

    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

          For Gerrit Dashboard: QTBUG-82719
          # Subject Branch Project Status CR V

          Activity

            People

              qt.team.graphics.and.multimedia Qt Graphics Team
              lagocs Laszlo Agocs
              Pasi Keränen Pasi Keränen
              Andy Nichols Andy Nichols
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes