Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;=========================================================================
  2. detect_chunks:
  3. ; make pivot table, sort, remove unused vertices, find chunks...
  4. ; in  - some global variables
  5. ; out:
  6. ;      ebx - chunks list ptr, every chunk as word
  7. ;      ecx - chunks number
  8. ;      esi - tri_ch    ; vertices with triangles list
  9. ;      edi - t_ptr     ; pointers to tri_ch list
  10.  
  11.     push ebp
  12.     mov  ebp,esp
  13.     sub  esp,60
  14.  
  15.  
  16.    .tri_ch         equ  dword[ebp-4]    ; tri chunks list ptr
  17.    .chunks         equ  dword[ebp-8]    ; chunks ptreach tri chunk No. as word
  18.    .endt           equ  dword[ebp-12]   ;
  19.    .t_ptr          equ  dword[ebp-16]   ; pointers list
  20.    .tri_ch1        equ  dword[ebp-20]   ;
  21.    .up             equ  dword[ebp-24]   ; upload ptr
  22.    .chmr           equ  dword[ebp-28]   ; bit mark list if tri stored
  23.    .str            equ  dword[ebp-32]   ; store ptr
  24.    .ltch1          equ  dword[ebp-36]   ; end of tri_ch1 ptr
  25.    .ch_cnt         equ  dword[ebp-40]
  26.    .cntt           equ  dword[ebp-44]
  27.    .cc             equ  dword[ebp-48]
  28.    .lsparam        equ  dword[ebp-52]
  29.    .fix_mark       equ  dword[ebp-56]
  30.    .endVptr        equ  dword[ebp-60]
  31.  
  32.    ; some triangles have repeated indices of vertices
  33.    ; check and remove such triangles
  34.    call    remove_dead_tri
  35.  
  36.    mov     ecx,[triangles_count_var]
  37.    shl     ecx,3
  38.    lea     ecx,[ecx*3]
  39.    add     ecx,100
  40.    mov     eax,68
  41.    mov     ebx,12
  42.    int     0x40
  43.    mov     .tri_ch,eax
  44.  
  45.  
  46.    mov     ecx,[triangles_count_var]
  47.    imul    ecx,[i12]
  48.    add     ecx,32
  49.    mov     eax,68
  50.    mov     ebx,12
  51.    int     0x40
  52.    mov     .tri_ch1,eax
  53.  
  54.    mov     ecx,[points_count_var]
  55.    shl     ecx,2
  56.    add     ecx,1120
  57.    mov     eax,68
  58.    mov     ebx,12
  59.    int     0x40
  60.    mov     .t_ptr,eax
  61.  
  62.    mov     ecx,[triangles_count_var]
  63.    shl     ecx,1
  64.    add     ecx,20
  65.    mov     eax,68
  66.    mov     ebx,12
  67.    int     0x40
  68.    mov     .chunks,eax
  69.  
  70.    mov     ecx,[triangles_count_var]
  71.    shr     ecx,3
  72.    add     ecx,20
  73.    mov     eax,68
  74.    mov     ebx,12
  75.    int     0x40
  76.    mov     .chmr,eax     ; chunks mark if bit is set - tri was used
  77.  
  78.    mov     edi,eax
  79.    pxor    xmm0,xmm0
  80.    mov     ecx,[triangles_count_var]
  81.    shr     ecx,7
  82.    inc     ecx
  83.  @@:
  84.    movdqa  [edi],xmm0
  85.    add     edi,16
  86.    loop    @b
  87.  
  88.  
  89.   mov      eax,[points_count_var]
  90.   imul     eax,[i12]
  91.   add      eax,[points_ptr]
  92.   mov      .endVptr,eax
  93.  
  94. ; make pivot table
  95.  
  96.    mov       edi,.tri_ch
  97.    mov       esi,[triangles_ptr]
  98.    xor       ecx,ecx
  99.   @@:
  100.    movd      xmm1,ecx
  101.    movq      xmm0,[esi]
  102.    pshufd    xmm1,xmm1,0
  103.    movd      xmm2,[esi+8]
  104.    punpckldq xmm0,xmm1
  105.    punpckldq xmm2,xmm1
  106.    movdqu   [edi],xmm0
  107.    movq     [edi+16],xmm2
  108.    add       esi,12
  109.    add       edi,24
  110.    inc       ecx
  111.    cmp       ecx,[triangles_count_var]
  112.    jnz       @b
  113.  
  114. ;sort
  115.  
  116.    mov    ebx,.tri_ch
  117.    mov    ecx,[triangles_count_var]
  118.    lea    ecx,[ecx*3]
  119.  
  120.    mov    esi,ecx
  121.    shl    esi,3
  122.    add    esi,ebx
  123.    mov   .endt,esi
  124.  
  125.  .ccc:                                ; ebx    - vert index
  126.    mov    eax,[ebx+8]                 ; ebx+4  - tri index
  127.    cmp    eax,[ebx]
  128.    jge    .g
  129.    movq   xmm0,[ebx+8]
  130.    push   ebx
  131.  .c:
  132.    cmp    ebx,esi
  133.    jae    .done
  134.    cmp    ebx,.tri_ch
  135.    jb     .done
  136.    cmp    eax,[ebx]
  137.    jae    .done
  138.    movq   xmm7,[ebx]
  139.    movq   [ebx+8],xmm7
  140.    sub    ebx,8
  141.    jnc    .c
  142.    add    ebx,8
  143.  .done:
  144.    movq   [ebx+8],xmm0
  145.  .p:
  146.    pop    ebx
  147.  .g:
  148.    add    ebx,8
  149.    dec    ecx
  150.    cmp    ecx,1
  151.    jnz    .ccc
  152.  
  153.  
  154.  
  155.  
  156.  
  157.   mov    ecx,[points_count_var]
  158.   mov    esi,.tri_ch
  159.   dec    ecx
  160.  .ptC:
  161.   mov     eax,[esi]
  162.   add     esi,8
  163.  .ptCff:
  164.   cmp     esi,.endt
  165.   jae     .dnC
  166.   cmp    eax,[esi]
  167.   je     @f
  168.   lea    ebx,[eax+1]
  169.   cmp    ebx,[esi]
  170.   jne    .movt
  171.   dec    ecx
  172.   jz    .dnC            ; check done
  173.  @@:
  174.   jmp   .ptC
  175.  
  176. ;  jmp  .dnC
  177.  
  178.  .movt:
  179.  
  180.   movd    xmm5,esi
  181.   movd    xmm7,ebx
  182.   mov     edi,[esi]
  183.   sub     edi,ebx
  184.   movd    xmm6,edi
  185.  
  186.  @@:
  187.   cmp     esi,.endt
  188.   jnb     @f
  189.   sub     [esi],edi    ; fix .tri_ch pivot table list
  190.   add     esi,8
  191.   jmp     @b
  192.  @@:
  193.  
  194.  
  195.   ;shrink vert
  196.   lea     ebx,[ebx*3]
  197.   shl     ebx,2
  198.   add     ebx,[points_ptr]
  199.   imul    edi,[i12]
  200.   add     edi,ebx
  201.  
  202.   cmp     edi,.endVptr           ; fix points_r  list
  203.   ja      .dnV
  204.  @@:
  205.   movq    xmm0,[edi]
  206.   movd    xmm1,[edi+8]
  207.   movq    [ebx],xmm0
  208.   movd    [ebx+8],xmm1
  209.   add     edi,12
  210.   add     ebx,12
  211.   cmp     edi,.endVptr           ; fix point_r  list
  212.   jna     @b
  213.  
  214.  .dnV:
  215.  
  216. ; recalc tri  all indices above ebx - sub edi
  217.   push   ecx
  218.  
  219.   mov    esi,[triangles_ptr]
  220.   mov    ecx,[triangles_count_var]
  221.   lea    ecx,[ecx*3]
  222.   movd   edi,xmm6
  223.   movd   ebx,xmm7
  224.  .agT:
  225.   cmp    [esi],ebx
  226.   jb     @f
  227.   sub     [esi],edi
  228.  @@:
  229.   add   esi,4
  230.   loop  .agT
  231.  
  232.   pop   ecx
  233.  
  234.   movd  esi,xmm5
  235.  
  236.   sub    [points_count_var],edi
  237.  
  238.   dec   ecx
  239.  
  240.   jmp   .ptCff           ; again check sth found
  241.  
  242.  
  243.  .dnC:      ; check done
  244.  
  245.  
  246.  
  247.   .do_ch:
  248.  
  249.  
  250. ;make t_ptr  - table with pointers/adresses
  251.  
  252.  
  253.   mov    ecx,[points_count_var]
  254.   mov    esi,.tri_ch
  255.   mov    edi,.t_ptr
  256.   mov    ebx,ecx
  257.  
  258.   mov    [edi],esi
  259.   add    edi,4
  260.   dec    ecx
  261.   jz     .dn
  262.  .pt:
  263.   mov    eax,[esi]        ; [esi]   - vert ind
  264.   add    esi,8
  265.   cmp    eax,[esi]        ; [esi+4] - tri ind
  266.   je     @f
  267.   mov    [edi],esi
  268.   add    edi,4
  269.   dec    ecx
  270.   jz     .dn
  271.  @@:
  272.   cmp   esi,.endt
  273.   jb    .pt
  274.  
  275.  
  276.  .dn:
  277.  
  278.  
  279.  ; each dword position in .t_ptr list - adress of corresponding
  280.  ; triangles indices, each triangles from such index contains this
  281.  ; vertice
  282.  
  283.  
  284.         mov     eax,[triangles_count_var]
  285.         mov     .cntt,eax   ; temp help cnt
  286.         xor     ecx,ecx
  287.         mov     .cc,ecx
  288.         mov     esi,[triangles_ptr]
  289.         mov     edi,.tri_ch1
  290.         imul    eax,[i12]
  291.         add     eax,edi
  292.         mov     .ltch1,eax    ; last
  293.  
  294.         mov     .up,esi
  295.         mov     .str,edi
  296.     .lb1:                     ; nx chunk
  297.         cmp     edi,.ltch1
  298.         jnb     .endl
  299.         mov     edi,.tri_ch1
  300.         mov     .str,edi
  301.         mov     eax,.cc
  302.         mov     edx,.cc
  303.         inc     .cc
  304.         cmp     edx,[triangles_count_var]
  305.         jz      .endl
  306.         shr     eax,3
  307.         and     edx,111b
  308.         add     eax,.chmr
  309.  
  310.         xor     ebx,ebx
  311.         bt      [eax],edx           ; mark
  312.         jc      @f                  ; tri was stored
  313.         inc     ecx
  314.         or      ebx,1b
  315.         mov     esi,.up
  316.         movdqu  xmm0,[esi]
  317.         movdqu  [edi],xmm0
  318.         add     .str,12
  319.       @@:
  320.         add     .up,12
  321.         or      ebx,ebx
  322.         jz      .lb1
  323.  
  324.     .lb2:
  325.         mov     eax,[edi]
  326.         mov     edx,[edi] ; edx - vert ind
  327.         shl     eax,2
  328.         add     eax,.t_ptr
  329.         mov     eax,[eax]           ; [eax] -   t ptr
  330.         or      eax,eax
  331.         jz      .endl
  332.     .nxt:
  333.  
  334.         mov     esi,[eax+4]
  335.         mov     ebx,[eax+4]
  336.         shr     esi,3
  337.         and     ebx,111b
  338.         add     esi,.chmr
  339.         bts     [esi],ebx           ; mark
  340.         jc      @f                  ; tri was stored
  341.         dec     .cntt
  342.         je      .endl
  343.         mov     esi,[eax+4]         ; [eax+4] - tri ind
  344.         add     esi,esi
  345.         add     esi,.chunks
  346.         mov     [esi],cx
  347.         mov     esi,[eax+4]
  348.  
  349.         imul    esi,[i12]
  350.         add     esi,[triangles_ptr]
  351.         movups  xmm0,[esi]
  352.         mov     esi,.str
  353.         movups  [esi],xmm0
  354.         add     .str,12
  355.       @@:
  356.         add     eax,8
  357.         cmp     edx,[eax]
  358.         je      .nxt
  359.         add     edi,4
  360.  
  361.         cmp     edi,.str
  362.         jne     .lb2
  363.         jmp     .lb1
  364.  
  365.     .endl:
  366.  
  367.         mov     .ch_cnt,ecx
  368.  
  369.  
  370.   .end:
  371.  
  372.  
  373.  
  374. ;   mov     eax,68
  375. ;   mov     ebx,13
  376. ;   mov     ecx,.t_ptr
  377. ;   int     0x40
  378.  
  379. ;   mov     eax,68
  380. ;   mov     ebx,13
  381. ;   mov     ecx,.tri_ch
  382. ;   int     0x40
  383.  
  384.    mov     eax,68
  385.    mov     ebx,13
  386.    mov     ecx,.tri_ch1
  387.    int     0x40
  388.  
  389.    mov     eax,68
  390.    mov     ebx,13
  391.    mov     ecx,.chmr
  392.    int     0x40
  393. ; for now free mem - cunks list - unused
  394.  
  395. ;   mov     eax,68
  396. ;   mov     ebx,13
  397. ;   mov     ecx,.chunks
  398. ;   int     0x40
  399.  
  400.  
  401.  
  402. ;   mov    ebx,.chunks
  403.    mov    ecx,.ch_cnt
  404.  
  405.    mov  esi,.tri_ch
  406.    mov  edi,.t_ptr
  407.  
  408.  
  409.    mov    esp,ebp
  410.    pop    ebp
  411. ret
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.