New rules based order
All checks were successful
CI / React UI Build (push) Successful in 11s
CI / Native Windows Build And Tests (push) Successful in 2m53s
CI / Windows Release Package (push) Successful in 3m18s

This commit is contained in:
Aiden
2026-05-12 02:35:15 +10:00
parent c0d7e84495
commit 511b67c9bc
18 changed files with 772 additions and 150 deletions

View File

@@ -1,6 +1,7 @@
#include "RuntimeSlangShaderCompiler.h"
#include "ShaderCompiler.h"
#include "ShaderPackageRegistry.h"
#include "ShaderTypes.h"
#include <chrono>
@@ -9,16 +10,6 @@
namespace
{
ShaderParameterDefinition FloatParam(const std::string& id, double defaultValue)
{
ShaderParameterDefinition parameter;
parameter.id = id;
parameter.label = id;
parameter.type = ShaderParameterType::Float;
parameter.defaultNumbers.push_back(defaultValue);
return parameter;
}
std::filesystem::path FindRepoRoot()
{
std::filesystem::path current = std::filesystem::current_path();
@@ -36,6 +27,44 @@ std::filesystem::path FindRepoRoot()
current = parent;
}
}
bool IsStatelessSinglePassPackage(const ShaderPackage& shaderPackage, std::string& error)
{
if (shaderPackage.passes.size() != 1)
{
error = "RenderCadenceCompositor currently supports only single-pass runtime shaders.";
return false;
}
if (shaderPackage.temporal.enabled)
{
error = "RenderCadenceCompositor currently supports only stateless shaders; temporal history is not enabled in this app.";
return false;
}
if (shaderPackage.feedback.enabled)
{
error = "RenderCadenceCompositor currently supports only stateless shaders; feedback storage is not enabled in this app.";
return false;
}
if (!shaderPackage.textureAssets.empty())
{
error = "RenderCadenceCompositor does not load shader texture assets on the render thread; texture-backed shaders need a CPU-prepared asset handoff first.";
return false;
}
if (!shaderPackage.fontAssets.empty())
{
error = "RenderCadenceCompositor does not load shader font assets on the render thread; text shaders need a CPU-prepared asset handoff first.";
return false;
}
for (const ShaderParameterDefinition& parameter : shaderPackage.parameters)
{
if (parameter.type == ShaderParameterType::Text)
{
error = "RenderCadenceCompositor currently skips text parameters because they require per-shader text texture storage.";
return false;
}
}
return true;
}
}
RuntimeSlangShaderCompiler::~RuntimeSlangShaderCompiler()
@@ -44,6 +73,11 @@ RuntimeSlangShaderCompiler::~RuntimeSlangShaderCompiler()
}
void RuntimeSlangShaderCompiler::StartHappyAccidentBuild()
{
StartShaderBuild("happy-accident");
}
void RuntimeSlangShaderCompiler::StartShaderBuild(const std::string& shaderId)
{
if (mRunning.load(std::memory_order_acquire))
return;
@@ -57,8 +91,8 @@ void RuntimeSlangShaderCompiler::StartHappyAccidentBuild()
}
mRunning.store(true, std::memory_order_release);
mThread = std::thread([this]() {
RuntimeSlangShaderBuild build = BuildHappyAccident();
mThread = std::thread([this, shaderId]() {
RuntimeSlangShaderBuild build = BuildShader(shaderId);
{
std::lock_guard<std::mutex> lock(mMutex);
mReadyBuild = std::move(build);
@@ -86,57 +120,57 @@ bool RuntimeSlangShaderCompiler::TryConsume(RuntimeSlangShaderBuild& build)
return true;
}
RuntimeSlangShaderBuild RuntimeSlangShaderCompiler::BuildHappyAccident() const
RuntimeSlangShaderBuild RuntimeSlangShaderCompiler::BuildShader(const std::string& shaderId) const
{
RuntimeSlangShaderBuild build;
build.artifact.shaderId = "happy-accident";
build.artifact.shaderId = shaderId;
try
{
const std::filesystem::path repoRoot = FindRepoRoot();
const std::filesystem::path shaderDir = repoRoot / "shaders" / "happy-accident";
const std::filesystem::path shaderDir = repoRoot / "shaders" / shaderId;
const std::filesystem::path runtimeBuildDir = repoRoot / "runtime" / "generated" / "render-cadence-compositor";
ShaderPackageRegistry registry(0);
ShaderPackage shaderPackage;
shaderPackage.id = "happy-accident";
shaderPackage.displayName = "Happy Accident";
shaderPackage.entryPoint = "shadeVideo";
shaderPackage.directoryPath = shaderDir;
shaderPackage.shaderPath = shaderDir / "shader.slang";
shaderPackage.manifestPath = shaderDir / "shader.json";
shaderPackage.parameters.push_back(FloatParam("speed", 1.0));
shaderPackage.parameters.push_back(FloatParam("scale", 1.0));
shaderPackage.parameters.push_back(FloatParam("raySteps", 77.0));
shaderPackage.parameters.push_back(FloatParam("intensity", 1.0));
shaderPackage.parameters.push_back(FloatParam("sourceMix", 0.0));
std::string error;
if (!registry.ParseManifest(shaderDir / "shader.json", shaderPackage, error))
{
build.succeeded = false;
build.message = error.empty() ? "Shader manifest parse failed." : error;
return build;
}
if (!IsStatelessSinglePassPackage(shaderPackage, error))
{
build.succeeded = false;
build.message = error;
return build;
}
ShaderPassDefinition pass;
pass.id = "main";
pass.entryPoint = shaderPackage.entryPoint;
pass.sourcePath = shaderPackage.shaderPath;
pass.outputName = "output";
shaderPackage.passes.push_back(pass);
const ShaderPassDefinition& pass = shaderPackage.passes.front();
ShaderCompiler compiler(
repoRoot,
runtimeBuildDir / "happy_accident_wrapper.slang",
runtimeBuildDir / "happy_accident.generated.glsl",
runtimeBuildDir / "happy_accident.patched.glsl",
runtimeBuildDir / (shaderId + ".wrapper.slang"),
runtimeBuildDir / (shaderId + ".generated.glsl"),
runtimeBuildDir / (shaderId + ".patched.glsl"),
0);
std::string error;
const auto start = std::chrono::steady_clock::now();
if (!compiler.BuildPassFragmentShaderSource(shaderPackage, pass, build.artifact.fragmentShaderSource, error))
{
build.succeeded = false;
build.message = error.empty() ? "Happy Accident Slang compile failed." : error;
build.message = error.empty() ? "Slang compile failed." : error;
return build;
}
const auto end = std::chrono::steady_clock::now();
const double milliseconds = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(end - start).count();
build.succeeded = true;
build.artifact.message = "Happy Accident Slang compile completed in " + std::to_string(milliseconds) + " ms.";
build.artifact.shaderId = shaderPackage.id;
build.artifact.displayName = shaderPackage.displayName;
build.artifact.parameterDefinitions = shaderPackage.parameters;
build.artifact.message = shaderPackage.displayName + " Slang compile completed in " + std::to_string(milliseconds) + " ms.";
build.message = build.artifact.message;
return build;
}