Details
Description
Maybe https://developer.apple.com/documentation/metal/render_passes/rendering_to_multiple_texture_slices_in_a_draw_command?language=objc
with the SPIRV-Cross options https://github.com/KhronosGroup/SPIRV-Cross/blob/main/spirv_msl.hpp#L336
Experiment what kind of shader those generates and what kind of extra buffers are needed.
Initial investigation:
With https://codereview.qt-project.org/c/qt/qtshadertools/+/487281 passing --view-count 2 generates the following shader. This would mean instancing must be used (and when the application uses instancing, it needs to be internally adjusted), combined with an additional buffer than contains the view offset and divisor to calculate gl_ViewIndex.
Shader 1: MSL 12 [Standard] Entry point: main0 Native resource binding map: 0 -> [0, -1] Native shader extra buffer bindings: [view-mask-buffer-binding] = 24 Contents: #include <metal_stdlib> #include <simd/simd.h> using namespace metal; struct buf { float4x4 mvp[2]; }; struct main0_out { float4 gl_Position [[position]]; uint gl_Layer [[render_target_array_index]]; }; struct main0_in { float4 pos [[attribute(0)]]; }; vertex main0_out main0(main0_in in [[stage_in]], constant uint* spvViewMask [[buffer(24)]], constant buf& _21 [[buffer(0)]], uint gl_InstanceIndex [[instance_id]], uint gl_BaseInstance [[base_instance]]) { main0_out out = {}; uint gl_ViewIndex = spvViewMask[0] + (gl_InstanceIndex - gl_BaseInstance) % spvViewMask[1]; gl_InstanceIndex = (gl_InstanceIndex - gl_BaseInstance) / spvViewMask[1] + gl_BaseInstance; out.gl_Position = _21.mvp[int(gl_ViewIndex)] * in.pos; out.gl_Layer = gl_ViewIndex - spvViewMask[0]; return out; }
Attachments
For Gerrit Dashboard: QTBUG-114774 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
487281,4 | msl: Opt in to multiview when --view-count is specified | dev | qt/qtshadertools | Status: MERGED | +2 | 0 |
487282,3 | Allow storing the view mask buffer binding in QShader metadata | dev | qt/qtbase | Status: MERGED | +2 | 0 |
487696,8 | rhi: metal: Add support for multiview rendering | dev | qt/qtbase | Status: MERGED | +2 | 0 |