Skip to content

Commit

Permalink
Merge branch 'sultimt/checked-init' into 'main'
Browse files Browse the repository at this point in the history
[REMIX-2695] More precise error codes to check initialization failures

See merge request lightspeedrtx/dxvk-remix-nv!688
  • Loading branch information
sultim-t-nv committed Jan 29, 2024
2 parents 5962b89 + 9935d14 commit fad42e6
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 9 deletions.
2 changes: 2 additions & 0 deletions public/include/remix/remix.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ namespace remix {
remixapi_ErrorCode status = pfn_InitializeLibrary(&info, &interfaceInC);

if (status != REMIXAPI_ERROR_CODE_SUCCESS) {
FreeLibrary(remixDll);
return status;
}

Expand All @@ -233,6 +234,7 @@ namespace remix {
return interfaceInCpp;
}

FreeLibrary(remixDll);
return REMIXAPI_ERROR_CODE_GET_PROC_ADDRESS_FAILURE;
}

Expand Down
7 changes: 7 additions & 0 deletions public/include/remix/remix_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ extern "C" {
// RegisterD3D9Device was not called
REMIXAPI_ERROR_CODE_REMIX_DEVICE_WAS_NOT_REGISTERED = 7,
REMIXAPI_ERROR_CODE_INCOMPATIBLE_VERSION = 8,
// Error codes that are encoded as HRESULT, i.e. returned from D3D9 functions.
// Look MAKE_D3DHRESULT, but with _FACD3D=0x896, instead of D3D9's 0x876
REMIXAPI_ERROR_CODE_HRESULT_NO_REQUIRED_GPU_FEATURES = 0x88960001,
REMIXAPI_ERROR_CODE_HRESULT_DRIVER_VERSION_BELOW_MINIMUM = 0x88960002,
REMIXAPI_ERROR_CODE_HRESULT_DXVK_INSTANCE_EXTENSION_FAIL = 0x88960003,
REMIXAPI_ERROR_CODE_HRESULT_VK_CREATE_INSTANCE_FAIL = 0x88960004,
REMIXAPI_ERROR_CODE_HRESULT_VK_CREATE_DEVICE_FAIL = 0x88960005,
} remixapi_ErrorCode;

