Skip to content

Commit

Permalink
[d3d8] Add a R8G8B8 workaround for Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Sep 14, 2024
1 parent 04cf000 commit b1ef86b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/d3d8/d3d8_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ namespace dxvk {
UINT Height,
D3DFORMAT Format,
IDirect3DSurface8** ppSurface) {
// FIXME: Handle D3DPOOL_SCRATCH in CopyRects
// Workaround for Chrome: Gold Edition
if (m_d3d8Options.useX8R8G8B8forR8G8B8 && Format == D3DFMT_R8G8B8)
Format = D3DFMT_X8R8G8B8;

// TODO: Handle D3DPOOL_SCRATCH in CopyRects
D3DPOOL pool = isUnsupportedSurfaceFormat(Format) ? D3DPOOL_SCRATCH : D3DPOOL_SYSTEMMEM;

Com<d3d9::IDirect3DSurface9> pSurf = nullptr;
Expand Down
12 changes: 12 additions & 0 deletions src/d3d8/d3d8_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,23 @@ namespace dxvk {
/// and above. Most likely ATI/AMD drivers never supported P8 in the first place.
bool placeP8InScratch = false;

/// Chrome: Gold Edition ends up on a path calling CopyRects on a D3DPOOL_DEFAULT source
/// surface using the X8R8G8B8 format and a D3DPOOL_SYSTEMMEM (or D3DPOOL_SCRATCH)
/// destination surface using R8G8B8, and crashes should that call fail.
///
/// Since CopyRects does not perform format conversions, we need to handle it ourselves
/// before it gets to that point, by swapping R8G8B8 with X8R8G8B8 during the call to
/// CreateImageSurface (which creates the destination surface for CopyRects).
///
/// I am unsure how this entire thing even ever worked on native...
bool useX8R8G8B8forR8G8B8 = false;

D3D8Options() {}
D3D8Options(const Config& config) {
auto forceVsDeclStr = config.getOption<std::string>("d3d8.forceVsDecl", "");
batching = config.getOption<bool> ("d3d8.batching", batching);
placeP8InScratch = config.getOption<bool> ("d3d8.placeP8InScratch", placeP8InScratch);
useX8R8G8B8forR8G8B8 = config.getOption<bool> ("d3d8.useX8R8G8B8forR8G8B8", useX8R8G8B8forR8G8B8);

parseVsDecl(forceVsDeclStr);
}
Expand Down
8 changes: 4 additions & 4 deletions src/d3d8/d3d8_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace dxvk {
d3d9::D3DMULTISAMPLE_NONE, 0,
FALSE,
&image,
NULL);
NULL);

if (FAILED(res))
throw new DxvkError("D3D8: Failed to create blit image");
Logger::err(str::format("Failed to create blit image for format: ", desc.Format));

return image;
}
}
7 changes: 7 additions & 0 deletions src/util/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,13 @@ namespace dxvk {
{ R"(\\SplinterCell2\.exe$)", {{
{ "d3d9.maxFrameRate", "60" },
}} },
/* Chrome: Gold Edition *
* Relies on some form of R8G8B8 support and *
* has broken character motion at high FPS */
{ R"(\\Chrome(Single|Net)\.exe$)", {{
{ "d3d8.useX8R8G8B8forR8G8B8", "True" },
{ "d3d9.maxFrameRate", "60" },
}} },
}};


Expand Down

0 comments on commit b1ef86b

Please sign in to comment.