More physics work. New assets.
This commit is contained in:
parent
ada7896a9b
commit
9f5142738b
132 changed files with 122928 additions and 4688 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
|
@ -87,3 +87,4 @@ menu.dat !filter !diff !merge text
|
|||
# Model
|
||||
#
|
||||
*.glb filter=lfs diff=lfs merge=lfs -text
|
||||
*.stl filter=lfs diff=lfs merge=lfs -text
|
||||
|
|
|
|||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -16,6 +16,8 @@ docs/Manual.html
|
|||
docs/Manual.pdf
|
||||
docs/.asciidoctor/
|
||||
.claude/settings.local.json
|
||||
**/__pycache__/
|
||||
/util/perl/
|
||||
|
||||
# Extracted by the binary when it is run from here; never source.
|
||||
/Singe/
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ API Changes
|
|||
velocities, forces and impulses; triggers; hinge, ball and slider
|
||||
joints with limits; a raycast; onCollision and onTrigger callbacks.
|
||||
The world steps at a fixed 60 Hz between animation and rendering and
|
||||
pauses with the game. New calls: body*, joint*, physics*, and the
|
||||
pauses with the game. physicsSet2D keeps bodies in a plane for 2D
|
||||
games, which need no GPU (nodes now exist on every machine, so a
|
||||
Raspberry Pi 3 gets 2D physics without 3D). New calls: body*,
|
||||
joint*, physics*, and the
|
||||
BODY_*, SHAPE_* and JOINT_* constants; see the Physics chapter. Needs
|
||||
SSE4.1 on x86 (2008 and later); the engine's first C++ (one wrapper
|
||||
file and the library), statically linked, no runtime to install.
|
||||
|
|
@ -35,8 +38,8 @@ API Changes
|
|||
colour, textures from sprites, the disc or a loaded video, metallic and
|
||||
roughness, up to eight lights each able to cast shadows (cube maps for
|
||||
point lights), any node as the camera, and glTF 2.0
|
||||
models (.glb, self-contained) with node animation and skinning, placed
|
||||
any number of times. Everything is a node in one tree. New calls:
|
||||
models (.glb, self-contained) with node animation, skinning and morph
|
||||
targets, placed any number of times. Everything is a node in one tree. New calls:
|
||||
scene*, node*, mesh*, material*, light*, camera*, model*, animation*,
|
||||
and the LIGHT_* constants; see the 3D Scenes chapter of the manual.
|
||||
Needs a GPU with Vulkan, Direct3D 12 or Metal (Raspberry Pi 4 or
|
||||
|
|
|
|||
|
|
@ -624,6 +624,25 @@ foreach(imageLib libjpeg.a libpng16.a)
|
|||
endif()
|
||||
endforeach()
|
||||
|
||||
# The scene shaders: src/shaders/scene.hlsl compiled at build time into a header of SPIR-V, DXIL
|
||||
# and MSL blobs by SDL_shadercross, which the superbuild builds for the host (cmake/hostTools.cmake)
|
||||
# and names in SINGE_SHADERCROSS; configuring this project alone finds one on the PATH.
|
||||
if(NOT SINGE_SHADERCROSS)
|
||||
find_program(SINGE_SHADERCROSS shadercross)
|
||||
if(NOT SINGE_SHADERCROSS)
|
||||
message(FATAL_ERROR "SDL_shadercross is needed to compile the scene shaders; build through the superbuild (cmake --preset ...) or set SINGE_SHADERCROSS.")
|
||||
endif()
|
||||
endif()
|
||||
set(shaderHeader ${CMAKE_BINARY_DIR}/generated/shaders/sceneShaders.h)
|
||||
add_custom_command(
|
||||
OUTPUT ${shaderHeader}
|
||||
COMMAND ${CMAKE_COMMAND} -DSHADERCROSS=${SINGE_SHADERCROSS} -DSOURCE=${CMAKE_SOURCE_DIR}/src/shaders/scene.hlsl -DOUTPUT=${shaderHeader} -P ${CMAKE_SOURCE_DIR}/cmake/shaderHeader.cmake
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/src/shaders/scene.hlsl ${CMAKE_SOURCE_DIR}/cmake/shaderHeader.cmake
|
||||
COMMENT "Compiling the scene shaders"
|
||||
)
|
||||
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${shaderHeader})
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}/generated)
|
||||
|
||||
# Jolt Physics comes with the compile definitions it was built with (SIMD level, layer bits) through
|
||||
# its exported target; the one C++ file in the tree (physicsJolt.cpp) needs them. Its C++ runtime is
|
||||
# zig's own libc++, linked statically, or the host's libstdc++ under gcc; macOS already lists -lc++.
|
||||
|
|
|
|||
9
INSTALL
9
INSTALL
|
|
@ -96,6 +96,15 @@ builds the Apple silicon and Intel presets (macos-aarch64, macos-x86_64)
|
|||
and joins them with llvm-lipo into Singe-v3.00-Macos-universal. Either
|
||||
architecture alone is ./build-all.sh macos aarch64 or x86_64.
|
||||
|
||||
The 3D scene's shaders are HLSL, compiled when Singe is built. The
|
||||
superbuild builds SDL_shadercross and SPIRV-Cross for the host machine
|
||||
once (into .builddir/toolchains/host, shared by every preset) and fetches
|
||||
Microsoft's prebuilt DirectX Shader Compiler, which SDL_shadercross
|
||||
drives, into .builddir/toolchains/dxc. That prebuilt package exists for
|
||||
x86_64 Linux hosts; on another host, unpack a DirectX Shader Compiler
|
||||
release (lib/libdxcompiler.so, lib/libdxil.so, include/dxc/dxcapi.h) at
|
||||
that path yourself, or build it from source there.
|
||||
|
||||
The Raspberry Pi build (64-bit Raspberry Pi OS, glibc 2.31 or newer)
|
||||
also uses zig. The platform headers and libraries it links against are
|
||||
Debian bookworm arm64 packages listed in cmake/zig/piPackages.cmake,
|
||||
|
|
|
|||
3
LICENSES
3
LICENSES
|
|
@ -6,6 +6,7 @@ these tools, Singe would not exist.
|
|||
arg_parser BSD-2-Clause http://savannah.nongnu.org/projects/arg-parser
|
||||
binaryheap.lua MIT http://tieske.github.io/binaryheap.lua
|
||||
cgltf MIT https://github.com/jkuhlmann/cgltf
|
||||
DirectXShaderCompiler NCSA https://github.com/microsoft/DirectXShaderCompiler (prebuilt, downloaded at build time; host tool only)
|
||||
copas MIT https://lunarmodules.github.io/copas
|
||||
ffmpeg LGPL-2.1 https://ffmpeg.org
|
||||
freetype FTL https://freetype.org
|
||||
|
|
@ -27,9 +28,11 @@ openssl Apache-2.0 https://www.openssl.org
|
|||
opus BSD-3-Clause https://opus-codec.org
|
||||
opusfile BSD-3-Clause https://opus-codec.org
|
||||
SDL3 Zlib https://www.libsdl.org
|
||||
SDL_shadercross Zlib https://github.com/libsdl-org/SDL_shadercross (host tool only)
|
||||
SDL3_image Zlib https://www.libsdl.org
|
||||
SDL3_mixer Zlib https://www.libsdl.org
|
||||
SDL3_ttf Zlib https://www.libsdl.org
|
||||
SPIRV-Cross Apache-2.0 https://github.com/KhronosGroup/SPIRV-Cross (host tool only)
|
||||
sqlite Public-Domain https://sqlite.org
|
||||
timerwheel.lua MIT https://tieske.github.io/timerwheel.lua
|
||||
uthash BSD-1-Clause https://troydhanson.github.io/uthash
|
||||
|
|
|
|||
34
assets/Dragon.mtl
Normal file
34
assets/Dragon.mtl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Materials for Dragon.obj
|
||||
newmtl dark
|
||||
Ka 0.060 0.062 0.066
|
||||
Kd 0.300 0.310 0.330
|
||||
Ks 0.700 0.700 0.700
|
||||
Ns 180.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.35
|
||||
|
||||
newmtl champagne
|
||||
Ka 0.144 0.128 0.108
|
||||
Kd 0.720 0.640 0.540
|
||||
Ks 0.850 0.800 0.700
|
||||
Ns 120.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.40
|
||||
|
||||
newmtl glass
|
||||
Ka 0.176 0.184 0.180
|
||||
Kd 0.880 0.920 0.900
|
||||
Ks 0.950 0.950 0.950
|
||||
Ns 300.0
|
||||
d 0.55
|
||||
Ni 1.50
|
||||
illum 4
|
||||
Pm 0.00
|
||||
Pr 0.15
|
||||
|
||||
1339
assets/Dragon.obj
Normal file
1339
assets/Dragon.obj
Normal file
File diff suppressed because it is too large
Load diff
79
assets/Dragon.svg
Normal file
79
assets/Dragon.svg
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="193 22 889 749" width="889" height="749">
|
||||
<!-- Singe dragon, reconstructed as polygons from Dragon.jpeg; transparent background. -->
|
||||
<defs>
|
||||
<linearGradient id="g0" gradientUnits="userSpaceOnUse" x1="698.7" y1="96.1" x2="629.6" y2="137.3"><stop offset="0" stop-color="#6f7277"/><stop offset="1" stop-color="#97969a"/></linearGradient>
|
||||
<linearGradient id="g1" gradientUnits="userSpaceOnUse" x1="503.6" y1="307.1" x2="382.6" y2="159.3"><stop offset="0" stop-color="#66686f"/><stop offset="1" stop-color="#8a8b90"/></linearGradient>
|
||||
<linearGradient id="g2" gradientUnits="userSpaceOnUse" x1="845.5" y1="159.5" x2="866.9" y2="156.5"><stop offset="0" stop-color="#73777b"/><stop offset="1" stop-color="#73767c"/></linearGradient>
|
||||
<linearGradient id="g3" gradientUnits="userSpaceOnUse" x1="835.5" y1="229.1" x2="842.3" y2="253.1"><stop offset="0" stop-color="#54575d"/><stop offset="1" stop-color="#5a5d63"/></linearGradient>
|
||||
<linearGradient id="g4" gradientUnits="userSpaceOnUse" x1="738.8" y1="402.4" x2="778.4" y2="373.8"><stop offset="0" stop-color="#4e5357"/><stop offset="1" stop-color="#55595e"/></linearGradient>
|
||||
<linearGradient id="g5" gradientUnits="userSpaceOnUse" x1="502.9" y1="620.5" x2="456.0" y2="520.4"><stop offset="0" stop-color="#52575e"/><stop offset="1" stop-color="#5a6166"/></linearGradient>
|
||||
<linearGradient id="g6" gradientUnits="userSpaceOnUse" x1="854.9" y1="616.3" x2="901.1" y2="622.7"><stop offset="0" stop-color="#33393e"/><stop offset="1" stop-color="#373c42"/></linearGradient>
|
||||
<linearGradient id="g7" gradientUnits="userSpaceOnUse" x1="364.2" y1="664.4" x2="360.7" y2="746.1"><stop offset="0" stop-color="#353b40"/><stop offset="1" stop-color="#40474d"/></linearGradient>
|
||||
<linearGradient id="g8" gradientUnits="userSpaceOnUse" x1="965.4" y1="697.5" x2="906.6" y2="706.0"><stop offset="0" stop-color="#63686c"/><stop offset="1" stop-color="#676c70"/></linearGradient>
|
||||
<linearGradient id="g9" gradientUnits="userSpaceOnUse" x1="894.1" y1="714.4" x2="875.2" y2="729.2"><stop offset="0" stop-color="#43474a"/><stop offset="1" stop-color="#45474b"/></linearGradient>
|
||||
<linearGradient id="g10" gradientUnits="userSpaceOnUse" x1="682.0" y1="67.3" x2="737.5" y2="95.0"><stop offset="0" stop-color="#d5c9bc"/><stop offset="1" stop-color="#dbcdc1"/></linearGradient>
|
||||
<linearGradient id="g11" gradientUnits="userSpaceOnUse" x1="979.3" y1="183.9" x2="958.7" y2="176.5"><stop offset="0" stop-color="#9b9187"/><stop offset="1" stop-color="#b9aea5"/></linearGradient>
|
||||
<linearGradient id="g12" gradientUnits="userSpaceOnUse" x1="924.1" y1="150.5" x2="852.7" y2="205.4"><stop offset="0" stop-color="#c2b6a8"/><stop offset="1" stop-color="#f1e7d9"/></linearGradient>
|
||||
<linearGradient id="g13" gradientUnits="userSpaceOnUse" x1="663.8" y1="225.3" x2="726.2" y2="233.1"><stop offset="0" stop-color="#d4c4b2"/><stop offset="1" stop-color="#dccebd"/></linearGradient>
|
||||
<linearGradient id="g14" gradientUnits="userSpaceOnUse" x1="945.6" y1="245.5" x2="885.2" y2="257.5"><stop offset="0" stop-color="#837b70"/><stop offset="1" stop-color="#b0a292"/></linearGradient>
|
||||
<linearGradient id="g15" gradientUnits="userSpaceOnUse" x1="889.0" y1="403.3" x2="817.3" y2="411.5"><stop offset="0" stop-color="#a1998c"/><stop offset="1" stop-color="#e4d7c8"/></linearGradient>
|
||||
<linearGradient id="g16" gradientUnits="userSpaceOnUse" x1="886.4" y1="506.4" x2="918.1" y2="507.5"><stop offset="0" stop-color="#857f74"/><stop offset="1" stop-color="#8b8279"/></linearGradient>
|
||||
<linearGradient id="g17" gradientUnits="userSpaceOnUse" x1="881.7" y1="569.7" x2="827.2" y2="506.1"><stop offset="0" stop-color="#888175"/><stop offset="1" stop-color="#a49b8d"/></linearGradient>
|
||||
<linearGradient id="g18" gradientUnits="userSpaceOnUse" x1="208.2" y1="559.7" x2="242.4" y2="555.4"><stop offset="0" stop-color="#aa9c8d"/><stop offset="1" stop-color="#b3a693"/></linearGradient>
|
||||
<linearGradient id="g19" gradientUnits="userSpaceOnUse" x1="852.5" y1="644.9" x2="736.7" y2="633.3"><stop offset="0" stop-color="#928a7d"/><stop offset="1" stop-color="#daccbc"/></linearGradient>
|
||||
<linearGradient id="g20" gradientUnits="userSpaceOnUse" x1="224.4" y1="631.6" x2="303.9" y2="662.7"><stop offset="0" stop-color="#8d8376"/><stop offset="1" stop-color="#b0a396"/></linearGradient>
|
||||
<linearGradient id="g21" gradientUnits="userSpaceOnUse" x1="1017.2" y1="708.7" x2="974.7" y2="752.6"><stop offset="0" stop-color="#726b60"/><stop offset="1" stop-color="#867e73"/></linearGradient>
|
||||
<linearGradient id="g22" gradientUnits="userSpaceOnUse" x1="560.7" y1="705.9" x2="600.9" y2="763.2"><stop offset="0" stop-color="#898072"/><stop offset="1" stop-color="#a89b8b"/></linearGradient>
|
||||
<linearGradient id="g23" gradientUnits="userSpaceOnUse" x1="801.0" y1="120.8" x2="796.8" y2="140.0"><stop offset="0" stop-color="#e5e4e4"/><stop offset="1" stop-color="#eff0ef"/></linearGradient>
|
||||
<linearGradient id="g24" gradientUnits="userSpaceOnUse" x1="795.2" y1="187.5" x2="744.9" y2="264.6"><stop offset="0" stop-color="#d6dad6"/><stop offset="1" stop-color="#e7e8e7"/></linearGradient>
|
||||
<linearGradient id="g25" gradientUnits="userSpaceOnUse" x1="444.3" y1="360.6" x2="343.6" y2="248.4"><stop offset="0" stop-color="#eaeaea"/><stop offset="1" stop-color="#f1f1f0"/></linearGradient>
|
||||
<linearGradient id="g26" gradientUnits="userSpaceOnUse" x1="774.0" y1="291.5" x2="756.7" y2="328.6"><stop offset="0" stop-color="#e0e1de"/><stop offset="1" stop-color="#e7e8e5"/></linearGradient>
|
||||
<linearGradient id="g27" gradientUnits="userSpaceOnUse" x1="504.5" y1="428.2" x2="600.5" y2="343.0"><stop offset="0" stop-color="#e6e8e7"/><stop offset="1" stop-color="#e9eae8"/></linearGradient>
|
||||
<linearGradient id="g28" gradientUnits="userSpaceOnUse" x1="270.4" y1="455.9" x2="305.1" y2="499.0"><stop offset="0" stop-color="#e7e8e7"/><stop offset="1" stop-color="#ececeb"/></linearGradient>
|
||||
<linearGradient id="g29" gradientUnits="userSpaceOnUse" x1="780.3" y1="469.6" x2="741.5" y2="534.9"><stop offset="0" stop-color="#dbdfdb"/><stop offset="1" stop-color="#e6e7e4"/></linearGradient>
|
||||
<linearGradient id="g30" gradientUnits="userSpaceOnUse" x1="572.4" y1="460.6" x2="554.8" y2="532.2"><stop offset="0" stop-color="#e1e3e0"/><stop offset="1" stop-color="#eaeae9"/></linearGradient>
|
||||
<linearGradient id="g31" gradientUnits="userSpaceOnUse" x1="373.0" y1="591.4" x2="450.6" y2="588.1"><stop offset="0" stop-color="#e1e4e0"/><stop offset="1" stop-color="#e5e7e4"/></linearGradient>
|
||||
<linearGradient id="g32" gradientUnits="userSpaceOnUse" x1="634.8" y1="522.2" x2="694.0" y2="646.0"><stop offset="0" stop-color="#cfd5d1"/><stop offset="1" stop-color="#d8ddd9"/></linearGradient>
|
||||
<linearGradient id="g33" gradientUnits="userSpaceOnUse" x1="488.1" y1="692.3" x2="494.0" y2="725.6"><stop offset="0" stop-color="#d5dad6"/><stop offset="1" stop-color="#e2e5e2"/></linearGradient>
|
||||
<filter id="shadow" x="-10%" y="-10%" width="130%" height="130%"><feDropShadow dx="3" dy="5" stdDeviation="4" flood-color="#000" flood-opacity="0.18"/></filter>
|
||||
<filter id="brush" x="0" y="0" width="100%" height="100%"><feTurbulence type="fractalNoise" baseFrequency="0.003 0.7" numOctaves="2" seed="7" result="noise"/><feColorMatrix in="noise" type="saturate" values="0" result="grey"/><feComponentTransfer in="grey" result="grain"><feFuncA type="linear" slope="0.22"/></feComponentTransfer><feComposite in="grain" in2="SourceGraphic" operator="in" result="clipped"/><feBlend in="clipped" in2="SourceGraphic" mode="overlay"/></filter>
|
||||
</defs>
|
||||
<title>Singe dragon</title>
|
||||
<g filter="url(#shadow)">
|
||||
<polygon points="620.3,450.0 420.1,406.2 575.1,277.9 680.5,456.9" fill="url(#g27)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="718.9,692.9 547.2,565.9 642.9,498.6 688.8,474.3 721.0,511.5" fill="url(#g32)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="832.0,437.8 829.7,543.9 705.5,374.0 673.4,303.6 704.9,256.9" fill="url(#g4)" stroke="#aaacae" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="573.2,269.1 519.7,314.7 404.5,263.3 302.7,135.5" fill="url(#g1)" stroke="#c4c5c7" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="281.8,224.7 375.5,258.3 510.4,318.9 414.4,400.8" fill="url(#g25)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="732.1,520.7 894.5,701.6 730.0,691.8" fill="url(#g19)" stroke="#ece5dd" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="412.5,697.6 353.4,656.7 383.4,543.9 473.3,459.7" fill="url(#g31)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="320.8,754.9 288.6,624.8 486.2,759.6" fill="url(#g7)" stroke="#9fa3a6" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="481.8,461.2 539.9,571.7 415.1,701.2" fill="url(#g5)" stroke="#acb0b2" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="785.2,280.5 915.9,436.6 874.0,506.8 815.2,407.5" fill="url(#g15)" stroke="#f1ebe3" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="674.6,467.0 539.5,557.8 484.1,450.4" fill="url(#g30)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="829.1,553.8 825.4,615.9 692.3,464.8 719.1,401.9" fill="url(#g29)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="346.0,386.3 325.7,487.9 266.2,553.8 224.8,479.9" fill="url(#g28)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="266.0,555.8 310.0,745.6 202.7,639.4" fill="url(#g20)" stroke="#d7d1ca" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="772.9,160.4 839.1,206.4 782.1,265.6 730.4,279.6 711.1,253.1" fill="url(#g24)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="481.7,755.7 587.6,673.5 660.8,760.2" fill="url(#g22)" stroke="#d3cdc5" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="656.2,206.4 767.6,153.0 644.6,335.1" fill="url(#g13)" stroke="#ede6de" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="837.1,618.3 834.8,444.4 906.2,561.9" fill="url(#g17)" stroke="#d1cdc6" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="956.0,158.3 956.0,190.3 862.2,209.3 774.5,150.0 819.0,146.0" fill="url(#g12)" stroke="#f8f3ec" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="933.1,751.6 995.8,671.8 1073.3,758.9" fill="url(#g21)" stroke="#c2beb9" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="778.2,149.8 640.3,144.9 552.5,57.2" fill="url(#g0)" stroke="#cbcacc" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="928.4,545.6 882.6,680.7 833.3,626.6" fill="url(#g6)" stroke="#9b9da0" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="421.4,698.7 579.0,670.2 483.0,746.1" fill="url(#g33)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="883.2,680.4 990.9,673.4 926.5,753.0" fill="url(#g8)" stroke="#b3b5b7" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="930.3,539.5 906.2,561.1 871.3,508.2 912.0,435.2" fill="url(#g16)" stroke="#c5c0bc" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="257.8,560.4 201.9,632.0 214.1,482.6" fill="url(#g18)" stroke="#d9d2c9" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="783.1,149.1 712.8,111.3 830.2,116.0 874.7,144.4" fill="url(#g23)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="940.3,291.2 842.3,211.4 966.9,239.2" fill="url(#g14)" stroke="#d7d0c8" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="887.2,248.1 785.9,269.7 841.6,212.7" fill="url(#g3)" stroke="#acaeb1" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="771.8,272.5 797.9,379.7 733.9,288.2" fill="url(#g26)" fill-opacity="0.88" stroke="#c2ccc6" stroke-width="2" stroke-linejoin="round"/>
|
||||
<polygon points="700.8,100.8 653.0,30.8 778.0,107.7" fill="url(#g10)" stroke="#ede6e0" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="826.6,702.0 893.1,702.0 934.9,762.2" fill="url(#g9)" stroke="#a2a3a5" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="954.9,193.0 958.8,135.4 989.6,179.7 970.4,218.2" fill="url(#g11)" stroke="#dcd6d2" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
<polygon points="825.0,149.0 887.9,149.0 854.9,174.1" fill="url(#g2)" stroke="#b9bbbd" stroke-width="1.5" stroke-linejoin="round" filter="url(#brush)"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 13 KiB |
BIN
assets/DragonModel.glb
(Stored with Git LFS)
Normal file
BIN
assets/DragonModel.glb
(Stored with Git LFS)
Normal file
Binary file not shown.
34
assets/DragonModel.mtl
Normal file
34
assets/DragonModel.mtl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Materials for DragonModel.obj
|
||||
newmtl dark
|
||||
Ka 0.060 0.062 0.066
|
||||
Kd 0.300 0.310 0.330
|
||||
Ks 0.700 0.700 0.700
|
||||
Ns 180.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.35
|
||||
|
||||
newmtl champagne
|
||||
Ka 0.144 0.128 0.108
|
||||
Kd 0.720 0.640 0.540
|
||||
Ks 0.850 0.800 0.700
|
||||
Ns 120.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.40
|
||||
|
||||
newmtl glass
|
||||
Ka 0.176 0.184 0.180
|
||||
Kd 0.880 0.920 0.900
|
||||
Ks 0.950 0.950 0.950
|
||||
Ns 300.0
|
||||
d 0.55
|
||||
Ni 1.50
|
||||
illum 4
|
||||
Pm 0.00
|
||||
Pr 0.15
|
||||
|
||||
3155
assets/DragonModel.obj
Normal file
3155
assets/DragonModel.obj
Normal file
File diff suppressed because it is too large
Load diff
BIN
assets/DragonPrint-champagne.stl
(Stored with Git LFS)
Normal file
BIN
assets/DragonPrint-champagne.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/DragonPrint-dark.stl
(Stored with Git LFS)
Normal file
BIN
assets/DragonPrint-dark.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/DragonPrint-frame.stl
(Stored with Git LFS)
Normal file
BIN
assets/DragonPrint-frame.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/DragonPrint-glass.stl
(Stored with Git LFS)
Normal file
BIN
assets/DragonPrint-glass.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
45
assets/DragonPrint.mtl
Normal file
45
assets/DragonPrint.mtl
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Materials for DragonPrint.obj
|
||||
newmtl dark
|
||||
Ka 0.060 0.062 0.066
|
||||
Kd 0.300 0.310 0.330
|
||||
Ks 0.700 0.700 0.700
|
||||
Ns 180.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.35
|
||||
|
||||
newmtl champagne
|
||||
Ka 0.144 0.128 0.108
|
||||
Kd 0.720 0.640 0.540
|
||||
Ks 0.850 0.800 0.700
|
||||
Ns 120.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.40
|
||||
|
||||
newmtl glass
|
||||
Ka 0.176 0.184 0.180
|
||||
Kd 0.880 0.920 0.900
|
||||
Ks 0.950 0.950 0.950
|
||||
Ns 300.0
|
||||
d 0.55
|
||||
Ni 1.50
|
||||
illum 4
|
||||
Pm 0.00
|
||||
Pr 0.15
|
||||
|
||||
newmtl frame
|
||||
Ka 0.024 0.022 0.020
|
||||
Kd 0.120 0.110 0.100
|
||||
Ks 0.300 0.300 0.300
|
||||
Ns 40.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.00
|
||||
Pr 0.70
|
||||
|
||||
9538
assets/DragonPrint.obj
Normal file
9538
assets/DragonPrint.obj
Normal file
File diff suppressed because it is too large
Load diff
BIN
assets/DragonRelief.glb
(Stored with Git LFS)
Normal file
BIN
assets/DragonRelief.glb
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/Plaque-champagne.stl
(Stored with Git LFS)
Normal file
BIN
assets/Plaque-champagne.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/Plaque-dark.stl
(Stored with Git LFS)
Normal file
BIN
assets/Plaque-dark.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/Plaque-frame.stl
(Stored with Git LFS)
Normal file
BIN
assets/Plaque-frame.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/Plaque-glass.stl
(Stored with Git LFS)
Normal file
BIN
assets/Plaque-glass.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/Plaque-plate.stl
(Stored with Git LFS)
Normal file
BIN
assets/Plaque-plate.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
56
assets/Plaque.mtl
Normal file
56
assets/Plaque.mtl
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# Materials for Plaque.obj
|
||||
newmtl dark
|
||||
Ka 0.060 0.062 0.066
|
||||
Kd 0.300 0.310 0.330
|
||||
Ks 0.700 0.700 0.700
|
||||
Ns 180.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.35
|
||||
|
||||
newmtl champagne
|
||||
Ka 0.144 0.128 0.108
|
||||
Kd 0.720 0.640 0.540
|
||||
Ks 0.850 0.800 0.700
|
||||
Ns 120.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.40
|
||||
|
||||
newmtl glass
|
||||
Ka 0.176 0.184 0.180
|
||||
Kd 0.880 0.920 0.900
|
||||
Ks 0.950 0.950 0.950
|
||||
Ns 300.0
|
||||
d 0.55
|
||||
Ni 1.50
|
||||
illum 4
|
||||
Pm 0.00
|
||||
Pr 0.15
|
||||
|
||||
newmtl frame
|
||||
Ka 0.024 0.022 0.020
|
||||
Kd 0.120 0.110 0.100
|
||||
Ks 0.300 0.300 0.300
|
||||
Ns 40.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.00
|
||||
Pr 0.70
|
||||
|
||||
newmtl plate
|
||||
Ka 0.110 0.106 0.100
|
||||
Kd 0.550 0.530 0.500
|
||||
Ks 0.200 0.200 0.200
|
||||
Ns 30.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.00
|
||||
Pr 0.80
|
||||
|
||||
7040
assets/Plaque.obj
Normal file
7040
assets/Plaque.obj
Normal file
File diff suppressed because it is too large
Load diff
BIN
assets/SingeText.glb
(Stored with Git LFS)
Normal file
BIN
assets/SingeText.glb
(Stored with Git LFS)
Normal file
Binary file not shown.
12
assets/SingeText.mtl
Normal file
12
assets/SingeText.mtl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Materials for SingeText.obj
|
||||
newmtl logo
|
||||
Ka 0.060 0.062 0.066
|
||||
Kd 0.300 0.310 0.330
|
||||
Ks 0.700 0.700 0.700
|
||||
Ns 180.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.35
|
||||
|
||||
1735
assets/SingeText.obj
Normal file
1735
assets/SingeText.obj
Normal file
File diff suppressed because it is too large
Load diff
8
assets/SingeText.svg
Normal file
8
assets/SingeText.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 12 KiB |
BIN
assets/SingeTextPrint-face.stl
(Stored with Git LFS)
Normal file
BIN
assets/SingeTextPrint-face.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/SingeTextPrint-plate.stl
(Stored with Git LFS)
Normal file
BIN
assets/SingeTextPrint-plate.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/SingeTextPrint-walls.stl
(Stored with Git LFS)
Normal file
BIN
assets/SingeTextPrint-walls.stl
(Stored with Git LFS)
Normal file
Binary file not shown.
34
assets/SingeTextPrint.mtl
Normal file
34
assets/SingeTextPrint.mtl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Materials for SingeTextPrint.obj
|
||||
newmtl dark
|
||||
Ka 0.060 0.062 0.066
|
||||
Kd 0.300 0.310 0.330
|
||||
Ks 0.700 0.700 0.700
|
||||
Ns 180.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.35
|
||||
|
||||
newmtl frame
|
||||
Ka 0.024 0.022 0.020
|
||||
Kd 0.120 0.110 0.100
|
||||
Ks 0.300 0.300 0.300
|
||||
Ns 40.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.00
|
||||
Pr 0.70
|
||||
|
||||
newmtl champagne
|
||||
Ka 0.144 0.128 0.108
|
||||
Kd 0.720 0.640 0.540
|
||||
Ks 0.850 0.800 0.700
|
||||
Ns 120.0
|
||||
d 1.00
|
||||
Ni 1.00
|
||||
illum 2
|
||||
Pm 0.80
|
||||
Pr 0.40
|
||||
|
||||
2617
assets/SingeTextPrint.obj
Normal file
2617
assets/SingeTextPrint.obj
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -169,6 +169,9 @@ singeCmakeProject(zstd ${SB_THIRDPARTY}/zstd/build/cmake "" "-DZSTD_BUILD_SHARED
|
|||
|
||||
singeCmakeProject(SDL3 ${SB_THIRDPARTY}/SDL3 "" "-DSDL_SHARED=off;-DSDL_STATIC=on;-DSDL_TESTS=off;-DSDL_EXAMPLES=off" "${SB_ENV}")
|
||||
|
||||
# ===== Host tools: the shader compiler (see cmake/hostTools.cmake) =====
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/hostTools.cmake)
|
||||
|
||||
# ===== Jolt Physics (C++; static, single precision, no tests or samples) =====
|
||||
# The x86 baseline is SSE4.1/4.2 so a shipped binary runs on anything from 2008 on; AVX and the
|
||||
# bit-count instructions would silently raise it. No link-time optimisation through the cross
|
||||
|
|
@ -315,8 +318,8 @@ set(singeBinary ${SB_PREFIX}/singe)
|
|||
ExternalProject_Add(singe
|
||||
SOURCE_DIR ${CMAKE_SOURCE_DIR}
|
||||
BINARY_DIR ${singeBinary}
|
||||
DEPENDS zlib zstd SDL3 SDL3_image SDL3_mixer SDL3_ttf openssl ffmpeg Jolt
|
||||
CONFIGURE_COMMAND ${SB_ENV} ${CMAKE_COMMAND} -S ${CMAKE_SOURCE_DIR} -B ${singeBinary} ${SB_CMAKE_ARGS} -DSINGE_SUPERBUILD=OFF -DKANGAROO_OS=${KANGAROO_OS} -DKANGAROO_ARCH=${KANGAROO_ARCH} -DSINGE_TREE=${SINGE_TREE}
|
||||
DEPENDS zlib zstd SDL3 SDL3_image SDL3_mixer SDL3_ttf openssl ffmpeg Jolt shadercross
|
||||
CONFIGURE_COMMAND ${SB_ENV} ${CMAKE_COMMAND} -S ${CMAKE_SOURCE_DIR} -B ${singeBinary} ${SB_CMAKE_ARGS} -DSINGE_SHADERCROSS=${SINGE_SHADERCROSS} -DSINGE_SUPERBUILD=OFF -DKANGAROO_OS=${KANGAROO_OS} -DKANGAROO_ARCH=${KANGAROO_ARCH} -DSINGE_TREE=${SINGE_TREE}
|
||||
BUILD_COMMAND ${SB_ENV} ${CMAKE_COMMAND} --build ${singeBinary} --parallel ${SB_JOBS}
|
||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${singeBinary}/${singeBinaryBase}${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_SOURCE_DIR}/.builddir/${singeBinaryName}
|
||||
BUILD_ALWAYS ON
|
||||
|
|
|
|||
66
cmake/hostTools.cmake
Normal file
66
cmake/hostTools.cmake
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# Host tools the build needs at build time, built once for the host machine and shared by every
|
||||
# preset: SDL_shadercross (the scene shaders are HLSL, compiled to SPIR-V, DXIL and MSL when Singe
|
||||
# is built, the way the icon and the other embedded files are made) with SPIRV-Cross, a minimal
|
||||
# host SDL3 for its command line tool, and Microsoft's prebuilt DirectX Shader Compiler, which
|
||||
# SDL_shadercross drives and which is fetched like zig (building it from source is a half-hour
|
||||
# job nobody should need). Everything lives under .builddir/toolchains.
|
||||
#
|
||||
# DXC's prebuilt release exists for x86_64 Linux hosts. On another host put an unpacked DXC
|
||||
# (lib/libdxcompiler.so, lib/libdxil.so, include/dxc/dxcapi.h) at .builddir/toolchains/dxc.
|
||||
|
||||
set(SINGE_DXC_VERSION "v1.10.2605.37")
|
||||
set(SINGE_DXC_FILE "linux_dxc_2026_08_11.x86_64.tar.gz")
|
||||
set(SINGE_DXC_SHA256 "dea02d61c0548a6163a5fb45daa9263faeb5334e35d25a30b0293a32d089ceae")
|
||||
|
||||
get_filename_component(hostToolchains ${CMAKE_CURRENT_LIST_DIR}/../.builddir/toolchains ABSOLUTE)
|
||||
set(hostPrefix ${hostToolchains}/host)
|
||||
set(hostBuild ${hostToolchains}/hostBuild)
|
||||
set(hostDxc ${hostToolchains}/dxc)
|
||||
file(MAKE_DIRECTORY ${hostPrefix} ${hostBuild})
|
||||
|
||||
# ----- DirectX Shader Compiler, prebuilt -----
|
||||
if(NOT EXISTS ${hostDxc}/lib/libdxcompiler.so)
|
||||
if((CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64"))
|
||||
set(dxcUrl "https://github.com/microsoft/DirectXShaderCompiler/releases/download/${SINGE_DXC_VERSION}/${SINGE_DXC_FILE}")
|
||||
message(STATUS "Downloading the DirectX Shader Compiler ${SINGE_DXC_VERSION}")
|
||||
file(DOWNLOAD ${dxcUrl} ${hostToolchains}/${SINGE_DXC_FILE} EXPECTED_HASH SHA256=${SINGE_DXC_SHA256} STATUS status)
|
||||
list(GET status 0 code)
|
||||
if(NOT code EQUAL 0)
|
||||
message(FATAL_ERROR "DirectX Shader Compiler download failed: ${status}")
|
||||
endif()
|
||||
file(MAKE_DIRECTORY ${hostDxc})
|
||||
file(ARCHIVE_EXTRACT INPUT ${hostToolchains}/${SINGE_DXC_FILE} DESTINATION ${hostDxc})
|
||||
else()
|
||||
message(FATAL_ERROR "No prebuilt DirectX Shader Compiler for this host; put one at ${hostDxc} (see cmake/hostTools.cmake).")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ----- The host builds run with the host's own compilers, never the cross toolchain -----
|
||||
set(hostEnv ${CMAKE_COMMAND} -E env --unset=CC --unset=CXX --unset=AR --unset=RANLIB --unset=CFLAGS --unset=CXXFLAGS --unset=LDFLAGS --unset=PKG_CONFIG_LIBDIR --unset=PKG_CONFIG_SYSROOT_DIR "MAKEFLAGS=-j${SB_JOBS}")
|
||||
# A | inside an argument becomes a ; (a CMake list) on the way to the child, see LIST_SEPARATOR.
|
||||
set(hostArgs -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${hostPrefix} "-DCMAKE_INSTALL_RPATH=${hostPrefix}/lib|${hostDxc}/lib" -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON)
|
||||
|
||||
# A host CMake project; its stamps and build tree live with the tools, so every preset shares them.
|
||||
function(singeHostProject name source deps args)
|
||||
ExternalProject_Add(${name}
|
||||
SOURCE_DIR ${source}
|
||||
BINARY_DIR ${hostBuild}/${name}
|
||||
STAMP_DIR ${hostBuild}/${name}-stamp
|
||||
TMP_DIR ${hostBuild}/${name}-tmp
|
||||
DEPENDS ${deps}
|
||||
LIST_SEPARATOR |
|
||||
CONFIGURE_COMMAND ${hostEnv} ${CMAKE_COMMAND} -S ${source} -B ${hostBuild}/${name} ${hostArgs} ${args}
|
||||
BUILD_COMMAND ${hostEnv} ${CMAKE_COMMAND} --build ${hostBuild}/${name} --parallel ${SB_JOBS}
|
||||
INSTALL_COMMAND ${hostEnv} ${CMAKE_COMMAND} --build ${hostBuild}/${name} --target install
|
||||
LOG_CONFIGURE ON LOG_BUILD ON LOG_INSTALL ON LOG_OUTPUT_ON_FAILURE ON
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# SDL3 for the host, shared, with nothing SDL_shadercross's tool does not use.
|
||||
singeHostProject(hostSDL3 ${SB_THIRDPARTY}/SDL3 "" "-DSDL_SHARED=ON;-DSDL_STATIC=OFF;-DSDL_TESTS=OFF;-DSDL_EXAMPLES=OFF;-DSDL_AUDIO=OFF;-DSDL_VIDEO=OFF;-DSDL_GPU=OFF;-DSDL_RENDER=OFF;-DSDL_CAMERA=OFF;-DSDL_JOYSTICK=OFF;-DSDL_HAPTIC=OFF;-DSDL_HIDAPI=OFF;-DSDL_POWER=OFF;-DSDL_SENSOR=OFF;-DSDL_DIALOG=OFF;-DSDL_UNIX_CONSOLE_BUILD=ON")
|
||||
# SPIRV-Cross as the shared C library SDL_shadercross looks for.
|
||||
singeHostProject(spirvCross ${SB_THIRDPARTY}/SPIRV-Cross "" "-DSPIRV_CROSS_SHARED=ON;-DSPIRV_CROSS_STATIC=OFF;-DSPIRV_CROSS_CLI=OFF;-DSPIRV_CROSS_ENABLE_TESTS=OFF")
|
||||
# SDL_shadercross, unvendored: SPIRV-Cross and SDL3 from the host prefix, DXC from its download.
|
||||
singeHostProject(shadercross ${SB_THIRDPARTY}/SDL_shadercross "hostSDL3;spirvCross" "-DSDLSHADERCROSS_VENDORED=OFF;-DSDLSHADERCROSS_DXC=ON;-DSDLSHADERCROSS_SHARED=OFF;-DSDLSHADERCROSS_STATIC=ON;-DSDLSHADERCROSS_CLI=ON;-DSDLSHADERCROSS_INSTALL=ON;-DSDLSHADERCROSS_INSTALL_CPACK=OFF;-DCMAKE_PREFIX_PATH=${hostPrefix}|${hostDxc};-DSDL3_DIR=${hostPrefix}/lib/cmake/SDL3")
|
||||
|
||||
set(SINGE_SHADERCROSS ${hostPrefix}/bin/shadercross)
|
||||
38
cmake/shaderHeader.cmake
Normal file
38
cmake/shaderHeader.cmake
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Compiles src/shaders/scene.hlsl into a C header of SPIR-V, DXIL and MSL blobs with
|
||||
# SDL_shadercross. Run by the build as
|
||||
# cmake -DSHADERCROSS=<tool> -DSOURCE=<scene.hlsl> -DOUTPUT=<sceneShaders.h> -P shaderHeader.cmake
|
||||
# so the header is generated into the build tree like the icon and the other embedded files.
|
||||
|
||||
set(entries vertexStatic:vertex vertexSkinned:vertex fragmentMain:fragment depthMain:fragment)
|
||||
set(formats SPIRV DXIL MSL)
|
||||
get_filename_component(sourceDir ${SOURCE} DIRECTORY)
|
||||
get_filename_component(outputDir ${OUTPUT} DIRECTORY)
|
||||
set(work ${outputDir}/work)
|
||||
file(MAKE_DIRECTORY ${work})
|
||||
|
||||
set(header "// Generated from scene.hlsl by cmake/shaderHeader.cmake with SDL_shadercross; do not edit.\n")
|
||||
string(APPEND header "// SPIR-V for Vulkan, DXIL for Direct3D 12, MSL for Metal, one set per entry point.\n\n")
|
||||
string(APPEND header "#ifndef SCENE_SHADERS_H\n#define SCENE_SHADERS_H\n\n#include <stddef.h>\n\n")
|
||||
string(APPEND header "typedef struct SceneShaderS {\n\tconst char *entryPoint;\n\tconst unsigned char *spirv;\n\tsize_t spirvSize;\n\tconst unsigned char *dxil;\n\tsize_t dxilSize;\n\tconst unsigned char *msl;\n\tsize_t mslSize;\n} SceneShaderT;\n\n")
|
||||
foreach(entry IN LISTS entries)
|
||||
string(REPLACE ":" ";" parts ${entry})
|
||||
list(GET parts 0 name)
|
||||
list(GET parts 1 stage)
|
||||
foreach(format IN LISTS formats)
|
||||
string(TOLOWER ${format} extension)
|
||||
set(blob ${work}/${name}.${extension})
|
||||
execute_process(COMMAND ${SHADERCROSS} ${SOURCE} -s HLSL -d ${format} -t ${stage} -e ${name} -o ${blob} RESULT_VARIABLE code OUTPUT_VARIABLE out ERROR_VARIABLE err)
|
||||
if(NOT code EQUAL 0)
|
||||
message(FATAL_ERROR "Shader ${name} (${format}) failed to compile:\n${out}\n${err}")
|
||||
endif()
|
||||
file(READ ${blob} hex HEX)
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," bytes "${hex}")
|
||||
string(APPEND header "static const unsigned char _${name}${format}[] = {\n\t${bytes}\n};\n\n")
|
||||
endforeach()
|
||||
string(SUBSTRING ${name} 0 1 initial)
|
||||
string(SUBSTRING ${name} 1 -1 rest)
|
||||
string(TOUPPER ${initial} initial)
|
||||
string(APPEND header "static const SceneShaderT sceneShader${initial}${rest} = { \"${name}\", _${name}SPIRV, sizeof(_${name}SPIRV), _${name}DXIL, sizeof(_${name}DXIL), _${name}MSL, sizeof(_${name}MSL) };\n\n")
|
||||
endforeach()
|
||||
string(APPEND header "#endif\n")
|
||||
file(WRITE ${OUTPUT} "${header}")
|
||||
114
docs/Manual.adoc
114
docs/Manual.adoc
|
|
@ -771,9 +771,11 @@ for diagrams and HUD-like scenes.
|
|||
A model's animations are listed by `modelGetAnimations` and driven per
|
||||
instance with `animationPlay(node, nameOrIndex, loop, speed)` on the
|
||||
instance's root node, plus pause, resume, stop, and seek calls. Node
|
||||
animation (things moving) and skinning (characters deforming) both work;
|
||||
morph targets do not yet. Animations advance with real time and hold while
|
||||
the game is paused.
|
||||
animation (things moving), skinning (characters deforming) and morph
|
||||
targets (blend shapes: faces, lip sync, muscle bulges) all work; a model's
|
||||
morph weights can also be set from script with `nodeSetMorph`, by name or
|
||||
number, on the node that carries the mesh. Animations advance with real
|
||||
time and hold while the game is paused.
|
||||
|
||||
.From scene to overlay and back
|
||||
`sceneProject(x, y, z)` turns a world point into overlay coordinates, so
|
||||
|
|
@ -880,6 +882,39 @@ BODY_DYNAMIC, SHAPE_HULL)` wraps the whole model in a convex hull. Skinned
|
|||
characters are best driven kinematically with a capsule and left to push
|
||||
things rather than be pushed.
|
||||
|
||||
.2D games
|
||||
Physics is not tied to the 3D scene. Nodes exist on every machine, GPU or
|
||||
not, so a 2D game can give nodes bodies, call `physicsSet2D(true)` so they
|
||||
move in X and Y and turn about Z only, work in overlay coordinates with
|
||||
gravity pointing down the screen, and draw sprites where the nodes are:
|
||||
|
||||
[source,lua]
|
||||
----
|
||||
physicsSet2D(true)
|
||||
physicsSetGravity(0, 900, 0) -- Pixels per second squared; overlay Y runs down.
|
||||
|
||||
floor = nodeNew()
|
||||
nodeSetPosition(floor, 360, 470, 0)
|
||||
bodyNew(floor, BODY_STATIC, SHAPE_BOX, 720, 20, 50)
|
||||
|
||||
crate = nodeNew()
|
||||
nodeSetPosition(crate, 200, -40, 0)
|
||||
bodyNew(crate, BODY_DYNAMIC, SHAPE_BOX, 40, 40, 50)
|
||||
bodySetMass(crate, 1)
|
||||
|
||||
function onOverlayUpdate()
|
||||
local x, y = nodeGetPosition(crate)
|
||||
local _, _, angle = nodeGetRotation(crate)
|
||||
spriteRotate(crateArt, angle)
|
||||
spriteDraw(crateArt, x, y, true)
|
||||
return OVERLAY_UPDATED
|
||||
end
|
||||
----
|
||||
|
||||
Give every 2D body some depth (the third size) so shapes overlap in Z;
|
||||
`50` is fine. Circles are `SHAPE_SPHERE`. This is the form that runs on a
|
||||
Raspberry Pi 3, which has no 3D.
|
||||
|
||||
.Where it runs
|
||||
Physics runs on the CPU and needs no GPU, but the library is built for
|
||||
SSE4.1 on x86 (2008 and later) and NEON on the Pi; a machine below that
|
||||
|
|
@ -1078,8 +1113,8 @@ These calls drive the animations a model carries, per instance. Every one
|
|||
takes the *root node* returned by `modelInstance`; other nodes raise an
|
||||
error. Animations are numbered from `1` in the order `modelGetAnimations`
|
||||
lists them, or named. Time advances with the wall clock and holds while the
|
||||
game is paused. Node animation and skinning are supported; morph targets are
|
||||
not.
|
||||
game is paused. Node animation, skinning and morph target weights are all
|
||||
driven.
|
||||
|
||||
[#animationgettime]
|
||||
==== animationGetTime
|
||||
|
|
@ -3246,6 +3281,36 @@ The node's direct children as a table of handles, in the order they were added.
|
|||
*Since:* 3.00.
|
||||
*See also:* <<nodegetparent,nodeGetParent>>
|
||||
|
||||
[#nodegetmorph]
|
||||
==== nodeGetMorph
|
||||
|
||||
[source,text]
|
||||
----
|
||||
weight = nodeGetMorph(node, nameOrIndex)
|
||||
----
|
||||
|
||||
The current weight of one of the mesh's morph targets.
|
||||
|
||||
*Returns:* A number.
|
||||
|
||||
*Since:* 3.00.
|
||||
*See also:* <<nodesetmorph,nodeSetMorph>>, <<nodegetmorphs,nodeGetMorphs>>
|
||||
|
||||
[#nodegetmorphs]
|
||||
==== nodeGetMorphs
|
||||
|
||||
[source,text]
|
||||
----
|
||||
names = nodeGetMorphs(node)
|
||||
----
|
||||
|
||||
The morph targets of the node's mesh, in the order the file stores them, as a table of names. Exporters that write no names give empty strings; those targets can still be set by number.
|
||||
|
||||
*Returns:* A table of strings.
|
||||
|
||||
*Since:* 3.00.
|
||||
*See also:* <<nodesetmorph,nodeSetMorph>>
|
||||
|
||||
[#nodegetname]
|
||||
==== nodeGetName
|
||||
|
||||
|
|
@ -3404,6 +3469,32 @@ Gives the node a mesh to draw, optionally with a material (default look otherwis
|
|||
*Since:* 3.00.
|
||||
*See also:* <<meshbox,meshBox>>, <<materialnew,materialNew>>, <<nodesetvisible,nodeSetVisible>>
|
||||
|
||||
[#nodesetmorph]
|
||||
==== nodeSetMorph
|
||||
|
||||
[source,text]
|
||||
----
|
||||
nodeSetMorph(node, nameOrIndex, weight)
|
||||
----
|
||||
|
||||
How much of a morph target (blend shape) the node's mesh shows, usually `0` to `1`; several targets add up. The node is the one carrying the mesh, which for a model is a child of the instance root (`nodeFind` by the mesh's name, or `nodeGetChildren`). An animation with a weights channel overrides what you set while it plays.
|
||||
|
||||
*Notes:* Up to eight targets with non-zero weights apply per mesh in a frame, the strongest if there are more.
|
||||
|
||||
*Since:* 3.00.
|
||||
*See also:* <<nodegetmorph,nodeGetMorph>>, <<nodegetmorphs,nodeGetMorphs>>, <<animationplay,animationPlay>>
|
||||
|
||||
.Example
|
||||
[source,lua]
|
||||
----
|
||||
-- Lip sync from a table of mouth openings per disc frame.
|
||||
face = nodeFind("Head", hero)
|
||||
function onOverlayUpdate()
|
||||
nodeSetMorph(face, "mouthOpen", mouthByFrame[discGetFrame()] or 0)
|
||||
return OVERLAY_UPDATED
|
||||
end
|
||||
----
|
||||
|
||||
[#nodesetname]
|
||||
==== nodeSetName
|
||||
|
||||
|
|
@ -3723,6 +3814,19 @@ The first body along a ray from `(x, y, z)` in the direction `(dx, dy, dz)` (any
|
|||
*Since:* 3.00.
|
||||
*See also:* <<sceneunproject,sceneUnproject>>, <<bodyapplyimpulse,bodyApplyImpulse>>
|
||||
|
||||
[#physicsset2d]
|
||||
==== physicsSet2D
|
||||
|
||||
[source,text]
|
||||
----
|
||||
physicsSet2D(planar)
|
||||
----
|
||||
|
||||
Bodies made from now on move only in X and Y and turn only about Z: a 2D game's world, usually in overlay coordinates with gravity pointing +Y. Bodies already made keep their freedom. Works without a GPU, the Raspberry Pi 3 included.
|
||||
|
||||
*Since:* 3.00.
|
||||
*See also:* <<physicssetgravity,physicsSetGravity>>, <<bodynew,bodyNew>>
|
||||
|
||||
[#physicssetenabled]
|
||||
==== physicsSetEnabled
|
||||
|
||||
|
|
|
|||
134
src/model.c
134
src/model.c
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
#define NO_HANDLE -1
|
||||
#define ERROR_LENGTH 256
|
||||
#define MAX_MORPH_TARGETS 64
|
||||
#define DEGREES(r) ((r) * (180.0f / 3.14159265358979323846f))
|
||||
|
||||
|
||||
|
|
@ -93,9 +94,11 @@ static void _freeStaleInstances(void);
|
|||
static SDL_Surface *_loadImage(const cgltf_image *image);
|
||||
static int32_t _loadMaterial(const cgltf_material *material);
|
||||
static bool _loadMeshes(ModelT *model);
|
||||
static int32_t _loadPrimitive(const cgltf_primitive *primitive);
|
||||
static void _loadMorphs(int32_t mesh, const cgltf_mesh *source, const cgltf_primitive *primitive, int32_t vertexCount);
|
||||
static int32_t _loadPrimitive(const cgltf_mesh *source, const cgltf_primitive *primitive);
|
||||
static bool _readAttribute(const cgltf_accessor *accessor, float *out, int32_t components, int32_t count);
|
||||
static void _sampleChannel(const cgltf_animation_channel *channel, double time, float *out, int32_t components);
|
||||
static void _sampleWeights(const cgltf_animation_channel *channel, double time, float *out, int32_t count);
|
||||
|
||||
|
||||
static ModelT *_models;
|
||||
|
|
@ -172,6 +175,7 @@ static void _applyAnimation(InstanceT *instance) {
|
|||
const cgltf_animation *animation;
|
||||
int32_t x;
|
||||
float values[4];
|
||||
float morphValues[MAX_MORPH_TARGETS];
|
||||
|
||||
if ((instance->animation < 0) || (instance->animation >= (int32_t)data->animations_count)) {
|
||||
return;
|
||||
|
|
@ -203,6 +207,27 @@ static void _applyAnimation(InstanceT *instance) {
|
|||
} else if (channel->target_path == cgltf_animation_path_type_scale) {
|
||||
_sampleChannel(channel, instance->time, values, 3);
|
||||
nodeSetScale(node, vec3(values[0], values[1], values[2]));
|
||||
} else if (channel->target_path == cgltf_animation_path_type_weights) {
|
||||
// One weight per target per keyframe, to the node's own mesh or its primitive children.
|
||||
int32_t count = (int32_t)(channel->sampler->output->count / channel->sampler->input->count);
|
||||
int32_t w;
|
||||
int32_t c;
|
||||
|
||||
if ((count <= 0) || (count > MAX_MORPH_TARGETS)) {
|
||||
continue;
|
||||
}
|
||||
_sampleWeights(channel, instance->time, morphValues, count);
|
||||
if (nodeGetMorphCount(node) > 0) {
|
||||
for (w = 0; w < count; w++) {
|
||||
nodeSetMorphWeight(node, w, morphValues[w]);
|
||||
}
|
||||
} else {
|
||||
for (c = 0; c < nodeGetChildCount(node); c++) {
|
||||
for (w = 0; w < count; w++) {
|
||||
nodeSetMorphWeight(nodeGetChild(node, c), w, morphValues[w]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -289,15 +314,25 @@ static void _buildNode(ModelT *model, InstanceT *instance, const cgltf_node *nod
|
|||
nodeSetRotation(handle, rotation);
|
||||
nodeSetScale(handle, scale);
|
||||
if (node->mesh != NULL) {
|
||||
const float *weights = (node->weights_count > 0) ? node->weights : node->mesh->weights;
|
||||
int32_t weightCount = (int32_t)((node->weights_count > 0) ? node->weights_count : node->mesh->weights_count);
|
||||
int32_t w;
|
||||
|
||||
mesh = &model->meshes[node->mesh - model->data->meshes];
|
||||
if (mesh->count == 1) {
|
||||
nodeSetMesh(handle, mesh->primitives[0].mesh, mesh->primitives[0].material);
|
||||
for (w = 0; w < weightCount; w++) {
|
||||
nodeSetMorphWeight(handle, w, weights[w]);
|
||||
}
|
||||
} else {
|
||||
for (x = 0; x < mesh->count; x++) {
|
||||
int32_t child = nodeNew(handle);
|
||||
|
||||
if (child != NO_HANDLE) {
|
||||
nodeSetMesh(child, mesh->primitives[x].mesh, mesh->primitives[x].material);
|
||||
for (w = 0; w < weightCount; w++) {
|
||||
nodeSetMorphWeight(child, w, weights[w]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -489,7 +524,7 @@ static bool _loadMeshes(ModelT *model) {
|
|||
utilTrace("Model: mesh %s primitive %d is not triangles; skipped.", data->meshes[x].name ? data->meshes[x].name : "(unnamed)", y);
|
||||
continue;
|
||||
}
|
||||
mesh = _loadPrimitive(primitive);
|
||||
mesh = _loadPrimitive(&data->meshes[x], primitive);
|
||||
if (mesh == NO_HANDLE) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -502,9 +537,58 @@ static bool _loadMeshes(ModelT *model) {
|
|||
}
|
||||
|
||||
|
||||
// The primitive's morph targets: position and normal deltas per target, named from the mesh's
|
||||
// target names when the exporter wrote them.
|
||||
static void _loadMorphs(int32_t mesh, const cgltf_mesh *source, const cgltf_primitive *primitive, int32_t vertexCount) {
|
||||
int32_t targetCount = (int32_t)primitive->targets_count;
|
||||
float *deltas;
|
||||
float *values;
|
||||
const char **names = NULL;
|
||||
int32_t t;
|
||||
int32_t x;
|
||||
int32_t a;
|
||||
|
||||
deltas = SDL_calloc((size_t)targetCount * (size_t)vertexCount * 6, sizeof(float));
|
||||
values = SDL_calloc((size_t)vertexCount * 3, sizeof(float));
|
||||
if ((deltas == NULL) || (values == NULL)) {
|
||||
utilDie("Out of memory loading morph targets.");
|
||||
}
|
||||
for (t = 0; t < targetCount; t++) {
|
||||
const cgltf_morph_target *target = &primitive->targets[t];
|
||||
|
||||
for (a = 0; a < (int32_t)target->attributes_count; a++) {
|
||||
const cgltf_attribute *attribute = &target->attributes[a];
|
||||
int32_t offset;
|
||||
|
||||
if ((attribute->type == cgltf_attribute_type_position) && (attribute->index == 0)) {
|
||||
offset = 0;
|
||||
} else if ((attribute->type == cgltf_attribute_type_normal) && (attribute->index == 0)) {
|
||||
offset = 3;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (!_readAttribute(attribute->data, values, 3, vertexCount)) {
|
||||
continue;
|
||||
}
|
||||
for (x = 0; x < vertexCount; x++) {
|
||||
deltas[((size_t)t * (size_t)vertexCount + (size_t)x) * 6 + (size_t)offset] = values[x * 3];
|
||||
deltas[((size_t)t * (size_t)vertexCount + (size_t)x) * 6 + (size_t)offset + 1] = values[x * 3 + 1];
|
||||
deltas[((size_t)t * (size_t)vertexCount + (size_t)x) * 6 + (size_t)offset + 2] = values[x * 3 + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((source->target_names != NULL) && ((int32_t)source->target_names_count >= targetCount)) {
|
||||
names = (const char **)source->target_names;
|
||||
}
|
||||
meshSetMorphTargets(mesh, deltas, targetCount, names);
|
||||
SDL_free(values);
|
||||
SDL_free(deltas);
|
||||
}
|
||||
|
||||
|
||||
// One primitive as a scene mesh: positions, normals (computed when absent), texture
|
||||
// coordinates, joints and weights when skinned, and indices (generated when absent).
|
||||
static int32_t _loadPrimitive(const cgltf_primitive *primitive) {
|
||||
static int32_t _loadPrimitive(const cgltf_mesh *source, const cgltf_primitive *primitive) {
|
||||
const cgltf_accessor *positions = NULL;
|
||||
const cgltf_accessor *normals = NULL;
|
||||
const cgltf_accessor *uvs = NULL;
|
||||
|
|
@ -595,6 +679,8 @@ static int32_t _loadPrimitive(const cgltf_primitive *primitive) {
|
|||
mesh = meshNewVertices(vertices, vertexCount, indices, indexCount, (joints != NULL) && (weights != NULL));
|
||||
if (mesh == NO_HANDLE) {
|
||||
_fail("Unable to upload a primitive.");
|
||||
} else if (primitive->targets_count > 0) {
|
||||
_loadMorphs(mesh, source, primitive, vertexCount);
|
||||
}
|
||||
SDL_free(values);
|
||||
SDL_free(indices);
|
||||
|
|
@ -700,6 +786,48 @@ static void _sampleChannel(const cgltf_animation_channel *channel, double time,
|
|||
}
|
||||
|
||||
|
||||
// A weights channel at a time: count scalars per keyframe, linear or step (cubic spline treated
|
||||
// as linear between its values), clamped at both ends.
|
||||
static void _sampleWeights(const cgltf_animation_channel *channel, double time, float *out, int32_t count) {
|
||||
const cgltf_accessor *input = channel->sampler->input;
|
||||
const cgltf_accessor *output = channel->sampler->output;
|
||||
int32_t keys = (int32_t)input->count;
|
||||
int32_t k;
|
||||
int32_t next;
|
||||
int32_t stride = (channel->sampler->interpolation == cgltf_interpolation_type_cubic_spline) ? 3 : 1;
|
||||
float t0;
|
||||
float t1;
|
||||
float t;
|
||||
float a;
|
||||
float b;
|
||||
int32_t w;
|
||||
|
||||
if (keys == 0) {
|
||||
return;
|
||||
}
|
||||
for (k = 0; k < keys - 1; k++) {
|
||||
cgltf_accessor_read_float(input, (cgltf_size)(k + 1), &t1, 1);
|
||||
if (time < t1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
next = SDL_min(k + 1, keys - 1);
|
||||
cgltf_accessor_read_float(input, (cgltf_size)k, &t0, 1);
|
||||
cgltf_accessor_read_float(input, (cgltf_size)next, &t1, 1);
|
||||
t = (t1 > t0) ? (float)((time - t0) / (t1 - t0)) : 0.0f;
|
||||
t = SDL_clamp(t, 0.0f, 1.0f);
|
||||
if (channel->sampler->interpolation == cgltf_interpolation_type_step) {
|
||||
t = 0.0f;
|
||||
}
|
||||
for (w = 0; w < count; w++) {
|
||||
// Cubic spline keyframes hold in-tangent, value, out-tangent per weight; the value is the middle.
|
||||
cgltf_accessor_read_float(output, (cgltf_size)((k * stride + (stride == 3 ? 1 : 0)) * count + w), &a, 1);
|
||||
cgltf_accessor_read_float(output, (cgltf_size)((next * stride + (stride == 3 ? 1 : 0)) * count + w), &b, 1);
|
||||
out[w] = a + (b - a) * t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===== Animation (on a model instance's root node) =====
|
||||
|
||||
double animationGetTime(int32_t root) {
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ int32_t physicsGetEvents(PhysicsEventT *events, int32_t maximum);
|
|||
bool physicsInit(void);
|
||||
void physicsQuit(void);
|
||||
bool physicsRaycast(Vec3T origin, Vec3T direction, float maxDistance, int32_t *node, Vec3T *point, Vec3T *normal);
|
||||
void physicsSet2D(bool planar);
|
||||
void physicsSetEnabled(bool enabled);
|
||||
void physicsSetGravity(Vec3T gravity);
|
||||
void physicsUpdate(bool advance);
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ namespace {
|
|||
double accumulator; // Seconds owed to the fixed step
|
||||
uint64_t lastTick;
|
||||
bool enabled;
|
||||
bool planar; // New bodies keep to the XY plane (2D games)
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -568,6 +569,10 @@ bool bodyNew(int32_t node, BodyTypeE type, ShapeTypeE shape, float a, float b, f
|
|||
settings.mFriction = DEFAULT_FRICTION;
|
||||
settings.mRestitution = DEFAULT_BOUNCE;
|
||||
settings.mUserData = (JPH::uint64)(uint32_t)node;
|
||||
if (_world->planar) {
|
||||
// Moves in X and Y, turns about Z, nothing else: a 2D game's world.
|
||||
settings.mAllowedDOFs = JPH::EAllowedDOFs::Plane2D;
|
||||
}
|
||||
record->id = _world->system->GetBodyInterface().CreateAndAddBody(settings, JPH::EActivation::Activate);
|
||||
}
|
||||
if (record->id.IsInvalid()) {
|
||||
|
|
@ -929,6 +934,16 @@ bool physicsRaycast(Vec3T origin, Vec3T direction, float maxDistance, int32_t *n
|
|||
}
|
||||
|
||||
|
||||
// 2D mode for bodies made from now on: they move in X and Y and turn about Z only, so a 2D game
|
||||
// can run its world in overlay coordinates (gravity pointing +Y then, since the overlay's Y runs
|
||||
// down) and draw sprites where the nodes are. Bodies already made keep their freedom.
|
||||
void physicsSet2D(bool planar) {
|
||||
if (_world != nullptr) {
|
||||
_world->planar = planar;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pauses the simulation (bodies hold still) without losing it.
|
||||
void physicsSetEnabled(bool enabled) {
|
||||
if (_world != nullptr) {
|
||||
|
|
|
|||
242
src/scene.c
242
src/scene.c
|
|
@ -64,13 +64,18 @@
|
|||
#define SHADOW_BIAS 0.0015f
|
||||
#define SHADOW_MARGIN 1.05f // The fitted light frustum, a little larger than the scene
|
||||
#define SKIN_BOUNDS_GROW 1.5f // A skinned mesh moves beyond its bind pose
|
||||
#define MAX_MORPHS 8 // Active morph targets per draw (the shader's limit)
|
||||
#define MORPH_FLOATS 8 // Per target per vertex: position delta xyz + pad, normal delta xyz + pad
|
||||
|
||||
|
||||
// Matches DrawUniforms in scene.hlsl.
|
||||
typedef struct DrawUniformsS {
|
||||
Mat4T modelViewProjection;
|
||||
Mat4T model;
|
||||
Mat4T normalMatrix;
|
||||
Mat4T modelViewProjection;
|
||||
Mat4T model;
|
||||
Mat4T normalMatrix;
|
||||
float morphWeights[MAX_MORPHS];
|
||||
int32_t morphTargets[MAX_MORPHS];
|
||||
int32_t morphInfo[4];
|
||||
} DrawUniformsT;
|
||||
|
||||
// Matches Light and FragmentUniforms in scene.hlsl.
|
||||
|
|
@ -114,6 +119,9 @@ typedef struct MeshS {
|
|||
float *positions; // A CPU copy of the geometry (x, y, z per vertex) for physics shapes
|
||||
uint32_t *indices;
|
||||
int32_t vertexCount;
|
||||
SDL_GPUBuffer *morphBuffer; // Morph target deltas, MORPH_FLOATS per vertex per target
|
||||
char **morphNames;
|
||||
int32_t morphCount;
|
||||
bool skinned;
|
||||
bool used;
|
||||
} MeshT;
|
||||
|
|
@ -162,6 +170,8 @@ typedef struct NodeS {
|
|||
int32_t material;
|
||||
LightT light;
|
||||
bool castsShadow;
|
||||
float *morphWeights; // One per target of the node's mesh
|
||||
int32_t morphCount;
|
||||
int32_t *skinJoints; // Nodes whose world matrices drive a skinned mesh
|
||||
Mat4T *skinInverseBind;
|
||||
int32_t skinCount;
|
||||
|
|
@ -208,6 +218,7 @@ typedef struct SceneS {
|
|||
ShadowT shadows[MAX_SHADOWS];
|
||||
int32_t shadowCount;
|
||||
SDL_GPUTexture *white; // 1x1 stand-in for untextured materials
|
||||
SDL_GPUBuffer *noMorphs; // Stand-in delta buffer for meshes without morph targets
|
||||
SDL_FColor background;
|
||||
Vec3T ambient;
|
||||
NodeT *nodes;
|
||||
|
|
@ -243,7 +254,7 @@ static bool _createPipeline(int32_t variant);
|
|||
static SDL_GPUTexture *_createShadowArray(SDL_GPUTextureType type, int32_t layers, int32_t size);
|
||||
static bool _createShadowMaps(int32_t layers);
|
||||
static bool _createShadowPipeline(int32_t variant);
|
||||
static SDL_GPUShader *_createShader(const SceneShaderT *shader, SDL_GPUShaderStage stage, uint32_t samplers, uint32_t uniforms);
|
||||
static SDL_GPUShader *_createShader(const SceneShaderT *shader, SDL_GPUShaderStage stage, uint32_t samplers, uint32_t uniforms, uint32_t storageBuffers);
|
||||
static bool _createShaders(void);
|
||||
static SDL_GPUTextureFormat _depthFormat(void);
|
||||
static SDL_GPUTextureFormat _shadowFormat(void);
|
||||
|
|
@ -256,7 +267,10 @@ static void _fillLights(FragmentUniformsT *uniforms);
|
|||
static void _fitShadows(int32_t drawCount);
|
||||
static void _fillSkin(const NodeT *node, SkinUniformsT *uniforms);
|
||||
static void _freeFeed(FeedT *feed);
|
||||
static void _freeMorphs(MeshT *mesh);
|
||||
static void _freeMorphWeights(NodeT *node);
|
||||
static void _freeSkin(NodeT *node);
|
||||
static void _matchMorphWeights(NodeT *node);
|
||||
static void _freeMaterialTexture(MaterialT *material);
|
||||
static void _lathe(SceneVertexT **vertices, int32_t *vertexCount, uint32_t **indices, int32_t *indexCount, float bottomRadius, float topRadius, float height, int32_t segments);
|
||||
static int32_t _lookupPipeline(int32_t node);
|
||||
|
|
@ -531,7 +545,7 @@ static bool _createPipeline(int32_t variant) {
|
|||
|
||||
|
||||
// Picks the blob for the format the device accepts.
|
||||
static SDL_GPUShader *_createShader(const SceneShaderT *shader, SDL_GPUShaderStage stage, uint32_t samplers, uint32_t uniforms) {
|
||||
static SDL_GPUShader *_createShader(const SceneShaderT *shader, SDL_GPUShaderStage stage, uint32_t samplers, uint32_t uniforms, uint32_t storageBuffers) {
|
||||
SDL_GPUShaderCreateInfo info;
|
||||
SDL_GPUShaderFormat formats = SDL_GetGPUShaderFormats(_scene.device);
|
||||
SDL_GPUShader *result;
|
||||
|
|
@ -557,6 +571,7 @@ static SDL_GPUShader *_createShader(const SceneShaderT *shader, SDL_GPUShaderSta
|
|||
info.stage = stage;
|
||||
info.num_samplers = samplers;
|
||||
info.num_uniform_buffers = uniforms;
|
||||
info.num_storage_buffers = storageBuffers;
|
||||
result = SDL_CreateGPUShader(_scene.device, &info);
|
||||
if (result == NULL) {
|
||||
utilTrace("Scene: shader %s: %s", shader->entryPoint, SDL_GetError());
|
||||
|
|
@ -566,10 +581,10 @@ static SDL_GPUShader *_createShader(const SceneShaderT *shader, SDL_GPUShaderSta
|
|||
|
||||
|
||||
static bool _createShaders(void) {
|
||||
_scene.vertexStatic = _createShader(&sceneShaderVertexStatic, SDL_GPU_SHADERSTAGE_VERTEX, 0, 1);
|
||||
_scene.vertexSkinned = _createShader(&sceneShaderVertexSkinned, SDL_GPU_SHADERSTAGE_VERTEX, 0, 2);
|
||||
_scene.fragment = _createShader(&sceneShaderFragmentMain, SDL_GPU_SHADERSTAGE_FRAGMENT, 2, 1);
|
||||
_scene.depthFragment = _createShader(&sceneShaderDepthMain, SDL_GPU_SHADERSTAGE_FRAGMENT, 0, 0);
|
||||
_scene.vertexStatic = _createShader(&sceneShaderVertexStatic, SDL_GPU_SHADERSTAGE_VERTEX, 0, 1, 1);
|
||||
_scene.vertexSkinned = _createShader(&sceneShaderVertexSkinned, SDL_GPU_SHADERSTAGE_VERTEX, 0, 2, 1);
|
||||
_scene.fragment = _createShader(&sceneShaderFragmentMain, SDL_GPU_SHADERSTAGE_FRAGMENT, 2, 1, 0);
|
||||
_scene.depthFragment = _createShader(&sceneShaderDepthMain, SDL_GPU_SHADERSTAGE_FRAGMENT, 0, 0, 0);
|
||||
return (_scene.vertexStatic != NULL) && (_scene.vertexSkinned != NULL) && (_scene.fragment != NULL) && (_scene.depthFragment != NULL);
|
||||
}
|
||||
|
||||
|
|
@ -783,6 +798,7 @@ static void _drawList(SDL_GPUCommandBuffer *commands, SDL_GPURenderPass *pass, i
|
|||
SDL_BindGPUGraphicsPipeline(pass, pipeline);
|
||||
lastPipeline = variant;
|
||||
}
|
||||
memset(&drawUniforms, 0, sizeof(drawUniforms));
|
||||
drawUniforms.modelViewProjection = mat4Multiply(*viewProjection, node->world);
|
||||
drawUniforms.model = node->world;
|
||||
if (mat4Invert(node->world, &inverse)) {
|
||||
|
|
@ -790,7 +806,40 @@ static void _drawList(SDL_GPUCommandBuffer *commands, SDL_GPURenderPass *pass, i
|
|||
} else {
|
||||
drawUniforms.normalMatrix = identity;
|
||||
}
|
||||
// The strongest active morph targets, up to the shader's limit.
|
||||
if ((mesh->morphBuffer != NULL) && (node->morphCount == mesh->morphCount)) {
|
||||
int32_t active = 0;
|
||||
int32_t t;
|
||||
|
||||
for (t = 0; t < node->morphCount; t++) {
|
||||
if (node->morphWeights[t] == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
if (active < MAX_MORPHS) {
|
||||
drawUniforms.morphWeights[active] = node->morphWeights[t];
|
||||
drawUniforms.morphTargets[active] = t;
|
||||
active++;
|
||||
} else {
|
||||
// Replace the weakest chosen one if this is stronger.
|
||||
int32_t weakest = 0;
|
||||
int32_t k;
|
||||
|
||||
for (k = 1; k < MAX_MORPHS; k++) {
|
||||
if (fabsf(drawUniforms.morphWeights[k]) < fabsf(drawUniforms.morphWeights[weakest])) {
|
||||
weakest = k;
|
||||
}
|
||||
}
|
||||
if (fabsf(node->morphWeights[t]) > fabsf(drawUniforms.morphWeights[weakest])) {
|
||||
drawUniforms.morphWeights[weakest] = node->morphWeights[t];
|
||||
drawUniforms.morphTargets[weakest] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
drawUniforms.morphInfo[0] = active;
|
||||
drawUniforms.morphInfo[1] = mesh->vertexCount;
|
||||
}
|
||||
SDL_PushGPUVertexUniformData(commands, 0, &drawUniforms, sizeof(drawUniforms));
|
||||
SDL_BindGPUVertexStorageBuffers(pass, 0, (mesh->morphBuffer != NULL) ? &mesh->morphBuffer : &_scene.noMorphs, 1);
|
||||
if (mesh->skinned && (node->skinCount > 0)) {
|
||||
// 8 KB per skinned draw; allocated once per pass that needs it.
|
||||
if (skinUniforms == NULL) {
|
||||
|
|
@ -1051,6 +1100,29 @@ static void _freeMaterialTexture(MaterialT *material) {
|
|||
}
|
||||
|
||||
|
||||
static void _freeMorphs(MeshT *mesh) {
|
||||
int32_t x;
|
||||
|
||||
if (mesh->morphBuffer != NULL) {
|
||||
SDL_ReleaseGPUBuffer(_scene.device, mesh->morphBuffer);
|
||||
mesh->morphBuffer = NULL;
|
||||
}
|
||||
for (x = 0; x < mesh->morphCount; x++) {
|
||||
SDL_free(mesh->morphNames[x]);
|
||||
}
|
||||
SDL_free(mesh->morphNames);
|
||||
mesh->morphNames = NULL;
|
||||
mesh->morphCount = 0;
|
||||
}
|
||||
|
||||
|
||||
static void _freeMorphWeights(NodeT *node) {
|
||||
SDL_free(node->morphWeights);
|
||||
node->morphWeights = NULL;
|
||||
node->morphCount = 0;
|
||||
}
|
||||
|
||||
|
||||
static void _freeSkin(NodeT *node) {
|
||||
SDL_free(node->skinJoints);
|
||||
SDL_free(node->skinInverseBind);
|
||||
|
|
@ -1131,6 +1203,24 @@ static void _lathe(SceneVertexT **vertices, int32_t *vertexCount, uint32_t **ind
|
|||
}
|
||||
|
||||
|
||||
// Sizes the node's weight list to its mesh's targets (weights start at 0).
|
||||
static void _matchMorphWeights(NodeT *node) {
|
||||
int32_t count = ((node->mesh != NO_HANDLE) && meshValid(node->mesh)) ? _scene.meshes[node->mesh].morphCount : 0;
|
||||
|
||||
if (count == node->morphCount) {
|
||||
return;
|
||||
}
|
||||
_freeMorphWeights(node);
|
||||
if (count > 0) {
|
||||
node->morphWeights = SDL_calloc((size_t)count, sizeof(float));
|
||||
if (node->morphWeights == NULL) {
|
||||
utilDie("Out of memory allocating morph weights.");
|
||||
}
|
||||
node->morphCount = count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// What the fragment shader samples for a material: its video feed, its image, or NULL.
|
||||
static SDL_GPUTexture *_materialTexture(const MaterialT *material) {
|
||||
if ((material->feed != NO_HANDLE) && (material->feed < _scene.feedCount) && _scene.feeds[material->feed].used) {
|
||||
|
|
@ -1680,16 +1770,34 @@ bool meshDelete(int32_t mesh) {
|
|||
}
|
||||
SDL_free(_scene.meshes[mesh].positions);
|
||||
SDL_free(_scene.meshes[mesh].indices);
|
||||
_freeMorphs(&_scene.meshes[mesh]);
|
||||
memset(&_scene.meshes[mesh], 0, sizeof(MeshT));
|
||||
for (x = 0; x < _scene.nodeCount; x++) {
|
||||
if (_scene.nodes[x].used && (_scene.nodes[x].mesh == mesh)) {
|
||||
_scene.nodes[x].mesh = NO_HANDLE;
|
||||
_freeMorphWeights(&_scene.nodes[x]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// A morph target by name, or -1.
|
||||
int32_t meshFindMorph(int32_t mesh, const char *name) {
|
||||
int32_t x;
|
||||
|
||||
if (!meshValid(mesh) || (name == NULL)) {
|
||||
return NO_HANDLE;
|
||||
}
|
||||
for (x = 0; x < _scene.meshes[mesh].morphCount; x++) {
|
||||
if ((_scene.meshes[mesh].morphNames[x] != NULL) && (strcmp(_scene.meshes[mesh].morphNames[x], name) == 0)) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
return NO_HANDLE;
|
||||
}
|
||||
|
||||
|
||||
// The mesh's geometry as kept on the CPU: x, y, z per vertex and triangle indices.
|
||||
bool meshGetGeometry(int32_t mesh, const float **positions, int32_t *vertexCount, const uint32_t **indices, int32_t *indexCount) {
|
||||
if (!meshValid(mesh)) {
|
||||
|
|
@ -1703,6 +1811,22 @@ bool meshGetGeometry(int32_t mesh, const float **positions, int32_t *vertexCount
|
|||
}
|
||||
|
||||
|
||||
int32_t meshGetMorphCount(int32_t mesh) {
|
||||
if (!meshValid(mesh)) {
|
||||
return 0;
|
||||
}
|
||||
return _scene.meshes[mesh].morphCount;
|
||||
}
|
||||
|
||||
|
||||
const char *meshGetMorphName(int32_t mesh, int32_t target) {
|
||||
if (!meshValid(mesh) || (target < 0) || (target >= _scene.meshes[mesh].morphCount) || (_scene.meshes[mesh].morphNames[target] == NULL)) {
|
||||
return "";
|
||||
}
|
||||
return _scene.meshes[mesh].morphNames[target];
|
||||
}
|
||||
|
||||
|
||||
// Raw geometry from a script: positions (3 per vertex), normals (3, may be NULL for flat
|
||||
// shading computed here), uvs (2, may be NULL), and triangle indices.
|
||||
int32_t meshNew(const float *positions, const float *normals, const float *uvs, int32_t vertexCount, const uint32_t *indices, int32_t indexCount) {
|
||||
|
|
@ -1770,6 +1894,56 @@ int32_t meshPlane(float width, float depth) {
|
|||
}
|
||||
|
||||
|
||||
// Gives the mesh morph targets: deltas holds, per target, per vertex, a position delta (x, y, z)
|
||||
// and a normal delta (x, y, z), six floats; names may be NULL or hold NULL entries. Nodes using
|
||||
// the mesh get a weight per target, all 0.
|
||||
bool meshSetMorphTargets(int32_t mesh, const float *deltas, int32_t targetCount, const char **names) {
|
||||
MeshT *m;
|
||||
float *packed;
|
||||
int32_t count;
|
||||
int32_t x;
|
||||
|
||||
if (!meshValid(mesh) || (deltas == NULL) || (targetCount <= 0)) {
|
||||
return false;
|
||||
}
|
||||
m = &_scene.meshes[mesh];
|
||||
count = targetCount * m->vertexCount;
|
||||
packed = SDL_calloc((size_t)count * MORPH_FLOATS, sizeof(float));
|
||||
if (packed == NULL) {
|
||||
utilDie("Out of memory packing morph targets.");
|
||||
}
|
||||
// float4 pairs for the shader: xyz0 position delta, xyz0 normal delta.
|
||||
for (x = 0; x < count; x++) {
|
||||
packed[x * MORPH_FLOATS] = deltas[x * 6];
|
||||
packed[x * MORPH_FLOATS + 1] = deltas[x * 6 + 1];
|
||||
packed[x * MORPH_FLOATS + 2] = deltas[x * 6 + 2];
|
||||
packed[x * MORPH_FLOATS + 4] = deltas[x * 6 + 3];
|
||||
packed[x * MORPH_FLOATS + 5] = deltas[x * 6 + 4];
|
||||
packed[x * MORPH_FLOATS + 6] = deltas[x * 6 + 5];
|
||||
}
|
||||
_freeMorphs(m);
|
||||
m->morphBuffer = _uploadBuffer(SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ, packed, (uint32_t)((size_t)count * MORPH_FLOATS * sizeof(float)));
|
||||
SDL_free(packed);
|
||||
if (m->morphBuffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
m->morphNames = SDL_calloc((size_t)targetCount, sizeof(char *));
|
||||
if (m->morphNames == NULL) {
|
||||
utilDie("Out of memory naming morph targets.");
|
||||
}
|
||||
for (x = 0; x < targetCount; x++) {
|
||||
m->morphNames[x] = ((names != NULL) && (names[x] != NULL)) ? SDL_strdup(names[x]) : NULL;
|
||||
}
|
||||
m->morphCount = targetCount;
|
||||
for (x = 0; x < _scene.nodeCount; x++) {
|
||||
if (_scene.nodes[x].used && (_scene.nodes[x].mesh == mesh)) {
|
||||
_matchMorphWeights(&_scene.nodes[x]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Latitude/longitude sphere; segments around, half as many from pole to pole.
|
||||
int32_t meshSphere(float radius, int32_t segments) {
|
||||
SceneVertexT *vertices;
|
||||
|
|
@ -1905,6 +2079,7 @@ bool nodeDelete(int32_t node) {
|
|||
}
|
||||
SDL_free(_scene.nodes[node].name);
|
||||
_freeSkin(&_scene.nodes[node]);
|
||||
_freeMorphWeights(&_scene.nodes[node]);
|
||||
_scene.nodes[node].name = NULL;
|
||||
_scene.nodes[node].used = false;
|
||||
return true;
|
||||
|
|
@ -1979,6 +2154,22 @@ int32_t nodeGetMesh(int32_t node) {
|
|||
}
|
||||
|
||||
|
||||
int32_t nodeGetMorphCount(int32_t node) {
|
||||
if (!nodeValid(node)) {
|
||||
return 0;
|
||||
}
|
||||
return _scene.nodes[node].morphCount;
|
||||
}
|
||||
|
||||
|
||||
float nodeGetMorphWeight(int32_t node, int32_t target) {
|
||||
if (!nodeValid(node) || (target < 0) || (target >= _scene.nodes[node].morphCount)) {
|
||||
return 0.0f;
|
||||
}
|
||||
return _scene.nodes[node].morphWeights[target];
|
||||
}
|
||||
|
||||
|
||||
const char *nodeGetName(int32_t node) {
|
||||
if (!nodeValid(node) || (_scene.nodes[node].name == NULL)) {
|
||||
return "";
|
||||
|
|
@ -2077,9 +2268,6 @@ bool nodeMove(int32_t node, Vec3T delta) {
|
|||
int32_t nodeNew(int32_t parent) {
|
||||
int32_t node;
|
||||
|
||||
if (_scene.device == NULL) {
|
||||
return NO_HANDLE;
|
||||
}
|
||||
if (parent == NO_HANDLE) {
|
||||
parent = SCENE_ROOT_NODE;
|
||||
}
|
||||
|
|
@ -2115,6 +2303,17 @@ bool nodeSetMesh(int32_t node, int32_t mesh, int32_t material) {
|
|||
}
|
||||
_scene.nodes[node].mesh = mesh;
|
||||
_scene.nodes[node].material = material;
|
||||
_matchMorphWeights(&_scene.nodes[node]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// How much of a morph target the node's mesh shows (usually 0 to 1).
|
||||
bool nodeSetMorphWeight(int32_t node, int32_t target, float weight) {
|
||||
if (!nodeValid(node) || (target < 0) || (target >= _scene.nodes[node].morphCount)) {
|
||||
return false;
|
||||
}
|
||||
_scene.nodes[node].morphWeights[target] = weight;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2293,13 +2492,15 @@ bool sceneInit(SDL_GPUDevice *device, SDL_Renderer *renderer) {
|
|||
_scene.antialias = true;
|
||||
_scene.sampleCount = SDL_GPU_SAMPLECOUNT_1;
|
||||
_scene.shadowSize = SHADOW_SIZE;
|
||||
// The node tree is plain data and exists on every machine (physics bodies live on nodes);
|
||||
// everything from here on needs the GPU, and without one the layer cannot be enabled.
|
||||
_allocNode();
|
||||
nodeSetName(SCENE_ROOT_NODE, "root");
|
||||
if (device == NULL) {
|
||||
return false;
|
||||
}
|
||||
_scene.depthFormat = _depthFormat();
|
||||
_scene.shadowFormat = _shadowFormat();
|
||||
_allocNode();
|
||||
nodeSetName(SCENE_ROOT_NODE, "root");
|
||||
if (!_createShaders()) {
|
||||
sceneQuit();
|
||||
return false;
|
||||
|
|
@ -2326,8 +2527,13 @@ bool sceneInit(SDL_GPUDevice *device, SDL_Renderer *renderer) {
|
|||
_scene.white = _uploadTexture(pixel);
|
||||
SDL_DestroySurface(pixel);
|
||||
}
|
||||
{
|
||||
float zero[MORPH_FLOATS] = { 0.0f };
|
||||
|
||||
_scene.noMorphs = _uploadBuffer(SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ, zero, sizeof(zero));
|
||||
}
|
||||
_scene.shadowMapsNone = _createShadowArray(SDL_GPU_TEXTURETYPE_2D_ARRAY, 1, 1);
|
||||
if ((_scene.sampler == NULL) || (_scene.shadowSampler == NULL) || (_scene.white == NULL) || (_scene.shadowMapsNone == NULL)) {
|
||||
if ((_scene.sampler == NULL) || (_scene.shadowSampler == NULL) || (_scene.white == NULL) || (_scene.shadowMapsNone == NULL) || (_scene.noMorphs == NULL)) {
|
||||
utilTrace("Scene: %s", SDL_GetError());
|
||||
sceneQuit();
|
||||
return false;
|
||||
|
|
@ -2398,11 +2604,15 @@ void sceneQuit(void) {
|
|||
if (_scene.white != NULL) {
|
||||
SDL_ReleaseGPUTexture(_scene.device, _scene.white);
|
||||
}
|
||||
if (_scene.noMorphs != NULL) {
|
||||
SDL_ReleaseGPUBuffer(_scene.device, _scene.noMorphs);
|
||||
}
|
||||
_destroyTargets();
|
||||
}
|
||||
for (x = 0; x < _scene.nodeCount; x++) {
|
||||
SDL_free(_scene.nodes[x].name);
|
||||
_freeSkin(&_scene.nodes[x]);
|
||||
_freeMorphWeights(&_scene.nodes[x]);
|
||||
}
|
||||
SDL_free(_scene.nodes);
|
||||
SDL_free(_scene.meshes);
|
||||
|
|
@ -2728,7 +2938,7 @@ Vec3T sceneUnproject(float x, float y, float distance) {
|
|||
void sceneUpdateTransforms(void) {
|
||||
Mat4T identity = mat4Identity();
|
||||
|
||||
if (_scene.device != NULL) {
|
||||
if (_scene.nodeCount > 0) {
|
||||
_updateWorld(SCENE_ROOT_NODE, &identity, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,11 +98,15 @@ int32_t meshCone(float radius, float height, int32_t segments);
|
|||
int32_t meshCylinder(float radius, float height, int32_t segments);
|
||||
bool meshDelete(int32_t mesh);
|
||||
bool meshGetGeometry(int32_t mesh, const float **positions, int32_t *vertexCount, const uint32_t **indices, int32_t *indexCount);
|
||||
int32_t meshFindMorph(int32_t mesh, const char *name);
|
||||
int32_t meshGetMorphCount(int32_t mesh);
|
||||
const char *meshGetMorphName(int32_t mesh, int32_t target);
|
||||
int32_t meshNew(const float *positions, const float *normals, const float *uvs, int32_t vertexCount, const uint32_t *indices, int32_t indexCount);
|
||||
int32_t meshNewVertices(const SceneVertexT *vertices, int32_t vertexCount, const uint32_t *indices, int32_t indexCount, bool skinned);
|
||||
int32_t meshPlane(float width, float depth);
|
||||
int32_t meshSphere(float radius, int32_t segments);
|
||||
int32_t meshTorus(float radius, float tubeRadius, int32_t segments);
|
||||
bool meshSetMorphTargets(int32_t mesh, const float *deltas, int32_t targetCount, const char **names);
|
||||
bool meshValid(int32_t mesh);
|
||||
|
||||
bool nodeDelete(int32_t node);
|
||||
|
|
@ -111,6 +115,8 @@ int32_t nodeGetChild(int32_t node, int32_t index);
|
|||
int32_t nodeGetChildCount(int32_t node);
|
||||
uint32_t nodeGetGeneration(int32_t node);
|
||||
int32_t nodeGetMesh(int32_t node);
|
||||
int32_t nodeGetMorphCount(int32_t node);
|
||||
float nodeGetMorphWeight(int32_t node, int32_t target);
|
||||
const char *nodeGetName(int32_t node);
|
||||
int32_t nodeGetParent(int32_t node);
|
||||
Vec3T nodeGetPosition(int32_t node);
|
||||
|
|
@ -123,6 +129,7 @@ bool nodeMove(int32_t node, Vec3T delta);
|
|||
int32_t nodeNew(int32_t parent);
|
||||
bool nodeRotate(int32_t node, QuatT delta);
|
||||
bool nodeSetMesh(int32_t node, int32_t mesh, int32_t material);
|
||||
bool nodeSetMorphWeight(int32_t node, int32_t target, float weight);
|
||||
bool nodeSetName(int32_t node, const char *name);
|
||||
bool nodeSetParent(int32_t node, int32_t parent);
|
||||
bool nodeSetPosition(int32_t node, Vec3T position);
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Compiles scene.hlsl into sceneShaders.h: SPIR-V (Vulkan), DXIL (Direct3D 12) and MSL (Metal)
|
||||
# for each entry point, as C arrays. Needs SDL_shadercross's command line tool (built from
|
||||
# https://github.com/libsdl-org/SDL_shadercross with SDLSHADERCROSS_DXC=ON); pass its path as the
|
||||
# first argument or put it on PATH. The engine build never runs this: the output is checked in.
|
||||
#
|
||||
# Usage: src/shaders/build.sh [path/to/shadercross]
|
||||
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
SHADERCROSS=${1:-shadercross}
|
||||
OUT=sceneShaders.h
|
||||
TMP=$(mktemp -d)
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
ENTRIES="vertexStatic:vertex vertexSkinned:vertex fragmentMain:fragment depthMain:fragment"
|
||||
|
||||
emit() {
|
||||
# emit NAME FILE: a C array from a binary file
|
||||
local name=$1
|
||||
local file=$2
|
||||
echo "static const unsigned char ${name}[] = {"
|
||||
od -An -v -tx1 "$file" | sed 's/ \([0-9a-f][0-9a-f]\)/0x\1,/g; s/^/\t/'
|
||||
echo "};"
|
||||
}
|
||||
|
||||
{
|
||||
echo "// Generated by build.sh from scene.hlsl with SDL_shadercross; do not edit."
|
||||
echo "// SPIR-V for Vulkan, DXIL for Direct3D 12, MSL for Metal, one set per entry point."
|
||||
echo
|
||||
echo "#ifndef SCENE_SHADERS_H"
|
||||
echo "#define SCENE_SHADERS_H"
|
||||
echo
|
||||
echo "#include <stddef.h>"
|
||||
echo
|
||||
echo "typedef struct SceneShaderS {"
|
||||
echo " const char *entryPoint;"
|
||||
echo " const unsigned char *spirv;"
|
||||
echo " size_t spirvSize;"
|
||||
echo " const unsigned char *dxil;"
|
||||
echo " size_t dxilSize;"
|
||||
echo " const unsigned char *msl;"
|
||||
echo " size_t mslSize;"
|
||||
echo "} SceneShaderT;"
|
||||
echo
|
||||
for entry in $ENTRIES; do
|
||||
name=${entry%%:*}
|
||||
stage=${entry##*:}
|
||||
for format in SPIRV DXIL MSL; do
|
||||
ext=$(echo "$format" | tr '[:upper:]' '[:lower:]')
|
||||
"$SHADERCROSS" scene.hlsl -s HLSL -d "$format" -t "$stage" -e "$name" -o "$TMP/$name.$ext" >&2
|
||||
emit "_${name}${format}" "$TMP/$name.$ext"
|
||||
echo
|
||||
done
|
||||
echo "static const SceneShaderT sceneShader$(echo "${name:0:1}" | tr '[:lower:]' '[:upper:]')${name:1} = { \"$name\", _${name}SPIRV, sizeof(_${name}SPIRV), _${name}DXIL, sizeof(_${name}DXIL), _${name}MSL, sizeof(_${name}MSL) };"
|
||||
echo
|
||||
done
|
||||
echo "#endif"
|
||||
} > "$OUT"
|
||||
echo "Wrote $OUT"
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
#define MAX_LIGHTS 8
|
||||
#define MAX_JOINTS 128
|
||||
#define MAX_SHADOWS 8
|
||||
#define MAX_MORPHS 8 // Active morph targets per draw
|
||||
|
||||
#define SHADOW_NONE 0
|
||||
#define SHADOW_MAP 1
|
||||
|
|
@ -25,8 +26,14 @@ cbuffer DrawUniforms : register(b0, space1) {
|
|||
float4x4 modelViewProjection;
|
||||
float4x4 model;
|
||||
float4x4 normalMatrix; // Inverse transpose of model, for normals under non-uniform scale
|
||||
float4 morphWeights[2]; // Up to MAX_MORPHS active targets ...
|
||||
int4 morphTargets[2]; // ... and which targets they are
|
||||
int4 morphInfo; // x = active count, y = vertices per target
|
||||
};
|
||||
|
||||
// Morph target deltas: per target, per vertex, a position delta then a normal delta.
|
||||
StructuredBuffer<float4> morphDeltas : register(t0, space0);
|
||||
|
||||
cbuffer SkinUniforms : register(b1, space1) {
|
||||
float4x4 joints[MAX_JOINTS];
|
||||
};
|
||||
|
|
@ -47,32 +54,59 @@ struct VertexOutput {
|
|||
};
|
||||
|
||||
|
||||
VertexOutput vertexStatic(VertexInput input) {
|
||||
VertexOutput output;
|
||||
// Adds the active morph targets' deltas to a vertex.
|
||||
void morph(uint vertex, inout float3 position, inout float3 normal) {
|
||||
int x;
|
||||
|
||||
output.position = mul(modelViewProjection, float4(input.position, 1.0));
|
||||
output.worldPosition = mul(model, float4(input.position, 1.0)).xyz;
|
||||
output.worldNormal = normalize(mul((float3x3)normalMatrix, input.normal));
|
||||
for (x = 0; x < MAX_MORPHS; x++) {
|
||||
float weight;
|
||||
uint base;
|
||||
|
||||
if (x >= morphInfo.x) {
|
||||
continue;
|
||||
}
|
||||
weight = morphWeights[x / 4][x % 4];
|
||||
base = ((uint)morphTargets[x / 4][x % 4] * (uint)morphInfo.y + vertex) * 2;
|
||||
position += morphDeltas[base].xyz * weight;
|
||||
normal += morphDeltas[base + 1].xyz * weight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VertexOutput vertexStatic(VertexInput input, uint vertex : SV_VertexID) {
|
||||
VertexOutput output;
|
||||
float3 position = input.position;
|
||||
float3 normal = input.normal;
|
||||
|
||||
morph(vertex, position, normal);
|
||||
output.position = mul(modelViewProjection, float4(position, 1.0));
|
||||
output.worldPosition = mul(model, float4(position, 1.0)).xyz;
|
||||
output.worldNormal = normalize(mul((float3x3)normalMatrix, normal));
|
||||
output.uv = input.uv;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
VertexOutput vertexSkinned(VertexInput input) {
|
||||
VertexOutput vertexSkinned(VertexInput input, uint vertex : SV_VertexID) {
|
||||
VertexOutput output;
|
||||
float4 position = float4(input.position, 1.0);
|
||||
float3 morphed = input.position;
|
||||
float3 normal = input.normal;
|
||||
float4 position;
|
||||
float4 skinned;
|
||||
float3 skinnedNormal;
|
||||
|
||||
morph(vertex, morphed, normal);
|
||||
position = float4(morphed, 1.0);
|
||||
|
||||
// The weighted sum of the joint transforms, applied to the position and the normal.
|
||||
skinned = mul(joints[input.joints.x], position) * input.weights.x
|
||||
+ mul(joints[input.joints.y], position) * input.weights.y
|
||||
+ mul(joints[input.joints.z], position) * input.weights.z
|
||||
+ mul(joints[input.joints.w], position) * input.weights.w;
|
||||
skinnedNormal = mul((float3x3)joints[input.joints.x], input.normal) * input.weights.x
|
||||
+ mul((float3x3)joints[input.joints.y], input.normal) * input.weights.y
|
||||
+ mul((float3x3)joints[input.joints.z], input.normal) * input.weights.z
|
||||
+ mul((float3x3)joints[input.joints.w], input.normal) * input.weights.w;
|
||||
skinnedNormal = mul((float3x3)joints[input.joints.x], normal) * input.weights.x
|
||||
+ mul((float3x3)joints[input.joints.y], normal) * input.weights.y
|
||||
+ mul((float3x3)joints[input.joints.z], normal) * input.weights.z
|
||||
+ mul((float3x3)joints[input.joints.w], normal) * input.weights.w;
|
||||
output.position = mul(modelViewProjection, skinned);
|
||||
output.worldPosition = mul(model, skinned).xyz;
|
||||
output.worldNormal = normalize(mul((float3x3)normalMatrix, skinnedNormal));
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
84
src/singe.c
84
src/singe.c
|
|
@ -440,6 +440,7 @@ static FontT *_argFont(lua_State *L, const char *method, int32_t index);
|
|||
static int32_t _argInteger(lua_State *L, const char *method, int32_t index);
|
||||
static int32_t _argBody(lua_State *L, const char *method, int32_t index);
|
||||
static int32_t _argMaterial(lua_State *L, const char *method, int32_t index);
|
||||
static int32_t _argMorph(lua_State *L, const char *method, int32_t node, int32_t index);
|
||||
static int32_t _argMesh(lua_State *L, const char *method, int32_t index);
|
||||
static int32_t _argNode(lua_State *L, const char *method, int32_t index);
|
||||
static int64_t _argInteger64(lua_State *L, const char *method, int32_t index);
|
||||
|
|
@ -627,6 +628,8 @@ static int32_t apiMouseSetMode(lua_State *L);
|
|||
static int32_t apiNodeDelete(lua_State *L);
|
||||
static int32_t apiNodeFind(lua_State *L);
|
||||
static int32_t apiNodeGetChildren(lua_State *L);
|
||||
static int32_t apiNodeGetMorph(lua_State *L);
|
||||
static int32_t apiNodeGetMorphs(lua_State *L);
|
||||
static int32_t apiNodeGetName(lua_State *L);
|
||||
static int32_t apiNodeGetParent(lua_State *L);
|
||||
static int32_t apiNodeGetPosition(lua_State *L);
|
||||
|
|
@ -639,6 +642,7 @@ static int32_t apiNodeMove(lua_State *L);
|
|||
static int32_t apiNodeNew(lua_State *L);
|
||||
static int32_t apiNodeRotate(lua_State *L);
|
||||
static int32_t apiNodeSetMesh(lua_State *L);
|
||||
static int32_t apiNodeSetMorph(lua_State *L);
|
||||
static int32_t apiNodeSetName(lua_State *L);
|
||||
static int32_t apiNodeSetParent(lua_State *L);
|
||||
static int32_t apiNodeSetPosition(lua_State *L);
|
||||
|
|
@ -658,6 +662,7 @@ static int32_t apiOverlayPlot(lua_State *L);
|
|||
static int32_t apiOverlayPrint(lua_State *L);
|
||||
static int32_t apiOverlaySetResolution(lua_State *L);
|
||||
static int32_t apiPhysicsRaycast(lua_State *L);
|
||||
static int32_t apiPhysicsSet2D(lua_State *L);
|
||||
static int32_t apiPhysicsSetEnabled(lua_State *L);
|
||||
static int32_t apiPhysicsSetGravity(lua_State *L);
|
||||
static int32_t apiSceneEnable(lua_State *L);
|
||||
|
|
@ -826,6 +831,25 @@ static int32_t _argInteger(lua_State *L, const char *method, int32_t index) {
|
|||
}
|
||||
|
||||
|
||||
// A morph target of a node's mesh, by name or by number from 1, checked.
|
||||
static int32_t _argMorph(lua_State *L, const char *method, int32_t node, int32_t index) {
|
||||
int32_t target;
|
||||
|
||||
if (lua_type(L, index) == LUA_TSTRING) {
|
||||
target = meshFindMorph(nodeGetMesh(node), lua_tostring(L, index));
|
||||
if (target < 0) {
|
||||
_luaDie(L, method, "Node %d has no morph target named %s.", node, lua_tostring(L, index));
|
||||
}
|
||||
return target;
|
||||
}
|
||||
target = _argInteger(L, method, index) - 1;
|
||||
if ((target < 0) || (target >= nodeGetMorphCount(node))) {
|
||||
_luaDie(L, method, "Node %d has no morph target %d.", node, target + 1);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
// A node that carries a physics body, checked.
|
||||
static int32_t _argBody(lua_State *L, const char *method, int32_t index) {
|
||||
int32_t node = _argNode(L, method, index);
|
||||
|
|
@ -3679,7 +3703,7 @@ static int32_t apiLightNew(lua_State *L) {
|
|||
}
|
||||
node = lightNew((LightTypeE)type, parent);
|
||||
if (node < 0) {
|
||||
_luaDie(L, "lightNew", "3D is not available on this machine.");
|
||||
_luaDie(L, "lightNew", "Unable to create the node.");
|
||||
}
|
||||
_luaTrace(L, "lightNew", "%d type %d under %d", node, type, parent);
|
||||
lua_pushinteger(L, node);
|
||||
|
|
@ -4242,6 +4266,37 @@ static int32_t apiNodeGetChildren(lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
// weight = nodeGetMorph(node, nameOrIndex)
|
||||
static int32_t apiNodeGetMorph(lua_State *L) {
|
||||
int32_t node;
|
||||
int32_t target;
|
||||
|
||||
_argCheck(L, "nodeGetMorph", 2, 2);
|
||||
node = _argNode(L, "nodeGetMorph", 1);
|
||||
target = _argMorph(L, "nodeGetMorph", node, 2);
|
||||
lua_pushnumber(L, nodeGetMorphWeight(node, target));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// names = nodeGetMorphs(node): the mesh's morph target names, in order (empty strings when unnamed)
|
||||
static int32_t apiNodeGetMorphs(lua_State *L) {
|
||||
int32_t node;
|
||||
int32_t count;
|
||||
int32_t x;
|
||||
|
||||
_argCheck(L, "nodeGetMorphs", 1, 1);
|
||||
node = _argNode(L, "nodeGetMorphs", 1);
|
||||
count = nodeGetMorphCount(node);
|
||||
lua_createtable(L, count, 0);
|
||||
for (x = 0; x < count; x++) {
|
||||
lua_pushstring(L, meshGetMorphName(nodeGetMesh(node), x));
|
||||
lua_rawseti(L, -2, x + 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// name = nodeGetName(node)
|
||||
static int32_t apiNodeGetName(lua_State *L) {
|
||||
_argCheck(L, "nodeGetName", 1, 1);
|
||||
|
|
@ -4342,7 +4397,7 @@ static int32_t apiNodeNew(lua_State *L) {
|
|||
}
|
||||
node = nodeNew(parent);
|
||||
if (node < 0) {
|
||||
_luaDie(L, "nodeNew", "3D is not available on this machine.");
|
||||
_luaDie(L, "nodeNew", "Unable to create the node.");
|
||||
}
|
||||
_luaTrace(L, "nodeNew", "%d under %d", node, parent);
|
||||
lua_pushinteger(L, node);
|
||||
|
|
@ -4375,6 +4430,19 @@ static int32_t apiNodeSetMesh(lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
// nodeSetMorph(node, nameOrIndex, weight): how much of a morph target shows, usually 0 to 1
|
||||
static int32_t apiNodeSetMorph(lua_State *L) {
|
||||
int32_t node;
|
||||
int32_t target;
|
||||
|
||||
_argCheck(L, "nodeSetMorph", 3, 3);
|
||||
node = _argNode(L, "nodeSetMorph", 1);
|
||||
target = _argMorph(L, "nodeSetMorph", node, 2);
|
||||
nodeSetMorphWeight(node, target, (float)_argNumber(L, "nodeSetMorph", 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// nodeSetName(node, name)
|
||||
static int32_t apiNodeSetName(lua_State *L) {
|
||||
_argCheck(L, "nodeSetName", 2, 2);
|
||||
|
|
@ -4788,6 +4856,14 @@ static int32_t apiPhysicsRaycast(lua_State *L) {
|
|||
}
|
||||
|
||||
|
||||
// physicsSet2D(bool): bodies made from now on stay in the XY plane (2D games)
|
||||
static int32_t apiPhysicsSet2D(lua_State *L) {
|
||||
_argCheck(L, "physicsSet2D", 1, 1);
|
||||
physicsSet2D(_argBoolean(L, "physicsSet2D", 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// physicsSetEnabled(bool): pauses the simulation without losing it
|
||||
static int32_t apiPhysicsSetEnabled(lua_State *L) {
|
||||
_argCheck(L, "physicsSetEnabled", 1, 1);
|
||||
|
|
@ -6427,6 +6503,8 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, SDL_GPUDevice *device, Co
|
|||
lua_register(_global.luaContext, "nodeDelete", apiNodeDelete); // 3.00
|
||||
lua_register(_global.luaContext, "nodeFind", apiNodeFind); // 3.00
|
||||
lua_register(_global.luaContext, "nodeGetChildren", apiNodeGetChildren); // 3.00
|
||||
lua_register(_global.luaContext, "nodeGetMorph", apiNodeGetMorph); // 3.00
|
||||
lua_register(_global.luaContext, "nodeGetMorphs", apiNodeGetMorphs); // 3.00
|
||||
lua_register(_global.luaContext, "nodeGetName", apiNodeGetName); // 3.00
|
||||
lua_register(_global.luaContext, "nodeGetParent", apiNodeGetParent); // 3.00
|
||||
lua_register(_global.luaContext, "nodeGetPosition", apiNodeGetPosition); // 3.00
|
||||
|
|
@ -6439,6 +6517,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, SDL_GPUDevice *device, Co
|
|||
lua_register(_global.luaContext, "nodeNew", apiNodeNew); // 3.00
|
||||
lua_register(_global.luaContext, "nodeRotate", apiNodeRotate); // 3.00
|
||||
lua_register(_global.luaContext, "nodeSetMesh", apiNodeSetMesh); // 3.00
|
||||
lua_register(_global.luaContext, "nodeSetMorph", apiNodeSetMorph); // 3.00
|
||||
lua_register(_global.luaContext, "nodeSetName", apiNodeSetName); // 3.00
|
||||
lua_register(_global.luaContext, "nodeSetParent", apiNodeSetParent); // 3.00
|
||||
lua_register(_global.luaContext, "nodeSetPosition", apiNodeSetPosition); // 3.00
|
||||
|
|
@ -6458,6 +6537,7 @@ void singe(SDL_Window *window, SDL_Renderer *renderer, SDL_GPUDevice *device, Co
|
|||
lua_register(_global.luaContext, "overlaySetResolution", apiOverlaySetResolution); // 2.00
|
||||
|
||||
lua_register(_global.luaContext, "physicsRaycast", apiPhysicsRaycast); // 3.00
|
||||
lua_register(_global.luaContext, "physicsSet2D", apiPhysicsSet2D); // 3.00
|
||||
lua_register(_global.luaContext, "physicsSetEnabled", apiPhysicsSetEnabled); // 3.00
|
||||
lua_register(_global.luaContext, "physicsSetGravity", apiPhysicsSetGravity); // 3.00
|
||||
lua_register(_global.luaContext, "sceneEnable", apiSceneEnable); // 3.00
|
||||
|
|
|
|||
BIN
testScripts/Models/AnimatedMorphCube.glb
(Stored with Git LFS)
Normal file
BIN
testScripts/Models/AnimatedMorphCube.glb
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
testScripts/Models/DragonModel.glb
(Stored with Git LFS)
Normal file
BIN
testScripts/Models/DragonModel.glb
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
testScripts/Models/SingeText.glb
(Stored with Git LFS)
Normal file
BIN
testScripts/Models/SingeText.glb
(Stored with Git LFS)
Normal file
Binary file not shown.
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
The Lua scripts used to verify the 3D scene and physics work, one per stage
|
||||
of PLAN.md sections 18 and 19, with everything they load: the Khronos
|
||||
Duck, Fox and BoxAnimated sample models under Models/, and Box.png. The
|
||||
Duck, Fox, BoxAnimated and AnimatedMorphCube sample models under Models/, Box.png and crate.png. The
|
||||
disc and the font are the engine's own, addressed as
|
||||
Singe/menuBackground.mkv and Singe/FreeSansBold.ttf like any engine
|
||||
asset. This directory is a complete Singe game directory. Run one from the singe directory with
|
||||
|
||||
.builddir/Singe-v3.00-Linux-x86_64 -w -d data -v Singe/menuBackground.mkv testScripts/scene6.singe
|
||||
|
||||
(scene12 has no disc: give it -C 720x480 instead of -v)
|
||||
|
||||
or pack it (singe --pack testScripts testScripts.game) and run an entry
|
||||
with --entry N (the numbers follow games.dat). Every script takes a
|
||||
screenshot or two and quits by itself; the results are in screenshots/.
|
||||
|
|
@ -26,3 +28,8 @@ screenshot or two and quits by itself; the results are in screenshots/.
|
|||
| scene9.singe | 9 | 19.2 | Physics: a crate stack, a ball, a kinematic paddle |
|
||||
| scene10.singe | 10 | 19.3 | Physics: a trigger volume, collision callbacks, a raycast pick |
|
||||
| scene11.singe | 11 | 19.4 | Physics: a hull down a ramp, a mesh torus, hinge, ball and slider joints |
|
||||
| scene12.singe | 12 | 19.6 | 2D physics drawn with sprites; runs with no GPU (SDL_GPU_DRIVER=nothing) |
|
||||
| scene13.singe | 13 | 18.8 | Morph targets: the AnimatedMorphCube, animated and driven from script |
|
||||
| scene14.singe | 14 | - | The solid tangram dragon (Models/DragonModel.glb, a copy of assets/DragonModel.glb) turning under a sun with shadows |
|
||||
| scene15.singe | 15 | - | The Singe logotype as solid letters (Models/SingeText.glb, a copy of assets/SingeText.glb) turning under a sun with shadows |
|
||||
| scene16.singe | 16 | - | The dragon perched on the logotype, both models under one parent node, turning together |
|
||||
|
|
|
|||
BIN
testScripts/crate.png
(Stored with Git LFS)
Normal file
BIN
testScripts/crate.png
(Stored with Git LFS)
Normal file
Binary file not shown.
|
|
@ -120,4 +120,58 @@ GAMES = {
|
|||
DEVELOPER = "Test",
|
||||
PUBLISHER = "Test",
|
||||
},
|
||||
{
|
||||
TITLE = "Physics2D",
|
||||
SCRIPT = "testScripts/scene12.singe",
|
||||
DESCRIPTION = "2D physics drawn with sprites, no 3D or GPU needed.",
|
||||
YEAR = 2026,
|
||||
GENRE = "Test",
|
||||
PLATFORM = "Singe",
|
||||
DEVELOPER = "Test",
|
||||
PUBLISHER = "Test",
|
||||
},
|
||||
{
|
||||
TITLE = "Morphs",
|
||||
SCRIPT = "testScripts/scene13.singe",
|
||||
VIDEO = "Singe/menuBackground.mkv",
|
||||
DESCRIPTION = "Morph targets: the AnimatedMorphCube, animated and scripted.",
|
||||
YEAR = 2026,
|
||||
GENRE = "Test",
|
||||
PLATFORM = "Singe",
|
||||
DEVELOPER = "Test",
|
||||
PUBLISHER = "Test",
|
||||
},
|
||||
{
|
||||
TITLE = "Dragon",
|
||||
SCRIPT = "testScripts/scene14.singe",
|
||||
VIDEO = "Singe/menuBackground.mkv",
|
||||
DESCRIPTION = "The solid tangram dragon model (assets/DragonModel.glb) turning under a sun with shadows.",
|
||||
YEAR = 2026,
|
||||
GENRE = "Test",
|
||||
PLATFORM = "Singe",
|
||||
DEVELOPER = "Test",
|
||||
PUBLISHER = "Test",
|
||||
},
|
||||
{
|
||||
TITLE = "Logo",
|
||||
SCRIPT = "testScripts/scene15.singe",
|
||||
VIDEO = "Singe/menuBackground.mkv",
|
||||
DESCRIPTION = "The Singe logotype as solid letters (assets/SingeText.glb) turning under a sun with shadows.",
|
||||
YEAR = 2026,
|
||||
GENRE = "Test",
|
||||
PLATFORM = "Singe",
|
||||
DEVELOPER = "Test",
|
||||
PUBLISHER = "Test",
|
||||
},
|
||||
{
|
||||
TITLE = "DragonOnLogo",
|
||||
SCRIPT = "testScripts/scene16.singe",
|
||||
VIDEO = "Singe/menuBackground.mkv",
|
||||
DESCRIPTION = "The dragon perched on the Singe logotype, turning together under a sun with shadows.",
|
||||
YEAR = 2026,
|
||||
GENRE = "Test",
|
||||
PLATFORM = "Singe",
|
||||
DEVELOPER = "Test",
|
||||
PUBLISHER = "Test",
|
||||
},
|
||||
}
|
||||
|
|
|
|||
70
testScripts/scene12.singe
Normal file
70
testScripts/scene12.singe
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
-- 2D physics with no 3D at all: crates drawn as sprites fall and pile up in overlay coordinates.
|
||||
-- Runs on any machine, GPU or not (try it with SDL_GPU_DRIVER=nothing).
|
||||
local font = fontLoad("Singe/FreeSansBold.ttf", 24)
|
||||
local box = spriteLoad("testScripts/crate.png")
|
||||
local frames = 0
|
||||
local width, height = overlayGetWidth(), overlayGetHeight()
|
||||
|
||||
fontSelect(font)
|
||||
physicsSet2D(true)
|
||||
physicsSetGravity(0, 900, 0) -- Pixels per second squared; overlay Y runs down.
|
||||
|
||||
-- The floor and walls, static, sized in pixels.
|
||||
local floor = nodeNew()
|
||||
nodeSetPosition(floor, width / 2, height - 10, 0)
|
||||
bodyNew(floor, BODY_STATIC, SHAPE_BOX, width, 20, 50)
|
||||
local leftWall = nodeNew()
|
||||
nodeSetPosition(leftWall, -10, height / 2, 0)
|
||||
bodyNew(leftWall, BODY_STATIC, SHAPE_BOX, 20, height, 50)
|
||||
local rightWall = nodeNew()
|
||||
nodeSetPosition(rightWall, width + 10, height / 2, 0)
|
||||
bodyNew(rightWall, BODY_STATIC, SHAPE_BOX, 20, height, 50)
|
||||
|
||||
-- A slope the crates tumble off.
|
||||
local slope = nodeNew()
|
||||
nodeSetPosition(slope, width * 0.3, height * 0.55, 0)
|
||||
nodeSetRotation(slope, 0, 0, 20)
|
||||
bodyNew(slope, BODY_STATIC, SHAPE_BOX, width * 0.45, 12, 50)
|
||||
|
||||
local size = spriteGetWidth(box)
|
||||
local crates = {}
|
||||
local function drop(i)
|
||||
local crate = nodeNew()
|
||||
nodeSetPosition(crate, width * 0.15 + (i % 5) * size * 0.6, -size * (1 + i * 0.5), 0)
|
||||
nodeSetRotation(crate, 0, 0, i * 13)
|
||||
bodyNew(crate, BODY_DYNAMIC, SHAPE_BOX, size, size, 50)
|
||||
bodySetMass(crate, 1)
|
||||
bodySetFriction(crate, 0.6)
|
||||
bodySetBounce(crate, 0.2)
|
||||
crates[#crates + 1] = crate
|
||||
end
|
||||
for i = 1, 14 do
|
||||
drop(i)
|
||||
end
|
||||
|
||||
local resting = 0
|
||||
function onCollision(a, b, x, y, z, speed)
|
||||
end
|
||||
|
||||
function onOverlayUpdate()
|
||||
frames = frames + 1
|
||||
overlayClear()
|
||||
resting = 0
|
||||
for _, crate in ipairs(crates) do
|
||||
local x, y = nodeGetPosition(crate)
|
||||
local _, _, angle = nodeGetRotation(crate)
|
||||
spriteRotate(box, angle)
|
||||
spriteDraw(box, x, y, true)
|
||||
if bodyIsResting(crate) then
|
||||
resting = resting + 1
|
||||
end
|
||||
end
|
||||
fontPrint(10, 8, string.format("2D physics, frame %d, %d of %d resting", frames, resting, #crates))
|
||||
if frames == 40 or frames == 100 or frames == 220 then
|
||||
singeScreenshot()
|
||||
end
|
||||
if frames == 240 then
|
||||
singeQuit()
|
||||
end
|
||||
return OVERLAY_UPDATED
|
||||
end
|
||||
52
testScripts/scene13.singe
Normal file
52
testScripts/scene13.singe
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
-- Morph targets: the Khronos AnimatedMorphCube. Left, its own animation blending the two
|
||||
-- targets; right, the same model with weights set from the script.
|
||||
local font = fontLoad("Singe/FreeSansBold.ttf", 28)
|
||||
local frames = 0
|
||||
|
||||
fontSelect(font)
|
||||
discPlay()
|
||||
sceneEnable(true)
|
||||
sceneSetBackground(18, 18, 30, 255)
|
||||
sceneSetAmbient(70, 70, 85)
|
||||
|
||||
local cubeModel = modelLoad("testScripts/Models/AnimatedMorphCube.glb")
|
||||
|
||||
local animated = modelInstance(cubeModel)
|
||||
nodeSetPosition(animated, -1.6, 0, 0)
|
||||
nodeSetScale(animated, 0.9)
|
||||
animationPlay(animated, 1, true)
|
||||
|
||||
local scripted = modelInstance(cubeModel)
|
||||
nodeSetPosition(scripted, 1.6, 0, 0)
|
||||
nodeSetScale(scripted, 0.9)
|
||||
local meshNode = nodeGetChildren(scripted)[1]
|
||||
local names = nodeGetMorphs(meshNode)
|
||||
debugPrint("morph targets: " .. #names)
|
||||
|
||||
local sun = lightNew(LIGHT_DIRECTIONAL)
|
||||
nodeSetPosition(sun, -3, 5, 4)
|
||||
nodeLookAt(sun, 0, 0, 0)
|
||||
lightSetIntensity(sun, 1.3)
|
||||
|
||||
local camera = nodeNew()
|
||||
nodeSetPosition(camera, 0, 2.2, 6)
|
||||
nodeLookAt(camera, 0, 0, 0)
|
||||
cameraSet(camera)
|
||||
|
||||
function onOverlayUpdate()
|
||||
frames = frames + 1
|
||||
-- The scripted cube sweeps target 1 up while target 2 comes down.
|
||||
local t = (frames % 120) / 120
|
||||
nodeSetMorph(meshNode, 1, t)
|
||||
nodeSetMorph(meshNode, 2, 1 - t)
|
||||
nodeRotate(animated, 0, 0.8, 0)
|
||||
nodeRotate(scripted, 0, -0.8, 0)
|
||||
overlayClear()
|
||||
fontPrint(20, 20, string.format("Morph targets, frame %d scripted: %.2f / %.2f", frames, nodeGetMorph(meshNode, 1), nodeGetMorph(meshNode, 2)))
|
||||
if frames == 20 or frames == 80 or frames == 140 then
|
||||
singeScreenshot()
|
||||
end
|
||||
if frames == 150 then
|
||||
singeQuit()
|
||||
end
|
||||
end
|
||||
48
testScripts/scene14.singe
Normal file
48
testScripts/scene14.singe
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
-- Dragon model test: the solid tangram dragon built by util/dragonModel.py and converted to glTF
|
||||
-- by util/objToGlb.py, turning slowly under a sun with shadows, over the disc.
|
||||
local font = fontLoad("Singe/FreeSansBold.ttf", 28)
|
||||
local frames = 0
|
||||
|
||||
fontSelect(font)
|
||||
discPlay()
|
||||
sceneEnable(true)
|
||||
sceneSetBackground(0, 0, 0, 0)
|
||||
sceneSetAmbient(70, 70, 80)
|
||||
|
||||
local dragonModel = modelLoad("testScripts/Models/DragonModel.glb")
|
||||
local dragon = modelInstance(dragonModel)
|
||||
nodeSetPosition(dragon, 0, -3.5, 0)
|
||||
nodeSetRotation(dragon, 0, 35, 0)
|
||||
|
||||
local stone = materialNew()
|
||||
materialSetColor(stone, 120, 120, 130)
|
||||
materialSetRoughness(stone, 0.9)
|
||||
local floor = nodeNew()
|
||||
nodeSetMesh(floor, meshBox(14, 0.2, 10), stone)
|
||||
nodeSetPosition(floor, 0, -3.6, 0)
|
||||
|
||||
local sun = lightNew(LIGHT_DIRECTIONAL)
|
||||
nodeSetPosition(sun, -4, 8, 6)
|
||||
nodeLookAt(sun, 0, 0, 0)
|
||||
lightSetIntensity(sun, 1.6)
|
||||
lightSetShadow(sun, true)
|
||||
|
||||
local camera = nodeNew()
|
||||
nodeSetPosition(camera, 0, 1.5, 12)
|
||||
nodeLookAt(camera, 0, 0, 0)
|
||||
cameraSet(camera)
|
||||
|
||||
debugPrint("dragon parts " .. #nodeGetChildren(dragon))
|
||||
|
||||
function onOverlayUpdate()
|
||||
frames = frames + 1
|
||||
nodeRotate(dragon, 0, 0.75, 0)
|
||||
overlayClear()
|
||||
fontPrint(20, 20, "Dragon model, frame " .. frames)
|
||||
if frames == 30 or frames == 100 or frames == 170 then
|
||||
singeScreenshot()
|
||||
end
|
||||
if frames == 180 then
|
||||
singeQuit()
|
||||
end
|
||||
end
|
||||
48
testScripts/scene15.singe
Normal file
48
testScripts/scene15.singe
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
-- Logo model test: the Singe logotype built by util/textModel.py and converted to glTF by
|
||||
-- util/objToGlb.py, turning under a sun with shadows, over the disc.
|
||||
local font = fontLoad("Singe/FreeSansBold.ttf", 28)
|
||||
local frames = 0
|
||||
|
||||
fontSelect(font)
|
||||
discPlay()
|
||||
sceneEnable(true)
|
||||
sceneSetBackground(0, 0, 0, 0)
|
||||
sceneSetAmbient(70, 70, 80)
|
||||
|
||||
local logoModel = modelLoad("testScripts/Models/SingeText.glb")
|
||||
local logo = modelInstance(logoModel)
|
||||
nodeSetPosition(logo, 0, -2.5, 0)
|
||||
nodeSetRotation(logo, 0, -30, 0)
|
||||
|
||||
local stone = materialNew()
|
||||
materialSetColor(stone, 120, 120, 130)
|
||||
materialSetRoughness(stone, 0.9)
|
||||
local floor = nodeNew()
|
||||
nodeSetMesh(floor, meshBox(16, 0.2, 10), stone)
|
||||
nodeSetPosition(floor, 0, -2.6, 0)
|
||||
|
||||
local sun = lightNew(LIGHT_DIRECTIONAL)
|
||||
nodeSetPosition(sun, -4, 8, 6)
|
||||
nodeLookAt(sun, 0, 0, 0)
|
||||
lightSetIntensity(sun, 1.6)
|
||||
lightSetShadow(sun, true)
|
||||
|
||||
local camera = nodeNew()
|
||||
nodeSetPosition(camera, 0, 2, 13)
|
||||
nodeLookAt(camera, 0, 0, 0)
|
||||
cameraSet(camera)
|
||||
|
||||
debugPrint("logo letters " .. #nodeGetChildren(nodeGetChildren(logo)[1]))
|
||||
|
||||
function onOverlayUpdate()
|
||||
frames = frames + 1
|
||||
nodeRotate(logo, 0, 0.5, 0)
|
||||
overlayClear()
|
||||
fontPrint(20, 20, "Logo model, frame " .. frames)
|
||||
if frames == 30 or frames == 100 or frames == 170 then
|
||||
singeScreenshot()
|
||||
end
|
||||
if frames == 180 then
|
||||
singeQuit()
|
||||
end
|
||||
end
|
||||
54
testScripts/scene16.singe
Normal file
54
testScripts/scene16.singe
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
-- Dragon and logo together: the solid tangram dragon perched on top of the Singe logotype, the pair
|
||||
-- turning as one under a sun with shadows, over the disc.
|
||||
local font = fontLoad("Singe/FreeSansBold.ttf", 28)
|
||||
local frames = 0
|
||||
|
||||
fontSelect(font)
|
||||
discPlay()
|
||||
sceneEnable(true)
|
||||
sceneSetBackground(0, 0, 0, 0)
|
||||
sceneSetAmbient(70, 70, 80)
|
||||
|
||||
-- Both models rest on Y = 0 and are centred on X; the logo is 5 units tall at the top of the S.
|
||||
local group = nodeNew()
|
||||
nodeSetPosition(group, 0, -6, 0)
|
||||
nodeSetRotation(group, 0, -25, 0)
|
||||
|
||||
local logo = modelInstance(modelLoad("testScripts/Models/SingeText.glb"))
|
||||
nodeSetParent(logo, group)
|
||||
|
||||
local dragon = modelInstance(modelLoad("testScripts/Models/DragonModel.glb"))
|
||||
nodeSetParent(dragon, group)
|
||||
nodeSetPosition(dragon, 0, 4.85, 0)
|
||||
nodeSetScale(dragon, 0.9)
|
||||
|
||||
local stone = materialNew()
|
||||
materialSetColor(stone, 120, 120, 130)
|
||||
materialSetRoughness(stone, 0.9)
|
||||
local floor = nodeNew()
|
||||
nodeSetMesh(floor, meshBox(18, 0.2, 12), stone)
|
||||
nodeSetPosition(floor, 0, -6.1, 0)
|
||||
|
||||
local sun = lightNew(LIGHT_DIRECTIONAL)
|
||||
nodeSetPosition(sun, -5, 10, 7)
|
||||
nodeLookAt(sun, 0, 0, 0)
|
||||
lightSetIntensity(sun, 1.6)
|
||||
lightSetShadow(sun, true)
|
||||
|
||||
local camera = nodeNew()
|
||||
nodeSetPosition(camera, 0, 3, 15.5)
|
||||
nodeLookAt(camera, 0, 0, 0)
|
||||
cameraSet(camera)
|
||||
|
||||
function onOverlayUpdate()
|
||||
frames = frames + 1
|
||||
nodeRotate(group, 0, 0.4, 0)
|
||||
overlayClear()
|
||||
fontPrint(20, 20, "Dragon on logo, frame " .. frames)
|
||||
if frames == 30 or frames == 100 or frames == 170 then
|
||||
singeScreenshot()
|
||||
end
|
||||
if frames == 180 then
|
||||
singeQuit()
|
||||
end
|
||||
end
|
||||
549
thirdparty/SDL_shadercross/CMakeLists.txt
vendored
Normal file
549
thirdparty/SDL_shadercross/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,549 @@
|
|||
# CMake Project for SDL3_shadercross - Simple DirectMedia Layer Shader Cross Compiler
|
||||
# Written by @thatcosmonaut
|
||||
cmake_minimum_required(VERSION 3.22...4.0)
|
||||
|
||||
# Version
|
||||
set(MAJOR_VERSION 3)
|
||||
set(MINOR_VERSION 0)
|
||||
set(MICRO_VERSION 0)
|
||||
set(SDL_REQUIRED_VERSION "3.1.3")
|
||||
|
||||
# option() honors normal variables.
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
|
||||
project(SDL3_shadercross LANGUAGES C VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")
|
||||
|
||||
set(SHADERCROSS_MAINPROJECT ${SDL3_shadercross_IS_TOP_LEVEL})
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
include(CMakeDependentOption)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/cmake/GetGitRevisionDescription.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/cmake/PrivateSdlFunctions.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sdlcpu.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sdlplatform.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sdlmanpages.cmake")
|
||||
|
||||
if(NOT (TARGET SDL3::Headers AND TARGET SDL3::SDL3 AND (TARGET SDL3::SDL3-static OR TARGET SDL3::SDL3-shared)))
|
||||
find_package(SDL3 ${SDL_REQUIRED_VERSION})
|
||||
endif()
|
||||
|
||||
if(TARGET SDL3::SDL3-shared)
|
||||
set(SDLSHADERCROSS_SHARED_DEFAULT ON)
|
||||
set(SDLSHADERCROSS_STATIC_DEFAULT OFF)
|
||||
else()
|
||||
set(SDLSHADERCROSS_SHARED_DEFAULT OFF)
|
||||
set(SDLSHADERCROSS_STATIC_DEFAULT ON)
|
||||
endif()
|
||||
|
||||
# Options
|
||||
option(SDLSHADERCROSS_DXC "Enable HLSL compilation via DXC" ON)
|
||||
option(SDLSHADERCROSS_SHARED "Build shared SDL_shadercross library" ${SDLSHADERCROSS_SHARED_DEFAULT})
|
||||
option(SDLSHADERCROSS_STATIC "Build static SDL_shadercross library" ${SDLSHADERCROSS_STATIC_DEFAULT})
|
||||
option(SDLSHADERCROSS_SPIRVCROSS_SHARED "Link to shared library variants of dependencies" ON)
|
||||
option(SDLSHADERCROSS_VENDORED "Use vendored dependencies" OFF)
|
||||
option(SDLSHADERCROSS_CLI "Build command line executable" ON)
|
||||
cmake_dependent_option(SDLSHADERCROSS_CLI_STATIC "Link CLI with static libraries" OFF "SDLSHADERCROSS_CLI;SDLSHADERCROSS_STATIC;TARGET SDL3::SDL3-static" OFF)
|
||||
cmake_dependent_option(SDLSHADERCROSS_CLI_LEAKCHECK "Check shadercross for memory leaks" OFF "SDLSHADERCROSS_CLI;TARGET SDL3::SDL3_test" OFF)
|
||||
option(SDLSHADERCROSS_WERROR "Enable Werror" OFF)
|
||||
option(SDLSHADERCROSS_INSTALL "Enable installation" ${SHADERCROSS_MAINPROJECT})
|
||||
cmake_dependent_option(SDLSHADERCROSS_INSTALL_CPACK "Enable CPack installation" ${SHADERCROSS_MAINPROJECT} "SDLSHADERCROSS_INSTALL" OFF)
|
||||
cmake_dependent_option(SDLSHADERCROSS_INSTALL_MAN "Install man pages for SDL3_shadercross" OFF "SDLSHADERCROSS_INSTALL" OFF)
|
||||
cmake_dependent_option(SDLSHADERCROSS_INSTALL_RUNTIME "Download, build and install runtime dependencies" OFF "SDLSHADERCROSS_INSTALL" OFF)
|
||||
|
||||
option(SDLSHADERCROSS_TESTS "Build unit tests?" OFF)
|
||||
cmake_dependent_option(SDLSHADERCROSS_TESTS_TRACKMEM "Enable memory tracking in tests" OFF SDLSHADERCROSS_TESTS OFF)
|
||||
|
||||
sdl_calculate_derived_version_variables(${MAJOR_VERSION} ${MINOR_VERSION} ${MICRO_VERSION})
|
||||
SDL_DetectTargetCPUArchitectures(SDL_CPU_NAMES)
|
||||
SDL_DetectCMakePlatform()
|
||||
|
||||
if(SDLSHADERCROSS_INSTALL)
|
||||
include(GNUInstallDirs)
|
||||
endif()
|
||||
|
||||
if(NOT SDLSHADERCROSS_SHARED AND NOT SDLSHADERCROSS_STATIC)
|
||||
message(FATAL_ERROR "SDLSHADERCROSS_SHARED and SDLSHADERCROSS_STATIC cannot be both disabled")
|
||||
endif()
|
||||
|
||||
# Platform Flags
|
||||
if(APPLE)
|
||||
set(CMAKE_MACOSX_RPATH ON)
|
||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
add_compile_options(-pedantic) # -Wno-strict-aliasing
|
||||
endif()
|
||||
|
||||
set(spirv_static_targets spirv-cross-c spirv-cross-glsl spirv-cross-hlsl spirv-cross-msl spirv-cross-cpp spirv-cross-reflect spirv-cross-core)
|
||||
|
||||
set(pc_requires )
|
||||
set(vendored_targets )
|
||||
if(SDLSHADERCROSS_VENDORED)
|
||||
set(SPIRV_CROSS_SKIP_INSTALL ON)
|
||||
set(SPIRV_CROSS_CLI OFF)
|
||||
set(SPIRV_CROSS_ENABLE_TESTS OFF)
|
||||
if(SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
set(SPIRV_CROSS_SHARED ON)
|
||||
set(SPIRV_CROSS_STATIC OFF)
|
||||
else()
|
||||
set(SPIRV_CROSS_SHARED OFF)
|
||||
set(SPIRV_CROSS_STATIC ON)
|
||||
endif()
|
||||
|
||||
sdl_check_project_in_subfolder(external/SPIRV-Cross SPIRV-Cross SDLSHADERCROSS_VENDORED)
|
||||
set(SPIRV_CROSS_ENABLE_TESTS ON)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
add_subdirectory(external/SPIRV-Cross EXCLUDE_FROM_ALL)
|
||||
|
||||
if(SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
list(APPEND vendored_targets spirv-cross-c-shared)
|
||||
list(APPEND pc_requires "spirv-cross-c-shared")
|
||||
else()
|
||||
enable_language(CXX)
|
||||
if(SDLSHADERCROSS_STATIC)
|
||||
foreach(extra IN LISTS spirv_static_targets)
|
||||
if(TARGET ${extra})
|
||||
list(APPEND vendored_targets ${extra})
|
||||
list(APPEND pc_requires "${extra}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
sdl_check_project_in_subfolder(external/SPIRV-Headers SPIRV-Headers SDLSHADERCROSS_VENDORED)
|
||||
add_subdirectory(external/SPIRV-Headers EXCLUDE_FROM_ALL)
|
||||
sdl_check_project_in_subfolder(external/SPIRV-Tools SPIRV-Tools SDLSHADERCROSS_VENDORED)
|
||||
add_subdirectory(external/SPIRV-Tools EXCLUDE_FROM_ALL)
|
||||
|
||||
sdl_check_project_in_subfolder(external/DirectXShaderCompiler DirectXShaderCompiler SDLSHADERCROSS_VENDORED)
|
||||
if(MINGW)
|
||||
set(CMAKE_C_COMPILER_ARCHITECTURE_ID "${SDL_CPU_NAMES}")
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_DXC)
|
||||
# LLVM dependencies of dxc does not support building as a shared library
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
# Enabling HLSL_ENABLE_DEBUG_ITERATORS blocks DirectXShaderCompiler from adding /D_ITERATOR_DEBUG_LEVEL=0
|
||||
set(HLSL_ENABLE_DEBUG_ITERATORS ON)
|
||||
set(DXC_COVERAGE OFF)
|
||||
set(HLSL_INCLUDE_TESTS OFF)
|
||||
set(LLVM_INCLUDE_TESTS OFF)
|
||||
set(HLSL_DISABLE_SOURCE_GENERATION TRUE)
|
||||
set(SPIRV_BUILD_TESTS FALSE)
|
||||
include(external/DirectXShaderCompiler/cmake/caches/PredefinedParams.cmake)
|
||||
add_subdirectory(external/DirectXShaderCompiler EXCLUDE_FROM_ALL)
|
||||
add_library(DirectXShaderCompiler::dxcompiler ALIAS dxcompiler)
|
||||
add_library(DirectXShaderCompiler::dxil ALIAS dxildll)
|
||||
list(APPEND vendored_targets dxcompiler dxildll)
|
||||
add_dependencies(dxcompiler dxildll)
|
||||
endif()
|
||||
|
||||
export(TARGETS ${vendored_targets} NAMESPACE "SDL3_shadercross::" FILE "SDL3_shadercross-vendored-targets.cmake")
|
||||
else()
|
||||
if(SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
if(NOT TARGET spirv_cross_c_shared)
|
||||
find_package(spirv_cross_c_shared REQUIRED)
|
||||
endif()
|
||||
else()
|
||||
enable_language(CXX)
|
||||
if(NOT TARGET spirv_cross_c)
|
||||
find_package(spirv_cross_core QUIET)
|
||||
find_package(spirv_cross_glsl QUIET)
|
||||
find_package(spirv_cross_hlsl QUIET)
|
||||
find_package(spirv_cross_msl QUIET)
|
||||
find_package(spirv_cross_cpp QUIET)
|
||||
find_package(spirv_cross_reflect QUIET)
|
||||
find_package(spirv_cross_c REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_DXC)
|
||||
set(DirectXShaderCompiler_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/external/DirectXShaderCompiler-binaries")
|
||||
find_package(DirectXShaderCompiler REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Source lists
|
||||
set(SOURCE_FILES
|
||||
# Public Headers
|
||||
include/SDL3_shadercross/SDL_shadercross.h
|
||||
# Source Files
|
||||
src/SDL_shadercross.c
|
||||
)
|
||||
|
||||
set(SDL3_shadercross_targets)
|
||||
if(SDLSHADERCROSS_SHARED)
|
||||
list(APPEND SDL3_shadercross_targets SDL3_shadercross-shared)
|
||||
if(NOT TARGET SDL3::SDL3-shared)
|
||||
find_package(SDL3 ${SDL_REQUIRED_VERSION} REQUIRED COMPONENTS SDL3-shared)
|
||||
endif()
|
||||
|
||||
add_library(SDL3_shadercross-shared SHARED ${SOURCE_FILES})
|
||||
add_library(SDL3_shadercross::SDL3_shadercross ALIAS SDL3_shadercross-shared)
|
||||
|
||||
set_property(TARGET SDL3_shadercross-shared PROPERTY DEFINE_SYMBOL DLL_EXPORT)
|
||||
sdl_target_link_option_version_file(SDL3_shadercross-shared "${CMAKE_CURRENT_SOURCE_DIR}/src/SDL_shadercross.sym")
|
||||
sdl_target_link_options_no_undefined(SDL3_shadercross-shared)
|
||||
|
||||
# Build flags
|
||||
if(WIN32)
|
||||
target_sources(SDL3_shadercross-shared PRIVATE "src/version.rc")
|
||||
set_property(TARGET SDL3_shadercross-shared PROPERTY PREFIX "")
|
||||
endif()
|
||||
|
||||
# SDL3_shadercross folders as includes, for other targets to consume
|
||||
target_include_directories(SDL3_shadercross-shared PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
|
||||
target_include_directories(SDL3_shadercross-shared PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
|
||||
# Soname
|
||||
set_target_properties(SDL3_shadercross-shared PROPERTIES
|
||||
OUTPUT_NAME "SDL3_shadercross"
|
||||
SOVERSION "${SO_VERSION_MAJOR}"
|
||||
VERSION "${SO_VERSION}"
|
||||
)
|
||||
|
||||
target_link_libraries(SDL3_shadercross-shared PRIVATE
|
||||
SDL3::SDL3-shared
|
||||
)
|
||||
export(TARGETS SDL3_shadercross-shared NAMESPACE "SDL3_shadercross::" FILE "SDL3_shadercross-shared-targets.cmake")
|
||||
endif()
|
||||
|
||||
|
||||
if(SDLSHADERCROSS_STATIC)
|
||||
list(APPEND SDL3_shadercross_targets SDL3_shadercross-static)
|
||||
if(NOT TARGET SDL3::Headers)
|
||||
find_package(SDL3 ${SDL_REQUIRED_VERSION} REQUIRED COMPONENTS Headers)
|
||||
endif()
|
||||
|
||||
add_library(SDL3_shadercross-static STATIC ${SOURCE_FILES})
|
||||
add_library(SDL3_shadercross::SDL3_shadercross-static ALIAS SDL3_shadercross-static)
|
||||
|
||||
if(NOT MSVC)
|
||||
set_property(TARGET SDL3_shadercross-static PROPERTY OUTPUT_NAME "SDL3_shadercross")
|
||||
endif()
|
||||
|
||||
# SDL3_shadercross folders as includes, for other targets to consume
|
||||
target_include_directories(SDL3_shadercross-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
|
||||
target_include_directories(SDL3_shadercross-static PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
|
||||
target_link_libraries(SDL3_shadercross-static PUBLIC
|
||||
SDL3::Headers
|
||||
)
|
||||
export(TARGETS SDL3_shadercross-static NAMESPACE "SDL3_shadercross::" FILE "SDL3_shadercross-static-targets.cmake")
|
||||
endif()
|
||||
|
||||
# Copy dependencies of SDL3_shadercross-config.cmake to build directory.
|
||||
# This allows usage of the package without installation.
|
||||
file(COPY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdlcpu.cmake"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindDirectXShaderCompiler.cmake"
|
||||
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
foreach(target IN LISTS SDL3_shadercross_targets)
|
||||
sdl_add_warning_options(${target} WARNING_AS_ERROR ${SDLSHADERCROSS_WERROR})
|
||||
target_compile_features(${target} PRIVATE c_std_99)
|
||||
|
||||
if(SDLSHADERCROSS_DXC)
|
||||
add_compile_definitions(SDL_SHADERCROSS_DXC)
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
target_link_libraries(${target} PRIVATE spirv-cross-c-shared)
|
||||
else()
|
||||
target_link_libraries(${target} PRIVATE spirv-cross-c)
|
||||
endif()
|
||||
if(SDLSHADERCROSS_DXC)
|
||||
target_link_libraries(${target} PRIVATE DirectXShaderCompiler::dxcompiler)
|
||||
endif()
|
||||
if(NOT SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
# spirv-cross uses C++
|
||||
set_property(TARGET ${target} PROPERTY LINKER_LANGUAGE CXX)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT TARGET SDL3_shadercross::SDL3_shadercross)
|
||||
if(TARGET SDL3_shadercross-shared)
|
||||
add_library(SDL3_shadercross::SDL3_shadercross ALIAS SDL3_shadercross-shared)
|
||||
else()
|
||||
add_library(SDL3_shadercross::SDL3_shadercross ALIAS SDL3_shadercross-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_CLI)
|
||||
add_executable(shadercross src/cli.c)
|
||||
sdl_add_warning_options(shadercross WARNING_AS_ERROR ${SDLSHADERCROSS_WERROR})
|
||||
sdl_target_link_options_no_undefined(shadercross)
|
||||
|
||||
if(SDLSHADERCROSS_CLI_LEAKCHECK)
|
||||
target_link_libraries(shadercross PRIVATE SDL3::SDL3_test)
|
||||
target_compile_definitions(shadercross PRIVATE LEAKCHECK)
|
||||
endif()
|
||||
if(SDLSHADERCROSS_CLI_STATIC)
|
||||
target_link_libraries(shadercross PRIVATE SDL3_shadercross::SDL3_shadercross-static)
|
||||
target_link_libraries(shadercross PRIVATE SDL3::SDL3-static)
|
||||
else()
|
||||
if(NOT TARGET SDL3::SDL3)
|
||||
find_package(SDL3 ${SDL_REQUIRED_VERSION} REQUIRED CONFIG COMPONENTS SDL3)
|
||||
endif()
|
||||
target_link_libraries(shadercross PRIVATE SDL3_shadercross::SDL3_shadercross)
|
||||
target_link_libraries(shadercross PRIVATE SDL3::SDL3)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_INSTALL)
|
||||
if(WIN32 AND NOT MINGW)
|
||||
set(INSTALL_CMAKEDIR_ROOT_DEFAULT "cmake")
|
||||
else()
|
||||
set(INSTALL_CMAKEDIR_ROOT_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake")
|
||||
endif()
|
||||
set(SDLSHADERCROSS_INSTALL_CMAKEDIR_ROOT "${INSTALL_CMAKEDIR_ROOT_DEFAULT}" CACHE STRING "Root folder where to install SDL3_shadercross cmake related files (SDL3_shadercross subfolder for MSVC projects)")
|
||||
set(SDLSHADERCROSS_PKGCONFIG_INSTALLDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
|
||||
if(WIN32 AND NOT MINGW)
|
||||
set(SDLSHADERCROSS_INSTALL_CMAKEDIR "${SDLSHADERCROSS_INSTALL_CMAKEDIR_ROOT}")
|
||||
else()
|
||||
set(SDLSHADERCROSS_INSTALL_CMAKEDIR "${SDLSHADERCROSS_INSTALL_CMAKEDIR_ROOT}/SDL3_shadercross")
|
||||
endif()
|
||||
|
||||
if(TARGET SDL3_shadercross-shared)
|
||||
install(TARGETS SDL3_shadercross-shared EXPORT SDL3_shadercross-shared-export
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT library
|
||||
)
|
||||
install(EXPORT SDL3_shadercross-shared-export
|
||||
FILE SDL3_shadercross-shared-targets.cmake
|
||||
NAMESPACE SDL3_shadercross::
|
||||
DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}"
|
||||
COMPONENT devel
|
||||
)
|
||||
endif()
|
||||
if(TARGET SDL3_shadercross-static)
|
||||
install(TARGETS SDL3_shadercross-static EXPORT SDL3_shadercross-static-export
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library
|
||||
)
|
||||
install(EXPORT SDL3_shadercross-static-export
|
||||
FILE SDL3_shadercross-static-targets.cmake
|
||||
NAMESPACE SDL3_shadercross::
|
||||
DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}"
|
||||
COMPONENT devel
|
||||
)
|
||||
endif()
|
||||
if(vendored_targets)
|
||||
install(TARGETS ${vendored_targets} EXPORT SDL3_shadercross-vendored
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT library
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT library
|
||||
)
|
||||
install(EXPORT SDL3_shadercross-vendored
|
||||
FILE SDL3_shadercross-vendored-targets.cmake
|
||||
NAMESPACE SDL3_shadercross::vendored::
|
||||
DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}"
|
||||
COMPONENT devel
|
||||
)
|
||||
endif()
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/SDL3_shadercross/SDL_shadercross.h"
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/SDL3_shadercross" COMPONENT DEVEL
|
||||
)
|
||||
if(SDLSHADERCROSS_CLI)
|
||||
install(TARGETS shadercross RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
endif()
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(cmake/SDL3_shadercrossConfig.cmake.in SDL3_shadercrossConfig.cmake
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
INSTALL_DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}"
|
||||
)
|
||||
write_basic_package_version_file("${PROJECT_BINARY_DIR}/SDL3_shadercrossConfigVersion.cmake"
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/SDL3_shadercrossConfig.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/SDL3_shadercrossConfigVersion.cmake"
|
||||
DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}"
|
||||
COMPONENT devel
|
||||
)
|
||||
if(NOT SDLSHADERCROSS_VENDORED)
|
||||
install(
|
||||
FILES
|
||||
"cmake/sdlcpu.cmake"
|
||||
"cmake/FindDirectXShaderCompiler.cmake"
|
||||
DESTINATION "${SDLSHADERCROSS_INSTALL_CMAKEDIR}"
|
||||
COMPONENT devel
|
||||
)
|
||||
endif()
|
||||
|
||||
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
set(INCLUDEDIR_FOR_PKG_CONFIG "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
else()
|
||||
set(INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
endif()
|
||||
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
|
||||
set(LIBDIR_FOR_PKG_CONFIG "${CMAKE_INSTALL_LIBDIR}")
|
||||
else()
|
||||
set(LIBDIR_FOR_PKG_CONFIG "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
|
||||
file(RELATIVE_PATH SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${CMAKE_INSTALL_PREFIX}/${SDLSHADERCROSS_PKGCONFIG_INSTALLDIR}" "${CMAKE_INSTALL_PREFIX}")
|
||||
string(REGEX REPLACE "[/]+$" "" SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}")
|
||||
set(SDL_PKGCONFIG_PREFIX "\${pcfiledir}/${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}")
|
||||
if(NOT SDLSHADERCROSS_VENDORED)
|
||||
if(SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
set(PC_REQUIRES "spirv-cross-c-shared")
|
||||
else()
|
||||
set(PC_REQUIRES "spirv-cross-c")
|
||||
endif()
|
||||
endif()
|
||||
set(PC_LIBS "-ldxcompiler")
|
||||
configure_file(cmake/sdl3-shadercross.pc.in sdl3-shadercross.pc @ONLY)
|
||||
|
||||
# Always install sdl3-shadercross.pc file: libraries might be different between config modes
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sdl3-shadercross.pc"
|
||||
DESTINATION "${SDLSHADERCROSS_PKGCONFIG_INSTALLDIR}" COMPONENT devel)
|
||||
|
||||
install(FILES "LICENSE.txt"
|
||||
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}"
|
||||
COMPONENT library
|
||||
)
|
||||
if(SDLSHADERCROSS_INSTALL_CPACK)
|
||||
if(MSVC)
|
||||
set(CPACK_GENERATOR "ZIP")
|
||||
else()
|
||||
set(CPACK_GENERATOR "TGZ")
|
||||
endif()
|
||||
configure_file(cmake/CPackProjectConfig.cmake.in CPackProjectConfig.cmake @ONLY)
|
||||
set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/CPackProjectConfig.cmake")
|
||||
# CPACK_SOURCE_PACKAGE_FILE_NAME must end with "-src" (so we can block creating a source archive)
|
||||
set(CPACK_SOURCE_PACKAGE_FILE_NAME "SDL3_shadercross-${PROJECT_VERSION}-src")
|
||||
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/dist")
|
||||
include(CPack)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_INSTALL_MAN)
|
||||
sdl_get_git_revision_hash(SDLSHADERCROSS_REVISION)
|
||||
SDL_generate_manpages(
|
||||
HEADERS_DIR "${PROJECT_SOURCE_DIR}/include/SDL3_shadercross"
|
||||
SYMBOL "SDL_ShaderCross_Init"
|
||||
WIKIHEADERS_PL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build-scripts/wikiheaders.pl"
|
||||
REVISION "${SDLSHADERCROSS_REVISION}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
if(SDLSHADERCROSS_INSTALL_RUNTIME)
|
||||
set(chmod_0755 OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
if(APPLE)
|
||||
set(rpath_origin "@executable_path")
|
||||
else()
|
||||
set(rpath_origin "\$ORIGIN")
|
||||
endif()
|
||||
|
||||
if(NOT SDLSHADERCROSS_VENDORED)
|
||||
if(SDLSHADERCROSS_DXC)
|
||||
install(IMPORTED_RUNTIME_ARTIFACTS DirectXShaderCompiler::dxcompiler DirectXShaderCompiler::dxil RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
if(SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
install(IMPORTED_RUNTIME_ARTIFACTS spirv-cross-c-shared RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||
if(WIN32)
|
||||
install(CODE "
|
||||
set(CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM \"windows+pe\")
|
||||
set(CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL \"$<IF:$<BOOL:${MSVC}>,dumpbin,objdump>\")
|
||||
set(CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND \"${CMAKE_OBJDUMP}\")
|
||||
file(GET_RUNTIME_DEPENDENCIES
|
||||
RESOLVED_DEPENDENCIES_VAR resolved
|
||||
UNRESOLVED_DEPENDENCIES_VAR unresolved
|
||||
DIRECTORIES \"$<TARGET_FILE_DIR:spirv-cross-c-shared>\" \"${CMAKE_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR}\"
|
||||
LIBRARIES \"$<TARGET_FILE:spirv-cross-c-shared>\"
|
||||
POST_EXCLUDE_REGEXES \".*[sS][yY][sS][tT][eE][mM]32.*\" \".*[aA][pP][iI]-[mM][sS].*\" \".*[aA][pP][iI]-[eE][xX][tT].*\"
|
||||
)
|
||||
file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/bin\" TYPE SHARED_LIBRARY FILES \${resolved})
|
||||
")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(TARGET shadercross)
|
||||
file(RELATIVE_PATH bin_to_lib "${CMAKE_INSTALL_FULL_BINDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}")
|
||||
set_property(TARGET shadercross PROPERTY INSTALL_RPATH "${rpath_origin}/${bin_to_lib}")
|
||||
endif()
|
||||
|
||||
# Install SDL3
|
||||
if(SDLSHADERCROSS_CLI AND NOT SDLSHADERCROSS_CLI_STATIC)
|
||||
install(IMPORTED_RUNTIME_ARTIFACTS SDL3::SDL3-shared RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
include(ExternalProject)
|
||||
|
||||
if(NOT WIN32)
|
||||
set(configure_CFLAGS "${CMAKE_C_FLAGS}")
|
||||
if(APPLE)
|
||||
foreach(osx_arch IN LISTS CMAKE_OSX_ARCHITECTURES)
|
||||
string(APPEND configure_CFLAGS " -arch ${osx_arch}")
|
||||
endforeach()
|
||||
endif()
|
||||
string(REPLACE ";" "$<SEMICOLON>" genex_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
|
||||
|
||||
ExternalProject_Add(spirv_headers
|
||||
GIT_REPOSITORY "https://github.com/KhronosGroup/SPIRV-Headers.git"
|
||||
GIT_TAG "main"
|
||||
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DCMAKE_OSX_ARCHITECTURES=${genex_CMAKE_OSX_ARCHITECTURES}" "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}"
|
||||
BUILD_COMMAND "${CMAKE_COMMAND}" "--build" "<BINARY_DIR>" --config "Release"
|
||||
INSTALL_COMMAND "${CMAKE_COMMAND}" "--install" "<BINARY_DIR>" --config "Release"
|
||||
)
|
||||
ExternalProject_Get_property(spirv_headers INSTALL_DIR)
|
||||
set(spirv_headers_install_dir "${INSTALL_DIR}")
|
||||
|
||||
ExternalProject_Add(vulkan_headers
|
||||
GIT_REPOSITORY "https://github.com/KhronosGroup/Vulkan-Headers"
|
||||
GIT_TAG "main"
|
||||
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DCMAKE_OSX_ARCHITECTURES=${genex_CMAKE_OSX_ARCHITECTURES}" "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}"
|
||||
BUILD_COMMAND "${CMAKE_COMMAND}" "--build" "<BINARY_DIR>" --config "Release"
|
||||
INSTALL_COMMAND "${CMAKE_COMMAND}" "--install" "<BINARY_DIR>" --config "Release"
|
||||
)
|
||||
ExternalProject_Get_property(vulkan_headers INSTALL_DIR)
|
||||
set(vulkan_headers_install_dir "${INSTALL_DIR}")
|
||||
|
||||
ExternalProject_Add(vulkan_loader
|
||||
DEPENDS spirv_headers vulkan_headers
|
||||
GIT_REPOSITORY "https://github.com/KhronosGroup/Vulkan-Loader.git"
|
||||
GIT_TAG "main"
|
||||
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DCMAKE_OSX_ARCHITECTURES=${genex_CMAKE_OSX_ARCHITECTURES}" "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}" "-DCMAKE_PREFIX_PATH=${vulkan_headers_install_dir}"
|
||||
BUILD_COMMAND "${CMAKE_COMMAND}" "--build" "<BINARY_DIR>" --config "Release"
|
||||
INSTALL_COMMAND "${CMAKE_COMMAND}" "--install" "<BINARY_DIR>" --config "Release"
|
||||
)
|
||||
ExternalProject_Get_property(vulkan_loader INSTALL_DIR)
|
||||
set(vulkan_loader_install_dir "${INSTALL_DIR}")
|
||||
|
||||
find_package(BISON REQUIRED)
|
||||
ExternalProject_Add(vkd3d
|
||||
DEPENDS spirv_headers vulkan_headers vulkan_loader
|
||||
URL "https://dl.winehq.org/vkd3d/source/vkd3d-2.0.tar.xz"
|
||||
URL_HASH "SHA256=9ad29bb236808186a47ec66e853b21e6fca59b9dc62a9474b05d5e3eda2710ef"
|
||||
DOWNLOAD_EXTRACT_TIMESTAMP "1"
|
||||
CONFIGURE_COMMAND "sh" "<SOURCE_DIR>/configure" "--prefix=<INSTALL_DIR>" "--enable-tests=no" "--enable-demos=no" "--disable-doxygen-doc" "CFLAGS=-I${spirv_headers_install_dir}/include -I${vulkan_headers_install_dir}/include -I${vulkan_loader_install_dir}/include ${configure_CFLAGS}" "LDFLAGS=-L${vulkan_loader_install_dir}/lib" "BISON=${BISON_EXECUTABLE}"
|
||||
BUILD_COMMAND "make"
|
||||
INSTALL_COMMAND "make" "install"
|
||||
)
|
||||
ExternalProject_Get_property(vkd3d SOURCE_DIR)
|
||||
ExternalProject_Get_property(vkd3d INSTALL_DIR)
|
||||
install(DIRECTORY "${INSTALL_DIR}/lib/" DESTINATION "${CMAKE_INSTALL_LIBDIR}" FILES_MATCHING PATTERN "*.so*" PERMISSIONS ${chmod_0755})
|
||||
install(DIRECTORY "${INSTALL_DIR}/lib/" DESTINATION "${CMAKE_INSTALL_LIBDIR}" FILES_MATCHING PATTERN "*.dylib*" PERMISSIONS ${chmod_0755})
|
||||
install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/vkd3d")
|
||||
endif()
|
||||
if(LINUX)
|
||||
find_program(PATCHELF_BIN NAMES "patchelf" REQUIRED)
|
||||
install(CODE "file(GLOB so_paths \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/*so*\")\n foreach(so_path \${so_paths})\n if(NOT IS_SYMLINK \${so_path})\n message(STATUS \"Adding \\\"\$ORIGIN\\\" to RPATH of \${so_path}\")\n execute_process(COMMAND ${PATCHELF_BIN} \"\${so_path}\" --add-rpath \"\$ORIGIN\")\n endif()\n endforeach()")
|
||||
elseif(APPLE)
|
||||
find_program(INT_BIN NAMES "install_name_tool" REQUIRED)
|
||||
install(CODE "file(GLOB so_paths \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/*dylib*\")\n foreach(so_path \${so_paths})\n if(NOT IS_SYMLINK \${so_path})\n message(STATUS \"Adding \\\"\@loader_path\\\" to RPATH of \${so_path}\")\n execute_process(COMMAND ${INT_BIN} \"\${so_path}\" -add_rpath \"\@loader_path\")\n endif()\n endforeach()")
|
||||
endif()
|
||||
endif()
|
||||
18
thirdparty/SDL_shadercross/LICENSE.txt
vendored
Normal file
18
thirdparty/SDL_shadercross/LICENSE.txt
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Copyright (C) 2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
37
thirdparty/SDL_shadercross/cmake/CPackProjectConfig.cmake.in
vendored
Normal file
37
thirdparty/SDL_shadercross/cmake/CPackProjectConfig.cmake.in
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
if(CPACK_PACKAGE_FILE_NAME MATCHES ".*-src$")
|
||||
message(FATAL_ERROR "Creating source archives is not supported.")
|
||||
endif()
|
||||
|
||||
set(PROJECT_NAME "@PROJECT_NAME@")
|
||||
set(PROJECT_VERSION "@PROJECT_VERSION@")
|
||||
set(PROJECT_SOURCE_DIR "@PROJECT_SOURCE_DIR@")
|
||||
set(SDL_CMAKE_PLATFORM "@SDL_CMAKE_PLATFORM@")
|
||||
set(SDL_CPU_NAMES "@SDL_CPU_NAMES@")
|
||||
list(SORT SDL_CPU_NAMES)
|
||||
|
||||
string(TOLOWER "${SDL_CMAKE_PLATFORM}" SDL_CMAKE_PLATFORM)
|
||||
string(TOLOWER "${SDL_CPU_NAMES}" SDL_CPU_NAMES)
|
||||
if(lower_sdl_cmake_platform STREQUAL lower_sdl_cpu_names)
|
||||
set(SDL_CPU_NAMES_WITH_DASHES)
|
||||
endif()
|
||||
|
||||
string(REPLACE ";" "-" SDL_CPU_NAMES_WITH_DASHES "${SDL_CPU_NAMES}")
|
||||
if(SDL_CPU_NAMES_WITH_DASHES)
|
||||
set(SDL_CPU_NAMES_WITH_DASHES "-${SDL_CPU_NAMES_WITH_DASHES}")
|
||||
endif()
|
||||
|
||||
set(MSVC @MSVC@)
|
||||
set(MINGW @MINGW@)
|
||||
if(MSVC)
|
||||
set(SDL_CMAKE_PLATFORM "${SDL_CMAKE_PLATFORM}-VC")
|
||||
elseif(MINGW)
|
||||
set(SDL_CMAKE_PLATFORM "${SDL_CMAKE_PLATFORM}-mingw")
|
||||
endif()
|
||||
|
||||
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${SDL_CMAKE_PLATFORM}${SDL_CPU_NAMES_WITH_DASHES}")
|
||||
|
||||
if(CPACK_GENERATOR STREQUAL "DragNDrop")
|
||||
set(CPACK_DMG_VOLUME_NAME "@PROJECT_NAME@ @PROJECT_VERSION@")
|
||||
# FIXME: use pre-built/create .DS_Store through AppleScript (CPACK_DMG_DS_STORE/CPACK_DMG_DS_STORE_SETUP_SCRIPT)
|
||||
set(CPACK_DMG_DS_STORE "${PROJECT_SOURCE_DIR}/Xcode/SDL/pkg-support/resources/SDL_DS_Store")
|
||||
endif()
|
||||
60
thirdparty/SDL_shadercross/cmake/FindDirectXShaderCompiler.cmake
vendored
Normal file
60
thirdparty/SDL_shadercross/cmake/FindDirectXShaderCompiler.cmake
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
set(required_vars)
|
||||
|
||||
if(WIN32)
|
||||
find_path(DirectXShaderCompiler_INCLUDE_PATH NAMES "dxcapi.h" PATH_SUFFIXES "inc" "windows/inc" HINTS ${DirectXShaderCompiler_ROOT})
|
||||
if(SDL_CPU_ARM64)
|
||||
set(extra_bin_suffix "bin/arm64" "windows/bin/arm64")
|
||||
set(extra_lib_suffix "lib/arm64" "windows/lib/arm64")
|
||||
elseif(SDL_CPU_X86)
|
||||
set(extra_bin_suffix "bin/x86" "windows/bin/x86")
|
||||
set(extra_lib_suffix "lib/x86" "windows/lib/x86")
|
||||
elseif(SDL_CPU_X64)
|
||||
set(extra_bin_suffix "bin/x64" "windows/bin/x64")
|
||||
set(extra_lib_suffix "lib/x64" "windows/lib/x64")
|
||||
endif()
|
||||
find_file(DirectXShaderCompiler_dxcompiler_BINARY NAMES "dxcompiler.dll" PATH_SUFFIXES "bin" ${extra_bin_suffix} HINTS ${DirectXShaderCompiler_ROOT})
|
||||
find_library(DirectXShaderCompiler_dxcompiler_LIBRARY NAMES "dxcompiler" "dxcompiler.lib" PATH_SUFFIXES "lib" ${extra_lib_suffix} HINTS ${DirectXShaderCompiler_ROOT})
|
||||
find_file(DirectXShaderCompiler_dxil_BINARY NAMES "dxil.dll" PATH_SUFFIXES "bin" ${extra_bin_suffix} HINTS ${DirectXShaderCompiler_ROOT})
|
||||
set(required_vars
|
||||
DirectXShaderCompiler_INCLUDE_PATH
|
||||
DirectXShaderCompiler_dxcompiler_BINARY
|
||||
DirectXShaderCompiler_dxcompiler_LIBRARY
|
||||
DirectXShaderCompiler_dxil_BINARY
|
||||
)
|
||||
else()
|
||||
find_path(DirectXShaderCompiler_INCLUDE_PATH NAMES "dxcapi.h" PATH_SUFFIXES "include" "include/dxc" "linux/include" "linux/include/dxc" HINTS ${DirectXShaderCompiler_ROOT})
|
||||
find_library(DirectXShaderCompiler_dxcompiler_LIBRARY NAMES "dxcompiler" PATH_SUFFIXES "lib" "linux/lib" HINTS ${DirectXShaderCompiler_ROOT})
|
||||
find_library(DirectXShaderCompiler_dxil_LIBRARY NAMES "dxil" PATH_SUFFIXES "lib" "linux/lib" HINTS ${DirectXShaderCompiler_ROOT})
|
||||
set(required_vars
|
||||
DirectXShaderCompiler_INCLUDE_PATH
|
||||
DirectXShaderCompiler_dxcompiler_LIBRARY
|
||||
DirectXShaderCompiler_dxil_LIBRARY
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(DirectXShaderCompiler
|
||||
REQUIRED_VARS ${required_vars}
|
||||
)
|
||||
|
||||
if(DirectXShaderCompiler_FOUND)
|
||||
if(NOT TARGET DirectXShaderCompiler::dxcompiler)
|
||||
add_library(DirectXShaderCompiler::dxcompiler IMPORTED SHARED)
|
||||
set_property(TARGET DirectXShaderCompiler::dxcompiler PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${DirectXShaderCompiler_INCLUDE_PATH}")
|
||||
if(WIN32)
|
||||
set_property(TARGET DirectXShaderCompiler::dxcompiler PROPERTY IMPORTED_LOCATION "${DirectXShaderCompiler_dxcompiler_BINARY}")
|
||||
set_property(TARGET DirectXShaderCompiler::dxcompiler PROPERTY IMPORTED_IMPLIB "${DirectXShaderCompiler_dxcompiler_LIBRARY}")
|
||||
else()
|
||||
set_property(TARGET DirectXShaderCompiler::dxcompiler PROPERTY IMPORTED_LOCATION "${DirectXShaderCompiler_dxcompiler_LIBRARY}")
|
||||
endif()
|
||||
endif()
|
||||
if(NOT TARGET DirectXShaderCompiler::dxil)
|
||||
add_library(DirectXShaderCompiler::dxil IMPORTED SHARED)
|
||||
if(WIN32)
|
||||
set_property(TARGET DirectXShaderCompiler::dxil PROPERTY IMPORTED_LOCATION "${DirectXShaderCompiler_dxil_BINARY}")
|
||||
else()
|
||||
set_property(TARGET DirectXShaderCompiler::dxil PROPERTY IMPORTED_LOCATION "${DirectXShaderCompiler_dxil_LIBRARY}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
284
thirdparty/SDL_shadercross/cmake/GetGitRevisionDescription.cmake
vendored
Normal file
284
thirdparty/SDL_shadercross/cmake/GetGitRevisionDescription.cmake
vendored
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
# - Returns a version string from Git
|
||||
#
|
||||
# These functions force a re-configure on each git commit so that you can
|
||||
# trust the values of the variables in your build system.
|
||||
#
|
||||
# get_git_head_revision(<refspecvar> <hashvar> [ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR])
|
||||
#
|
||||
# Returns the refspec and sha hash of the current head revision
|
||||
#
|
||||
# git_describe(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the source tree, and adjusting
|
||||
# the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_describe_working_tree(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the working tree (--dirty option),
|
||||
# and adjusting the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe --exact-match on the source tree,
|
||||
# and adjusting the output so that it tests false if there was no exact
|
||||
# matching tag.
|
||||
#
|
||||
# git_local_changes(<var>)
|
||||
#
|
||||
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
|
||||
# Uses the return code of "git diff-index --quiet HEAD --".
|
||||
# Does not regard untracked files.
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
#
|
||||
# Copyright 2009-2013, Iowa State University.
|
||||
# Copyright 2013-2020, Ryan Pavlik
|
||||
# Copyright 2013-2020, Contributors
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(__get_git_revision_description)
|
||||
return()
|
||||
endif()
|
||||
set(__get_git_revision_description YES)
|
||||
|
||||
# We must run the following at "include" time, not at function call time,
|
||||
# to find the path to this module rather than the path to a calling list file
|
||||
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
|
||||
# Function _git_find_closest_git_dir finds the next closest .git directory
|
||||
# that is part of any directory in the path defined by _start_dir.
|
||||
# The result is returned in the parent scope variable whose name is passed
|
||||
# as variable _git_dir_var. If no .git directory can be found, the
|
||||
# function returns an empty string via _git_dir_var.
|
||||
#
|
||||
# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and
|
||||
# neither foo nor bar contain a file/directory .git. This will return
|
||||
# C:/bla/.git
|
||||
#
|
||||
function(_git_find_closest_git_dir _start_dir _git_dir_var)
|
||||
set(cur_dir "${_start_dir}")
|
||||
set(git_dir "${_start_dir}/.git")
|
||||
while(NOT EXISTS "${git_dir}")
|
||||
# .git dir not found, search parent directories
|
||||
set(git_previous_parent "${cur_dir}")
|
||||
get_filename_component(cur_dir "${cur_dir}" DIRECTORY)
|
||||
if(cur_dir STREQUAL git_previous_parent)
|
||||
# We have reached the root directory, we are not in git
|
||||
set(${_git_dir_var}
|
||||
""
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
set(git_dir "${cur_dir}/.git")
|
||||
endwhile()
|
||||
set(${_git_dir_var}
|
||||
"${git_dir}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(get_git_head_revision _refspecvar _hashvar)
|
||||
_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
|
||||
|
||||
if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR")
|
||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE)
|
||||
else()
|
||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR FALSE)
|
||||
endif()
|
||||
if(NOT "${GIT_DIR}" STREQUAL "")
|
||||
file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}"
|
||||
"${GIT_DIR}")
|
||||
if("${_relative_to_source_dir}" MATCHES "[.][.]" AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
|
||||
# We've gone above the CMake root dir.
|
||||
set(GIT_DIR "")
|
||||
endif()
|
||||
endif()
|
||||
if("${GIT_DIR}" STREQUAL "")
|
||||
set(${_refspecvar}
|
||||
"GITDIR-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
set(${_hashvar}
|
||||
"GITDIR-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Check if the current source dir is a git submodule or a worktree.
|
||||
# In both cases .git is a file instead of a directory.
|
||||
#
|
||||
if(NOT IS_DIRECTORY ${GIT_DIR})
|
||||
# The following git command will return a non empty string that
|
||||
# points to the super project working tree if the current
|
||||
# source dir is inside a git submodule.
|
||||
# Otherwise the command will return an empty string.
|
||||
#
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" rev-parse
|
||||
--show-superproject-working-tree
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT "${out}" STREQUAL "")
|
||||
# If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule
|
||||
file(READ ${GIT_DIR} submodule)
|
||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE
|
||||
${submodule})
|
||||
string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
|
||||
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
|
||||
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
|
||||
ABSOLUTE)
|
||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||
else()
|
||||
# GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree
|
||||
file(READ ${GIT_DIR} worktree_ref)
|
||||
# The .git directory contains a path to the worktree information directory
|
||||
# inside the parent git repo of the worktree.
|
||||
#
|
||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir
|
||||
${worktree_ref})
|
||||
string(STRIP ${git_worktree_dir} git_worktree_dir)
|
||||
_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
|
||||
set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
|
||||
endif()
|
||||
else()
|
||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||
endif()
|
||||
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
|
||||
if(NOT EXISTS "${GIT_DATA}")
|
||||
file(MAKE_DIRECTORY "${GIT_DATA}")
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${HEAD_SOURCE_FILE}")
|
||||
return()
|
||||
endif()
|
||||
set(HEAD_FILE "${GIT_DATA}/HEAD")
|
||||
configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY)
|
||||
|
||||
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
|
||||
"${GIT_DATA}/grabRef.cmake" @ONLY)
|
||||
include("${GIT_DATA}/grabRef.cmake")
|
||||
|
||||
set(${_refspecvar}
|
||||
"${HEAD_REF}"
|
||||
PARENT_SCOPE)
|
||||
set(${_hashvar}
|
||||
"${HEAD_HASH}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_describe _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash)
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var}
|
||||
"HEAD-HASH-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# TODO sanitize
|
||||
#if((${ARGN}" MATCHES "&&") OR
|
||||
# (ARGN MATCHES "||") OR
|
||||
# (ARGN MATCHES "\\;"))
|
||||
# message("Please report the following error to the project!")
|
||||
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
|
||||
#endif()
|
||||
|
||||
#message(STATUS "Arguments to execute_process: ${ARGN}")
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
set(out "${out}-${res}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_describe_working_tree _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
set(out "${out}-${res}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_get_exact_tag _var)
|
||||
git_describe(out --exact-match ${ARGN})
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_local_changes _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash)
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var}
|
||||
"HEAD-HASH-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(res EQUAL 0)
|
||||
set(${_var}
|
||||
"CLEAN"
|
||||
PARENT_SCOPE)
|
||||
else()
|
||||
set(${_var}
|
||||
"DIRTY"
|
||||
PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
43
thirdparty/SDL_shadercross/cmake/GetGitRevisionDescription.cmake.in
vendored
Normal file
43
thirdparty/SDL_shadercross/cmake/GetGitRevisionDescription.cmake.in
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# Internal file for GetGitRevisionDescription.cmake
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright 2009-2012, Iowa State University
|
||||
# Copyright 2011-2015, Contributors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
set(HEAD_HASH)
|
||||
|
||||
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
|
||||
|
||||
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
|
||||
if(HEAD_CONTENTS MATCHES "ref")
|
||||
# named branch
|
||||
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
|
||||
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
|
||||
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
else()
|
||||
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
|
||||
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
|
||||
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
|
||||
set(HEAD_HASH "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
# detached HEAD
|
||||
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
endif()
|
||||
|
||||
if(NOT HEAD_HASH)
|
||||
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
||||
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
||||
endif()
|
||||
363
thirdparty/SDL_shadercross/cmake/PrivateSdlFunctions.cmake
vendored
Normal file
363
thirdparty/SDL_shadercross/cmake/PrivateSdlFunctions.cmake
vendored
Normal file
|
|
@ -0,0 +1,363 @@
|
|||
# This file is shared amongst SDL_image/SDL_mixer/SDL_ttf
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
include(CheckCSourceCompiles)
|
||||
include(CMakePushCheckState)
|
||||
|
||||
macro(sdl_calculate_derived_version_variables MAJOR MINOR MICRO)
|
||||
set(SO_VERSION_MAJOR "0")
|
||||
set(SO_VERSION_MINOR "${MINOR_VERSION}")
|
||||
set(SO_VERSION_MICRO "${MICRO_VERSION}")
|
||||
set(SO_VERSION "${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_MICRO}")
|
||||
|
||||
if(MINOR MATCHES "[02468]$")
|
||||
math(EXPR DYLIB_COMPAT_VERSION_MAJOR "100 * ${MINOR} + 1")
|
||||
set(DYLIB_COMPAT_VERSION_MINOR "0")
|
||||
math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${DYLIB_COMPAT_VERSION_MAJOR}")
|
||||
set(DYLIB_CURRENT_VERSION_MINOR "${MICRO}")
|
||||
else()
|
||||
math(EXPR DYLIB_COMPAT_VERSION_MAJOR "100 * ${MINOR} + ${MICRO} + 1")
|
||||
set(DYLIB_COMPAT_VERSION_MINOR "0")
|
||||
math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${DYLIB_COMPAT_VERSION_MAJOR}")
|
||||
set(DYLIB_CURRENT_VERSION_MINOR "0")
|
||||
endif()
|
||||
set(DYLIB_COMPAT_VERSION_MICRO "0")
|
||||
set(DYLIB_CURRENT_VERSION_MICRO "0")
|
||||
|
||||
set(DYLIB_CURRENT_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.${DYLIB_CURRENT_VERSION_MINOR}.${DYLIB_CURRENT_VERSION_MICRO}")
|
||||
set(DYLIB_COMPAT_VERSION "${DYLIB_COMPAT_VERSION_MAJOR}.${DYLIB_COMPAT_VERSION_MINOR}.${DYLIB_COMPAT_VERSION_MICRO}")
|
||||
endmacro()
|
||||
|
||||
function(read_absolute_symlink DEST PATH)
|
||||
file(READ_SYMLINK "${PATH}" p)
|
||||
if(NOT IS_ABSOLUTE "${p}")
|
||||
get_filename_component(pdir "${PATH}" DIRECTORY)
|
||||
set(p "${pdir}/${p}")
|
||||
endif()
|
||||
get_filename_component(p "${p}" ABSOLUTE)
|
||||
set("${DEST}" "${p}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(win32_implib_identify_dll DEST IMPLIB)
|
||||
cmake_parse_arguments(ARGS "NOTFATAL" "" "" ${ARGN})
|
||||
if(CMAKE_DLLTOOL)
|
||||
execute_process(
|
||||
COMMAND "${CMAKE_DLLTOOL}" --identify "${IMPLIB}"
|
||||
RESULT_VARIABLE retcode
|
||||
OUTPUT_VARIABLE stdout
|
||||
ERROR_VARIABLE stderr)
|
||||
if(NOT retcode EQUAL 0)
|
||||
if(NOT ARGS_NOTFATAL)
|
||||
message(FATAL_ERROR "${CMAKE_DLLTOOL} failed.")
|
||||
else()
|
||||
set("${DEST}" "${DEST}-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
string(STRIP "${stdout}" result)
|
||||
set(${DEST} "${result}" PARENT_SCOPE)
|
||||
elseif(MSVC)
|
||||
get_filename_component(CMAKE_C_COMPILER_DIRECTORY "${CMAKE_C_COMPILER}" DIRECTORY CACHE)
|
||||
find_program(CMAKE_DUMPBIN NAMES dumpbin PATHS "${CMAKE_C_COMPILER_DIRECTORY}")
|
||||
if(CMAKE_DUMPBIN)
|
||||
execute_process(
|
||||
COMMAND "${CMAKE_DUMPBIN}" "-headers" "${IMPLIB}"
|
||||
RESULT_VARIABLE retcode
|
||||
OUTPUT_VARIABLE stdout
|
||||
ERROR_VARIABLE stderr)
|
||||
if(NOT retcode EQUAL 0)
|
||||
if(NOT ARGS_NOTFATAL)
|
||||
message(FATAL_ERROR "dumpbin failed.")
|
||||
else()
|
||||
set(${DEST} "${DEST}-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
string(REGEX MATCH "DLL name[ ]+:[ ]+([^\n]+)\n" match "${stdout}")
|
||||
if(NOT match)
|
||||
if(NOT ARGS_NOTFATAL)
|
||||
message(FATAL_ERROR "dumpbin did not find any associated dll for ${IMPLIB}.")
|
||||
else()
|
||||
set(${DEST} "${DEST}-NOTFOUND" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
set(result "${CMAKE_MATCH_1}")
|
||||
set(${DEST} "${result}" PARENT_SCOPE)
|
||||
else()
|
||||
message(FATAL_ERROR "Cannot find dumpbin, please set CMAKE_DUMPBIN cmake variable")
|
||||
endif()
|
||||
else()
|
||||
if(NOT ARGS_NOTFATAL)
|
||||
message(FATAL_ERROR "Don't know how to identify dll from import library. Set CMAKE_DLLTOOL (for mingw) or CMAKE_DUMPBIN (for MSVC)")
|
||||
else()
|
||||
set(${DEST} "${DEST}-NOTFOUND")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(get_actual_target)
|
||||
set(dst "${ARGV0}")
|
||||
set(target "${${dst}}")
|
||||
set(input "${target}")
|
||||
get_target_property(alias "${target}" ALIASED_TARGET)
|
||||
while(alias)
|
||||
set(target "${alias}")
|
||||
get_target_property(alias "${target}" ALIASED_TARGET)
|
||||
endwhile()
|
||||
message(DEBUG "get_actual_target(\"${input}\") -> \"${target}\"")
|
||||
set("${dst}" "${target}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(target_get_dynamic_library DEST TARGET)
|
||||
set(result)
|
||||
if(DEFINED ${DEST})
|
||||
if(NOT EXISTS "${${DEST}}")
|
||||
message(FATAL_ERROR "${DEST}=${${DEST}} does not exist")
|
||||
endif()
|
||||
get_filename_component(filename ${${DEST}} NAME)
|
||||
set(${DEST} ${filename} PARENT_SCOPE)
|
||||
else()
|
||||
get_actual_target(TARGET)
|
||||
if(WIN32)
|
||||
# Use the target dll of the import library
|
||||
set(props_to_check IMPORTED_IMPLIB)
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
list(APPEND props_to_check IMPORTED_IMPLIB_${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
list(APPEND props_to_check IMPORTED_LOCATION)
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
list(APPEND props_to_check IMPORTED_LOCATION_${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
foreach (config_type ${CMAKE_CONFIGURATION_TYPES} RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
|
||||
list(APPEND props_to_check IMPORTED_IMPLIB_${config_type})
|
||||
list(APPEND props_to_check IMPORTED_LOCATION_${config_type})
|
||||
endforeach()
|
||||
|
||||
foreach(prop_to_check ${props_to_check})
|
||||
if(NOT result)
|
||||
get_target_property(propvalue "${TARGET}" ${prop_to_check})
|
||||
if(propvalue AND EXISTS "${propvalue}")
|
||||
win32_implib_identify_dll(result "${propvalue}" NOTFATAL)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
# 1. find the target library a file might be symbolic linking to
|
||||
# 2. find all other files in the same folder that symolic link to it
|
||||
# 3. sort all these files, and select the 1st item on Linux, and last on Macos
|
||||
set(location_properties IMPORTED_LOCATION)
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
list(APPEND location_properties IMPORTED_LOCATION_${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
foreach (config_type ${CMAKE_CONFIGURATION_TYPES} RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
|
||||
list(APPEND location_properties IMPORTED_LOCATION_${config_type})
|
||||
endforeach()
|
||||
if(APPLE)
|
||||
set(valid_shared_library_regex "\\.[0-9]+\\.dylib$")
|
||||
else()
|
||||
set(valid_shared_library_regex "\\.so\\.([0-9.]+)?[0-9]")
|
||||
endif()
|
||||
foreach(location_property ${location_properties})
|
||||
if(NOT result)
|
||||
get_target_property(library_path "${TARGET}" ${location_property})
|
||||
message(DEBUG "get_target_property(${TARGET} ${location_propert}) -> ${library_path}")
|
||||
if(EXISTS "${library_path}")
|
||||
get_filename_component(library_path "${library_path}" ABSOLUTE)
|
||||
while (IS_SYMLINK "${library_path}")
|
||||
read_absolute_symlink(library_path "${library_path}")
|
||||
endwhile()
|
||||
message(DEBUG "${TARGET} -> ${library_path}")
|
||||
get_filename_component(libdir "${library_path}" DIRECTORY)
|
||||
file(GLOB subfiles "${libdir}/*")
|
||||
set(similar_files "${library_path}")
|
||||
foreach(subfile ${subfiles})
|
||||
if(IS_SYMLINK "${subfile}")
|
||||
read_absolute_symlink(subfile_target "${subfile}")
|
||||
while(IS_SYMLINK "${subfile_target}")
|
||||
read_absolute_symlink(subfile_target "${subfile_target}")
|
||||
endwhile()
|
||||
get_filename_component(subfile_target "${subfile_target}" ABSOLUTE)
|
||||
if(subfile_target STREQUAL library_path AND subfile MATCHES "${valid_shared_library_regex}")
|
||||
list(APPEND similar_files "${subfile}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
list(SORT similar_files)
|
||||
message(DEBUG "files that are similar to \"${library_path}\"=${similar_files}")
|
||||
if(APPLE)
|
||||
list(REVERSE similar_files)
|
||||
endif()
|
||||
list(GET similar_files 0 item)
|
||||
get_filename_component(result "${item}" NAME)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
if(result)
|
||||
string(TOLOWER "${result}" result_lower)
|
||||
if(WIN32 OR OS2)
|
||||
if(NOT result_lower MATCHES ".*dll")
|
||||
message(FATAL_ERROR "\"${result}\" is not a .dll library")
|
||||
endif()
|
||||
elseif(APPLE)
|
||||
if(NOT result_lower MATCHES ".*dylib.*")
|
||||
message(FATAL_ERROR "\"${result}\" is not a .dylib shared library")
|
||||
endif()
|
||||
else()
|
||||
if(NOT result_lower MATCHES ".*so.*")
|
||||
message(FATAL_ERROR "\"${result}\" is not a .so shared library")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
get_target_property(target_type ${TARGET} TYPE)
|
||||
if(target_type MATCHES "SHARED_LIBRARY|MODULE_LIBRARY")
|
||||
# OK
|
||||
elseif(target_type MATCHES "STATIC_LIBRARY|OBJECT_LIBRARY|INTERFACE_LIBRARY|EXECUTABLE")
|
||||
message(SEND_ERROR "${TARGET} is not a shared library, but has type=${target_type}")
|
||||
else()
|
||||
message(WARNING "Unable to extract dynamic library from target=${TARGET}, type=${target_type}.")
|
||||
endif()
|
||||
# TARGET_SONAME_FILE is not allowed for DLL target platforms.
|
||||
if(WIN32)
|
||||
set(result "$<TARGET_FILE_NAME:${TARGET}>")
|
||||
else()
|
||||
set(result "$<TARGET_SONAME_FILE_NAME:${TARGET}>")
|
||||
endif()
|
||||
endif()
|
||||
set(${DEST} ${result} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(sdl_check_project_in_subfolder relative_subfolder name vendored_option)
|
||||
cmake_parse_arguments(ARG "" "FILE" "" ${ARGN})
|
||||
if(NOT ARG_FILE)
|
||||
set(ARG_FILE "CMakeLists.txt")
|
||||
endif()
|
||||
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/${relative_subfolder}/${ARG_FILE}")
|
||||
message(FATAL_ERROR "Could not find ${ARG_FILE} for ${name} in ${relative_subfolder}.\n"
|
||||
"Run the download script in the external folder, or re-configure with -D${vendored_option}=OFF to use system packages.")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
macro(sdl_check_linker_flag flag var)
|
||||
# FIXME: Use CheckLinkerFlag module once cmake minimum version >= 3.18
|
||||
cmake_push_check_state(RESET)
|
||||
set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}")
|
||||
check_c_source_compiles("int main() { return 0; }" ${var} FAIL_REGEX "(unsupported|syntax error|unrecognized option)")
|
||||
cmake_pop_check_state()
|
||||
endmacro()
|
||||
|
||||
function(SDL_detect_linker)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.29)
|
||||
if(NOT DEFINED SDL_CMAKE_C_COMPILER_LINKER_ID)
|
||||
execute_process(COMMAND ${CMAKE_LINKER} -v OUTPUT_VARIABLE LINKER_OUTPUT ERROR_VARIABLE LINKER_OUTPUT)
|
||||
string(REGEX REPLACE "[\r\n]" " " LINKER_OUTPUT "${LINKER_OUTPUT}")
|
||||
if(LINKER_OUTPUT MATCHES ".*Microsoft.*")
|
||||
set(linker MSVC)
|
||||
else()
|
||||
set(linker GNUlike)
|
||||
endif()
|
||||
message(STATUS "Linker identification: ${linker}")
|
||||
set(SDL_CMAKE_C_COMPILER_LINKER_ID "${linker}" CACHE STRING "Linker identification")
|
||||
mark_as_advanced(SDL_CMAKE_C_COMPILER_LINKER_ID)
|
||||
endif()
|
||||
set(CMAKE_C_COMPILER_LINKER_ID "${SDL_CMAKE_C_COMPILER_LINKER_ID}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(check_linker_support_version_script VAR)
|
||||
SDL_detect_linker()
|
||||
if(CMAKE_C_COMPILER_LINKER_ID MATCHES "^(MSVC)$")
|
||||
set(LINKER_SUPPORTS_VERSION_SCRIPT FALSE)
|
||||
else()
|
||||
cmake_push_check_state(RESET)
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.sym" "n_0 {\n global:\n func;\n local: *;\n};\n")
|
||||
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/dummy.sym")
|
||||
check_c_source_compiles("int func(void) {return 0;} int main(int argc,char*argv[]){(void)argc;(void)argv;return func();}" LINKER_SUPPORTS_VERSION_SCRIPT FAIL_REGEX "(unsupported|syntax error|unrecognized option)")
|
||||
cmake_pop_check_state()
|
||||
endif()
|
||||
set(${VAR} "${LINKER_SUPPORTS_VERSION_SCRIPT}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(sdl_target_link_options_no_undefined TARGET)
|
||||
if(NOT MSVC AND NOT CMAKE_SYSTEM_NAME MATCHES ".*OpenBSD.*")
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang")
|
||||
target_link_options(${TARGET} PRIVATE "-Wl,-undefined,error")
|
||||
else()
|
||||
sdl_check_linker_flag("-Wl,--no-undefined" HAVE_WL_NO_UNDEFINED)
|
||||
if(HAVE_WL_NO_UNDEFINED AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") AND WIN32))
|
||||
target_link_options(${TARGET} PRIVATE "-Wl,--no-undefined")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(sdl_target_link_option_version_file TARGET VERSION_SCRIPT)
|
||||
check_linker_support_version_script(HAVE_WL_VERSION_SCRIPT)
|
||||
if(HAVE_WL_VERSION_SCRIPT)
|
||||
target_link_options(${TARGET} PRIVATE "-Wl,--version-script=${VERSION_SCRIPT}")
|
||||
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${VERSION_SCRIPT}")
|
||||
else()
|
||||
if(LINUX OR ANDROID)
|
||||
message(FATAL_ERROR "Linker does not support '-Wl,--version-script=xxx.sym'. This is required on the current host platform.")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(sdl_add_warning_options TARGET)
|
||||
cmake_parse_arguments(ARGS "" "WARNING_AS_ERROR" "" ${ARGN})
|
||||
if(MSVC)
|
||||
target_compile_options(${TARGET} PRIVATE /W2)
|
||||
else()
|
||||
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
endif()
|
||||
if(ARGS_WARNING_AS_ERROR)
|
||||
if(MSVC)
|
||||
target_compile_options(${TARGET} PRIVATE /WX)
|
||||
else()
|
||||
target_compile_options(${TARGET} PRIVATE -Werror)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(sdl_no_deprecated_errors TARGET)
|
||||
check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
|
||||
if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
|
||||
target_compile_options(${TARGET} PRIVATE "-Wno-error=deprecated-declarations")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(sdl_get_git_revision_hash VARNAME)
|
||||
set("${VARNAME}" "" CACHE STRING "${PROJECT_NAME} revision")
|
||||
set(revision "${${VARNAME}}")
|
||||
if(NOT revision)
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt")
|
||||
# If VERSION.txt exists, it contains the SDL version
|
||||
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt" revision_version)
|
||||
string(STRIP "${revision_version}" revision_version)
|
||||
else()
|
||||
# If VERSION.txt does not exist, use git to calculate a version
|
||||
git_describe(revision_version)
|
||||
if(NOT revision_version)
|
||||
set(revision_version "${PROJECT_VERSION}-no-vcs")
|
||||
endif()
|
||||
endif()
|
||||
set(revision "${revision_version}")
|
||||
endif()
|
||||
set("${VARNAME}" "${revision}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(SDL_install_pdb TARGET DIRECTORY)
|
||||
get_property(type TARGET ${TARGET} PROPERTY TYPE)
|
||||
if(type MATCHES "^(SHARED_LIBRARY|EXECUTABLE)$")
|
||||
install(FILES $<TARGET_PDB_FILE:${TARGET}> DESTINATION "${DIRECTORY}" OPTIONAL)
|
||||
elseif(type STREQUAL "STATIC_LIBRARY")
|
||||
# FIXME: Use $<TARGET_COMPILE_PDB_FILE:${TARGET} once it becomes available (https://gitlab.kitware.com/cmake/cmake/-/issues/25244)
|
||||
if(CMAKE_GENERATOR MATCHES "^Visual Studio.*")
|
||||
install(CODE "file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${DIRECTORY}\" TYPE FILE OPTIONAL FILES \"${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${TARGET}.pdb\")")
|
||||
else()
|
||||
install(CODE "file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${DIRECTORY}\" TYPE FILE OPTIONAL FILES \"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET}.dir/${TARGET}.pdb\")")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
76
thirdparty/SDL_shadercross/cmake/SDL3_shadercrossConfig.cmake.in
vendored
Normal file
76
thirdparty/SDL_shadercross/cmake/SDL3_shadercrossConfig.cmake.in
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# sdl3_shadercross cmake project-config input for CMakeLists.txt script
|
||||
|
||||
include(FeatureSummary)
|
||||
set_package_properties(SDL3_shadercross PROPERTIES
|
||||
URL "https://github.com/libsdl-org/SDL_shadercross/"
|
||||
DESCRIPTION "Support SPIR-V and HLSL on various backends"
|
||||
)
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set(SDLSHADERCROSS_VENDORED @SDLSHADERCROSS_VENDORED@)
|
||||
set(SDLSHADERCROSS_SPIRVCROSS_SHARED @SDLSHADERCROSS_SPIRVCROSS_SHARED@)
|
||||
|
||||
set(SDL3_shadercross_FOUND ON)
|
||||
|
||||
set(SDL3_gpu_SHADERCROSS_REQUIRED_VERSION @SDL_REQUIRED_VERSION@)
|
||||
|
||||
if(SDLSHADERCROSS_VENDORED)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SDL3_shadercross-vendored-targets.cmake")
|
||||
endif()
|
||||
|
||||
set(SDL3_shadercross_SDL3_shadercross-shared_FOUND FALSE)
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_shadercross-shared-targets.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SDL3_shadercross-shared-targets.cmake")
|
||||
set(SDL3_shadercross_SDL3_shadercross-shared_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
set(SDL3_shadercross_SDL3_shadercross-static FALSE)
|
||||
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_shadercross-static-targets.cmake")
|
||||
if(NOT SDLSHADERCROSS_VENDORED)
|
||||
set(original_cmake_module_path "${CMAKE_MODULE_PATH}")
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
if(SDLSHADERCROSS_SPIRVCROSS_SHARED)
|
||||
find_dependency(spirv_cross_c_shared REQUIRED)
|
||||
else()
|
||||
find_package(spirv_cross_core QUIET)
|
||||
find_package(spirv_cross_glsl QUIET)
|
||||
find_package(spirv_cross_hlsl QUIET)
|
||||
find_package(spirv_cross_msl QUIET)
|
||||
find_package(spirv_cross_cpp QUIET)
|
||||
find_package(spirv_cross_reflect QUIET)
|
||||
find_package(spirv_cross_c)
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/sdlcpu.cmake")
|
||||
SDL_DetectTargetCPUArchitectures(SDL_CPU_NAMES)
|
||||
find_dependency(DirectXShaderCompiler)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${original_cmake_module_path}")
|
||||
endif()
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/SDL3_shadercross-static-targets.cmake")
|
||||
set(SDL3_shadercross_SDL3_shadercross-static_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
|
||||
if(CMAKE_VERSION VERSION_LESS "3.18")
|
||||
# Aliasing local targets is not supported on CMake < 3.18, so make it global.
|
||||
add_library(${NEW_TARGET} INTERFACE IMPORTED)
|
||||
set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
|
||||
else()
|
||||
add_library(${NEW_TARGET} ALIAS ${TARGET})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Make sure SDL3_shadercross::SDL3_shadercross always exists
|
||||
if(NOT TARGET SDL3_shadercross::SDL3_shadercross)
|
||||
if(TARGET SDL3_shadercross::SDL3_shadercross-shared)
|
||||
_sdl_create_target_alias_compat(SDL3_shadercross::SDL3_shadercross SDL3_shadercross::SDL3_shadercross-shared)
|
||||
elseif(TARGET SDL3_shadercross::SDL3_shadercross-static)
|
||||
_sdl_create_target_alias_compat(SDL3_shadercross::SDL3_shadercross SDL3_shadercross::SDL3_shadercross-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
check_required_components(SDL3_shadercross)
|
||||
13
thirdparty/SDL_shadercross/cmake/sdl3-shadercross.pc.in
vendored
Normal file
13
thirdparty/SDL_shadercross/cmake/sdl3-shadercross.pc.in
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
prefix=@SDL_PKGCONFIG_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=@LIBDIR_FOR_PKG_CONFIG@
|
||||
includedir=@INCLUDEDIR_FOR_PKG_CONFIG@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: Support SPIR-V and HLSL on various backends
|
||||
Version: @PROJECT_VERSION@
|
||||
Requires: sdl3 >= @SDL_REQUIRED_VERSION@
|
||||
Libs: -L${libdir} -lSDL3_shadercross
|
||||
Requires.private: @PC_REQUIRES@
|
||||
Libs.private: @PC_LIBS@
|
||||
Cflags: -I${includedir}
|
||||
158
thirdparty/SDL_shadercross/cmake/sdlcpu.cmake
vendored
Normal file
158
thirdparty/SDL_shadercross/cmake/sdlcpu.cmake
vendored
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
function(SDL_DetectTargetCPUArchitectures DETECTED_ARCHS)
|
||||
|
||||
set(known_archs EMSCRIPTEN ARM32 ARM64 ARM64EC LOONGARCH64 POWERPC32 POWERPC64 RISCV32 RISCV64 X86 X64)
|
||||
|
||||
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
|
||||
foreach(known_arch IN LISTS known_archs)
|
||||
set(SDL_CPU_${known_arch} "0" PARENT_SCOPE)
|
||||
endforeach()
|
||||
set(detected_archs)
|
||||
foreach(osx_arch IN LISTS CMAKE_OSX_ARCHITECTURES)
|
||||
if(osx_arch STREQUAL "x86_64")
|
||||
set(SDL_CPU_X64 "1" PARENT_SCOPE)
|
||||
list(APPEND detected_archs "X64")
|
||||
elseif(osx_arch STREQUAL "arm64")
|
||||
set(SDL_CPU_ARM64 "1" PARENT_SCOPE)
|
||||
list(APPEND detected_archs "ARM64")
|
||||
endif()
|
||||
endforeach()
|
||||
set("${DETECTED_ARCHS}" "${detected_archs}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(detected_archs)
|
||||
foreach(known_arch IN LISTS known_archs)
|
||||
if(SDL_CPU_${known_arch})
|
||||
list(APPEND detected_archs "${known_arch}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(detected_archs)
|
||||
set("${DETECTED_ARCHS}" "${detected_archs}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(arch_check_ARM32 "defined(__arm__) || defined(_M_ARM)")
|
||||
set(arch_check_ARM64 "defined(__aarch64__) || defined(_M_ARM64)")
|
||||
set(arch_check_ARM64EC "defined(_M_ARM64EC)")
|
||||
set(arch_check_EMSCRIPTEN "defined(__EMSCRIPTEN__)")
|
||||
set(arch_check_LOONGARCH64 "defined(__loongarch64)")
|
||||
set(arch_check_POWERPC32 "(defined(__PPC__) || defined(__powerpc__)) && !defined(__powerpc64__)")
|
||||
set(arch_check_POWERPC64 "defined(__PPC64__) || defined(__powerpc64__)")
|
||||
set(arch_check_RISCV32 "defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 32")
|
||||
set(arch_check_RISCV64 "defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64")
|
||||
set(arch_check_X86 "defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)")
|
||||
set(arch_check_X64 "(defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)) && !defined(_M_ARM64EC)")
|
||||
|
||||
set(src_vars "")
|
||||
set(src_main "")
|
||||
foreach(known_arch IN LISTS known_archs)
|
||||
set(detected_${known_arch} "0")
|
||||
|
||||
string(APPEND src_vars "
|
||||
#if ${arch_check_${known_arch}}
|
||||
#define ARCH_${known_arch} \"1\"
|
||||
#else
|
||||
#define ARCH_${known_arch} \"0\"
|
||||
#endif
|
||||
const char *arch_${known_arch} = \"INFO<${known_arch}=\" ARCH_${known_arch} \">\";
|
||||
")
|
||||
string(APPEND src_main "
|
||||
result += arch_${known_arch}[argc];")
|
||||
endforeach()
|
||||
|
||||
set(src_arch_detect "${src_vars}
|
||||
int main(int argc, char *argv[]) {
|
||||
int result = 0;
|
||||
(void)argv;
|
||||
${src_main}
|
||||
return result;
|
||||
}")
|
||||
|
||||
if(CMAKE_C_COMPILER)
|
||||
set(ext ".c")
|
||||
elseif(CMAKE_CXX_COMPILER)
|
||||
set(ext ".cpp")
|
||||
else()
|
||||
enable_language(C)
|
||||
set(ext ".c")
|
||||
endif()
|
||||
set(path_src_arch_detect "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/SDL_detect_arch${ext}")
|
||||
file(WRITE "${path_src_arch_detect}" "${src_arch_detect}")
|
||||
set(path_dir_arch_detect "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/SDL_detect_arch")
|
||||
set(path_bin_arch_detect "${path_dir_arch_detect}/bin")
|
||||
|
||||
set(detected_archs)
|
||||
|
||||
set(msg "Detecting Target CPU Architecture")
|
||||
message(STATUS "${msg}")
|
||||
|
||||
include(CMakePushCheckState)
|
||||
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
|
||||
|
||||
cmake_push_check_state(RESET)
|
||||
try_compile(SDL_CPU_CHECK_ALL
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp/SDL_detect_arch"
|
||||
SOURCES "${path_src_arch_detect}"
|
||||
COPY_FILE "${path_bin_arch_detect}"
|
||||
)
|
||||
cmake_pop_check_state()
|
||||
if(NOT SDL_CPU_CHECK_ALL)
|
||||
message(STATUS "${msg} - <ERROR>")
|
||||
message(WARNING "Failed to compile source detecting the target CPU architecture")
|
||||
else()
|
||||
set(re "INFO<([A-Z0-9]+)=([01])>")
|
||||
file(STRINGS "${path_bin_arch_detect}" infos REGEX "${re}")
|
||||
|
||||
foreach(info_arch_01 IN LISTS infos)
|
||||
string(REGEX MATCH "${re}" A "${info_arch_01}")
|
||||
if(NOT "${CMAKE_MATCH_1}" IN_LIST known_archs)
|
||||
message(WARNING "Unknown architecture: \"${CMAKE_MATCH_1}\"")
|
||||
continue()
|
||||
endif()
|
||||
set(arch "${CMAKE_MATCH_1}")
|
||||
set(arch_01 "${CMAKE_MATCH_2}")
|
||||
set(detected_${arch} "${arch_01}")
|
||||
endforeach()
|
||||
|
||||
foreach(known_arch IN LISTS known_archs)
|
||||
if(detected_${known_arch})
|
||||
list(APPEND detected_archs ${known_arch})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(detected_archs)
|
||||
foreach(known_arch IN LISTS known_archs)
|
||||
set("SDL_CPU_${known_arch}" "${detected_${known_arch}}" CACHE BOOL "Detected architecture ${known_arch}")
|
||||
endforeach()
|
||||
message(STATUS "${msg} - ${detected_archs}")
|
||||
else()
|
||||
include(CheckCSourceCompiles)
|
||||
cmake_push_check_state(RESET)
|
||||
foreach(known_arch IN LISTS known_archs)
|
||||
if(NOT detected_archs)
|
||||
set(cache_variable "SDL_CPU_${known_arch}")
|
||||
set(test_src "
|
||||
int main(int argc, char *argv[]) {
|
||||
#if ${arch_check_${known_arch}}
|
||||
return 0;
|
||||
#else
|
||||
choke
|
||||
#endif
|
||||
}
|
||||
")
|
||||
check_c_source_compiles("${test_src}" "${cache_variable}")
|
||||
if(${cache_variable})
|
||||
set(SDL_CPU_${known_arch} "1" CACHE BOOL "Detected architecture ${known_arch}")
|
||||
set(detected_archs ${known_arch})
|
||||
else()
|
||||
set(SDL_CPU_${known_arch} "0" CACHE BOOL "Detected architecture ${known_arch}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
cmake_pop_check_state()
|
||||
endif()
|
||||
set("${DETECTED_ARCHS}" "${detected_archs}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
68
thirdparty/SDL_shadercross/cmake/sdlmanpages.cmake
vendored
Normal file
68
thirdparty/SDL_shadercross/cmake/sdlmanpages.cmake
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
include(CMakeParseArguments)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
function(SDL_generate_manpages)
|
||||
cmake_parse_arguments(ARG "" "RESULT_VARIABLE;NAME;BUILD_DOCDIR;HEADERS_DIR;SOURCE_DIR;SYMBOL;OPTION_FILE;WIKIHEADERS_PL_PATH;REVISION" "" ${ARGN})
|
||||
|
||||
set(wikiheaders_extra_args)
|
||||
|
||||
if(NOT ARG_NAME)
|
||||
set(ARG_NAME "${PROJECT_NAME}")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_SOURCE_DIR)
|
||||
set(ARG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_OPTION_FILE)
|
||||
set(ARG_OPTION_FILE "${PROJECT_SOURCE_DIR}/.wikiheaders-options")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_HEADERS_DIR)
|
||||
message(FATAL_ERROR "Missing required HEADERS_DIR argument")
|
||||
endif()
|
||||
|
||||
# FIXME: get rid of SYMBOL and let the perl script figure out the dependencies
|
||||
if(NOT ARG_SYMBOL)
|
||||
message(FATAL_ERROR "Missing required SYMBOL argument")
|
||||
endif()
|
||||
|
||||
if(ARG_REVISION)
|
||||
list(APPEND wikiheaders_extra_args "--rev=${ARG_REVISION}")
|
||||
endif()
|
||||
|
||||
if(NOT ARG_BUILD_DOCDIR)
|
||||
set(ARG_BUILD_DOCDIR "${CMAKE_CURRENT_BINARY_DIR}/docs")
|
||||
endif()
|
||||
set(BUILD_WIKIDIR "${ARG_BUILD_DOCDIR}/wiki")
|
||||
set(BUILD_MANDIR "${ARG_BUILD_DOCDIR}/man")
|
||||
|
||||
find_package(Perl)
|
||||
file(GLOB HEADER_FILES "${ARG_HEADERS_DIR}/*.h")
|
||||
|
||||
set(result FALSE)
|
||||
|
||||
if(PERL_FOUND AND EXISTS "${ARG_WIKIHEADERS_PL_PATH}")
|
||||
add_custom_command(
|
||||
OUTPUT "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md"
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${BUILD_WIKIDIR}"
|
||||
COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" --copy-to-wiki ${wikiheaders_extra_args}
|
||||
DEPENDS ${HEADER_FILES} "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
|
||||
COMMENT "Generating ${ARG_NAME} wiki markdown files"
|
||||
)
|
||||
add_custom_command(
|
||||
OUTPUT "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3"
|
||||
COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" "--manpath=${BUILD_MANDIR}" --copy-to-manpages ${wikiheaders_extra_args}
|
||||
DEPENDS "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
|
||||
COMMENT "Generating ${ARG_NAME} man pages"
|
||||
)
|
||||
add_custom_target(${ARG_NAME}-docs ALL DEPENDS "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3")
|
||||
|
||||
install(DIRECTORY "${BUILD_MANDIR}/" DESTINATION "${CMAKE_INSTALL_MANDIR}")
|
||||
set(result TRUE)
|
||||
endif()
|
||||
|
||||
if(ARG_RESULT_VARIABLE)
|
||||
set(${ARG_RESULT_VARIABLE} ${result} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
106
thirdparty/SDL_shadercross/cmake/sdlplatform.cmake
vendored
Normal file
106
thirdparty/SDL_shadercross/cmake/sdlplatform.cmake
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
macro(SDL_DetectCMakePlatform)
|
||||
set(SDL_CMAKE_PLATFORM )
|
||||
# Get the platform
|
||||
if(WIN32)
|
||||
set(SDL_CMAKE_PLATFORM Windows)
|
||||
elseif(PSP)
|
||||
set(SDL_CMAKE_PLATFORM psp)
|
||||
elseif(APPLE)
|
||||
if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
|
||||
set(SDL_CMAKE_PLATFORM Darwin)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
|
||||
set(SDL_CMAKE_PLATFORM MacosX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
|
||||
set(SDL_CMAKE_PLATFORM tvOS)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*")
|
||||
set(SDL_CMAKE_PLATFORM iOS)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
|
||||
set(SDL_CMAKE_PLATFORM Haiku)
|
||||
elseif(NINTENDO_3DS)
|
||||
set(SDL_CMAKE_PLATFORM n3ds)
|
||||
elseif(PS2)
|
||||
set(SDL_CMAKE_PLATFORM ps2)
|
||||
elseif(VITA)
|
||||
set(SDL_CMAKE_PLATFORM Vita)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
|
||||
set(SDL_CMAKE_PLATFORM Linux)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
|
||||
set(SDL_CMAKE_PLATFORM FreeBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
|
||||
set(SDL_CMAKE_PLATFORM NetBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
|
||||
set(SDL_CMAKE_PLATFORM OpenBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
|
||||
set(SDL_CMAKE_PLATFORM GNU)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
|
||||
set(SDL_CMAKE_PLATFORM BSDi)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
|
||||
set(SDL_CMAKE_PLATFORM FreeBSD)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
|
||||
set(SDL_CMAKE_PLATFORM SYSV5)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*|SunOS.*")
|
||||
set(SDL_CMAKE_PLATFORM Solaris)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
|
||||
set(SDL_CMAKE_PLATFORM HPUX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
|
||||
set(SDL_CMAKE_PLATFORM AIX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
|
||||
set(SDL_CMAKE_PLATFORM Minix)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Android.*")
|
||||
set(SDL_CMAKE_PLATFORM Android)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten.*")
|
||||
set(SDL_CMAKE_PLATFORM Emscripten)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "QNX.*")
|
||||
set(SDL_CMAKE_PLATFORM QNX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
|
||||
message(FATAL_ERROR "BeOS support has been removed as of SDL 2.0.2.")
|
||||
endif()
|
||||
|
||||
if(SDL_CMAKE_PLATFORM)
|
||||
string(TOUPPER "${SDL_CMAKE_PLATFORM}" _upper_platform)
|
||||
set(${_upper_platform} TRUE)
|
||||
else()
|
||||
set(SDL_CMAKE_PLATFORM} "unknown")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(SDL_DetectCPUArchitecture)
|
||||
set(sdl_cpu_names)
|
||||
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
|
||||
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
|
||||
if(osx_arch STREQUAL "x86_64")
|
||||
list(APPEND sdl_cpu_names "x64")
|
||||
elseif(osx_arch STREQUAL "arm64")
|
||||
list(APPEND sdl_cpu_names "arm64")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(sdl_known_archs x64 x86 arm64 arm32 emscripten powerpc64 powerpc32 loongarch64)
|
||||
if(NOT sdl_cpu_names)
|
||||
set(found FALSE)
|
||||
foreach(sdl_known_arch ${sdl_known_archs})
|
||||
if(NOT found)
|
||||
string(TOUPPER "${sdl_known_arch}" sdl_known_arch_upper)
|
||||
set(var_name "SDL_CPU_${sdl_known_arch_upper}")
|
||||
check_cpu_architecture(${sdl_known_arch} ${var_name})
|
||||
if(${var_name})
|
||||
list(APPEND sdl_cpu_names ${sdl_known_arch})
|
||||
set(found TRUE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
foreach(sdl_known_arch ${sdl_known_archs})
|
||||
string(TOUPPER "${sdl_known_arch}" sdl_known_arch_upper)
|
||||
set(var_name "SDL_CPU_${sdl_known_arch_upper}")
|
||||
if(sdl_cpu_names MATCHES "(^|;)${sdl_known_arch}($|;)") # FIXME: use if(IN_LIST)
|
||||
set(${var_name} 1 PARENT_SCOPE)
|
||||
else()
|
||||
set(${var_name} 0 PARENT_SCOPE)
|
||||
endif()
|
||||
endforeach()
|
||||
set(SDL_CPU_NAMES ${sdl_cpu_names} PARENT_SCOPE)
|
||||
endfunction()
|
||||
356
thirdparty/SDL_shadercross/include/SDL3_shadercross/SDL_shadercross.h
vendored
Normal file
356
thirdparty/SDL_shadercross/include/SDL3_shadercross/SDL_shadercross.h
vendored
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
/*
|
||||
Simple DirectMedia Layer Shader Cross Compiler
|
||||
Copyright (C) 2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_SHADERCROSS_H
|
||||
#define SDL_SHADERCROSS_H
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_begin_code.h>
|
||||
#include <SDL3/SDL_gpu.h>
|
||||
|
||||
/* Set up for C function definitions, even when using C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
|
||||
*/
|
||||
#define SDL_SHADERCROSS_MAJOR_VERSION 3
|
||||
#define SDL_SHADERCROSS_MINOR_VERSION 0
|
||||
#define SDL_SHADERCROSS_MICRO_VERSION 0
|
||||
|
||||
typedef enum SDL_ShaderCross_IOVarType {
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_UNKNOWN,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_INT8,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_UINT8,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_INT16,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_UINT16,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_INT32,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_UINT32,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_INT64,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_UINT64,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_FLOAT16,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_FLOAT32,
|
||||
SDL_SHADERCROSS_IOVAR_TYPE_FLOAT64
|
||||
} SDL_ShaderCross_IOVarType;
|
||||
|
||||
typedef enum SDL_ShaderCross_ShaderStage
|
||||
{
|
||||
SDL_SHADERCROSS_SHADERSTAGE_VERTEX,
|
||||
SDL_SHADERCROSS_SHADERSTAGE_FRAGMENT,
|
||||
SDL_SHADERCROSS_SHADERSTAGE_COMPUTE
|
||||
} SDL_ShaderCross_ShaderStage;
|
||||
|
||||
typedef struct SDL_ShaderCross_IOVarMetadata {
|
||||
char *name; /**< The UTF-8 name of the variable. */
|
||||
Uint32 location; /**< The location of the variable. */
|
||||
SDL_ShaderCross_IOVarType vector_type; /**< The vector type of the variable. */
|
||||
Uint32 vector_size; /**< The number of components in the vector type of the variable. */
|
||||
} SDL_ShaderCross_IOVarMetadata;
|
||||
|
||||
typedef struct SDL_ShaderCross_GraphicsShaderResourceInfo
|
||||
{
|
||||
Uint32 num_samplers; /**< The number of samplers defined in the shader. */
|
||||
Uint32 num_storage_textures; /**< The number of storage textures defined in the shader. */
|
||||
Uint32 num_storage_buffers; /**< The number of storage buffers defined in the shader. */
|
||||
Uint32 num_uniform_buffers; /**< The number of uniform buffers defined in the shader. */
|
||||
} SDL_ShaderCross_GraphicsShaderResourceInfo;
|
||||
|
||||
typedef struct SDL_ShaderCross_GraphicsShaderMetadata
|
||||
{
|
||||
SDL_ShaderCross_GraphicsShaderResourceInfo resource_info; /**< Sub-struct containing the resource info of the shader. */
|
||||
Uint32 num_inputs; /**< The number of inputs defined in the shader. */
|
||||
SDL_ShaderCross_IOVarMetadata *inputs; /**< The inputs defined in the shader. */
|
||||
Uint32 num_outputs; /**< The number of outputs defined in the shader. */
|
||||
SDL_ShaderCross_IOVarMetadata *outputs; /**< The outputs defined in the shader. */
|
||||
} SDL_ShaderCross_GraphicsShaderMetadata;
|
||||
|
||||
typedef struct SDL_ShaderCross_ComputePipelineMetadata
|
||||
{
|
||||
Uint32 num_samplers; /**< The number of samplers defined in the shader. */
|
||||
Uint32 num_readonly_storage_textures; /**< The number of readonly storage textures defined in the shader. */
|
||||
Uint32 num_readonly_storage_buffers; /**< The number of readonly storage buffers defined in the shader. */
|
||||
Uint32 num_readwrite_storage_textures; /**< The number of read-write storage textures defined in the shader. */
|
||||
Uint32 num_readwrite_storage_buffers; /**< The number of read-write storage buffers defined in the shader. */
|
||||
Uint32 num_uniform_buffers; /**< The number of uniform buffers defined in the shader. */
|
||||
Uint32 threadcount_x; /**< The number of threads in the X dimension. */
|
||||
Uint32 threadcount_y; /**< The number of threads in the Y dimension. */
|
||||
Uint32 threadcount_z; /**< The number of threads in the Z dimension. */
|
||||
} SDL_ShaderCross_ComputePipelineMetadata;
|
||||
|
||||
typedef struct SDL_ShaderCross_SPIRV_Info
|
||||
{
|
||||
const Uint8 *bytecode; /**< The SPIRV bytecode. */
|
||||
size_t bytecode_size; /**< The length of the SPIRV bytecode. */
|
||||
const char *entrypoint; /**< The entry point function name for the shader in UTF-8. */
|
||||
SDL_ShaderCross_ShaderStage shader_stage; /**< The shader stage to transpile the shader with. */
|
||||
|
||||
SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
|
||||
} SDL_ShaderCross_SPIRV_Info;
|
||||
|
||||
#define SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN "SDL_shadercross.spirv.debug.enable"
|
||||
#define SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING "SDL_shadercross.spirv.debug.name"
|
||||
#define SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN "SDL_shadercross.spirv.cull_unused_bindings"
|
||||
|
||||
#define SDL_SHADERCROSS_PROP_SPIRV_PSSL_COMPATIBILITY_BOOLEAN "SDL_shadercross.spirv.pssl.compatibility"
|
||||
#define SDL_SHADERCROSS_PROP_SPIRV_MSL_VERSION_STRING "SDL_shadercross.spirv.msl.version"
|
||||
#define SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN "SDL_shadercross.hlsl.skip_spirv_roundtrip"
|
||||
|
||||
typedef struct SDL_ShaderCross_HLSL_Define
|
||||
{
|
||||
char *name; /**< The define name. */
|
||||
char *value; /**< An optional value for the define. Can be NULL. */
|
||||
} SDL_ShaderCross_HLSL_Define;
|
||||
|
||||
typedef struct SDL_ShaderCross_HLSL_Info
|
||||
{
|
||||
const char *source; /**< The HLSL source code for the shader. */
|
||||
const char *entrypoint; /**< The entry point function name for the shader in UTF-8. */
|
||||
const char *include_dir; /**< The include directory for shader code. Optional, can be NULL. */
|
||||
SDL_ShaderCross_HLSL_Define *defines; /**< An array of defines. Optional, can be NULL. If not NULL, must be terminated with a fully NULL define struct. */
|
||||
SDL_ShaderCross_ShaderStage shader_stage; /**< The shader stage to compile the shader with. */
|
||||
|
||||
SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
|
||||
} SDL_ShaderCross_HLSL_Info;
|
||||
|
||||
/**
|
||||
* Initializes SDL_shadercross
|
||||
*
|
||||
* \threadsafety This should only be called once, from a single thread.
|
||||
* \returns true on success, false otherwise.
|
||||
*/
|
||||
extern SDL_DECLSPEC bool SDLCALL SDL_ShaderCross_Init(void);
|
||||
/**
|
||||
* De-initializes SDL_shadercross
|
||||
*
|
||||
* \threadsafety This should only be called once, from a single thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC void SDLCALL SDL_ShaderCross_Quit(void);
|
||||
|
||||
/**
|
||||
* Get the supported shader formats that SPIRV cross-compilation can output
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
* \returns GPU shader formats supported by SPIRV cross-compilation.
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_ShaderCross_GetSPIRVShaderFormats(void);
|
||||
|
||||
/**
|
||||
* Transpile to MSL code from SPIRV code.
|
||||
*
|
||||
* You must SDL_free the returned string once you are done with it.
|
||||
*
|
||||
* These are the optional properties that can be used:
|
||||
*
|
||||
* - `SDL_SHADERCROSS_PROP_SPIRV_MSL_VERSION_STRING`: specifies the MSL version that should be emitted. Defaults to 1.2.0.
|
||||
*
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \returns an SDL_malloc'd string containing MSL code.
|
||||
*/
|
||||
extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_TranspileMSLFromSPIRV(
|
||||
const SDL_ShaderCross_SPIRV_Info *info);
|
||||
|
||||
/**
|
||||
* Transpile to HLSL code from SPIRV code.
|
||||
*
|
||||
* You must SDL_free the returned string once you are done with it.
|
||||
*
|
||||
* These are the optional properties that can be used:
|
||||
*
|
||||
* - `SDL_SHADERCROSS_PROP_SPIRV_PSSL_COMPATIBILITY_BOOLEAN`: generates PSSL-compatible shader.
|
||||
*
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \returns an SDL_malloc'd string containing HLSL code.
|
||||
*/
|
||||
extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_TranspileHLSLFromSPIRV(
|
||||
const SDL_ShaderCross_SPIRV_Info *info);
|
||||
|
||||
/**
|
||||
* Compile DXBC bytecode from SPIRV code.
|
||||
*
|
||||
* You must SDL_free the returned buffer once you are done with it.
|
||||
*
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \param size filled in with the bytecode buffer size.
|
||||
* \returns an SDL_malloc'd buffer containing DXBC bytecode.
|
||||
*/
|
||||
extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXBCFromSPIRV(
|
||||
const SDL_ShaderCross_SPIRV_Info *info,
|
||||
size_t *size);
|
||||
|
||||
/**
|
||||
* Compile DXIL bytecode from SPIRV code.
|
||||
*
|
||||
* You must SDL_free the returned buffer once you are done with it.
|
||||
*
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \param size filled in with the bytecode buffer size.
|
||||
* \returns an SDL_malloc'd buffer containing DXIL bytecode.
|
||||
*/
|
||||
extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXILFromSPIRV(
|
||||
const SDL_ShaderCross_SPIRV_Info *info,
|
||||
size_t *size);
|
||||
|
||||
/**
|
||||
* Compile an SDL GPU shader from SPIRV code. If your shader source is HLSL, you should obtain SPIR-V bytecode from SDL_ShaderCross_CompileSPIRVFromHLSL().
|
||||
*
|
||||
* \param device the SDL GPU device.
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \param resource_info a struct describing resource info of the shader. Can be obtained from SDL_ShaderCross_ReflectGraphicsSPIRV().
|
||||
* \param props a properties object filled in with extra shader metadata.
|
||||
* \returns a compiled SDL_GPUShader.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_GPUShader * SDLCALL SDL_ShaderCross_CompileGraphicsShaderFromSPIRV(
|
||||
SDL_GPUDevice *device,
|
||||
const SDL_ShaderCross_SPIRV_Info *info,
|
||||
const SDL_ShaderCross_GraphicsShaderResourceInfo *resource_info,
|
||||
SDL_PropertiesID props);
|
||||
|
||||
/**
|
||||
* Compile an SDL GPU compute pipeline from SPIRV code. If your shader source is HLSL, you should obtain SPIR-V bytecode from SDL_ShaderCross_CompileSPIRVFromHLSL().
|
||||
*
|
||||
* \param device the SDL GPU device.
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \param metadata a struct describing shader metadata. Can be obtained from SDL_ShaderCross_ReflectComputeSPIRV().
|
||||
* \param props a properties object filled in with extra shader metadata.
|
||||
* \returns a compiled SDL_GPUComputePipeline.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_GPUComputePipeline * SDLCALL SDL_ShaderCross_CompileComputePipelineFromSPIRV(
|
||||
SDL_GPUDevice *device,
|
||||
const SDL_ShaderCross_SPIRV_Info *info,
|
||||
const SDL_ShaderCross_ComputePipelineMetadata *metadata,
|
||||
SDL_PropertiesID props);
|
||||
|
||||
/**
|
||||
* Reflect graphics shader info from SPIRV code. If your shader source is HLSL, you should obtain SPIR-V bytecode from SDL_ShaderCross_CompileSPIRVFromHLSL(). This must be freed with SDL_free() when you are done with the metadata.
|
||||
*
|
||||
* \param bytecode the SPIRV bytecode.
|
||||
* \param bytecode_size the length of the SPIRV bytecode.
|
||||
* \param props a properties object filled in with extra shader metadata, provided by the user.
|
||||
* \returns A metadata struct on success, NULL otherwise. The struct must be free'd when it is no longer needed.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_ShaderCross_GraphicsShaderMetadata * SDLCALL SDL_ShaderCross_ReflectGraphicsSPIRV(
|
||||
const Uint8 *bytecode,
|
||||
size_t bytecode_size,
|
||||
SDL_PropertiesID props);
|
||||
|
||||
/**
|
||||
* Reflect compute pipeline info from SPIRV code. If your shader source is HLSL, you should obtain SPIR-V bytecode from SDL_ShaderCross_CompileSPIRVFromHLSL(). This must be freed with SDL_free() when you are done with the metadata.
|
||||
*
|
||||
* \param bytecode the SPIRV bytecode.
|
||||
* \param bytecode_size the length of the SPIRV bytecode.
|
||||
* \param props a properties object filled in with extra shader metadata, provided by the user.
|
||||
* \returns A metadata struct on success, NULL otherwise.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_ShaderCross_ComputePipelineMetadata * SDLCALL SDL_ShaderCross_ReflectComputeSPIRV(
|
||||
const Uint8 *bytecode,
|
||||
size_t bytecode_size,
|
||||
SDL_PropertiesID props);
|
||||
|
||||
/**
|
||||
* Get the supported shader formats that HLSL cross-compilation can output
|
||||
*
|
||||
* \returns GPU shader formats supported by HLSL cross-compilation.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_ShaderCross_GetHLSLShaderFormats(void);
|
||||
|
||||
/**
|
||||
* Compile to DXBC bytecode from HLSL code via a SPIRV-Cross round trip.
|
||||
*
|
||||
* You must SDL_free the returned buffer once you are done with it.
|
||||
*
|
||||
* These are the optional properties that can be used:
|
||||
*
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN`: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING`: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN`: When true, indicates that the compiler should cull unused shader resources. This behavior is disabled by default.
|
||||
* - `SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN`: When true, the SPIRV roundtrip is skipped. This behavior is disabled by default. Do not use this property if your shader uses Structured Buffers.
|
||||
*
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \param size filled in with the bytecode buffer size.
|
||||
* \returns an SDL_malloc'd buffer containing DXBC bytecode.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXBCFromHLSL(
|
||||
const SDL_ShaderCross_HLSL_Info *info,
|
||||
size_t *size);
|
||||
|
||||
/**
|
||||
* Compile to DXIL bytecode from HLSL code via a SPIRV-Cross round trip.
|
||||
*
|
||||
* You must SDL_free the returned buffer once you are done with it.
|
||||
*
|
||||
* These are the optional properties that can be used:
|
||||
*
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN`: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING`: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN`: when true, indicates that the compiler should cull unused shader resources. This behavior is disabled by default.
|
||||
* - `SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN`: when true, the SPIRV roundtrip is skipped. This behavior is disabled by default. Do not use this property if your shader uses Structured Buffers.
|
||||
*
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \param size filled in with the bytecode buffer size.
|
||||
* \returns an SDL_malloc'd buffer containing DXIL bytecode.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXILFromHLSL(
|
||||
const SDL_ShaderCross_HLSL_Info *info,
|
||||
size_t *size);
|
||||
|
||||
/**
|
||||
* Compile to SPIRV bytecode from HLSL code.
|
||||
*
|
||||
* You must SDL_free the returned buffer once you are done with it.
|
||||
*
|
||||
* These are the optional properties that can be used:
|
||||
*
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN`: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING`: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
|
||||
* - `SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN`: when true, indicates that the compiler should cull unused shader resources. This behavior is disabled by default.
|
||||
*
|
||||
* \param info a struct describing the shader to transpile.
|
||||
* \param size filled in with the bytecode buffer size.
|
||||
* \returns an SDL_malloc'd buffer containing SPIRV bytecode.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*/
|
||||
extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileSPIRVFromHLSL(
|
||||
const SDL_ShaderCross_HLSL_Info *info,
|
||||
size_t *size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include <SDL3/SDL_close_code.h>
|
||||
|
||||
#endif /* SDL_SHADERCROSS_H */
|
||||
2699
thirdparty/SDL_shadercross/src/SDL_shadercross.c
vendored
Normal file
2699
thirdparty/SDL_shadercross/src/SDL_shadercross.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
19
thirdparty/SDL_shadercross/src/SDL_shadercross.sym
vendored
Normal file
19
thirdparty/SDL_shadercross/src/SDL_shadercross.sym
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
SDL3_shadercross_0.0.0 {
|
||||
global:
|
||||
SDL_ShaderCross_Init;
|
||||
SDL_ShaderCross_Quit;
|
||||
SDL_ShaderCross_GetSPIRVShaderFormats;
|
||||
SDL_ShaderCross_TranspileMSLFromSPIRV;
|
||||
SDL_ShaderCross_TranspileHLSLFromSPIRV;
|
||||
SDL_ShaderCross_CompileDXBCFromSPIRV;
|
||||
SDL_ShaderCross_CompileDXILFromSPIRV;
|
||||
SDL_ShaderCross_CompileGraphicsShaderFromSPIRV;
|
||||
SDL_ShaderCross_CompileComputePipelineFromSPIRV;
|
||||
SDL_ShaderCross_GetHLSLShaderFormats;
|
||||
SDL_ShaderCross_CompileDXBCFromHLSL;
|
||||
SDL_ShaderCross_CompileDXILFromHLSL;
|
||||
SDL_ShaderCross_CompileSPIRVFromHLSL;
|
||||
SDL_ShaderCross_ReflectGraphicsSPIRV;
|
||||
SDL_ShaderCross_ReflectComputeSPIRV;
|
||||
local: *;
|
||||
};
|
||||
824
thirdparty/SDL_shadercross/src/cli.c
vendored
Normal file
824
thirdparty/SDL_shadercross/src/cli.c
vendored
Normal file
|
|
@ -0,0 +1,824 @@
|
|||
/*
|
||||
Simple DirectMedia Layer Shader Cross Compiler
|
||||
Copyright (C) 2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <SDL3_shadercross/SDL_shadercross.h>
|
||||
#include <SDL3/SDL_log.h>
|
||||
#include <SDL3/SDL_iostream.h>
|
||||
#ifdef LEAKCHECK
|
||||
#include <SDL3/SDL_test_memory.h>
|
||||
#endif
|
||||
|
||||
// We can emit HLSL and JSON as a destination, so let's redefine the shader format enum.
|
||||
typedef enum ShaderCross_DestinationFormat {
|
||||
SHADERFORMAT_INVALID,
|
||||
SHADERFORMAT_SPIRV,
|
||||
SHADERFORMAT_DXBC,
|
||||
SHADERFORMAT_DXIL,
|
||||
SHADERFORMAT_MSL,
|
||||
SHADERFORMAT_HLSL,
|
||||
SHADERFORMAT_JSON
|
||||
} ShaderCross_ShaderFormat;
|
||||
|
||||
void print_help(void)
|
||||
{
|
||||
int column_width = 32;
|
||||
SDL_Log("Usage: shadercross <input> [options]");
|
||||
SDL_Log("Required options:\n");
|
||||
SDL_Log(" %-*s %s", column_width, "-s | --source <value>", "Source language format. May be inferred from the filename. Values: [SPIRV, HLSL]");
|
||||
SDL_Log(" %-*s %s", column_width, "-d | --dest <value>", "Destination format. May be inferred from the filename. Values: [DXBC, DXIL, MSL, SPIRV, HLSL, JSON]");
|
||||
SDL_Log(" %-*s %s", column_width, "-t | --stage <value>", "Shader stage. May be inferred from the filename. Values: [vertex, fragment, compute]");
|
||||
SDL_Log(" %-*s %s", column_width, "-e | --entrypoint <value>", "Entrypoint function name. Default: \"main\".");
|
||||
SDL_Log(" %-*s %s", column_width, "-o | --output <value>", "Output file.");
|
||||
SDL_Log("\n");
|
||||
SDL_Log("Optional options:\n");
|
||||
SDL_Log(" %-*s %s", column_width, "-I | --include <value>", "HLSL include directory. Only used with HLSL source.");
|
||||
SDL_Log(" %-*s %s", column_width, "-D<name>[=<value>]", "HLSL define. Only used with HLSL source. Can be repeated.");
|
||||
SDL_Log(" %-*s %s", column_width, "", "If =<value> is omitted the define will be treated as equal to 1.");
|
||||
SDL_Log(" %-*s %s", column_width, "--msl-version <value>", "Target MSL version. Only used when transpiling to MSL. The default is 1.2.0.");
|
||||
SDL_Log(" %-*s %s", column_width, "-c | --cull", "Allow the compiler to cull unused resource bindings. This may lead to surprising binding behavior so be careful when enabling this!");
|
||||
SDL_Log(" %-*s %s", column_width, "-g | --debug", "Generate debug information when possible. Shaders are valid only when graphics debuggers are attached.");
|
||||
SDL_Log(" %-*s %s", column_width, "-p | --pssl", "Generate PSSL-compatible shader. Destination format should be HLSL.");
|
||||
}
|
||||
|
||||
static const char* io_var_type_to_string(SDL_ShaderCross_IOVarType io_var_type, Uint32 vector_size)
|
||||
{
|
||||
switch (io_var_type) {
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_INT8:
|
||||
switch (vector_size) {
|
||||
case 1: return "byte";
|
||||
case 2: return "byte2";
|
||||
case 3: return "byte3";
|
||||
case 4: return "byte4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_UINT8:
|
||||
switch (vector_size) {
|
||||
case 1: return "ubyte";
|
||||
case 2: return "ubyte2";
|
||||
case 3: return "ubyte3";
|
||||
case 4: return "ubyte4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_INT16:
|
||||
switch (vector_size) {
|
||||
case 1: return "short";
|
||||
case 2: return "short2";
|
||||
case 3: return "short3";
|
||||
case 4: return "short4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_UINT16:
|
||||
switch (vector_size) {
|
||||
case 1: return "ushort";
|
||||
case 2: return "ushort2";
|
||||
case 3: return "ushort3";
|
||||
case 4: return "ushort4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_INT32:
|
||||
switch (vector_size) {
|
||||
case 1: return "int";
|
||||
case 2: return "int2";
|
||||
case 3: return "int3";
|
||||
case 4: return "int4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_UINT32:
|
||||
switch (vector_size) {
|
||||
case 1: return "uint";
|
||||
case 2: return "uint2";
|
||||
case 3: return "uint3";
|
||||
case 4: return "uint4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_INT64:
|
||||
switch (vector_size) {
|
||||
case 1: return "long";
|
||||
case 2: return "long2";
|
||||
case 3: return "long3";
|
||||
case 4: return "long4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_UINT64:
|
||||
switch (vector_size) {
|
||||
case 1: return "ulong";
|
||||
case 2: return "ulong2";
|
||||
case 3: return "ulong3";
|
||||
case 4: return "ulong4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_FLOAT16:
|
||||
switch (vector_size) {
|
||||
case 1: return "half";
|
||||
case 2: return "half2";
|
||||
case 3: return "half3";
|
||||
case 4: return "half4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_FLOAT32:
|
||||
switch (vector_size) {
|
||||
case 1: return "float";
|
||||
case 2: return "float2";
|
||||
case 3: return "float3";
|
||||
case 4: return "float4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_FLOAT64:
|
||||
switch (vector_size) {
|
||||
case 1: return "double";
|
||||
case 2: return "double2";
|
||||
case 3: return "double3";
|
||||
case 4: return "double4";
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_SHADERCROSS_IOVAR_TYPE_UNKNOWN:
|
||||
default: break;
|
||||
}
|
||||
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown IO variable type: vector_type=%u vector_size=%u", io_var_type, vector_size);
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
void write_graphics_reflect_json(SDL_IOStream *outputIO, SDL_ShaderCross_GraphicsShaderMetadata *info)
|
||||
{
|
||||
SDL_IOprintf(
|
||||
outputIO,
|
||||
"{ \"samplers\": %u, \"storage_textures\": %u, \"storage_buffers\": %u, \"uniform_buffers\": %u, ",
|
||||
info->resource_info.num_samplers,
|
||||
info->resource_info.num_storage_textures,
|
||||
info->resource_info.num_storage_buffers,
|
||||
info->resource_info.num_uniform_buffers
|
||||
);
|
||||
|
||||
SDL_IOprintf(outputIO, "\"inputs\": [");
|
||||
for (Uint32 i = 0; i < info->num_inputs; i++) {
|
||||
const SDL_ShaderCross_IOVarMetadata* input = &info->inputs[i];
|
||||
SDL_IOprintf(outputIO, "{ \"name\": \"%s\", \"type\": \"%s\", \"location\": %u }%s",
|
||||
input->name,
|
||||
io_var_type_to_string(input->vector_type, input->vector_size),
|
||||
input->location,
|
||||
i + 1 < info->num_inputs ? ", " : ""
|
||||
);
|
||||
}
|
||||
SDL_IOprintf(outputIO, "], ");
|
||||
|
||||
SDL_IOprintf(outputIO, "\"outputs\": [");
|
||||
for (Uint32 i = 0; i < info->num_outputs; i++) {
|
||||
const SDL_ShaderCross_IOVarMetadata* output = &info->outputs[i];
|
||||
SDL_IOprintf(outputIO, "{ \"name\": \"%s\", \"type\": \"%s\", \"location\": %u }%s",
|
||||
output->name,
|
||||
io_var_type_to_string(output->vector_type, output->vector_size),
|
||||
output->location,
|
||||
i + 1 < info->num_outputs ? ", " : ""
|
||||
);
|
||||
}
|
||||
SDL_IOprintf(outputIO, "] }\n");
|
||||
}
|
||||
|
||||
void write_compute_reflect_json(SDL_IOStream *outputIO, SDL_ShaderCross_ComputePipelineMetadata *info)
|
||||
{
|
||||
SDL_IOprintf(
|
||||
outputIO,
|
||||
"{ \"samplers\": %u, \"readonly_storage_textures\": %u, \"readonly_storage_buffers\": %u, \"readwrite_storage_textures\": %u, \"readwrite_storage_buffers\": %u, \"uniform_buffers\": %u, \"threadcount_x\": %u, \"threadcount_y\": %u, \"threadcount_z\": %u }\n",
|
||||
info->num_samplers,
|
||||
info->num_readonly_storage_textures,
|
||||
info->num_readonly_storage_buffers,
|
||||
info->num_readwrite_storage_textures,
|
||||
info->num_readwrite_storage_buffers,
|
||||
info->num_uniform_buffers,
|
||||
info->threadcount_x,
|
||||
info->threadcount_y,
|
||||
info->threadcount_z
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool sourceValid = false;
|
||||
bool destinationValid = false;
|
||||
bool stageValid = false;
|
||||
|
||||
bool spirvSource = false;
|
||||
ShaderCross_ShaderFormat destinationFormat = SHADERFORMAT_INVALID;
|
||||
SDL_ShaderCross_ShaderStage shaderStage = SDL_SHADERCROSS_SHADERSTAGE_VERTEX;
|
||||
char *outputFilename = NULL;
|
||||
char *entrypointName = "main";
|
||||
char *includeDir = NULL;
|
||||
|
||||
char *filename = NULL;
|
||||
size_t fileSize = 0;
|
||||
void *fileData = NULL;
|
||||
bool accept_optionals = true;
|
||||
|
||||
SDL_ShaderCross_HLSL_Define *defines = NULL;
|
||||
size_t numDefines = 0;
|
||||
|
||||
bool cullUnusedBindings = false;
|
||||
bool enableDebug = false;
|
||||
char *mslVersion = NULL;
|
||||
|
||||
bool psslCompat = false;
|
||||
|
||||
#ifdef LEAKCHECK
|
||||
SDLTest_TrackAllocations();
|
||||
#endif
|
||||
|
||||
for (int i = 1; i < argc; i += 1) {
|
||||
char *arg = argv[i];
|
||||
|
||||
if (accept_optionals && arg[0] == '-') {
|
||||
if (SDL_strcmp(arg, "-h") == 0 || SDL_strcmp(arg, "--help") == 0) {
|
||||
print_help();
|
||||
return 0;
|
||||
} else if (SDL_strcmp(arg, "-s") == 0 || SDL_strcmp(arg, "--source") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s requires an argument", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
i += 1;
|
||||
if (SDL_strcasecmp(argv[i], "spirv") == 0) {
|
||||
spirvSource = true;
|
||||
sourceValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "hlsl") == 0) {
|
||||
spirvSource = false;
|
||||
sourceValid = true;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized source input %s, source must be SPIRV or HLSL!", argv[i]);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
} else if (SDL_strcmp(arg, "-d") == 0 || SDL_strcmp(arg, "--dest") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s requires an argument", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
i += 1;
|
||||
if (SDL_strcasecmp(argv[i], "DXBC") == 0) {
|
||||
destinationFormat = SHADERFORMAT_DXBC;
|
||||
destinationValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "DXIL") == 0) {
|
||||
destinationFormat = SHADERFORMAT_DXIL;
|
||||
destinationValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "MSL") == 0) {
|
||||
destinationFormat = SHADERFORMAT_MSL;
|
||||
destinationValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "SPIRV") == 0) {
|
||||
destinationFormat = SHADERFORMAT_SPIRV;
|
||||
destinationValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "HLSL") == 0) {
|
||||
destinationFormat = SHADERFORMAT_HLSL;
|
||||
destinationValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "JSON") == 0) {
|
||||
destinationFormat = SHADERFORMAT_JSON;
|
||||
destinationValid = true;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized destination input %s, destination must be DXBC, DXIL, MSL or SPIRV!", argv[i]);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
} else if (SDL_strcmp(arg, "-t") == 0 || SDL_strcmp(arg, "--stage") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s requires an argument", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
i += 1;
|
||||
if (SDL_strcasecmp(argv[i], "vertex") == 0) {
|
||||
shaderStage = SDL_SHADERCROSS_SHADERSTAGE_VERTEX;
|
||||
stageValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "fragment") == 0) {
|
||||
shaderStage = SDL_SHADERCROSS_SHADERSTAGE_FRAGMENT;
|
||||
stageValid = true;
|
||||
} else if (SDL_strcasecmp(argv[i], "compute") == 0) {
|
||||
shaderStage = SDL_SHADERCROSS_SHADERSTAGE_COMPUTE;
|
||||
stageValid = true;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized shader stage input %s, must be vertex, fragment, or compute.", argv[i]);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
} else if (SDL_strcmp(arg, "-e") == 0 || SDL_strcmp(arg, "--entrypoint") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s requires an argument", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
i += 1;
|
||||
entrypointName = argv[i];
|
||||
} else if (SDL_strcmp(arg, "-I") == 0 || SDL_strcmp(arg, "--include") == 0) {
|
||||
if (includeDir) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "'%s' can only be used once", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
if (i + 1 >= argc) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s requires an argument", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
i += 1;
|
||||
includeDir = argv[i];
|
||||
} else if (SDL_strcmp(arg, "-o") == 0 || SDL_strcmp(arg, "--output") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s requires an argument", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
i += 1;
|
||||
outputFilename = argv[i];
|
||||
} else if (SDL_strncmp(argv[i], "-D", SDL_strlen("-D")) == 0) {
|
||||
numDefines += 1;
|
||||
defines = SDL_realloc(defines, sizeof(SDL_ShaderCross_HLSL_Define) * numDefines);
|
||||
char *equalSign = SDL_strchr(argv[i], '=');
|
||||
if (equalSign != NULL) {
|
||||
defines[numDefines - 1].value = equalSign + 1;
|
||||
size_t len = defines[numDefines - 1].value - argv[i] - 2;
|
||||
defines[numDefines - 1].name = SDL_malloc(len);
|
||||
SDL_utf8strlcpy(defines[numDefines - 1].name, (const char *)argv[i] + 2, len);
|
||||
} else { // no '=' was found
|
||||
defines[numDefines - 1].value = NULL;
|
||||
size_t len = SDL_utf8strlen(argv[i]) + 1 - 2;
|
||||
defines[numDefines - 1].name = SDL_malloc(len);
|
||||
SDL_utf8strlcpy(defines[numDefines - 1].name, (const char *)argv[i] + 2, len);
|
||||
}
|
||||
} else if (SDL_strcmp(arg, "--msl-version") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s requires an argument", arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
i += 1;
|
||||
mslVersion = argv[i];
|
||||
} else if (SDL_strcmp(arg, "-c") == 0 || SDL_strcmp(arg, "--cull") == 0) {
|
||||
cullUnusedBindings = true;
|
||||
} else if (SDL_strcmp(arg, "-g") == 0 || SDL_strcmp(arg, "--debug") == 0) {
|
||||
enableDebug = true;
|
||||
} else if (SDL_strcmp(arg, "-p") == 0 || SDL_strcmp(arg, "--pssl") == 0) {
|
||||
psslCompat = true;
|
||||
} else if (SDL_strcmp(arg, "--") == 0) {
|
||||
accept_optionals = false;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s: Unknown argument: %s", argv[0], arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
} else if (!filename) {
|
||||
filename = arg;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s: Unknown argument: %s", argv[0], arg);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!filename) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s: missing input path", argv[0]);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
if (!outputFilename) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s: missing output path", argv[0]);
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
fileData = SDL_LoadFile(filename, &fileSize);
|
||||
if (fileData == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid file (%s)", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!SDL_ShaderCross_Init())
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_GPU, "%s", "Failed to initialize shadercross!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!sourceValid) {
|
||||
if (SDL_strstr(filename, ".spv")) {
|
||||
spirvSource = true;
|
||||
} else if (SDL_strstr(filename, ".hlsl")) {
|
||||
spirvSource = false;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Could not infer source format!");
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!destinationValid) {
|
||||
if (SDL_strstr(outputFilename, ".dxbc")) {
|
||||
destinationFormat = SHADERFORMAT_DXBC;
|
||||
} else if (SDL_strstr(outputFilename, ".dxil")) {
|
||||
destinationFormat = SHADERFORMAT_DXIL;
|
||||
} else if (SDL_strstr(outputFilename, ".msl")) {
|
||||
destinationFormat = SHADERFORMAT_MSL;
|
||||
} else if (SDL_strstr(outputFilename, ".spv")) {
|
||||
destinationFormat = SHADERFORMAT_SPIRV;
|
||||
} else if (SDL_strstr(outputFilename, ".hlsl")) {
|
||||
destinationFormat = SHADERFORMAT_HLSL;
|
||||
} else if (SDL_strstr(outputFilename, ".json")) {
|
||||
destinationFormat = SHADERFORMAT_JSON;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", "Could not infer destination format!");
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!stageValid) {
|
||||
if (SDL_strcasestr(filename, ".vert")) {
|
||||
shaderStage = SDL_SHADERCROSS_SHADERSTAGE_VERTEX;
|
||||
} else if (SDL_strcasestr(filename, ".frag")) {
|
||||
shaderStage = SDL_SHADERCROSS_SHADERSTAGE_FRAGMENT;
|
||||
} else if (SDL_strcasestr(filename, ".comp")) {
|
||||
shaderStage = SDL_SHADERCROSS_SHADERSTAGE_COMPUTE;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not infer shader stage from filename!");
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_IOStream *outputIO = SDL_IOFromFile(outputFilename, "w");
|
||||
|
||||
if (outputIO == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t bytecodeSize;
|
||||
int result = 0;
|
||||
|
||||
// null-terminate the defines array
|
||||
if (defines != NULL) {
|
||||
defines = SDL_realloc(defines, sizeof(SDL_ShaderCross_HLSL_Define) * (numDefines + 1));
|
||||
defines[numDefines].name = NULL;
|
||||
defines[numDefines].value = NULL;
|
||||
}
|
||||
|
||||
if (spirvSource) {
|
||||
SDL_ShaderCross_SPIRV_Info spirvInfo;
|
||||
spirvInfo.bytecode = fileData;
|
||||
spirvInfo.bytecode_size = fileSize;
|
||||
spirvInfo.entrypoint = entrypointName;
|
||||
spirvInfo.shader_stage = shaderStage;
|
||||
spirvInfo.props = SDL_CreateProperties();
|
||||
if (enableDebug) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN, true);
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING, filename);
|
||||
}
|
||||
if (cullUnusedBindings) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN, true);
|
||||
}
|
||||
if (mslVersion) {
|
||||
SDL_SetStringProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SPIRV_MSL_VERSION_STRING, mslVersion);
|
||||
}
|
||||
if (psslCompat) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SPIRV_PSSL_COMPATIBILITY_BOOLEAN, true);
|
||||
}
|
||||
|
||||
switch (destinationFormat) {
|
||||
case SHADERFORMAT_DXBC: {
|
||||
Uint8 *buffer = SDL_ShaderCross_CompileDXBCFromSPIRV(
|
||||
&spirvInfo,
|
||||
&bytecodeSize);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXBC from SPIR-V: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_WriteIO(outputIO, buffer, bytecodeSize);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_DXIL: {
|
||||
Uint8 *buffer = SDL_ShaderCross_CompileDXILFromSPIRV(
|
||||
&spirvInfo,
|
||||
&bytecodeSize);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXIL from SPIR-V: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_WriteIO(outputIO, buffer, bytecodeSize);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_MSL: {
|
||||
char *buffer = SDL_ShaderCross_TranspileMSLFromSPIRV(
|
||||
&spirvInfo);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile MSL from SPIR-V: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_IOprintf(outputIO, "%s", buffer);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_HLSL: {
|
||||
char *buffer = SDL_ShaderCross_TranspileHLSLFromSPIRV(
|
||||
&spirvInfo);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile HLSL from SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_IOprintf(outputIO, "%s", buffer);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_SPIRV: {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Input and output are both SPIRV. Did you mean to do that?");
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_JSON: {
|
||||
if (shaderStage == SDL_SHADERCROSS_SHADERSTAGE_COMPUTE) {
|
||||
SDL_ShaderCross_ComputePipelineMetadata *info = SDL_ShaderCross_ReflectComputeSPIRV(
|
||||
fileData,
|
||||
fileSize,
|
||||
0);
|
||||
if (info) {
|
||||
write_compute_reflect_json(outputIO, info);
|
||||
SDL_free(info);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to reflect SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
}
|
||||
} else {
|
||||
SDL_ShaderCross_GraphicsShaderMetadata *info = SDL_ShaderCross_ReflectGraphicsSPIRV(
|
||||
fileData,
|
||||
fileSize,
|
||||
0);
|
||||
if (info) {
|
||||
write_graphics_reflect_json(outputIO, info);
|
||||
SDL_free(info);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to reflect SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_INVALID: {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Destination format not provided!");
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_DestroyProperties(spirvInfo.props);
|
||||
} else {
|
||||
SDL_ShaderCross_HLSL_Info hlslInfo;
|
||||
hlslInfo.source = fileData;
|
||||
hlslInfo.entrypoint = entrypointName;
|
||||
hlslInfo.include_dir = includeDir;
|
||||
hlslInfo.defines = defines;
|
||||
hlslInfo.shader_stage = shaderStage;
|
||||
hlslInfo.props = SDL_CreateProperties();
|
||||
|
||||
if (enableDebug) {
|
||||
SDL_SetBooleanProperty(hlslInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN, true);
|
||||
SDL_SetStringProperty(hlslInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING, filename);
|
||||
}
|
||||
|
||||
if (cullUnusedBindings) {
|
||||
SDL_SetBooleanProperty(hlslInfo.props, SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN, true);
|
||||
}
|
||||
|
||||
switch (destinationFormat) {
|
||||
case SHADERFORMAT_DXBC: {
|
||||
Uint8 *buffer = SDL_ShaderCross_CompileDXBCFromHLSL(
|
||||
&hlslInfo,
|
||||
&bytecodeSize);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXBC from HLSL: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_WriteIO(outputIO, buffer, bytecodeSize);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_DXIL: {
|
||||
Uint8 *buffer = SDL_ShaderCross_CompileDXILFromHLSL(
|
||||
&hlslInfo,
|
||||
&bytecodeSize);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile DXIL from HLSL: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_WriteIO(outputIO, buffer, bytecodeSize);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: Should we have TranspileMSLFromHLSL?
|
||||
case SHADERFORMAT_MSL: {
|
||||
void *spirv = SDL_ShaderCross_CompileSPIRVFromHLSL(
|
||||
&hlslInfo,
|
||||
&bytecodeSize);
|
||||
if (spirv == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile MSL from HLSL: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_ShaderCross_SPIRV_Info spirvInfo;
|
||||
spirvInfo.bytecode = spirv;
|
||||
spirvInfo.bytecode_size = bytecodeSize;
|
||||
spirvInfo.entrypoint = entrypointName;
|
||||
spirvInfo.shader_stage = shaderStage;
|
||||
spirvInfo.props = SDL_CreateProperties();
|
||||
|
||||
if (enableDebug) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN, true);
|
||||
SDL_SetStringProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING, filename);
|
||||
}
|
||||
if (cullUnusedBindings) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN, true);
|
||||
}
|
||||
if (mslVersion) {
|
||||
SDL_SetStringProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SPIRV_MSL_VERSION_STRING, mslVersion);
|
||||
}
|
||||
|
||||
char *buffer = SDL_ShaderCross_TranspileMSLFromSPIRV(
|
||||
&spirvInfo);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile MSL from HLSL: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_IOprintf(outputIO, "%s", buffer);
|
||||
SDL_free(spirv);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
SDL_DestroyProperties(spirvInfo.props);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_SPIRV: {
|
||||
Uint8 *buffer = SDL_ShaderCross_CompileSPIRVFromHLSL(
|
||||
&hlslInfo,
|
||||
&bytecodeSize);
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile SPIR-V From HLSL: %s", SDL_GetError());
|
||||
result = 1;
|
||||
} else {
|
||||
SDL_WriteIO(outputIO, buffer, bytecodeSize);
|
||||
SDL_free(buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_HLSL: {
|
||||
void *spirv = SDL_ShaderCross_CompileSPIRVFromHLSL(
|
||||
&hlslInfo,
|
||||
&bytecodeSize);
|
||||
|
||||
if (spirv == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile HLSL to SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_ShaderCross_SPIRV_Info spirvInfo;
|
||||
spirvInfo.bytecode = spirv;
|
||||
spirvInfo.bytecode_size = bytecodeSize;
|
||||
spirvInfo.entrypoint = entrypointName;
|
||||
spirvInfo.shader_stage = shaderStage;
|
||||
spirvInfo.props = SDL_CreateProperties();
|
||||
|
||||
if (enableDebug) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN, true);
|
||||
SDL_SetStringProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING, filename);
|
||||
}
|
||||
if (cullUnusedBindings) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN, true);
|
||||
}
|
||||
if (psslCompat) {
|
||||
SDL_SetBooleanProperty(spirvInfo.props, SDL_SHADERCROSS_PROP_SPIRV_PSSL_COMPATIBILITY_BOOLEAN, true);
|
||||
}
|
||||
|
||||
char *buffer = SDL_ShaderCross_TranspileHLSLFromSPIRV(
|
||||
&spirvInfo);
|
||||
|
||||
if (buffer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to transpile HLSL from SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_IOprintf(outputIO, "%s", buffer);
|
||||
SDL_free(spirv);
|
||||
SDL_free(buffer);
|
||||
SDL_DestroyProperties(spirvInfo.props);
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_JSON: {
|
||||
void *spirv = SDL_ShaderCross_CompileSPIRVFromHLSL(
|
||||
&hlslInfo,
|
||||
&bytecodeSize);
|
||||
|
||||
if (spirv == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile HLSL to SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shaderStage == SDL_SHADERCROSS_SHADERSTAGE_COMPUTE) {
|
||||
SDL_ShaderCross_ComputePipelineMetadata *info = SDL_ShaderCross_ReflectComputeSPIRV(
|
||||
spirv,
|
||||
bytecodeSize,
|
||||
0);
|
||||
SDL_free(spirv);
|
||||
|
||||
if (info) {
|
||||
write_compute_reflect_json(outputIO, info);
|
||||
SDL_free(info);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to reflect SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
}
|
||||
} else {
|
||||
SDL_ShaderCross_GraphicsShaderMetadata *info = SDL_ShaderCross_ReflectGraphicsSPIRV(
|
||||
spirv,
|
||||
bytecodeSize,
|
||||
0);
|
||||
SDL_free(spirv);
|
||||
|
||||
if (info) {
|
||||
write_graphics_reflect_json(outputIO, info);
|
||||
SDL_free(info);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to reflect SPIRV: %s", SDL_GetError());
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SHADERFORMAT_INVALID: {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Destination format not provided!");
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_DestroyProperties(hlslInfo.props);
|
||||
}
|
||||
|
||||
SDL_CloseIO(outputIO);
|
||||
SDL_free(fileData);
|
||||
for (Uint32 i = 0; i < numDefines; i += 1) {
|
||||
SDL_free(defines[i].name);
|
||||
}
|
||||
SDL_free(defines);
|
||||
SDL_ShaderCross_Quit();
|
||||
SDL_Quit();
|
||||
|
||||
#ifdef LEAKCHECK
|
||||
SDLTest_LogAllocations();
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
38
thirdparty/SDL_shadercross/src/version.rc
vendored
Normal file
38
thirdparty/SDL_shadercross/src/version.rc
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
#include "winresrc.h"
|
||||
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,0,0,0
|
||||
PRODUCTVERSION 3,0,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
FILEFLAGS 0x0L
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "\0"
|
||||
VALUE "FileDescription", "SDL_shadercross\0"
|
||||
VALUE "FileVersion", "3, 0, 0, 0\0"
|
||||
VALUE "InternalName", "SDL_shadercross\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2024 Sam Lantinga\0"
|
||||
VALUE "OriginalFilename", "SDL3_shadercross.dll\0"
|
||||
VALUE "ProductName", "Simple DirectMedia Layer\0"
|
||||
VALUE "ProductVersion", "3, 0, 0, 0\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
659
thirdparty/SPIRV-Cross/CMakeLists.txt
vendored
Normal file
659
thirdparty/SPIRV-Cross/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,659 @@
|
|||
# Copyright 2016-2021 Google Inc.
|
||||
# SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#
|
||||
# At your option, you may choose to accept this material under either:
|
||||
# 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
# 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
# Avoid a warning if parent project sets VERSION in project().
|
||||
if (${CMAKE_VERSION} VERSION_GREATER "3.0.1")
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
endif()
|
||||
|
||||
# Avoid error on Android NDK 27+'s CMake files
|
||||
cmake_policy(SET CMP0057 NEW)
|
||||
|
||||
project(SPIRV-Cross LANGUAGES CXX C)
|
||||
enable_testing()
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
option(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS "Instead of throwing exceptions assert" OFF)
|
||||
option(SPIRV_CROSS_SHARED "Build the C API as a single shared library." OFF)
|
||||
option(SPIRV_CROSS_STATIC "Build the C and C++ API as static libraries." ON)
|
||||
option(SPIRV_CROSS_CLI "Build the CLI binary. Requires SPIRV_CROSS_STATIC." ON)
|
||||
option(SPIRV_CROSS_ENABLE_TESTS "Enable SPIRV-Cross tests." ON)
|
||||
|
||||
option(SPIRV_CROSS_ENABLE_GLSL "Enable GLSL support." ON)
|
||||
option(SPIRV_CROSS_ENABLE_HLSL "Enable HLSL target support." ON)
|
||||
option(SPIRV_CROSS_ENABLE_MSL "Enable MSL target support." ON)
|
||||
option(SPIRV_CROSS_ENABLE_CPP "Enable C++ target support." ON)
|
||||
option(SPIRV_CROSS_ENABLE_REFLECT "Enable JSON reflection target support." ON)
|
||||
option(SPIRV_CROSS_ENABLE_C_API "Enable C API wrapper support in static library." ON)
|
||||
option(SPIRV_CROSS_ENABLE_UTIL "Enable util module support." ON)
|
||||
|
||||
option(SPIRV_CROSS_SANITIZE_ADDRESS "Sanitize address" OFF)
|
||||
option(SPIRV_CROSS_SANITIZE_MEMORY "Sanitize memory" OFF)
|
||||
option(SPIRV_CROSS_SANITIZE_THREADS "Sanitize threads" OFF)
|
||||
option(SPIRV_CROSS_SANITIZE_UNDEFINED "Sanitize undefined" OFF)
|
||||
|
||||
option(SPIRV_CROSS_NAMESPACE_OVERRIDE "" "Override the namespace used in the C++ API.")
|
||||
option(SPIRV_CROSS_SPV_HEADER_NAMESPACE_OVERRIDE "" "Override the namespace used by spirv.hpp (to workaround conflicts).")
|
||||
option(SPIRV_CROSS_FORCE_STL_TYPES "Force use of STL types instead of STL replacements in certain places. Might reduce performance." OFF)
|
||||
|
||||
option(SPIRV_CROSS_SKIP_INSTALL "Skips installation targets." OFF)
|
||||
|
||||
option(SPIRV_CROSS_WERROR "Fail build on warnings." OFF)
|
||||
option(SPIRV_CROSS_MISC_WARNINGS "Misc warnings useful for Travis runs." OFF)
|
||||
|
||||
option(SPIRV_CROSS_FORCE_PIC "Force position-independent code for all targets." OFF)
|
||||
|
||||
if(${CMAKE_GENERATOR} MATCHES "Makefile")
|
||||
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
|
||||
message(FATAL_ERROR "Build out of tree to avoid overwriting Makefile")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(spirv-compiler-options "")
|
||||
set(spirv-compiler-defines "")
|
||||
set(spirv-cross-link-flags "")
|
||||
|
||||
message(STATUS "SPIRV-Cross: Finding Git version for SPIRV-Cross.")
|
||||
set(spirv-cross-build-version "unknown")
|
||||
find_package(Git)
|
||||
if (GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --always --tags --dirty=+
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE spirv-cross-build-version
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
message(STATUS "SPIRV-Cross: Git hash: ${spirv-cross-build-version}")
|
||||
else()
|
||||
message(STATUS "SPIRV-Cross: Git not found, using unknown build version.")
|
||||
endif()
|
||||
|
||||
string(TIMESTAMP spirv-cross-timestamp)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.in.h ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h @ONLY)
|
||||
|
||||
if (SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
||||
set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
||||
if (NOT MSVC)
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_FORCE_STL_TYPES)
|
||||
set(spirv-compiler-defines ${spirv-compiler-defines} SPIRV_CROSS_FORCE_STL_TYPES)
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
endif()
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX OR ((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") AND NOT MSVC))
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -Wall -Wextra -Wshadow -Wno-deprecated-declarations)
|
||||
if (SPIRV_CROSS_MISC_WARNINGS)
|
||||
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -Wshorten-64-to-32)
|
||||
endif()
|
||||
endif()
|
||||
if (SPIRV_CROSS_WERROR)
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -Werror)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -fno-exceptions)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_SANITIZE_ADDRESS)
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=address)
|
||||
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=address")
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_SANITIZE_UNDEFINED)
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=undefined)
|
||||
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=undefined")
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_SANITIZE_MEMORY)
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=memory)
|
||||
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=memory")
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_SANITIZE_THREADS)
|
||||
set(spirv-compiler-options ${spirv-compiler-options} -fsanitize=thread)
|
||||
set(spirv-cross-link-flags "${spirv-cross-link-flags} -fsanitize=thread")
|
||||
endif()
|
||||
elseif (MSVC)
|
||||
# AppVeyor spuriously fails in debug build on older MSVC without /bigobj.
|
||||
set(spirv-compiler-options ${spirv-compiler-options} /wd4267 /wd4996 $<$<CONFIG:DEBUG>:/bigobj>)
|
||||
endif()
|
||||
|
||||
macro(extract_headers out_abs file_list)
|
||||
set(${out_abs}) # absolute paths
|
||||
foreach(_a ${file_list})
|
||||
# get_filename_component only returns the longest extension, so use a regex
|
||||
string(REGEX REPLACE ".*\\.(h|hpp)" "\\1" ext ${_a})
|
||||
|
||||
# For shared library, we are only interested in the C header.
|
||||
if (SPIRV_CROSS_STATIC)
|
||||
if(("${ext}" STREQUAL "h") OR ("${ext}" STREQUAL "hpp"))
|
||||
list(APPEND ${out_abs} "${_a}")
|
||||
endif()
|
||||
else()
|
||||
if("${ext}" STREQUAL "h")
|
||||
list(APPEND ${out_abs} "${_a}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
macro(spirv_cross_add_library name config_name library_type)
|
||||
add_library(${name} ${library_type} ${ARGN})
|
||||
extract_headers(hdrs "${ARGN}")
|
||||
target_include_directories(${name} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross>)
|
||||
set_target_properties(${name} PROPERTIES
|
||||
PUBLIC_HEADERS "${hdrs}")
|
||||
if (SPIRV_CROSS_FORCE_PIC)
|
||||
set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
target_compile_options(${name} PRIVATE ${spirv-compiler-options})
|
||||
target_compile_definitions(${name} PRIVATE ${spirv-compiler-defines})
|
||||
if (SPIRV_CROSS_NAMESPACE_OVERRIDE)
|
||||
if (${library_type} MATCHES "STATIC")
|
||||
target_compile_definitions(${name} PUBLIC SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE})
|
||||
else()
|
||||
target_compile_definitions(${name} PRIVATE SPIRV_CROSS_NAMESPACE_OVERRIDE=${SPIRV_CROSS_NAMESPACE_OVERRIDE})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_SPV_HEADER_NAMESPACE_OVERRIDE)
|
||||
if (${library_type} MATCHES "STATIC")
|
||||
target_compile_definitions(${name} PUBLIC SPIRV_CROSS_SPV_HEADER_NAMESPACE_OVERRIDE=${SPIRV_CROSS_SPV_HEADER_NAMESPACE_OVERRIDE})
|
||||
else()
|
||||
target_compile_definitions(${name} PRIVATE SPIRV_CROSS_SPV_HEADER_NAMESPACE_OVERRIDE=${SPIRV_CROSS_SPV_HEADER_NAMESPACE_OVERRIDE})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT SPIRV_CROSS_SKIP_INSTALL)
|
||||
install(TARGETS ${name}
|
||||
EXPORT ${config_name}Config
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross)
|
||||
install(FILES ${hdrs} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spirv_cross)
|
||||
install(EXPORT ${config_name}Config DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${config_name}/cmake)
|
||||
export(TARGETS ${name} FILE ${config_name}Config.cmake)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(spirv-cross-core-sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GLSL.std.450.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_common.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_containers.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_error_handling.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_parser.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_parser.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_parsed_ir.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_parsed_ir.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cfg.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cfg.cpp)
|
||||
|
||||
set(spirv-cross-c-sources
|
||||
spirv.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_c.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_c.h)
|
||||
|
||||
set(spirv-cross-glsl-sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_glsl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_glsl.hpp)
|
||||
|
||||
set(spirv-cross-cpp-sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cpp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cpp.hpp)
|
||||
|
||||
set(spirv-cross-msl-sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_msl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_msl.hpp)
|
||||
|
||||
set(spirv-cross-hlsl-sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_hlsl.hpp)
|
||||
|
||||
set(spirv-cross-reflect-sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_reflect.hpp)
|
||||
|
||||
set(spirv-cross-util-sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spirv_cross_util.hpp)
|
||||
|
||||
set(spirv-cross-abi-major 0)
|
||||
set(spirv-cross-abi-minor 68)
|
||||
set(spirv-cross-abi-patch 0)
|
||||
set(SPIRV_CROSS_VERSION ${spirv-cross-abi-major}.${spirv-cross-abi-minor}.${spirv-cross-abi-patch})
|
||||
|
||||
if (SPIRV_CROSS_STATIC)
|
||||
if (NOT SPIRV_CROSS_SKIP_INSTALL)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pkg-config/spirv-cross-c.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/spirv-cross-c.pc @ONLY)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/spirv-cross-c.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
endif()
|
||||
|
||||
spirv_cross_add_library(spirv-cross-core spirv_cross_core STATIC
|
||||
${spirv-cross-core-sources})
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
spirv_cross_add_library(spirv-cross-glsl spirv_cross_glsl STATIC
|
||||
${spirv-cross-glsl-sources})
|
||||
target_link_libraries(spirv-cross-glsl PRIVATE spirv-cross-core)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_CPP)
|
||||
spirv_cross_add_library(spirv-cross-cpp spirv_cross_cpp STATIC
|
||||
${spirv-cross-cpp-sources})
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_link_libraries(spirv-cross-cpp PRIVATE spirv-cross-glsl)
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable C++ support.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_REFLECT)
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
spirv_cross_add_library(spirv-cross-reflect spirv_cross_reflect STATIC
|
||||
${spirv-cross-reflect-sources})
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable JSON reflection support.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_MSL)
|
||||
spirv_cross_add_library(spirv-cross-msl spirv_cross_msl STATIC
|
||||
${spirv-cross-msl-sources})
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_link_libraries(spirv-cross-msl PRIVATE spirv-cross-glsl)
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable MSL support.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_HLSL)
|
||||
spirv_cross_add_library(spirv-cross-hlsl spirv_cross_hlsl STATIC
|
||||
${spirv-cross-hlsl-sources})
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_link_libraries(spirv-cross-hlsl PRIVATE spirv-cross-glsl)
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable HLSL support.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_UTIL)
|
||||
spirv_cross_add_library(spirv-cross-util spirv_cross_util STATIC
|
||||
${spirv-cross-util-sources})
|
||||
target_link_libraries(spirv-cross-util PRIVATE spirv-cross-core)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_C_API)
|
||||
spirv_cross_add_library(spirv-cross-c spirv_cross_c STATIC
|
||||
${spirv-cross-c-sources})
|
||||
target_include_directories(spirv-cross-c PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_compile_definitions(spirv-cross-c PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION)
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-glsl)
|
||||
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_GLSL=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_HLSL)
|
||||
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-hlsl)
|
||||
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_HLSL=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_MSL)
|
||||
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-msl)
|
||||
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_MSL=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_CPP)
|
||||
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-cpp)
|
||||
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_CPP=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_REFLECT)
|
||||
target_link_libraries(spirv-cross-c PRIVATE spirv-cross-reflect)
|
||||
target_compile_definitions(spirv-cross-c PRIVATE SPIRV_CROSS_C_API_REFLECT=1)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_SHARED)
|
||||
if (NOT SPIRV_CROSS_SKIP_INSTALL)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pkg-config/spirv-cross-c-shared.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/spirv-cross-c-shared.pc @ONLY)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/spirv-cross-c-shared.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
endif()
|
||||
|
||||
spirv_cross_add_library(spirv-cross-c-shared spirv_cross_c_shared SHARED
|
||||
${spirv-cross-core-sources}
|
||||
${spirv-cross-c-sources})
|
||||
|
||||
target_include_directories(spirv-cross-c-shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE HAVE_SPIRV_CROSS_GIT_VERSION)
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-glsl-sources})
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_GLSL=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_HLSL)
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-hlsl-sources})
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable HLSL support.")
|
||||
endif()
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_HLSL=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_MSL)
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-msl-sources})
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable MSL support.")
|
||||
endif()
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_MSL=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_CPP)
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-cpp-sources})
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable C++ support.")
|
||||
endif()
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_CPP=1)
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_REFLECT)
|
||||
if (SPIRV_CROSS_ENABLE_GLSL)
|
||||
target_sources(spirv-cross-c-shared PRIVATE ${spirv-cross-reflect-sources})
|
||||
else()
|
||||
message(FATAL_ERROR "Must enable GLSL support to enable JSON reflection support.")
|
||||
endif()
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE SPIRV_CROSS_C_API_REFLECT=1)
|
||||
endif()
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
|
||||
# Only export the C API.
|
||||
target_compile_options(spirv-cross-c-shared PRIVATE -fvisibility=hidden)
|
||||
if (NOT APPLE)
|
||||
set_target_properties(spirv-cross-c-shared PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_compile_definitions(spirv-cross-c-shared PRIVATE SPVC_EXPORT_SYMBOLS)
|
||||
|
||||
set_target_properties(spirv-cross-c-shared PROPERTIES
|
||||
VERSION ${SPIRV_CROSS_VERSION}
|
||||
SOVERSION ${spirv-cross-abi-major})
|
||||
endif()
|
||||
|
||||
if (SPIRV_CROSS_CLI)
|
||||
if (NOT SPIRV_CROSS_ENABLE_GLSL)
|
||||
message(FATAL_ERROR "Must enable GLSL if building CLI.")
|
||||
endif()
|
||||
|
||||
if (NOT SPIRV_CROSS_ENABLE_HLSL)
|
||||
message(FATAL_ERROR "Must enable HLSL if building CLI.")
|
||||
endif()
|
||||
|
||||
if (NOT SPIRV_CROSS_ENABLE_MSL)
|
||||
message(FATAL_ERROR "Must enable MSL if building CLI.")
|
||||
endif()
|
||||
|
||||
if (NOT SPIRV_CROSS_ENABLE_CPP)
|
||||
message(FATAL_ERROR "Must enable C++ if building CLI.")
|
||||
endif()
|
||||
|
||||
if (NOT SPIRV_CROSS_ENABLE_REFLECT)
|
||||
message(FATAL_ERROR "Must enable reflection if building CLI.")
|
||||
endif()
|
||||
|
||||
if (NOT SPIRV_CROSS_ENABLE_UTIL)
|
||||
message(FATAL_ERROR "Must enable utils if building CLI.")
|
||||
endif()
|
||||
|
||||
if (NOT SPIRV_CROSS_STATIC)
|
||||
message(FATAL_ERROR "Must build static libraries if building CLI.")
|
||||
endif()
|
||||
add_executable(spirv-cross main.cpp)
|
||||
target_compile_options(spirv-cross PRIVATE ${spirv-compiler-options})
|
||||
target_include_directories(spirv-cross PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_compile_definitions(spirv-cross PRIVATE ${spirv-compiler-defines} HAVE_SPIRV_CROSS_GIT_VERSION)
|
||||
set_target_properties(spirv-cross PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
if (NOT SPIRV_CROSS_SKIP_INSTALL)
|
||||
install(TARGETS spirv-cross DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
target_link_libraries(spirv-cross PRIVATE
|
||||
spirv-cross-glsl
|
||||
spirv-cross-hlsl
|
||||
spirv-cross-cpp
|
||||
spirv-cross-reflect
|
||||
spirv-cross-msl
|
||||
spirv-cross-util
|
||||
spirv-cross-core)
|
||||
|
||||
if (SPIRV_CROSS_ENABLE_TESTS)
|
||||
# Set up tests, using only the simplest modes of the test_shaders
|
||||
# script. You have to invoke the script manually to:
|
||||
# - Update the reference files
|
||||
# - Get cycle counts from malisc
|
||||
# - Keep failing outputs
|
||||
if (${CMAKE_VERSION} VERSION_GREATER "3.12")
|
||||
find_package(Python3)
|
||||
if (${PYTHON3_FOUND})
|
||||
set(PYTHONINTERP_FOUND ON)
|
||||
set(PYTHON_VERSION_MAJOR 3)
|
||||
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
|
||||
else()
|
||||
set(PYTHONINTERP_FOUND OFF)
|
||||
endif()
|
||||
else()
|
||||
find_package(PythonInterp)
|
||||
endif()
|
||||
|
||||
find_program(spirv-cross-glslang NAMES glslangValidator
|
||||
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/glslang-build/output/bin
|
||||
NO_DEFAULT_PATH)
|
||||
find_program(spirv-cross-spirv-as NAMES spirv-as
|
||||
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/spirv-tools-build/output/bin
|
||||
NO_DEFAULT_PATH)
|
||||
find_program(spirv-cross-spirv-val NAMES spirv-val
|
||||
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/spirv-tools-build/output/bin
|
||||
NO_DEFAULT_PATH)
|
||||
find_program(spirv-cross-spirv-opt NAMES spirv-opt
|
||||
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/spirv-tools-build/output/bin
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
if ((${spirv-cross-glslang} MATCHES "NOTFOUND") OR (${spirv-cross-spirv-as} MATCHES "NOTFOUND") OR (${spirv-cross-spirv-val} MATCHES "NOTFOUND") OR (${spirv-cross-spirv-opt} MATCHES "NOTFOUND"))
|
||||
set(SPIRV_CROSS_ENABLE_TESTS OFF)
|
||||
message("SPIRV-Cross: Testing will be disabled for SPIRV-Cross. Could not find glslang or SPIRV-Tools build under external/. To enable testing, run ./checkout_glslang_spirv_tools.sh and ./build_glslang_spirv_tools.sh first.")
|
||||
else()
|
||||
set(SPIRV_CROSS_ENABLE_TESTS ON)
|
||||
message("SPIRV-Cross: Found glslang and SPIRV-Tools. Enabling test suite.")
|
||||
message("SPIRV-Cross: Found glslangValidator in: ${spirv-cross-glslang}.")
|
||||
message("SPIRV-Cross: Found spirv-as in: ${spirv-cross-spirv-as}.")
|
||||
message("SPIRV-Cross: Found spirv-val in: ${spirv-cross-spirv-val}.")
|
||||
message("SPIRV-Cross: Found spirv-opt in: ${spirv-cross-spirv-opt}.")
|
||||
endif()
|
||||
|
||||
set(spirv-cross-externals
|
||||
--glslang "${spirv-cross-glslang}"
|
||||
--spirv-as "${spirv-cross-spirv-as}"
|
||||
--spirv-opt "${spirv-cross-spirv-opt}"
|
||||
--spirv-val "${spirv-cross-spirv-val}")
|
||||
|
||||
if (${PYTHONINTERP_FOUND} AND SPIRV_CROSS_ENABLE_TESTS)
|
||||
if (${PYTHON_VERSION_MAJOR} GREATER 2)
|
||||
add_executable(spirv-cross-c-api-test tests-other/c_api_test.c)
|
||||
target_link_libraries(spirv-cross-c-api-test spirv-cross-c)
|
||||
set_target_properties(spirv-cross-c-api-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-small-vector-test tests-other/small_vector.cpp)
|
||||
target_link_libraries(spirv-cross-small-vector-test spirv-cross-core)
|
||||
set_target_properties(spirv-cross-small-vector-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-msl-constexpr-test tests-other/msl_constexpr_test.cpp)
|
||||
target_link_libraries(spirv-cross-msl-constexpr-test spirv-cross-c)
|
||||
set_target_properties(spirv-cross-msl-constexpr-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-msl-resource-binding-test tests-other/msl_resource_bindings.cpp)
|
||||
target_link_libraries(spirv-cross-msl-resource-binding-test spirv-cross-c)
|
||||
set_target_properties(spirv-cross-msl-resource-binding-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-hlsl-resource-binding-test tests-other/hlsl_resource_bindings.cpp)
|
||||
target_link_libraries(spirv-cross-hlsl-resource-binding-test spirv-cross-c)
|
||||
set_target_properties(spirv-cross-hlsl-resource-binding-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-msl-ycbcr-conversion-test tests-other/msl_ycbcr_conversion_test.cpp)
|
||||
target_link_libraries(spirv-cross-msl-ycbcr-conversion-test spirv-cross-c)
|
||||
set_target_properties(spirv-cross-msl-ycbcr-conversion-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-typed-id-test tests-other/typed_id_test.cpp)
|
||||
target_link_libraries(spirv-cross-typed-id-test spirv-cross-core)
|
||||
set_target_properties(spirv-cross-typed-id-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-debug-lines-test tests-other/debug-lines.cpp)
|
||||
target_link_libraries(spirv-cross-debug-lines-test spirv-cross-core)
|
||||
set_target_properties(spirv-cross-debug-lines-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
add_executable(spirv-cross-debug-info-test tests-other/debug-info.cpp)
|
||||
target_link_libraries(spirv-cross-debug-info-test spirv-cross-core)
|
||||
set_target_properties(spirv-cross-debug-info-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
|
||||
target_compile_options(spirv-cross-c-api-test PRIVATE -std=c89 -Wall -Wextra)
|
||||
endif()
|
||||
add_test(NAME spirv-cross-c-api-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-c-api-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/c_api_test.spv
|
||||
${spirv-cross-abi-major}
|
||||
${spirv-cross-abi-minor}
|
||||
${spirv-cross-abi-patch})
|
||||
add_test(NAME spirv-cross-small-vector-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-small-vector-test>)
|
||||
add_test(NAME spirv-cross-msl-constexpr-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-msl-constexpr-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_constexpr_test.spv)
|
||||
add_test(NAME spirv-cross-msl-resource-binding-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-msl-resource-binding-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_resource_binding.spv)
|
||||
add_test(NAME spirv-cross-hlsl-resource-binding-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-hlsl-resource-binding-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/hlsl_resource_binding.spv)
|
||||
add_test(NAME spirv-cross-msl-ycbcr-conversion-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-msl-ycbcr-conversion-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_ycbcr_conversion_test.spv)
|
||||
add_test(NAME spirv-cross-msl-ycbcr-conversion-test-2
|
||||
COMMAND $<TARGET_FILE:spirv-cross-msl-ycbcr-conversion-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_ycbcr_conversion_test_2.spv)
|
||||
add_test(NAME spirv-cross-typed-id-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-typed-id-test>)
|
||||
add_test(NAME spirv-cross-debug-lines-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-debug-lines-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/debug-lines.spv)
|
||||
add_test(NAME spirv-cross-debug-info-test
|
||||
COMMAND $<TARGET_FILE:spirv-cross-debug-info-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/debug-info.spv)
|
||||
add_test(NAME spirv-cross-test
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-no-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-no-opt
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-metal
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-metal-no-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl-no-opt
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-hlsl
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-hlsl-no-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl-no-opt
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --opt --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-metal-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --metal --opt --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-msl
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-hlsl-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --hlsl --opt --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-hlsl
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-reflection
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --reflect --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-reflection
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-ue4
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --msl --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-ue4
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-ue4-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --msl --opt --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-ue4
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
add_test(NAME spirv-cross-test-ue4-no-opt
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --msl --parallel
|
||||
${spirv-cross-externals}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders-ue4-no-opt
|
||||
WORKING_DIRECTORY $<TARGET_FILE_DIR:spirv-cross>)
|
||||
endif()
|
||||
elseif(NOT ${PYTHONINTERP_FOUND})
|
||||
message(WARNING "SPIRV-Cross: Testing disabled. Could not find python3. If you have python3 installed try running "
|
||||
"cmake with -DPYTHON_EXECUTABLE:FILEPATH=/path/to/python3 to help it find the executable")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
114
thirdparty/SPIRV-Cross/GLSL.std.450.h
vendored
Normal file
114
thirdparty/SPIRV-Cross/GLSL.std.450.h
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright 2014-2016,2021 The Khronos Group, Inc.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
* STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
* HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
*/
|
||||
|
||||
#ifndef GLSLstd450_H
|
||||
#define GLSLstd450_H
|
||||
|
||||
static const int GLSLstd450Version = 100;
|
||||
static const int GLSLstd450Revision = 3;
|
||||
|
||||
enum GLSLstd450 {
|
||||
GLSLstd450Bad = 0, // Don't use
|
||||
|
||||
GLSLstd450Round = 1,
|
||||
GLSLstd450RoundEven = 2,
|
||||
GLSLstd450Trunc = 3,
|
||||
GLSLstd450FAbs = 4,
|
||||
GLSLstd450SAbs = 5,
|
||||
GLSLstd450FSign = 6,
|
||||
GLSLstd450SSign = 7,
|
||||
GLSLstd450Floor = 8,
|
||||
GLSLstd450Ceil = 9,
|
||||
GLSLstd450Fract = 10,
|
||||
|
||||
GLSLstd450Radians = 11,
|
||||
GLSLstd450Degrees = 12,
|
||||
GLSLstd450Sin = 13,
|
||||
GLSLstd450Cos = 14,
|
||||
GLSLstd450Tan = 15,
|
||||
GLSLstd450Asin = 16,
|
||||
GLSLstd450Acos = 17,
|
||||
GLSLstd450Atan = 18,
|
||||
GLSLstd450Sinh = 19,
|
||||
GLSLstd450Cosh = 20,
|
||||
GLSLstd450Tanh = 21,
|
||||
GLSLstd450Asinh = 22,
|
||||
GLSLstd450Acosh = 23,
|
||||
GLSLstd450Atanh = 24,
|
||||
GLSLstd450Atan2 = 25,
|
||||
|
||||
GLSLstd450Pow = 26,
|
||||
GLSLstd450Exp = 27,
|
||||
GLSLstd450Log = 28,
|
||||
GLSLstd450Exp2 = 29,
|
||||
GLSLstd450Log2 = 30,
|
||||
GLSLstd450Sqrt = 31,
|
||||
GLSLstd450InverseSqrt = 32,
|
||||
|
||||
GLSLstd450Determinant = 33,
|
||||
GLSLstd450MatrixInverse = 34,
|
||||
|
||||
GLSLstd450Modf = 35, // second operand needs an OpVariable to write to
|
||||
GLSLstd450ModfStruct = 36, // no OpVariable operand
|
||||
GLSLstd450FMin = 37,
|
||||
GLSLstd450UMin = 38,
|
||||
GLSLstd450SMin = 39,
|
||||
GLSLstd450FMax = 40,
|
||||
GLSLstd450UMax = 41,
|
||||
GLSLstd450SMax = 42,
|
||||
GLSLstd450FClamp = 43,
|
||||
GLSLstd450UClamp = 44,
|
||||
GLSLstd450SClamp = 45,
|
||||
GLSLstd450FMix = 46,
|
||||
GLSLstd450IMix = 47, // Reserved
|
||||
GLSLstd450Step = 48,
|
||||
GLSLstd450SmoothStep = 49,
|
||||
|
||||
GLSLstd450Fma = 50,
|
||||
GLSLstd450Frexp = 51, // second operand needs an OpVariable to write to
|
||||
GLSLstd450FrexpStruct = 52, // no OpVariable operand
|
||||
GLSLstd450Ldexp = 53,
|
||||
|
||||
GLSLstd450PackSnorm4x8 = 54,
|
||||
GLSLstd450PackUnorm4x8 = 55,
|
||||
GLSLstd450PackSnorm2x16 = 56,
|
||||
GLSLstd450PackUnorm2x16 = 57,
|
||||
GLSLstd450PackHalf2x16 = 58,
|
||||
GLSLstd450PackDouble2x32 = 59,
|
||||
GLSLstd450UnpackSnorm2x16 = 60,
|
||||
GLSLstd450UnpackUnorm2x16 = 61,
|
||||
GLSLstd450UnpackHalf2x16 = 62,
|
||||
GLSLstd450UnpackSnorm4x8 = 63,
|
||||
GLSLstd450UnpackUnorm4x8 = 64,
|
||||
GLSLstd450UnpackDouble2x32 = 65,
|
||||
|
||||
GLSLstd450Length = 66,
|
||||
GLSLstd450Distance = 67,
|
||||
GLSLstd450Cross = 68,
|
||||
GLSLstd450Normalize = 69,
|
||||
GLSLstd450FaceForward = 70,
|
||||
GLSLstd450Reflect = 71,
|
||||
GLSLstd450Refract = 72,
|
||||
|
||||
GLSLstd450FindILsb = 73,
|
||||
GLSLstd450FindSMsb = 74,
|
||||
GLSLstd450FindUMsb = 75,
|
||||
|
||||
GLSLstd450InterpolateAtCentroid = 76,
|
||||
GLSLstd450InterpolateAtSample = 77,
|
||||
GLSLstd450InterpolateAtOffset = 78,
|
||||
|
||||
GLSLstd450NMin = 79,
|
||||
GLSLstd450NMax = 80,
|
||||
GLSLstd450NClamp = 81,
|
||||
|
||||
GLSLstd450Count
|
||||
};
|
||||
|
||||
#endif // #ifndef GLSLstd450_H
|
||||
202
thirdparty/SPIRV-Cross/LICENSE
vendored
Normal file
202
thirdparty/SPIRV-Cross/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
208
thirdparty/SPIRV-Cross/LICENSES/Apache-2.0.txt
vendored
Normal file
208
thirdparty/SPIRV-Cross/LICENSES/Apache-2.0.txt
vendored
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
Apache License
|
||||
|
||||
Version 2.0, January 2004
|
||||
|
||||
http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION,
|
||||
AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution
|
||||
as defined by Sections 1 through 9 of this document.
|
||||
|
||||
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct
|
||||
or indirect, to cause the direction or management of such entity, whether
|
||||
by contract or otherwise, or (ii) ownership of fifty percent (50%) or more
|
||||
of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions
|
||||
granted by this License.
|
||||
|
||||
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation
|
||||
or translation of a Source form, including but not limited to compiled object
|
||||
code, generated documentation, and conversions to other media types.
|
||||
|
||||
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form,
|
||||
made available under the License, as indicated by a copyright notice that
|
||||
is included in or attached to the work (an example is provided in the Appendix
|
||||
below).
|
||||
|
||||
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form,
|
||||
that is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative
|
||||
Works shall not include works that remain separable from, or merely link (or
|
||||
bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative
|
||||
Works thereof, that is intentionally submitted to Licensor for inclusion in
|
||||
the Work by the copyright owner or by an individual or Legal Entity authorized
|
||||
to submit on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication
|
||||
sent to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor
|
||||
for the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently incorporated
|
||||
within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this
|
||||
License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||
no-charge, royalty-free, irrevocable copyright license to reproduce, prepare
|
||||
Derivative Works of, publicly display, publicly perform, sublicense, and distribute
|
||||
the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
||||
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
||||
license to make, have made, use, offer to sell, sell, import, and otherwise
|
||||
transfer the Work, where such license applies only to those patent claims
|
||||
licensable by such Contributor that are necessarily infringed by their Contribution(s)
|
||||
alone or by combination of their Contribution(s) with the Work to which such
|
||||
Contribution(s) was submitted. If You institute patent litigation against
|
||||
any entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that the Work or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses granted to You
|
||||
under this License for that Work shall terminate as of the date such litigation
|
||||
is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or
|
||||
Derivative Works thereof in any medium, with or without modifications, and
|
||||
in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or Derivative Works a copy
|
||||
of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices stating that
|
||||
You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source
|
||||
form of the Work, excluding those notices that do not pertain to any part
|
||||
of the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
||||
then any Derivative Works that You distribute must include a readable copy
|
||||
of the attribution notices contained within such NOTICE file, excluding those
|
||||
notices that do not pertain to any part of the Derivative Works, in at least
|
||||
one of the following places: within a NOTICE text file distributed as part
|
||||
of the Derivative Works; within the Source form or documentation, if provided
|
||||
along with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works
|
||||
that You distribute, alongside or as an addendum to the NOTICE text from the
|
||||
Work, provided that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction,
|
||||
or distribution of Your modifications, or for any such Derivative Works as
|
||||
a whole, provided Your use, reproduction, and distribution of the Work otherwise
|
||||
complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
||||
Contribution intentionally submitted for inclusion in the Work by You to the
|
||||
Licensor shall be under the terms and conditions of this License, without
|
||||
any additional terms or conditions. Notwithstanding the above, nothing herein
|
||||
shall supersede or modify the terms of any separate license agreement you
|
||||
may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names,
|
||||
trademarks, service marks, or product names of the Licensor, except as required
|
||||
for reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to
|
||||
in writing, Licensor provides the Work (and each Contributor provides its
|
||||
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied, including, without limitation, any warranties
|
||||
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR
|
||||
A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness
|
||||
of using or redistributing the Work and assume any risks associated with Your
|
||||
exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether
|
||||
in tort (including negligence), contract, or otherwise, unless required by
|
||||
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
||||
in writing, shall any Contributor be liable to You for damages, including
|
||||
any direct, indirect, special, incidental, or consequential damages of any
|
||||
character arising as a result of this License or out of the use or inability
|
||||
to use the Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all other commercial
|
||||
damages or losses), even if such Contributor has been advised of the possibility
|
||||
of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work
|
||||
or Derivative Works thereof, You may choose to offer, and charge a fee for,
|
||||
acceptance of support, warranty, indemnity, or other liability obligations
|
||||
and/or rights consistent with this License. However, in accepting such obligations,
|
||||
You may act only on Your own behalf and on Your sole responsibility, not on
|
||||
behalf of any other Contributor, and only if You agree to indemnify, defend,
|
||||
and hold each Contributor harmless for any liability incurred by, or claims
|
||||
asserted against, such Contributor by reason of your accepting any such warranty
|
||||
or additional liability. END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate
|
||||
notice, with the fields enclosed by brackets "[]" replaced with your own identifying
|
||||
information. (Don't include the brackets!) The text should be enclosed in
|
||||
the appropriate comment syntax for the file format. We also recommend that
|
||||
a file or class name and description of purpose be included on the same "printed
|
||||
page" as the copyright notice for easier identification within third-party
|
||||
archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
|
||||
limitations under the License.
|
||||
324
thirdparty/SPIRV-Cross/LICENSES/CC-BY-4.0.txt
vendored
Normal file
324
thirdparty/SPIRV-Cross/LICENSES/CC-BY-4.0.txt
vendored
Normal file
|
|
@ -0,0 +1,324 @@
|
|||
Creative Commons Attribution 4.0 International Creative Commons Corporation
|
||||
("Creative Commons") is not a law firm and does not provide legal services
|
||||
or legal advice. Distribution of Creative Commons public licenses does not
|
||||
create a lawyer-client or other relationship. Creative Commons makes its licenses
|
||||
and related information available on an "as-is" basis. Creative Commons gives
|
||||
no warranties regarding its licenses, any material licensed under their terms
|
||||
and conditions, or any related information. Creative Commons disclaims all
|
||||
liability for damages resulting from their use to the fullest extent possible.
|
||||
|
||||
Using Creative Commons Public Licenses
|
||||
|
||||
Creative Commons public licenses provide a standard set of terms and conditions
|
||||
that creators and other rights holders may use to share original works of
|
||||
authorship and other material subject to copyright and certain other rights
|
||||
specified in the public license below. The following considerations are for
|
||||
informational purposes only, are not exhaustive, and do not form part of our
|
||||
licenses.
|
||||
|
||||
Considerations for licensors: Our public licenses are intended for use by
|
||||
those authorized to give the public permission to use material in ways otherwise
|
||||
restricted by copyright and certain other rights. Our licenses are irrevocable.
|
||||
Licensors should read and understand the terms and conditions of the license
|
||||
they choose before applying it. Licensors should also secure all rights necessary
|
||||
before applying our licenses so that the public can reuse the material as
|
||||
expected. Licensors should clearly mark any material not subject to the license.
|
||||
This includes other CC-licensed material, or material used under an exception
|
||||
or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors
|
||||
|
||||
Considerations for the public: By using one of our public licenses, a licensor
|
||||
grants the public permission to use the licensed material under specified
|
||||
terms and conditions. If the licensor's permission is not necessary for any
|
||||
reason–for example, because of any applicable exception or limitation to copyright–then
|
||||
that use is not regulated by the license. Our licenses grant only permissions
|
||||
under copyright and certain other rights that a licensor has authority to
|
||||
grant. Use of the licensed material may still be restricted for other reasons,
|
||||
including because others have copyright or other rights in the material. A
|
||||
licensor may make special requests, such as asking that all changes be marked
|
||||
or described. Although not required by our licenses, you are encouraged to
|
||||
respect those requests where reasonable. More considerations for the public
|
||||
: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution
|
||||
4.0 International Public License
|
||||
|
||||
By exercising the Licensed Rights (defined below), You accept and agree to
|
||||
be bound by the terms and conditions of this Creative Commons Attribution
|
||||
4.0 International Public License ("Public License"). To the extent this Public
|
||||
License may be interpreted as a contract, You are granted the Licensed Rights
|
||||
in consideration of Your acceptance of these terms and conditions, and the
|
||||
Licensor grants You such rights in consideration of benefits the Licensor
|
||||
receives from making the Licensed Material available under these terms and
|
||||
conditions.
|
||||
|
||||
Section 1 – Definitions.
|
||||
|
||||
a. Adapted Material means material subject to Copyright and Similar Rights
|
||||
that is derived from or based upon the Licensed Material and in which the
|
||||
Licensed Material is translated, altered, arranged, transformed, or otherwise
|
||||
modified in a manner requiring permission under the Copyright and Similar
|
||||
Rights held by the Licensor. For purposes of this Public License, where the
|
||||
Licensed Material is a musical work, performance, or sound recording, Adapted
|
||||
Material is always produced where the Licensed Material is synched in timed
|
||||
relation with a moving image.
|
||||
|
||||
b. Adapter's License means the license You apply to Your Copyright and Similar
|
||||
Rights in Your contributions to Adapted Material in accordance with the terms
|
||||
and conditions of this Public License.
|
||||
|
||||
c. Copyright and Similar Rights means copyright and/or similar rights closely
|
||||
related to copyright including, without limitation, performance, broadcast,
|
||||
sound recording, and Sui Generis Database Rights, without regard to how the
|
||||
rights are labeled or categorized. For purposes of this Public License, the
|
||||
rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
|
||||
|
||||
d. Effective Technological Measures means those measures that, in the absence
|
||||
of proper authority, may not be circumvented under laws fulfilling obligations
|
||||
under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996,
|
||||
and/or similar international agreements.
|
||||
|
||||
e. Exceptions and Limitations means fair use, fair dealing, and/or any other
|
||||
exception or limitation to Copyright and Similar Rights that applies to Your
|
||||
use of the Licensed Material.
|
||||
|
||||
f. Licensed Material means the artistic or literary work, database, or other
|
||||
material to which the Licensor applied this Public License.
|
||||
|
||||
g. Licensed Rights means the rights granted to You subject to the terms and
|
||||
conditions of this Public License, which are limited to all Copyright and
|
||||
Similar Rights that apply to Your use of the Licensed Material and that the
|
||||
Licensor has authority to license.
|
||||
|
||||
h. Licensor means the individual(s) or entity(ies) granting rights under this
|
||||
Public License.
|
||||
|
||||
i. Share means to provide material to the public by any means or process that
|
||||
requires permission under the Licensed Rights, such as reproduction, public
|
||||
display, public performance, distribution, dissemination, communication, or
|
||||
importation, and to make material available to the public including in ways
|
||||
that members of the public may access the material from a place and at a time
|
||||
individually chosen by them.
|
||||
|
||||
j. Sui Generis Database Rights means rights other than copyright resulting
|
||||
from Directive 96/9/EC of the European Parliament and of the Council of 11
|
||||
March 1996 on the legal protection of databases, as amended and/or succeeded,
|
||||
as well as other essentially equivalent rights anywhere in the world.
|
||||
|
||||
k. You means the individual or entity exercising the Licensed Rights under
|
||||
this Public License. Your has a corresponding meaning.
|
||||
|
||||
Section 2 – Scope.
|
||||
|
||||
a. License grant.
|
||||
|
||||
1. Subject to the terms and conditions of this Public License, the Licensor
|
||||
hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive,
|
||||
irrevocable license to exercise the Licensed Rights in the Licensed Material
|
||||
to:
|
||||
|
||||
A. reproduce and Share the Licensed Material, in whole or in part; and
|
||||
|
||||
B. produce, reproduce, and Share Adapted Material.
|
||||
|
||||
2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions
|
||||
and Limitations apply to Your use, this Public License does not apply, and
|
||||
You do not need to comply with its terms and conditions.
|
||||
|
||||
3. Term. The term of this Public License is specified in Section 6(a).
|
||||
|
||||
4. Media and formats; technical modifications allowed. The Licensor authorizes
|
||||
You to exercise the Licensed Rights in all media and formats whether now known
|
||||
or hereafter created, and to make technical modifications necessary to do
|
||||
so. The Licensor waives and/or agrees not to assert any right or authority
|
||||
to forbid You from making technical modifications necessary to exercise the
|
||||
Licensed Rights, including technical modifications necessary to circumvent
|
||||
Effective Technological Measures. For purposes of this Public License, simply
|
||||
making modifications authorized by this Section 2(a)(4) never produces Adapted
|
||||
Material.
|
||||
|
||||
5. Downstream recipients.
|
||||
|
||||
A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed
|
||||
Material automatically receives an offer from the Licensor to exercise the
|
||||
Licensed Rights under the terms and conditions of this Public License.
|
||||
|
||||
B. No downstream restrictions. You may not offer or impose any additional
|
||||
or different terms or conditions on, or apply any Effective Technological
|
||||
Measures to, the Licensed Material if doing so restricts exercise of the Licensed
|
||||
Rights by any recipient of the Licensed Material.
|
||||
|
||||
6. No endorsement. Nothing in this Public License constitutes or may be construed
|
||||
as permission to assert or imply that You are, or that Your use of the Licensed
|
||||
Material is, connected with, or sponsored, endorsed, or granted official status
|
||||
by, the Licensor or others designated to receive attribution as provided in
|
||||
Section 3(a)(1)(A)(i).
|
||||
|
||||
b. Other rights.
|
||||
|
||||
1. Moral rights, such as the right of integrity, are not licensed under this
|
||||
Public License, nor are publicity, privacy, and/or other similar personality
|
||||
rights; however, to the extent possible, the Licensor waives and/or agrees
|
||||
not to assert any such rights held by the Licensor to the limited extent necessary
|
||||
to allow You to exercise the Licensed Rights, but not otherwise.
|
||||
|
||||
2. Patent and trademark rights are not licensed under this Public License.
|
||||
|
||||
3. To the extent possible, the Licensor waives any right to collect royalties
|
||||
from You for the exercise of the Licensed Rights, whether directly or through
|
||||
a collecting society under any voluntary or waivable statutory or compulsory
|
||||
licensing scheme. In all other cases the Licensor expressly reserves any right
|
||||
to collect such royalties.
|
||||
|
||||
Section 3 – License Conditions.
|
||||
|
||||
Your exercise of the Licensed Rights is expressly made subject to the following
|
||||
conditions.
|
||||
|
||||
a. Attribution.
|
||||
|
||||
1. If You Share the Licensed Material (including in modified form), You must:
|
||||
|
||||
A. retain the following if it is supplied by the Licensor with the Licensed
|
||||
Material:
|
||||
|
||||
i. identification of the creator(s) of the Licensed Material and any others
|
||||
designated to receive attribution, in any reasonable manner requested by the
|
||||
Licensor (including by pseudonym if designated);
|
||||
|
||||
ii. a copyright notice;
|
||||
|
||||
iii. a notice that refers to this Public License;
|
||||
|
||||
iv. a notice that refers to the disclaimer of warranties;
|
||||
|
||||
v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
|
||||
|
||||
B. indicate if You modified the Licensed Material and retain an indication
|
||||
of any previous modifications; and
|
||||
|
||||
C. indicate the Licensed Material is licensed under this Public License, and
|
||||
include the text of, or the URI or hyperlink to, this Public License.
|
||||
|
||||
2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner
|
||||
based on the medium, means, and context in which You Share the Licensed Material.
|
||||
For example, it may be reasonable to satisfy the conditions by providing a
|
||||
URI or hyperlink to a resource that includes the required information.
|
||||
|
||||
3. If requested by the Licensor, You must remove any of the information required
|
||||
by Section 3(a)(1)(A) to the extent reasonably practicable.
|
||||
|
||||
4. If You Share Adapted Material You produce, the Adapter's License You apply
|
||||
must not prevent recipients of the Adapted Material from complying with this
|
||||
Public License.
|
||||
|
||||
Section 4 – Sui Generis Database Rights.
|
||||
|
||||
Where the Licensed Rights include Sui Generis Database Rights that apply to
|
||||
Your use of the Licensed Material:
|
||||
|
||||
a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract,
|
||||
reuse, reproduce, and Share all or a substantial portion of the contents of
|
||||
the database;
|
||||
|
||||
b. if You include all or a substantial portion of the database contents in
|
||||
a database in which You have Sui Generis Database Rights, then the database
|
||||
in which You have Sui Generis Database Rights (but not its individual contents)
|
||||
is Adapted Material; and
|
||||
|
||||
c. You must comply with the conditions in Section 3(a) if You Share all or
|
||||
a substantial portion of the contents of the database.
|
||||
|
||||
For the avoidance of doubt, this Section 4 supplements and does not replace
|
||||
Your obligations under this Public License where the Licensed Rights include
|
||||
other Copyright and Similar Rights.
|
||||
|
||||
Section 5 – Disclaimer of Warranties and Limitation of Liability.
|
||||
|
||||
a. Unless otherwise separately undertaken by the Licensor, to the extent possible,
|
||||
the Licensor offers the Licensed Material as-is and as-available, and makes
|
||||
no representations or warranties of any kind concerning the Licensed Material,
|
||||
whether express, implied, statutory, or other. This includes, without limitation,
|
||||
warranties of title, merchantability, fitness for a particular purpose, non-infringement,
|
||||
absence of latent or other defects, accuracy, or the presence or absence of
|
||||
errors, whether or not known or discoverable. Where disclaimers of warranties
|
||||
are not allowed in full or in part, this disclaimer may not apply to You.
|
||||
|
||||
b. To the extent possible, in no event will the Licensor be liable to You
|
||||
on any legal theory (including, without limitation, negligence) or otherwise
|
||||
for any direct, special, indirect, incidental, consequential, punitive, exemplary,
|
||||
or other losses, costs, expenses, or damages arising out of this Public License
|
||||
or use of the Licensed Material, even if the Licensor has been advised of
|
||||
the possibility of such losses, costs, expenses, or damages. Where a limitation
|
||||
of liability is not allowed in full or in part, this limitation may not apply
|
||||
to You.
|
||||
|
||||
c. The disclaimer of warranties and limitation of liability provided above
|
||||
shall be interpreted in a manner that, to the extent possible, most closely
|
||||
approximates an absolute disclaimer and waiver of all liability.
|
||||
|
||||
Section 6 – Term and Termination.
|
||||
|
||||
a. This Public License applies for the term of the Copyright and Similar Rights
|
||||
licensed here. However, if You fail to comply with this Public License, then
|
||||
Your rights under this Public License terminate automatically.
|
||||
|
||||
b. Where Your right to use the Licensed Material has terminated under Section
|
||||
6(a), it reinstates:
|
||||
|
||||
1. automatically as of the date the violation is cured, provided it is cured
|
||||
within 30 days of Your discovery of the violation; or
|
||||
|
||||
2. upon express reinstatement by the Licensor.
|
||||
|
||||
c. For the avoidance of doubt, this Section 6(b) does not affect any right
|
||||
the Licensor may have to seek remedies for Your violations of this Public
|
||||
License.
|
||||
|
||||
d. For the avoidance of doubt, the Licensor may also offer the Licensed Material
|
||||
under separate terms or conditions or stop distributing the Licensed Material
|
||||
at any time; however, doing so will not terminate this Public License.
|
||||
|
||||
e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
|
||||
|
||||
Section 7 – Other Terms and Conditions.
|
||||
|
||||
a. The Licensor shall not be bound by any additional or different terms or
|
||||
conditions communicated by You unless expressly agreed.
|
||||
|
||||
b. Any arrangements, understandings, or agreements regarding the Licensed
|
||||
Material not stated herein are separate from and independent of the terms
|
||||
and conditions of this Public License.
|
||||
|
||||
Section 8 – Interpretation.
|
||||
|
||||
a. For the avoidance of doubt, this Public License does not, and shall not
|
||||
be interpreted to, reduce, limit, restrict, or impose conditions on any use
|
||||
of the Licensed Material that could lawfully be made without permission under
|
||||
this Public License.
|
||||
|
||||
b. To the extent possible, if any provision of this Public License is deemed
|
||||
unenforceable, it shall be automatically reformed to the minimum extent necessary
|
||||
to make it enforceable. If the provision cannot be reformed, it shall be severed
|
||||
from this Public License without affecting the enforceability of the remaining
|
||||
terms and conditions.
|
||||
|
||||
c. No term or condition of this Public License will be waived and no failure
|
||||
to comply consented to unless expressly agreed to by the Licensor.
|
||||
|
||||
d. Nothing in this Public License constitutes or may be interpreted as a limitation
|
||||
upon, or waiver of, any privileges and immunities that apply to the Licensor
|
||||
or You, including from the legal processes of any jurisdiction or authority.
|
||||
|
||||
Creative Commons is not a party to its public licenses. Notwithstanding, Creative
|
||||
Commons may elect to apply one of its public licenses to material it publishes
|
||||
and in those instances will be considered the "Licensor." The text of the
|
||||
Creative Commons public licenses is dedicated to the public domain under the
|
||||
CC0 Public Domain Dedication. Except for the limited purpose of indicating
|
||||
that material is shared under a Creative Commons public license or as otherwise
|
||||
permitted by the Creative Commons policies published at creativecommons.org/policies,
|
||||
Creative Commons does not authorize the use of the trademark "Creative Commons"
|
||||
or any other trademark or logo of Creative Commons without its prior written
|
||||
consent including, without limitation, in connection with any unauthorized
|
||||
modifications to any of its public licenses or any other arrangements, understandings,
|
||||
or agreements concerning use of licensed material. For the avoidance of doubt,
|
||||
this paragraph does not form part of the public licenses.
|
||||
|
||||
Creative Commons may be contacted at creativecommons.org.
|
||||
23
thirdparty/SPIRV-Cross/LICENSES/LicenseRef-KhronosFreeUse.txt
vendored
Normal file
23
thirdparty/SPIRV-Cross/LICENSES/LicenseRef-KhronosFreeUse.txt
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Copyright (c) 2014-2020 The Khronos Group Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and/or associated documentation files (the "Materials"),
|
||||
to deal in the Materials without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Materials, and to permit persons to whom the
|
||||
Materials are furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Materials.
|
||||
|
||||
MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
|
||||
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
IN THE MATERIALS.
|
||||
19
thirdparty/SPIRV-Cross/LICENSES/MIT.txt
vendored
Normal file
19
thirdparty/SPIRV-Cross/LICENSES/MIT.txt
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
MIT License Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
171
thirdparty/SPIRV-Cross/NonSemanticShaderDebugInfo100.h
vendored
Normal file
171
thirdparty/SPIRV-Cross/NonSemanticShaderDebugInfo100.h
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
// Copyright (c) 2018-2024 The Khronos Group Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and/or associated documentation files (the "Materials"),
|
||||
// to deal in the Materials without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Materials, and to permit persons to whom the
|
||||
// Materials are furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Materials.
|
||||
//
|
||||
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
// STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
// HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
//
|
||||
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
// IN THE MATERIALS.
|
||||
|
||||
#ifndef SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
|
||||
#define SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
NonSemanticShaderDebugInfo100Version = 100,
|
||||
NonSemanticShaderDebugInfo100Version_BitWidthPadding = 0x7fffffff
|
||||
};
|
||||
enum {
|
||||
NonSemanticShaderDebugInfo100Revision = 6,
|
||||
NonSemanticShaderDebugInfo100Revision_BitWidthPadding = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100Instructions {
|
||||
NonSemanticShaderDebugInfo100DebugInfoNone = 0,
|
||||
NonSemanticShaderDebugInfo100DebugCompilationUnit = 1,
|
||||
NonSemanticShaderDebugInfo100DebugTypeBasic = 2,
|
||||
NonSemanticShaderDebugInfo100DebugTypePointer = 3,
|
||||
NonSemanticShaderDebugInfo100DebugTypeQualifier = 4,
|
||||
NonSemanticShaderDebugInfo100DebugTypeArray = 5,
|
||||
NonSemanticShaderDebugInfo100DebugTypeVector = 6,
|
||||
NonSemanticShaderDebugInfo100DebugTypedef = 7,
|
||||
NonSemanticShaderDebugInfo100DebugTypeFunction = 8,
|
||||
NonSemanticShaderDebugInfo100DebugTypeEnum = 9,
|
||||
NonSemanticShaderDebugInfo100DebugTypeComposite = 10,
|
||||
NonSemanticShaderDebugInfo100DebugTypeMember = 11,
|
||||
NonSemanticShaderDebugInfo100DebugTypeInheritance = 12,
|
||||
NonSemanticShaderDebugInfo100DebugTypePtrToMember = 13,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplate = 14,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplateParameter = 15,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplateTemplateParameter = 16,
|
||||
NonSemanticShaderDebugInfo100DebugTypeTemplateParameterPack = 17,
|
||||
NonSemanticShaderDebugInfo100DebugGlobalVariable = 18,
|
||||
NonSemanticShaderDebugInfo100DebugFunctionDeclaration = 19,
|
||||
NonSemanticShaderDebugInfo100DebugFunction = 20,
|
||||
NonSemanticShaderDebugInfo100DebugLexicalBlock = 21,
|
||||
NonSemanticShaderDebugInfo100DebugLexicalBlockDiscriminator = 22,
|
||||
NonSemanticShaderDebugInfo100DebugScope = 23,
|
||||
NonSemanticShaderDebugInfo100DebugNoScope = 24,
|
||||
NonSemanticShaderDebugInfo100DebugInlinedAt = 25,
|
||||
NonSemanticShaderDebugInfo100DebugLocalVariable = 26,
|
||||
NonSemanticShaderDebugInfo100DebugInlinedVariable = 27,
|
||||
NonSemanticShaderDebugInfo100DebugDeclare = 28,
|
||||
NonSemanticShaderDebugInfo100DebugValue = 29,
|
||||
NonSemanticShaderDebugInfo100DebugOperation = 30,
|
||||
NonSemanticShaderDebugInfo100DebugExpression = 31,
|
||||
NonSemanticShaderDebugInfo100DebugMacroDef = 32,
|
||||
NonSemanticShaderDebugInfo100DebugMacroUndef = 33,
|
||||
NonSemanticShaderDebugInfo100DebugImportedEntity = 34,
|
||||
NonSemanticShaderDebugInfo100DebugSource = 35,
|
||||
NonSemanticShaderDebugInfo100DebugFunctionDefinition = 101,
|
||||
NonSemanticShaderDebugInfo100DebugSourceContinued = 102,
|
||||
NonSemanticShaderDebugInfo100DebugLine = 103,
|
||||
NonSemanticShaderDebugInfo100DebugNoLine = 104,
|
||||
NonSemanticShaderDebugInfo100DebugBuildIdentifier = 105,
|
||||
NonSemanticShaderDebugInfo100DebugStoragePath = 106,
|
||||
NonSemanticShaderDebugInfo100DebugEntryPoint = 107,
|
||||
NonSemanticShaderDebugInfo100DebugTypeMatrix = 108,
|
||||
NonSemanticShaderDebugInfo100InstructionsMax = 0x7fffffff
|
||||
};
|
||||
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugInfoFlags {
|
||||
NonSemanticShaderDebugInfo100None = 0x0000,
|
||||
NonSemanticShaderDebugInfo100FlagIsProtected = 0x01,
|
||||
NonSemanticShaderDebugInfo100FlagIsPrivate = 0x02,
|
||||
NonSemanticShaderDebugInfo100FlagIsPublic = 0x03,
|
||||
NonSemanticShaderDebugInfo100FlagIsLocal = 0x04,
|
||||
NonSemanticShaderDebugInfo100FlagIsDefinition = 0x08,
|
||||
NonSemanticShaderDebugInfo100FlagFwdDecl = 0x10,
|
||||
NonSemanticShaderDebugInfo100FlagArtificial = 0x20,
|
||||
NonSemanticShaderDebugInfo100FlagExplicit = 0x40,
|
||||
NonSemanticShaderDebugInfo100FlagPrototyped = 0x80,
|
||||
NonSemanticShaderDebugInfo100FlagObjectPointer = 0x100,
|
||||
NonSemanticShaderDebugInfo100FlagStaticMember = 0x200,
|
||||
NonSemanticShaderDebugInfo100FlagIndirectVariable = 0x400,
|
||||
NonSemanticShaderDebugInfo100FlagLValueReference = 0x800,
|
||||
NonSemanticShaderDebugInfo100FlagRValueReference = 0x1000,
|
||||
NonSemanticShaderDebugInfo100FlagIsOptimized = 0x2000,
|
||||
NonSemanticShaderDebugInfo100FlagIsEnumClass = 0x4000,
|
||||
NonSemanticShaderDebugInfo100FlagTypePassByValue = 0x8000,
|
||||
NonSemanticShaderDebugInfo100FlagTypePassByReference = 0x10000,
|
||||
NonSemanticShaderDebugInfo100FlagUnknownPhysicalLayout = 0x20000,
|
||||
NonSemanticShaderDebugInfo100DebugInfoFlagsMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100BuildIdentifierFlags {
|
||||
NonSemanticShaderDebugInfo100IdentifierPossibleDuplicates = 0x01,
|
||||
NonSemanticShaderDebugInfo100BuildIdentifierFlagsMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugBaseTypeAttributeEncoding {
|
||||
NonSemanticShaderDebugInfo100Unspecified = 0,
|
||||
NonSemanticShaderDebugInfo100Address = 1,
|
||||
NonSemanticShaderDebugInfo100Boolean = 2,
|
||||
NonSemanticShaderDebugInfo100Float = 3,
|
||||
NonSemanticShaderDebugInfo100Signed = 4,
|
||||
NonSemanticShaderDebugInfo100SignedChar = 5,
|
||||
NonSemanticShaderDebugInfo100Unsigned = 6,
|
||||
NonSemanticShaderDebugInfo100UnsignedChar = 7,
|
||||
NonSemanticShaderDebugInfo100DebugBaseTypeAttributeEncodingMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugCompositeType {
|
||||
NonSemanticShaderDebugInfo100Class = 0,
|
||||
NonSemanticShaderDebugInfo100Structure = 1,
|
||||
NonSemanticShaderDebugInfo100Union = 2,
|
||||
NonSemanticShaderDebugInfo100DebugCompositeTypeMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugTypeQualifier {
|
||||
NonSemanticShaderDebugInfo100ConstType = 0,
|
||||
NonSemanticShaderDebugInfo100VolatileType = 1,
|
||||
NonSemanticShaderDebugInfo100RestrictType = 2,
|
||||
NonSemanticShaderDebugInfo100AtomicType = 3,
|
||||
NonSemanticShaderDebugInfo100DebugTypeQualifierMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugOperation {
|
||||
NonSemanticShaderDebugInfo100Deref = 0,
|
||||
NonSemanticShaderDebugInfo100Plus = 1,
|
||||
NonSemanticShaderDebugInfo100Minus = 2,
|
||||
NonSemanticShaderDebugInfo100PlusUconst = 3,
|
||||
NonSemanticShaderDebugInfo100BitPiece = 4,
|
||||
NonSemanticShaderDebugInfo100Swap = 5,
|
||||
NonSemanticShaderDebugInfo100Xderef = 6,
|
||||
NonSemanticShaderDebugInfo100StackValue = 7,
|
||||
NonSemanticShaderDebugInfo100Constu = 8,
|
||||
NonSemanticShaderDebugInfo100Fragment = 9,
|
||||
NonSemanticShaderDebugInfo100DebugOperationMax = 0x7fffffff
|
||||
};
|
||||
|
||||
enum NonSemanticShaderDebugInfo100DebugImportedEntity {
|
||||
NonSemanticShaderDebugInfo100ImportedModule = 0,
|
||||
NonSemanticShaderDebugInfo100ImportedDeclaration = 1,
|
||||
NonSemanticShaderDebugInfo100DebugImportedEntityMax = 0x7fffffff
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SPIRV_UNIFIED1_NonSemanticShaderDebugInfo100_H_
|
||||
558
thirdparty/SPIRV-Cross/README.md
vendored
Normal file
558
thirdparty/SPIRV-Cross/README.md
vendored
Normal file
|
|
@ -0,0 +1,558 @@
|
|||
<!--
|
||||
Copyright 2020-2021 The Khronos Group, Inc.
|
||||
SPDX-License-Identifier: CC-BY-4.0
|
||||
-->
|
||||
|
||||
# SPIRV-Cross
|
||||
|
||||
SPIRV-Cross is a tool designed for parsing and converting SPIR-V to other shader languages.
|
||||
|
||||
[](https://github.com/KhronosGroup/SPIRV-Cross/actions/workflows/main.yml)
|
||||
[](https://ci.appveyor.com/project/HansKristian-Work/SPIRV-Cross)
|
||||
|
||||
## Features
|
||||
|
||||
- Convert SPIR-V to readable, usable and efficient GLSL
|
||||
- Convert SPIR-V to readable, usable and efficient Metal Shading Language (MSL)
|
||||
- Convert SPIR-V to readable, usable and efficient HLSL
|
||||
- Convert SPIR-V to a JSON reflection format
|
||||
- Convert SPIR-V to debuggable C++ [DEPRECATED]
|
||||
- Reflection API to simplify the creation of Vulkan pipeline layouts
|
||||
- Reflection API to modify and tweak OpDecorations
|
||||
- Supports "all" of vertex, fragment, tessellation, geometry and compute shaders.
|
||||
|
||||
SPIRV-Cross tries hard to emit readable and clean output from the SPIR-V.
|
||||
The goal is to emit GLSL or MSL that looks like it was written by a human and not awkward IR/assembly-like code.
|
||||
|
||||
NOTE: Individual features are expected to be mostly complete, but it is possible that certain obscure GLSL features are not yet supported.
|
||||
However, most missing features are expected to be "trivial" improvements at this stage.
|
||||
|
||||
## Building
|
||||
|
||||
SPIRV-Cross has been tested on Linux, iOS/OSX, Windows and Android. CMake is the main build system.
|
||||
|
||||
### NOTE: main branch rename
|
||||
|
||||
On 2023-01-12, `master` was renamed to `main` as per Khronos policy.
|
||||
|
||||
### Linux and macOS
|
||||
|
||||
Building with CMake is recommended, as it is the only build system which is tested in continuous integration.
|
||||
It is also the only build system which has install commands and other useful build system features.
|
||||
|
||||
However, you can just run `make` on the command line as a fallback if you only care about the CLI tool.
|
||||
|
||||
A non-ancient GCC (4.8+) or Clang (3.x+) compiler is required as SPIRV-Cross uses C++11 extensively.
|
||||
|
||||
### Windows
|
||||
|
||||
Building with CMake is recommended, which is the only way to target MSVC.
|
||||
MinGW-w64 based compilation works with `make` as a fallback.
|
||||
|
||||
### Android
|
||||
|
||||
SPIRV-Cross is only useful as a library here. Use the CMake build to link SPIRV-Cross to your project.
|
||||
|
||||
### C++ exceptions
|
||||
|
||||
The make and CMake build flavors offer the option to treat exceptions as assertions. To disable exceptions for make just append `SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS=1` to the command line. For CMake append `-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS=ON`. By default exceptions are enabled.
|
||||
|
||||
### Static, shared and CLI
|
||||
|
||||
You can use `-DSPIRV_CROSS_STATIC=ON/OFF` `-DSPIRV_CROSS_SHARED=ON/OFF` `-DSPIRV_CROSS_CLI=ON/OFF` to control which modules are built (and installed).
|
||||
|
||||
### Installing SPIRV-Cross (vcpkg)
|
||||
|
||||
Alternatively, you can build and install SPIRV-Cross using [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
||||
|
||||
```
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
./vcpkg install spirv-cross
|
||||
```
|
||||
|
||||
The SPIRV-Cross port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
## Usage
|
||||
|
||||
### Using the C++ API
|
||||
|
||||
The C++ API is the main API for SPIRV-Cross. For more in-depth documentation than what's provided in this README,
|
||||
please have a look at the [Wiki](https://github.com/KhronosGroup/SPIRV-Cross/wiki).
|
||||
**NOTE**: This API is not guaranteed to be ABI-stable, and it is highly recommended to link against this API statically.
|
||||
The API is generally quite stable, but it can change over time, see the C API for more stability.
|
||||
|
||||
To perform reflection and convert to other shader languages you can use the SPIRV-Cross API.
|
||||
For example:
|
||||
|
||||
```c++
|
||||
#include "spirv_glsl.hpp"
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
extern std::vector<uint32_t> load_spirv_file();
|
||||
|
||||
int main()
|
||||
{
|
||||
// Read SPIR-V from disk or similar.
|
||||
std::vector<uint32_t> spirv_binary = load_spirv_file();
|
||||
|
||||
spirv_cross::CompilerGLSL glsl(std::move(spirv_binary));
|
||||
|
||||
// The SPIR-V is now parsed, and we can perform reflection on it.
|
||||
spirv_cross::ShaderResources resources = glsl.get_shader_resources();
|
||||
|
||||
// Get all sampled images in the shader.
|
||||
for (auto &resource : resources.sampled_images)
|
||||
{
|
||||
unsigned set = glsl.get_decoration(resource.id, spv::DecorationDescriptorSet);
|
||||
unsigned binding = glsl.get_decoration(resource.id, spv::DecorationBinding);
|
||||
printf("Image %s at set = %u, binding = %u\n", resource.name.c_str(), set, binding);
|
||||
|
||||
// Modify the decoration to prepare it for GLSL.
|
||||
glsl.unset_decoration(resource.id, spv::DecorationDescriptorSet);
|
||||
|
||||
// Some arbitrary remapping if we want.
|
||||
glsl.set_decoration(resource.id, spv::DecorationBinding, set * 16 + binding);
|
||||
}
|
||||
|
||||
// Set some options.
|
||||
spirv_cross::CompilerGLSL::Options options;
|
||||
options.version = 310;
|
||||
options.es = true;
|
||||
glsl.set_common_options(options);
|
||||
|
||||
// Compile to GLSL, ready to give to GL driver.
|
||||
std::string source = glsl.compile();
|
||||
}
|
||||
```
|
||||
|
||||
### Using the C API wrapper
|
||||
|
||||
To facilitate C compatibility and compatibility with foreign programming languages, a C89-compatible API wrapper is provided. Unlike the C++ API,
|
||||
the goal of this wrapper is to be fully stable, both API and ABI-wise.
|
||||
This is the only interface which is supported when building SPIRV-Cross as a shared library.
|
||||
|
||||
An important point of the wrapper is that all memory allocations are contained in the `spvc_context`.
|
||||
This simplifies the use of the API greatly. However, you should destroy the context as soon as reasonable,
|
||||
or use `spvc_context_release_allocations()` if you intend to reuse the `spvc_context` object again soon.
|
||||
|
||||
Most functions return a `spvc_result`, where `SPVC_SUCCESS` is the only success code.
|
||||
For brevity, the code below does not do any error checking.
|
||||
|
||||
```c
|
||||
#include <spirv_cross_c.h>
|
||||
|
||||
const SpvId *spirv = get_spirv_data();
|
||||
size_t word_count = get_spirv_word_count();
|
||||
|
||||
spvc_context context = NULL;
|
||||
spvc_parsed_ir ir = NULL;
|
||||
spvc_compiler compiler_glsl = NULL;
|
||||
spvc_compiler_options options = NULL;
|
||||
spvc_resources resources = NULL;
|
||||
const spvc_reflected_resource *list = NULL;
|
||||
const char *result = NULL;
|
||||
size_t count;
|
||||
size_t i;
|
||||
|
||||
// Create context.
|
||||
spvc_context_create(&context);
|
||||
|
||||
// Set debug callback.
|
||||
spvc_context_set_error_callback(context, error_callback, userdata);
|
||||
|
||||
// Parse the SPIR-V.
|
||||
spvc_context_parse_spirv(context, spirv, word_count, &ir);
|
||||
|
||||
// Hand it off to a compiler instance and give it ownership of the IR.
|
||||
spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler_glsl);
|
||||
|
||||
// Do some basic reflection.
|
||||
spvc_compiler_create_shader_resources(compiler_glsl, &resources);
|
||||
spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, &list, &count);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
printf("ID: %u, BaseTypeID: %u, TypeID: %u, Name: %s\n", list[i].id, list[i].base_type_id, list[i].type_id,
|
||||
list[i].name);
|
||||
printf(" Set: %u, Binding: %u\n",
|
||||
spvc_compiler_get_decoration(compiler_glsl, list[i].id, SpvDecorationDescriptorSet),
|
||||
spvc_compiler_get_decoration(compiler_glsl, list[i].id, SpvDecorationBinding));
|
||||
}
|
||||
|
||||
// Modify options.
|
||||
spvc_compiler_create_compiler_options(compiler_glsl, &options);
|
||||
spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_GLSL_VERSION, 330);
|
||||
spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_FALSE);
|
||||
spvc_compiler_install_compiler_options(compiler_glsl, options);
|
||||
|
||||
spvc_compiler_compile(compiler_glsl, &result);
|
||||
printf("Cross-compiled source: %s\n", result);
|
||||
|
||||
// Frees all memory we allocated so far.
|
||||
spvc_context_destroy(context);
|
||||
```
|
||||
|
||||
### Linking
|
||||
|
||||
#### CMake add_subdirectory()
|
||||
|
||||
This is the recommended way if you are using CMake and want to link against SPIRV-Cross statically.
|
||||
|
||||
#### Integrating SPIRV-Cross in a custom build system
|
||||
|
||||
To add SPIRV-Cross to your own codebase, just copy the source and header files from root directory
|
||||
and build the relevant .cpp files you need. Make sure to build with C++11 support, e.g. `-std=c++11` in GCC and Clang.
|
||||
Alternatively, the Makefile generates a libspirv-cross.a static library during build that can be linked in.
|
||||
|
||||
#### Linking against SPIRV-Cross as a system library
|
||||
|
||||
It is possible to link against SPIRV-Cross when it is installed as a system library,
|
||||
which would be mostly relevant for Unix-like platforms.
|
||||
|
||||
##### pkg-config
|
||||
|
||||
For Unix-based systems, a pkg-config is installed for the C API, e.g.:
|
||||
|
||||
```
|
||||
$ pkg-config spirv-cross-c-shared --libs --cflags
|
||||
-I/usr/local/include/spirv_cross -L/usr/local/lib -lspirv-cross-c-shared
|
||||
```
|
||||
|
||||
##### CMake
|
||||
|
||||
If the project is installed, it can be found with `find_package()`, e.g.:
|
||||
|
||||
```
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
project(Test LANGUAGES C)
|
||||
|
||||
find_package(spirv_cross_c_shared)
|
||||
if (spirv_cross_c_shared_FOUND)
|
||||
message(STATUS "Found SPIRV-Cross C API! :)")
|
||||
else()
|
||||
message(STATUS "Could not find SPIRV-Cross C API! :(")
|
||||
endif()
|
||||
|
||||
add_executable(test test.c)
|
||||
target_link_libraries(test spirv-cross-c-shared)
|
||||
```
|
||||
|
||||
test.c:
|
||||
```c
|
||||
#include <spirv_cross_c.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
spvc_context context;
|
||||
spvc_context_create(&context);
|
||||
spvc_context_destroy(context);
|
||||
}
|
||||
```
|
||||
|
||||
### CLI
|
||||
|
||||
The CLI is suitable for basic cross-compilation tasks, but it cannot support the full flexibility that the API can.
|
||||
Some examples below.
|
||||
|
||||
#### Creating a SPIR-V file from GLSL with glslang
|
||||
|
||||
```
|
||||
glslangValidator -H -V -o test.spv test.frag
|
||||
```
|
||||
|
||||
NOTE: This assumes Vulkan GLSL input. In general, only modern GLSL (#version 330+ for desktop) can be compiled to SPIR-V.
|
||||
Typically when cross compiling GLSL, you start with modern GLSL and cross compile to older targets for compatibility,
|
||||
not the other way around.
|
||||
|
||||
#### Converting a SPIR-V file to GLSL ES
|
||||
|
||||
```
|
||||
glslangValidator -H -V -o test.spv shaders/comp/basic.comp
|
||||
./spirv-cross --version 310 --es test.spv
|
||||
```
|
||||
|
||||
#### Converting to desktop GLSL
|
||||
|
||||
```
|
||||
glslangValidator -H -V -o test.spv shaders/comp/basic.comp
|
||||
./spirv-cross --version 330 --no-es test.spv --output test.comp
|
||||
```
|
||||
|
||||
#### Disable prettifying optimizations
|
||||
|
||||
```
|
||||
glslangValidator -H -V -o test.spv shaders/comp/basic.comp
|
||||
./spirv-cross --version 310 --es test.spv --output test.comp --force-temporary
|
||||
```
|
||||
|
||||
### Using shaders generated from C++ backend
|
||||
|
||||
Please see `samples/cpp` where some GLSL shaders are compiled to SPIR-V, decompiled to C++ and run with test data.
|
||||
Reading through the samples should explain how to use the C++ interface.
|
||||
A simple Makefile is included to build all shaders in the directory.
|
||||
|
||||
### Implementation notes
|
||||
|
||||
When using SPIR-V and SPIRV-Cross as an intermediate step for cross-compiling between high level languages there are some considerations to take into account,
|
||||
as not all features used by one high-level language are necessarily supported natively by the target shader language.
|
||||
SPIRV-Cross aims to provide the tools needed to handle these scenarios in a clean and robust way, but some manual action is required to maintain compatibility.
|
||||
|
||||
#### HLSL source to GLSL
|
||||
|
||||
##### HLSL entry points
|
||||
|
||||
When using SPIR-V shaders compiled from HLSL, there are some extra things you need to take care of.
|
||||
First make sure that the entry point is used correctly.
|
||||
If you forget to set the entry point correctly in glslangValidator (-e MyFancyEntryPoint),
|
||||
you will likely encounter this error message:
|
||||
|
||||
```
|
||||
Cannot end a function before ending the current block.
|
||||
Likely cause: If this SPIR-V was created from glslang HLSL, make sure the entry point is valid.
|
||||
```
|
||||
|
||||
##### Vertex/Fragment interface linking
|
||||
|
||||
HLSL relies on semantics in order to effectively link together shader stages. In the SPIR-V generated by glslang, the transformation from HLSL to GLSL ends up looking like
|
||||
|
||||
```c++
|
||||
struct VSOutput {
|
||||
// SV_Position is rerouted to gl_Position
|
||||
float4 position : SV_Position;
|
||||
float4 coord : TEXCOORD0;
|
||||
};
|
||||
|
||||
VSOutput main(...) {}
|
||||
```
|
||||
|
||||
```c++
|
||||
struct VSOutput {
|
||||
float4 coord;
|
||||
}
|
||||
layout(location = 0) out VSOutput _magicNameGeneratedByGlslang;
|
||||
```
|
||||
|
||||
While this works, be aware of the type of the struct which is used in the vertex stage and the fragment stage.
|
||||
There may be issues if the structure type name differs in vertex stage and fragment stage.
|
||||
|
||||
You can make use of the reflection interface to force the name of the struct type.
|
||||
|
||||
```
|
||||
// Something like this for both vertex outputs and fragment inputs.
|
||||
compiler.set_name(varying_resource.base_type_id, "VertexFragmentLinkage");
|
||||
```
|
||||
|
||||
Some platform may require identical variable name for both vertex outputs and fragment inputs. (for example MacOSX)
|
||||
to rename variable base on location, please add
|
||||
```
|
||||
--rename-interface-variable <in|out> <location> <new_variable_name>
|
||||
```
|
||||
|
||||
#### HLSL source to legacy GLSL/ESSL
|
||||
|
||||
HLSL tends to emit varying struct types to pass data between vertex and fragment.
|
||||
This is not supported in legacy GL/GLES targets, so to support this, varying structs are flattened.
|
||||
This is done automatically, but the API user might need to be aware that this is happening in order to support all cases.
|
||||
|
||||
Modern GLES code like this:
|
||||
```c++
|
||||
struct Output {
|
||||
vec4 a;
|
||||
vec2 b;
|
||||
};
|
||||
out Output vout;
|
||||
```
|
||||
|
||||
Is transformed into:
|
||||
```c++
|
||||
struct Output {
|
||||
vec4 a;
|
||||
vec2 b;
|
||||
};
|
||||
varying vec4 Output_a;
|
||||
varying vec2 Output_b;
|
||||
```
|
||||
|
||||
Note that now, both the struct name and the member names will participate in the linking interface between vertex and fragment, so
|
||||
API users might want to ensure that both the struct names and member names match so that vertex outputs and fragment inputs can link properly.
|
||||
|
||||
|
||||
#### Separate image samplers (HLSL/Vulkan) for backends which do not support it (GLSL)
|
||||
|
||||
Another thing you need to remember is when using samplers and textures in HLSL these are separable, and not directly compatible with GLSL. If you need to use this with desktop GL/GLES, you need to call `Compiler::build_combined_image_samplers` first before calling `Compiler::compile`, or you will get an exception.
|
||||
|
||||
```c++
|
||||
// From main.cpp
|
||||
// Builds a mapping for all combinations of images and samplers.
|
||||
compiler->build_combined_image_samplers();
|
||||
|
||||
// Give the remapped combined samplers new names.
|
||||
// Here you can also set up decorations if you want (binding = #N).
|
||||
for (auto &remap : compiler->get_combined_image_samplers())
|
||||
{
|
||||
compiler->set_name(remap.combined_id, join("SPIRV_Cross_Combined", compiler->get_name(remap.image_id),
|
||||
compiler->get_name(remap.sampler_id)));
|
||||
}
|
||||
```
|
||||
|
||||
If your target is Vulkan GLSL, `--vulkan-semantics` will emit separate image samplers as you'd expect.
|
||||
The command line client calls `Compiler::build_combined_image_samplers` automatically, but if you're calling the library, you'll need to do this yourself.
|
||||
|
||||
#### Descriptor sets (Vulkan GLSL) for backends which do not support them (pre HLSL 5.1 / GLSL)
|
||||
|
||||
Descriptor sets are unique to Vulkan, so make sure that descriptor set + binding is remapped to a flat binding scheme (set always 0), so that other APIs can make sense of the bindings.
|
||||
This can be done with `Compiler::set_decoration(id, spv::DecorationDescriptorSet)`. For other backends like MSL and HLSL, descriptor sets
|
||||
can be used, with some minor caveats, see below.
|
||||
|
||||
##### MSL 2.0+
|
||||
|
||||
Metal supports indirect argument buffers (--msl-argument-buffers). In this case, descriptor sets become argument buffers,
|
||||
and bindings are mapped to [[id(N)]] within the argument buffer. One quirk is that arrays of resources consume multiple ids,
|
||||
where Vulkan does not. This can be worked around either from shader authoring stage
|
||||
or remapping bindings as needed to avoid the overlap.
|
||||
There is also a rich API to declare remapping schemes which is intended to work like
|
||||
the pipeline layout in Vulkan. See `CompilerMSL::add_msl_resource_binding`. Remapping combined image samplers for example
|
||||
must be split into two bindings in MSL, so it's possible to declare an id for the texture and sampler binding separately.
|
||||
|
||||
##### HLSL - SM 5.1+
|
||||
|
||||
In SM 5.1+, descriptor set bindings are interpreted as register spaces directly. In HLSL however, arrays of resources consume
|
||||
multiple binding slots where Vulkan does not, so there might be overlap if the SPIR-V was not authored with this in mind.
|
||||
This can be worked around either from shader authoring stage (don't assign overlapping bindings)
|
||||
or remap bindings in SPIRV-Cross as needed to avoid the overlap.
|
||||
|
||||
#### Linking by name for targets which do not support explicit locations (legacy GLSL/ESSL)
|
||||
|
||||
Modern GLSL and HLSL sources (and SPIR-V) relies on explicit layout(location) qualifiers to guide the linking process between shader stages,
|
||||
but older GLSL relies on symbol names to perform the linking. When emitting shaders with older versions, these layout statements will be removed,
|
||||
so it is important that the API user ensures that the names of I/O variables are sanitized so that linking will work properly.
|
||||
The reflection API can rename variables, struct types and struct members to deal with these scenarios using `Compiler::set_name` and friends.
|
||||
|
||||
#### Clip-space conventions
|
||||
|
||||
SPIRV-Cross can perform some common clip space conversions on gl_Position/SV_Position by enabling `CompilerGLSL::Options.vertex.fixup_clipspace`.
|
||||
While this can be convenient, it is recommended to modify the projection matrices instead as that can achieve the same result.
|
||||
|
||||
For GLSL targets, enabling this will convert a shader which assumes `[0, w]` depth range (Vulkan / D3D / Metal) into `[-w, w]` range.
|
||||
For MSL and HLSL targets, enabling this will convert a shader in `[-w, w]` depth range (OpenGL) to `[0, w]` depth range.
|
||||
|
||||
By default, the CLI will not enable `fixup_clipspace`, but in the API you might want to set an explicit value using `CompilerGLSL::set_options()`.
|
||||
|
||||
Y-flipping of gl_Position and similar is also supported.
|
||||
The use of this is discouraged, because relying on vertex shader Y-flipping tends to get quite messy.
|
||||
To enable this, set `CompilerGLSL::Options.vertex.flip_vert_y` or `--flip-vert-y` in CLI.
|
||||
|
||||
#### Reserved identifiers
|
||||
|
||||
When cross-compiling, certain identifiers are considered to be reserved by the implementation.
|
||||
Code generated by SPIRV-Cross cannot emit these identifiers as they are reserved and used for various internal purposes,
|
||||
and such variables will typically show up as `_RESERVED_IDENTIFIER_FIXUP_`
|
||||
or some similar name to make it more obvious that an identifier has been renamed.
|
||||
|
||||
Reflection output will follow the exact name specified in the SPIR-V module. It might not be a valid identifier in the C sense,
|
||||
as it may contain non-alphanumeric/non-underscore characters.
|
||||
|
||||
Reserved identifiers currently assumed by the implementation are (in pseudo-regex):
|
||||
|
||||
- _$digit+, e.g. `_100`, `_2`
|
||||
- _$digit+_.+, e.g. `_100_tmp`, `_2_foobar`. `_2Bar` is **not** reserved.
|
||||
- gl_- prefix
|
||||
- spv- prefix
|
||||
- SPIRV_Cross prefix. This prefix is generally used for interface variables where app needs to provide data for workaround purposes.
|
||||
This identifier will not be rewritten, but be aware of potential collisions.
|
||||
- Double underscores (reserved by all target languages).
|
||||
|
||||
Members of structs also have a reserved identifier:
|
||||
- _m$digit+$END, e.g. `_m20` and `_m40` are reserved, but not `_m40Foobar`.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions to SPIRV-Cross are welcome. See Testing and Licensing sections for details.
|
||||
|
||||
### Testing
|
||||
|
||||
SPIRV-Cross maintains a test suite of shaders with reference output of how the output looks after going through a roundtrip through
|
||||
glslangValidator/spirv-as then back through SPIRV-Cross again.
|
||||
The reference files are stored inside the repository in order to be able to track regressions.
|
||||
|
||||
All pull requests should ensure that test output does not change unexpectedly. This can be tested with:
|
||||
|
||||
```
|
||||
./checkout_glslang_spirv_tools.sh # Checks out glslang and SPIRV-Tools at a fixed revision which matches the reference output.
|
||||
./build_glslang_spirv_tools.sh # Builds glslang and SPIRV-Tools.
|
||||
./test_shaders.sh # Runs over all changes and makes sure that there are no deltas compared to reference files.
|
||||
```
|
||||
|
||||
`./test_shaders.sh` currently requires a Makefile setup with GCC/Clang to be set up.
|
||||
However, on Windows, this can be rather inconvenient if a MinGW environment is not set up.
|
||||
To use a spirv-cross binary you built with CMake (or otherwise), you can pass in an environment variable as such:
|
||||
|
||||
```
|
||||
SPIRV_CROSS_PATH=path/to/custom/spirv-cross ./test_shaders.sh
|
||||
```
|
||||
|
||||
However, when improving SPIRV-Cross there are of course legitimate cases where reference output should change.
|
||||
In these cases, run:
|
||||
|
||||
```
|
||||
./update_test_shaders.sh # SPIRV_CROSS_PATH also works here.
|
||||
```
|
||||
|
||||
to update the reference files and include these changes as part of the pull request.
|
||||
Always make sure you are running the correct version of glslangValidator as well as SPIRV-Tools when updating reference files.
|
||||
See `checkout_glslang_spirv_tools.sh` which revisions are currently expected. The revisions change regularly.
|
||||
|
||||
In short, the main branch should always be able to run `./test_shaders.py shaders` and friends without failure.
|
||||
SPIRV-Cross uses Travis CI to test all pull requests, so it is not strictly needed to perform testing yourself if you have problems running it locally.
|
||||
A pull request which does not pass testing on Travis will not be accepted however.
|
||||
|
||||
When adding support for new features to SPIRV-Cross, a new shader and reference file should be added which covers usage of the new shader features in question.
|
||||
Travis CI runs the test suite with the CMake, by running `ctest`. This is a more straight-forward alternative to `./test_shaders.sh`.
|
||||
|
||||
### Licensing
|
||||
|
||||
Contributors of new files should add a copyright header at the top of every new source code file with their copyright
|
||||
along with the Apache 2.0 licensing stub.
|
||||
|
||||
### Formatting
|
||||
|
||||
SPIRV-Cross uses `clang-format` to automatically format code.
|
||||
Please use `clang-format` with the style sheet found in `.clang-format` to automatically format code before submitting a pull request.
|
||||
|
||||
To make things easy, the `format_all.sh` script can be used to format all
|
||||
source files in the library. In this directory, run the following from the
|
||||
command line:
|
||||
|
||||
./format_all.sh
|
||||
|
||||
## Regression testing
|
||||
|
||||
In shaders/ a collection of shaders are maintained for purposes of regression testing.
|
||||
The current reference output is contained in reference/.
|
||||
`./test_shaders.py shaders` can be run to perform regression testing.
|
||||
|
||||
See `./test_shaders.py --help` for more.
|
||||
|
||||
### Metal backend
|
||||
|
||||
To test the roundtrip path GLSL -> SPIR-V -> MSL, `--msl` can be added, e.g. `./test_shaders.py --msl shaders-msl`.
|
||||
|
||||
### HLSL backend
|
||||
|
||||
To test the roundtrip path GLSL -> SPIR-V -> HLSL, `--hlsl` can be added, e.g. `./test_shaders.py --hlsl shaders-hlsl`.
|
||||
|
||||
### Updating regression tests
|
||||
|
||||
When legitimate changes are found, use `--update` flag to update regression files.
|
||||
Otherwise, `./test_shaders.py` will fail with error code.
|
||||
|
||||
### Mali Offline Compiler cycle counts
|
||||
|
||||
To obtain a CSV of static shader cycle counts before and after going through spirv-cross, add
|
||||
`--malisc` flag to `./test_shaders`. This requires the Mali Offline Compiler to be installed in PATH.
|
||||
|
||||
9
thirdparty/SPIRV-Cross/cmake/gitversion.in.h
vendored
Normal file
9
thirdparty/SPIRV-Cross/cmake/gitversion.in.h
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright 2016-2021 The Khronos Group Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#ifndef SPIRV_CROSS_GIT_VERSION_H_
|
||||
#define SPIRV_CROSS_GIT_VERSION_H_
|
||||
|
||||
#define SPIRV_CROSS_GIT_REVISION "Git commit: @spirv-cross-build-version@ Timestamp: @spirv-cross-timestamp@"
|
||||
|
||||
#endif
|
||||
80
thirdparty/SPIRV-Cross/include/spirv_cross/barrier.hpp
vendored
Normal file
80
thirdparty/SPIRV-Cross/include/spirv_cross/barrier.hpp
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright 2015-2017 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_BARRIER_HPP
|
||||
#define SPIRV_CROSS_BARRIER_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
namespace spirv_cross
|
||||
{
|
||||
class Barrier
|
||||
{
|
||||
public:
|
||||
Barrier()
|
||||
{
|
||||
count.store(0);
|
||||
iteration.store(0);
|
||||
}
|
||||
|
||||
void set_release_divisor(unsigned divisor)
|
||||
{
|
||||
this->divisor = divisor;
|
||||
}
|
||||
|
||||
static inline void memoryBarrier()
|
||||
{
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
}
|
||||
|
||||
void reset_counter()
|
||||
{
|
||||
count.store(0);
|
||||
iteration.store(0);
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
unsigned target_iteration = iteration.load(std::memory_order_relaxed) + 1;
|
||||
// Overflows cleanly.
|
||||
unsigned target_count = divisor * target_iteration;
|
||||
|
||||
// Barriers don't enforce memory ordering.
|
||||
// Be as relaxed about the barrier as we possibly can!
|
||||
unsigned c = count.fetch_add(1u, std::memory_order_relaxed);
|
||||
|
||||
if (c + 1 == target_count)
|
||||
{
|
||||
iteration.store(target_iteration, std::memory_order_relaxed);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we have more threads than the CPU, don't hog the CPU for very long periods of time.
|
||||
while (iteration.load(std::memory_order_relaxed) != target_iteration)
|
||||
std::this_thread::yield();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned divisor = 1;
|
||||
std::atomic<unsigned> count;
|
||||
std::atomic<unsigned> iteration;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
127
thirdparty/SPIRV-Cross/include/spirv_cross/external_interface.h
vendored
Normal file
127
thirdparty/SPIRV-Cross/include/spirv_cross/external_interface.h
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright 2015-2017 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_EXTERNAL_INTERFACE_H
|
||||
#define SPIRV_CROSS_EXTERNAL_INTERFACE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct spirv_cross_shader spirv_cross_shader_t;
|
||||
|
||||
struct spirv_cross_interface
|
||||
{
|
||||
spirv_cross_shader_t *(*construct)(void);
|
||||
void (*destruct)(spirv_cross_shader_t *thiz);
|
||||
void (*invoke)(spirv_cross_shader_t *thiz);
|
||||
};
|
||||
|
||||
void spirv_cross_set_stage_input(spirv_cross_shader_t *thiz, unsigned location, void *data, size_t size);
|
||||
|
||||
void spirv_cross_set_stage_output(spirv_cross_shader_t *thiz, unsigned location, void *data, size_t size);
|
||||
|
||||
void spirv_cross_set_push_constant(spirv_cross_shader_t *thiz, void *data, size_t size);
|
||||
|
||||
void spirv_cross_set_uniform_constant(spirv_cross_shader_t *thiz, unsigned location, void *data, size_t size);
|
||||
|
||||
void spirv_cross_set_resource(spirv_cross_shader_t *thiz, unsigned set, unsigned binding, void **data, size_t size);
|
||||
|
||||
const struct spirv_cross_interface *spirv_cross_get_interface(void);
|
||||
|
||||
typedef enum spirv_cross_builtin {
|
||||
SPIRV_CROSS_BUILTIN_POSITION = 0,
|
||||
SPIRV_CROSS_BUILTIN_FRAG_COORD = 1,
|
||||
SPIRV_CROSS_BUILTIN_WORK_GROUP_ID = 2,
|
||||
SPIRV_CROSS_BUILTIN_NUM_WORK_GROUPS = 3,
|
||||
SPIRV_CROSS_NUM_BUILTINS
|
||||
} spirv_cross_builtin;
|
||||
|
||||
void spirv_cross_set_builtin(spirv_cross_shader_t *thiz, spirv_cross_builtin builtin, void *data, size_t size);
|
||||
|
||||
#define SPIRV_CROSS_NUM_DESCRIPTOR_SETS 4
|
||||
#define SPIRV_CROSS_NUM_DESCRIPTOR_BINDINGS 16
|
||||
#define SPIRV_CROSS_NUM_STAGE_INPUTS 16
|
||||
#define SPIRV_CROSS_NUM_STAGE_OUTPUTS 16
|
||||
#define SPIRV_CROSS_NUM_UNIFORM_CONSTANTS 32
|
||||
|
||||
enum spirv_cross_format
|
||||
{
|
||||
SPIRV_CROSS_FORMAT_R8_UNORM = 0,
|
||||
SPIRV_CROSS_FORMAT_R8G8_UNORM = 1,
|
||||
SPIRV_CROSS_FORMAT_R8G8B8_UNORM = 2,
|
||||
SPIRV_CROSS_FORMAT_R8G8B8A8_UNORM = 3,
|
||||
|
||||
SPIRV_CROSS_NUM_FORMATS
|
||||
};
|
||||
|
||||
enum spirv_cross_wrap
|
||||
{
|
||||
SPIRV_CROSS_WRAP_CLAMP_TO_EDGE = 0,
|
||||
SPIRV_CROSS_WRAP_REPEAT = 1,
|
||||
|
||||
SPIRV_CROSS_NUM_WRAP
|
||||
};
|
||||
|
||||
enum spirv_cross_filter
|
||||
{
|
||||
SPIRV_CROSS_FILTER_NEAREST = 0,
|
||||
SPIRV_CROSS_FILTER_LINEAR = 1,
|
||||
|
||||
SPIRV_CROSS_NUM_FILTER
|
||||
};
|
||||
|
||||
enum spirv_cross_mipfilter
|
||||
{
|
||||
SPIRV_CROSS_MIPFILTER_BASE = 0,
|
||||
SPIRV_CROSS_MIPFILTER_NEAREST = 1,
|
||||
SPIRV_CROSS_MIPFILTER_LINEAR = 2,
|
||||
|
||||
SPIRV_CROSS_NUM_MIPFILTER
|
||||
};
|
||||
|
||||
struct spirv_cross_miplevel
|
||||
{
|
||||
const void *data;
|
||||
unsigned width, height;
|
||||
size_t stride;
|
||||
};
|
||||
|
||||
struct spirv_cross_sampler_info
|
||||
{
|
||||
const struct spirv_cross_miplevel *mipmaps;
|
||||
unsigned num_mipmaps;
|
||||
|
||||
enum spirv_cross_format format;
|
||||
enum spirv_cross_wrap wrap_s;
|
||||
enum spirv_cross_wrap wrap_t;
|
||||
enum spirv_cross_filter min_filter;
|
||||
enum spirv_cross_filter mag_filter;
|
||||
enum spirv_cross_mipfilter mip_filter;
|
||||
};
|
||||
|
||||
typedef struct spirv_cross_sampler_2d spirv_cross_sampler_2d_t;
|
||||
spirv_cross_sampler_2d_t *spirv_cross_create_sampler_2d(const struct spirv_cross_sampler_info *info);
|
||||
void spirv_cross_destroy_sampler_2d(spirv_cross_sampler_2d_t *samp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
63
thirdparty/SPIRV-Cross/include/spirv_cross/image.hpp
vendored
Normal file
63
thirdparty/SPIRV-Cross/include/spirv_cross/image.hpp
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright 2015-2017 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_IMAGE_HPP
|
||||
#define SPIRV_CROSS_IMAGE_HPP
|
||||
|
||||
#ifndef GLM_SWIZZLE
|
||||
#define GLM_SWIZZLE
|
||||
#endif
|
||||
|
||||
#ifndef GLM_FORCE_RADIANS
|
||||
#define GLM_FORCE_RADIANS
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace spirv_cross
|
||||
{
|
||||
template <typename T>
|
||||
struct image2DBase
|
||||
{
|
||||
virtual ~image2DBase() = default;
|
||||
inline virtual T load(glm::ivec2 coord) const
|
||||
{
|
||||
return T(0, 0, 0, 1);
|
||||
}
|
||||
inline virtual void store(glm::ivec2 coord, const T &v)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
typedef image2DBase<glm::vec4> image2D;
|
||||
typedef image2DBase<glm::ivec4> iimage2D;
|
||||
typedef image2DBase<glm::uvec4> uimage2D;
|
||||
|
||||
template <typename T>
|
||||
inline T imageLoad(const image2DBase<T> &image, glm::ivec2 coord)
|
||||
{
|
||||
return image.load(coord);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void imageStore(image2DBase<T> &image, glm::ivec2 coord, const T &value)
|
||||
{
|
||||
image.store(coord, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
604
thirdparty/SPIRV-Cross/include/spirv_cross/internal_interface.hpp
vendored
Normal file
604
thirdparty/SPIRV-Cross/include/spirv_cross/internal_interface.hpp
vendored
Normal file
|
|
@ -0,0 +1,604 @@
|
|||
/*
|
||||
* Copyright 2015-2017 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_INTERNAL_INTERFACE_HPP
|
||||
#define SPIRV_CROSS_INTERNAL_INTERFACE_HPP
|
||||
|
||||
// This file must only be included by the shader generated by spirv-cross!
|
||||
|
||||
#ifndef GLM_FORCE_SWIZZLE
|
||||
#define GLM_FORCE_SWIZZLE
|
||||
#endif
|
||||
|
||||
#ifndef GLM_FORCE_RADIANS
|
||||
#define GLM_FORCE_RADIANS
|
||||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "barrier.hpp"
|
||||
#include "external_interface.h"
|
||||
#include "image.hpp"
|
||||
#include "sampler.hpp"
|
||||
#include "thread_group.hpp"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace internal
|
||||
{
|
||||
// Adaptor helpers to adapt GLSL access chain syntax to C++.
|
||||
// Don't bother with arrays of arrays on uniforms ...
|
||||
// Would likely need horribly complex variadic template munging.
|
||||
|
||||
template <typename T>
|
||||
struct Interface
|
||||
{
|
||||
enum
|
||||
{
|
||||
ArraySize = 1,
|
||||
Size = sizeof(T)
|
||||
};
|
||||
|
||||
Interface()
|
||||
: ptr(0)
|
||||
{
|
||||
}
|
||||
T &get()
|
||||
{
|
||||
assert(ptr);
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
T *ptr;
|
||||
};
|
||||
|
||||
// For array types, return a pointer instead.
|
||||
template <typename T, unsigned U>
|
||||
struct Interface<T[U]>
|
||||
{
|
||||
enum
|
||||
{
|
||||
ArraySize = U,
|
||||
Size = U * sizeof(T)
|
||||
};
|
||||
|
||||
Interface()
|
||||
: ptr(0)
|
||||
{
|
||||
}
|
||||
T *get()
|
||||
{
|
||||
assert(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T *ptr;
|
||||
};
|
||||
|
||||
// For case when array size is 1, avoid double dereference.
|
||||
template <typename T>
|
||||
struct PointerInterface
|
||||
{
|
||||
enum
|
||||
{
|
||||
ArraySize = 1,
|
||||
Size = sizeof(T *)
|
||||
};
|
||||
enum
|
||||
{
|
||||
PreDereference = true
|
||||
};
|
||||
|
||||
PointerInterface()
|
||||
: ptr(0)
|
||||
{
|
||||
}
|
||||
|
||||
T &get()
|
||||
{
|
||||
assert(ptr);
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
T *ptr;
|
||||
};
|
||||
|
||||
// Automatically converts a pointer down to reference to match GLSL syntax.
|
||||
template <typename T>
|
||||
struct DereferenceAdaptor
|
||||
{
|
||||
DereferenceAdaptor(T **ptr)
|
||||
: ptr(ptr)
|
||||
{
|
||||
}
|
||||
T &operator[](unsigned index) const
|
||||
{
|
||||
return *(ptr[index]);
|
||||
}
|
||||
T **ptr;
|
||||
};
|
||||
|
||||
// We can't have a linear array of T* since T* can be an abstract type in case of samplers.
|
||||
// We also need a list of pointers since we can have run-time length SSBOs.
|
||||
template <typename T, unsigned U>
|
||||
struct PointerInterface<T[U]>
|
||||
{
|
||||
enum
|
||||
{
|
||||
ArraySize = U,
|
||||
Size = sizeof(T *) * U
|
||||
};
|
||||
enum
|
||||
{
|
||||
PreDereference = false
|
||||
};
|
||||
PointerInterface()
|
||||
: ptr(0)
|
||||
{
|
||||
}
|
||||
|
||||
DereferenceAdaptor<T> get()
|
||||
{
|
||||
assert(ptr);
|
||||
return DereferenceAdaptor<T>(ptr);
|
||||
}
|
||||
|
||||
T **ptr;
|
||||
};
|
||||
|
||||
// Resources can be more abstract and be unsized,
|
||||
// so we need to have an array of pointers for those cases.
|
||||
template <typename T>
|
||||
struct Resource : PointerInterface<T>
|
||||
{
|
||||
};
|
||||
|
||||
// POD with no unknown sizes, so we can express these as flat arrays.
|
||||
template <typename T>
|
||||
struct UniformConstant : Interface<T>
|
||||
{
|
||||
};
|
||||
template <typename T>
|
||||
struct StageInput : Interface<T>
|
||||
{
|
||||
};
|
||||
template <typename T>
|
||||
struct StageOutput : Interface<T>
|
||||
{
|
||||
};
|
||||
template <typename T>
|
||||
struct PushConstant : Interface<T>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
struct spirv_cross_shader
|
||||
{
|
||||
struct PPSize
|
||||
{
|
||||
PPSize()
|
||||
: ptr(0)
|
||||
, size(0)
|
||||
{
|
||||
}
|
||||
void **ptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct PPSizeResource
|
||||
{
|
||||
PPSizeResource()
|
||||
: ptr(0)
|
||||
, size(0)
|
||||
, pre_dereference(false)
|
||||
{
|
||||
}
|
||||
void **ptr;
|
||||
size_t size;
|
||||
bool pre_dereference;
|
||||
};
|
||||
|
||||
PPSizeResource resources[SPIRV_CROSS_NUM_DESCRIPTOR_SETS][SPIRV_CROSS_NUM_DESCRIPTOR_BINDINGS];
|
||||
PPSize stage_inputs[SPIRV_CROSS_NUM_STAGE_INPUTS];
|
||||
PPSize stage_outputs[SPIRV_CROSS_NUM_STAGE_OUTPUTS];
|
||||
PPSize uniform_constants[SPIRV_CROSS_NUM_UNIFORM_CONSTANTS];
|
||||
PPSize push_constant;
|
||||
PPSize builtins[SPIRV_CROSS_NUM_BUILTINS];
|
||||
|
||||
template <typename U>
|
||||
void register_builtin(spirv_cross_builtin builtin, const U &value)
|
||||
{
|
||||
assert(!builtins[builtin].ptr);
|
||||
|
||||
builtins[builtin].ptr = (void **)&value.ptr;
|
||||
builtins[builtin].size = sizeof(*value.ptr) * U::ArraySize;
|
||||
}
|
||||
|
||||
void set_builtin(spirv_cross_builtin builtin, void *data, size_t size)
|
||||
{
|
||||
assert(builtins[builtin].ptr);
|
||||
assert(size >= builtins[builtin].size);
|
||||
|
||||
*builtins[builtin].ptr = data;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void register_resource(const internal::Resource<U> &value, unsigned set, unsigned binding)
|
||||
{
|
||||
assert(set < SPIRV_CROSS_NUM_DESCRIPTOR_SETS);
|
||||
assert(binding < SPIRV_CROSS_NUM_DESCRIPTOR_BINDINGS);
|
||||
assert(!resources[set][binding].ptr);
|
||||
|
||||
resources[set][binding].ptr = (void **)&value.ptr;
|
||||
resources[set][binding].size = internal::Resource<U>::Size;
|
||||
resources[set][binding].pre_dereference = internal::Resource<U>::PreDereference;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void register_stage_input(const internal::StageInput<U> &value, unsigned location)
|
||||
{
|
||||
assert(location < SPIRV_CROSS_NUM_STAGE_INPUTS);
|
||||
assert(!stage_inputs[location].ptr);
|
||||
|
||||
stage_inputs[location].ptr = (void **)&value.ptr;
|
||||
stage_inputs[location].size = internal::StageInput<U>::Size;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void register_stage_output(const internal::StageOutput<U> &value, unsigned location)
|
||||
{
|
||||
assert(location < SPIRV_CROSS_NUM_STAGE_OUTPUTS);
|
||||
assert(!stage_outputs[location].ptr);
|
||||
|
||||
stage_outputs[location].ptr = (void **)&value.ptr;
|
||||
stage_outputs[location].size = internal::StageOutput<U>::Size;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void register_uniform_constant(const internal::UniformConstant<U> &value, unsigned location)
|
||||
{
|
||||
assert(location < SPIRV_CROSS_NUM_UNIFORM_CONSTANTS);
|
||||
assert(!uniform_constants[location].ptr);
|
||||
|
||||
uniform_constants[location].ptr = (void **)&value.ptr;
|
||||
uniform_constants[location].size = internal::UniformConstant<U>::Size;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
void register_push_constant(const internal::PushConstant<U> &value)
|
||||
{
|
||||
assert(!push_constant.ptr);
|
||||
|
||||
push_constant.ptr = (void **)&value.ptr;
|
||||
push_constant.size = internal::PushConstant<U>::Size;
|
||||
}
|
||||
|
||||
void set_stage_input(unsigned location, void *data, size_t size)
|
||||
{
|
||||
assert(location < SPIRV_CROSS_NUM_STAGE_INPUTS);
|
||||
assert(stage_inputs[location].ptr);
|
||||
assert(size >= stage_inputs[location].size);
|
||||
|
||||
*stage_inputs[location].ptr = data;
|
||||
}
|
||||
|
||||
void set_stage_output(unsigned location, void *data, size_t size)
|
||||
{
|
||||
assert(location < SPIRV_CROSS_NUM_STAGE_OUTPUTS);
|
||||
assert(stage_outputs[location].ptr);
|
||||
assert(size >= stage_outputs[location].size);
|
||||
|
||||
*stage_outputs[location].ptr = data;
|
||||
}
|
||||
|
||||
void set_uniform_constant(unsigned location, void *data, size_t size)
|
||||
{
|
||||
assert(location < SPIRV_CROSS_NUM_UNIFORM_CONSTANTS);
|
||||
assert(uniform_constants[location].ptr);
|
||||
assert(size >= uniform_constants[location].size);
|
||||
|
||||
*uniform_constants[location].ptr = data;
|
||||
}
|
||||
|
||||
void set_push_constant(void *data, size_t size)
|
||||
{
|
||||
assert(push_constant.ptr);
|
||||
assert(size >= push_constant.size);
|
||||
|
||||
*push_constant.ptr = data;
|
||||
}
|
||||
|
||||
void set_resource(unsigned set, unsigned binding, void **data, size_t size)
|
||||
{
|
||||
assert(set < SPIRV_CROSS_NUM_DESCRIPTOR_SETS);
|
||||
assert(binding < SPIRV_CROSS_NUM_DESCRIPTOR_BINDINGS);
|
||||
assert(resources[set][binding].ptr);
|
||||
assert(size >= resources[set][binding].size);
|
||||
|
||||
// We're using the regular PointerInterface, dereference ahead of time.
|
||||
if (resources[set][binding].pre_dereference)
|
||||
*resources[set][binding].ptr = *data;
|
||||
else
|
||||
*resources[set][binding].ptr = data;
|
||||
}
|
||||
};
|
||||
|
||||
namespace spirv_cross
|
||||
{
|
||||
template <typename T>
|
||||
struct BaseShader : spirv_cross_shader
|
||||
{
|
||||
void invoke()
|
||||
{
|
||||
static_cast<T *>(this)->main();
|
||||
}
|
||||
};
|
||||
|
||||
struct FragmentResources
|
||||
{
|
||||
internal::StageOutput<glm::vec4> gl_FragCoord;
|
||||
void init(spirv_cross_shader &s)
|
||||
{
|
||||
s.register_builtin(SPIRV_CROSS_BUILTIN_FRAG_COORD, gl_FragCoord);
|
||||
}
|
||||
#define gl_FragCoord __res->gl_FragCoord.get()
|
||||
};
|
||||
|
||||
template <typename T, typename Res>
|
||||
struct FragmentShader : BaseShader<FragmentShader<T, Res>>
|
||||
{
|
||||
inline void main()
|
||||
{
|
||||
impl.main();
|
||||
}
|
||||
|
||||
FragmentShader()
|
||||
{
|
||||
resources.init(*this);
|
||||
impl.__res = &resources;
|
||||
}
|
||||
|
||||
T impl;
|
||||
Res resources;
|
||||
};
|
||||
|
||||
struct VertexResources
|
||||
{
|
||||
internal::StageOutput<glm::vec4> gl_Position;
|
||||
void init(spirv_cross_shader &s)
|
||||
{
|
||||
s.register_builtin(SPIRV_CROSS_BUILTIN_POSITION, gl_Position);
|
||||
}
|
||||
#define gl_Position __res->gl_Position.get()
|
||||
};
|
||||
|
||||
template <typename T, typename Res>
|
||||
struct VertexShader : BaseShader<VertexShader<T, Res>>
|
||||
{
|
||||
inline void main()
|
||||
{
|
||||
impl.main();
|
||||
}
|
||||
|
||||
VertexShader()
|
||||
{
|
||||
resources.init(*this);
|
||||
impl.__res = &resources;
|
||||
}
|
||||
|
||||
T impl;
|
||||
Res resources;
|
||||
};
|
||||
|
||||
struct TessEvaluationResources
|
||||
{
|
||||
inline void init(spirv_cross_shader &)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Res>
|
||||
struct TessEvaluationShader : BaseShader<TessEvaluationShader<T, Res>>
|
||||
{
|
||||
inline void main()
|
||||
{
|
||||
impl.main();
|
||||
}
|
||||
|
||||
TessEvaluationShader()
|
||||
{
|
||||
resources.init(*this);
|
||||
impl.__res = &resources;
|
||||
}
|
||||
|
||||
T impl;
|
||||
Res resources;
|
||||
};
|
||||
|
||||
struct TessControlResources
|
||||
{
|
||||
inline void init(spirv_cross_shader &)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Res>
|
||||
struct TessControlShader : BaseShader<TessControlShader<T, Res>>
|
||||
{
|
||||
inline void main()
|
||||
{
|
||||
impl.main();
|
||||
}
|
||||
|
||||
TessControlShader()
|
||||
{
|
||||
resources.init(*this);
|
||||
impl.__res = &resources;
|
||||
}
|
||||
|
||||
T impl;
|
||||
Res resources;
|
||||
};
|
||||
|
||||
struct GeometryResources
|
||||
{
|
||||
inline void init(spirv_cross_shader &)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Res>
|
||||
struct GeometryShader : BaseShader<GeometryShader<T, Res>>
|
||||
{
|
||||
inline void main()
|
||||
{
|
||||
impl.main();
|
||||
}
|
||||
|
||||
GeometryShader()
|
||||
{
|
||||
resources.init(*this);
|
||||
impl.__res = &resources;
|
||||
}
|
||||
|
||||
T impl;
|
||||
Res resources;
|
||||
};
|
||||
|
||||
struct ComputeResources
|
||||
{
|
||||
internal::StageInput<glm::uvec3> gl_WorkGroupID__;
|
||||
internal::StageInput<glm::uvec3> gl_NumWorkGroups__;
|
||||
void init(spirv_cross_shader &s)
|
||||
{
|
||||
s.register_builtin(SPIRV_CROSS_BUILTIN_WORK_GROUP_ID, gl_WorkGroupID__);
|
||||
s.register_builtin(SPIRV_CROSS_BUILTIN_NUM_WORK_GROUPS, gl_NumWorkGroups__);
|
||||
}
|
||||
#define gl_WorkGroupID __res->gl_WorkGroupID__.get()
|
||||
#define gl_NumWorkGroups __res->gl_NumWorkGroups__.get()
|
||||
|
||||
Barrier barrier__;
|
||||
#define barrier() __res->barrier__.wait()
|
||||
};
|
||||
|
||||
struct ComputePrivateResources
|
||||
{
|
||||
uint32_t gl_LocalInvocationIndex__;
|
||||
#define gl_LocalInvocationIndex __priv_res.gl_LocalInvocationIndex__
|
||||
glm::uvec3 gl_LocalInvocationID__;
|
||||
#define gl_LocalInvocationID __priv_res.gl_LocalInvocationID__
|
||||
glm::uvec3 gl_GlobalInvocationID__;
|
||||
#define gl_GlobalInvocationID __priv_res.gl_GlobalInvocationID__
|
||||
};
|
||||
|
||||
template <typename T, typename Res, unsigned WorkGroupX, unsigned WorkGroupY, unsigned WorkGroupZ>
|
||||
struct ComputeShader : BaseShader<ComputeShader<T, Res, WorkGroupX, WorkGroupY, WorkGroupZ>>
|
||||
{
|
||||
inline void main()
|
||||
{
|
||||
resources.barrier__.reset_counter();
|
||||
|
||||
for (unsigned z = 0; z < WorkGroupZ; z++)
|
||||
for (unsigned y = 0; y < WorkGroupY; y++)
|
||||
for (unsigned x = 0; x < WorkGroupX; x++)
|
||||
impl[z][y][x].__priv_res.gl_GlobalInvocationID__ =
|
||||
glm::uvec3(WorkGroupX, WorkGroupY, WorkGroupZ) * resources.gl_WorkGroupID__.get() +
|
||||
glm::uvec3(x, y, z);
|
||||
|
||||
group.run();
|
||||
group.wait();
|
||||
}
|
||||
|
||||
ComputeShader()
|
||||
: group(&impl[0][0][0])
|
||||
{
|
||||
resources.init(*this);
|
||||
resources.barrier__.set_release_divisor(WorkGroupX * WorkGroupY * WorkGroupZ);
|
||||
|
||||
unsigned i = 0;
|
||||
for (unsigned z = 0; z < WorkGroupZ; z++)
|
||||
{
|
||||
for (unsigned y = 0; y < WorkGroupY; y++)
|
||||
{
|
||||
for (unsigned x = 0; x < WorkGroupX; x++)
|
||||
{
|
||||
impl[z][y][x].__priv_res.gl_LocalInvocationID__ = glm::uvec3(x, y, z);
|
||||
impl[z][y][x].__priv_res.gl_LocalInvocationIndex__ = i++;
|
||||
impl[z][y][x].__res = &resources;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T impl[WorkGroupZ][WorkGroupY][WorkGroupX];
|
||||
ThreadGroup<T, WorkGroupX * WorkGroupY * WorkGroupZ> group;
|
||||
Res resources;
|
||||
};
|
||||
|
||||
inline void memoryBarrierShared()
|
||||
{
|
||||
Barrier::memoryBarrier();
|
||||
}
|
||||
inline void memoryBarrier()
|
||||
{
|
||||
Barrier::memoryBarrier();
|
||||
}
|
||||
// TODO: Rest of the barriers.
|
||||
|
||||
// Atomics
|
||||
template <typename T>
|
||||
inline T atomicAdd(T &v, T a)
|
||||
{
|
||||
static_assert(sizeof(std::atomic<T>) == sizeof(T), "Cannot cast properly to std::atomic<T>.");
|
||||
|
||||
// We need explicit memory barriers in GLSL to enfore any ordering.
|
||||
// FIXME: Can we really cast this? There is no other way I think ...
|
||||
return std::atomic_fetch_add_explicit(reinterpret_cast<std::atomic<T> *>(&v), a, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
void spirv_cross_set_stage_input(spirv_cross_shader_t *shader, unsigned location, void *data, size_t size)
|
||||
{
|
||||
shader->set_stage_input(location, data, size);
|
||||
}
|
||||
|
||||
void spirv_cross_set_stage_output(spirv_cross_shader_t *shader, unsigned location, void *data, size_t size)
|
||||
{
|
||||
shader->set_stage_output(location, data, size);
|
||||
}
|
||||
|
||||
void spirv_cross_set_uniform_constant(spirv_cross_shader_t *shader, unsigned location, void *data, size_t size)
|
||||
{
|
||||
shader->set_uniform_constant(location, data, size);
|
||||
}
|
||||
|
||||
void spirv_cross_set_resource(spirv_cross_shader_t *shader, unsigned set, unsigned binding, void **data, size_t size)
|
||||
{
|
||||
shader->set_resource(set, binding, data, size);
|
||||
}
|
||||
|
||||
void spirv_cross_set_push_constant(spirv_cross_shader_t *shader, void *data, size_t size)
|
||||
{
|
||||
shader->set_push_constant(data, size);
|
||||
}
|
||||
|
||||
void spirv_cross_set_builtin(spirv_cross_shader_t *shader, spirv_cross_builtin builtin, void *data, size_t size)
|
||||
{
|
||||
shader->set_builtin(builtin, data, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
106
thirdparty/SPIRV-Cross/include/spirv_cross/sampler.hpp
vendored
Normal file
106
thirdparty/SPIRV-Cross/include/spirv_cross/sampler.hpp
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright 2015-2017 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_SAMPLER_HPP
|
||||
#define SPIRV_CROSS_SAMPLER_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace spirv_cross
|
||||
{
|
||||
struct spirv_cross_sampler_2d
|
||||
{
|
||||
inline virtual ~spirv_cross_sampler_2d()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct sampler2DBase : spirv_cross_sampler_2d
|
||||
{
|
||||
sampler2DBase(const spirv_cross_sampler_info *info)
|
||||
{
|
||||
mips.insert(mips.end(), info->mipmaps, info->mipmaps + info->num_mipmaps);
|
||||
format = info->format;
|
||||
wrap_s = info->wrap_s;
|
||||
wrap_t = info->wrap_t;
|
||||
min_filter = info->min_filter;
|
||||
mag_filter = info->mag_filter;
|
||||
mip_filter = info->mip_filter;
|
||||
}
|
||||
|
||||
inline virtual T sample(glm::vec2 uv, float bias)
|
||||
{
|
||||
return sampleLod(uv, bias);
|
||||
}
|
||||
|
||||
inline virtual T sampleLod(glm::vec2 uv, float lod)
|
||||
{
|
||||
if (mag_filter == SPIRV_CROSS_FILTER_NEAREST)
|
||||
{
|
||||
uv.x = wrap(uv.x, wrap_s, mips[0].width);
|
||||
uv.y = wrap(uv.y, wrap_t, mips[0].height);
|
||||
glm::vec2 uv_full = uv * glm::vec2(mips[0].width, mips[0].height);
|
||||
|
||||
int x = int(uv_full.x);
|
||||
int y = int(uv_full.y);
|
||||
return sample(x, y, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return T(0, 0, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
inline float wrap(float v, spirv_cross_wrap wrap, unsigned size)
|
||||
{
|
||||
switch (wrap)
|
||||
{
|
||||
case SPIRV_CROSS_WRAP_REPEAT:
|
||||
return v - glm::floor(v);
|
||||
case SPIRV_CROSS_WRAP_CLAMP_TO_EDGE:
|
||||
{
|
||||
float half = 0.5f / size;
|
||||
return glm::clamp(v, half, 1.0f - half);
|
||||
}
|
||||
|
||||
default:
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<spirv_cross_miplevel> mips;
|
||||
spirv_cross_format format;
|
||||
spirv_cross_wrap wrap_s;
|
||||
spirv_cross_wrap wrap_t;
|
||||
spirv_cross_filter min_filter;
|
||||
spirv_cross_filter mag_filter;
|
||||
spirv_cross_mipfilter mip_filter;
|
||||
};
|
||||
|
||||
typedef sampler2DBase<glm::vec4> sampler2D;
|
||||
typedef sampler2DBase<glm::ivec4> isampler2D;
|
||||
typedef sampler2DBase<glm::uvec4> usampler2D;
|
||||
|
||||
template <typename T>
|
||||
inline T texture(const sampler2DBase<T> &samp, const glm::vec2 &uv, float bias = 0.0f)
|
||||
{
|
||||
return samp.sample(uv, bias);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
114
thirdparty/SPIRV-Cross/include/spirv_cross/thread_group.hpp
vendored
Normal file
114
thirdparty/SPIRV-Cross/include/spirv_cross/thread_group.hpp
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright 2015-2017 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_THREAD_GROUP_HPP
|
||||
#define SPIRV_CROSS_THREAD_GROUP_HPP
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace spirv_cross
|
||||
{
|
||||
template <typename T, unsigned Size>
|
||||
class ThreadGroup
|
||||
{
|
||||
public:
|
||||
ThreadGroup(T *impl)
|
||||
{
|
||||
for (unsigned i = 0; i < Size; i++)
|
||||
workers[i].start(&impl[i]);
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
for (auto &worker : workers)
|
||||
worker.run();
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
for (auto &worker : workers)
|
||||
worker.wait();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Thread
|
||||
{
|
||||
enum State
|
||||
{
|
||||
Idle,
|
||||
Running,
|
||||
Dying
|
||||
};
|
||||
State state = Idle;
|
||||
|
||||
void start(T *impl)
|
||||
{
|
||||
worker = std::thread([impl, this] {
|
||||
for (;;)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> l{ lock };
|
||||
cond.wait(l, [this] { return state != Idle; });
|
||||
if (state == Dying)
|
||||
break;
|
||||
}
|
||||
|
||||
impl->main();
|
||||
|
||||
std::lock_guard<std::mutex> l{ lock };
|
||||
state = Idle;
|
||||
cond.notify_one();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
std::unique_lock<std::mutex> l{ lock };
|
||||
cond.wait(l, [this] { return state == Idle; });
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
std::lock_guard<std::mutex> l{ lock };
|
||||
state = Running;
|
||||
cond.notify_one();
|
||||
}
|
||||
|
||||
~Thread()
|
||||
{
|
||||
if (worker.joinable())
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> l{ lock };
|
||||
state = Dying;
|
||||
cond.notify_one();
|
||||
}
|
||||
worker.join();
|
||||
}
|
||||
}
|
||||
std::thread worker;
|
||||
std::condition_variable cond;
|
||||
std::mutex lock;
|
||||
};
|
||||
Thread workers[Size];
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
2099
thirdparty/SPIRV-Cross/main.cpp
vendored
Normal file
2099
thirdparty/SPIRV-Cross/main.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
16
thirdparty/SPIRV-Cross/pkg-config/spirv-cross-c-shared.pc.in
vendored
Normal file
16
thirdparty/SPIRV-Cross/pkg-config/spirv-cross-c-shared.pc.in
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Copyright 2020-2021 Hans-Kristian Arntzen
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
sharedlibdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/spirv_cross
|
||||
|
||||
Name: spirv-cross-c-shared
|
||||
Description: C API for SPIRV-Cross (shared)
|
||||
Version: @SPIRV_CROSS_VERSION@
|
||||
|
||||
Requires:
|
||||
Libs: -L${libdir} -L${sharedlibdir} -lspirv-cross-c-shared
|
||||
Cflags: -I${includedir}
|
||||
15
thirdparty/SPIRV-Cross/pkg-config/spirv-cross-c.pc.in
vendored
Normal file
15
thirdparty/SPIRV-Cross/pkg-config/spirv-cross-c.pc.in
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright 2020-2021 Hans-Kristian Arntzen
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/spirv_cross
|
||||
|
||||
Name: spirv-cross-c
|
||||
Description: C API for SPIRV-Cross (static)
|
||||
Version: @SPIRV_CROSS_VERSION@
|
||||
|
||||
Requires:
|
||||
Libs: -L${libdir} -lspirv-cross-c
|
||||
Cflags: -I${includedir}
|
||||
5602
thirdparty/SPIRV-Cross/spirv.h
vendored
Normal file
5602
thirdparty/SPIRV-Cross/spirv.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
5667
thirdparty/SPIRV-Cross/spirv.hpp
vendored
Normal file
5667
thirdparty/SPIRV-Cross/spirv.hpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
525
thirdparty/SPIRV-Cross/spirv_cfg.cpp
vendored
Normal file
525
thirdparty/SPIRV-Cross/spirv_cfg.cpp
vendored
Normal file
|
|
@ -0,0 +1,525 @@
|
|||
/*
|
||||
* Copyright 2016-2021 Arm Limited
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
*/
|
||||
|
||||
#include "spirv_cfg.hpp"
|
||||
#include "spirv_cross.hpp"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
CFG::CFG(Compiler &compiler_, const SPIRFunction &func_)
|
||||
: compiler(compiler_)
|
||||
, func(func_)
|
||||
{
|
||||
build_post_order_visit_order();
|
||||
build_immediate_dominators();
|
||||
}
|
||||
|
||||
uint32_t CFG::find_common_dominator(uint32_t a, uint32_t b) const
|
||||
{
|
||||
while (a != b)
|
||||
{
|
||||
if (get_visit_order(a) < get_visit_order(b))
|
||||
a = get_immediate_dominator(a);
|
||||
else
|
||||
b = get_immediate_dominator(b);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
void CFG::build_immediate_dominators()
|
||||
{
|
||||
// Traverse the post-order in reverse and build up the immediate dominator tree.
|
||||
immediate_dominators.clear();
|
||||
immediate_dominators[func.entry_block] = func.entry_block;
|
||||
|
||||
for (auto i = post_order.size(); i; i--)
|
||||
{
|
||||
uint32_t block = post_order[i - 1];
|
||||
|
||||
const auto resolve_preds = [&](const SmallVector<uint32_t> &pred)
|
||||
{
|
||||
if (pred.empty()) // This is for the entry block, but we've already set up the dominators.
|
||||
return;
|
||||
|
||||
for (auto &edge : pred)
|
||||
{
|
||||
if (immediate_dominators[block])
|
||||
{
|
||||
assert(immediate_dominators[edge]);
|
||||
immediate_dominators[block] = find_common_dominator(immediate_dominators[block], edge);
|
||||
}
|
||||
else
|
||||
immediate_dominators[block] = edge;
|
||||
}
|
||||
};
|
||||
|
||||
resolve_preds(preceding_edges[block]);
|
||||
resolve_preds(virtual_dominance_preceding_edges[block]);
|
||||
}
|
||||
}
|
||||
|
||||
bool CFG::is_back_edge(uint32_t to) const
|
||||
{
|
||||
// We have a back edge if the visit order is set with the temporary magic value 0.
|
||||
// Crossing edges will have already been recorded with a visit order.
|
||||
auto itr = visit_order.find(to);
|
||||
return itr != end(visit_order) && itr->second.visited_branches && !itr->second.visited_resolve;
|
||||
}
|
||||
|
||||
bool CFG::has_visited_branch(uint32_t to) const
|
||||
{
|
||||
auto itr = visit_order.find(to);
|
||||
return itr != end(visit_order) && itr->second.visited_branches;
|
||||
}
|
||||
|
||||
void CFG::post_order_visit_entry(uint32_t block)
|
||||
{
|
||||
visit_stack.push_back(block);
|
||||
|
||||
while (!visit_stack.empty())
|
||||
{
|
||||
bool keep_iterating;
|
||||
do
|
||||
{
|
||||
// Reverse the order to allow for stack-like behavior and preserves the visit order from recursive algorithm.
|
||||
// Traverse depth first.
|
||||
uint32_t to_visit = visit_stack.back();
|
||||
last_visited_size = visit_stack.size();
|
||||
post_order_visit_branches(to_visit);
|
||||
keep_iterating = last_visited_size != visit_stack.size();
|
||||
if (keep_iterating)
|
||||
std::reverse(visit_stack.begin() + last_visited_size, visit_stack.end());
|
||||
} while (keep_iterating);
|
||||
|
||||
// We've reached the end of some tree leaf. Resolve the stack.
|
||||
// Any node which has been visited for real can be popped now.
|
||||
while (!visit_stack.empty() && visit_order[visit_stack.back()].visited_branches)
|
||||
{
|
||||
post_order_visit_resolve(visit_stack.back());
|
||||
visit_stack.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CFG::visit_branch(uint32_t block_id)
|
||||
{
|
||||
// Prune obvious duplicates.
|
||||
if (std::find(visit_stack.begin() + last_visited_size, visit_stack.end(), block_id) == visit_stack.end() &&
|
||||
!has_visited_branch(block_id))
|
||||
{
|
||||
visit_stack.push_back(block_id);
|
||||
}
|
||||
}
|
||||
|
||||
void CFG::post_order_visit_branches(uint32_t block_id)
|
||||
{
|
||||
auto &block = compiler.get<SPIRBlock>(block_id);
|
||||
|
||||
auto &visit = visit_order[block_id];
|
||||
if (visit.visited_branches)
|
||||
return;
|
||||
visit.visited_branches = true;
|
||||
|
||||
if (block.merge == SPIRBlock::MergeLoop)
|
||||
visit_branch(block.merge_block);
|
||||
else if (block.merge == SPIRBlock::MergeSelection)
|
||||
visit_branch(block.next_block);
|
||||
|
||||
// First visit our branch targets.
|
||||
switch (block.terminator)
|
||||
{
|
||||
case SPIRBlock::Direct:
|
||||
visit_branch(block.next_block);
|
||||
break;
|
||||
|
||||
case SPIRBlock::Select:
|
||||
visit_branch(block.true_block);
|
||||
visit_branch(block.false_block);
|
||||
break;
|
||||
|
||||
case SPIRBlock::MultiSelect:
|
||||
{
|
||||
const auto &cases = compiler.get_case_list(block);
|
||||
for (const auto &target : cases)
|
||||
visit_branch(target.block);
|
||||
if (block.default_block)
|
||||
visit_branch(block.default_block);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CFG::post_order_visit_resolve(uint32_t block_id)
|
||||
{
|
||||
auto &block = compiler.get<SPIRBlock>(block_id);
|
||||
|
||||
auto &visit_block = visit_order[block_id];
|
||||
assert(visit_block.visited_branches);
|
||||
auto &visited = visit_order[block_id].visited_resolve;
|
||||
if (visited)
|
||||
return;
|
||||
|
||||
// If this is a loop header, add an implied branch to the merge target.
|
||||
// This is needed to avoid annoying cases with do { ... } while(false) loops often generated by inliners.
|
||||
// To the CFG, this is linear control flow, but we risk picking the do/while scope as our dominating block.
|
||||
// This makes sure that if we are accessing a variable outside the do/while, we choose the loop header as dominator.
|
||||
// We could use has_visited_forward_edge, but this break code-gen where the merge block is unreachable in the CFG.
|
||||
|
||||
// Make a point out of visiting merge target first. This is to make sure that post visit order outside the loop
|
||||
// is lower than inside the loop, which is going to be key for some traversal algorithms like post-dominance analysis.
|
||||
// For selection constructs true/false blocks will end up visiting the merge block directly and it works out fine,
|
||||
// but for loops, only the header might end up actually branching to merge block.
|
||||
if (block.merge == SPIRBlock::MergeLoop && !is_back_edge(block.merge_block))
|
||||
add_branch(block_id, block.merge_block);
|
||||
|
||||
// Similar case as do/while loops, but expressed in a different form.
|
||||
// if (true) { foo = 1; } else { return/unreachable/kill/blah; } access(foo);
|
||||
// Only consider this branch when computing dominance to avoid breaking other analysis like
|
||||
// parameter preservation.
|
||||
if (block.merge == SPIRBlock::MergeSelection && !is_back_edge(block.next_block))
|
||||
add_virtual_dominance_branch(block_id, block.next_block);
|
||||
|
||||
// First visit our branch targets.
|
||||
switch (block.terminator)
|
||||
{
|
||||
case SPIRBlock::Direct:
|
||||
if (!is_back_edge(block.next_block))
|
||||
add_branch(block_id, block.next_block);
|
||||
break;
|
||||
|
||||
case SPIRBlock::Select:
|
||||
if (!is_back_edge(block.true_block))
|
||||
add_branch(block_id, block.true_block);
|
||||
if (!is_back_edge(block.false_block))
|
||||
add_branch(block_id, block.false_block);
|
||||
break;
|
||||
|
||||
case SPIRBlock::MultiSelect:
|
||||
{
|
||||
const auto &cases = compiler.get_case_list(block);
|
||||
for (const auto &target : cases)
|
||||
{
|
||||
if (!is_back_edge(target.block))
|
||||
add_branch(block_id, target.block);
|
||||
}
|
||||
if (block.default_block && !is_back_edge(block.default_block))
|
||||
add_branch(block_id, block.default_block);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// If this is a selection merge, add an implied branch to the merge target.
|
||||
// This is needed to avoid cases where an inner branch dominates the outer branch.
|
||||
// This can happen if one of the branches exit early, e.g.:
|
||||
// if (cond) { ...; break; } else { var = 100 } use_var(var);
|
||||
// We can use the variable without a Phi since there is only one possible parent here.
|
||||
// However, in this case, we need to hoist out the inner variable to outside the branch.
|
||||
// Use same strategy as loops.
|
||||
if (block.merge == SPIRBlock::MergeSelection && !is_back_edge(block.next_block))
|
||||
{
|
||||
// If there is only one preceding edge to the merge block and it's not ourselves, we need a fixup.
|
||||
// Add a fake branch so any dominator in either the if (), or else () block, or a lone case statement
|
||||
// will be hoisted out to outside the selection merge.
|
||||
// If size > 1, the variable will be automatically hoisted, so we should not mess with it.
|
||||
// The exception here is switch blocks, where we can have multiple edges to merge block,
|
||||
// all coming from same scope, so be more conservative in this case.
|
||||
// Adding fake branches unconditionally breaks parameter preservation analysis,
|
||||
// which looks at how variables are accessed through the CFG.
|
||||
auto pred_itr = preceding_edges.find(block.next_block);
|
||||
if (pred_itr != end(preceding_edges))
|
||||
{
|
||||
auto &pred = pred_itr->second;
|
||||
auto succ_itr = succeeding_edges.find(block_id);
|
||||
size_t num_succeeding_edges = 0;
|
||||
if (succ_itr != end(succeeding_edges))
|
||||
num_succeeding_edges = succ_itr->second.size();
|
||||
|
||||
if (block.terminator == SPIRBlock::MultiSelect && num_succeeding_edges == 1)
|
||||
{
|
||||
// Multiple branches can come from the same scope due to "break;", so we need to assume that all branches
|
||||
// come from same case scope in worst case, even if there are multiple preceding edges.
|
||||
// If we have more than one succeeding edge from the block header, it should be impossible
|
||||
// to have a dominator be inside the block.
|
||||
// Only case this can go wrong is if we have 2 or more edges from block header and
|
||||
// 2 or more edges to merge block, and still have dominator be inside a case label.
|
||||
if (!pred.empty())
|
||||
add_branch(block_id, block.next_block);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pred.size() == 1 && *pred.begin() != block_id)
|
||||
add_branch(block_id, block.next_block);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the merge block does not have any preceding edges, i.e. unreachable, hallucinate it.
|
||||
// We're going to do code-gen for it, and domination analysis requires that we have at least one preceding edge.
|
||||
add_branch(block_id, block.next_block);
|
||||
}
|
||||
}
|
||||
|
||||
visited = true;
|
||||
visit_block.order = ++visit_count;
|
||||
post_order.push_back(block_id);
|
||||
}
|
||||
|
||||
void CFG::build_post_order_visit_order()
|
||||
{
|
||||
uint32_t block = func.entry_block;
|
||||
visit_count = 0;
|
||||
visit_order.clear();
|
||||
post_order.clear();
|
||||
post_order_visit_entry(block);
|
||||
}
|
||||
|
||||
static void add_unique(SmallVector <uint32_t> &l, uint32_t value)
|
||||
{
|
||||
auto itr = find(begin(l), end(l), value);
|
||||
if (itr == end(l))
|
||||
l.push_back(value);
|
||||
}
|
||||
|
||||
void CFG::add_branch(uint32_t from, uint32_t to)
|
||||
{
|
||||
assert(from && to);
|
||||
add_unique(preceding_edges[to], from);
|
||||
add_unique(succeeding_edges[from], to);
|
||||
}
|
||||
|
||||
void CFG::add_virtual_dominance_branch(uint32_t from, uint32_t to)
|
||||
{
|
||||
assert(from && to);
|
||||
add_unique(virtual_dominance_preceding_edges[to], from);
|
||||
}
|
||||
|
||||
uint32_t CFG::find_loop_dominator(uint32_t block_id) const
|
||||
{
|
||||
while (block_id != SPIRBlock::NoDominator)
|
||||
{
|
||||
auto itr = preceding_edges.find(block_id);
|
||||
if (itr == end(preceding_edges))
|
||||
return SPIRBlock::NoDominator;
|
||||
if (itr->second.empty())
|
||||
return SPIRBlock::NoDominator;
|
||||
|
||||
uint32_t pred_block_id = SPIRBlock::NoDominator;
|
||||
bool ignore_loop_header = false;
|
||||
|
||||
// If we are a merge block, go directly to the header block.
|
||||
// Only consider a loop dominator if we are branching from inside a block to a loop header.
|
||||
// NOTE: In the CFG we forced an edge from header to merge block always to support variable scopes properly.
|
||||
for (auto &pred : itr->second)
|
||||
{
|
||||
auto &pred_block = compiler.get<SPIRBlock>(pred);
|
||||
if (pred_block.merge == SPIRBlock::MergeLoop && pred_block.merge_block == ID(block_id))
|
||||
{
|
||||
pred_block_id = pred;
|
||||
ignore_loop_header = true;
|
||||
break;
|
||||
}
|
||||
else if (pred_block.merge == SPIRBlock::MergeSelection && pred_block.next_block == ID(block_id))
|
||||
{
|
||||
pred_block_id = pred;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// No merge block means we can just pick any edge. Loop headers dominate the inner loop, so any path we
|
||||
// take will lead there.
|
||||
if (pred_block_id == SPIRBlock::NoDominator)
|
||||
pred_block_id = itr->second.front();
|
||||
|
||||
block_id = pred_block_id;
|
||||
|
||||
if (!ignore_loop_header && block_id)
|
||||
{
|
||||
auto &block = compiler.get<SPIRBlock>(block_id);
|
||||
if (block.merge == SPIRBlock::MergeLoop)
|
||||
return block_id;
|
||||
}
|
||||
}
|
||||
|
||||
return block_id;
|
||||
}
|
||||
|
||||
bool CFG::node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const
|
||||
{
|
||||
// Walk backwards, starting from "to" block.
|
||||
// Only follow pred edges if they have a 1:1 relationship, or a merge relationship.
|
||||
// If we cannot find a path to "from", we must assume that to is inside control flow in some way.
|
||||
|
||||
auto &from_block = compiler.get<SPIRBlock>(from);
|
||||
BlockID ignore_block_id = 0;
|
||||
if (from_block.merge == SPIRBlock::MergeLoop)
|
||||
ignore_block_id = from_block.merge_block;
|
||||
|
||||
while (to != from)
|
||||
{
|
||||
auto pred_itr = preceding_edges.find(to);
|
||||
if (pred_itr == end(preceding_edges))
|
||||
return false;
|
||||
|
||||
DominatorBuilder builder(*this);
|
||||
for (auto &edge : pred_itr->second)
|
||||
builder.add_block(edge);
|
||||
|
||||
uint32_t dominator = builder.get_dominator();
|
||||
if (dominator == 0)
|
||||
return false;
|
||||
|
||||
auto &dom = compiler.get<SPIRBlock>(dominator);
|
||||
|
||||
bool true_path_ignore = false;
|
||||
bool false_path_ignore = false;
|
||||
|
||||
bool merges_to_nothing = dom.merge == SPIRBlock::MergeNone ||
|
||||
(dom.merge == SPIRBlock::MergeSelection && dom.next_block &&
|
||||
compiler.get<SPIRBlock>(dom.next_block).terminator == SPIRBlock::Unreachable) ||
|
||||
(dom.merge == SPIRBlock::MergeLoop && dom.merge_block &&
|
||||
compiler.get<SPIRBlock>(dom.merge_block).terminator == SPIRBlock::Unreachable);
|
||||
|
||||
if (dom.self == from || merges_to_nothing)
|
||||
{
|
||||
// We can only ignore inner branchy paths if there is no merge,
|
||||
// i.e. no code is generated afterwards. E.g. this allows us to elide continue:
|
||||
// for (;;) { if (cond) { continue; } else { break; } }.
|
||||
// Codegen here in SPIR-V will be something like either no merge if one path directly breaks, or
|
||||
// we merge to Unreachable.
|
||||
if (ignore_block_id && dom.terminator == SPIRBlock::Select)
|
||||
{
|
||||
auto &true_block = compiler.get<SPIRBlock>(dom.true_block);
|
||||
auto &false_block = compiler.get<SPIRBlock>(dom.false_block);
|
||||
auto &ignore_block = compiler.get<SPIRBlock>(ignore_block_id);
|
||||
true_path_ignore = compiler.execution_is_branchless(true_block, ignore_block);
|
||||
false_path_ignore = compiler.execution_is_branchless(false_block, ignore_block);
|
||||
}
|
||||
}
|
||||
|
||||
// Cases where we allow traversal. This serves as a proxy for post-dominance in a loop body.
|
||||
// TODO: Might want to do full post-dominance analysis, but it's a lot of churn for something like this ...
|
||||
// - We're the merge block of a selection construct. Jump to header.
|
||||
// - We're the merge block of a loop. Jump to header.
|
||||
// - Direct branch. Trivial.
|
||||
// - Allow cases inside a branch if the header cannot merge execution before loop exit.
|
||||
if ((dom.merge == SPIRBlock::MergeSelection && dom.next_block == to) ||
|
||||
(dom.merge == SPIRBlock::MergeLoop && dom.merge_block == to) ||
|
||||
(dom.terminator == SPIRBlock::Direct && dom.next_block == to) ||
|
||||
(dom.terminator == SPIRBlock::Select && dom.true_block == to && false_path_ignore) ||
|
||||
(dom.terminator == SPIRBlock::Select && dom.false_block == to && true_path_ignore))
|
||||
{
|
||||
// Allow walking selection constructs if the other branch reaches out of a loop construct.
|
||||
// It cannot be in-scope anymore.
|
||||
to = dominator;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DominatorBuilder::DominatorBuilder(const CFG &cfg_)
|
||||
: cfg(cfg_)
|
||||
{
|
||||
}
|
||||
|
||||
void DominatorBuilder::add_block(uint32_t block)
|
||||
{
|
||||
if (!cfg.get_immediate_dominator(block))
|
||||
{
|
||||
// Unreachable block via the CFG, we will never emit this code anyways.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dominator)
|
||||
{
|
||||
dominator = block;
|
||||
return;
|
||||
}
|
||||
|
||||
if (block != dominator)
|
||||
dominator = cfg.find_common_dominator(block, dominator);
|
||||
}
|
||||
|
||||
void DominatorBuilder::lift_continue_block_dominator()
|
||||
{
|
||||
// It is possible for a continue block to be the dominator of a variable is only accessed inside the while block of a do-while loop.
|
||||
// We cannot safely declare variables inside a continue block, so move any variable declared
|
||||
// in a continue block to the entry block to simplify.
|
||||
// It makes very little sense for a continue block to ever be a dominator, so fall back to the simplest
|
||||
// solution.
|
||||
|
||||
if (!dominator)
|
||||
return;
|
||||
|
||||
auto &block = cfg.get_compiler().get<SPIRBlock>(dominator);
|
||||
auto post_order = cfg.get_visit_order(dominator);
|
||||
|
||||
// If we are branching to a block with a higher post-order traversal index (continue blocks), we have a problem
|
||||
// since we cannot create sensible GLSL code for this, fallback to entry block.
|
||||
bool back_edge_dominator = false;
|
||||
switch (block.terminator)
|
||||
{
|
||||
case SPIRBlock::Direct:
|
||||
if (cfg.get_visit_order(block.next_block) > post_order)
|
||||
back_edge_dominator = true;
|
||||
break;
|
||||
|
||||
case SPIRBlock::Select:
|
||||
if (cfg.get_visit_order(block.true_block) > post_order)
|
||||
back_edge_dominator = true;
|
||||
if (cfg.get_visit_order(block.false_block) > post_order)
|
||||
back_edge_dominator = true;
|
||||
break;
|
||||
|
||||
case SPIRBlock::MultiSelect:
|
||||
{
|
||||
auto &cases = cfg.get_compiler().get_case_list(block);
|
||||
for (auto &target : cases)
|
||||
{
|
||||
if (cfg.get_visit_order(target.block) > post_order)
|
||||
back_edge_dominator = true;
|
||||
}
|
||||
if (block.default_block && cfg.get_visit_order(block.default_block) > post_order)
|
||||
back_edge_dominator = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (back_edge_dominator)
|
||||
dominator = cfg.get_function().entry_block;
|
||||
}
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
168
thirdparty/SPIRV-Cross/spirv_cfg.hpp
vendored
Normal file
168
thirdparty/SPIRV-Cross/spirv_cfg.hpp
vendored
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright 2016-2021 Arm Limited
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_CFG_HPP
|
||||
#define SPIRV_CROSS_CFG_HPP
|
||||
|
||||
#include "spirv_common.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class Compiler;
|
||||
class CFG
|
||||
{
|
||||
public:
|
||||
CFG(Compiler &compiler, const SPIRFunction &function);
|
||||
|
||||
Compiler &get_compiler()
|
||||
{
|
||||
return compiler;
|
||||
}
|
||||
|
||||
const Compiler &get_compiler() const
|
||||
{
|
||||
return compiler;
|
||||
}
|
||||
|
||||
const SPIRFunction &get_function() const
|
||||
{
|
||||
return func;
|
||||
}
|
||||
|
||||
uint32_t get_immediate_dominator(uint32_t block) const
|
||||
{
|
||||
auto itr = immediate_dominators.find(block);
|
||||
if (itr != std::end(immediate_dominators))
|
||||
return itr->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool is_reachable(uint32_t block) const
|
||||
{
|
||||
return visit_order.count(block) != 0;
|
||||
}
|
||||
|
||||
uint32_t get_visit_order(uint32_t block) const
|
||||
{
|
||||
auto itr = visit_order.find(block);
|
||||
assert(itr != std::end(visit_order));
|
||||
int v = itr->second.order;
|
||||
assert(v > 0);
|
||||
return uint32_t(v);
|
||||
}
|
||||
|
||||
uint32_t find_common_dominator(uint32_t a, uint32_t b) const;
|
||||
|
||||
const SmallVector<uint32_t> &get_preceding_edges(uint32_t block) const
|
||||
{
|
||||
auto itr = preceding_edges.find(block);
|
||||
if (itr != std::end(preceding_edges))
|
||||
return itr->second;
|
||||
else
|
||||
return empty_vector;
|
||||
}
|
||||
|
||||
const SmallVector<uint32_t> &get_succeeding_edges(uint32_t block) const
|
||||
{
|
||||
auto itr = succeeding_edges.find(block);
|
||||
if (itr != std::end(succeeding_edges))
|
||||
return itr->second;
|
||||
else
|
||||
return empty_vector;
|
||||
}
|
||||
|
||||
template <typename Op>
|
||||
void walk_from(std::unordered_set<uint32_t> &seen_blocks, uint32_t block, const Op &op) const
|
||||
{
|
||||
if (seen_blocks.count(block))
|
||||
return;
|
||||
seen_blocks.insert(block);
|
||||
|
||||
if (op(block))
|
||||
{
|
||||
for (auto b : get_succeeding_edges(block))
|
||||
walk_from(seen_blocks, b, op);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t find_loop_dominator(uint32_t block) const;
|
||||
|
||||
bool node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const;
|
||||
|
||||
private:
|
||||
struct VisitOrder
|
||||
{
|
||||
int order = -1;
|
||||
bool visited_resolve = false;
|
||||
bool visited_branches = false;
|
||||
};
|
||||
|
||||
Compiler &compiler;
|
||||
const SPIRFunction &func;
|
||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> preceding_edges;
|
||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> virtual_dominance_preceding_edges;
|
||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> succeeding_edges;
|
||||
std::unordered_map<uint32_t, uint32_t> immediate_dominators;
|
||||
std::unordered_map<uint32_t, VisitOrder> visit_order;
|
||||
SmallVector<uint32_t> post_order;
|
||||
SmallVector<uint32_t> empty_vector;
|
||||
|
||||
void add_branch(uint32_t from, uint32_t to);
|
||||
void add_virtual_dominance_branch(uint32_t from, uint32_t to);
|
||||
void build_post_order_visit_order();
|
||||
void build_immediate_dominators();
|
||||
void post_order_visit_branches(uint32_t block);
|
||||
void post_order_visit_resolve(uint32_t block);
|
||||
void post_order_visit_entry(uint32_t block);
|
||||
uint32_t visit_count = 0;
|
||||
|
||||
bool is_back_edge(uint32_t to) const;
|
||||
bool has_visited_branch(uint32_t to) const;
|
||||
void visit_branch(uint32_t block_id);
|
||||
|
||||
SmallVector<uint32_t> visit_stack;
|
||||
size_t last_visited_size = 0;
|
||||
};
|
||||
|
||||
class DominatorBuilder
|
||||
{
|
||||
public:
|
||||
DominatorBuilder(const CFG &cfg);
|
||||
|
||||
void add_block(uint32_t block);
|
||||
uint32_t get_dominator() const
|
||||
{
|
||||
return dominator;
|
||||
}
|
||||
|
||||
void lift_continue_block_dominator();
|
||||
|
||||
private:
|
||||
const CFG &cfg;
|
||||
uint32_t dominator = 0;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
2096
thirdparty/SPIRV-Cross/spirv_common.hpp
vendored
Normal file
2096
thirdparty/SPIRV-Cross/spirv_common.hpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue