You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Building off of #8281, this PR adds a native lowering via SPV_EXT_descriptor_heap and SPV_KHR_untyped_pointers and is part 1/3 in a series.
ResourceDescriptorHeap and SamplerDescriptorHeap are lowered to untyped variables decorated with ResourceHeapEXT and SamplerHeapEXT. Each heap access emits OpUntypedAccessChainKHR into a runtime array of the appropriate descriptor type. Buffer-like resources (StructuredBuffer, ByteAddressBuffer, ConstantBuffer, TextureBuffer) use OpTypeBufferEXT and OpBufferPointerEXT; image and sampler resources use OpLoad. Interlocked operations on RWTexture use OpUntypedImageTexelPointerEXT.
Jonathan Zakharov (@jzakharovnv) I think the OpConstantSizeOfEXT usage in this MR isn't quite right - it looks like you're just taking the stride of the descriptor type being loaded and using that? This works for the sampler heap where there's only one type (samplers), but not for the resource heap.
I might be misunderstanding the code, but I don't see anything for finding the largest of the two sizes? They're both POT, so it is a simple "which is max" calculation, but I don't see it being done in this PR.
Diego Novillo (@dnovillo) In response to your last comment on this PR, yes I think it's more correct to have the TODO commit a part of this initial branch rather than one down the line. Cherrypicked and rebased to reflect this.
This looks like a user-visible bug fix/feature change. Please add (or point to) the corresponding entry in docs/ReleaseNotes.md.
If release-note coverage is planned in a related PR (including one that hasn’t been submitted yet), please mention that plan/link so we can avoid duplicate notes.
Fixes#8603: MergeBinaryOpSelect produced an OpSelect with a vector
result type and a scalar condition, which is only legal in SPIR-V 1.4+
(KhronosGroup/SPIRV-Tools#6827).
This exposes #8740 where the resource-heap-ext-texture.hlsl test fails
validation - for now this is worked around by disabling the test, since
#8517 looks like it is reworking it anyway.
Assisted-by: copilot
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b04b21af-2d8b-4af5-b9ad-1b84073588f5
Track heap-sourced images returned from function calls
tools/clang/lib/SPIRV/SpirvEmitter.cpp:5307
isHeapSourcedValue does not recognize a call that returns a heap-sourced image. Consequently, RWTexture2D x = makeHeapImage(); records x as Bound, and a later x = ResourceDescriptorHeap[i] is rejected as bound/heap mixing even though both sources are heap-backed. Function-returned image handles are explicitly supported for ordinary reads/writes, so this rejects an otherwise supported reassignment; classify heap-returning calls (and their forwarded locals) separately from genuinely bound resources here.
Preserve heap provenance through conditional image selection
tools/clang/lib/SPIRV/SpirvEmitter.cpp:8598
Valid HLSL heap provenance is not limited to a direct subscript or DeclRefExpr; conditional selection is commonly used (for example, RWTexture2D t = cond ? ResourceDescriptorHeap[a] : ResourceDescriptorHeap[b]). This returns false for that expression, so buffer resources fall back to storing OpBufferPointerEXT values through an ordinary function variable, while an image atomic later has no descriptor index and falls back to invalid OpImageTexelPointer. Track/merge both heap indices through conditionals, or diagnose this form before lowering it.
Scan nested declaration contexts for heap image callers
tools/clang/lib/SPIRV/SpirvEmitter.cpp:8715
This caller search skips function bodies nested in record/namespace declaration contexts. HLSL supports member functions, so a member can load an RWTexture from ResourceDescriptorHeap and pass it to a free function whose parameter is used by an interlocked operation; that call site is never found here, and the callee falls back to the invalid OpImageTexelPointer path this check is intended to prevent. Traverse nested declaration contexts (or a TU-wide call graph) so every user-function body is scanned.
I spent some time just iterating on Copilot's review comments and think I was able to fix most of the critical bugs it found. After a while it seemed like it was finding less significant issues and more so just requesting diagnostics for descriptor heap use cases that DXIL backend generically rejects, but would otherwise get silently compiled by SPIR-V backend- just to get rejected by spirv-val.
I think implementing a bunch of diagnostics for cases people will likely never see is less productive than going and fixing the issue at its source, but that is what I have actually done.
I have a local branch that just about gets SPIRV native descriptor heaps 1-1 with DXIL backend functionally (hopefully means less future work), but it feels morally wrong to make that apart of this branch since it is a decently large change and I've learned from my mistake of making monolithic PRs.
Thus, I'm in favor of leaving Copilot's diagnostic requests and functional gap complaints unfulfilled on this PR so we can aim to proceed with merging this branch, then layering many small PRs to follow.
I know the big dogs are at KH F2F this week, so I'll do a self-review pass again this week, but that's what I got
…8518)
Building off of #8517, this PR extends the SPV_EXT_descriptor_heap
native heap lowering to cover RaytracingAccelerationStructure resources
loaded from ResourceDescriptorHeap. It is part 2/4 in a series.
Acceleration structure descriptors are accessed via
OpUntypedAccessChainKHR into a runtime array of
OpTypeAccelerationStructureKHR, consistent with the image and sampler
paths added in the previous commit.
Assisted by an AI agent
@dnovillo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building off of #8281, this PR adds a native lowering via SPV_EXT_descriptor_heap and SPV_KHR_untyped_pointers and is part 1/3 in a series.
ResourceDescriptorHeap and SamplerDescriptorHeap are lowered to untyped variables decorated with ResourceHeapEXT and SamplerHeapEXT. Each heap access emits OpUntypedAccessChainKHR into a runtime array of the appropriate descriptor type. Buffer-like resources (StructuredBuffer, ByteAddressBuffer, ConstantBuffer, TextureBuffer) use OpTypeBufferEXT and OpBufferPointerEXT; image and sampler resources use OpLoad. Interlocked operations on RWTexture use OpUntypedImageTexelPointerEXT.
Requires -fspv-target-env=vulkan1.3.
Assisted by an AI agent.
Diego Novillo (@dnovillo)