Files
Toastconcern--FrameStudio/third_party/spirv-tools/source/opt/eliminate_dead_constant_pass.cpp
T
ToastconcernandClaude Opus 5.5 6d0b4fcd2f v0.2.0: splats, copy/paste, faster homes, seat facing, and a full bug sweep
Frame Studio
- Gaussian splats (PLY, SPZ v2-v4), PLY vertex colours, panorama skies
- Copy, cut, paste and duplicate for objects, splats and world items
- Walkable-area rebake moved off the UI thread; viewport one frame sooner;
  refresh-locked pacing (FS_PACE=timer for the old one)
- Fixed: bundle thumbnail use-after-free crash, auto-save deleting
  environments, saves into scratch copies, edits lost on non-ASCII paths,
  unopenable manifests with inf/nan, bundle save data loss, opening a home
  marking it changed, gizmo NaN, long paths, many malformed-file crashes
- Updater verifies sha256, journals the swap and never leaves the exe missing

Frame Home
- Seats turn you to face their way
- Draw batching (Hand Tutorials up to ~20% less GPU time), cut-out EQUAL pass,
  late head-pose read before submit
- Proper queue-family hand-over to the compositor layer; layer descriptor
  generations and seqlocked slots; structural SPIR-V check
- Fixed: hangs/crashes on damaged .fenv files and shaders, render-pass
  validation error, sync hazard in the foveation smoothing pass, unverified
  update downloads, half-done installs

Tests: tests_loco/env_share/spv_check wired into CMake (FRAME_TESTS) and CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VsaXGU27gsrXjDoFtyFJP9
2026-10-25 13:15:07 -05:00

104 lines
3.6 KiB
C++

// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "source/opt/eliminate_dead_constant_pass.h"
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "source/opt/def_use_manager.h"
#include "source/opt/log.h"
#include "source/opt/reflect.h"
namespace spvtools {
namespace opt {
Pass::Status EliminateDeadConstantPass::Process() {
std::unordered_set<Instruction*> working_list;
// Traverse all the instructions to get the initial set of dead constants as
// working list and count number of real uses for constants. Uses in
// annotation instructions do not count.
std::unordered_map<Instruction*, size_t> use_counts;
std::vector<Instruction*> constants = context()->GetConstants();
for (auto* c : constants) {
uint32_t const_id = c->result_id();
size_t count = 0;
context()->get_def_use_mgr()->ForEachUse(
const_id, [&count](Instruction* user, uint32_t index) {
(void)index;
spv::Op op = user->opcode();
if (!(IsAnnotationInst(op) || IsDebug1Inst(op) || IsDebug2Inst(op) ||
IsDebug3Inst(op))) {
++count;
}
});
use_counts[c] = count;
if (!count) {
working_list.insert(c);
}
}
// Start from the constants with 0 uses, back trace through the def-use chain
// to find all dead constants.
std::unordered_set<Instruction*> dead_consts;
while (!working_list.empty()) {
Instruction* inst = *working_list.begin();
// Back propagate if the instruction contains IDs in its operands.
switch (inst->opcode()) {
case spv::Op::OpConstantComposite:
case spv::Op::OpSpecConstantComposite:
case spv::Op::OpSpecConstantOp:
for (uint32_t i = 0; i < inst->NumInOperands(); i++) {
// SpecConstantOp instruction contains 'opcode' as its operand. Need
// to exclude such operands when decreasing uses.
if (inst->GetInOperand(i).type != SPV_OPERAND_TYPE_ID) {
continue;
}
uint32_t operand_id = inst->GetSingleWordInOperand(i);
Instruction* def_inst =
context()->get_def_use_mgr()->GetDef(operand_id);
// If the use_count does not have any count for the def_inst,
// def_inst must not be a constant, and should be ignored here.
if (!use_counts.count(def_inst)) {
continue;
}
// The number of uses should never be less then 0, so it can not be
// less than 1 before it decreases.
SPIRV_ASSERT(consumer(), use_counts[def_inst] > 0);
--use_counts[def_inst];
if (!use_counts[def_inst]) {
working_list.insert(def_inst);
}
}
break;
default:
break;
}
dead_consts.insert(inst);
working_list.erase(inst);
}
// Turn all dead instructions and uses of them to nop
for (auto* dc : dead_consts) {
context()->KillDef(dc->result_id());
}
return dead_consts.empty() ? Status::SuccessWithoutChange
: Status::SuccessWithChange;
}
} // namespace opt
} // namespace spvtools