Debian Codegraph @

docs/drivers/kosmickrisp/workarounds.rst

raw
1 KosmicKrisp workarounds
2 #######################
3
4 This file documents the relevant issues found in either Metal, the MSL
5 compiler or any other component we have no control over that needed to be
6 worked around to accomplish Vulkan conformance.
7
8 All workarounds must be documented here and no code comment info should be
9 provided other than the name ``KK_WORKAROUND_#``.
10
11 Once a workaround was removed from the code, the code comment will be
12 removed but the documentation here will be kept.
13
14 Template
15 ========
16
17 Use the following template to create documentation for a new workaround:
18
19 .. code-block::
20
21 KK_WORKAROUND_#
22 ---------------
23 | macOS version:
24 | Metal ticket:
25 | Metal ticket status:
26 | CTS test failure/crash:
27 | Comments:
28 | Log:
29
30 ``macOS version`` needs to have the OS version with which it was found.
31
32 ``Metal ticket`` needs to be either the Metal ticket number with the GitLab
33 handle of the user that reported the ticket or ``Unreported``.
34
35 ``Metal ticket status`` needs to be either ``Fixed in macOS # (Build hash)``,
36
37 ``Waiting resolution`` or empty if unreported. If Apple reported that the issue
38 was fixed, but no user has verified the fix, append ``[Untested]``.
39 ``CTS test failure/crash`` (remove ``failure`` or ``crash`` based on test
40 behavior) needs to be the name of the test or test family the issue can be
41 reproduced with.
42
43 ``Comments`` needs to include as much information on the issue and how the
44 workaround fixes it.
45
46 ``Log`` needs to have the dates (yyyy-mm-dd, the only correct date format) with
47 info on what was updated.
48
49 Workarounds
50 ===========
51
52 KK_WORKAROUND_6
53 ---------------
54 | macOS version: 26.0.1
55 | Metal ticket: Not reported
56 | Metal ticket status:
57 | CTS test failure: ``dEQP-VK.spirv_assembly.instruction.*.float16.opcompositeinsert.*``
58 | Comments:
59
60 Metal does not respect its own Memory Coherency Model (MSL spec 4.8). From
61 the spec:
62 ``By default, memory in the device address space has threadgroup coherence.``
63
64 If we have a single thread compute dispatch so that we do (simplified version):
65
66 .. code-block:: c
67
68 for (...) {
69 value = ssbo_data[0]; // ssbo_data is a device buffer
70 ...
71 ssbo_data[0] = new_value;
72 }
73
74 ``ssbo_data[0]`` will not correctly store/load the values so the value
75 written in iteration 0, will not be available in iteration 1. The workaround
76 to this issue is marking the device memory pointer through which the memory
77 is accessed as coherent so that the value is stored and loaded correctly.
78 Hopefully this does not affect performance much.
79
80 | Log:
81 | 2025-12-08: Workaround implemented and reported to Apple
82
83 KK_WORKAROUND_5
84 ---------------
85 | macOS version: 26.0.1
86 | Metal ticket: Not reported
87 | Metal ticket status:
88 | CTS test failure: ``dEQP-VK.fragment_operations.early_fragment.discard_no_early_fragment_tests_depth``
89 | Comments:
90
91 Fragment shaders that have side effects (like writing to a buffer) will be
92 prematurely discarded if there is a ``discard_fragment`` that will always
93 execute. To work around this, we just make the discard "optional" by moving
94 it inside a run time conditional that will always be true (such as is the
95 fragment a helper?). This tricks the MSL compiler into not optimizing it into
96 a premature discard.
97
98 | Log:
99 | 2025-12-01: Workaround implemented
100
101 KK_WORKAROUND_4
102 ---------------
103 | macOS version: 26.0.1
104 | Metal ticket: FB21124215 (@aitor)
105 | Metal ticket status: Waiting resolution
106 | CTS test failure: ``dEQP-VK.draw.renderpass.shader_invocation.helper_invocation*`` and few others
107 | Comments:
108
109 ``simd_is_helper_thread()`` will always return true if the shader was started
110 as a non-helper thread, even after ``discard_fragment()`` is called. The
111 workaround is to have a variable tracking this state and update it when the
112 fragment is discarded. This issue is present in M1 and M2 chips.
113
114 | Log:
115 | 2025-11-22: Workaround implemented and reported to Apple
116
117 KK_WORKAROUND_3
118 ---------------
119 | macOS version: 15.4.x
120 | Metal ticket: FB20113490 (@aitor)
121 | Metal ticket status: Waiting resolution
122 | CTS test failure: ``dEQP-VK.subgroups.ballot_other.*.subgroupballotfindlsb``
123 | Comments:
124
125 ``simd_is_first`` does not seem to behave as documented in the MSL
126 specification. The following code snippet misbehaves:
127
128 .. code-block:: c
129
130 if (simd_is_first())
131 temp = 3u;
132 else
133 temp = simd_ballot(true); /* <- This will return all active threads... */
134
135 The way to fix this is by changing the conditional to:
136
137 .. code-block:: c
138
139 if (simd_is_first() && (ulong)simd_ballot(true))
140 temp = 3u;
141 else
142 temp = (ulong)simd_ballot(true);
143
144 | Log:
145 | 2025-09-09: Workaround implemented and reported to Apple
146
147 KK_WORKAROUND_2
148 ---------------
149 | macOS version: 15.4.x
150 | Metal ticket: FB21065475 (@aitor)
151 | Metal ticket status: Waiting resolution
152 | CTS test crash: ``dEQP-VK.graphicsfuzz.cov-nested-loops-never-change-array-element-one`` and ``dEQP-VK.graphicsfuzz.disc-and-add-in-func-in-loop``
153 | Comments:
154
155 We need to loop to infinite since MSL compiler crashes if we have something
156 like (simplified version):
157
158 .. code-block:: c
159
160 while (true) {
161 if (some_conditional) {
162 break_loop = true;
163 } else {
164 break_loop = false;
165 }
166 if (break_loop) {
167 break;
168 }
169 }
170
171 The issue I believe is that ``some_conditional`` wouldn't change the value no
172 matter in which iteration we are (something like fetching the same value from
173 a buffer) and the MSL compiler doesn't seem to like that much to the point it
174 crashes.
175
176 The implemented solution is to change the ``while(true)`` loop with
177 ``for (uint64_t no_crash = 0u; no_crash < UINT64_MAX; ++no_crash)``, which
178 tricks the MSL compiler into believing we are not doing an infinite loop
179 (wink wink).
180
181 | Log:
182 | 2025-09-08: Workaround implemented
183
184 KK_WORKAROUND_1
185 ---------------
186 | macOS version: 15.4.x
187 | Metal ticket: FB17604106 (@aitor)
188 | Metal ticket status: [Untested] Fixed in macOS 26 Beta (25A5279m)
189 | CTS test crash: ``dEQP-VK.glsl.indexing.tmp_array.vec3_dynamic_loop_write_dynamic_loop_read_fragment``
190 | Comments:
191
192 Uninitialized local scratch variable causes the MSL compiler to crash.
193 Initialize scratch to avoid issue.
194
195 | Log:
196 | 2025-05-14: Workaround implemented and reported to Apple
197 | 2025-06-14: Apple reported back saying it is now fixed in macOS 26 Beta (Build 25A5279m)
198
199
200