// File: rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::CombinedImageSamplerUsageHandler::handle(spv::Op, unsigned int const*, unsigned int)
bool Compiler::CombinedImageSamplerUsageHandler::handle(Op opcode, const uint32_t *args, uint32_t length)
{
	switch (opcode)
	{
	case OpAccessChain:
	case OpInBoundsAccessChain:
	case OpLoad:
	{
		if (length < 3)
			return false;
		dependency_hierarchy[args[1]].insert(args[2]);

		// Ideally defer this to OpImageRead, but then we'd need to track loaded IDs.
		// If we load an image, we're going to use it and there is little harm in declaring an unused gl_FragCoord.
		auto &type = compiler.get<SPIRType>(args[0]);
		if (type.image.dim == DimSubpassData)
			need_subpass_input = true;

		// If we load a SampledImage and it will be used with Dref, propagate the state up.
		if (dref_combined_samplers.count(args[1]) != 0)
			add_hierarchy_to_comparison_ids(args[1]);
		break;
	}

	case OpSampledImage:
	{
		if (length < 4)
			return false;

		uint32_t result_type = args[0];
		uint32_t result_id = args[1];
		auto &type = compiler.get<SPIRType>(result_type);
		if (type.image.depth || dref_combined_samplers.count(result_id) != 0)
		{
			// This image must be a depth image.
			uint32_t image = args[2];
			add_hierarchy_to_comparison_ids(image);

			// This sampler must be a SamplerComparisonState, and not a regular SamplerState.
			uint32_t sampler = args[3];
			add_hierarchy_to_comparison_ids(sampler);

			// Mark the OpSampledImage itself as being comparison state.
			comparison_ids.insert(result_id);
		}
		return true;
	}

	default:
		break;
	}

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0x3d, %eax
je 0x2bd6c
jmp 0x2bd4e
movl -0x6c(%rbp), %eax
addl $-0x41, %eax
subl $0x2, %eax
jb 0x2bd6c
jmp 0x2bd5b
movl -0x6c(%rbp), %eax
subl $0x56, %eax
je 0x2be09
jmp 0x2bead
cmpl $0x3, -0x24(%rbp)
jae 0x2bd7b
movb $0x0, -0x1(%rbp)
jmp 0x2beb3
movq -0x78(%rbp), %rdi
addq $0x18, %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x31a50
movq %rax, %rdi
movq -0x20(%rbp), %rsi
addq $0x8, %rsi
callq 0x2e890
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x38(%rbp)
movb %dl, -0x30(%rbp)
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %esi
callq 0xea90
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x6, 0x84(%rax)
jne 0x2bdd9
movq -0x78(%rbp), %rax
movb $0x1, 0x88(%rax)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x13520
cmpq $0x0, %rax
je 0x2be04
movq -0x78(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x2bc80
jmp 0x2beaf
cmpl $0x4, -0x24(%rbp)
jae 0x2be18
movb $0x0, -0x1(%rbp)
jmp 0x2beb3
movq -0x78(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, -0x44(%rbp)
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %ecx
movl %ecx, -0x48(%rbp)
movq 0x8(%rax), %rdi
movl -0x44(%rbp), %esi
callq 0xea90
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
testb $0x1, 0x88(%rax)
jne 0x2be63
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x13520
cmpq $0x0, %rax
je 0x2bea7
movq -0x78(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %esi
callq 0x2bc80
movq -0x78(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %esi
callq 0x2bc80
movq -0x78(%rbp), %rdi
addq $0x50, %rdi
leaq -0x48(%rbp), %rsi
callq 0x2e890
movq %rax, -0x68(%rbp)
movb %dl, -0x60(%rbp)
movb $0x1, -0x1(%rbp)
jmp 0x2beb3
jmp 0x2beaf
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)