Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
option('enable_dxgi', type : 'boolean', value : true, description: 'Build DXGI')
option('enable_ddraw', type : 'boolean', value : true, description: 'Build DDRAW')
option('enable_d3d8', type : 'boolean', value : true, description: 'Build D3D8')
option('enable_d3d9', type : 'boolean', value : true, description: 'Build D3D9')
option('enable_d3d10', type : 'boolean', value : true, description: 'Build D3D10')
Expand Down
8 changes: 6 additions & 2 deletions src/d3d9/d3d9_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ namespace dxvk {
return m_d3d9Formats.GetUnsupportedFormatInfo(Format);
}

void RefreshFormatsTable(bool isD3D8Compatible) const {
m_d3d9Formats.RefreshFormatSupport(isD3D8Compatible);
}

private:

HRESULT CheckDeviceVkFormat(
Expand All @@ -105,8 +109,8 @@ namespace dxvk {
std::vector<D3DDISPLAYMODEEX> m_modes;
D3D9Format m_modeCacheFormat;

const D3D9VkFormatTable m_d3d9Formats;
mutable D3D9VkFormatTable m_d3d9Formats;

};

}
}
38 changes: 38 additions & 0 deletions src/d3d9/d3d9_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ namespace dxvk {
return m_device->QueryInterface(riid, ppvObject);
}

uint32_t DxvkD3D8Bridge::DetermineInitialTextureMemory() {
const int64_t initialTextureMemory = m_device->DetermineInitialTextureMemory();
return initialTextureMemory > 0 ? static_cast<uint32_t>(initialTextureMemory) : 0;
}

HRESULT DxvkD3D8Bridge::ResetSwapChain(D3DPRESENT_PARAMETERS* Params) {
return m_device->ResetSwapChain(Params, nullptr);
}

HRESULT DxvkD3D8Bridge::SetColorKeyState(bool colorKeyState) {
return m_device->SetColorKeyState(colorKeyState);
}

HRESULT DxvkD3D8Bridge::SetColorKey(DWORD colorKeyLow, DWORD colorKeyHigh) {
return m_device->SetColorKey(colorKeyLow, colorKeyHigh);
}

HRESULT DxvkD3D8Bridge::SetLegacyLightsState(bool legacyLightsState, bool isD3DLight2) {
m_device->SetRenderState(D3DRS_NORMALIZENORMALS, legacyLightsState);
return m_device->SetLegacyLightsState(legacyLightsState, isD3DLight2);
}

