// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::emit_builtin_variables()
void CompilerHLSL::emit_builtin_variables()
{
	Bitset builtins = active_input_builtins;
	builtins.merge_or(active_output_builtins);

	// Emit global variables for the interface variables which are statically used by the shader.
	builtins.for_each_bit([&](uint32_t i) {
		const char *type = nullptr;
		auto builtin = static_cast<BuiltIn>(i);
		uint32_t array_size = 0;

		switch (builtin)
		{
		case BuiltInFragCoord:
		case BuiltInPosition:
			type = "float4";
			break;

		case BuiltInFragDepth:
			type = "float";
			break;

		case BuiltInVertexId:
		case BuiltInVertexIndex:
		case BuiltInInstanceId:
		case BuiltInInstanceIndex:
		case BuiltInSampleId:
			type = "int";
			break;

		case BuiltInPointSize:
			if (hlsl_options.point_size_compat)
			{
				// Just emit the global variable, it will be ignored.
				type = "float";
				break;
			}
			else
				SPIRV_CROSS_THROW(join("Unsupported builtin in HLSL: ", unsigned(builtin)));

		case BuiltInGlobalInvocationId:
		case BuiltInLocalInvocationId:
		case BuiltInWorkgroupId:
			type = "uint3";
			break;

		case BuiltInLocalInvocationIndex:
			type = "uint";
			break;

		case BuiltInFrontFacing:
			type = "bool";
			break;

		case BuiltInNumWorkgroups:
		case BuiltInPointCoord:
			// Handled specially.
			break;

		case BuiltInSubgroupLocalInvocationId:
		case BuiltInSubgroupSize:
			if (hlsl_options.shader_model < 60)
				SPIRV_CROSS_THROW("Need SM 6.0 for Wave ops.");
			break;

		case BuiltInSubgroupEqMask:
		case BuiltInSubgroupLtMask:
		case BuiltInSubgroupLeMask:
		case BuiltInSubgroupGtMask:
		case BuiltInSubgroupGeMask:
			if (hlsl_options.shader_model < 60)
				SPIRV_CROSS_THROW("Need SM 6.0 for Wave ops.");
			type = "uint4";
			break;

		case BuiltInClipDistance:
			array_size = clip_distance_count;
			type = "float";
			break;

		case BuiltInCullDistance:
			array_size = cull_distance_count;
			type = "float";
			break;

		default:
			SPIRV_CROSS_THROW(join("Unsupported builtin in HLSL: ", unsigned(builtin)));
		}

		StorageClass storage = active_input_builtins.get(i) ? StorageClassInput : StorageClassOutput;
		// FIXME: SampleMask can be both in and out with sample builtin,
		// need to distinguish that when we add support for that.

		if (type)
		{
			if (array_size)
				statement("static ", type, " ", builtin_to_glsl(builtin, storage), "[", array_size, "];");
			else
				statement("static ", type, " ", builtin_to_glsl(builtin, storage), ";");
		}
	});
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r14
movq 0x2d0(%rdi), %rax
leaq 0x20(%rsp), %rbx
movq %rax, -0x8(%rbx)
leaq 0x2d8(%rdi), %rsi
xorl %eax, %eax
movq %rax, (%rbx)
movq 0x2e0(%rdi), %rcx
movq %rcx, 0x8(%rbx)
movq %rax, 0x10(%rbx)
movq 0x2f0(%rdi), %rcx
movq %rcx, 0x18(%rbx)
movups 0x2f8(%rdi), %xmm0
movups %xmm0, 0x20(%rbx)
movq %rax, 0x30(%rbx)
movq %rsp, %rdx
movq %rbx, (%rdx)
movq %rbx, %rdi
callq 0xd3c2
movq 0x310(%r14), %rax
orq %rax, -0x8(%rbx)
movq 0x328(%r14), %r12
testq %r12, %r12
je 0x65188
movq %rsp, %r15
leaq 0x8(%r12), %rsi
movq %rbx, (%rsp)
movq %rbx, %rdi
movq %r15, %rdx
callq 0x1f510
movq (%r12), %r12
testq %r12, %r12
jne 0x6516b
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
btq %r15, %rax
jae 0x651a1
movq %r14, %rdi
movl %r15d, %esi
callq 0x74092
incq %r15
cmpq $0x40, %r15
jne 0x6518b
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
je 0x65282
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x7c9e4
movq 0x30(%rsp), %r12
testq %r12, %r12
je 0x6520c
movq %rsp, %r15
leaq 0x8(%r12), %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x651fb
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x65203
movq %r15, %rdi
callq 0x797e
movq (%r12), %r12
testq %r12, %r12
jne 0x651db
movq (%rsp), %r15
movq 0x8(%rsp), %r12
cmpq %r12, %r15
je 0x6526d
movq %r12, %rax
subq %r15, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x214b1
movq %r15, %rdi
movq %r12, %rsi
callq 0x21594
movq (%rsp), %r15
movq 0x8(%rsp), %r12
cmpq %r12, %r15
je 0x6526d
movl (%r15), %esi
movq %r14, %rdi
callq 0x74092
addq $0x4, %r15
cmpq %r12, %r15
jne 0x65255
movq (%rsp), %r15
testq %r15, %r15
je 0x65282
movq 0x10(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x6260
movq %rbx, %rdi
callq 0xd570
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x6529a
jmp 0x6529a
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x652ba
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6260
jmp 0x652ba
jmp 0x652b7
movq %rax, %r14
movq %rbx, %rdi
callq 0xd570
movq %r14, %rdi
callq 0x64a0