MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / main

Function main

examples/cpp-interface/main.cpp:29–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#include "spirv-tools/optimizer.hpp"
28
29int main() {
30 const std::string source =
31 " OpCapability Linkage "
32 " OpCapability Shader "
33 " OpMemoryModel Logical GLSL450 "
34 " OpSource GLSL 450 "
35 " OpDecorate %spec SpecId 1 "
36 " %int = OpTypeInt 32 1 "
37 " %spec = OpSpecConstant %int 0 "
38 "%const = OpConstant %int 42";
39
40 spvtools::SpirvTools core(SPV_ENV_UNIVERSAL_1_3);
41 spvtools::Optimizer opt(SPV_ENV_UNIVERSAL_1_3);
42
43 auto print_msg_to_stderr = [](spv_message_level_t, const char*,
44 const spv_position_t&, const char* m) {
45 std::cerr << "error: " << m << std::endl;
46 };
47 core.SetMessageConsumer(print_msg_to_stderr);
48 opt.SetMessageConsumer(print_msg_to_stderr);
49
50 std::vector<uint32_t> spirv;
51 if (!core.Assemble(source, &spirv)) return 1;
52 if (!core.Validate(spirv)) return 1;
53
54 opt.RegisterPass(spvtools::CreateSetSpecConstantDefaultValuePass({{1, "42"}}))
55 .RegisterPass(spvtools::CreateFreezeSpecConstantValuePass())
56 .RegisterPass(spvtools::CreateUnifyConstantPass())
57 .RegisterPass(spvtools::CreateStripDebugInfoPass());
58 if (!opt.Run(spirv.data(), spirv.size(), &spirv)) return 1;
59
60 std::string disassembly;
61 if (!core.Disassemble(spirv, &disassembly)) return 1;
62 std::cout << disassembly << "\n";
63
64 return 0;
65}

Callers

nothing calls this directly

Calls 11

CreateUnifyConstantPassFunction · 0.85
CreateStripDebugInfoPassFunction · 0.85
SetMessageConsumerMethod · 0.45
AssembleMethod · 0.45
ValidateMethod · 0.45
RunMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
DisassembleMethod · 0.45

Tested by

no test coverage detected