typedef uint32_t remixapi_Bool;
Expand Down
6 changes: 6 additions & 0 deletions src/d3d9/d3d9_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ namespace dxvk {

*ppReturnedDeviceInterface = ref(device);
}
// NV-DXVK start: provide error code on exception
catch (const DxvkErrorWithId& e) {
Logger::err(e.message());
return e.id();
}
// NV-DXVK end
catch (const DxvkError& e) {
Logger::err(e.message());
return D3DERR_NOTAVAILABLE;
Expand Down
14 changes: 12 additions & 2 deletions src/d3d9/d3d9_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ namespace dxvk {
if (!ppDirect3D9Ex)
return D3DERR_INVALIDCALL;

// NV-DXVK start: external API
*ppDirect3D9Ex = ref(new D3D9InterfaceEx(Extended, WithExternalSwapchain, WithDrawCallConversion));
// NV-DXVK start: external API / provide error code on exception
try {
*ppDirect3D9Ex = ref(new D3D9InterfaceEx(Extended, WithExternalSwapchain, WithDrawCallConversion));
}
catch (const dxvk::DxvkErrorWithId& err) {
Logger::err(err.message());
return err.id();
}
catch (const dxvk::DxvkError& err) {
dxvk::Logger::err(err.message());
return D3DERR_NOTAVAILABLE;
}
// NV-DXVK end
return D3D_OK;
}
Expand Down
19 changes: 15 additions & 4 deletions src/dxvk/dxvk_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
// NV-DXVK start: Remix message box utilities
#include "rtx_render/rtx_env.h"
// NV-DXVK end:
// NV-DXVK start: Provide error code on exception
#include <remix/remix_c.h>
// NV-DXVK end

namespace dxvk {

Expand Down Expand Up @@ -415,7 +418,9 @@ namespace dxvk {
messageBox("Your GPU doesn't support the required features to run RTX Remix. See the *_d3d9.log for what features your GPU doesn't support. The game will exit now.", "RTX Remix - GPU Feature Error!", MB_OK);
// NV-DXVK end

throw DxvkError("DxvkAdapter: Failed to create device");
// NV-DXVK start: Provide error code on exception
throw DxvkErrorWithId(REMIXAPI_ERROR_CODE_HRESULT_NO_REQUIRED_GPU_FEATURES, "DxvkAdapter: Failed to create device");
// NV-DXVK end
}

// NV-DXVK start: Integrate Aftermath extensions
Expand Down Expand Up @@ -495,7 +500,9 @@ namespace dxvk {
RtxIoExtensionProvider::s_instance.initDeviceExtensions(instance.ptr());
if (!RtxIoExtensionProvider::s_instance.getDeviceFeatures(m_handle, enabledFeatures)) {
Logger::err("Physical device does not support features required to enable RTX IO.");
throw DxvkError("DxvkAdapter: Failed to create device");
// NV-DXVK start: Provide error code on exception
throw DxvkErrorWithId(REMIXAPI_ERROR_CODE_HRESULT_NO_REQUIRED_GPU_FEATURES, "DxvkAdapter: Failed to create device");
// NV-DXVK end
}
}
#endif
Expand Down Expand Up @@ -657,7 +664,9 @@ namespace dxvk {

messageBox(minDriverCheckDialogMessage.c_str(), "RTX Remix - Driver Compatibility Error!", MB_OK);

throw DxvkError("DxvkAdapter: Failed to create device");
// NV-DXVK start: Provide error code on exception
throw DxvkErrorWithId(REMIXAPI_ERROR_CODE_HRESULT_DRIVER_VERSION_BELOW_MINIMUM, "DxvkAdapter: Failed to create device");
// NV-DXVK end
}
}
// NV-DXVK end
Expand Down Expand Up @@ -767,7 +776,9 @@ namespace dxvk {
}

if (vr != VK_SUCCESS)
throw DxvkError("DxvkAdapter: Failed to create device");
// NV-DXVK start: Provide error code on exception
throw DxvkErrorWithId(REMIXAPI_ERROR_CODE_HRESULT_VK_CREATE_DEVICE_FAIL, "DxvkAdapter: Failed to create device");
// NV-DXVK end

Rc<DxvkDevice> result = new DxvkDevice(instance, this,
new vk::DeviceFn(true, m_vki->instance(), device),
Expand Down
12 changes: 10 additions & 2 deletions src/dxvk/dxvk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#include "rtx_render/rtx_io.h"
// NV-DXVK end

// NV-DXVK start: Provide error code on exception
#include <remix/remix_c.h>
// NV-DXVK end

namespace dxvk {
bool filterErrorMessages(const char* message) {
// validation errors that we are currently ignoring --- to fix!
Expand Down Expand Up @@ -373,7 +377,9 @@ namespace dxvk {
insExtensionList.size(),
insExtensionList.data(),
extensionsEnabled))
throw DxvkError("DxvkInstance: Failed to create instance");
// NV-DXVK start: Provide error code on exception
throw DxvkErrorWithId(REMIXAPI_ERROR_CODE_HRESULT_DXVK_INSTANCE_EXTENSION_FAIL, "DxvkInstance: Failed to create instance");
// NV-DXVK end

m_extensions = insExtensions;

Expand Down Expand Up @@ -454,7 +460,9 @@ namespace dxvk {
VkResult status = m_vkl->vkCreateInstance(&info, nullptr, &result);

if (status != VK_SUCCESS)
throw DxvkError("DxvkInstance::createInstance: Failed to create Vulkan 1.3 instance");
// NV-DXVK start: Provide error code on exception
throw DxvkErrorWithId(REMIXAPI_ERROR_CODE_HRESULT_VK_CREATE_INSTANCE_FAIL, "DxvkInstance::createInstance: Failed to create Vulkan 1.3 instance");
// NV-DXVK end

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/rtx_render/rtx_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace dxvk {
// Note: Respect the blocking dialog box disable flag when attempting to open this message box to not
// cause blocking on user input when not desired.
if (!RtxOptions::Automation::disableBlockingDialogBoxes()) {
MessageBox(NULL, text, caption, type);
MessageBox(NULL, text, caption, type | MB_ICONSTOP);
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/dxvk/rtx_render/rtx_remix_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ namespace {
}


bool isHResultAliasedWithRemixErrorCode(HRESULT hr) {
switch (hr) {
case REMIXAPI_ERROR_CODE_HRESULT_NO_REQUIRED_GPU_FEATURES:
case REMIXAPI_ERROR_CODE_HRESULT_DRIVER_VERSION_BELOW_MINIMUM:
case REMIXAPI_ERROR_CODE_HRESULT_DXVK_INSTANCE_EXTENSION_FAIL:
case REMIXAPI_ERROR_CODE_HRESULT_VK_CREATE_INSTANCE_FAIL:
case REMIXAPI_ERROR_CODE_HRESULT_VK_CREATE_DEVICE_FAIL: return true;
default: return false;
}
}


void sanitizeConfigs() {
// Disable fallback light
const_cast<dxvk::LightManager::FallbackLightMode&>(dxvk::LightManager::fallbackLightMode()) = dxvk::LightManager::FallbackLightMode::Never;
Expand Down Expand Up @@ -1044,6 +1056,9 @@ namespace {
IDirect3D9Ex* d3d9ex = nullptr;
auto hr = dxvk::CreateD3D9(true, &d3d9ex, true, false);
if (FAILED(hr) || !d3d9ex) {
if (isHResultAliasedWithRemixErrorCode(hr)) {
return static_cast<remixapi_ErrorCode>(hr);
}
return REMIXAPI_ERROR_CODE_GENERAL_FAILURE;
}

Expand Down
22 changes: 22 additions & 0 deletions src/util/util_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,27 @@ namespace dxvk {
std::string m_message;

};

// NV-DXVK start: Provide error code on exception
class DxvkErrorWithId : public DxvkError {
public:
DxvkErrorWithId(int id, std::string&& message)
: DxvkError { std::move(message) }
, m_id { id } {}
~DxvkErrorWithId() = default;

DxvkErrorWithId(DxvkErrorWithId&&) = delete;
DxvkErrorWithId& operator=(DxvkErrorWithId&&) = delete;
DxvkErrorWithId(const DxvkErrorWithId&) = delete;
DxvkErrorWithId& operator=(const DxvkErrorWithId&&) = delete;

int id() const {
return m_id;
}

private:
int m_id {};
};
// NV-DXVK end

}

0 comments on commit fad42e6

Please sign in to comment.