Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (49 loc) · 2.31 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (49 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Nothing here names a generated file. The shaders arrive through one import,
// and the two that share a stem are told apart by the directory they came from.
//
// `shader_app`, not `spirv_module_consumer`: the module root comes from
// `[package] name`, and this project's directory is named differently on
// purpose so that the two derivations are distinguishable here.
import std;
import shader_app.shaders;
namespace shaders = shader_app::shaders;
namespace {
// The one property that identifies a SPIR-V module without executing it.
constexpr std::uint32_t kSpirvMagic = 0x07230203u;
bool check(std::string_view label, shaders::payload p) {
const bool ok = p.size_bytes >= 4 && p.code[0] == kSpirvMagic;
std::cout << std::format("{}: magic={:08x} bytes={} {}\n", label,
p.size_bytes >= 4 ? p.code[0] : 0u, p.size_bytes,
ok ? "ok" : "BAD");
return ok;
}
} // namespace
int main() {
bool ok = true;
ok &= check("a/scale.comp", shaders::a::scale_comp());
ok &= check("b/scale.comp", shaders::b::scale_comp());
// A DIRECTORY NAMED AFTER A C++ KEYWORD, reached as `default_`.
//
// `a` and `b` are ordinary identifiers, so neither could tell a name filter
// that knows the keywords from one that does not. `shaders/default/` is an
// ordinary name for a shader directory and `namespace default {` is not a
// namespace: without the trailing underscore the generator writes a file
// that does not parse, and the error names a line nobody wrote.
ok &= check("default/scale.comp", shaders::default_::scale_comp());
// The two shaders are the same source in two directories, so they must
// produce identical modules -- and they must be two distinct objects, not
// one symbol reached twice. Both are properties of the naming, and a build
// that collapsed them would still print two lines above.
const auto x = shaders::a::scale_comp();
const auto y = shaders::b::scale_comp();
if (x.code == y.code) {
std::cout << "BAD: both namespaces resolve to one array\n";
ok = false;
}
if (x.size_bytes != y.size_bytes) {
std::cout << "BAD: identical sources produced different sizes\n";
ok = false;
}
std::cout << (ok ? "all ok\n" : "FAILED\n");
return ok ? 0 : 1;
}