Fix not setting graphics pipeline primitive type for Metal#15184
Conversation
This information is needed when a vertex shader outputs [[render_target_array_index]] for a 2D texture array. The GPU needs to know the primitive topology at pipeline compile time to determine which vertex's array index value to use when routing fragments to the indexed texture layer.
|
It looks like layered rendering is only supported on A12 chips and above, which is above the min spec for SDL_GPU (A9+ devices). Per Apple’s documentation it also looks like this feature requires specifying a |
flibitijibibo
left a comment
There was a problem hiding this comment.
From an outside perspective (having little knowledge of the Metal side of things) what specifically does this do that we don't already do to support primitive types in Metal overall? This is important for others to understand since we would presumably need to port this feature to Vulkan, D3D12, and PS4/5, and even knowing how those backends work I can't quickly figure out what this is doing and why it's doing it, other than it simply being possible for the Metal API to accept for some reason.
Once we have a better understand of the above it should be easier to see how this applies to the other backends and what restrictions might apply (other than the system requirements that @TheSpydog already mentioned)
|
From my perspective, I just followed the error trail and noticed we weren't setting the |
|
@flibitijibibo, I don't think anything needs to be done for the other backends, we just weren't specifying the GPU primitive type correctly. @tuzz, please add setting renderTargetArrayLength to this PR. |
|
Huh, so we weren't setting it anywhere? So point and line rendering just didn't work at all until now...? (I could have sworn we tested all types as part of the SDL_Render backend...) |
The SDL_Renderer backend doesn't exercise |
|
@flibitijibibo In Metal, the primitive type is passed in to draw commands rather than on the pipeline itself. You only need to provide it to the pipeline if you’re doing layered rendering, which is what this PR is about. I haven’t yet investigated what capabilities might be necessary to support layered rendering on other backends, but I can definitely imagine this being a Vulkan extension or device feature. |
Requested in the GitHub comment: libsdl-org#15184 (comment) Apple Docs: https://developer.apple.com/documentation/metal/rendering-to-multiple-texture-slices-in-a-draw-command
Requested in the GitHub comment: libsdl-org#15184 (comment) Apple Docs: https://developer.apple.com/documentation/metal/rendering-to-multiple-texture-slices-in-a-draw-command
706fb43 to
77e44e7
Compare
|
I've tried adding More docs here: |
77e44e7 to
5408309
Compare
| METAL_INTERNAL_TrackTexture(metalCommandBuffer, texture); | ||
| } | ||
|
|
||
| Uint32 layerCount = 0; |
There was a problem hiding this comment.
Looks like this also needs an @available check for iOS/tvOS
|
@tuzz What was the motivation for using It looks like support for this feature is very spotty on Vulkan ( Since this would raise our min spec even on Metal, I'm inclined to avoid adding this feature, at least not without significantly more investigation and design consideration. But if there's a very compelling use case, we'll see what we can do. |
|
I don't mind closing this. My use case was for lightmap generation. I was using a compute shader to raytrace some lines for light geometry and needed to partition the vertices into separate texture layers, with additive blending. I can workaround it in a few differents ways, e.g. adding a conditional to the vertex shader and issuing separate draw calls or by moving more of the processing into the compute shader. So it's definitely not a blocker for me. |
|
First off, the PR title is misleading, the problem here is that an unsupported shader feature is being used. The concept being used here is known as "Single Draw Multiple Viewport". In Vulkan this is covered by VK_EXT_shader_viewport_index_layer which was promoted to Core in 1.2 with about 87% hardware support and 80% on Android. In D3D12 it is covered by the This feature actually is quite useful for a common use case (point light shadow mapping) but I think we should have a lot more discussion about this before officially supporting it in some way. EDIT: Looks like Caleb got to this first, but thankfully we came to the same conclusion... |
|
I'm going to close this for now, because it looks offhand like a bug fix and I don't want to accidentally merge it, but we can keep this in mind for the future! |
This information is needed when a vertex shader outputs
[[render_target_array_index]]for a 2D texture array.The GPU needs to know the primitive topology at pipeline compile time to determine which vertex's array index value to use when routing fragments to the layered texture.
Fixes this pipeline creation error:
Existing Issue(s)
None found.
Other platforms
I haven't checked D3D12, Vulkan and XR because I'm only running macOS. Would someone be able to check other other GPU backends and apply the same patch there if needed? Thanks!
Reproduction