diff --git a/DDrawCompat/D3dDdi/Device.cpp b/DDrawCompat/D3dDdi/Device.cpp index 14f5d2a..73629f7 100644 --- a/DDrawCompat/D3dDdi/Device.cpp +++ b/DDrawCompat/D3dDdi/Device.cpp @@ -124,8 +124,8 @@ namespace D3dDdi auto& repo = getRepo(); SurfaceRepository::Surface tex; SurfaceRepository::Surface rt; - repo.getTempSurface(tex, 1, 1, D3DDDIFMT_X8R8G8B8, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY); - repo.getTempSurface(rt, 1, 1, D3DDDIFMT_X8R8G8B8, DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY); + repo.getTempSurface(tex, 1, 1, D3DDDIFMT_R5G6B5, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY); + repo.getTempSurface(rt, 1, 1, D3DDDIFMT_R5G6B5, DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY); if (tex.resource && rt.resource) { @@ -134,7 +134,8 @@ namespace D3dDdi tex.surface->Lock(tex.surface, nullptr, &desc, DDLOCK_DISCARDCONTENTS | DDLOCK_WAIT, nullptr); if (desc.lpSurface) { - static_cast(desc.lpSurface)[0] = 0xFF; + const WORD testColor = static_cast(getFormatInfo(D3DDDIFMT_R5G6B5).pixelFormat.dwGBitMask); + static_cast(desc.lpSurface)[0] = testColor; tex.surface->Unlock(tex.surface, nullptr); m_shaderBlitter.colorKeyTestBlt(*rt.resource, *tex.resource); @@ -144,7 +145,7 @@ namespace D3dDdi rt.surface->Lock(rt.surface, nullptr, &desc, DDLOCK_READONLY | DDLOCK_WAIT, nullptr); if (desc.lpSurface) { - method = 0xFF == static_cast(desc.lpSurface)[0] + method = testColor == static_cast(desc.lpSurface)[0] ? Config::Settings::ColorKeyMethod::ALPHATEST : Config::Settings::ColorKeyMethod::NATIVE; rt.surface->Unlock(rt.surface, nullptr); diff --git a/DDrawCompat/D3dDdi/DeviceState.cpp b/DDrawCompat/D3dDdi/DeviceState.cpp index 0c19744..4d7cec2 100644 --- a/DDrawCompat/D3dDdi/DeviceState.cpp +++ b/DDrawCompat/D3dDdi/DeviceState.cpp @@ -100,10 +100,7 @@ namespace D3dDdi const UINT UNINITIALIZED_STATE = 0xBAADBAAD; m_device.getOrigVtable().pfnSetDepthStencil(m_device, &m_current.depthStencil); - m_device.getOrigVtable().pfnSetPixelShader(m_device, nullptr); m_device.getOrigVtable().pfnSetRenderTarget(m_device, &m_current.renderTarget); - m_device.getOrigVtable().pfnSetVertexShaderDecl(m_device, nullptr); - m_device.getOrigVtable().pfnSetVertexShaderFunc(m_device, nullptr); m_device.getOrigVtable().pfnSetViewport(m_device, &m_current.viewport); m_device.getOrigVtable().pfnUpdateWInfo(m_device, &m_current.wInfo); m_device.getOrigVtable().pfnSetZRange(m_device, &m_current.zRange); @@ -836,7 +833,10 @@ namespace D3dDdi } m_device.flushPrimitives(); - origSetShaderFunc(m_device, shader); + if (shader) + { + origSetShaderFunc(m_device, shader); + } currentShader = shader; return true; } diff --git a/DDrawCompat/D3dDdi/KernelModeThunks.cpp b/DDrawCompat/D3dDdi/KernelModeThunks.cpp index 65d5ab1..7956a4a 100644 --- a/DDrawCompat/D3dDdi/KernelModeThunks.cpp +++ b/DDrawCompat/D3dDdi/KernelModeThunks.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -234,6 +235,30 @@ namespace } } } + else if (!Config::forceD3D9On12.get() && + KMTQAITYPE_UMDRIVERNAME == pData->Type && + KMTUMDVERSION_DX9 == static_cast(pData->pPrivateDriverData)->Version) + { + D3DKMT_UMDFILENAMEINFO fn = {}; + fn.Version = KMTUMDVERSION_DX12; + D3DKMT_QUERYADAPTERINFO data = *pData; + data.pPrivateDriverData = &fn; + data.PrivateDriverDataSize = sizeof(fn); + if (SUCCEEDED(D3DKMTQueryAdapterInfo(&data))) + { + std::filesystem::path path(fn.UmdFileName); + path.replace_filename("igd9trinity32.dll"); + HMODULE mod = LoadLibraryExW(path.native().c_str(), nullptr, LOAD_LIBRARY_AS_DATAFILE); + if (mod) + { + FreeLibrary(mod); + memcpy(static_cast(pData->pPrivateDriverData)->UmdFileName, + path.wstring().c_str(), (path.native().length() + 1) * 2); + LOG_ONCE("Replacing D3D9On12 with igd9trinity32.dll"); + return LOG_RESULT(S_OK); + } + } + } return LOG_RESULT(result); } diff --git a/DDrawCompat/D3dDdi/ShaderBlitter.cpp b/DDrawCompat/D3dDdi/ShaderBlitter.cpp index c3a7e8e..1aef51e 100644 --- a/DDrawCompat/D3dDdi/ShaderBlitter.cpp +++ b/DDrawCompat/D3dDdi/ShaderBlitter.cpp @@ -257,7 +257,8 @@ namespace D3dDdi LOWORD(filter) | (srgbRead ? D3DTEXF_SRGBREAD : 0)); if (flags & BLT_COLORKEYTEST) { - state.setTempTextureStageState({ 0, D3DDDITSS_TEXTURECOLORKEYVAL, 0xFF }); + const DWORD testColor = getFormatInfo(D3DDDIFMT_R5G6B5).pixelFormat.dwGBitMask; + state.setTempTextureStageState({ 0, D3DDDITSS_TEXTURECOLORKEYVAL, testColor }); } state.setTempStreamSourceUm({ 0, sizeof(Vertex) }, m_vertices.data()); diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index 5f30cf1..0726e21 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -319,7 +319,7 @@ namespace g_frontBuffer->SetClipper(g_frontBuffer, g_clipper); g_surfaceDesc = desc; - if (0 != (desc.ddsCaps.dwCaps & DDSCAPS_FLIP)) + if (g_isExclusiveFullscreen && 0 != (desc.ddsCaps.dwCaps & DDSCAPS_FLIP)) { g_frontBuffer->Flip(g_frontBuffer, getLastSurface(), DDFLIP_WAIT); D3dDdi::KernelModeThunks::waitForVsyncCounter(D3dDdi::KernelModeThunks::getVsyncCounter() + 1); @@ -408,7 +408,7 @@ namespace { updatePresentationWindow(); *g_deviceWindowPtr = g_presentationWindow; - g_frontBuffer->Flip(g_frontBuffer, getBackBuffer(), DDFLIP_WAIT); + g_frontBuffer->Flip(g_frontBuffer, g_isExclusiveFullscreen ? getBackBuffer() : nullptr, DDFLIP_WAIT); *g_deviceWindowPtr = g_deviceWindow; } g_presentEndVsyncCount = D3dDdi::KernelModeThunks::getVsyncCounter() + 1; @@ -522,7 +522,7 @@ namespace DDraw desc.dwSize = sizeof(desc); desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_COMPLEX | DDSCAPS_FLIP; - desc.dwBackBufferCount = 2; + desc.dwBackBufferCount = g_isExclusiveFullscreen ? 2 : 1; auto prevIsFullscreen = g_isFullscreen; g_isFullscreen = true;