Skip to content

Commit

Permalink
Update D9SURFACE structure
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jul 8, 2024
1 parent 6823ef1 commit bde69b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
24 changes: 12 additions & 12 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3823,9 +3823,9 @@ LPDIRECT3DTEXTURE9 m_IDirectDrawSurfaceX::Get3DDrawTexture()
// Create texture
if (surface.Texture)
{
if (FAILED((*d3d9Device)->CreateTexture(surface.Tex.Width, surface.Tex.Height, MaxMipMapLevel, surface.Tex.Usage, D3DFMT_A8R8G8B8, surface.Tex.Pool, &surface.DrawTexture, nullptr)))
if (FAILED((*d3d9Device)->CreateTexture(surface.Width, surface.Height, MaxMipMapLevel, surface.TextureUsage, D3DFMT_A8R8G8B8, surface.TexturePool, &surface.DrawTexture, nullptr)))
{
LOG_LIMIT(100, __FUNCTION__ << " Error: failed to create surface texture. Size: " << surface.Tex.Width << "x" << surface.Tex.Height << " Format: " << surfaceFormat << " dwCaps: " << surfaceDesc2.ddsCaps.dwCaps);
LOG_LIMIT(100, __FUNCTION__ << " Error: failed to create surface texture. Size: " << surface.Width << "x" << surface.Height << " Format: " << surfaceFormat << " dwCaps: " << surfaceDesc2.ddsCaps.dwCaps);
return nullptr;
}
if (FAILED(CopyToDrawTexture(nullptr)))
Expand Down Expand Up @@ -3859,9 +3859,9 @@ LPDIRECT3DTEXTURE9 m_IDirectDrawSurfaceX::Get3DTexture()
}

// Check texture pool
if (surface.Tex.Pool == D3DPOOL_SYSTEMMEM || surface.Tex.Pool == D3DPOOL_SCRATCH)
if (surface.TexturePool == D3DPOOL_SYSTEMMEM || surface.TexturePool == D3DPOOL_SCRATCH)
{
LOG_LIMIT(100, __FUNCTION__ << " Error: texture pool does not support Driect3D: " << surfaceFormat << " Pool: " << surface.Tex.Pool <<
LOG_LIMIT(100, __FUNCTION__ << " Error: texture pool does not support Driect3D: " << surfaceFormat << " Pool: " << surface.TexturePool <<
" Caps: " << surfaceDesc2.ddsCaps.dwCaps << " Attached: " << attached3DTexture);
return nullptr;
}
Expand Down Expand Up @@ -3993,7 +3993,7 @@ HRESULT m_IDirectDrawSurfaceX::CheckInterface(char *FunctionName, bool CheckD3DD
}

// Check if texture pool is wrong
if (attached3DTexture && surface.Tex.Pool != D3DPOOL_MANAGED)
if (attached3DTexture && surface.TexturePool != D3DPOOL_MANAGED)
{
ReleaseD9Surface(true, false);
}
Expand Down Expand Up @@ -4050,7 +4050,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
const D3DFORMAT Format = ConvertSurfaceFormat(surfaceFormat);

// Get memory pool
surface.Tex.Pool = (IsPrimaryOrBackBuffer() && surface.IsUsingWindowedMode && !Using3D) ? D3DPOOL_SYSTEMMEM :
surface.TexturePool = (IsPrimaryOrBackBuffer() && surface.IsUsingWindowedMode && !Using3D) ? D3DPOOL_SYSTEMMEM :
(IsPrimaryOrBackBuffer() || (surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE) ||
(surfaceDesc2.ddsCaps.dwCaps2 & (DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE))) ? D3DPOOL_MANAGED :
(surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) ? D3DPOOL_SYSTEMMEM : D3DPOOL_MANAGED;
Expand Down Expand Up @@ -4078,7 +4078,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
ShouldEmulate = (ShouldEmulate == SC_NOT_CREATED) ? SC_DONT_FORCE : ShouldEmulate;

Logging::LogDebug() << __FUNCTION__ " (" << this << ") D3d9 Surface. Size: " << Width << "x" << Height << " Format: " << surfaceFormat <<
" Pool: " << surface.Tex.Pool << " dwCaps: " << surfaceDesc2.ddsCaps.dwCaps << " " << surfaceDesc2;
" Pool: " << surface.TexturePool << " dwCaps: " << surfaceDesc2.ddsCaps.dwCaps << " " << surfaceDesc2;

HRESULT hr = DD_OK;

Expand Down Expand Up @@ -4113,12 +4113,12 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
DWORD MipMapLevel = SurfaceRequiresEmulation ? 1 : MaxMipMapLevel;
HRESULT hr_t;
do {
surface.Tex.Usage = Config.DdrawForceMipMapAutoGen && MipMapLevel != 1 ? D3DUSAGE_AUTOGENMIPMAP : 0;
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, surface.Tex.Usage, Format, surface.Tex.Pool, &surface.Texture, nullptr);
surface.TextureUsage = Config.DdrawForceMipMapAutoGen && MipMapLevel != 1 ? D3DUSAGE_AUTOGENMIPMAP : 0;
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, surface.TextureUsage, Format, surface.TexturePool, &surface.Texture, nullptr);
// Try failover format
if (FAILED(hr_t))
{
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, surface.Tex.Usage, GetFailoverFormat(Format), surface.Tex.Pool, &surface.Texture, nullptr);
hr_t = (*d3d9Device)->CreateTexture(Width, Height, MipMapLevel, surface.TextureUsage, GetFailoverFormat(Format), surface.TexturePool, &surface.Texture, nullptr);
}
} while (FAILED(hr_t) && ((!MipMapLevel && ++MipMapLevel) || --MipMapLevel > 0));
if (FAILED(hr_t))
Expand All @@ -4132,8 +4132,6 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
MaxMipMapLevel = MipMapLevel ? MipMapLevel : surface.Texture->GetLevelCount();
surfaceDesc2.dwMipMapCount = MaxMipMapLevel;
}
surface.Tex.Width = Width;
surface.Tex.Height = Height;
}
else
{
Expand Down Expand Up @@ -4173,6 +4171,8 @@ HRESULT m_IDirectDrawSurfaceX::CreateD3d9Surface()
}
}

