VirtualBox

Ignore:
Timestamp:
Nov 8, 2011 4:46:46 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
74772
Message:

wddm/3d: proper dealing with compressed formats

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/common/wddm/VBoxMPIf.h

    r39160 r39245  
    483483
    484484/* tooling */
    485 DECLINLINE(UINT) vboxWddmCalcBitsPerPixel(D3DDDIFORMAT format)
    486 {
    487     switch (format)
     485DECLINLINE(UINT) vboxWddmCalcBitsPerPixel(D3DDDIFORMAT enmFormat)
     486{
     487    switch (enmFormat)
    488488    {
    489489        case D3DDDIFMT_R8G8B8:
     
    563563}
    564564
    565 DECLINLINE(uint32_t) vboxWddmFormatToFourcc(D3DDDIFORMAT format)
    566 {
    567     uint32_t uFormat = (uint32_t)format;
     565DECLINLINE(uint32_t) vboxWddmFormatToFourcc(D3DDDIFORMAT enmFormat)
     566{
     567    uint32_t uFormat = (uint32_t)enmFormat;
    568568    /* assume that in case both four bytes are non-zero, this is a fourcc */
    569     if ((format & 0xff000000)
    570             && (format & 0x00ff0000)
    571             && (format & 0x0000ff00)
    572             && (format & 0x000000ff)
     569    if ((uFormat & 0xff000000)
     570            && (uFormat & 0x00ff0000)
     571            && (uFormat & 0x0000ff00)
     572            && (uFormat & 0x000000ff)
    573573            )
    574574        return uFormat;
     
    578578#define VBOXWDDM_ROUNDBOUND(_v, _b) (((_v) + ((_b) - 1)) & ~((_b) - 1))
    579579
    580 DECLINLINE(UINT) vboxWddmCalcPitch(UINT w, UINT bitsPerPixel)
    581 {
    582     UINT Pitch = bitsPerPixel * w;
    583     /* pitch is now in bits, translate in bytes */
    584     return VBOXWDDM_ROUNDBOUND(Pitch, 8) >> 3;
     580DECLINLINE(UINT) vboxWddmCalcOffXru(UINT w, D3DDDIFORMAT enmFormat)
     581{
     582    switch (enmFormat)
     583    {
     584        /* pitch for the DXT* (aka compressed) formats is the size in bytes of blocks that fill in an image width
     585         * i.e. each block decompressed into 4 x 4 pixels, so we have ((Width + 3) / 4) blocks for Width.
     586         * then each block has 64 bits (8 bytes) for DXT1 and 64+64 bits (16 bytes) for DXT2-DXT5, so.. : */
     587        case D3DDDIFMT_DXT1:
     588        {
     589            UINT Pitch = (w + 3) / 4; /* <- pitch size in blocks */
     590            Pitch *= 8;               /* <- pitch size in bytes */
     591            return Pitch;
     592        }
     593        case D3DDDIFMT_DXT2:
     594        case D3DDDIFMT_DXT3:
     595        case D3DDDIFMT_DXT4:
     596        case D3DDDIFMT_DXT5:
     597        {
     598            UINT Pitch = (w + 3) / 4; /* <- pitch size in blocks */
     599            Pitch *= 8;               /* <- pitch size in bytes */
     600            return Pitch;
     601        }
     602        default:
     603        {
     604            /* the default is just to calculate the pitch from bpp */
     605            UINT bpp = vboxWddmCalcBitsPerPixel(enmFormat);
     606            UINT Pitch = bpp * w;
     607            /* pitch is now in bits, translate in bytes */
     608            return VBOXWDDM_ROUNDBOUND(Pitch, 8) >> 3;
     609        }
     610    }
     611}
     612
     613DECLINLINE(UINT) vboxWddmCalcOffXrd(UINT w, D3DDDIFORMAT enmFormat)
     614{
     615    switch (enmFormat)
     616    {
     617        /* pitch for the DXT* (aka compressed) formats is the size in bytes of blocks that fill in an image width
     618         * i.e. each block decompressed into 4 x 4 pixels, so we have ((Width + 3) / 4) blocks for Width.
     619         * then each block has 64 bits (8 bytes) for DXT1 and 64+64 bits (16 bytes) for DXT2-DXT5, so.. : */
     620        case D3DDDIFMT_DXT1:
     621        {
     622            UINT Pitch = w / 4; /* <- pitch size in blocks */
     623            Pitch *= 8;         /* <- pitch size in bytes */
     624            return Pitch;
     625        }
     626        case D3DDDIFMT_DXT2:
     627        case D3DDDIFMT_DXT3:
     628        case D3DDDIFMT_DXT4:
     629        case D3DDDIFMT_DXT5:
     630        {
     631            UINT Pitch = w / 4; /* <- pitch size in blocks */
     632            Pitch *= 16;               /* <- pitch size in bytes */
     633            return Pitch;
     634        }
     635        default:
     636        {
     637            /* the default is just to calculate the pitch from bpp */
     638            UINT bpp = vboxWddmCalcBitsPerPixel(enmFormat);
     639            UINT Pitch = bpp * w;
     640            /* pitch is now in bits, translate in bytes */
     641            return Pitch >> 3;
     642        }
     643    }
     644}
     645
     646DECLINLINE(UINT) vboxWddmCalcHightPacking(D3DDDIFORMAT enmFormat)
     647{
     648    switch (enmFormat)
     649    {
     650        /* for the DXT* (aka compressed) formats each block is decompressed into 4 x 4 pixels,
     651         * so packing is 4
     652         */
     653        case D3DDDIFMT_DXT1:
     654        case D3DDDIFMT_DXT2:
     655        case D3DDDIFMT_DXT3:
     656        case D3DDDIFMT_DXT4:
     657        case D3DDDIFMT_DXT5:
     658            return 4;
     659        default:
     660            return 1;
     661    }
     662}
     663
     664DECLINLINE(UINT) vboxWddmCalcOffYru(UINT height, D3DDDIFORMAT enmFormat)
     665{
     666    UINT packing = vboxWddmCalcHightPacking(enmFormat);
     667    /* round it up */
     668    return (height + packing - 1) / packing;
     669}
     670
     671DECLINLINE(UINT) vboxWddmCalcOffYrd(UINT height, D3DDDIFORMAT enmFormat)
     672{
     673    UINT packing = vboxWddmCalcHightPacking(enmFormat);
     674    /* round it up */
     675    return height / packing;
     676}
     677
     678DECLINLINE(UINT) vboxWddmCalcPitch(UINT w, D3DDDIFORMAT enmFormat)
     679{
     680    return vboxWddmCalcOffXru(w, enmFormat);
     681}
     682
     683DECLINLINE(UINT) vboxWddmCalcWidthForPitch(UINT Pitch, D3DDDIFORMAT enmFormat)
     684{
     685    switch (enmFormat)
     686    {
     687        /* pitch for the DXT* (aka compressed) formats is the size in bytes of blocks that fill in an image width
     688         * i.e. each block decompressed into 4 x 4 pixels, so we have ((Width + 3) / 4) blocks for Width.
     689         * then each block has 64 bits (8 bytes) for DXT1 and 64+64 bits (16 bytes) for DXT2-DXT5, so.. : */
     690        case D3DDDIFMT_DXT1:
     691        {
     692            return (Pitch / 8) * 4;
     693        }
     694        case D3DDDIFMT_DXT2:
     695        case D3DDDIFMT_DXT3:
     696        case D3DDDIFMT_DXT4:
     697        case D3DDDIFMT_DXT5:
     698        {
     699            return (Pitch / 16) * 4;;
     700        }
     701        default:
     702        {
     703            /* the default is just to calculate it from bpp */
     704            UINT bpp = vboxWddmCalcBitsPerPixel(enmFormat);
     705            return (Pitch << 3) / bpp;
     706        }
     707    }
     708}
     709
     710DECLINLINE(UINT) vboxWddmCalcNumRows(UINT top, UINT bottom, D3DDDIFORMAT enmFormat)
     711{
     712    Assert(bottom > top);
     713    top = top ? vboxWddmCalcOffYrd(top, enmFormat) : 0; /* <- just to optimize it a bit */
     714    bottom = vboxWddmCalcOffYru(bottom, enmFormat);
     715    return bottom - top;
     716}
     717
     718DECLINLINE(UINT) vboxWddmCalcRowSize(UINT left, UINT right, D3DDDIFORMAT enmFormat)
     719{
     720    Assert(right > left);
     721    left = left ? vboxWddmCalcOffXrd(left, enmFormat) : 0; /* <- just to optimize it a bit */
     722    right = vboxWddmCalcOffXru(right, enmFormat);
     723    return right - left;
     724}
     725
     726DECLINLINE(UINT) vboxWddmCalcSize(UINT pitch, UINT height, D3DDDIFORMAT enmFormat)
     727{
     728    UINT cRows = vboxWddmCalcNumRows(0, height, enmFormat);
     729    return pitch * cRows;
     730}
     731
     732DECLINLINE(UINT) vboxWddmCalcOffXYrd(UINT x, UINT y, UINT pitch, D3DDDIFORMAT enmFormat)
     733{
     734    UINT offY = 0;
     735    if (y)
     736        offY = vboxWddmCalcSize(pitch, y, enmFormat);
     737
     738    return offY + vboxWddmCalcOffXrd(x, enmFormat);
    585739}
    586740
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette