From 76179a192c34def0209a8826a10be6472f0be4f5 Mon Sep 17 00:00:00 2001 From: Sander van Rossen Date: Thu, 26 Nov 2026 15:09:26 +0100 Subject: [PATCH] Read a color style's image once in the shaders, so SDL GPU's first frame no longer stalls (#301) SDL GPU can't index its images, so each image read in a shader is a case for every image a draw binds. getSDFColor read its image in each color type's branch: 17 reads, each 16 cases, up to three times a shader. lavapipe compiles that the first time it draws, and on Windows a first frame took about 16 s. getSDFColor now works out the image and where to read it for each type, then reads it in one place: one size query, one sample, and one row of four texels for the interpolated triangle and box. The drawing is the same on every backend, byte for byte. - The Direct3D 12 and SDL GPU tests draw every color type and compare it with Vulkan's drawing. - CI runs the whole-app tests on SDL GPU over lavapipe on Windows again. --- .github/workflows/ci.yml | 7 + CHANGELOG.md | 1 + tests/gpu/d3d12_draw_test.cpp | 5 + tests/gpu/gpu_draw_app.h | 184 ++++++++++++++++++++++---- tests/gpu/sdlgpu_draw_test.cpp | 7 + workdirectory/shaders/sdf_color.slang | 97 +++++++------- 6 files changed, 228 insertions(+), 73 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0edbdd..d062cb2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,6 +163,13 @@ jobs: New-Item -Path HKLM:\SOFTWARE\Khronos\Vulkan\Drivers -Force | Out-Null New-ItemProperty -Path HKLM:\SOFTWARE\Khronos\Vulkan\Drivers -Name $icd -Value 0 -PropertyType DWord -Force | Out-Null + # The whole-app GPU tests on SDL GPU, through SDL's Vulkan driver on lavapipe. + - name: Whole-app GPU tests on SDL GPU (Debug, lavapipe) + timeout-minutes: 15 + env: + SDL_GPU_DRIVER: vulkan + run: bin/Debug/gui_gpu_tests.exe --graphics=sdlgpu + - name: Package consumer renders a frame timeout-minutes: 10 env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 262aab5..a0032d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -304,3 +304,4 @@ First public preview. The API is not stable yet. - Trees: which rows are open belongs to each view. `TreeViewRow::isOpen` is gone; a view's `TableState::openRows` holds the rows it has open, by `TreeViewRowKey` (the row's `id`, or its position without one), so two views of one tree open and close on their own. `TreeCell` takes a `TreeOpenRef`: a bool of the caller's, or a view's open rows (`GUIApplication::TreeViewOpenRef`); the `bool*` overload stays. `WalkTreeViewVisibility` without a state takes the open rows. `TreeUtils::ReorderTreeRow` opens the target only for rows with an `isOpen` of their own. The showcase's Hierarchy and Files panels keep their open folders in their tree's state. - 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. +- 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/tests/gpu/d3d12_draw_test.cpp b/tests/gpu/d3d12_draw_test.cpp index c8b9c0a..52300a8 100644 --- a/tests/gpu/d3d12_draw_test.cpp +++ b/tests/gpu/d3d12_draw_test.cpp @@ -28,6 +28,11 @@ TEST(D3D12Draw, TheUIDrawsAsOnVulkanWithNothingFromTheDebugLayer) ExpectDrawnAsOnVulkan(drawn); } +TEST(D3D12Draw, EveryColorTypeDrawsAsOnVulkan) +{ + ExpectColorTypesAsOnVulkan(GraphicsAPI::D3D12); +} + TEST(D3D12Draw, ARedrawThatClosesItsWindowStopsThere) { ExpectARedrawThatClosesItsWindowStopsThere(GraphicsAPI::D3D12); diff --git a/tests/gpu/gpu_draw_app.h b/tests/gpu/gpu_draw_app.h index c408e66..4bb9910 100644 --- a/tests/gpu/gpu_draw_app.h +++ b/tests/gpu/gpu_draw_app.h @@ -1,12 +1,13 @@ #pragma once -// A window with a button, a label and a cached scope, drawn by a graphics backend and compared -// with Vulkan's drawing of it: for the tests of the other backends. +// Windows drawn by a graphics backend and compared with Vulkan's drawing of them, for the tests of +// the other backends: one with a button, a label and a cached scope, and one with every color type. #include #include +#include #include #include #include @@ -79,6 +80,107 @@ namespace GpuDrawApp } }; + // A window with a shape for each color type the shaders resolve: the gradients, read from the + // gradient atlas, the interpolated box and triangle, and an image stretched and repeated. + class ColorTypesApp : public GUIApplicationInternals + { + public: + ID windowID = ID::Invalid(), areaID = ID::Invalid(); + int frame = 0; + static constexpr int kFrames = 3; + + void OnGUI() override + { + if (BeginWindow(windowID, "Colors", theme.windowStyleRef, LayoutOverride{}.Size(360, 160))) + { + BeginArea(areaID, LayoutOverride::FixedSize(tachyon::Pixels{ 352 }, tachyon::Pixels{ 96 })); + (void)elementStorage.AddCustomDrawAfter(elementStorage.FindElementRefByID(areaID), + [this](CustomDrawContext& c) { Draw(c); }); + EndArea(); + } + EndWindow(); + if (++frame >= kFrames) + applicationQuit = true; + } + + // False when no window system or no GPU runs `api` (the app fell back to another). + bool Start(GraphicsAPI api, std::unique_ptr backend = {}) + { + InitializeOptions options; + options.graphicsAPI = api; + if (backend) + SetGraphicsBackend(std::move(backend)); + if (!Initialize(options) || graphicsContext->GetAPI() != api) + return false; + windowID = idManager.CreateStaticID(); + areaID = idManager.CreateStaticID(); + + const color4b red{ 255, 0, 0, 255 }, green{ 0, 255, 0, 255 }, blue{ 0, 0, 255, 255 }, white{ 255, 255, 255, 255 }; + for (const ColorType type : { ColorType::LinearGradient, ColorType::CircularAngularGradient, + ColorType::EllipsoidAngularGradient, ColorType::RadialGradient, ColorType::SDFGradient }) + m_quads.push_back(styleManager.RegisterColorStyle(ColorStyle::Create(red, blue, type))); + m_quads.push_back(styleManager.RegisterColorStyle(ColorStyle::Create(green))); + m_quads.push_back(styleManager.RegisterColorStyle(ColorStyle::Create(red, green, blue, white, ColorType::InterpolatedBox))); + m_triangle = styleManager.RegisterColorStyle(ColorStyle::Create(red, green, blue, ColorType::InterpolatedTriangle)); + m_stretched = styleManager.RegisterColorStyle(ColorStyle::Create(white, white, ColorType::StretchedTexture)); + m_repeated = styleManager.RegisterColorStyle(ColorStyle::Create(white, white, ColorType::RepeatedTexture)); + + // A 4x4 image, its texels each a different color (RGBA). + uint32_t pixels[16]; + for (uint32_t i = 0; i < 16; ++i) + pixels[i] = 0xff000000u | (i * 16u) | ((255u - i * 16u) << 8) | ((i & 3u) * 80u << 16); + m_created = graphicsContext->CreateImage(pixels, uint2{ 4, 4 }, ImageFormat::R8G8B8A8, Sampler::NearestRepeat); + m_image = m_created != nullptr ? graphicsContext->RegisterImage(m_created) : ImageIndex::Invalid; + if (m_image == ImageIndex::Invalid) + return false; + transitionManager.SetEnabled(false); + SetRedrawMode(RedrawMode::Always); + return true; + } + + void Release() + { + if (m_created != nullptr && graphicsContext != nullptr) + graphicsContext->DestroyImageAtEnd(m_created, DeviceScope::Application); + m_created = nullptr; + Cleanup(); + } + + // The window's last frame, BGRA; empty when it can't be read. + std::vector Pixels(IntRect& rect) + { + rect = windowManager->GetWindowRect(windowID); + std::vector pixels(size_t(std::max(rect.w, 0)) * std::max(rect.h, 0) * 4); + if (pixels.empty() || !ReadWindowPixels(windowID, pixels)) + pixels.clear(); + return pixels; + } + + private: + std::vector m_quads; + VisualColorStyleIndex m_triangle{}, m_stretched{}, m_repeated{}; + tachyon::Image* m_created = nullptr; // qualified: Image is also the app's control + ImageIndex m_image = ImageIndex::Invalid; + + // Rows of seven 40-pixel cells, 4 pixels apart. + void Draw(CustomDrawContext& c) const + { + int cell = 0; + auto next = [&cell] { + const IntRect r{ .position = { 4 + (cell % 7) * 44, 4 + (cell / 7) * 44 }, .size = { 40, 40 } }; + ++cell; + return r; + }; + for (const VisualColorStyleIndex style : m_quads) + c.RenderQuad(next(), style); + const IntRect t = next(); + c.RenderTriangle(float2{ float(t.x), float(t.y + t.h) }, float2{ float(t.x + t.w), float(t.y + t.h) }, + float2{ float(t.x) + float(t.w) * 0.5f, float(t.y) }, m_triangle); + c.RenderQuad(next(), m_stretched, 0.0f, m_image); + c.RenderQuad(next(), m_repeated, 0.0f, m_image); + } + }; + // A window and a transparent one beside it, like a drag preview, which its OnGUI stops // declaring once `closePreview` is set. class PreviewApp : public GUIApplicationInternals @@ -179,38 +281,25 @@ namespace GpuDrawApp return drawn; } - // What was drawn looks as it should, and as it does on Vulkan where Vulkan runs (else on the - // native Metal backend): the same pixels, but for rounding. Call once the app that drew it is - // cleaned up. - inline void ExpectDrawnAsOnVulkan(const Drawn& drawn) + // `pixels`, a frame `rect` in size, as an App (DrawApp, ColorTypesApp) draws them on Vulkan + // where Vulkan runs, else on the native Metal backend: the same, but for rounding. Call once + // the app that drew them is cleaned up. + template + void ExpectSameAsOnVulkan(const std::vector& pixels, IntRect rect) { - const std::vector& pixels = drawn.pixels; - ASSERT_FALSE(pixels.empty()); - const IntRect rect = drawn.rect, window = drawn.window, button = drawn.button, label = drawn.label; - - // The window's background is drawn, the button stands out from it, and the label has glyphs. - const Rgb background = At(pixels, rect.w, window, window.x + window.w - 4, window.y + window.h - 4); - EXPECT_GT(background.Sum(), 0) << "the window's background is drawn"; - const Rgb buttonFill = At(pixels, rect.w, window, button.x + 4, button.y + button.h / 2); - EXPECT_GT(std::abs(buttonFill.Sum() - background.Sum()), 9) << "the button stands out"; - int glyphPixels = 0; - for (int y = label.y; y < label.y + label.h; ++y) - for (int x = label.x; x < label.x + label.w; ++x) - glyphPixels += std::abs(At(pixels, rect.w, window, x, y).Sum() - background.Sum()) > 60; - EXPECT_GT(glyphPixels, 50) << "the label's glyphs are drawn"; - - // The same app on Vulkan, where it runs: the same pixels, but for rounding. Without - // Vulkan (macOS), on the native Metal backend instead. IntRect vulkanRect{}; std::vector expected; for (const GraphicsAPI reference : { GraphicsAPI::Vulkan, GraphicsAPI::Metal }) { if (reference == GraphicsAPI::Metal && !TACHYON_METAL) continue; - DrawApp app; + App app; if (app.Start(reference) && app.Run()) expected = app.Pixels(vulkanRect); - app.Cleanup(); + if constexpr (requires { app.Release(); }) + app.Release(); + else + app.Cleanup(); if (!expected.empty()) break; } @@ -232,4 +321,49 @@ namespace GpuDrawApp } EXPECT_EQ(differing, 0u) << "pixels that differ from Vulkan's, of " << pixels.size() / 4; } + + // What was drawn looks as it should, and as it does on Vulkan where Vulkan runs (else on the + // native Metal backend): the same pixels, but for rounding. Call once the app that drew it is + // cleaned up. + inline void ExpectDrawnAsOnVulkan(const Drawn& drawn) + { + const std::vector& pixels = drawn.pixels; + ASSERT_FALSE(pixels.empty()); + const IntRect rect = drawn.rect, window = drawn.window, button = drawn.button, label = drawn.label; + + // The window's background is drawn, the button stands out from it, and the label has glyphs. + const Rgb background = At(pixels, rect.w, window, window.x + window.w - 4, window.y + window.h - 4); + EXPECT_GT(background.Sum(), 0) << "the window's background is drawn"; + const Rgb buttonFill = At(pixels, rect.w, window, button.x + 4, button.y + button.h / 2); + EXPECT_GT(std::abs(buttonFill.Sum() - background.Sum()), 9) << "the button stands out"; + int glyphPixels = 0; + for (int y = label.y; y < label.y + label.h; ++y) + for (int x = label.x; x < label.x + label.w; ++x) + glyphPixels += std::abs(At(pixels, rect.w, window, x, y).Sum() - background.Sum()) > 60; + EXPECT_GT(glyphPixels, 50) << "the label's glyphs are drawn"; + ExpectSameAsOnVulkan(pixels, rect); + } + + // Every color type draws on the backend `api` as it does on Vulkan. + inline void ExpectColorTypesAsOnVulkan(GraphicsAPI api, std::unique_ptr backend = {}) + { + ColorTypesApp app; + if (!app.Start(api, std::move(backend))) + { + app.Release(); + GTEST_SKIP() << "no window system, or no GPU runs this backend"; + } + ASSERT_TRUE(app.Run()); + IntRect rect{}; + const std::vector pixels = app.Pixels(rect); + app.Release(); + ASSERT_FALSE(pixels.empty()); + + // The shapes are drawn: their colors are strong, the window's background gray. + size_t colored = 0; + for (size_t i = 0; i < pixels.size(); i += 4) + colored += std::max({ pixels[i], pixels[i + 1], pixels[i + 2] }) - std::min({ pixels[i], pixels[i + 1], pixels[i + 2] }) > 100; + EXPECT_GT(colored, 8000u) << "pixels in a strong color"; + ExpectSameAsOnVulkan(pixels, rect); + } } diff --git a/tests/gpu/sdlgpu_draw_test.cpp b/tests/gpu/sdlgpu_draw_test.cpp index c6b2073..bcd504a 100644 --- a/tests/gpu/sdlgpu_draw_test.cpp +++ b/tests/gpu/sdlgpu_draw_test.cpp @@ -34,6 +34,13 @@ TEST_P(SDLGPUDraw, TheUIDrawsAsOnVulkanWithNothingFromDebugMode) ExpectDrawnAsOnVulkan(drawn); } +TEST_P(SDLGPUDraw, EveryColorTypeDrawsAsOnVulkan) +{ + auto backend = std::make_unique(); + backend->SetDriver(GetParam()); + ExpectColorTypesAsOnVulkan(GraphicsAPI::SDLGPU, std::move(backend)); +} + TEST_P(SDLGPUDraw, ARedrawThatClosesItsWindowStopsThere) { auto backend = std::make_unique(); diff --git a/workdirectory/shaders/sdf_color.slang b/workdirectory/shaders/sdf_color.slang index 6d614ca..ae41455 100644 --- a/workdirectory/shaders/sdf_color.slang +++ b/workdirectory/shaders/sdf_color.slang @@ -136,10 +136,18 @@ float2 SizeOf(SDLImage image) return float2(width, height); } +// Four texels in a row, from `texel` right, the last no further right than `lastX`. +float4x4 LoadRow(SDLImage image, int2 texel, int lastX) +{ + return float4x4(image.Load(int3(texel, 0)), image.Load(int3(texel.x + 1, texel.y, 0)), + image.Load(int3(texel.x + 2, texel.y, 0)), image.Load(int3(min(texel.x + 3, lastX), texel.y, 0))); +} + float2 ImageSize(uint index) { SDL_ON_IMAGE(BoundImage(index), SizeOf(image), float2(1, 1)) } // The base level, as on the other APIs. float4 SampleImage(uint index, float2 uv) { SDL_ON_IMAGE(BoundImage(index), image.SampleLevel(uv, 0), float4(0, 0, 0, 0)) } float4 FetchImage(uint index, int2 texel) { SDL_ON_IMAGE(BoundImage(index), image.Load(int3(texel, 0)), float4(0, 0, 0, 0)) } +float4x4 FetchImageRow(uint index, int2 texel, int lastX) { SDL_ON_IMAGE(BoundImage(index), LoadRow(image, texel, lastX), float4x4(0)) } #else // Every registered image, by its ImageIndex (set 0, binding 0), with its own sampler. [[vk::binding(0, 0)]] Sampler2D allTextures[]; @@ -155,11 +163,15 @@ float4 SampleImage(uint index, float2 uv) { return allTextures[NonUniformResourc float4 FetchImage(uint index, int2 texel) { return allTextures[NonUniformResourceIndex(index)].Load(int3(texel, 0)); } #endif -float4 getGradientColor(uint gradientPageIdx, float2 texSize, float offset, float gradientIndex) +#if !defined(TACHYON_SDLGPU) +// Four texels in a row, from `texel` right, the last no further right than `lastX`. SDL GPU has +// its own, one case for each bound image rather than four. +float4x4 FetchImageRow(uint index, int2 texel, int lastX) { - offset = clamp(offset * texSize.x, 0, texSize.x - 1) / texSize.x; - return SampleImage(gradientPageIdx, float2(offset, gradientIndex)); + return float4x4(FetchImage(index, texel), FetchImage(index, int2(texel.x + 1, texel.y)), + FetchImage(index, int2(texel.x + 2, texel.y)), FetchImage(index, int2(min(texel.x + 3, lastX), texel.y))); } +#endif float cross2(float2 a, float2 b) { @@ -194,25 +206,38 @@ float4 getSDFColor(int colorStyleIndex, float2 pos, float2 size, float edgeDepth // page; every atlas fetch for this style uses it. uint gradientPageIdx = colorStyle.colorUV_type.w; - float2 defaultTextureSize = ImageSize(gradientPageIdx); - float2 colorPos = float2(colorPixelPos) / defaultTextureSize; - - float4 color; + // 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 + // GPU every image read is a case for each bound image, so there are as few as there can be. + const uint imageIndex = (colorType == 1 || colorType == 2) ? textureIndex : gradientPageIdx; + const float2 imageSize = ImageSize(imageIndex); + float2 colorPos = float2(colorPixelPos) / imageSize; float2 animOffset = float2(colorStyle.animSpeed) * pc.elapsedTime; + if (colorType == 7 || colorType == 8) // InterpolatedTriangle, InterpolatedBox + { + // The corners' colors side by side: a triangle's three, a box's four (top-left, + // top-right, bottom-left, bottom-right). + const float4x4 c = FetchImageRow(gradientPageIdx, int2(colorPixelPos), int(imageSize.x) - 1); + float4 color = (c[0] * weights.x) + + (c[1] * weights.y) + + (c[2] * weights.z); + if (colorType == 8) + color += c[3] * weights.w; + return color; + } + + float2 uv; if (colorType == 1) // StretchedTexture { - float2 normalizedUV = lerp(uvRect.xy, uvRect.zw, frac((pos / (size * 2)) + 0.5 + animOffset)); - color = SampleImage(textureIndex, normalizedUV.xy); + uv = lerp(uvRect.xy, uvRect.zw, frac((pos / (size * 2)) + 0.5 + animOffset)); } else if (colorType == 2) // RepeatedTexture { - float2 displayTextureSize = ImageSize(textureIndex); - float2 uv = ((pos / size) + 1.0) * 0.5 * boxSize; - float2 repeatedUV = (uv / displayTextureSize) + animOffset; - color = SampleImage(textureIndex, repeatedUV.xy); + float2 boxUV = ((pos / size) + 1.0) * 0.5 * boxSize; + uv = (boxUV / imageSize) + animOffset; } else if (colorType == 3) // LinearGradient @@ -221,18 +246,18 @@ float4 getSDFColor(int colorStyleIndex, float2 pos, float2 size, float edgeDepth float2 normalizedUV = (pos / (size * 2)) + 0.5; float3 transformedUV = ApplyTransform(uvRow0, uvRow1, float3(normalizedUV, 1)); normalizedUV = transformedUV.xy / transformedUV.z; - float gradient = min(abs(dot(gradient_vector, normalizedUV)), 1 - (1.0 / defaultTextureSize.x)); + float gradient = min(abs(dot(gradient_vector, normalizedUV)), 1 - (1.0 / imageSize.x)); float animGradient = clamp(frac(gradient + animOffset.x), 0, 1); - color = SampleImage(gradientPageIdx, float2(animGradient, colorPos.y)); + uv = float2(animGradient, colorPos.y); } else if (colorType == 4) // CircularAngularGradient { float3 transformedUV = ApplyTransform(uvRow0, uvRow1, float3(pos, 1)); pos = transformedUV.xy / transformedUV.z; - float gradient = min(length(pos), 1 - (1.0 / defaultTextureSize.x)); + float gradient = min(length(pos), 1 - (1.0 / imageSize.x)); float animGradient = frac(gradient + animOffset.x); - color = SampleImage(gradientPageIdx, float2(animGradient, colorPos.y)); + uv = float2(animGradient, colorPos.y); } else if (colorType == 5) // EllipsoidAngularGradient @@ -240,9 +265,9 @@ float4 getSDFColor(int colorStyleIndex, float2 pos, float2 size, float edgeDepth float2 normalizedUV = pos / size; float3 transformedUV = ApplyTransform(uvRow0, uvRow1, float3(normalizedUV, 1)); normalizedUV = transformedUV.xy / transformedUV.z; - float gradient = min(length(normalizedUV), 1 - (1.0 / defaultTextureSize.x)); + float gradient = min(length(normalizedUV), 1 - (1.0 / imageSize.x)); float animGradient = frac(gradient + animOffset.x); - color = SampleImage(gradientPageIdx, float2(animGradient, colorPos.y)); + uv = float2(animGradient, colorPos.y); } else if (colorType == 6) // RadialGradient @@ -256,44 +281,20 @@ float4 getSDFColor(int colorStyleIndex, float2 pos, float2 size, float edgeDepth float side = (from.x * to.y) - (from.y * to.x); float signed_angle = glslMod((((side < 0) ? -1 : 1) * angle) + 1, 1); - float gradient = min(abs(signed_angle), 1 - (1.0 / defaultTextureSize.x)); + float gradient = min(abs(signed_angle), 1 - (1.0 / imageSize.x)); float animGradient = frac(gradient + animOffset.x); - color = SampleImage(gradientPageIdx, float2(animGradient, colorPos.y)); - } - - else if (colorType == 7) // InterpolatedTriangle - { - float4 c0 = FetchImage(gradientPageIdx, int2(colorPixelPos.x + 0, colorPixelPos.y)); - float4 c1 = FetchImage(gradientPageIdx, int2(colorPixelPos.x + 1, colorPixelPos.y)); - float4 c2 = FetchImage(gradientPageIdx, int2(colorPixelPos.x + 2, colorPixelPos.y)); - - color = (c0 * weights.x) + - (c1 * weights.y) + - (c2 * weights.z); - } - - else if (colorType == 8) // InterpolatedBox - { - float4 c00 = FetchImage(gradientPageIdx, int2(colorPixelPos.x + 0, colorPixelPos.y)); // top-left - float4 c01 = FetchImage(gradientPageIdx, int2(colorPixelPos.x + 1, colorPixelPos.y)); // top-right - float4 c11 = FetchImage(gradientPageIdx, int2(colorPixelPos.x + 2, colorPixelPos.y)); // bottom-left - float4 c10 = FetchImage(gradientPageIdx, int2(colorPixelPos.x + 3, colorPixelPos.y)); // bottom-right - - color = (c00 * weights.x) + - (c01 * weights.y) + - (c11 * weights.z) + - (c10 * weights.w); + uv = float2(animGradient, colorPos.y); } else if (colorType == 9) // SDFGradient: the ramp by edge depth, mapped by the first row { float t = ApplyTransform(uvRow0, uvRow1, float3(edgeDepth, 0, 1)).x; - color = getGradientColor(gradientPageIdx, defaultTextureSize, t, colorPos.y); + uv = float2(clamp(t * imageSize.x, 0, imageSize.x - 1) / imageSize.x, colorPos.y); } else // SolidColor (default) { - color = SampleImage(gradientPageIdx, colorPos); + uv = colorPos; } - return color; + return SampleImage(imageIndex, uv); }