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 c4bf3d0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
21 changes: 12 additions & 9 deletions src/d3d9/d3d9_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using D3D9VkQueueLockCallback = void(bool);

/**
* \brief Device queue info
* \brief Device create info
*/
struct D3D9VkQueueFamilies {
uint32_t graphics;
uint32_t transfer;
uint32_t sparse;
struct D3D9VkDeviceCreateInfo {
VkDeviceCreateInfo* info;
VkPhysicalDeviceFeatures2* features;
uint32_t graphics;
uint32_t transfer;
uint32_t sparse;
};

/**
Expand Down Expand Up @@ -62,14 +64,15 @@ ID3D9VkInteropInterface : public IUnknown {
/**
* \brief Gets the VkDeviceCreateInfo for a D3D9 adapter
*
* Pointers returned are guaranteed to be valid until
* the next call to GetDeviceCreateInfo or Release.
*
* \param [in] Adapter Adapter ordinal
* \param [out] pCreateInfo The Vulkan device create info
* \param [out] pQueueFamilies The required queue families
*/
virtual HRESULT STDMETHODCALLTYPE GetDeviceCreateInfo(
UINT Adapter,
VkDeviceCreateInfo* pCreateInfo,
D3D9VkQueueFamilies* pQueueFamilies) = 0;
UINT Adapter,
D3D9VkDeviceCreateInfo* pCreateInfo) = 0;

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

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

auto* adapter = m_interface->GetAdapter(Adapter);
Expand All @@ -65,18 +64,18 @@ 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)
*pCreateInfo = createInfo.info;
createInfo.info.enabledLayerCount = 0;
createInfo.info.ppEnabledLayerNames = nullptr;

if (pQueueFamilies != nullptr) {
pQueueFamilies->graphics = createInfo.queueFamilies.graphics;
pQueueFamilies->transfer = createInfo.queueFamilies.transfer;
pQueueFamilies->sparse = createInfo.queueFamilies.sparse;
}
pCreateInfo->info = &createInfo.info;
pCreateInfo->features = &createInfo.features.core;
pCreateInfo->graphics = createInfo.queueFamilies.graphics;
pCreateInfo->transfer = createInfo.queueFamilies.transfer;
pCreateInfo->sparse = createInfo.queueFamilies.sparse;

return D3D_OK;
}
Expand Down
8 changes: 5 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,8 @@ namespace dxvk {
VkPhysicalDevice* pPhysicalDevice);

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

HRESULT STDMETHODCALLTYPE ImportDevice(
UINT Adapter,
Expand All @@ -52,6 +53,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 c4bf3d0

Please sign in to comment.