[DirectX] Add suport to remove specified sections (parts)

This commit is contained in:
Finn Plummer 2025-08-12 18:06:12 +00:00
parent d450f5e5a1
commit 09a5ebed14
4 changed files with 50 additions and 0 deletions

View File

@ -44,6 +44,7 @@ source_group("Source Files\\DXContainer" REGULAR_EXPRESSION
add_llvm_component_library(LLVMObjCopy
Archive.cpp
DXContainer/DXContainerObjcopy.cpp
DXContainer/DXContainerObject.cpp
DXContainer/DXContainerReader.cpp
DXContainer/DXContainerWriter.cpp
CommonConfig.cpp

View File

@ -19,6 +19,18 @@ namespace dxbc {
using namespace object;
static Error handleArgs(const CommonConfig &Config, Object &Obj) {
std::function<bool(const Part &)> RemovePred = [](const Part &) {
return false;
};
if (!Config.ToRemove.empty())
RemovePred = [&Config](const Part &P) {
return Config.ToRemove.matches(P.Name);
};
if (auto E = Obj.removeParts(RemovePred))
return E;
return Error::success();
}

View File

@ -0,0 +1,30 @@
//===- DXContainerObject.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "DXContainerObject.h"
namespace llvm {
namespace objcopy {
namespace dxbc {
Error Object::removeParts(PartPred ToRemove) {
erase_if(Parts, ToRemove);
recomputeHeader();
return Error::success();
}
void Object::recomputeHeader() {
Header.FileSize = headerSize();
Header.PartCount = Parts.size();
for (const Part &P : Parts)
Header.FileSize += P.size();
}
} // end namespace dxbc
} // end namespace objcopy
} // end namespace llvm

View File

@ -30,6 +30,8 @@ struct Part {
}
};
using PartPred = llvm::function_ref<bool(const Part &)>;
struct Object {
::llvm::dxbc::Header Header;
SmallVector<Part> Parts;
@ -38,6 +40,11 @@ struct Object {
return sizeof(::llvm::dxbc::Header) // base header
+ sizeof(uint32_t) * Parts.size(); // part offset values
}
Error removeParts(PartPred ToRemove);
private:
void recomputeHeader();
};
} // end namespace dxbc