// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::emit_specialization_constants()
void CompilerMSL::emit_specialization_constants()
{
	SpecializationConstant wg_x, wg_y, wg_z;
	uint32_t workgroup_size_id = get_work_group_size_specialization_constants(wg_x, wg_y, wg_z);
	bool emitted = false;

	for (auto &id : ir.ids)
	{
		if (id.get_type() == TypeConstant)
		{
			auto &c = id.get<SPIRConstant>();
			if (!c.specialization)
				continue;

			// If WorkGroupSize is a specialization constant, it will be declared explicitly below.
			if (c.self == workgroup_size_id)
				continue;

			auto &type = get<SPIRType>(c.constant_type);
			string sc_type_name = type_to_glsl(type);
			string sc_name = to_name(c.self);
			string sc_tmp_name = sc_name + "_tmp";

			// Function constants are only supported in MSL 1.2 and later.
			// If we don't support it just declare the "default" directly.
			// This "default" value can be overridden to the true specialization constant by the API user.
			if (msl_options.supports_msl_version(1, 2) && has_decoration(c.self, DecorationSpecId))
			{
				uint32_t constant_id = get_decoration(c.self, DecorationSpecId);
				// Only scalar, non-composite values can be function constants.
				statement("constant ", sc_type_name, " ", sc_tmp_name, " [[function_constant(", constant_id, ")]];");
				statement("constant ", sc_type_name, " ", sc_name, " = is_function_constant_defined(", sc_tmp_name,
				          ") ? ", sc_tmp_name, " : ", constant_expression(c), ";");
			}
			else
			{
				// Composite specialization constants must be built from other specialization constants.
				statement("constant ", sc_type_name, " ", sc_name, " = ", constant_expression(c), ";");
			}
			emitted = true;
		}
		else if (id.get_type() == TypeConstantOp)
		{
			auto &c = id.get<SPIRConstantOp>();
			auto &type = get<SPIRType>(c.basetype);
			auto name = to_name(c.self);
			statement("constant ", variable_decl(type, name), " = ", constant_op_expression(c), ";");
			emitted = true;
		}
	}

	// TODO: This can be expressed as a [[threads_per_threadgroup]] input semantic, but we need to know
	// the work group size at compile time in SPIR-V, and [[threads_per_threadgroup]] would need to be passed around as a global.
	// The work group size may be a specialization constant.
	if (workgroup_size_id)
	{
		statement("constant uint3 ", builtin_to_glsl(BuiltInWorkgroupSize, StorageClassWorkgroup), " = ",
		          constant_expression(get<SPIRConstant>(workgroup_size_id)), ";");
		emitted = true;
	}

	if (emitted)
		statement("");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %r15
leaq 0xa0(%rsp), %rsi
leaq 0x98(%rsp), %rdx
leaq 0x90(%rsp), %rcx
callq 0x12fd6
movl %eax, (%rsp)
movq 0x20(%r15), %rdi
movq 0x28(%r15), %rbx
xorl %ebp, %ebp
leaq 0x50(%rsp), %r13
cmpq %rbx, %rdi
je 0x71956
movl 0x8(%rdi), %eax
cmpl $0xa, %eax
je 0x71835
cmpl $0x3, %eax
jne 0x7194d
movq %rdi, %r14
callq 0x172b0
cmpb $0x1, 0x108(%rax)
jne 0x7194a
movq %rax, %r12
movl (%rsp), %eax
cmpl %eax, 0x8(%r12)
movq %r14, %rdi
je 0x7194d
movl 0xc(%r12), %esi
movq %r15, %rdi
callq 0x90a4
movq (%r15), %r8
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq *0x98(%r8)
movl 0x8(%r12), %edx
movq (%r15), %rax
movq %r13, %rdi
movq %r15, %rsi
pushq $0x1
popq %rcx
callq *0x38(%rax)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
leaq 0x2ba9d(%rip), %rdx     # 0x9d1f6
callq 0x174a5
cmpl $0x27d8, 0x7d0(%r15) # imm = 0x27D8
jb 0x718e0
movl 0x8(%r12), %esi
movq %r15, %rdi
pushq $0x1
popq %rdx
callq 0x103d2
testb %al, %al
je 0x718e0
movl 0x8(%r12), %esi
movq %r15, %rdi
pushq $0x1
popq %rdx
callq 0x12174
movl %eax, 0x4(%rsp)
movq %r15, %rdi
leaq 0x2ba40(%rip), %rsi     # 0x9d1e5
leaq 0x8(%rsp), %rdx
leaq 0x1e0d5(%rip), %rcx     # 0x8f886
leaq 0x30(%rsp), %r8
leaq 0x2ba3e(%rip), %r9      # 0x9d1fb
leaq 0x2ba4d(%rip), %rax     # 0x9d211
pushq %rax
leaq 0xc(%rsp), %rax
pushq %rax
callq 0x81068
popq %rax
popq %rcx
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x271d4
movq %r15, %rdi
leaq 0x2b9f6(%rip), %rsi     # 0x9d1e5
leaq 0x8(%rsp), %rdx
leaq 0x1e08b(%rip), %rcx     # 0x8f886
movq %r13, %r8
leaq 0x2ba11(%rip), %r9      # 0x9d216
leaq 0x28275(%rip), %rax     # 0x99a81
pushq %rax
pushq %rbp
leaq 0x1db2d(%rip), %rax     # 0x8f342
pushq %rax
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x2ba13(%rip), %rax     # 0x9d237
pushq %rax
pushq %r10
callq 0x81184
addq $0x30, %rsp
jmp 0x71923
movq %rbx, %r14
movq %rdi, 0x28(%rsp)
callq 0x20ad0
movq %rax, %r12
movl 0x28(%rax), %esi
movq %r15, %rdi
callq 0x90a4
movq %rax, %rbp
movl 0x8(%r12), %edx
movq (%r15), %rax
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
pushq $0x1
popq %rcx
callq *0x38(%rax)
movq (%r15), %rax
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
leaq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq *0xc8(%rax)
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x265a8
movq %r15, %rdi
leaq 0x2b945(%rip), %rsi     # 0x9d1e5
movq %r13, %rdx
leaq 0x28140(%rip), %rcx     # 0x999ea
movq %rbp, %r8
leaq 0x281cd(%rip), %r9      # 0x99a81
callq 0x80f72
movq %r14, %rbx
movq %rbp, %rdi
callq 0x6548
movq %r13, %rdi
callq 0x6548
leaq 0x8(%rsp), %rdi
callq 0x6548
movb $0x1, %bpl
movq 0x28(%rsp), %rdi
jmp 0x7194d
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x271d4
movq %r15, %rdi
leaq 0x2b8e8(%rip), %rsi     # 0x9d1e5
leaq 0x8(%rsp), %rdx
leaq 0x1df7d(%rip), %rcx     # 0x8f886
movq %r13, %r8
leaq 0x280d7(%rip), %r9      # 0x999ea
leaq 0x28167(%rip), %rax     # 0x99a81
pushq %rax
pushq %rbp
callq 0x812fa
popq %rax
popq %rcx
movq %rbp, %rdi
callq 0x6548
leaq 0x30(%rsp), %rdi
callq 0x6548
movq %r13, %rdi
callq 0x6548
leaq 0x8(%rsp), %rdi
callq 0x6548
movb $0x1, %bpl
movq %r14, %rdi
addq $0x10, %rdi
jmp 0x716cb
movl (%rsp), %r14d
testl %r14d, %r14d
je 0x719ce
movq (%r15), %rax
leaq 0x8(%rsp), %rdi
pushq $0x19
popq %rdx
pushq $0x4
popq %rcx
movq %r15, %rsi
callq *0xa0(%rax)
movq %r15, %rdi
movl %r14d, %esi
callq 0x17bce
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x271d4
leaq 0x2b8a4(%rip), %rsi     # 0x9d23c
leaq 0x2804b(%rip), %rcx     # 0x999ea
leaq 0x280db(%rip), %r9      # 0x99a81
leaq 0x8(%rsp), %rdx
leaq 0x50(%rsp), %r8
movq %r15, %rdi
callq 0x81416
leaq 0x50(%rsp), %rdi
callq 0x6548
leaq 0x8(%rsp), %rdi
callq 0x6548
jmp 0x719d4
testb $0x1, %bpl
je 0x719e3
leaq 0x1deac(%rip), %rsi     # 0x8f887
movq %r15, %rdi
callq 0x928e
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x71a4d
jmp 0x71a04
jmp 0x71a13
jmp 0x71a36
jmp 0x71a13
jmp 0x71a13
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x6548
jmp 0x71a16
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x6548
jmp 0x71a25
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x6548
jmp 0x71a57
movq %rax, %rbx
jmp 0x71a2f
movq %rax, %rbx
jmp 0x71a57
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x6548
jmp 0x71a4d
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x6548
leaq 0x8(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0
nop