~ubuntu-branches/ubuntu/trusty/mupen64plus-video-rice/trusty

« back to all changes in this revision

Viewing changes to src/FrameBuffer.cpp

  • Committer: Package Import Robot
  • Author(s): Sven Eckelmann
  • Date: 2013-07-05 22:53:25 UTC
  • mfrom: (1.2.2) (3.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130705225325-k0fbb2m44xnrju66
Tags: 2.0-1
* New Upstream Version
* Upload to unstable
* debian/control:
  - Build-Depend on debhelper 9.20130604 for support of parameters when
    detecting targets in dh_auto_*
* debian/rules:
  - Work around new debhelper 9.20130624 dh_auto_{clean,test} behavior
    which is causing a FTBFS by adding an explicit
    override_dh_auto_{clean,test} rule
* debian/watch:
  - Verify new upstream versions using GPG key 954F81B094AA5BB226F5

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
3) This is slow due to the reading process, not the writing
40
40
*/
41
41
 
42
 
 
43
 
 
44
42
RecentCIInfo g_RecentCIInfo[5];
45
43
RecentCIInfo *g_uRecentCIInfoPtrs[5] =
46
44
{
116
114
 
117
115
    RecentCIInfo *temp;
118
116
 
119
 
        int i;
 
117
    int i;
120
118
    for( i=1; i<numOfRecentCIInfos; i++ )
121
119
    {
122
120
        if( ciinfo.dwAddr == g_uRecentCIInfoPtrs[i]->dwAddr )
169
167
{
170
168
    uint32 viwidth = *g_GraphicsInfo.VI_WIDTH_REG;
171
169
    addr &= (g_dwRamSize-1);
172
 
        int i;
 
170
    
 
171
    int i;
173
172
    for( i=0; i<numOfRecentCIInfos; i++ )
174
173
    {
175
174
        if( g_uRecentCIInfoPtrs[i]->dwAddr+2*viwidth == addr )
221
220
bool FrameBufferManager::HasAddrBeenDisplayed(uint32 addr, uint32 width)
222
221
{
223
222
    addr &= (g_dwRamSize-1);
224
 
        int i;
 
223
    
 
224
    int i;
225
225
    for( i=0; i<numOfRecentCIInfos; i++ )
226
226
    {
227
227
        if( g_uRecentCIInfoPtrs[i]->dwAddr == 0 )
381
381
        return false;
382
382
    }
383
383
    else
 
384
    {
384
385
        return true;
 
386
    }
385
387
 
386
388
 
387
389
    if( !foundSetCImg )
425
427
        DEBUGGER_IF_DUMP((logTextureBuffer&&r>1),TRACE2("Hit old back buffer at %08X, size=0x%X", addr, memsize));
426
428
 
427
429
        SaveBackBuffer(r, NULL, true);
428
 
    }       
 
430
    }
429
431
 
430
432
    return r;
431
433
}
482
484
    uint32 dwLeft = dwXL;
483
485
    uint32 dwTop = dwYL;
484
486
 
485
 
    dwWidth = min(dwWidth,maxW-dwLeft);
 
487
    dwWidth = min(dwWidth, maxW-dwLeft);
486
488
    dwHeight = min(dwHeight, maxH-dwTop);
487
 
    if( maxH <= dwTop ) return;
 
489
    
 
490
    if( maxH <= dwTop )
 
491
        return;
488
492
 
489
493
    for (uint32 y = 0; y < dwHeight; y++)
490
494
    {
584
588
        uint32 y = 0;
585
589
        while (y < height)
586
590
        {
587
 
          uint32 x = 0;
588
 
          while (x < realWidthInDWORD)
589
 
          {
590
 
            dwAsmCRC = (dwAsmCRC << 4) + ((dwAsmCRC >> 28) & 15);
591
 
            dwAsmCRC += pStart[x];
592
 
            x += xinc;
593
 
            dwAsmCRC += x;
594
 
          }
595
 
          dwAsmCRC ^= y;
596
 
          y += yinc;
597
 
          pStart += pitch;
 
591
            uint32 x = 0;
 
592
            while (x < realWidthInDWORD)
 
593
            {
 
594
                dwAsmCRC = (dwAsmCRC << 4) + ((dwAsmCRC >> 28) & 15);
 
595
                dwAsmCRC += pStart[x];
 
596
                x += xinc;
 
597
                dwAsmCRC += x;
 
598
            }
 
599
            dwAsmCRC ^= y;
 
600
            y += yinc;
 
601
            pStart += pitch;
598
602
        }
599
 
 
600
603
    }
601
604
    else
602
605
    {
603
 
        try{
 
606
        try
 
607
        {
604
608
            dwAsmdwBytesPerLine = ((width<<size)+1)/2;
605
609
 
606
610
            pAsmStart = (uint8*)(pPhysicalAddress);
609
613
            dwAsmHeight = height - 1;
610
614
            dwAsmPitch = pitchInBytes;
611
615
 
612
 
#if !defined(__GNUC__) && !defined(NO_ASM)
 
616
#if defined(NO_ASM)
 
617
            uint32 pitch = pitchInBytes>>2;
 
618
            uint32* pStart = (uint32*)pPhysicalAddress;
 
619
            pStart += (top * pitch) + (((left<<size)+1)>>3);
 
620
 
 
621
            int y = dwAsmHeight;
 
622
 
 
623
            while(y >= 0)
 
624
            {
 
625
                uint32 esi = 0;
 
626
                int x = dwAsmdwBytesPerLine - 4;
 
627
                while(x >= 0)
 
628
                {
 
629
                    esi = *(uint32*)(pAsmStart + x);
 
630
                    esi ^= x;
 
631
 
 
632
                    dwAsmCRC = (dwAsmCRC << 4) + ((dwAsmCRC >> 28) & 15);
 
633
                    dwAsmCRC += esi;
 
634
                    x-=4;
 
635
                }
 
636
                esi ^= y;
 
637
                dwAsmCRC += esi;
 
638
                pAsmStart += dwAsmPitch;
 
639
                y--;
 
640
            }
 
641
 
 
642
#elif !defined(__GNUC__) // !defined(NO_ASM)
613
643
            __asm 
614
644
            {
615
645
                push eax
618
648
                push edx
619
649
                push esi
620
650
 
621
 
                mov ecx, pAsmStart; // = pStart
622
 
                mov edx, 0          // The CRC
623
 
                mov eax, dwAsmHeight    // = y
 
651
                mov ecx, pAsmStart;             // = pStart
 
652
                mov edx, 0                      // The CRC
 
653
                mov eax, dwAsmHeight            // = y
624
654
l2:             mov ebx, dwAsmdwBytesPerLine    // = x
625
655
                sub ebx, 4
626
656
l1:             mov esi, [ecx+ebx]
643
673
                pop ebx
644
674
                pop eax
645
675
            }
646
 
#elif defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM)
 
676
#elif defined(__x86_64__) // defined(__GNUC__) && !defined(NO_ASM)
647
677
        asm volatile(" xorl          %k2,      %k2           \n"
648
678
                     " movslq        %k4,      %q4           \n"
649
679
                     "0:                                     \n"
665
695
                     : "m"(dwAsmdwBytesPerLine), "r"(dwAsmPitch)
666
696
                     : "%rbx", "%rax", "memory", "cc"
667
697
                     );
668
 
#elif !defined(NO_ASM)
669
 
# if !defined(__PIC__)
 
698
#elif !defined(__PIC__) // !defined(__x86_64__) && defined(__GNUC__) && !defined(NO_ASM)
670
699
           asm volatile("pusha                        \n"
671
 
                "mov    %[pAsmStart], %%ecx           \n"  // = pStart
672
 
                "mov    $0, %%edx                     \n"          // The CRC
673
 
                "mov    %[dwAsmHeight], %%eax         \n"  // = y
 
700
                "mov    %[pAsmStart], %%ecx           \n" // = pStart
 
701
                "mov    $0, %%edx                     \n" // The CRC
 
702
                "mov    %[dwAsmHeight], %%eax         \n" // = y
674
703
                "0:                                   \n" //l2:
675
 
                "mov    %[dwAsmdwBytesPerLine], %%ebx \n"  // = x
 
704
                "mov    %[dwAsmdwBytesPerLine], %%ebx \n" // = x
676
705
                "sub    $4, %%ebx                     \n"
677
706
                "1:                                   \n" //l1:
678
707
                "mov    (%%ecx,%%ebx), %%esi          \n"
693
722
                : [dwAsmdwBytesPerLine]"m"(dwAsmdwBytesPerLine), [dwAsmPitch]"m"(dwAsmPitch)
694
723
                : "memory", "cc"
695
724
                );
696
 
# else // defined(__PIC__)
 
725
#else // defined(__PIC__) && !defined(__x86_64__) && defined(__GNUC__) && !defined(NO_ASM)
697
726
           unsigned int saveEBX;
698
727
           unsigned int saveEAX;
699
728
           unsigned int saveECX;
708
737
                "mov    %%ecx, %7                  \n"
709
738
                "mov    %%edx, %8                  \n"
710
739
                "mov    %%esi, %9                  \n"
711
 
                "mov    %0, %%ecx                  \n"  // = pStart
712
 
                "mov    $0, %%edx                  \n"          // The CRC
713
 
                "mov    %1, %%eax                  \n"  // = y
 
740
                "mov    %0, %%ecx                  \n" // = pStart
 
741
                "mov    $0, %%edx                  \n" // The CRC
 
742
                "mov    %1, %%eax                  \n" // = y
714
743
                "0:                                \n" //l2:
715
 
                "mov    %3, %%ebx                  \n"  // = x
 
744
                "mov    %3, %%ebx                  \n" // = x
716
745
                "sub    $4, %%ebx                  \n"
717
746
                "1:                                \n" //l1:
718
747
                "mov    (%%ecx,%%ebx), %%esi       \n"
739
768
                : "memory", "cc"
740
769
                );
741
770
           dwAsmCRC = asmCRC;
742
 
# endif // defined(__PIC__)
743
771
#endif
744
772
        }
745
773
        catch(...)
1131
1159
                info.CI_Info.dwWidth == CIinfo.dwWidth &&
1132
1160
                info.CI_Info.dwFormat == CIinfo.dwFormat &&
1133
1161
                info.N64Height == height 
1134
 
                && info.CI_Info.dwAddr == CIinfo.dwAddr 
1135
1162
                )
1136
1163
            {
1137
1164
                // This is the same texture at the same address
1270
1297
 
1271
1298
int FrameBufferManager::SetBackBufferAsRenderTexture(SetImgInfo &CIinfo, int ciInfoIdx)
1272
1299
{
1273
 
/* MUDLORD:
1274
 
OK, heres the drill!
1275
 
* We  set the graphics card's back buffer's contents as a render_texure
1276
 
* This is done due to how the current framebuffer implementation detects
1277
 
  changes to the backbuffer memory pointer and then we do a texture
1278
 
  copy. This might be slow since it doesnt use hardware auxillary buffers*/
1279
 
         
 
1300
    // MUDLORD:
 
1301
    // OK, heres the drill!
 
1302
    //
 
1303
    // We  set the graphics card's back buffer's contents as a render_texure
 
1304
    // This is done due to how the current framebuffer implementation detects
 
1305
    // changes to the backbuffer memory pointer and then we do a texture
 
1306
    // copy. This might be slow since it doesnt use hardware auxillary buffers
1280
1307
 
1281
1308
    RenderTextureInfo tempRenderTextureInfo;
1282
1309
 
1328
1355
 
1329
1356
void FrameBufferManager::CloseRenderTexture(bool toSave)
1330
1357
{
1331
 
    if( m_curRenderTextureIndex < 0 )   return;
 
1358
    if( m_curRenderTextureIndex < 0 )
 
1359
        return;
1332
1360
 
1333
1361
    status.bHandleN64RenderTexture = false;
1334
1362
    if( status.bDirectWriteIntoRDRAM )
1335
1363
    {
 
1364
        // TODO: Implement
1336
1365
    }
1337
1366
    else 
1338
1367
    {
1415
1444
}
1416
1445
 
1417
1446
 
1418
 
//copies backbuffer to N64 framebuffer by notification by emu core
 
1447
// Copies backbuffer to N64 framebuffer by notification by emu core
1419
1448
// **buggy**
1420
1449
void FrameBufferManager::CopyBackToFrameBufferIfReadByCPU(uint32 addr)
1421
1450
{
1429
1458
        TRACE1("Copy back for CI Addr=%08X", info->dwAddr);
1430
1459
    }
1431
1460
}
1432
 
//we do this checks to see if a render_texture operation is occuring...
 
1461
 
 
1462
// We do these checks to see if a render_texture operation is occurring...
1433
1463
void FrameBufferManager::CheckRenderTextureCRCInRDRAM(void)
1434
1464
{
1435
1465
    for( int i=0; i<numOfTxtBufInfos; i++ )
1459
1489
    }
1460
1490
}
1461
1491
 
1462
 
//check render_texture memory addresses
 
1492
// Check render_texture memory addresses
1463
1493
int FrameBufferManager::CheckAddrInRenderTextures(uint32 addr, bool checkcrc)
1464
1494
{
1465
1495
    for( int i=0; i<numOfTxtBufInfos; i++ )
1504
1534
    return -1;
1505
1535
}
1506
1536
 
1507
 
//load texture from render_texture buffer
 
1537
// Load texture from render_texture buffer
1508
1538
void FrameBufferManager::LoadTextureFromRenderTexture(TxtrCacheEntry* pEntry, int infoIdx)
1509
1539
{
1510
1540
    if( infoIdx < 0 || infoIdx >= numOfTxtBufInfos )
1550
1580
    return CalculateRDRAMCRC(pAddr, 0, 0, info.N64Width, height, info.CI_Info.dwSize, pitch);
1551
1581
}
1552
1582
 
1553
 
//activates texture buffer for drawing
 
1583
// Activates texture buffer for drawing
1554
1584
void FrameBufferManager::ActiveTextureBuffer(void)
1555
1585
{
1556
1586
    status.bCIBufferIsRendered = true;
1659
1689
 
1660
1690
#define SAVE_CI {g_CI.dwAddr = newCI.dwAddr;g_CI.dwFormat = newCI.dwFormat;g_CI.dwSize = newCI.dwSize;g_CI.dwWidth = newCI.dwWidth;g_CI.bpl=newCI.bpl;}
1661
1691
 
1662
 
//sets CI address for framebuffer copies
 
1692
// Sets CI address for framebuffer copies
1663
1693
void FrameBufferManager::Set_CI_addr(SetImgInfo &newCI)
1664
1694
{
1665
1695
    bool wasDrawingTextureBuffer = status.bN64IsDrawingTextureBuffer;
1799
1829
 
1800
1830
void FrameBufferManager::StoreRenderTextureToRDRAM(int infoIdx)
1801
1831
{
1802
 
    if( !frameBufferOptions.bRenderTextureWriteBack )   return;
 
1832
    if( !frameBufferOptions.bRenderTextureWriteBack )
 
1833
        return;
1803
1834
 
1804
1835
    if( infoIdx < 0 )
1805
1836
        infoIdx = m_lastTextureBufferIndex;
1821
1852
void FrameBufferManager::CopyBufferToRDRAM(uint32 addr, uint32 fmt, uint32 siz, uint32 width, uint32 height, uint32 bufWidth, uint32 bufHeight, uint32 startaddr, uint32 memsize, uint32 pitch, TextureFmt bufFmt, void *buffer, uint32 bufPitch)
1822
1853
{
1823
1854
    uint32 startline=0;
1824
 
    if( startaddr == 0xFFFFFFFF )   startaddr = addr;
 
1855
    
 
1856
    if( startaddr == 0xFFFFFFFF )
 
1857
        startaddr = addr;
1825
1858
 
1826
1859
    startline = (startaddr-addr)/siz/pitch;
1827
1860
    if( startline >= height )
1888
1921
 
1889
1922
                    // Liner
1890
1923
                    *(pD+(j^1)) = ConvertRGBATo555( r, g, b, a);
1891
 
 
1892
1924
                }
1893
1925
            }
1894
1926
        }
1914
1946
                {
1915
1947
                    int pos = 4*(j*bufWidth/width);
1916
1948
                    tempword = ConvertRGBATo555((pS[pos+2]),        // Red
1917
 
                        (pS[pos+1]),        // G
1918
 
                        (pS[pos+0]),        // B
1919
 
                        (pS[pos+3]));       // Alpha
 
1949
                                                (pS[pos+1]),        // Green
 
1950
                                                (pS[pos+0]),        // Blue
 
1951
                                                (pS[pos+3]));       // Alpha
 
1952
                    
1920
1953
                    //*pD = CIFindIndex(tempword);
1921
1954
                    *(pD+(j^3)) = RevTlutTable[tempword];
1922
1955
                }
1953
1986
 
1954
1987
                    // Liner
1955
1988
                    *(pD+(j^3)) = (uint8)((r+b+g)/3);
1956
 
 
1957
1989
                }
1958
1990
            }
1959
1991
        }
1995
2027
 
1996
2028
 
1997
2029
 
1998
 
//Saves backbuffer
1999
 
//this is the core to the current framebuffer code
2000
 
//We need to save backbuffer when changed by framebuffer
2001
 
//so that we can use it for framebuffer effects
 
2030
// Saves backbuffer
 
2031
// this is the core to the current framebuffer code
 
2032
// We need to save backbuffer when changed by framebuffer
 
2033
// so that we can use it for framebuffer effects
2002
2034
void FrameBufferManager::SaveBackBuffer(int ciInfoIdx, RECT* pSrcRect, bool forceToSaveToRDRAM)
2003
2035
{
2004
2036
    RecentCIInfo &ciInfo = *g_uRecentCIInfoPtrs[ciInfoIdx];