This commit is contained in:
parent
c0e4067639
commit
19b059a88c
11 changed files with 286 additions and 1 deletions
61
tests/Shader/Shader.cpp
Normal file
61
tests/Shader/Shader.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
LGPL-3.0-only.
|
||||
|
||||
End-to-end shader build through the V2 pipeline:
|
||||
the inner project.cpp registers a vertex shader via cfg.shaders, and
|
||||
crafter.build-lib invokes glslang in-process to lower it to SPIR-V. The
|
||||
test verifies the resulting .spv file lands in the per-target bin dir
|
||||
and starts with the SPIR-V magic word — a zero-length output or one
|
||||
written under a different name would be flagged here rather than
|
||||
silently passing.
|
||||
*/
|
||||
|
||||
import std;
|
||||
import Crafter.Build;
|
||||
#include "../_shared/TestUtil.h"
|
||||
namespace fs = std::filesystem;
|
||||
using namespace TestUtil;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
try {
|
||||
fs::path src = fs::current_path() / "tests" / "Shader" / "inner";
|
||||
Configuration cfg = LoadFixture("Shader", src);
|
||||
fs::path work = fs::current_path();
|
||||
|
||||
auto br = BuildOnce(cfg);
|
||||
if (!br.result.empty()) {
|
||||
std::println(std::cerr, "build failed:\n{}", br.result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fs::path spv = work / "bin" / "shader-test-x86_64-pc-linux-gnu-native" / "triangle.spv";
|
||||
if (!fs::exists(spv)) {
|
||||
std::println(std::cerr, "expected SPIR-V output missing at {}", spv.string());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// SPIR-V module header magic is 0x07230203, written as a 32-bit word
|
||||
// in the module's endianness (always little-endian on the targets we
|
||||
// build). Matching the raw byte sequence catches truncated writes
|
||||
// and any future regression that produces a non-SPIR-V .spv.
|
||||
std::ifstream f(spv, std::ios::binary);
|
||||
unsigned char magic[4] = {};
|
||||
f.read(reinterpret_cast<char*>(magic), 4);
|
||||
if (magic[0] != 0x03 || magic[1] != 0x02 || magic[2] != 0x23 || magic[3] != 0x07) {
|
||||
std::println(std::cerr,
|
||||
"SPIR-V magic mismatch: got {:#04x} {:#04x} {:#04x} {:#04x}",
|
||||
magic[0], magic[1], magic[2], magic[3]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::println(std::cerr, "test exception: {}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
3
tests/Shader/inner/main.cpp
Normal file
3
tests/Shader/inner/main.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import std;
|
||||
|
||||
int main() { return 0; }
|
||||
21
tests/Shader/inner/project.cpp
Normal file
21
tests/Shader/inner/project.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view>) {
|
||||
Configuration cfg;
|
||||
cfg.path = "./";
|
||||
cfg.name = "shader-test";
|
||||
cfg.outputName = "shader-test";
|
||||
cfg.target = "x86_64-pc-linux-gnu";
|
||||
cfg.type = ConfigurationType::Executable;
|
||||
|
||||
std::array<fs::path, 0> ifaces = {};
|
||||
std::array<fs::path, 1> impls = { "main" };
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
|
||||
cfg.shaders.emplace_back("triangle.glsl", "main", ShaderType::Vertex);
|
||||
|
||||
return cfg;
|
||||
}
|
||||
13
tests/Shader/inner/triangle.glsl
Normal file
13
tests/Shader/inner/triangle.glsl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0) out vec3 color;
|
||||
|
||||
void main() {
|
||||
vec2 positions[3] = vec2[](
|
||||
vec2( 0.0, -0.5),
|
||||
vec2( 0.5, 0.5),
|
||||
vec2(-0.5, 0.5)
|
||||
);
|
||||
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
||||
color = vec3(1.0, 0.0, 0.0);
|
||||
}
|
||||
20
tests/Shader/project.cpp
Normal file
20
tests/Shader/project.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view>) {
|
||||
Configuration cfg;
|
||||
cfg.path = "tests/Shader/";
|
||||
cfg.name = "Shader";
|
||||
cfg.outputName = "Shader";
|
||||
cfg.target = "x86_64-pc-linux-gnu";
|
||||
cfg.type = ConfigurationType::Executable;
|
||||
cfg.dependencies = { ParentLib("crafter.build-lib") };
|
||||
cfg.linkFlags.push_back("-Wl,--export-dynamic");
|
||||
cfg.linkFlags.push_back("-ldl");
|
||||
std::array<fs::path, 0> ifaces = {};
|
||||
std::array<fs::path, 1> impls = { "Shader" };
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
return cfg;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue