diff --git a/DDrawCompat/D3dDdi/FormatInfo.cpp b/DDrawCompat/D3dDdi/FormatInfo.cpp index d48ae64..f1cf58a 100644 --- a/DDrawCompat/D3dDdi/FormatInfo.cpp +++ b/DDrawCompat/D3dDdi/FormatInfo.cpp @@ -1,7 +1,11 @@ +#include + #include namespace { + DDPIXELFORMAT getPixelFormat(const D3dDdi::FormatInfo& info); + struct ArgbColor { BYTE blue; @@ -10,85 +14,164 @@ namespace BYTE alpha; }; - struct RgbFormatInfo : D3dDdi::FormatInfo + struct FormatInfoBuilder : D3dDdi::FormatInfo { - RgbFormatInfo(BYTE unusedBitCount, BYTE alphaBitCount, BYTE redBitCount, BYTE greenBitCount, BYTE blueBitCount) - : FormatInfo(unusedBitCount, alphaBitCount, redBitCount, greenBitCount, blueBitCount) + void setComponent(D3dDdi::FormatInfo::Component& component, BYTE bitCount) { - red.pos = greenBitCount + blueBitCount; - green.pos = blueBitCount; + component.pos = bitsPerPixel; + component.bitCount = bitCount; + bitsPerPixel += bitCount; + bytesPerPixel = (bitsPerPixel + 7) / 8; } }; - struct BgrFormatInfo : D3dDdi::FormatInfo + struct FormatInfoXARGB : FormatInfoBuilder { - BgrFormatInfo(BYTE unusedBitCount, BYTE alphaBitCount, BYTE blueBitCount, BYTE greenBitCount, BYTE redBitCount) - : FormatInfo(unusedBitCount, alphaBitCount, redBitCount, greenBitCount, blueBitCount) + FormatInfoXARGB::FormatInfoXARGB(BYTE x, BYTE a, BYTE r, BYTE g, BYTE b) { - green.pos = redBitCount; - blue.pos = redBitCount + greenBitCount; + setComponent(blue, b); + setComponent(green, g); + setComponent(red, r); + setComponent(alpha, a); + setComponent(unused, x); + pixelFormat = getPixelFormat(*this); } }; - struct DxsFormatInfo : D3dDdi::FormatInfo + struct FormatInfoXABGR : FormatInfoBuilder { - DxsFormatInfo(BYTE depthBitCount, BYTE unusedBitCount, BYTE stencilBitCount) - : FormatInfo(unusedBitCount, depthBitCount, stencilBitCount) + FormatInfoXABGR::FormatInfoXABGR(BYTE x, BYTE a, BYTE b, BYTE g, BYTE r) { - depth.pos = unusedBitCount + stencilBitCount; - unused.pos = stencilBitCount; + setComponent(red, r); + setComponent(green, g); + setComponent(blue, b); + setComponent(alpha, a); + setComponent(unused, x); + pixelFormat = getPixelFormat(*this); } }; - struct XsdFormatInfo : D3dDdi::FormatInfo + struct FormatInfoAP : FormatInfoBuilder { - XsdFormatInfo(BYTE unusedBitCount, BYTE stencilBitCount, BYTE depthBitCount) - : FormatInfo(unusedBitCount, depthBitCount, stencilBitCount) + FormatInfoAP::FormatInfoAP(BYTE a, BYTE p) { - unused.pos = stencilBitCount + depthBitCount; - stencil.pos = depthBitCount; + setComponent(palette, p); + setComponent(alpha, a); + pixelFormat = getPixelFormat(*this); } }; + struct FormatInfoDXS : FormatInfoBuilder + { + FormatInfoDXS::FormatInfoDXS(BYTE d, BYTE x, BYTE s) + { + setComponent(stencil, s); + setComponent(unused, x); + setComponent(depth, d); + pixelFormat = getPixelFormat(*this); + } + }; + + struct FormatInfoXSD : FormatInfoBuilder + { + FormatInfoXSD::FormatInfoXSD(BYTE x, BYTE s, BYTE d) + { + setComponent(depth, d); + setComponent(stencil, s); + setComponent(unused, x); + pixelFormat = getPixelFormat(*this); + } + }; + + struct FormatInfoXALVU : FormatInfoBuilder + { + FormatInfoXALVU::FormatInfoXALVU(BYTE x, BYTE a, BYTE l, BYTE v, BYTE u) + { + setComponent(du, u); + setComponent(dv, v); + setComponent(luminance, l); + setComponent(alpha, a); + setComponent(unused, x); + pixelFormat = getPixelFormat(*this); + } + }; + + const std::map g_formatInfo = { + { D3DDDIFMT_R8G8B8, FormatInfoXARGB(0, 0, 8, 8, 8) }, + { D3DDDIFMT_A8R8G8B8, FormatInfoXARGB(0, 8, 8, 8, 8) }, + { D3DDDIFMT_X8R8G8B8, FormatInfoXARGB(8, 0, 8, 8, 8) }, + { D3DDDIFMT_R5G6B5, FormatInfoXARGB(0, 0, 5, 6, 5) }, + { D3DDDIFMT_X1R5G5B5, FormatInfoXARGB(1, 0, 5, 5, 5) }, + { D3DDDIFMT_A1R5G5B5, FormatInfoXARGB(0, 1, 5, 5, 5) }, + { D3DDDIFMT_A4R4G4B4, FormatInfoXARGB(0, 4, 4, 4, 4) }, + { D3DDDIFMT_R3G3B2, FormatInfoXARGB(0, 0, 3, 3, 2) }, + { D3DDDIFMT_A8, FormatInfoXARGB(0, 8, 0, 0, 0) }, + { D3DDDIFMT_A8R3G3B2, FormatInfoXARGB(0, 8, 3, 3, 2) }, + { D3DDDIFMT_X4R4G4B4, FormatInfoXARGB(4, 0, 4, 4, 4) }, + + { D3DDDIFMT_A8B8G8R8, FormatInfoXABGR(0, 8, 8, 8, 8) }, + { D3DDDIFMT_X8B8G8R8, FormatInfoXABGR(8, 0, 8, 8, 8) }, + + { D3DDDIFMT_A8P8, FormatInfoAP(8, 8) }, + { D3DDDIFMT_P8, FormatInfoAP(0, 8) }, + + { D3DDDIFMT_L8, FormatInfoXALVU(0, 0, 8, 0, 0) }, + { D3DDDIFMT_A8L8, FormatInfoXALVU(0, 8, 8, 0, 0) }, + { D3DDDIFMT_A4L4, FormatInfoXALVU(0, 4, 4, 0, 0) }, + + { D3DDDIFMT_V8U8, FormatInfoXALVU(0, 0, 0, 8, 8) }, + { D3DDDIFMT_L6V5U5, FormatInfoXALVU(0, 0, 6, 5, 5) }, + { D3DDDIFMT_X8L8V8U8, FormatInfoXALVU(8, 0, 8, 8, 8) }, + + { D3DDDIFMT_D32, FormatInfoDXS(32, 0, 0) }, + { D3DDDIFMT_D15S1, FormatInfoDXS(15, 0, 1) }, + { D3DDDIFMT_D24S8, FormatInfoDXS(24, 0, 8) }, + { D3DDDIFMT_D24X8, FormatInfoDXS(24, 8, 0) }, + { D3DDDIFMT_D16, FormatInfoDXS(16, 0, 0) }, + + { D3DDDIFMT_S1D15, FormatInfoXSD(0, 1, 15) }, + { D3DDDIFMT_S8D24, FormatInfoXSD(0, 8, 24) }, + { D3DDDIFMT_X8D24, FormatInfoXSD(8, 0, 24) }, + }; + DWORD getMask(const D3dDdi::FormatInfo::Component& component) { - return ((1 << component.bitCount) - 1) << component.pos; + return ((1ULL << component.bitCount) - 1) << component.pos; + } + + DDPIXELFORMAT getPixelFormat(const D3dDdi::FormatInfo& info) + { + DDPIXELFORMAT pf = {}; + pf.dwSize = sizeof(pf); + pf.dwFlags = + (info.alpha.bitCount ? (info.alpha.bitCount == info.bitsPerPixel ? DDPF_ALPHA : DDPF_ALPHAPIXELS) : 0) | + ((info.red.bitCount || info.palette.bitCount) ? DDPF_RGB : 0) | + (info.palette.bitCount ? DDPF_PALETTEINDEXED8 : 0) | + (info.depth.bitCount ? DDPF_ZBUFFER : 0) | + (info.stencil.bitCount ? DDPF_STENCILBUFFER : 0) | + (info.luminance.bitCount ? (info.du.bitCount ? DDPF_BUMPLUMINANCE : DDPF_LUMINANCE) : 0) | + (info.du.bitCount ? DDPF_BUMPDUDV : 0); + pf.dwRGBBitCount = info.bitsPerPixel; + + pf.dwRGBAlphaBitMask = info.alpha.bitCount == info.bitsPerPixel ? 0 : getMask(info.alpha); + pf.dwRBitMask = getMask(info.red); + pf.dwGBitMask = getMask(info.green); + pf.dwBBitMask = getMask(info.blue); + + pf.dwStencilBitDepth |= info.stencil.bitCount; + pf.dwZBitMask |= getMask(info.depth); + pf.dwStencilBitMask |= getMask(info.stencil); + + pf.dwLuminanceBitMask |= info.du.bitCount ? 0 : getMask(info.luminance); + pf.dwBumpDuBitMask |= getMask(info.du); + pf.dwBumpDvBitMask |= getMask(info.dv); + pf.dwBumpLuminanceBitMask |= info.du.bitCount ? getMask(info.luminance) : 0; + return pf; } } namespace D3dDdi { - FormatInfo::FormatInfo() - { - memset(this, 0, sizeof(*this)); - } - - FormatInfo::FormatInfo(BYTE unusedBitCount, BYTE alphaBitCount, BYTE redBitCount, BYTE greenBitCount, BYTE blueBitCount) - : bitsPerPixel(unusedBitCount + alphaBitCount + redBitCount + greenBitCount + blueBitCount) - , bytesPerPixel((bitsPerPixel + 7) / 8) - , unused{ unusedBitCount, static_cast(alphaBitCount + redBitCount + greenBitCount + blueBitCount) } - , alpha{ alphaBitCount, static_cast(redBitCount + greenBitCount + blueBitCount) } - , red{ redBitCount, 0 } - , green{ greenBitCount, 0 } - , blue{ blueBitCount, 0 } - , depth{} - , stencil{} - { - } - - FormatInfo::FormatInfo(BYTE unusedBitCount, BYTE depthBitCount, BYTE stencilBitCount) - : bitsPerPixel(unusedBitCount + depthBitCount + stencilBitCount) - , bytesPerPixel((bitsPerPixel + 7) / 8) - , unused{ unusedBitCount, 0 } - , alpha{} - , red{} - , green{} - , blue{} - , depth{ depthBitCount, 0 } - , stencil{ stencilBitCount, 0 } - { - } - D3DCOLOR convertFrom32Bit(const FormatInfo& dstFormatInfo, D3DCOLOR srcColor) { auto& src = *reinterpret_cast(&srcColor); @@ -96,12 +179,12 @@ namespace D3dDdi BYTE alpha = src.alpha >> (8 - dstFormatInfo.alpha.bitCount); BYTE red = src.red >> (8 - dstFormatInfo.red.bitCount); BYTE green = src.green >> (8 - dstFormatInfo.green.bitCount); - BYTE blue = src.blue >> (8 - dstFormatInfo.blue.bitCount); + BYTE blue = src.blue >> (8 - (dstFormatInfo.blue.bitCount | dstFormatInfo.palette.bitCount)); return (alpha << dstFormatInfo.alpha.pos) | (red << dstFormatInfo.red.pos) | (green << dstFormatInfo.green.pos) | - (blue << dstFormatInfo.blue.pos); + (blue << (dstFormatInfo.blue.pos | dstFormatInfo.palette.pos)); } DeviceState::ShaderConstF convertToShaderConst(const FormatInfo& srcFormatInfo, D3DCOLOR srcColor) @@ -130,86 +213,39 @@ namespace D3dDdi return static_cast((color & mask) >> component.pos) / max; } + D3DDDIFORMAT getFormat(const DDPIXELFORMAT& pixelFormat) + { + if (pixelFormat.dwFlags & DDPF_FOURCC) + { + return static_cast(pixelFormat.dwFourCC); + } + + for (auto& info : g_formatInfo) + { + if (0 == memcmp(&info.second.pixelFormat, &pixelFormat, sizeof(pixelFormat))) + { + return info.first; + } + } + + DDPIXELFORMAT pf = g_formatInfo.at(D3DDDIFMT_X8D24).pixelFormat; + pf.dwZBufferBitDepth = 24; // https://bugs.winehq.org/show_bug.cgi?id=22434 + if (0 == memcmp(&pf, &pixelFormat, sizeof(pixelFormat))) + { + return D3DDDIFMT_X8D24; + } + + return D3DDDIFMT_UNKNOWN; + } + FormatInfo getFormatInfo(D3DDDIFORMAT format) { - switch (format) - { - case D3DDDIFMT_R3G3B2: return RgbFormatInfo(0, 0, 3, 3, 2); - case D3DDDIFMT_A8: return RgbFormatInfo(0, 8, 0, 0, 0); - case D3DDDIFMT_P8: return RgbFormatInfo(0, 0, 0, 0, 8); - case D3DDDIFMT_R8: return RgbFormatInfo(0, 0, 8, 0, 0); - - case D3DDDIFMT_R5G6B5: return RgbFormatInfo(0, 0, 5, 6, 5); - case D3DDDIFMT_X1R5G5B5: return RgbFormatInfo(1, 0, 5, 5, 5); - case D3DDDIFMT_A1R5G5B5: return RgbFormatInfo(0, 1, 5, 5, 5); - case D3DDDIFMT_A4R4G4B4: return RgbFormatInfo(0, 4, 4, 4, 4); - case D3DDDIFMT_A8R3G3B2: return RgbFormatInfo(0, 8, 3, 3, 2); - case D3DDDIFMT_X4R4G4B4: return RgbFormatInfo(4, 0, 4, 4, 4); - case D3DDDIFMT_A8P8: return RgbFormatInfo(0, 8, 0, 0, 8); - case D3DDDIFMT_G8R8: return BgrFormatInfo(0, 0, 0, 8, 8); - - case D3DDDIFMT_R8G8B8: return RgbFormatInfo(0, 0, 8, 8, 8); - - case D3DDDIFMT_A8R8G8B8: return RgbFormatInfo(0, 8, 8, 8, 8); - case D3DDDIFMT_X8R8G8B8: return RgbFormatInfo(8, 0, 8, 8, 8); - case D3DDDIFMT_A8B8G8R8: return BgrFormatInfo(0, 8, 8, 8, 8); - case D3DDDIFMT_X8B8G8R8: return BgrFormatInfo(8, 0, 8, 8, 8); - - case D3DDDIFMT_D32: return DxsFormatInfo(32, 0, 0); - case D3DDDIFMT_D15S1: return DxsFormatInfo(15, 0, 1); - case D3DDDIFMT_D24S8: return DxsFormatInfo(24, 0, 8); - case D3DDDIFMT_D24X8: return DxsFormatInfo(24, 8, 0); - case D3DDDIFMT_D24X4S4: return DxsFormatInfo(24, 4, 4); - case D3DDDIFMT_D16: return DxsFormatInfo(16, 0, 0); - case D3DDDIFMT_S1D15: return XsdFormatInfo(0, 1, 15); - case D3DDDIFMT_S8D24: return XsdFormatInfo(0, 8, 24); - case D3DDDIFMT_X8D24: return XsdFormatInfo(8, 0, 24); - case D3DDDIFMT_X4S4D24: return XsdFormatInfo(4, 4, 24); - - default: - return FormatInfo(); - } + auto it = g_formatInfo.find(format); + return it != g_formatInfo.end() ? it->second : FormatInfo{}; } DDPIXELFORMAT getPixelFormat(D3DDDIFORMAT format) { - auto info = getFormatInfo(format); - if (0 == info.bytesPerPixel) - { - return {}; - } - - DDPIXELFORMAT pf = {}; - pf.dwSize = sizeof(pf); - if (0 != info.depth.bitCount) - { - pf.dwFlags = DDPF_ZBUFFER; - pf.dwZBufferBitDepth = info.depth.bitCount; - pf.dwZBitMask = getMask(info.depth); - if (0 != info.stencil.bitCount) - { - pf.dwFlags |= DDPF_STENCILBUFFER; - pf.dwZBufferBitDepth += info.stencil.bitCount; - pf.dwStencilBitDepth = info.stencil.bitCount; - pf.dwStencilBitMask = getMask(info.stencil); - } - } - else - { - pf.dwRGBBitCount = info.bitsPerPixel; - if (info.bitsPerPixel > info.alpha.bitCount) - { - pf.dwFlags = DDPF_RGB; - pf.dwRBitMask = getMask(info.red); - pf.dwGBitMask = getMask(info.green); - pf.dwBBitMask = getMask(info.blue); - } - if (0 != info.alpha.bitCount) - { - pf.dwFlags |= (0 == pf.dwFlags) ? DDPF_ALPHA : DDPF_ALPHAPIXELS; - pf.dwRGBAlphaBitMask = getMask(info.alpha); - } - } - return pf; + return getFormatInfo(format).pixelFormat; } } diff --git a/DDrawCompat/D3dDdi/FormatInfo.h b/DDrawCompat/D3dDdi/FormatInfo.h index cf4c48a..90ac9af 100644 --- a/DDrawCompat/D3dDdi/FormatInfo.h +++ b/DDrawCompat/D3dDdi/FormatInfo.h @@ -15,29 +15,31 @@ namespace D3dDdi { struct Component { - BYTE bitCount; - BYTE pos; + BYTE bitCount = 0; + BYTE pos = 0; }; - BYTE bitsPerPixel; - BYTE bytesPerPixel; + BYTE bitsPerPixel = 0; + BYTE bytesPerPixel = 0; Component unused; Component alpha; Component red; Component green; Component blue; + Component palette; Component depth; Component stencil; - - FormatInfo(); - FormatInfo(BYTE unusedBitCount, BYTE alphaBitCount, BYTE redBitCount, BYTE greenBitCount, BYTE blueBitCount); - FormatInfo(BYTE unusedBitCount, BYTE depthBitCount, BYTE stencilBitCount); + Component luminance; + Component du; + Component dv; + DDPIXELFORMAT pixelFormat = {}; }; D3DCOLOR convertFrom32Bit(const FormatInfo& dstFormatInfo, D3DCOLOR srcColor); DeviceState::ShaderConstF convertToShaderConst(const FormatInfo& srcFormatInfo, D3DCOLOR srcColor); DWORD getComponent(D3DCOLOR color, const D3dDdi::FormatInfo::Component& component); float getComponentAsFloat(D3DCOLOR color, const D3dDdi::FormatInfo::Component& component); + D3DDDIFORMAT getFormat(const DDPIXELFORMAT& pixelFormat); FormatInfo getFormatInfo(D3DDDIFORMAT format); DDPIXELFORMAT getPixelFormat(D3DDDIFORMAT format); } diff --git a/DDrawCompat/D3dDdi/SurfaceRepository.cpp b/DDrawCompat/D3dDdi/SurfaceRepository.cpp index ec7de67..324c6b8 100644 --- a/DDrawCompat/D3dDdi/SurfaceRepository.cpp +++ b/DDrawCompat/D3dDdi/SurfaceRepository.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace { @@ -56,6 +57,7 @@ namespace D3dDdi desc.dwBackBufferCount = surfaceCount - 1; } + DDraw::SuppressResourceFormatLogs suppressResourceFormatLogs; s_inCreateSurface = true; HRESULT result = dd.get()->lpVtbl->CreateSurface(dd, &desc, &surface.getRef(), nullptr); s_inCreateSurface = false; diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index e20748b..85a1809 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +35,10 @@ namespace return getOrigVtable(This).CreateSurface(This, lpDDSurfaceDesc, lplpDDSurface, pUnkOuter); } + DDSURFACEDESC2 desc2 = {}; + memcpy(&desc2, lpDDSurfaceDesc, sizeof(*lpDDSurfaceDesc)); + DDraw::LogUsedResourceFormat logUsedResourceFormat(desc2, reinterpret_cast(*lplpDDSurface)); + if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) { return DDraw::PrimarySurface::create(*This, *lpDDSurfaceDesc, *lplpDDSurface); diff --git a/DDrawCompat/DDraw/LogUsedResourceFormat.cpp b/DDrawCompat/DDraw/LogUsedResourceFormat.cpp new file mode 100644 index 0000000..1261fba --- /dev/null +++ b/DDrawCompat/DDraw/LogUsedResourceFormat.cpp @@ -0,0 +1,183 @@ +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace +{ + struct ResourceFormat + { + D3DDDIFORMAT format; + DWORD caps; + DWORD caps2; + DWORD memCaps; + }; + + UINT g_suppressResourceFormatLogs = 0; + + auto toTuple(const ResourceFormat& format) + { + return std::make_tuple(format.format, format.caps, format.caps2, format.memCaps); + } + + bool operator<(const ResourceFormat& left, const ResourceFormat& right) + { + return toTuple(left) < toTuple(right); + } +} + +namespace DDraw +{ + LogUsedResourceFormat::LogUsedResourceFormat(const DDSURFACEDESC2& desc, IUnknown*& surface) + : m_desc(desc) + , m_surface(surface) + { + if (!(m_desc.dwFlags & DDSD_PIXELFORMAT)) + { + m_desc.ddpfPixelFormat = {}; + if (m_desc.dwFlags & DDSD_ZBUFFERBITDEPTH) + { + switch (m_desc.dwMipMapCount) + { + case 16: m_desc.ddpfPixelFormat = D3dDdi::getPixelFormat(D3DDDIFMT_D16); break; + case 24: m_desc.ddpfPixelFormat = D3dDdi::getPixelFormat(D3DDDIFMT_X8D24); break; + case 32: m_desc.ddpfPixelFormat = D3dDdi::getPixelFormat(D3DDDIFMT_D32); break; + } + } + else if (!(desc.ddsCaps.dwCaps & DDSCAPS_RESERVED2)) + { + m_desc.ddpfPixelFormat = DDraw::DirectDraw::getRgbPixelFormat(Win32::DisplayMode::getBpp()); + } + } + } + + LogUsedResourceFormat::~LogUsedResourceFormat() + { + if (g_suppressResourceFormatLogs) + { + return; + } + + auto format = (m_desc.ddsCaps.dwCaps & DDSCAPS_RESERVED2) + ? D3DDDIFMT_VERTEXDATA + : D3dDdi::getFormat(m_desc.ddpfPixelFormat); + if (D3DDDIFMT_UNKNOWN == format) + { + LOG_ONCE("Unknown resource format: " << format); + } + + bool isMipMap = (m_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP) && (m_desc.ddsCaps.dwCaps & DDSCAPS_COMPLEX) && + (!(m_desc.dwFlags & DDSD_MIPMAPCOUNT) || m_desc.dwMipMapCount > 1); + auto caps = m_desc.ddsCaps.dwCaps & (DDSCAPS_SYSTEMMEMORY | DDSCAPS_VIDEOMEMORY | + DDSCAPS_3DDEVICE | DDSCAPS_TEXTURE | (isMipMap ? DDSCAPS_MIPMAP : 0) | DDSCAPS_ZBUFFER | DDSCAPS_RESERVED2 | + DDSCAPS_PRIMARYSURFACE | DDSCAPS_OVERLAY); + auto caps2 = m_desc.ddsCaps.dwCaps2 & (DDSCAPS2_CUBEMAP | DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE); + DWORD memCaps = 0; + + if (!(m_desc.ddsCaps.dwCaps & (DDSCAPS_SYSTEMMEMORY | DDSCAPS_VIDEOMEMORY)) && + !(m_desc.ddsCaps.dwCaps2 & (DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE))) + { + auto surface(CompatPtr::from(m_surface)); + if (surface) + { + DDSCAPS2 realCaps = {}; + surface->GetCaps(surface, &realCaps); + memCaps = realCaps.dwCaps & (DDSCAPS_SYSTEMMEMORY | DDSCAPS_VIDEOMEMORY); + } + } + + static std::set formats; + if (formats.insert({ format, caps, caps2, memCaps }).second) + { + Compat::Log log(Config::Settings::LogLevel::INFO); + log << "Using resource format: " << format << ','; + + if (caps & DDSCAPS_3DDEVICE) + { + log << " render target"; + } + if (caps & DDSCAPS_ZBUFFER) + { + log << " depth buffer"; + } + if (caps & DDSCAPS_RESERVED2) + { + log << " vertex buffer"; + } + if (caps2 & DDSCAPS2_CUBEMAP) + { + log << " cubic"; + } + if (caps & DDSCAPS_MIPMAP) + { + log << " mipmap"; + } + if (caps & DDSCAPS_TEXTURE) + { + log << " texture"; + } + if (caps & DDSCAPS_PRIMARYSURFACE) + { + log << " primary"; + } + if (caps & DDSCAPS_OVERLAY) + { + log << " overlay"; + } + if (!(caps & (DDSCAPS_3DDEVICE | DDSCAPS_ZBUFFER | DDSCAPS_RESERVED2 | DDSCAPS_TEXTURE | + DDSCAPS_PRIMARYSURFACE | DDSCAPS_OVERLAY))) + { + log << " plain"; + } + + log << ", "; + if (caps2 & DDSCAPS2_D3DTEXTUREMANAGE) + { + log << "D3D managed"; + } + else if (caps2 & DDSCAPS2_TEXTUREMANAGE) + { + log << "managed"; + } + else if (caps & DDSCAPS_VIDEOMEMORY) + { + log << "vidmem"; + } + else if (caps & DDSCAPS_SYSTEMMEMORY) + { + log << "sysmem"; + } + else + { + log << "anymem"; + if (m_surface) + { + log << " -> " << ((memCaps & DDSCAPS_VIDEOMEMORY) ? "vidmem" : "sysmem"); + } + } + + if (!m_surface) + { + log << " (FAILED)"; + } + } + } + + SuppressResourceFormatLogs::SuppressResourceFormatLogs() + { + ++g_suppressResourceFormatLogs; + } + + SuppressResourceFormatLogs::~SuppressResourceFormatLogs() + { + --g_suppressResourceFormatLogs; + } +} diff --git a/DDrawCompat/DDraw/LogUsedResourceFormat.h b/DDrawCompat/DDraw/LogUsedResourceFormat.h new file mode 100644 index 0000000..baef489 --- /dev/null +++ b/DDrawCompat/DDraw/LogUsedResourceFormat.h @@ -0,0 +1,22 @@ +#include + +namespace DDraw +{ + class LogUsedResourceFormat + { + public: + LogUsedResourceFormat(const DDSURFACEDESC2& desc, IUnknown*& surface); + ~LogUsedResourceFormat(); + + private: + DDSURFACEDESC2 m_desc; + IUnknown*& m_surface; + }; + + class SuppressResourceFormatLogs + { + public: + SuppressResourceFormatLogs(); + ~SuppressResourceFormatLogs(); + }; +} diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index 57154b4..a8fee56 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -120,6 +121,7 @@ namespace auto tagSurface = DDraw::TagSurface::findFullscreenWindow(); LOG_DEBUG << "Creating " << (tagSurface ? "fullscreen" : "windowed") << " default primary"; + DDraw::SuppressResourceFormatLogs suppressResourceFormatLogs; if (tagSurface) { DDSURFACEDESC desc = {}; diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp index bbaa0ea..1f0bb91 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -225,6 +226,7 @@ namespace DDraw template HRESULT SurfaceImpl::QueryInterface(TSurface* This, REFIID riid, LPVOID* obp) { + DDraw::SuppressResourceFormatLogs suppressResourceFormatLogs; auto& iid = Direct3d::replaceDevice(riid); HRESULT result = getOrigVtable(This).QueryInterface(This, iid, obp); if (DDERR_INVALIDOBJECT == result) diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index 4fc701c..bef6fca 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -228,6 +228,7 @@ + @@ -366,6 +367,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 4479a78..0b7a0cc 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -633,6 +633,9 @@ Header Files\Config\Settings + + Header Files\DDraw + @@ -998,6 +1001,9 @@ Source Files\Overlay + + Source Files\DDraw + diff --git a/DDrawCompat/Direct3d/Direct3d.cpp b/DDrawCompat/Direct3d/Direct3d.cpp index 0e7e64a..2a2fce1 100644 --- a/DDrawCompat/Direct3d/Direct3d.cpp +++ b/DDrawCompat/Direct3d/Direct3d.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ namespace TDirect3dDevice** lplpD3DDevice, Params... params) { + DDraw::SuppressResourceFormatLogs suppressResourceFormatLogs; auto& iid = Direct3d::replaceDevice(rclsid); HRESULT result = getOrigVtable(This).CreateDevice(This, iid, lpDDS, lplpD3DDevice, params...); if (DDERR_INVALIDOBJECT == result && lpDDS) diff --git a/DDrawCompat/Dll/DllMain.cpp b/DDrawCompat/Dll/DllMain.cpp index c24ba51..63ca710 100644 --- a/DDrawCompat/Dll/DllMain.cpp +++ b/DDrawCompat/Dll/DllMain.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,7 @@ namespace static bool isAlreadyInstalled = false; if (!isAlreadyInstalled) { + DDraw::SuppressResourceFormatLogs suppressResourceFormatLogs; LOG_INFO << "Installing display mode hooks"; Win32::DisplayMode::installHooks(); LOG_INFO << "Installing registry hooks"; diff --git a/DDrawCompat/Gdi/VirtualScreen.cpp b/DDrawCompat/Gdi/VirtualScreen.cpp index 688b267..3ff6e2d 100644 --- a/DDrawCompat/Gdi/VirtualScreen.cpp +++ b/DDrawCompat/Gdi/VirtualScreen.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -176,6 +177,7 @@ namespace Gdi primary->GetDDInterface(primary, reinterpret_cast(&ddUnk.getRef())); CompatPtr dd(ddUnk); + DDraw::SuppressResourceFormatLogs suppressResourceFormatLogs; CompatPtr surface; dd.get()->lpVtbl->CreateSurface(dd, &desc, &surface.getRef(), nullptr); return surface;