Skip to content

Commit

Permalink
[d3d9] Cache all device create info
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpyneDreams committed Nov 29, 2024
1 parent b0bb217 commit 998ae8d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
8 changes: 5 additions & 3 deletions src/d3d9/d3d9_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ ID3D9VkInteropInterface : public IUnknown {
* \param [in] Adapter Adapter ordinal
* \param [out] pCreateInfo The Vulkan device create info
* \param [out] pQueueFamilies The required queue families
* \param [out] pFeatures The required device features
*/
virtual HRESULT STDMETHODCALLTYPE GetDeviceCreateInfo(
UINT Adapter,
VkDeviceCreateInfo* pCreateInfo,
D3D9VkQueueFamilies* pQueueFamilies) = 0;
UINT Adapter,
VkDeviceCreateInfo* pCreateInfo,
D3D9VkQueueFamilies* pQueueFamilies,
VkPhysicalDeviceFeatures2* pFeatures) = 0;

/**
* \brief Create a D3D9 device for an existing Vulkan device
Expand Down
21 changes: 15 additions & 6 deletions src/d3d9/d3d9_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ namespace dxvk {
}

HRESULT STDMETHODCALLTYPE D3D9VkInteropInterface::GetDeviceCreateInfo(
UINT Adapter,
VkDeviceCreateInfo* pCreateInfo,
D3D9VkQueueFamilies* pQueueFamilies) {
if (unlikely(pCreateInfo == nullptr && pQueueFamilies == nullptr))
UINT Adapter,
VkDeviceCreateInfo* pCreateInfo,
D3D9VkQueueFamilies* pQueueFamilies,
VkPhysicalDeviceFeatures2* pFeatures) {
if (unlikely(pCreateInfo == nullptr && pQueueFamilies == nullptr && pFeatures == nullptr))
return D3DERR_INVALIDCALL;

auto* adapter = m_interface->GetAdapter(Adapter);
Expand All @@ -65,19 +66,27 @@ namespace dxvk {

auto dxvkAdapter = adapter->GetDXVKAdapter();

DxvkDeviceCreateInfo createInfo;
DxvkDeviceCreateInfo& createInfo = m_deviceCreateInfos[Adapter];
if (!dxvkAdapter->getDeviceCreateInfo(m_interface->GetInstance(), D3D9DeviceEx::GetDeviceFeatures(dxvkAdapter), false, createInfo))
return D3DERR_INVALIDCALL;

if (pCreateInfo != nullptr)
if (pCreateInfo != nullptr) {
createInfo.info.enabledLayerCount = 0;
createInfo.info.ppEnabledLayerNames = nullptr;

*pCreateInfo = createInfo.info;
}

if (pQueueFamilies != nullptr) {
pQueueFamilies->graphics = createInfo.queueFamilies.graphics;
pQueueFamilies->transfer = createInfo.queueFamilies.transfer;
pQueueFamilies->sparse = createInfo.queueFamilies.sparse;
}

if (pFeatures != nullptr) {
pFeatures = &createInfo.features.core;
}

return D3D_OK;
}

Expand Down
10 changes: 7 additions & 3 deletions src/d3d9/d3d9_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace dxvk {
class D3D9CommonTexture;
class D3D9DeviceEx;
struct D3D9_COMMON_TEXTURE_DESC;
struct DxvkDeviceCreateInfo;
struct DxvkDeviceFeatures;

class D3D9VkInteropInterface final : public ID3D9VkInteropInterface {

Expand All @@ -35,9 +37,10 @@ namespace dxvk {
VkPhysicalDevice* pPhysicalDevice);

HRESULT STDMETHODCALLTYPE GetDeviceCreateInfo(
UINT Adapter,
VkDeviceCreateInfo* pCreateInfo,
D3D9VkQueueFamilies* pQueueFamilies);
UINT Adapter,
VkDeviceCreateInfo* pCreateInfo,
D3D9VkQueueFamilies* pQueueFamilies,
VkPhysicalDeviceFeatures2* pFeatures);

HRESULT STDMETHODCALLTYPE ImportDevice(
UINT Adapter,
Expand All @@ -52,6 +55,7 @@ namespace dxvk {
private:

D3D9InterfaceEx* m_interface;
std::unordered_map<UINT, DxvkDeviceCreateInfo> m_deviceCreateInfos;

};

Expand Down
17 changes: 8 additions & 9 deletions src/dxvk/dxvk_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ namespace dxvk {

bool DxvkAdapter::getDeviceCreateInfo(
const Rc<DxvkInstance>& instance,
DxvkDeviceFeatures enabledFeatures,
DxvkDeviceFeatures baseEnabledFeatures,
bool logDeviceInfo,
DxvkDeviceCreateInfo& createInfo) const {
auto& [info, queueFamilies, extensionsEnabled, devExtensions, enableCudaInterop] = createInfo;
auto& [info, queueFamilies, extensionsEnabled, extensionNameList, devExtensions, enableCudaInterop, queueInfos, enabledFeatures] = createInfo;

enabledFeatures = baseEnabledFeatures;

auto devExtensionList = getExtensionList(devExtensions);

Expand Down Expand Up @@ -309,7 +311,7 @@ namespace dxvk {

// Enable additional extensions if necessary
extensionsEnabled.merge(m_extraExtensions);
DxvkNameList extensionNameList = extensionsEnabled.toNameList();
extensionNameList = extensionsEnabled.toNameList();

// Always enable robust buffer access
enabledFeatures.core.features.robustBufferAccess = VK_TRUE;
Expand Down Expand Up @@ -461,8 +463,6 @@ namespace dxvk {

// Create the requested queues
float queuePriority = 1.0f;
std::vector<VkDeviceQueueCreateInfo> queueInfos;

std::unordered_set<uint32_t> queueFamiliySet;

queueFamilies = findQueueFamilies();
Expand Down Expand Up @@ -504,7 +504,7 @@ namespace dxvk {
if (!getDeviceCreateInfo(instance, enabledFeatures, true, createInfo))
throw DxvkError("DxvkAdapter: Failed to create device");

auto& [info, queueFamilies, extensionsEnabled, devExtensions, enableCudaInterop] = createInfo;
auto& [info, queueFamilies, extensionsEnabled, extensionNameList, devExtensions, enableCudaInterop, queueInfos, features] = createInfo;

VkDevice device = VK_NULL_HANDLE;
VkResult vr = m_vki->vkCreateDevice(m_handle, &info, nullptr, &device);
Expand All @@ -518,9 +518,8 @@ namespace dxvk {
extensionsEnabled.disableExtension(devExtensions.nvxBinaryImport);
extensionsEnabled.disableExtension(devExtensions.nvxImageViewHandle);

enabledFeatures.vk12.bufferDeviceAddress = VK_FALSE;
features.vk12.bufferDeviceAddress = VK_FALSE;

DxvkNameList extensionNameList = extensionsEnabled.toNameList();
info.enabledExtensionCount = extensionNameList.count();
info.ppEnabledExtensionNames = extensionNameList.names();

Expand All @@ -537,7 +536,7 @@ namespace dxvk {
queues.transfer = getDeviceQueue(vkd, queueFamilies.transfer, 0);
queues.sparse = getDeviceQueue(vkd, queueFamilies.sparse, 0);

return new DxvkDevice(instance, this, vkd, enabledFeatures, queues, DxvkQueueCallback());
return new DxvkDevice(instance, this, vkd, features, queues, DxvkQueueCallback());
}


Expand Down
13 changes: 8 additions & 5 deletions src/dxvk/dxvk_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ namespace dxvk {
* \brief Device create info
*/
struct DxvkDeviceCreateInfo {
VkDeviceCreateInfo info;
DxvkAdapterQueueIndices queueFamilies;
DxvkNameSet extensionsEnabled;
DxvkDeviceExtensions devExtensions;
bool enableCudaInterop;
VkDeviceCreateInfo info;
DxvkAdapterQueueIndices queueFamilies;
DxvkNameSet extensionsEnabled;
DxvkNameList extensionNameList;
DxvkDeviceExtensions devExtensions;
bool enableCudaInterop;
std::vector<VkDeviceQueueCreateInfo> queueInfos;
DxvkDeviceFeatures features;
};

/**
Expand Down

0 comments on commit 998ae8d

Please sign in to comment.