mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-13 14:48:32 +09:00
[Fix, Test] (MG_Util, MG_Backend/DirectVulkan, MG_IntegrationTest): review round - one module parse for the shaders with no 1D-array image, per-kind values the combined case can name, and the invariants two shared buffers rest on
This commit is contained in:
@@ -112,16 +112,30 @@ namespace MobileGL {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool Lower1DArrayImagesPass::BinaryQueriesA1DArrayStorageImageSize(const Vector<Uint32>& binary) {
|
||||
Lower1DArrayImagesPass::ModuleTraits Lower1DArrayImagesPass::InspectBinary(const Vector<Uint32>& binary) {
|
||||
ModuleTraits traits{};
|
||||
if (binary.empty()) {
|
||||
return false;
|
||||
return traits;
|
||||
}
|
||||
std::unique_ptr<IRContext> context = spvtools::BuildModule(
|
||||
SPV_ENV_VULKAN_1_1, [](spv_message_level_t, const char*, const spv_position_t&, const char*) {},
|
||||
binary.data(), binary.size());
|
||||
if (!context) {
|
||||
return false;
|
||||
return traits;
|
||||
}
|
||||
|
||||
// The type table settles it for the cheap half, and it is the half almost every
|
||||
// shader takes: no such type declared, nothing to inspect further.
|
||||
for (const Instruction& type : context->module()->types_values()) {
|
||||
if (Is1DArrayStorageImageType(&type)) {
|
||||
traits.declaresImage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!traits.declaresImage) {
|
||||
return traits;
|
||||
}
|
||||
|
||||
for (auto& function : *context->module()) {
|
||||
for (auto& block : function) {
|
||||
for (auto& instruction : block) {
|
||||
@@ -130,12 +144,13 @@ namespace MobileGL {
|
||||
}
|
||||
if (Is1DArrayStorageImageType(
|
||||
ResolveImageType(context.get(), instruction.GetSingleWordInOperand(0)))) {
|
||||
return true;
|
||||
traits.queriesImageSize = true;
|
||||
return traits;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return traits;
|
||||
}
|
||||
|
||||
spvtools::opt::Pass::Status Lower1DArrayImagesPass::Process() {
|
||||
|
||||
@@ -65,11 +65,22 @@ namespace MobileGL {
|
||||
const char* name() const override { return "mobilegl-lower-1d-array-images"; }
|
||||
Status Process() override;
|
||||
|
||||
// True when the module declares a 1D-array storage image whose size is queried,
|
||||
// which is the shape this pass refuses to translate. Checked by the caller before
|
||||
// running, so a declined module is handed on untouched rather than partly
|
||||
// rewritten.
|
||||
static bool BinaryQueriesA1DArrayStorageImageSize(const Vector<Uint32>& binary);
|
||||
// What one inspection of a binary tells the caller. Both answers come from a
|
||||
// SINGLE parse on purpose: every ESSL shader in the process reaches this, and
|
||||
// almost none of them declare a 1D-array storage image, so the common path has to
|
||||
// cost one module parse and no optimizer run at all - not one parse to ask about
|
||||
// size queries and a second inside an Optimizer that then early-outs.
|
||||
struct ModuleTraits {
|
||||
// The module declares a 1D-array storage image, i.e. there is anything to do.
|
||||
bool declaresImage = false;
|
||||
// ...and queries its size, which is the shape this pass refuses to translate:
|
||||
// afterwards the image is a 2D array, so the query yields three components
|
||||
// where the shader consumes two, and there is no correct two-component answer
|
||||
// to substitute. The caller leaves such a module alone rather than half
|
||||
// rewriting it.
|
||||
bool queriesImageSize = false;
|
||||
};
|
||||
static ModuleTraits InspectBinary(const Vector<Uint32>& binary);
|
||||
|
||||
static spvtools::Optimizer::PassToken CreateLower1DArrayImagesPass();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user