HRESULT DxvkD3D8Bridge::UpdateTextureFromBuffer(
IDirect3DSurface9* pDestSurface,
IDirect3DSurface9* pSrcSurface,
Expand Down Expand Up @@ -115,6 +137,22 @@ namespace dxvk {
return m_interface->QueryInterface(riid, ppvObject);
}

void DxvkD3D8InterfaceBridge::EnableD3D3CompatibilityMode() {
m_interface->EnableD3D3CompatibilityMode();
}

void DxvkD3D8InterfaceBridge::EnableD3D5CompatibilityMode() {
m_interface->EnableD3D5CompatibilityMode();
}

void DxvkD3D8InterfaceBridge::EnableD3D6CompatibilityMode() {
m_interface->EnableD3D6CompatibilityMode();
}

void DxvkD3D8InterfaceBridge::EnableD3D7CompatibilityMode() {
m_interface->EnableD3D7CompatibilityMode();
}

void DxvkD3D8InterfaceBridge::EnableD3D8CompatibilityMode() {
m_interface->EnableD3D8CompatibilityMode();
}
Expand Down
22 changes: 22 additions & 0 deletions src/d3d9/d3d9_bridge.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <windows.h>
#include <d3d9.h>
#include "../util/config/config.h"

/**
Expand All @@ -20,6 +21,7 @@ IDxvkD3D8Bridge : public IUnknown {
#ifdef DXVK_D3D9_NAMESPACE
using IDirect3DSurface9 = d3d9::IDirect3DSurface9;
using D3DFORMAT = d3d9::D3DFORMAT;
using D3DPRESENT_PARAMETERS = d3d9::D3DPRESENT_PARAMETERS;
#endif

/**
Expand All @@ -30,6 +32,12 @@ IDxvkD3D8Bridge : public IUnknown {
* \param [in] pSrcRect Source rectangle
* \param [in] pDestPoint Destination (top-left) point
*/
virtual uint32_t DetermineInitialTextureMemory() = 0;
virtual HRESULT ResetSwapChain(D3DPRESENT_PARAMETERS* Params) = 0;
virtual HRESULT SetColorKeyState(bool colorKeyState) = 0;
virtual HRESULT SetColorKey(DWORD colorKeyLow, DWORD colorKeyHigh) = 0;
virtual HRESULT SetLegacyLightsState(bool legacyLightsState, bool isD3DLight2) = 0;

virtual HRESULT UpdateTextureFromBuffer(
IDirect3DSurface9* pDestSurface,
IDirect3DSurface9* pSrcSurface,
Expand All @@ -52,6 +60,10 @@ IDxvkD3D8InterfaceBridge : public IUnknown {
/**
* \brief Enforces D3D8-specific features and validations
*/
virtual void EnableD3D3CompatibilityMode() = 0;
virtual void EnableD3D5CompatibilityMode() = 0;
virtual void EnableD3D6CompatibilityMode() = 0;
virtual void EnableD3D7CompatibilityMode() = 0;
virtual void EnableD3D8CompatibilityMode() = 0;

/**
Expand Down Expand Up @@ -86,6 +98,12 @@ namespace dxvk {
REFIID riid,
void** ppvObject);

uint32_t DetermineInitialTextureMemory();
HRESULT ResetSwapChain(D3DPRESENT_PARAMETERS* Params);
HRESULT SetColorKeyState(bool colorKeyState);
HRESULT SetColorKey(DWORD colorKeyLow, DWORD colorKeyHigh);
HRESULT SetLegacyLightsState(bool legacyLightsState, bool isD3DLight2);

HRESULT UpdateTextureFromBuffer(
IDirect3DSurface9* pDestSurface,
IDirect3DSurface9* pSrcSurface,
Expand Down Expand Up @@ -114,6 +132,10 @@ namespace dxvk {
REFIID riid,
void** ppvObject);

void EnableD3D3CompatibilityMode();
void EnableD3D5CompatibilityMode();
void EnableD3D6CompatibilityMode();
void EnableD3D7CompatibilityMode();
void EnableD3D8CompatibilityMode();

const Config* GetConfig() const;
Expand Down
5 changes: 3 additions & 2 deletions src/d3d9/d3d9_common_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

// RENDERTARGET and DEPTHSTENCIL must be default pool
constexpr DWORD incompatibleUsages = D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL;
if (pDesc->Pool != D3DPOOL_DEFAULT && (pDesc->Usage & incompatibleUsages))
constexpr DWORD usageRTOrDS = D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL;

if (pDesc->Pool != D3DPOOL_DEFAULT && (pDesc->Usage & usageRTOrDS))
return D3DERR_INVALIDCALL;

// Use the maximum possible mip level count if the supplied
Expand Down
12 changes: 8 additions & 4 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ namespace dxvk {
, m_d3d9Options ( dxvkDevice, pParent->GetInstance()->config() )
, m_multithread ( BehaviorFlags & D3DCREATE_MULTITHREADED )
, m_isSWVP ( (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ? true : false )
, m_isD3D3Compatible ( pParent->IsD3D3Compatible() )
, m_isD3D5Compatible ( pParent->IsD3D5Compatible() )
, m_isD3D6Compatible ( pParent->IsD3D6Compatible() )
, m_isD3D7Compatible ( pParent->IsD3D7Compatible() )
, m_isD3D8Compatible ( pParent->IsD3D8Compatible() )
, m_csThread ( dxvkDevice, dxvkDevice->createContext() )
, m_csChunk ( AllocCsChunk() )
Expand Down Expand Up @@ -7429,16 +7433,16 @@ namespace dxvk {
m_flags.set(D3D9DeviceFlag::DirtyFFVertexShader);

// PS
rs[D3DRS_SPECULARENABLE] = FALSE;
rs[D3DRS_SPECULARENABLE] = m_isD3D5Compatible ? TRUE : FALSE;

rs[D3DRS_AMBIENT] = 0;
m_flags.set(D3D9DeviceFlag::DirtyFFVertexData);

rs[D3DRS_FOGENABLE] = FALSE;
rs[D3DRS_FOGCOLOR] = 0;
rs[D3DRS_FOGTABLEMODE] = D3DFOG_NONE;
rs[D3DRS_FOGSTART] = bit::cast<DWORD>(0.0f);
rs[D3DRS_FOGEND] = bit::cast<DWORD>(1.0f);
rs[D3DRS_FOGSTART] = m_isD3D6Compatible ? bit::cast<DWORD>(1.0f) : bit::cast<DWORD>(0.0f);
rs[D3DRS_FOGEND] = m_isD3D6Compatible ? bit::cast<DWORD>(100.0f) : bit::cast<DWORD>(1.0f);
rs[D3DRS_FOGDENSITY] = bit::cast<DWORD>(1.0f);
rs[D3DRS_FOGVERTEXMODE] = D3DFOG_NONE;
m_flags.set(D3D9DeviceFlag::DirtyFogColor);
Expand Down Expand Up @@ -7485,7 +7489,7 @@ namespace dxvk {
rs[D3DRS_WRAP6] = 0;
rs[D3DRS_WRAP7] = 0;
rs[D3DRS_CLIPPING] = TRUE;
rs[D3DRS_MULTISAMPLEANTIALIAS] = TRUE;
rs[D3DRS_MULTISAMPLEANTIALIAS] = m_isD3D7Compatible ? FALSE : TRUE;
rs[D3DRS_PATCHEDGESTYLE] = D3DPATCHEDGE_DISCRETE;
rs[D3DRS_DEBUGMONITORTOKEN] = D3DDMT_ENABLE;
rs[D3DRS_POSITIONDEGREE] = D3DDEGREE_CUBIC;
Expand Down
49 changes: 49 additions & 0 deletions src/d3d9/d3d9_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,29 @@ namespace dxvk {
const D3D9ConstantLayout& GetPixelConstantLayout() { return m_psLayout; }

HRESULT ResetState(D3DPRESENT_PARAMETERS* pPresentationParameters);
HRESULT SetColorKeyState(bool colorKeyState) {
if (likely(m_colorKeyEnabled != colorKeyState)) {
m_colorKeyEnabled = colorKeyState;
}
return D3D_OK;
}

HRESULT SetLegacyLightsState(bool legacyLightState, bool isD3DLight2) {
if (likely(m_useLegacyLights != legacyLightState)) {
m_useLegacyLights = legacyLightState;
m_isD3DLight2 = isD3DLight2;
}
return D3D_OK;
}

HRESULT SetColorKey(DWORD colorKeyLow, DWORD colorKeyHigh) {
if (likely(m_state.colorKeyLow != colorKeyLow || m_state.colorKeyHigh != colorKeyHigh)) {
m_state.colorKeyLow = colorKeyLow;
m_state.colorKeyHigh = colorKeyHigh;
}
return D3D_OK;
}

HRESULT ResetSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode);

HRESULT InitialReset(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode);
Expand All @@ -936,6 +959,22 @@ namespace dxvk {
return m_samplerCount.load();
}

bool IsD3D3Compatible() const {
return m_isD3D3Compatible;
}

bool IsD3D5Compatible() const {
return m_isD3D5Compatible;
}

bool IsD3D6Compatible() const {
return m_isD3D6Compatible;
}

bool IsD3D7Compatible() const {
return m_isD3D7Compatible;
}

bool IsD3D8Compatible() const {
return m_isD3D8Compatible;
}
Expand Down Expand Up @@ -1274,6 +1313,16 @@ namespace dxvk {
D3D9ShaderMasks m_psShaderMasks = FixedFunctionMask;

bool m_isSWVP;
bool m_isD3D3Compatible;
bool m_isD3D5Compatible;
bool m_isD3D6Compatible;
bool m_isD3D7Compatible;

// D3D7 and earlier color key transparency state
bool m_colorKeyEnabled = false;
// D3D6 and earlier legacy light model state
bool m_useLegacyLights = false;
bool m_isD3DLight2 = false;
bool m_isD3D8Compatible;
bool m_amdATOC = false;
bool m_nvATOC = false;
Expand Down
13 changes: 9 additions & 4 deletions src/d3d9/d3d9_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ namespace dxvk {

if (Format == D3D9Format::D32 && !m_d32supportFinal)
return D3D9_VK_FORMAT_MAPPING();

if (!m_d24s8Support && mapping.FormatColor == VK_FORMAT_D24_UNORM_S8_UINT)
mapping.FormatColor = VK_FORMAT_D32_SFLOAT_S8_UINT;

Expand Down Expand Up @@ -577,16 +577,21 @@ namespace dxvk {
return &unknown;
}
}



void D3D9VkFormatTable::RefreshFormatSupport(bool isD3D8Compatible) {
m_w11v11u10Support = isD3D8Compatible;
}


bool D3D9VkFormatTable::CheckImageFormatSupport(
const Rc<DxvkAdapter>& Adapter,
VkFormat Format,
VkFormatFeatureFlags Features) const {
VkFormatProperties supported = Adapter->formatProperties(Format);

return (supported.linearTilingFeatures & Features) == Features
|| (supported.optimalTilingFeatures & Features) == Features;
}

}
}
3 changes: 3 additions & 0 deletions src/d3d9/d3d9_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ namespace dxvk {
const DxvkFormatInfo* GetUnsupportedFormatInfo(
D3D9Format Format) const;

void RefreshFormatSupport(bool isD3D8Compatible);

private:

bool CheckImageFormatSupport(
Expand All @@ -225,6 +227,7 @@ namespace dxvk {

bool m_dfSupport;
bool m_x4r4g4b4Support;
bool m_w11v11u10Support;
bool m_d32supportFinal;
};

Expand Down
Loading
Loading