Align rasterizer state, readback paths, cull mode, triangle winding order across backends#1127
Conversation
|
I'm fine with either winding mode, but this feels like something we should add to the documentation. |
85e485f to
a63bea2
Compare
a63bea2 to
def5e69
Compare
|
The CI is failing on a Mandelbrot test. @EmilioLaiso Could you check if it uses a golden image and if that is still correct? Perhaps there is still a bug in the texture readbacks? |
| // source's per-row stride in bytes; pass `getImageRowBytes()` when the | ||
| // source is tightly packed (Vulkan / Metal), or the GPU's reported pitch | ||
| // when the source has row padding (e.g., D3D12's 256-byte aligned rows). | ||
| void copyFromTexture(const void *Src, size_t SrcRowPitch); |
There was a problem hiding this comment.
Bit odd that copyFromTexture() takes a raw CPU pointer and not a Texture object, but it makes sense from the perspective that it's a mapped readback pointer that was the target of a Texture-copy operation. Not sure I have a better name in mind though, so let's leave it if you don't have anything better either.
(copyFromReadbackTexture()?)
def5e69 to
8729f88
Compare
Summary
Make the three backends use the same image coordinate system, same culling mode and same
SV_IsFrontFacepolarity.The framework had the following setup:
Front-face polarity differed.
DX/MTL Y-flip clip→framebuffer at the viewport; Vulkan with positive-height viewport doesn't.
Same HLSL triangle ended up with opposite framebuffer winding on VK vs DX/MTL, so
SV_IsFrontFacegave opposite answers for the same input. This surfaced while writing a graphics-stage system-values test that neededSV_IsFrontFaceto agree across backends.Visual PNG output was aligned by two compensating flips.
DX and MTL each had a row-reversal on readback documented as "render target origin is top-left, while our image writer expects bottom-left".
The PNG writer reversed rows again on the way out.
VK had neither flip, but VK's no-Y-flip viewport meant its framebuffer was already "upside down" relative to DX/MTL, so its single PNG flip happened to produce a visually identical image. Two-flips-cancel on DX/MTL, no-flip-needed on VK, by accident.
Adding any new behavior on top of this (e.g., the negative-height-viewport change in the earlier stage of this PR that kicked off the investigation) immediately broke the cancellation and produced visually-flipped outputs.
PR
Pick HLSL/DX semantics as canonical:
Untangled the asymmetry by removing the readback flips on DX/MTL and the PNG writer's row reversal together with the VK viewport flip, so all three places change as one atomic step. After that, every backend produces the same Y-down memory layout end-to-end.
Exposed shared
copyFromTexturefunction that all backends can call.If #1113 goes in main, which introduces
Map/Unmapas functions on theBuffertype, the readback path can be generalized further.Golden Images
All graphics golden images still work as expected. The resulting Y-order is maintained.
The
Mandelbrot.testimage required updating as it's a compute path. Here's the PR: llvm/offload-golden-images#6