Files
MobileGL/MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/LowerDrawParametersPass.h
T
swung0x48andClaude Fable 5 5ea49f3c50 [Feat] (MG_Backend/DirectGLES): support Flywheel indirect rendering
- Advertise ARB_gpu_shader5 / ARB_multi_bind / ARB_shading_language_420pack /
  ARB_vertex_attrib_binding / ARB_shader_image_size so LWJGL reports
  SUPPORTS_INDIRECT.
- New LowerDrawParametersPass demotes DrawIndex/BaseInstance/BaseVertex
  builtins to Private globals (mg_DrawID/mg_BaseInstance/mg_BaseVertex) for
  the ESSL transpile; SPIRV-Cross otherwise throws for ES profiles. The
  program manager promotes the emitted globals to uniforms and feeds them
  per (sub-)draw.
- Indirect draws now execute natively on the GPU (glDrawElementsIndirect /
  glDrawArraysIndirect per command) when an indirect buffer is bound, so
  compute-written command fields (Flywheel culling updates instanceCount)
  are honored; detects GL_EXT_base_instance and falls back to the CPU loop
  when the command's baseInstance cannot be consumed natively.
- Sync SSBO binding points for graphics draws, not just compute (Flywheel
  vertex shaders read instance data from SSBOs).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 13:33:05 +00:00

35 lines
1.6 KiB
C++

// MobileGL - MobileGL/MG_Util/ShaderTranspiler/SpirvPasses/LowerDrawParametersPass.h
// Copyright (c) 2025-2026 MobileGL-Dev
// Licensed under the GNU Lesser General Public License v3.0:
// https://www.gnu.org/licenses/gpl-3.0.txt
// https://www.gnu.org/licenses/lgpl-3.0.txt
// SPDX-License-Identifier: LGPL-3.0-only
// End of Source File Header
#pragma once
#include "source/opt/pass.h"
#include "spirv-tools/optimizer.hpp"
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
namespace ShaderTranspiler {
// ESSL has no gl_DrawID / gl_BaseInstance / gl_BaseVertex builtins and SPIRV-Cross
// refuses to emit them for ES targets. This pass demotes the DrawIndex /
// BaseInstance / BaseVertex builtin inputs to plain Private globals with
// well-known names (mg_DrawID / mg_BaseInstance / mg_BaseVertex) so the decompiled
// ESSL declares ordinary globals; the DirectGLES program manager then upgrades the
// declarations to uniforms and feeds them per (sub-)draw. Only meant for the
// DirectGLES transpile path - the Vulkan backend keeps the native builtins.
class LowerDrawParametersPass : public spvtools::opt::Pass {
public:
const char* name() const override { return "lower-draw-parameters"; }
Status Process() override;
static spvtools::Optimizer::PassToken CreateLowerDrawParametersPass();
};
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL