// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rdi, %r14
movq 0x2d0(%rdi), %rax
leaq 0x30(%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 0xd402
movq 0x310(%r14), %rax
orq %rax, -0x8(%rbx)
movq 0x328(%r14), %r12
testq %r12, %r12
je 0x65a5e
movq %rsp, %r15
leaq 0x8(%r12), %rsi
movq %rbx, (%rsp)
movq %rbx, %rdi
movq %r15, %rdx
callq 0x1fc02
movq (%r12), %r12
testq %r12, %r12
jne 0x65a41
leaq 0x20(%rsp), %r15
movq %r14, (%r15)
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
btq %r14, %rax
jae 0x65a7f
movq %r15, %rdi
movl %r14d, %esi
callq 0x74b36
incq %r14
cmpq $0x40, %r14
jne 0x65a69
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0x65b60
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x7d4ee
movq 0x40(%rsp), %r15
testq %r15, %r15
je 0x65ae8
movq %rsp, %r14
leaq 0x8(%r15), %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x65ad8
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x65ae0
movq %r14, %rdi
callq 0x7a00
movq (%r15), %r15
testq %r15, %r15
jne 0x65ab9
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0x65b23
movq %r15, %rax
subq %r14, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x21b53
movq %r14, %rdi
movq %r15, %rsi
callq 0x21c36
movq (%rsp), %r15
movq 0x8(%rsp), %r12
cmpq %r12, %r15
je 0x65b4a
leaq 0x20(%rsp), %r14
movl (%r15), %esi
movq %r14, %rdi
callq 0x74b36
addq $0x4, %r15
cmpq %r12, %r15
jne 0x65b36
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x65b60
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6260
movq %rbx, %rdi
callq 0xd5b0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x65b78
jmp 0x65b78
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x65b98
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6260
jmp 0x65b98
jmp 0x65b95
movq %rax, %r14
movq %rbx, %rdi
callq 0xd5b0
movq %r14, %rdi
callq 0x64a0