//
// Created by igor on 28.03.2021.
//

#include "Camera.cuh"


Camera::Camera(float fov, const unsigned int x, const unsigned int y) : fov(fov), x(x), y(y) {
    position = Matrix4::IDENTITY;
    origin = Vector3{0, 0, 0};
    float pixelDxLen = tan(fov/2)/x*2;
    pixelDx = {pixelDxLen, 0, 0};
    pixelDy = {0, -pixelDxLen, 0};
    Vector3 left = x / -2.0 * pixelDx;
    Vector3 top = y / -2.0 * pixelDy;
    topLeft = left + top + Vector3{0, 0, -1};
}

	.file	"tmpxft_001fddc9_00000000-6_Camera.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2013:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2013:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.globl	_ZN6CameraC2Efjj
	.type	_ZN6CameraC2Efjj, @function
_ZN6CameraC2Efjj:
.LFB2009:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movd	%xmm0, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%esi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	leaq	60(%rsp), %r12
	call	_ZN7Matrix4C1Ev@PLT
	movd	%r14d, %xmm3
	movq	%rbx, %rdi
	xorps	%xmm2, %xmm2
	cvtss2sd	%xmm3, %xmm0
	movl	%ebp, 140(%rbx)
	movaps	%xmm2, %xmm1
	leaq	_ZN7Matrix48IDENTITYE(%rip), %rsi
	movsd	%xmm0, 128(%rbx)
	movl	$32, %ecx
	movaps	%xmm2, %xmm0
	movl	%r13d, 136(%rbx)
	rep movsl
	movq	%r12, %rdi
	call	_ZN7Vector3C1Efff@PLT
	movq	60(%rsp), %rax
	movd	%r14d, %xmm0
	mulss	.LC1(%rip), %xmm0
	movq	%rax, 180(%rbx)
	movl	68(%rsp), %eax
	movl	%eax, 188(%rbx)
	call	tanf@PLT
	xorps	%xmm2, %xmm2
	movq	%r12, %rdi
	movaps	%xmm0, %xmm1
	cvtsi2ssq	%r13, %xmm0
	divss	%xmm0, %xmm1
	addss	%xmm1, %xmm1
	movaps	%xmm1, %xmm0
	movaps	%xmm2, %xmm1
	movss	%xmm0, 12(%rsp)
	call	_ZN7Vector3C1Efff@PLT
	movq	60(%rsp), %rax
	xorps	%xmm2, %xmm2
	movq	%r12, %rdi
	movss	12(%rsp), %xmm0
	movq	%rax, 156(%rbx)
	movl	68(%rsp), %eax
	movaps	%xmm0, %xmm1
	xorps	.LC2(%rip), %xmm1
	movaps	%xmm2, %xmm0
	movl	%eax, 164(%rbx)
	call	_ZN7Vector3C1Efff@PLT
	movq	60(%rsp), %rax
	cvtsi2sdq	%r13, %xmm0
	mulsd	.LC3(%rip), %xmm0
	leaq	156(%rbx), %rdi
	movq	%rax, 168(%rbx)
	movl	68(%rsp), %eax
	movl	%eax, 176(%rbx)
	cvtsd2ss	%xmm0, %xmm0
	call	_ZmlfRK7Vector3@PLT
	leaq	168(%rbx), %rdi
	movq	%xmm0, 24(%rsp)
	cvtsi2sdq	%rbp, %xmm0
	mulsd	.LC3(%rip), %xmm0
	movss	%xmm1, 32(%rsp)
	cvtsd2ss	%xmm0, %xmm0
	call	_ZmlfRK7Vector3@PLT
	movq	%r12, %rdi
	movss	.LC4(%rip), %xmm2
	movss	%xmm1, 44(%rsp)
	xorps	%xmm1, %xmm1
	movq	%xmm0, 36(%rsp)
	movaps	%xmm1, %xmm0
	call	_ZN7Vector3C1Efff@PLT
	leaq	36(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	_ZplRK7Vector3S1_@PLT
	leaq	48(%rsp), %rdi
	movq	%r12, %rsi
	movq	%xmm0, 48(%rsp)
	movss	%xmm1, 56(%rsp)
	call	_ZplRK7Vector3S1_@PLT
	movq	%xmm0, 144(%rbx)
	movss	%xmm1, 152(%rbx)
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$80, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2009:
	.size	_ZN6CameraC2Efjj, .-_ZN6CameraC2Efjj
	.globl	_ZN6CameraC1Efjj
	.set	_ZN6CameraC1Efjj,_ZN6CameraC2Efjj
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1056964608
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	-1075838976
	.section	.rodata.cst4
	.align 4
.LC4:
	.long	-1082130432
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

//
// Created by igor on 28.03.2021.
//

#ifndef CUDATEST_CAMERA_CUH
#define CUDATEST_CAMERA_CUH


#include "Matrix4.cuh"

class Camera {
public:
    Camera(float fov, unsigned int x, unsigned int y);

public:
    Matrix4 position;
    double fov;
    const unsigned int x, y;
    Vector3 topLeft;
    Vector3 pixelDx, pixelDy;
    Vector3 origin;
};


#endif //CUDATEST_CAMERA_CUH

	.text
	.file	"Camera.hip"
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
