Subversion Repositories Kolibri OS

Rev

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