Skip to content

Commit

Permalink
[dxgi] Add option to limit reported device memory size
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Aug 24, 2018
1 parent 4869734 commit 57db0b6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
33 changes: 20 additions & 13 deletions src/dxgi/dxgi_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,25 @@ namespace dxvk {
if (pDesc == nullptr)
return DXGI_ERROR_INVALID_CALL;

const DxgiOptions* options = m_factory->GetOptions();

auto deviceProp = m_adapter->deviceProperties();
auto memoryProp = m_adapter->memoryProperties();

// Custom Vendor / Device ID
const int32_t customVendorID = m_factory->GetOptions()->customVendorId;
const int32_t customDeviceID = m_factory->GetOptions()->customDeviceId;

if (customVendorID >= 0) {
Logger::info(str::format("Using Custom PCI Vendor ID ", std::hex, customVendorID));
deviceProp.vendorID = customVendorID;
}
if (options->customVendorId >= 0)
deviceProp.vendorID = options->customVendorId;

if (customDeviceID >= 0) {
Logger::info(str::format("Using Custom PCI Device ID ", std::hex, customDeviceID));
deviceProp.deviceID = customDeviceID;
}
if (options->customDeviceId >= 0)
deviceProp.deviceID = options->customDeviceId;

// Convert device name
std::memset(pDesc->Description, 0, sizeof(pDesc->Description));
::MultiByteToWideChar(CP_UTF8, 0, deviceProp.deviceName, -1, pDesc->Description,
sizeof(pDesc->Description));
::MultiByteToWideChar(CP_UTF8, 0, deviceProp.deviceName, -1,
pDesc->Description, sizeof(pDesc->Description));

// Get amount of video memory
// based on the Vulkan heaps
VkDeviceSize deviceMemory = 0;
VkDeviceSize sharedMemory = 0;

Expand All @@ -176,6 +174,15 @@ namespace dxvk {
sharedMemory += heap.size;
}

// Some games are silly and need their memory limited
if (options->maxDeviceMemory > 0
&& options->maxDeviceMemory < deviceMemory)
deviceMemory = options->maxDeviceMemory;

if (options->maxSharedMemory > 0
&& options->maxSharedMemory < sharedMemory)
sharedMemory = options->maxSharedMemory;

#ifndef _WIN64
// The value returned by DXGI is a 32-bit value
// on 32-bit platforms, so we need to clamp it
Expand Down
10 changes: 8 additions & 2 deletions src/dxgi/dxgi_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ namespace dxvk {
DxgiOptions::DxgiOptions(const Config& config) {
this->deferSurfaceCreation = config.getOption<bool> ("dxgi.deferSurfaceCreation", false);
this->maxFrameLatency = config.getOption<int32_t> ("dxgi.maxFrameLatency", 0);
this->customVendorId = parsePciId(config.getOption<std::string>("dxgi.customVendorId"));
this->customDeviceId = parsePciId(config.getOption<std::string>("dxgi.customDeviceId"));

// Fetch these as a string representing a hexadecimal number and parse it.
this->customVendorId = parsePciId(config.getOption<std::string>("dxgi.customVendorId"));
this->customDeviceId = parsePciId(config.getOption<std::string>("dxgi.customDeviceId"));

// Interpret the memory limits as Megabytes
this->maxDeviceMemory = VkDeviceSize(config.getOption<int32_t>("dxgi.maxDeviceMemory", 0)) << 20;
this->maxSharedMemory = VkDeviceSize(config.getOption<int32_t>("dxgi.maxSharedMemory", 0)) << 20;
}

}
8 changes: 8 additions & 0 deletions src/dxgi/dxgi_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "../util/config/config.h"

#include "../dxvk/dxvk_include.h"

#include "dxgi_include.h"

namespace dxvk {
Expand Down Expand Up @@ -29,6 +31,12 @@ namespace dxvk {
/// on a different GPU than they do and behave differently.
int32_t customVendorId;
int32_t customDeviceId;

/// Override maximum reported VRAM size. This may be
/// useful for some 64-bit games which do not support
/// more than 4 GiB of VRAM.
VkDeviceSize maxDeviceMemory;
VkDeviceSize maxSharedMemory;
};

}

0 comments on commit 57db0b6

Please sign in to comment.