Skip to content

Commit

Permalink
[d3d9] Add GetInstanceExtensions to interop API
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpyneDreams authored and doitsujin committed Dec 9, 2024
1 parent 45da7d6 commit d1abce3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/d3d9/d3d9_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ namespace dxvk {
return S_OK;
}

if (riid == __uuidof(ID3D9VkInteropInterface)) {
if (riid == __uuidof(ID3D9VkInteropInterface)
|| riid == __uuidof(ID3D9VkInteropInterface1)) {
*ppvObject = ref(&m_d3d9Interop);
return S_OK;
}
Expand Down
21 changes: 21 additions & 0 deletions src/d3d9/d3d9_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ ID3D9VkInteropInterface : public IUnknown {
VkPhysicalDevice* pPhysicalDevice) = 0;
};

/**
* \brief D3D9 interface for Vulkan interop - extended
*
* Provides access to the instance extension lists
* and everything provided by ID3D9VkInteropInterface
*/
MIDL_INTERFACE("d6589ed4-7a37-4096-bac2-223b25ae31d2")
ID3D9VkInteropInterface1 : public ID3D9VkInteropInterface {
/**
* \brief Gets a list of enabled instance extensions
*
* \param [out] pExtensionCount Number of extensions
* \param [out] ppExtensions List of extension names
* \returns D3DERR_MOREDATA if the list was truncated
*/
virtual HRESULT STDMETHODCALLTYPE GetInstanceExtensions(
UINT* pExtensionCount,
const char** ppExtensions) = 0;
};

/**
* \brief D3D9 texture interface for Vulkan interop
*
Expand Down Expand Up @@ -263,6 +283,7 @@ ID3D9VkExtSwapchain : public IUnknown {

#ifndef _MSC_VER
__CRT_UUID_DECL(ID3D9VkInteropInterface, 0x3461a81b,0xce41,0x485b,0xb6,0xb5,0xfc,0xf0,0x8b,0xa6,0xa6,0xbd);
__CRT_UUID_DECL(ID3D9VkInteropInterface1, 0xd6589ed4,0x7a37,0x4096,0xba,0xc2,0x22,0x3b,0x25,0xae,0x31,0xd2);
__CRT_UUID_DECL(ID3D9VkInteropTexture, 0xd56344f5,0x8d35,0x46fd,0x80,0x6d,0x94,0xc3,0x51,0xb4,0x72,0xc1);
__CRT_UUID_DECL(ID3D9VkInteropDevice, 0x2eaa4b89,0x0107,0x4bdb,0x87,0xf7,0x0f,0x54,0x1c,0x49,0x3c,0xe0);
__CRT_UUID_DECL(ID3D9VkExtSwapchain, 0x13776e93,0x4aa9,0x430a,0xa4,0xec,0xfe,0x9e,0x28,0x11,0x81,0xd5);
Expand Down
25 changes: 25 additions & 0 deletions src/d3d9/d3d9_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@ namespace dxvk {
}
}

HRESULT STDMETHODCALLTYPE D3D9VkInteropInterface::GetInstanceExtensions(
UINT* pExtensionCount,
const char** ppExtensions) {
if (pExtensionCount == nullptr)
return D3DERR_INVALIDCALL;

const DxvkNameList& extensions = m_interface->GetInstance()->extensionNameList();

if (ppExtensions == nullptr) {
*pExtensionCount = extensions.count();
return D3D_OK;
}

// Write
UINT count = 0;
UINT maxCount = *pExtensionCount;
for (uint32_t i = 0; i < extensions.count() && i < maxCount; i++) {
ppExtensions[i] = extensions.name(i);
count++;
}

*pExtensionCount = count;
return (count < maxCount) ? D3DERR_MOREDATA : D3D_OK;
}

////////////////////////////////
// Texture Interop
///////////////////////////////
Expand Down
6 changes: 5 additions & 1 deletion src/d3d9/d3d9_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace dxvk {
class D3D9DeviceEx;
struct D3D9_COMMON_TEXTURE_DESC;

class D3D9VkInteropInterface final : public ID3D9VkInteropInterface {
class D3D9VkInteropInterface final : public ID3D9VkInteropInterface1 {

public:

Expand All @@ -34,6 +34,10 @@ namespace dxvk {
UINT Adapter,
VkPhysicalDevice* pPhysicalDevice);

HRESULT STDMETHODCALLTYPE GetInstanceExtensions(
UINT* pExtensionCount,
const char** ppExtensions);

private:

D3D9InterfaceEx* m_interface;
Expand Down
13 changes: 6 additions & 7 deletions src/dxvk/dxvk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ namespace dxvk {

void DxvkInstance::createInstanceLoader(const DxvkInstanceImportInfo& args, DxvkInstanceFlags flags) {
DxvkNameList layerList;
DxvkNameList extensionList;
DxvkNameSet extensionSet;

bool enablePerfEvents = false;
bool enableValidation = false;

if (args.instance) {
extensionList = DxvkNameList(args.extensionCount, args.extensionNames);
extensionSet = getExtensionSet(extensionList);
m_extensionNames = DxvkNameList(args.extensionCount, args.extensionNames);
extensionSet = getExtensionSet(m_extensionNames);

auto extensionInfos = getExtensionList(m_extensions, true);

Expand Down Expand Up @@ -168,11 +167,11 @@ namespace dxvk {
extensionSet.merge(provider->getInstanceExtensions());

// Generate list of extensions to enable
extensionList = extensionSet.toNameList();
m_extensionNames = extensionSet.toNameList();
}

Logger::info("Enabled instance extensions:");
this->logNameList(extensionList);
this->logNameList(m_extensionNames);

// If necessary, create a new Vulkan instance
VkInstance instance = args.instance;
Expand All @@ -191,8 +190,8 @@ namespace dxvk {
info.pApplicationInfo = &appInfo;
info.enabledLayerCount = layerList.count();
info.ppEnabledLayerNames = layerList.names();
info.enabledExtensionCount = extensionList.count();
info.ppEnabledExtensionNames = extensionList.names();
info.enabledExtensionCount = m_extensionNames.count();
info.ppEnabledExtensionNames = m_extensionNames.names();

VkResult status = m_vkl->vkCreateInstance(&info, nullptr, &instance);

Expand Down
13 changes: 13 additions & 0 deletions src/dxvk/dxvk_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ namespace dxvk {
const DxvkInstanceExtensions& extensions() const {
return m_extensions;
}

/**
* \brief Instance extension name list
*
* Returns the list of extensions that the
* instance was created with, provided by
* both DXVK and any extension providers.
* \returns Instance extension name list
*/
const DxvkNameList& extensionNameList() const {
return m_extensionNames;
}

private:

Expand All @@ -153,6 +165,7 @@ namespace dxvk {
Rc<vk::LibraryFn> m_vkl;
Rc<vk::InstanceFn> m_vki;
DxvkInstanceExtensions m_extensions;
DxvkNameList m_extensionNames;

VkDebugUtilsMessengerEXT m_messenger = VK_NULL_HANDLE;

Expand Down

0 comments on commit d1abce3

Please sign in to comment.