- Core simulator:
framework/(spirv_simulator.cpp/.hpp,util.*, opcode helpers, exceptions). - CLI entry points:
main.cpp(simulator) andmain_opcode_checker.cpp(opcode utility). - Build scaffolding: root
CMakeLists.txtpluscmake/modules andexternal/vendored deps. - Tests:
test/(gtest/gmock suites and harness) and sample shaders intest_shaders/. - Generated artifacts live in
build/(not committed).
- Configure:
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo - Build:
cmake --build build(orcmake --build build --target run_teststo compile tests too). - Run simulator:
cd build && ./spirv_simulator ../test_shaders/<shader>.spirv - Run unit tests:
cd build && ctest(ormake run_testsif using Makefiles). - Use system SPIR-V headers: add
-DSPIRV_HEADERS_PRESENT=1during configure.
- C++20, 4-space indentation, braces on new lines for control blocks as in existing sources.
- Keep header guards/
#pragma once, grouped includes, and minimal headers in headers. - Types/classes use PascalCase (
SPIRVSimulator); functions/methods are PascalCase; variables and struct fields are lower_snake_case. - Mirror existing patterns in
framework/spirv_simulator.*andtest/testing_common.*; prefer standard library utilities and assertions already in use.
- Framework: gtest + gmock (
TEST,TEST_P). Add new suites undertest/near related functionality. - When adding opcodes, include positive/edge cases and pointer/descriptor coverage where applicable.
- For shader-driven scenarios, place inputs in
test_shaders/and reference them via./spirv_simulatorin tests. - Ensure new tests run via
ctest; avoid long-running cases.
- Commits: concise, imperative subject line (e.g., “Add FNegate opcode handling”), scoped to a single concern.
- PRs: describe motivation, summarize changes, list test commands run, and link issues if relevant. Include before/after behavior for simulator-visible changes and any new CLI usage examples.
- The SPIRV simulator implements the SPIRV specification and parses SPIRV code to extract information about pointers and memory usage.
- Opcodes are handled in the c++ files
framework/spirv_simulator.cppandframework/spirv_simulator.hpp, and the classSPIRVSimulator - Each Opcode has a function handler of the form
void Op_<name>(const Instruction&); - Build with
make -j - Run tests with
ctest --output-on-failure
Minimal function implementation:
void SPIRVSimulator::Op_<name>(const Instruction& instruction)
{
/*
Op<name>
Some explanation goes here
*/
assert(instruction.opcode == spv::Op::Op<name>);
uint32_t type_id = instruction.words[1];
// do more work here
}- Place new cases in the closest suite under
test/(usemisc_test.cppas the fallback if no other suite fits) - Build with
make -j. Fix any errors shown. - Run tests with
ctest --output-on-failure. Fix any errors shown.