[GPU] Removed nvapi
- According to reports d3d12_nvapi_use_driver_heap_priorities give no benefit
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
#pragma once
|
||||
// requires windows.h
|
||||
#include <stdint.h>
|
||||
|
||||
namespace lightweight_nvapi {
|
||||
|
||||
using nvstatus_t = int;
|
||||
|
||||
using nvintfid_t = unsigned int;
|
||||
|
||||
#ifndef LIGHTWEIGHT_NVAPI_EXCLUDE_D3D12
|
||||
constexpr nvintfid_t id_NvAPI_D3D12_QueryCpuVisibleVidmem = 0x26322BC3;
|
||||
|
||||
using cb_NvAPI_D3D12_QueryCpuVisibleVidmem = nvstatus_t (*)(
|
||||
ID3D12Device* pDevice, uint64_t* pTotalBytes, uint64_t* pFreeBytes);
|
||||
|
||||
constexpr nvintfid_t id_NvAPI_D3D12_UseDriverHeapPriorities = 0xF0D978A8;
|
||||
using cb_NvAPI_D3D12_UseDriverHeapPriorities =
|
||||
nvstatus_t (*)(ID3D12Device* pDevice);
|
||||
enum NV_D3D12_RESOURCE_FLAGS {
|
||||
NV_D3D12_RESOURCE_FLAG_NONE = 0,
|
||||
NV_D3D12_RESOURCE_FLAG_HTEX = 1, //!< Create HTEX texture
|
||||
NV_D3D12_RESOURCE_FLAG_CPUVISIBLE_VIDMEM =
|
||||
2, //!< Hint to create resource in cpuvisible vidmem
|
||||
};
|
||||
|
||||
struct NV_RESOURCE_PARAMS {
|
||||
uint32_t version; //!< Version of structure. Must always be first member
|
||||
NV_D3D12_RESOURCE_FLAGS
|
||||
NVResourceFlags; //!< Additional NV specific flags (set the
|
||||
//!< NV_D3D12_RESOURCE_FLAG_HTEX bit to create HTEX
|
||||
//!< texture)
|
||||
};
|
||||
|
||||
using cb_NvAPI_D3D12_CreateCommittedResource = nvstatus_t (*)(
|
||||
ID3D12Device* pDevice, const D3D12_HEAP_PROPERTIES* pHeapProperties,
|
||||
D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC* pDesc,
|
||||
D3D12_RESOURCE_STATES InitialState,
|
||||
const D3D12_CLEAR_VALUE* pOptimizedClearValue,
|
||||
const NV_RESOURCE_PARAMS* pNVResourceParams, REFIID riid,
|
||||
void** ppvResource, bool* pSupported);
|
||||
constexpr nvintfid_t id_NvAPI_D3D12_CreateCommittedResource = 0x27E98AEu;
|
||||
#endif
|
||||
class nvapi_state_t {
|
||||
HMODULE nvapi64_;
|
||||
void* (*queryinterface_)(unsigned int intfid);
|
||||
bool available_;
|
||||
bool init_ptrs();
|
||||
|
||||
bool call_init_interface();
|
||||
void call_deinit_interface();
|
||||
|
||||
public:
|
||||
nvapi_state_t() : nvapi64_(LoadLibraryA("nvapi64.dll")), available_(false) {
|
||||
available_ = init_ptrs();
|
||||
}
|
||||
~nvapi_state_t();
|
||||
template <typename T>
|
||||
T* query_interface(unsigned int intfid) {
|
||||
if (queryinterface_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<T*>(queryinterface_(intfid));
|
||||
}
|
||||
|
||||
bool is_available() const { return available_; }
|
||||
};
|
||||
inline bool nvapi_state_t::call_init_interface() {
|
||||
int result = -1;
|
||||
auto initInterfaceEx = query_interface<int(int)>(0xAD298D3F);
|
||||
if (!initInterfaceEx) {
|
||||
auto initInterface = query_interface<int()>(0x150E828u);
|
||||
if (initInterface) {
|
||||
result = initInterface();
|
||||
}
|
||||
} else {
|
||||
result = initInterfaceEx(0);
|
||||
}
|
||||
return result == 0;
|
||||
}
|
||||
inline void nvapi_state_t::call_deinit_interface() {
|
||||
auto deinitinterfaceex = query_interface<void(int)>(0xD7C61344);
|
||||
if (deinitinterfaceex) {
|
||||
deinitinterfaceex(1); // or 0? im not sure what the proper value is
|
||||
} else {
|
||||
auto deinitinterface = query_interface<void()>(0xD22BDD7E);
|
||||
if (deinitinterface) {
|
||||
deinitinterface();
|
||||
}
|
||||
}
|
||||
}
|
||||
inline bool nvapi_state_t::init_ptrs() {
|
||||
if (!nvapi64_) return false;
|
||||
queryinterface_ = reinterpret_cast<void* (*)(unsigned)>(
|
||||
GetProcAddress(nvapi64_, "nvapi_QueryInterface"));
|
||||
|
||||
if (!queryinterface_) {
|
||||
return false;
|
||||
}
|
||||
if (!call_init_interface()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
inline nvapi_state_t::~nvapi_state_t() {
|
||||
if (available_) {
|
||||
call_deinit_interface();
|
||||
}
|
||||
}
|
||||
} // namespace lightweight_nvapi
|
||||
@@ -34,8 +34,6 @@ DEFINE_int32(
|
||||
"system responsibility)",
|
||||
"D3D12");
|
||||
|
||||
DEFINE_bool(d3d12_nvapi_use_driver_heap_priorities, false, "nvidia stuff",
|
||||
"D3D12");
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
namespace d3d12 {
|
||||
@@ -480,59 +478,14 @@ bool D3D12Provider::Initialize() {
|
||||
// Get the graphics analysis interface, will silently fail if PIX is not
|
||||
// attached.
|
||||
pfn_dxgi_get_debug_interface1_(0, IID_PPV_ARGS(&graphics_analysis_));
|
||||
if (GetAdapterVendorID() == ui::GraphicsProvider::GpuVendorID::kNvidia) {
|
||||
nvapi_ = new lightweight_nvapi::nvapi_state_t();
|
||||
if (!nvapi_->is_available()) {
|
||||
delete nvapi_;
|
||||
nvapi_ = nullptr;
|
||||
} else {
|
||||
using namespace lightweight_nvapi;
|
||||
|
||||
nvapi_createcommittedresource_ =
|
||||
(cb_NvAPI_D3D12_CreateCommittedResource)nvapi_->query_interface<void>(
|
||||
id_NvAPI_D3D12_CreateCommittedResource);
|
||||
nvapi_querycpuvisiblevidmem_ =
|
||||
(cb_NvAPI_D3D12_QueryCpuVisibleVidmem)nvapi_->query_interface<void>(
|
||||
id_NvAPI_D3D12_QueryCpuVisibleVidmem);
|
||||
nvapi_usedriverheappriorities_ =
|
||||
(cb_NvAPI_D3D12_UseDriverHeapPriorities)nvapi_->query_interface<void>(
|
||||
id_NvAPI_D3D12_UseDriverHeapPriorities);
|
||||
|
||||
if (nvapi_usedriverheappriorities_) {
|
||||
if (cvars::d3d12_nvapi_use_driver_heap_priorities) {
|
||||
if (nvapi_usedriverheappriorities_(device_) != 0) {
|
||||
XELOGI("Failed to enable driver heap priorities");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
uint32_t D3D12Provider::CreateUploadResource(
|
||||
D3D12_HEAP_FLAGS HeapFlags, _In_ const D3D12_RESOURCE_DESC* pDesc,
|
||||
D3D12_RESOURCE_STATES InitialResourceState, REFIID riidResource,
|
||||
void** ppvResource, bool try_create_cpuvisible,
|
||||
const D3D12_CLEAR_VALUE* pOptimizedClearValue) const {
|
||||
void** ppvResource, const D3D12_CLEAR_VALUE* pOptimizedClearValue) const {
|
||||
auto device = GetDevice();
|
||||
|
||||
if (try_create_cpuvisible && nvapi_createcommittedresource_) {
|
||||
lightweight_nvapi::NV_RESOURCE_PARAMS nvrp;
|
||||
nvrp.NVResourceFlags =
|
||||
lightweight_nvapi::NV_D3D12_RESOURCE_FLAG_CPUVISIBLE_VIDMEM;
|
||||
nvrp.version = 0; // nothing checks the version
|
||||
|
||||
if (nvapi_createcommittedresource_(
|
||||
device, &ui::d3d12::util::kHeapPropertiesUpload, HeapFlags, pDesc,
|
||||
InitialResourceState, pOptimizedClearValue, &nvrp, riidResource,
|
||||
ppvResource, nullptr) != 0) {
|
||||
XELOGI(
|
||||
"Failed to create CPUVISIBLE_VIDMEM upload resource, will just do "
|
||||
"normal CreateCommittedResource");
|
||||
} else {
|
||||
return UPLOAD_RESULT_CREATE_CPUVISIBLE;
|
||||
}
|
||||
}
|
||||
if (FAILED(device->CreateCommittedResource(
|
||||
&ui::d3d12::util::kHeapPropertiesUpload, HeapFlags, pDesc,
|
||||
InitialResourceState, pOptimizedClearValue, riidResource,
|
||||
|
||||
@@ -15,12 +15,6 @@
|
||||
#include "xenia/ui/d3d12/d3d12_api.h"
|
||||
#include "xenia/ui/graphics_provider.h"
|
||||
|
||||
// chrispy: this is here to prevent clang format from moving d3d12_nvapi above
|
||||
// the headers it depends on
|
||||
#define HEADERFENCE
|
||||
#undef HEADERFENCE
|
||||
#include "xenia/gpu/d3d12/d3d12_nvapi.hpp"
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
namespace d3d12 {
|
||||
@@ -47,7 +41,7 @@ class D3D12Provider : public GraphicsProvider {
|
||||
uint32_t CreateUploadResource(
|
||||
D3D12_HEAP_FLAGS HeapFlags, _In_ const D3D12_RESOURCE_DESC* pDesc,
|
||||
D3D12_RESOURCE_STATES InitialResourceState, REFIID riidResource,
|
||||
void** ppvResource, bool try_create_cpuvisible = false,
|
||||
void** ppvResource,
|
||||
const D3D12_CLEAR_VALUE* pOptimizedClearValue = nullptr) const;
|
||||
|
||||
IDXGIFactory2* GetDXGIFactory() const { return dxgi_factory_; }
|
||||
@@ -247,14 +241,6 @@ class D3D12Provider : public GraphicsProvider {
|
||||
bool ps_specified_stencil_reference_supported_;
|
||||
bool rasterizer_ordered_views_supported_;
|
||||
bool unaligned_block_textures_supported_;
|
||||
|
||||
lightweight_nvapi::nvapi_state_t* nvapi_;
|
||||
lightweight_nvapi::cb_NvAPI_D3D12_CreateCommittedResource
|
||||
nvapi_createcommittedresource_ = nullptr;
|
||||
lightweight_nvapi::cb_NvAPI_D3D12_UseDriverHeapPriorities
|
||||
nvapi_usedriverheappriorities_ = nullptr;
|
||||
lightweight_nvapi::cb_NvAPI_D3D12_QueryCpuVisibleVidmem
|
||||
nvapi_querycpuvisiblevidmem_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace d3d12
|
||||
|
||||
Reference in New Issue
Block a user