surface.Width = Width;
surface.Height = Height;
surface.IsPaletteDirty = IsPalette();

} while (false);
Expand Down
23 changes: 9 additions & 14 deletions ddraw/IDirectDrawSurfaceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj
float highColorKey[4] = {};
};

struct TEXTURECREATE
{
DWORD Width = 0;
DWORD Height = 0;
D3DPOOL Pool = D3DPOOL_DEFAULT;
DWORD Usage = 0;
};

// Extra Direct3D9 devices used in the primary surface
struct D9PRIMARY
{
Expand All @@ -110,20 +102,23 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj
// Real surface and surface data using Direct3D9 devices
struct D9SURFACE
{
D3DMULTISAMPLE_TYPE MultiSampleType = D3DMULTISAMPLE_NONE;
DWORD MultiSampleQuality = 0;
bool CanBeRenderTarget = false;
bool IsUsingWindowedMode = false;
bool SurfaceHasData = false;
bool UsingSurfaceMemory = false;
bool IsDirtyFlag = false;
bool IsDrawTextureDirty = false;
bool IsPaletteDirty = false; // Used to detect if the palette surface needs to be updated
DWORD LastPaletteUSN = 0; // The USN that was used last time the palette was updated
TEXTURECREATE Tex; // Values used for creating textures
DWORD Width = 0; // Width surface/texture was created with
DWORD Height = 0; // Height surface/texture was created with
DWORD TextureUsage = 0; // Usage surface was created with
D3DPOOL TexturePool = D3DPOOL_DEFAULT; // Memory pool texture was created with
D3DPOOL SurfacePool = D3DPOOL_DEFAULT; // Memory pool surface was created with
EMUSURFACE* emu = nullptr; // Emulated surface using device context
D3DMULTISAMPLE_TYPE MultiSampleType = D3DMULTISAMPLE_NONE;
DWORD MultiSampleQuality = 0;
DWORD LastPaletteUSN = 0; // The USN that was used last time the palette was updated
LPPALETTEENTRY PaletteEntryArray = nullptr; // Used to store palette data address
EMUSURFACE* emu = nullptr; // Emulated surface using device context
LPDIRECT3DSURFACE9 Surface = nullptr; // Surface used for Direct3D
LPDIRECT3DTEXTURE9 Texture = nullptr; // Main surface texture used for locks, Blts and Flips
LPDIRECT3DTEXTURE9 DrawTexture = nullptr; // Main surface texture with SetTexture calls
Expand Down Expand Up @@ -267,7 +262,7 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj
inline bool IsSurfaceBlitting() { return (IsInBlt || IsInBltBatch); }
inline bool IsSurfaceInDC() { return IsInDC; }
inline bool IsSurfaceBusy() { return (IsSurfaceBlitting() || IsSurfaceLocked() || IsSurfaceInDC()); }
inline bool IsD9UsingVideoMemory() { return ((surface.Texture && surface.Tex.Pool == D3DPOOL_DEFAULT) ||
inline bool IsD9UsingVideoMemory() { return ((surface.Texture && surface.TexturePool == D3DPOOL_DEFAULT) ||
(surface.Surface && surface.SurfacePool == D3DPOOL_DEFAULT)); }
inline bool IsLockedFromOtherThread() { return (IsSurfaceBlitting() || IsSurfaceLocked()) && LockedWithID && LockedWithID != GetCurrentThreadId(); }
inline DWORD GetWidth() { return surfaceDesc2.dwWidth; }
Expand Down

0 comments on commit bde69b9

Please sign in to comment.