Emit optional binary SPIR-V (.spv) via SPIRV-Tools#36
Closed
NripeshN wants to merge 1 commit into
Closed
Conversation
When SPIRV-Tools is available (detected like the optional MLIR path), the Vulkan backend assembles the generated .spvasm text in-process (spvTextToBinary, SPV_ENV_VULKAN_1_2 matching the vulkan1.2/SPIR-V 1.5 target) and writes a sibling .spv binary. Fully optional: builds without SPIRV-Tools succeed and emit only .spvasm. Adds SPIRVAssembler (.h/.cpp) and a spirv-val-gated smoke test.
Member
Author
|
Closing: on review this is redundant. The Vulkan native path (buildVulkanPrototypeBinary) already produces a validated binary .spv via the spirv-as/spirv-val CLI, and this PR's in-process library write runs only after the spirv-as requirement check (so only when the CLI is present) and is overwritten byte-identically by the CLI command. The genuinely-additive change — making vulkan native builds self-contained (assemble + validate in-process via the linked SPIRV-Tools library, relaxing the spirv-as/spirv-val CLI requirements) — is a separate focused change; will revisit. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The Vulkan target previously emitted SPIR-V only as text (
.spvasm). This adds optional binary SPIR-V (.spv) emission — real, GPU-loadable output — by assembling the generated assembly in-process with the SPIRV-Tools library.find_package(SPIRV-Tools CONFIG QUIET); when present,CROSSGL_HAVE_SPIRV_TOOLS=1is defined and the library linked. A build without SPIRV-Tools still succeeds and simply emits only.spvasm(verified via-DCMAKE_DISABLE_FIND_PACKAGE_SPIRV-Tools=ON—cglclinks, feature disabled).SPIRVAssembler.h/.cpp):assembleVulkanSpirvText()uses the SPIRV-Tools C API (spvTextToBinary) withSPV_ENV_VULKAN_1_2, matched to the backend'svulkan1.2/ SPIR-V 1.5 target. Returnsstd::nullopt(stub) when the library is absent, so callers compile either way.<module>.spvnext to the.spvasm(the package metadata already recognizes.spv). On assembly failure it surfaces the exact SPIRV-Tools diagnostic rather than hiding it.Verification
100% tests passed, 0 tests failed out of 2453..spvvalidates:spirv-val --target-env vulkan1.2 <module>.spv→ valid; SPIR-V magic word0x07230203; byte-identical tospirv-asassembling the same text.spirv-val-gated smoke test (cglc_build_vulkan_spirv_tools_binary_smoke) that asserts the.spvexists, carries the magic word, and validates.Follow-up
Native binary encoding (no SPIRV-Tools dependency) and wiring
.spvinto the.cglbpackage archive remain future work.