diff --git a/CHANGELOG.md b/CHANGELOG.md
index a772833b..275f74a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,9 +3,7 @@
Notable changes per release. Releases are tagged `vX.Y.Z`; the version lives in
`CMakeLists.txt` and is available in code from `gui_core/gui_version.h`.
-## [Unreleased] — 0.1.0
-
-First public preview. The API is not stable yet.
+## [Unreleased] — 1.1.0
- Immediate-mode style GUI library for C++20 on Vulkan and SDL3 (`gui_core`, `gui_controls`).
- CSS-like styling with a dark and a light theme; text shaping, bidi and font fallback through skribidi.
@@ -305,4 +303,5 @@ First public preview. The API is not stable yet.
- Showcase: every Hierarchy panel shows one scene, and every Files panel one set of files. An object added, deleted or moved in one Hierarchy, or a file moved or renamed in one Files panel, shows in the others; what each one opened, selected and searched stays its own.
- Fixed: a window that closed in the frame its own redraw ran, while it was resized or shown again, crashed the app: dragging a docked panel by its tab and dropping it could close the drag preview that way. The Vulkan, Direct3D 12, SDL GPU and Metal window contexts stop that redraw once the frame has closed their window, and don't present it.
- Fixed: a rich-text run's own color (`ContentRun::color` or `background`, a link's) was registered as a color style that was never let go, so a run whose color changed every frame added a style a frame. A run's color now has a style of its own, shared by the runs in that color and let go some frames after nothing draws with it. A cached panel's replay keeps the colors its text was drawn with, and one that went makes the panel draw again.
+- Runs on GPUs without 16-bit shader types: GeForce GTX 750, 900 and 10 series and Radeon RX 400 and 500 series on Vulkan; GeForce GTX 900 and 10 series and Radeon R9 285, 380 and Fury and RX 400 and 500 series on Direct3D 12. The shaders read the primitives' and styles' 16-bit fields from the 32-bit words holding them, with 32-bit operations; the data and what's drawn are unchanged. The Vulkan backend no longer requires `shaderFloat16`, `shaderInt16`, `shaderInt8` or 8- and 16-bit storage, and SDL GPU's device no longer asks for the 16-bit ones.
- SDL GPU: the shaders read each color style's image once, not once for each color type, so they hold far less code. SDL GPU can't index its images, so each read is a case for every image a draw binds. A driver that compiles shaders when they're first drawn with no longer stalls: lavapipe on Windows took 15 s to draw a first frame, and now takes under 3.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c90d686..3232d425 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,7 +17,7 @@ if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.3" CACHE STRING "The oldest macOS the programs run on")
endif()
-set(TACHYON_VERSION 0.1.0)
+set(TACHYON_VERSION 1.1.0)
project(TachyonUI VERSION ${TACHYON_VERSION} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
diff --git a/README.md b/README.md
index dd17d4b2..8f32e353 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
-
+
@@ -43,14 +43,30 @@ in an application that already has a Vulkan, Direct3D 12 or Metal renderer.
### Windows
+Renders with Vulkan by default.
+
- Windows x64
- Visual Studio 2026 with CMake 4.2 or newer, or Visual Studio 2022 with CMake 3.22 or newer
- The [Vulkan SDK](https://vulkan.lunarg.com/) 1.4.341 or newer, for its Slang shader compiler
(or an older SDK and a [Slang release](https://github.com/shader-slang/slang/releases) 2026.1 or newer)
- Git with [Git LFS](https://git-lfs.com/) (the fonts are stored in LFS)
+- A GPU with Vulkan 1.3, on a current driver:
+ - NVIDIA GeForce GTX 750 or 900 series, or newer
+ - AMD Radeon RX 400 series, or newer
+ - Intel HD or UHD Graphics 500 or 600 (6th-gen Core), Iris Xe or Arc, or newer
+- Optional: `-DTACHYON_D3D12=ON` adds the Direct3D 12 backend (no extra packages);
+ `--graphics d3d12` picks it in the showcase. It needs one of these GPUs, on a current driver:
+ - NVIDIA GeForce GTX 900 series, or newer
+ - AMD Radeon R9 285, R9 380 or R9 Fury, Radeon RX 400 series, or newer
+ - Intel Iris Plus (10th-gen Core "Ice Lake"), Iris Xe or Arc, or newer; not the HD or UHD
+ Graphics of 6th to 10th-gen Core
+- Optional: `-DTACHYON_SDLGPU=ON` adds the SDL GPU backend, on SDL's Vulkan or Direct3D 12
+ driver (no extra packages); `--graphics sdlgpu` picks it in the showcase
### Linux
+Renders with Vulkan by default.
+
- Linux x64
- GCC 13 or newer, or Clang 17 or newer
- CMake 3.22 or newer and Ninja
@@ -58,29 +74,31 @@ in an application that already has a Vulkan, Direct3D 12 or Metal renderer.
- The [Vulkan SDK](https://vulkan.lunarg.com/) 1.4.341 or newer, or your distribution's Vulkan
packages and a [Slang release](https://github.com/shader-slang/slang/releases) 2026.1 or newer
- Git with [Git LFS](https://git-lfs.com/) (the fonts are stored in LFS)
+- A GPU with Vulkan 1.3, on a current driver:
+ - NVIDIA GeForce GTX 750 or 900 series, or newer, on NVIDIA's driver
+ - AMD Radeon RX 400 series, or newer, on Mesa
+ - Intel HD or UHD Graphics 500 or 600 (6th-gen Core), Iris Xe or Arc, or newer, on Mesa
+- Optional: `-DTACHYON_SDLGPU=ON` adds the SDL GPU backend, on SDL's Vulkan driver (no extra
+ packages); `--graphics sdlgpu` picks it in the showcase
### macOS
-Renders with Metal by default.
+Renders with Metal by default.
-- macOS 13.3 or newer, on Apple silicon or an Intel Mac with a Metal 3 GPU
+- macOS 13.3 or newer
- Apple Clang: Xcode or just its Command Line Tools (`xcode-select --install`)
- CMake 3.22 or newer and Ninja (`brew install cmake ninja git-lfs`)
- A [Slang release](https://github.com/shader-slang/slang/releases) 2026.1 or newer for its `slangc`
(it's not in Homebrew): unpack it and put `slangc` on the `PATH`, or set `SLANGC` to it
- Git with [Git LFS](https://git-lfs.com/) (the fonts are stored in LFS)
+- A GPU with Metal 3:
+ - every Apple silicon Mac
+ - on an Intel Mac: AMD Radeon Vega, Radeon 5000 or 6000 series, or Intel UHD Graphics 630, or newer
- Optional: `-DTACHYON_SDLGPU=ON` adds the SDL GPU backend, on SDL's Metal driver (no extra
packages); `--graphics sdlgpu` picks it in the showcase
- Optional: `-DTACHYON_VULKAN=ON` adds the Vulkan backend through MoltenVK (the Vulkan SDK, or
Homebrew's `vulkan-headers`, `vulkan-loader` and `molten-vk`); `--graphics vulkan` picks it in the showcase
-### To run
-
-- Windows and Linux: a GPU driver with Vulkan 1.3 and the features listed by
- `VulkanDeviceContext::GetDeviceRequirements()`
-- macOS: a GPU of the Metal 3 family (every Apple silicon Mac; on Intel Macs, AMD Vega,
- Radeon 5000/6000 or Intel UHD 630 and newer)
-
## Quick start
```sh
@@ -142,7 +160,7 @@ If you're new to TachyonUI, the [tutorial](docs/tutorial.md) goes from an empty
app with docked panels, buttons and fields.
```cmake
-find_package(TachyonUI 0.1 CONFIG REQUIRED) # after cmake --install
+find_package(TachyonUI 1.1 CONFIG REQUIRED) # after cmake --install
# or: add_subdirectory(external/TachyonUI)
target_link_libraries(my_app PRIVATE TachyonUI::gui_controls)
```
@@ -165,8 +183,8 @@ The synchronization rules and code are in [Using your own Vulkan device](docs/in
## Status
-**0.1 preview.** The API will still change. Windows x64 and Linux x64 are built and tested in
-CI. macOS (Apple silicon) runs on Metal; CI builds it and runs the tests that need no GPU.
+**1.1.** Windows x64 and Linux x64 are built and tested in CI. macOS (Apple silicon) runs on
+Metal; CI builds it and runs the tests that need no GPU.
---
diff --git a/cmake/TachyonUIConfig.cmake.in b/cmake/TachyonUIConfig.cmake.in
index de72d11d..888089ef 100644
--- a/cmake/TachyonUIConfig.cmake.in
+++ b/cmake/TachyonUIConfig.cmake.in
@@ -2,7 +2,7 @@
# TachyonUI: C++ GUI library (gui_core, gui_controls).
#
-# find_package(TachyonUI 0.1 CONFIG REQUIRED)
+# find_package(TachyonUI 1.1 CONFIG REQUIRED)
# target_link_libraries(my_app PRIVATE TachyonUI::gui_controls)
#
# Provides:
diff --git a/docs/integration/build.md b/docs/integration/build.md
index 440e7670..785910bb 100644
--- a/docs/integration/build.md
+++ b/docs/integration/build.md
@@ -131,7 +131,7 @@ cmake --install build --config Release --prefix
A program using the package then needs no TachyonUI source or build tree:
```cmake
-find_package(TachyonUI 0.1 CONFIG REQUIRED)
+find_package(TachyonUI 1.1 CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE TachyonUI::gui_controls)
```
@@ -144,7 +144,7 @@ target_link_libraries(my_app PRIVATE TachyonUI::gui_controls)
```cmake
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)
set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release)
- find_package(TachyonUI 0.1 CONFIG REQUIRED)
+ find_package(TachyonUI 1.1 CONFIG REQUIRED)
```
- A minimal program using the package: `tests/package_consumer`.
diff --git a/docs/integration/sdlgpu-device.md b/docs/integration/sdlgpu-device.md
index 3b08fdef..44a45878 100644
--- a/docs/integration/sdlgpu-device.md
+++ b/docs/integration/sdlgpu-device.md
@@ -30,9 +30,7 @@ app.Initialize(options);
- The GUI's shaders are built as SPIR-V (for Vulkan), on Windows DXIL (for Direct3D 12), and on
macOS Metal source (MSL, for Metal). The device must take one of them.
-- On Vulkan, the shaders use features SDL doesn't turn on by itself:
- - 16-bit storage and 16-bit types
- - draw parameters
+- On Vulkan, the shaders use a feature SDL doesn't turn on by itself: draw parameters.
- `SDLGPUGraphicsContext::ApplyDeviceRequirements(props)` sets all of that on the properties
you create the device with:
@@ -47,12 +45,8 @@ SDL_DestroyProperties(props);
```
- It sets the Vulkan options property (`SDL_PROP_GPU_DEVICE_CREATE_VULKAN_OPTIONS_POINTER`).
- - If you set Vulkan options of your own, they replace it. Then turn these on in yours, with
- Vulkan 1.2:
- - `storageBuffer16BitAccess`, `uniformAndStorageBuffer16BitAccess` and
- `shaderDrawParameters` (Vulkan 1.1 features)
- - `shaderFloat16` (Vulkan 1.2)
- - `shaderInt16` (Vulkan 1.0)
+ - If you set Vulkan options of your own, they replace it. Then turn on `shaderDrawParameters`
+ (a Vulkan 1.1 feature) in yours, with Vulkan 1.2.
- `SDLGPUGraphicsContext::CheckDeviceSupport(device, &problems)` checks a device. It lists what
the device lacks, one line each:
diff --git a/docs/tutorial/setup.md b/docs/tutorial/setup.md
index 3a57d09b..ddd152a9 100644
--- a/docs/tutorial/setup.md
+++ b/docs/tutorial/setup.md
@@ -45,7 +45,7 @@ target_link_libraries(my_app PRIVATE TachyonUI::gui_controls)
the program.
- As a subproject, TachyonUI builds only its libraries, not its examples or tests.
- For an installed TachyonUI, replace `add_subdirectory` with
- `find_package(TachyonUI 0.1 CONFIG REQUIRED)`; see
+ `find_package(TachyonUI 1.1 CONFIG REQUIRED)`; see
[Adding the library to a build](../integration/build.md).
## Building
diff --git a/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.cpp b/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.cpp
index 529c7539..73ec7ba0 100644
--- a/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.cpp
+++ b/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.cpp
@@ -162,27 +162,20 @@ namespace tachyon::sdlgpu
void SDLGPUGraphicsContext::ApplyDeviceRequirements(SDL_PropertiesID props)
{
- // On Vulkan, what the shaders use that SDL's device doesn't enable by itself: the 16-bit
- // types, and the draw parameters SV_VertexID is built from (VertexIndex - BaseVertex).
- // SDL reads them when the device is made; they live as long as the program.
+ // On Vulkan, what the shaders use that SDL's device doesn't enable by itself: the draw
+ // parameters SV_VertexID is built from (VertexIndex - BaseVertex). SDL reads them when the
+ // device is made; they live as long as the program.
struct Vulkan
{
- VkPhysicalDeviceVulkan12Features features12{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES };
VkPhysicalDeviceVulkan11Features features11{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES };
- VkPhysicalDeviceFeatures features10{};
SDL_GPUVulkanOptions options{};
Vulkan()
{
- features12.shaderFloat16 = VK_TRUE;
- features11.pNext = &features12;
- features11.shaderDrawParameters = VK_TRUE;
- features11.storageBuffer16BitAccess = VK_TRUE;
- features11.uniformAndStorageBuffer16BitAccess = VK_TRUE;
- features10.shaderInt16 = VK_TRUE;
- options.vulkan_api_version = VK_API_VERSION_1_2;
- options.feature_list = &features11;
- options.vulkan_10_physical_device_features = &features10;
+ features11.shaderDrawParameters = VK_TRUE;
+ // The Vulkan 1.1 features struct is Vulkan 1.2's.
+ options.vulkan_api_version = VK_API_VERSION_1_2;
+ options.feature_list = &features11;
}
};
static Vulkan vulkan;
diff --git a/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.h b/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.h
index 96fe9e8b..0123c807 100644
--- a/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.h
+++ b/src/gui_core/graphics/sdlgpu/sdlgpu_graphics_context.h
@@ -64,12 +64,10 @@ namespace tachyon::sdlgpu
/// Sets on `props` what the GUI's shaders need of a device a host makes with
/// SDL_CreateGPUDeviceWithProperties: the shader formats they're built in (SPIR-V, and
- /// DXIL on Windows), and on Vulkan the features they use (16-bit storage and types,
- /// draw parameters), as SDL_PROP_GPU_DEVICE_CREATE_VULKAN_OPTIONS_POINTER. Options of
- /// the host's own replace those: then enable storageBuffer16BitAccess,
- /// uniformAndStorageBuffer16BitAccess and shaderDrawParameters (Vulkan 1.1),
- /// shaderFloat16 (1.2) and shaderInt16 (1.0) in them, with Vulkan 1.2. What it points to
- /// lives as long as the program.
+ /// DXIL on Windows), and on Vulkan the feature they use (draw parameters), as
+ /// SDL_PROP_GPU_DEVICE_CREATE_VULKAN_OPTIONS_POINTER. Options of the host's own replace
+ /// those: then enable shaderDrawParameters (Vulkan 1.1) in them, with Vulkan 1.2. What it
+ /// points to lives as long as the program.
static void ApplyDeviceRequirements(SDL_PropertiesID props);
/// Whether `device` takes the GUI's shaders; what it lacks, one line each, in
/// `problems`. SDL can't tell which Vulkan features a device has: one made without
diff --git a/src/gui_core/graphics/vulkan/vk_graphics_context.cpp b/src/gui_core/graphics/vulkan/vk_graphics_context.cpp
index a4e0a4da..6a4bcd29 100644
--- a/src/gui_core/graphics/vulkan/vk_graphics_context.cpp
+++ b/src/gui_core/graphics/vulkan/vk_graphics_context.cpp
@@ -1150,17 +1150,12 @@ tachyon::vulkan::VulkanDeviceContext::DeviceRequirements tachyon::vulkan::Vulkan
requirements.features12.descriptorBindingPartiallyBound = true;
requirements.features12.descriptorBindingVariableDescriptorCount = true;
requirements.features12.runtimeDescriptorArray = true;
- requirements.features12.storageBuffer8BitAccess = true;
- requirements.features12.uniformAndStorageBuffer8BitAccess = true;
requirements.features12.shaderSampledImageArrayNonUniformIndexing = true;
- requirements.features12.shaderInt8 = true;
- requirements.features12.shaderFloat16 = true;
requirements.features12.timelineSemaphore = true; // AddFrameWait
+ // No 16- or 8-bit types: the shaders read packed fields as 32-bit words (all_common.slang).
requirements.features11.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
- requirements.features11.storageBuffer16BitAccess = true;
- requirements.features.shaderInt16 = true;
requirements.features.shaderInt64 = true; // the shaders' buffer addresses
requirements.features.robustBufferAccess = true;
@@ -1201,15 +1196,9 @@ bool tachyon::vulkan::VulkanDeviceContext::CheckPhysicalDeviceSupport(VkPhysical
TACHYON_REQUIRE_FEATURE(features12, descriptorBindingPartiallyBound);
TACHYON_REQUIRE_FEATURE(features12, descriptorBindingVariableDescriptorCount);
TACHYON_REQUIRE_FEATURE(features12, runtimeDescriptorArray);
- TACHYON_REQUIRE_FEATURE(features12, storageBuffer8BitAccess);
- TACHYON_REQUIRE_FEATURE(features12, uniformAndStorageBuffer8BitAccess);
TACHYON_REQUIRE_FEATURE(features12, shaderSampledImageArrayNonUniformIndexing);
- TACHYON_REQUIRE_FEATURE(features12, shaderInt8);
- TACHYON_REQUIRE_FEATURE(features12, shaderFloat16);
TACHYON_REQUIRE_FEATURE(features12, timelineSemaphore);
- TACHYON_REQUIRE_FEATURE(features11, storageBuffer16BitAccess);
#undef TACHYON_REQUIRE_FEATURE
- if (required.features.shaderInt16 && !have.features.shaderInt16) missing("features.shaderInt16");
if (required.features.shaderInt64 && !have.features.shaderInt64) missing("features.shaderInt64");
if (required.features.robustBufferAccess && !have.features.robustBufferAccess) missing("features.robustBufferAccess");
diff --git a/tests/built_in_resources_test.cpp b/tests/built_in_resources_test.cpp
index adbe48af..14cb5bd6 100644
--- a/tests/built_in_resources_test.cpp
+++ b/tests/built_in_resources_test.cpp
@@ -89,6 +89,67 @@ namespace
EXPECT_EQ(dxil, std::size(kPrimitiveSpecs) * 2 * backends);
}
+ // The shaders keep their 16-bit fields packed in 32-bit words and do their math in 32 bits,
+ // so they run on GPUs without 16-bit shader types: SPIR-V declares no 16- or 8-bit capability.
+ TEST(BuiltInShaders, TheSPIRVNeedsNo16Or8BitTypes)
+ {
+ constexpr uint32_t kMagic = 0x07230203, kOpCapability = 17;
+ // Float16, Int16, Int8; 16-bit storage (buffer, uniform, push constant, in/out); 8-bit storage.
+ constexpr uint32_t kNarrow[] = { 9, 22, 39, 4433, 4434, 4435, 4436, 4448, 4449, 4450 };
+ size_t modules = 0;
+ for (const detail::EmbeddedFile& file : detail::EmbeddedShaderFiles())
+ {
+ if (!file.key.ends_with(".spv"))
+ continue;
+ ++modules;
+ std::vector words(file.data.size() / 4);
+ std::memcpy(words.data(), file.data.data(), words.size() * 4);
+ ASSERT_GT(words.size(), 5u) << file.key;
+ ASSERT_EQ(words[0], kMagic) << file.key;
+ for (size_t i = 5; i < words.size();)
+ {
+ const uint32_t opcode = words[i] & 0xFFFFu, count = words[i] >> 16;
+ ASSERT_GT(count, 0u) << file.key;
+ if (opcode == kOpCapability && count == 2)
+ EXPECT_EQ(std::ranges::count(kNarrow, words[i + 1]), 0) << file.key << " declares capability " << words[i + 1];
+ i += count;
+ }
+ }
+ if (modules == 0) GTEST_SKIP() << "built without a backend that runs SPIR-V";
+ }
+
+ // Nor does the DXIL ask for native 16-bit operations (the "SFI0" part's feature flags).
+ TEST(BuiltInShaders, TheDXILNeedsNoNative16BitOps)
+ {
+ constexpr uint64_t kNative16BitOps = 0x40000; // D3D_SHADER_REQUIRES_NATIVE_16BIT_OPS
+ size_t modules = 0;
+ for (const detail::EmbeddedFile& file : detail::EmbeddedShaderFiles())
+ {
+ if (!file.key.ends_with(".dxil"))
+ continue;
+ ++modules;
+ auto read32 = [&](size_t at) { uint32_t v = 0; std::memcpy(&v, file.data.data() + at, 4); return v; };
+ // DXBC, a 16-byte hash, a version, the container's size, the part count, then each
+ // part's offset; a part is its four letters, its size and its data.
+ ASSERT_GE(file.data.size(), 32u) << file.key;
+ const uint32_t parts = read32(28);
+ bool found = false;
+ for (uint32_t p = 0; p < parts; ++p)
+ {
+ const uint32_t at = read32(32 + 4 * p);
+ ASSERT_LE(size_t(at) + 16, file.data.size()) << file.key;
+ if (std::memcmp(file.data.data() + at, "SFI0", 4) != 0)
+ continue;
+ uint64_t flags = 0;
+ std::memcpy(&flags, file.data.data() + at + 8, 8);
+ EXPECT_EQ(flags & kNative16BitOps, 0u) << file.key << " needs native 16-bit operations";
+ found = true;
+ }
+ (void)found; // a shader that needs nothing extra has no SFI0 part
+ }
+ if (modules == 0) GTEST_SKIP() << "built without a backend that runs DXIL";
+ }
+
TEST(BuiltInResources, OnlyAtAFolderBoundary)
{
EXPECT_TRUE(FindBuiltInResource("styles.css").empty());
diff --git a/tests/package_consumer/CMakeLists.txt b/tests/package_consumer/CMakeLists.txt
index cd68c426..39894361 100644
--- a/tests/package_consumer/CMakeLists.txt
+++ b/tests/package_consumer/CMakeLists.txt
@@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
-find_package(TachyonUI 0.1 CONFIG REQUIRED)
+find_package(TachyonUI 1.1 CONFIG REQUIRED)
add_executable(package_consumer main.cpp)
target_link_libraries(package_consumer PRIVATE TachyonUI::gui_controls)
diff --git a/workdirectory/shaders/all_common.slang b/workdirectory/shaders/all_common.slang
index 23289669..e6a03d1e 100644
--- a/workdirectory/shaders/all_common.slang
+++ b/workdirectory/shaders/all_common.slang
@@ -2,28 +2,61 @@
// the push constants, and the color helpers. Structs read through a buffer address use Slang's
// natural layout, so every padding std430 would add is written out: offsets and sizes match the
// C++ structs.
+//
+// The C++ structs pack some fields in 16 bits (half, int16_t, uint16_t). Here those are read as
+// the 32-bit words holding them, two to a word (the first in the low half), and unpacked with
+// 32-bit operations: the shaders need no 16-bit types, which some GPUs (GeForce GTX 900 and 10,
+// Radeon RX 400 and 500) can't run. The values are widened before any math in either case.
+
+// Two halves, the first in the low 16 bits, as floats. SPIR-V has an instruction for it that
+// needs no 16-bit type, where Slang's f16tof32 goes through one; DXIL's f16tof32 needs none.
+float2 UnpackHalf2(uint bits)
+{
+ __target_switch
+ {
+ case spirv:
+ return spirv_asm { result:$$float2 = OpExtInst glsl450 UnpackHalf2x16 $bits };
+ default:
+ return f16tof32(uint2(bits & 0xFFFFu, bits >> 16));
+ }
+}
+float4 UnpackHalf4(uint2 bits) { return float4(UnpackHalf2(bits.x), UnpackHalf2(bits.y)); }
+// Two uint16_t, the first in the low 16 bits.
+uint2 UnpackUint16x2(uint bits) { return uint2(bits & 0xFFFFu, bits >> 16); }
+uint4 UnpackUint16x4(uint2 bits) { return uint4(UnpackUint16x2(bits.x), UnpackUint16x2(bits.y)); }
+// Two int16_t, the first in the low 16 bits, sign-extended.
+int2 UnpackInt16x2(uint bits) { return int2(int(bits << 16) >> 16, int(bits) >> 16); }
+int4 UnpackInt16x4(uint2 bits) { return int4(UnpackInt16x2(bits.x), UnpackInt16x2(bits.y)); }
struct ColorStyle
{
- half4 transformationX;
- half4 transformationY;
+ uint2 transformationXBits; // half4
+ uint2 transformationYBits; // half4
+ uint2 colorUVTypeBits; // uint16_t4 colorUV_type
- uint16_t4 colorUV_type;
+ int textureIndex;
+ uint animSpeedBits; // half2: x = U/gradient scroll speed, y = V scroll speed (textures only)
- int textureIndex;
- half2 animSpeed; // x = U/gradient scroll speed, y = V scroll speed (textures only)
+ float4 TransformationX() { return UnpackHalf4(transformationXBits); }
+ float4 TransformationY() { return UnpackHalf4(transformationYBits); }
+ uint4 ColorUVType() { return UnpackUint16x4(colorUVTypeBits); }
+ float2 AnimSpeed() { return UnpackHalf2(animSpeedBits); }
};
struct BoxStyle // aka 'StyleState'
{
- uint16_t4 borderWidth;
- uint16_t4 cornerRadius;
-
- int16_t4 borderColorIndex; // per-edge: x=top, y=right, z=bottom, w=left
- int16_t backgroundColorIndex;
- uint16_t borderDashSize; // pixels per dash (0 = solid)
- uint16_t borderDashOffset; // pixel start offset into dash pattern
- uint16_t shadowIndex; // CPU only
+ uint2 borderWidthBits; // uint16_t4
+ uint2 cornerRadiusBits; // uint16_t4
+ uint2 borderColorIndexBits; // int16_t4, per edge: x=top, y=right, z=bottom, w=left
+ uint backgroundAndDashSize; // int16_t backgroundColorIndex, uint16_t borderDashSize (pixels per dash, 0 = solid)
+ uint dashOffsetAndShadow; // uint16_t borderDashOffset (pixel start into the pattern), uint16_t shadowIndex (CPU only)
+
+ float4 BorderWidth() { return float4(UnpackUint16x4(borderWidthBits)); }
+ float4 CornerRadius() { return float4(UnpackUint16x4(cornerRadiusBits)); }
+ int4 BorderColorIndex() { return UnpackInt16x4(borderColorIndexBits); }
+ int BackgroundColorIndex() { return UnpackInt16x2(backgroundAndDashSize).x; }
+ float BorderDashSize() { return float(backgroundAndDashSize >> 16); }
+ float BorderDashOffset() { return float(dashOffsetAndShadow & 0xFFFFu); }
};
struct Box
@@ -37,10 +70,12 @@ struct Box
int2 size;
int textureIndex;
- int16_t colorIndex; // Per-element ColorStyle override (0 = use box style's background); supports gradients.
- int16_t _pad3;
- uint styles[4]; // up to four state styles mixed: GPU style index in the low 24 bits, share (of 255) in the top 8
- int16_t4 snappedPx; // window pixels {x0,y0,x1,y1} snapped to the parent; all 0 = snap here
+ uint colorIndexBits; // int16_t colorIndex, then padding: a ColorStyle override (0 = the box style's background); supports gradients
+ uint styles[4]; // up to four state styles mixed: GPU style index in the low 24 bits, share (of 255) in the top 8
+ uint2 snappedPxBits; // int16_t4: window pixels {x0,y0,x1,y1} snapped to the parent; all 0 = snap here
+
+ int ColorIndex() { return UnpackInt16x2(colorIndexBits).x; }
+ int4 SnappedPx() { return UnpackInt16x4(snappedPxBits); }
};
struct Glyph
@@ -57,11 +92,15 @@ struct Glyph
float2 uvMax;
float scale;
- uint16_t2 glyph_type;
+ uint glyphTypeBits; // uint16_t2 glyph_type
- int textureIndex; // Glyph atlas, not to be confused with ColorStyle texture index
- int16_t textColorIndex; // ColorStyle index for text color (1-based, 0 = invalid)
- int16_t shadowBlur; // -1: the glyph itself; 0 and up: a text shadow blurred by this many 1/8 pixels
+ int textureIndex; // Glyph atlas, not to be confused with ColorStyle texture index
+ uint colorAndBlurBits; // int16_t textColorIndex (1-based, 0 = invalid), int16_t shadowBlur
+ // (-1: the glyph itself; 0 and up: a text shadow blurred by this many 1/8 pixels)
+
+ uint2 GlyphType() { return UnpackUint16x2(glyphTypeBits); }
+ int TextColorIndex() { return UnpackInt16x2(colorAndBlurBits).x; }
+ int ShadowBlur() { return UnpackInt16x2(colorAndBlurBits).y; }
};
struct Dot
@@ -93,8 +132,13 @@ struct Line
float gradientOffset;
float gradientScale;
- int16_t2 p0, p1, p2, p3;
+ uint p0Bits, p1Bits, p2Bits, p3Bits; // int16_t2 each
int2 _padTo96; // std430 rounds the struct up to 16 bytes
+
+ float2 P0() { return float2(UnpackInt16x2(p0Bits)); }
+ float2 P1() { return float2(UnpackInt16x2(p1Bits)); }
+ float2 P2() { return float2(UnpackInt16x2(p2Bits)); }
+ float2 P3() { return float2(UnpackInt16x2(p3Bits)); }
};
struct Triangle
@@ -110,8 +154,10 @@ struct Triangle
int textureIndex;
- int16_t colorIndex;
- int16_t hardEdges; // bit 0: p0-p1, 1: p1-p2, 2: p2-p0, drawn without a soft edge
+ uint colorAndEdgesBits; // int16_t colorIndex, int16_t hardEdges (bit 0: p0-p1, 1: p1-p2, 2: p2-p0, drawn without a soft edge)
+
+ int ColorIndex() { return UnpackInt16x2(colorAndEdgesBits).x; }
+ int HardEdges() { return UnpackInt16x2(colorAndEdgesBits).y; }
};
struct Quad
@@ -125,12 +171,14 @@ struct Quad
int2 size;
int textureIndex;
- int16_t colorIndex;
- int16_t blur; // pixels; a shadow: the rect includes the blur on every side
+ uint colorAndBlurBits; // int16_t colorIndex, int16_t blur (pixels; a shadow: the rect includes the blur on every side)
float cornerRadius;
uint displayFlags; // ImageDisplay: 3 bits a channel's source (red first), bit 12 sRGB-encode, bit 31 on
float4 uvRect; // the texture's part a StretchedTexture stretches over the quad: min.xy, max.zw
float4 tint; // multiplies the color
+
+ int ColorIndex() { return UnpackInt16x2(colorAndBlurBits).x; }
+ int Blur() { return UnpackInt16x2(colorAndBlurBits).y; }
};
static const int kBoxSlot = 0;
diff --git a/workdirectory/shaders/box_shader.slang b/workdirectory/shaders/box_shader.slang
index 59c122df..cd5cadd0 100644
--- a/workdirectory/shaders/box_shader.slang
+++ b/workdirectory/shaders/box_shader.slang
@@ -35,7 +35,7 @@ VSOutput vertexMain(VertexInput vertex)
// The drawn box in whole pixels: snapped relative to its parent when the CPU
// supplies it (gui_pixel_snap.h), else each edge to the nearest pixel (half up).
// A non-empty box keeps at least one pixel.
- int4 parentSnapped = int4(box.snappedPx);
+ int4 parentSnapped = box.SnappedPx();
bool hasSnapped = parentSnapped.z > parentSnapped.x || parentSnapped.w > parentSnapped.y;
float2 snappedMin = hasSnapped ? float2(parentSnapped.xy) : floor(pos + 0.5);
float2 snappedMax = hasSnapped ? float2(parentSnapped.zw) : floor(pos + size + 0.5);
@@ -64,7 +64,7 @@ VSOutput vertexMain(VertexInput vertex)
output.blendFactors[i] = float(box.styles[i] >> 24) / 255.0;
}
output.textureIndex = box.textureIndex;
- output.colorIndex = int(box.colorIndex);
+ output.colorIndex = box.ColorIndex();
output.position = PrimitivePosition(position, box.transform0.w);
output.opacity = PrimitiveOpacity(box.transform1);
return output;
@@ -140,10 +140,10 @@ void AddPreStyle(inout CurrentStyle currentStyle, float weight, int styleIndex)
if (styleIndex < 0) return;
BoxStyle boxStyle = LoadBoxStyle(styleIndex);
- currentStyle.cornerRadius += weight * float4(boxStyle.cornerRadius);
- currentStyle.borderWidth += weight * float4(boxStyle.borderWidth);
- currentStyle.dashSize += weight * float(boxStyle.borderDashSize);
- currentStyle.dashOffset += weight * float(boxStyle.borderDashOffset);
+ currentStyle.cornerRadius += weight * boxStyle.CornerRadius();
+ currentStyle.borderWidth += weight * boxStyle.BorderWidth();
+ currentStyle.dashSize += weight * boxStyle.BorderDashSize();
+ currentStyle.dashOffset += weight * boxStyle.BorderDashOffset();
}
// A state's border and background colors at this fragment, straight (not premultiplied).
@@ -158,17 +158,18 @@ void StateColors(float2 uv, float2 sdfUv, float2 uvsize, float edgeDepth, int st
// Select border color based on which edge the fragment is closest to.
// Regions are divided by diagonals from the center (same convention as CSS):
// uv.y > 0 = top, uv.y < 0 = bottom, uv.x > 0 = right, uv.x < 0 = left.
- int16_t edgeColorIndex;
+ const int4 borderColorIndex = boxStyle.BorderColorIndex();
+ int edgeColorIndex;
float2 side = sdfUv / uvsize; // -1..1 from the center, y up
if (abs(side.y) >= abs(side.x))
- edgeColorIndex = (side.y >= 0.0) ? boxStyle.borderColorIndex.x // top
- : boxStyle.borderColorIndex.z; // bottom
+ edgeColorIndex = (side.y >= 0.0) ? borderColorIndex.x // top
+ : borderColorIndex.z; // bottom
else
- edgeColorIndex = (side.x > 0.0) ? boxStyle.borderColorIndex.y // right
- : boxStyle.borderColorIndex.w; // left
+ edgeColorIndex = (side.x > 0.0) ? borderColorIndex.y // right
+ : borderColorIndex.w; // left
- border = getSDFColor(int(edgeColorIndex), uv, uvsize, edgeDepth, textureIndex, boxSize, weights);
- background = getSDFColor(int(boxStyle.backgroundColorIndex), uv, uvsize, edgeDepth, textureIndex, boxSize, weights);
+ border = getSDFColor(edgeColorIndex, uv, uvsize, edgeDepth, textureIndex, boxSize, weights);
+ background = getSDFColor(boxStyle.BackgroundColorIndex(), uv, uvsize, edgeDepth, textureIndex, boxSize, weights);
}
// Depth is only tested here (occluders wrote it), so test it before shading.
diff --git a/workdirectory/shaders/glyph_shader.slang b/workdirectory/shaders/glyph_shader.slang
index d8aa5a15..eeccad21 100644
--- a/workdirectory/shaders/glyph_shader.slang
+++ b/workdirectory/shaders/glyph_shader.slang
@@ -54,10 +54,12 @@ VSOutput vertexMain(VertexInput vertex)
output.uv = uv;
output.textureIndex = max(0, glyph.textureIndex - 1);
output.scale = glyph.scale;
- output.bpp = glyph.glyph_type.x;
- output.mode = glyph.glyph_type.y;
- output.textColorIndex = int(glyph.textColorIndex);
- output.shadowBlur = glyph.shadowBlur < 0 ? -1.0 : float(glyph.shadowBlur) / 8.0;
+ const uint2 glyphType = glyph.GlyphType();
+ const int blur = glyph.ShadowBlur();
+ output.bpp = glyphType.x;
+ output.mode = glyphType.y;
+ output.textColorIndex = glyph.TextColorIndex();
+ output.shadowBlur = blur < 0 ? -1.0 : float(blur) / 8.0;
output.position = PrimitivePosition(position, glyph.transform0.w);
output.opacity = PrimitiveOpacity(glyph.transform1);
return output;
diff --git a/workdirectory/shaders/line_shader.slang b/workdirectory/shaders/line_shader.slang
index 4b1b12a0..08b590a6 100644
--- a/workdirectory/shaders/line_shader.slang
+++ b/workdirectory/shaders/line_shader.slang
@@ -36,10 +36,11 @@ VSOutput vertexMain(VertexInput vertex)
// Transform all four control points to screen space, then AABB.
// AABB-after-transform is the correct screen bounding box under any affine
// transform; transform-after-AABB would tilt for non-axis-aligned cases.
- float3 p0_t = ApplyTransform(line.transform0, line.transform1, float3(float2(line.p0), 1));
- float3 p1_t = ApplyTransform(line.transform0, line.transform1, float3(float2(line.p1), 1));
- float3 p2_t = ApplyTransform(line.transform0, line.transform1, float3(float2(line.p2), 1));
- float3 p3_t = ApplyTransform(line.transform0, line.transform1, float3(float2(line.p3), 1));
+ const float2 lp0 = line.P0(), lp1 = line.P1(), lp2 = line.P2(), lp3 = line.P3();
+ float3 p0_t = ApplyTransform(line.transform0, line.transform1, float3(lp0, 1));
+ float3 p1_t = ApplyTransform(line.transform0, line.transform1, float3(lp1, 1));
+ float3 p2_t = ApplyTransform(line.transform0, line.transform1, float3(lp2, 1));
+ float3 p3_t = ApplyTransform(line.transform0, line.transform1, float3(lp3, 1));
float2 p0s = p0_t.xy / p0_t.z;
float2 p1s = p1_t.xy / p1_t.z;
float2 p2s = p2_t.xy / p2_t.z;
@@ -52,8 +53,8 @@ VSOutput vertexMain(VertexInput vertex)
// Axis-aligned only when all four control points share the coordinate (2-point
// lines arrive as p0,p0,p1,p1); symmetric curves can match on endpoints and
// midpoints alone and must not be flattened.
- bool axisX = (line.p0.y == line.p1.y) && (line.p1.y == line.p2.y) && (line.p2.y == line.p3.y);
- bool axisY = (line.p0.x == line.p1.x) && (line.p1.x == line.p2.x) && (line.p2.x == line.p3.x);
+ bool axisX = (lp0.y == lp1.y) && (lp1.y == lp2.y) && (lp2.y == lp3.y);
+ bool axisY = (lp0.x == lp1.x) && (lp1.x == lp2.x) && (lp2.x == lp3.x);
if (axisX || axisY)
{
float effW = max(line.lineWidth * scale, 1.0);
diff --git a/workdirectory/shaders/quad_shader.slang b/workdirectory/shaders/quad_shader.slang
index 1672cad7..799e6dee 100644
--- a/workdirectory/shaders/quad_shader.slang
+++ b/workdirectory/shaders/quad_shader.slang
@@ -105,12 +105,12 @@ float4 fragmentMain(VSOutput input) : SV_Target
// drop shadow fade from the edge instead of sampling one fixed point.
float cornerRadius = input.cornerRadius * input.transformScale * pixelrange;
// A shadow's quad extends its shape by the blur on every side.
- float blurPx = float(quad.blur) * input.transformScale;
+ float blurPx = float(quad.Blur()) * input.transformScale;
float2 shape = max(uvsize - float2(blurPx * pixelrange), float2(0.0));
float dist = sdf_roundedBox(uv, shape, min(cornerRadius, min(shape.x, shape.y)));
// In units of the quad's smaller side: its middle is half a unit deep.
- float4 color = getSDFColor(int(quad.colorIndex), uv, uvsize, saturate(-dist * 2.0),
+ float4 color = getSDFColor(quad.ColorIndex(), uv, uvsize, saturate(-dist * 2.0),
input.textureIndex, input.boxSize, weights, quad.uvRect);
color = applyImageDisplay(color, quad.displayFlags) * quad.tint;
diff --git a/workdirectory/shaders/sdf_color.slang b/workdirectory/shaders/sdf_color.slang
index ae414551..8f10811a 100644
--- a/workdirectory/shaders/sdf_color.slang
+++ b/workdirectory/shaders/sdf_color.slang
@@ -197,14 +197,15 @@ float4 getSDFColor(int colorStyleIndex, float2 pos, float2 size, float edgeDepth
textureIndex = textureIndex >= 1 ? max(0, textureIndex - 1) : max(0, colorStyle.textureIndex - 1);
// Its UV transform's rows: transformationX.xyz, transformationY.xyz, (0, 0, 1).
- const float4 uvRow0 = float4(colorStyle.transformationX);
- const float4 uvRow1 = float4(colorStyle.transformationY);
- uint2 colorPixelPos = uint2(colorStyle.colorUV_type.xy);
- uint colorType = colorStyle.colorUV_type.z; // type
+ const float4 uvRow0 = colorStyle.TransformationX();
+ const float4 uvRow1 = colorStyle.TransformationY();
+ const uint4 colorUV_type = colorStyle.ColorUVType();
+ uint2 colorPixelPos = colorUV_type.xy;
+ uint colorType = colorUV_type.z; // type
// colorUV_type.w holds the 0-based physical bindless slot of the gradient-atlas
// page; every atlas fetch for this style uses it.
- uint gradientPageIdx = colorStyle.colorUV_type.w;
+ uint gradientPageIdx = colorUV_type.w;
// The one image the type reads, and its size: the texture for the texture types, the gradient
// page for the rest. Each type works out where to read it, then it's read in one place: on SDL
@@ -213,7 +214,7 @@ float4 getSDFColor(int colorStyleIndex, float2 pos, float2 size, float edgeDepth
const float2 imageSize = ImageSize(imageIndex);
float2 colorPos = float2(colorPixelPos) / imageSize;
- float2 animOffset = float2(colorStyle.animSpeed) * pc.elapsedTime;
+ float2 animOffset = colorStyle.AnimSpeed() * pc.elapsedTime;
if (colorType == 7 || colorType == 8) // InterpolatedTriangle, InterpolatedBox
{
diff --git a/workdirectory/shaders/triangle_shader.slang b/workdirectory/shaders/triangle_shader.slang
index d801298f..ec419090 100644
--- a/workdirectory/shaders/triangle_shader.slang
+++ b/workdirectory/shaders/triangle_shader.slang
@@ -92,7 +92,7 @@ float4 fragmentMain(VSOutput input) : SV_Target
// A hard edge (shared with a neighbour) cuts straight; only the others are soft.
// (A pixel's middle right on it is kept on both sides, despite rounding.)
- int hard = int(triangle.hardEdges);
+ int hard = triangle.HardEdges();
const float onEdge = -1e-4;
if (((hard & 1) != 0 && w0 < onEdge) || ((hard & 2) != 0 && w1 < onEdge) || ((hard & 4) != 0 && w2 < onEdge))
discard;
@@ -121,7 +121,7 @@ float4 fragmentMain(VSOutput input) : SV_Target
float perimeter = length(p1 - p0) + length(p2 - p1) + length(p0 - p2);
float inradius = abs(area) / max(perimeter, 0.0001);
float depth = saturate(-signedDistance / max(inradius, 0.0001));
- float4 color = getSDFColor(int(triangle.colorIndex), localPos, triHalfSize, depth, input.textureIndex, boxSize, weights);
+ float4 color = getSDFColor(triangle.ColorIndex(), localPos, triHalfSize, depth, input.textureIndex, boxSize, weights);
color.a *= opacity;
if (color.a <= (1.0 / 512.0))