• 用内联汇编写的RT核心


     

        __asm {

    152  :     ray_dir = ray->dir;
    153  : 
    154  :     dot_nd = - ( normal.x * ray_dir.x + normal.y * ray_dir.y + normal.z * ray_dir.z );

            xorps        xmm3, xmm3                                ;
            mov            ebx, dword ptr ray                        ;
            mov            edi, dword ptr state                    ;
            mov            esi, dword ptr 
    this                        ;
            mov            ecx, dword ptr [ebx]e_Ray.dir.x            ;
            mov            edx, dword ptr [ebx]e_Ray.dir.y            ;
            mov            eax, dword ptr [ebx]e_Ray.dir.z            ;
            movss        xmm0, dword ptr [esi]
    this.normal.z        ;
            movss        xmm1, dword ptr [esi]
    this.normal.y        ;
            prefetchnta 
    byte ptr [esi+TYPE this]                ;
            mov            dword ptr ray_dir.x, ecx                ;
            mov            dword ptr ray_dir.y, edx                ;
            mulss        xmm1, dword ptr ray_dir.y                ;
            mov            dword ptr ray_dir.z, eax                ;
            mulss        xmm0, dword ptr ray_dir.z                ;
            addss        xmm0, xmm1                                ;
            movss        xmm1, dword ptr [esi]
    this.normal.x        ;
            mulss        xmm1, dword ptr ray_dir.x                ;

    156  :     ray_src = ray->src;

            mov            edx, dword ptr [ebx]e_Ray.src.x            ;
            mov            eax, dword ptr [ebx]e_Ray.src.y            ;
            mov            ecx, dword ptr [ebx]e_Ray.src.z            ;
            addss        xmm0, xmm1                                ;
            movaps        xmm1, xmm3                                ;
            subss        xmm1, xmm0                                ;
     
    158  :     if( dot_nd <= 0.0f )

            comiss        xmm3, xmm1                                ;
            movss        dword ptr dot_nd, xmm1                    ;
            mov            dword ptr ray_src.x, edx                ;
            mov            dword ptr ray_src.y, eax                ;
            mov            dword ptr ray_src.z, ecx                ;

    159  :         return false;

            jae            RETURN_FALSE                            ;

    161  :     t = ray_src.x * normal.x + ray_src.y * normal.y + ray_src.z * normal.z + normal.w;

            movss        xmm7, dword ptr [esi]
    this.normal.z        ;
            mulss        xmm7, dword ptr ray_src.z                ;
            movss        xmm0, dword ptr [esi]
    this.normal.y        ;
            mulss        xmm0, dword ptr ray_src.y                ;
            addss        xmm7, xmm0                                ;
            movss        xmm0, dword ptr [esi]
    this.normal.x        ;
            mulss        xmm0, dword ptr ray_src.x                ;
            addss        xmm7, xmm0                                ;
            addss        xmm7, dword ptr [esi]
    this.normal.w        ;

    163  :     t_near = ray->t_near;

            movss        xmm0, dword ptr [ebx]e_Ray.t_near        ;

    165  :     if( t <= t_near * dot_nd )

            mulss        xmm0, xmm1                                ;
            comiss        xmm0, xmm7                                ;
            movss        dword ptr t, xmm7                        ;

    166  :         return false;

            jae            RETURN_FALSE                            ;
     
    168  :     t_far = MIN( ray->t_far, state->t );

            movss        xmm0, dword ptr [edi]e_RayState.t        ;
            comiss        xmm0, dword ptr [ebx]e_Ray.t_far        ;
            jbe            CASE_BELOW                                ;
            movss        xmm0, dword ptr [ebx]e_Ray.t_far        ;
            
    //jmp            FAR_TEST                                ;
    CASE_BELOW:
            
    //movss        xmm0, dword ptr [edi]e_RayState.t        ;
    //FAR_TEST:

    169  : 
    170  :     if( t >= t_far * dot_nd )

            mulss        xmm0, xmm1                                ;
            comiss        xmm7, xmm0                                ;

    171  :         return false;

            jae            RETURN_FALSE                            ;

    177  :     hit.arr[ projX ] = ray_src.arr[ projX ] * dot_nd + ray_dir.arr[ projX ] * t;

            movzx        eax, 
    byte ptr [esi]this.projX            ;
            add            eax, eax                                ;
            add            eax, eax                                ;
            movss        xmm0, dword ptr [ray_dir
    +eax]            ;
            movss        xmm2, dword ptr [ray_src
    +eax]            ;
            mulss        xmm0, xmm7                                ;
            mulss        xmm2, xmm1                                ;
            addss        xmm0, xmm2                                ;
            movss        dword ptr [hit
    +eax], xmm0                ;

    178  :     hit.arr[ projY ] = ray_src.arr[ projY ] * dot_nd + ray_dir.arr[ projY ] * t;

            movzx        ecx, 
    byte ptr [esi]this.projY            ;
            add            ecx, ecx                                ;
            add            ecx, ecx                                ;

    182  :     if( inited != TRUE )

            
    //cmp            byte ptr [esi]this.inited, 1            ;
            movss        xmm0, dword ptr [ray_dir+ecx]            ;
            movss        xmm2, dword ptr [ray_src
    +ecx]            ;
            mulss        xmm0, xmm7                                ;
            mulss        xmm2, xmm1                                ;
            addss        xmm0, xmm2                                ;
            movss        dword ptr [hit
    +ecx], xmm0                ;
            
    //je            BARY_TEST                                ;

    183  :         prepare_intersect();

            
    //call        prepare_intersect                        ;

    //BARY_TEST:

    187  :     bary.x = hit.arr[ projX ] * la.x + hit.arr[ projY ] * la.y + la.z * dot_nd;

            movss        xmm6, dword ptr [esi]
    this.la.y            ;
            mulss        xmm6, dword ptr [hit
    +ecx]                ;
            movss        xmm0, dword ptr [esi]
    this.la.z            ;
            lea            ecx, dword ptr [hit
    +ecx]                ;
            mulss        xmm0, xmm1                                ;
            addss        xmm6, xmm0                                ;
            movss        xmm0, dword ptr [esi]
    this.la.x            ;
            mulss        xmm0, dword ptr [hit
    +eax]                ;
            lea            eax, dword ptr [hit
    +eax]                ;
            addss        xmm6, xmm0                                ;
     
    189  :     if( bary.x < 0.0f || bary.x > dot_nd )

            comiss        xmm3, xmm6                                ;
            ja            RETURN_FALSE                            ;
            comiss        xmm6, xmm1                                ;
            ja            RETURN_FALSE                            ;
     
    192  :     bary.y = hit.arr[ projX ] * lb.x + hit.arr[ projY ] * lb.y + lb.z * dot_nd;

            movss        xmm5, dword ptr [esi]
    this.lb.y            ;
            mulss        xmm5, dword ptr [ecx]                    ;
            movss        xmm0, dword ptr [esi]
    this.lb.z            ;
            mulss        xmm0, xmm1                                ;
            addss        xmm5, xmm0                                ;
            movss        xmm0, dword ptr [esi]
    this.lb.x            ;
            mulss        xmm0, dword ptr [eax]                    ;
            addss        xmm5, xmm0                                ;
     
    194  :     if( bary.y < 0.0f || bary.y > dot_nd )

            comiss        xmm3, xmm5                                ;
            ja            RETURN_FALSE                            ;
            comiss        xmm5, xmm1                                ;
            ja            RETURN_FALSE                            ;

    197  :     bary.z = dot_nd - bary.x - bary.y;

            movaps        xmm4, xmm1                                ;
            subss        xmm4, xmm6                                ;
            subss        xmm4, xmm5                                ;
     
    199  :     if( bary.z < 0.0f || bary.z > dot_nd )

            comiss        xmm3, xmm4                                ;
            ja            RETURN_FALSE                            ;
            comiss        xmm4, xmm1                                ;
            ja            RETURN_FALSE                            ;

            movss        dword ptr bary.x, xmm6                    ;
            movss        dword ptr bary.y, xmm5                    ;
            movss        dword ptr bary.z, xmm4                    ;

        }
        //    __asm
  • 相关阅读:
    Seafile开源私有云自定义首页Logo图片
    启动seafile报错Error happened during creating seafile admin.
    jupyter的安装和使用(python3版)
    C#学习资料
    服务编排-以docker-swarm为例讲解
    docker swarm架构图
    VMware中安装centos7
    js获取数据:类似xpath
    博客园备份python程序
    解决docker中jenkins运行磁盘满的问题
  • 原文地址:https://www.cnblogs.com/len3d/p/817956.html
Copyright © 2020-2023  润新知