mirror of
https://github.com/KhronosGroup/SPIRV-Cross.git
synced 2024-11-09 22:00:05 +00:00
GLSL: Add option to disable buffer blocks regardless of version
This commit is contained in:
parent
fce83b7e8b
commit
7bc31491be
@ -267,7 +267,7 @@ endif()
|
||||
|
||||
if (SPIRV_CROSS_SHARED)
|
||||
set(spirv-cross-abi-major 0)
|
||||
set(spirv-cross-abi-minor 6)
|
||||
set(spirv-cross-abi-minor 7)
|
||||
set(spirv-cross-abi-patch 0)
|
||||
set(SPIRV_CROSS_VERSION ${spirv-cross-abi-major}.${spirv-cross-abi-minor}.${spirv-cross-abi-patch})
|
||||
set(SPIRV_CROSS_INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
|
4
main.cpp
4
main.cpp
@ -511,6 +511,7 @@ struct CLIArguments
|
||||
bool msl_argument_buffers = false;
|
||||
bool msl_texture_buffer_native = false;
|
||||
bool glsl_emit_push_constant_as_ubo = false;
|
||||
bool glsl_emit_ubo_as_plain_uniforms = false;
|
||||
SmallVector<uint32_t> msl_discrete_descriptor_sets;
|
||||
SmallVector<PLSArg> pls_in;
|
||||
SmallVector<PLSArg> pls_out;
|
||||
@ -563,6 +564,7 @@ static void print_help()
|
||||
"\t[--cpp]\n"
|
||||
"\t[--cpp-interface-name <name>]\n"
|
||||
"\t[--glsl-emit-push-constant-as-ubo]\n"
|
||||
"\t[--glsl-emit-ubo-as-plain-uniforms]\n"
|
||||
"\t[--msl]\n"
|
||||
"\t[--msl-version <MMmmpp>]\n"
|
||||
"\t[--msl-capture-output]\n"
|
||||
@ -854,6 +856,7 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
|
||||
opts.vertex.flip_vert_y = args.yflip;
|
||||
opts.vertex.support_nonzero_base_instance = args.support_nonzero_baseinstance;
|
||||
opts.emit_push_constant_as_uniform_buffer = args.glsl_emit_push_constant_as_ubo;
|
||||
opts.emit_uniform_buffer_as_plain_uniforms = args.glsl_emit_ubo_as_plain_uniforms;
|
||||
compiler->set_common_options(opts);
|
||||
|
||||
// Set HLSL specific options.
|
||||
@ -1025,6 +1028,7 @@ static int main_inner(int argc, char *argv[])
|
||||
cbs.add("--cpp-interface-name", [&args](CLIParser &parser) { args.cpp_interface_name = parser.next_string(); });
|
||||
cbs.add("--metal", [&args](CLIParser &) { args.msl = true; }); // Legacy compatibility
|
||||
cbs.add("--glsl-emit-push-constant-as-ubo", [&args](CLIParser &) { args.glsl_emit_push_constant_as_ubo = true; });
|
||||
cbs.add("--glsl-emit-ubo-as-plain-uniforms", [&args](CLIParser &) { args.glsl_emit_ubo_as_plain_uniforms = true; });
|
||||
cbs.add("--msl", [&args](CLIParser &) { args.msl = true; });
|
||||
cbs.add("--hlsl", [&args](CLIParser &) { args.hlsl = true; });
|
||||
cbs.add("--hlsl-enable-compat", [&args](CLIParser &) { args.hlsl_compat = true; });
|
||||
|
@ -442,6 +442,9 @@ spvc_result spvc_compiler_options_set_uint(spvc_compiler_options options, spvc_c
|
||||
case SPVC_COMPILER_OPTION_GLSL_EMIT_PUSH_CONSTANT_AS_UNIFORM_BUFFER:
|
||||
options->glsl.emit_push_constant_as_uniform_buffer = value != 0;
|
||||
break;
|
||||
case SPVC_COMPILER_OPTION_GLSL_EMIT_UNIFORM_BUFFER_AS_PLAIN_UNIFORMS:
|
||||
options->glsl.emit_uniform_buffer_as_plain_uniforms = value != 0;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if SPIRV_CROSS_C_API_HLSL
|
||||
|
@ -33,7 +33,7 @@ extern "C" {
|
||||
/* Bumped if ABI or API breaks backwards compatibility. */
|
||||
#define SPVC_C_API_VERSION_MAJOR 0
|
||||
/* Bumped if APIs or enumerations are added in a backwards compatible way. */
|
||||
#define SPVC_C_API_VERSION_MINOR 6
|
||||
#define SPVC_C_API_VERSION_MINOR 7
|
||||
/* Bumped if internal implementation details change. */
|
||||
#define SPVC_C_API_VERSION_PATCH 0
|
||||
|
||||
@ -426,6 +426,8 @@ typedef enum spvc_compiler_option
|
||||
|
||||
SPVC_COMPILER_OPTION_MSL_TEXTURE_BUFFER_NATIVE = 34 | SPVC_COMPILER_OPTION_MSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_GLSL_EMIT_UNIFORM_BUFFER_AS_PLAIN_UNIFORMS = 35 | SPVC_COMPILER_OPTION_GLSL_BIT,
|
||||
|
||||
SPVC_COMPILER_OPTION_INT_MAX = 0x7fffffff
|
||||
} spvc_compiler_option;
|
||||
|
||||
|
@ -1459,9 +1459,19 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var)
|
||||
attr.push_back(join("set = ", dec.set));
|
||||
}
|
||||
|
||||
bool push_constant_block = options.vulkan_semantics && var.storage == StorageClassPushConstant;
|
||||
bool ssbo_block = var.storage == StorageClassStorageBuffer ||
|
||||
(var.storage == StorageClassUniform && typeflags.get(DecorationBufferBlock));
|
||||
bool emulated_ubo = var.storage == StorageClassPushConstant && options.emit_push_constant_as_uniform_buffer;
|
||||
bool ubo_block = var.storage == StorageClassUniform && typeflags.get(DecorationBlock);
|
||||
|
||||
// GL 3.0/GLSL 1.30 is not considered legacy, but it doesn't have UBOs ...
|
||||
bool can_use_buffer_blocks = (options.es && options.version >= 300) || (!options.es && options.version >= 140);
|
||||
|
||||
// pretend no UBOs when options say so
|
||||
if (ubo_block && options.emit_uniform_buffer_as_plain_uniforms)
|
||||
can_use_buffer_blocks = false;
|
||||
|
||||
bool can_use_binding;
|
||||
if (options.es)
|
||||
can_use_binding = options.version >= 310;
|
||||
@ -1478,12 +1488,6 @@ string CompilerGLSL::layout_for_variable(const SPIRVariable &var)
|
||||
if (flags.get(DecorationOffset))
|
||||
attr.push_back(join("offset = ", dec.offset));
|
||||
|
||||
bool push_constant_block = options.vulkan_semantics && var.storage == StorageClassPushConstant;
|
||||
bool ssbo_block = var.storage == StorageClassStorageBuffer ||
|
||||
(var.storage == StorageClassUniform && typeflags.get(DecorationBufferBlock));
|
||||
bool emulated_ubo = var.storage == StorageClassPushConstant && options.emit_push_constant_as_uniform_buffer;
|
||||
bool ubo_block = var.storage == StorageClassUniform && typeflags.get(DecorationBlock);
|
||||
|
||||
// Instead of adding explicit offsets for every element here, just assume we're using std140 or std430.
|
||||
// If SPIR-V does not comply with either layout, we cannot really work around it.
|
||||
if (can_use_buffer_blocks && (ubo_block || emulated_ubo))
|
||||
@ -1611,9 +1615,13 @@ void CompilerGLSL::emit_push_constant_block_glsl(const SPIRVariable &var)
|
||||
|
||||
void CompilerGLSL::emit_buffer_block(const SPIRVariable &var)
|
||||
{
|
||||
auto &type = get<SPIRType>(var.basetype);
|
||||
bool ubo_block = var.storage == StorageClassUniform &&
|
||||
ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock);
|
||||
|
||||
if (flattened_buffer_blocks.count(var.self))
|
||||
emit_buffer_block_flattened(var);
|
||||
else if (is_legacy() || (!options.es && options.version == 130))
|
||||
else if (is_legacy() || (!options.es && options.version == 130) || (ubo_block && options.emit_uniform_buffer_as_plain_uniforms))
|
||||
emit_buffer_block_legacy(var);
|
||||
else
|
||||
emit_buffer_block_native(var);
|
||||
|
@ -99,6 +99,10 @@ public:
|
||||
// In non-Vulkan GLSL, emit push constant blocks as UBOs rather than plain uniforms.
|
||||
bool emit_push_constant_as_uniform_buffer = false;
|
||||
|
||||
// Always emit uniform blocks as plain uniforms, regardless of the GLSL version, even when UBOs are supported.
|
||||
// Does not apply to shader storage or push constant blocks.
|
||||
bool emit_uniform_buffer_as_plain_uniforms = false;
|
||||
|
||||
enum Precision
|
||||
{
|
||||
DontCare,
|
||||
|
Loading…
Reference in New Issue
Block a user