Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/Extensions/NRIDeviceCreation.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ NriStruct(AllocationCallbacks) {

NriStruct(CallbackInterface) {
void (NRI_CALL *MessageCallback)(Nri(Message) messageType, const char* file, uint32_t line, const char* message, void* userArg);
NriOptional void (NRI_CALL *AbortExecution)(void* userArg); // break on "Message::ERROR" if provided
NriOptional void (NRI_CALL *AbortExecution)(void* userArg); // called when reporting a positive "Result"
NriOptional void* userArg;
};

Expand Down
1 change: 1 addition & 0 deletions Include/NRIDescs.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ NriBits(GraphicsAPI, uint8_t,

NriEnum(Result, int8_t,
// All bad, but optionally require an action ("callbackInterface.AbortExecution" is not triggered)
EXT_ERROR = -5, // a potentially recoverable 3rd party SDK failure; details are reported
NOT_READY = -4, // VK: zero surface extent during swap chain creation; WGPU: no swap chain texture available yet. Process window events and retry
DEVICE_LOST = -3, // may be returned by "QueueSubmit*", "*WaitIdle", "AcquireNextTexture", "QueuePresent", "WaitForPresent"
OUT_OF_DATE = -2, // VK/WGPU: swap chain is out of date, can be triggered if "features.resizableSwapChain" is not supported; D3D12: shader cache is stale
Expand Down
5 changes: 3 additions & 2 deletions Source/D3D11/DescriptorD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ Result DescriptorD3D11::Create(const TextureViewDesc& textureViewDesc) {
desc.Texture2D.MipSlice = 0;

NvAPI_Status status = NvAPI_D3D11_CreateShadingRateResourceView(m_Device.GetNativeObject(), textureD3D11, &desc, (ID3D11NvShadingRateResourceView**)&m_Descriptor);
if (status == NVAPI_OK)
hr = S_OK;
NRI_RETURN_ON_FAILURE(&m_Device, status == NVAPI_OK, Result::FAILURE, "NvAPI_D3D11_CreateShadingRateResourceView() failed, result = %d", (int32_t)status);

hr = S_OK;
}
#endif

Expand Down
9 changes: 6 additions & 3 deletions Source/D3D11/DeviceD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Result DeviceD3D11::Create(const DeviceCreationDesc& desc, const DeviceCreationD
result = m_AmdExt.CreateDeviceD3D11(m_AmdExt.context, &deviceCreationParams, &extensionsParams, &agsParams);
}

NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() returned %d", (int32_t)result);
NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX11_CreateDevice() failed, result = %d", (int32_t)result);

deviceTemp = (ID3D11DeviceBest*)agsParams.pDevice;
isDepthBoundsTestSupported = agsParams.extensionsSupported.depthBoundsDeferredContexts;
Expand Down Expand Up @@ -669,8 +669,10 @@ void DeviceD3D11::InitializeNvExt(bool disableNVAPIInitialization, bool isImport
NRI_REPORT_WARNING(this, "NVAPI is disabled, because it's not loaded on the application side");
else {
NvAPI_Status status = NvAPI_Initialize();

if (status != NVAPI_OK)
NRI_REPORT_ERROR(this, "NvAPI_Initialize(): failed, result=%d!", (int32_t)status);
NRI_REPORT_WARNING(this, "NVAPI is disabled, because 'NvAPI_Initialize()' failed, result = %d", (int32_t)status);

m_NvExt.available = (status == NVAPI_OK);
}
#endif
Expand Down Expand Up @@ -724,8 +726,9 @@ void DeviceD3D11::InitializeAmdExt(AGSContext* agsContext, bool isImported) {
AGSConfiguration config = {};
if (!agsContext) {
AGSReturnCode result = m_AmdExt.Initialize(AGS_CURRENT_VERSION, &config, &agsContext, &gpuInfo);

if (result != AGS_SUCCESS || !agsContext) {
NRI_REPORT_ERROR(this, "Failed to initialize AMDAGS: %d", (int32_t)result);
NRI_REPORT_WARNING(this, "AMDAGS is disabled, because 'agsInitialize()' failed, result = %d", (int32_t)result);
UnloadSharedLibrary(*agsLibrary);

return;
Expand Down
13 changes: 9 additions & 4 deletions Source/D3D11/SwapChainD3D11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ NRI_INLINE Result SwapChainD3D11::SetLatencySleepMode(const LatencySleepMode& la
params.bUseMarkersToOptimize = true;

NvAPI_Status status = NvAPI_D3D_SetSleepMode(m_Device.GetNativeObject(), &params);
NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetSleepMode() failed, result = %d", (int32_t)status);

return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE;
return Result::SUCCESS;
#else
MaybeUnused(latencySleepMode);

Expand All @@ -239,8 +240,9 @@ NRI_INLINE Result SwapChainD3D11::SetLatencyMarker(uint64_t presentId, LatencyMa
params.markerType = (NV_LATENCY_MARKER_TYPE)latencyMarker;

NvAPI_Status status = NvAPI_D3D_SetLatencyMarker(m_Device.GetNativeObject(), &params);
NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetLatencyMarker() failed, result = %d", (int32_t)status);

return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE;
return Result::SUCCESS;
#else
MaybeUnused(presentId);
MaybeUnused(latencyMarker);
Expand All @@ -254,8 +256,9 @@ NRI_INLINE Result SwapChainD3D11::LatencySleep(uint64_t presentId) {

#if NRI_ENABLE_NVAPI
NvAPI_Status status = NvAPI_D3D_Sleep(m_Device.GetNativeObject());
NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_Sleep() failed, result = %d", (int32_t)status);

return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE;
return Result::SUCCESS;
#else
return Result::UNSUPPORTED;
#endif
Expand Down Expand Up @@ -286,7 +289,9 @@ NRI_INLINE Result SwapChainD3D11::GetLatencyReport(LatencyReport& latencyReport)
return Result::SUCCESS;
}

return Result::FAILURE;
NRI_REPORT_EXT_ERROR(&m_Device, "NvAPI_D3D_GetLatency() failed, result = %d", (int32_t)status);

return Result::EXT_ERROR;
#else
return Result::UNSUPPORTED;
#endif
Expand Down
23 changes: 18 additions & 5 deletions Source/D3D12/DeviceD3D12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& desc, const DeviceCreationD

AGSDX12ReturnedParams agsParams = {};
AGSReturnCode result = m_AmdExt.CreateDeviceD3D12(m_AmdExt.context, &deviceCreationParams, &extensionsParams, &agsParams);
NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX12_CreateDevice() failed: %d", (int32_t)result);
NRI_RETURN_ON_FAILURE(this, result == AGS_SUCCESS, Result::FAILURE, "agsDriverExtensionsDX12_CreateDevice() failed, result = %d", (int32_t)result);

deviceTemp = agsParams.pDevice;
isShaderAtomicsI64Supported = agsParams.extensionsSupported.intrinsics19;
Expand Down Expand Up @@ -711,8 +711,18 @@ Result DeviceD3D12::Create(const DeviceCreationDesc& desc, const DeviceCreationD
// Enable ray tracing validation
if (desc.enableD3D12RayTracingValidation) {
NvAPI_Status status = NvAPI_D3D12_EnableRaytracingValidation(m_Device, NVAPI_D3D12_RAYTRACING_VALIDATION_FLAG_NONE);
if (status == NVAPI_OK)
NRI_REPORT_ERROR_ON_BAD_NVAPI_STATUS(this, NvAPI_D3D12_RegisterRaytracingValidationMessageCallback(m_Device, NvapiMessageCallback, this, &m_CallbackHandle));

if (status != NVAPI_OK)
NRI_REPORT_WARNING(this, "Ray tracing validation is disabled, because 'NvAPI_D3D12_EnableRaytracingValidation()' failed, result = %d (requires envvar \"NV_ALLOW_RAYTRACING_VALIDATION=1\")", (int32_t)status);
else {
void* callbackHandle = nullptr;
status = NvAPI_D3D12_RegisterRaytracingValidationMessageCallback(m_Device, NvapiMessageCallback, this, &callbackHandle);

if (status == NVAPI_OK)
m_CallbackHandle = callbackHandle;
else
NRI_REPORT_WARNING(this, "NvAPI_D3D12_RegisterRaytracingValidationMessageCallback() failed, result = %d", (int32_t)status);
}

// TODO: if enabled, call "NvAPI_D3D12_FlushRaytracingValidationMessages()" after each submit? present? DEVICE_LOST?
}
Expand Down Expand Up @@ -1339,8 +1349,10 @@ void DeviceD3D12::InitializeNvExt(bool disableNVAPIInitialization, bool isImport
NRI_REPORT_WARNING(this, "NVAPI is disabled, because it's not loaded on the application side");
else {
NvAPI_Status status = NvAPI_Initialize();

if (status != NVAPI_OK)
NRI_REPORT_ERROR(this, "NvAPI_Initialize(): failed, result=%d!", (int32_t)status);
NRI_REPORT_WARNING(this, "NVAPI is disabled, because 'NvAPI_Initialize()' failed, result = %d", (int32_t)status);

m_NvExt.available = (status == NVAPI_OK);
}
#endif
Expand Down Expand Up @@ -1386,8 +1398,9 @@ void DeviceD3D12::InitializeAmdExt(AGSContext* agsContext, bool isImported) {
AGSConfiguration config = {};
if (!agsContext) {
const AGSReturnCode result = m_AmdExt.Initialize(AGS_CURRENT_VERSION, &config, &agsContext, &gpuInfo);

if (result != AGS_SUCCESS || !agsContext) {
NRI_REPORT_ERROR(this, "Failed to initialize AMDAGS: %d", (int32_t)result);
NRI_REPORT_WARNING(this, "AMDAGS is disabled, because 'agsInitialize()' failed, result = %d", (int32_t)result);
UnloadSharedLibrary(*agsLibrary);

return;
Expand Down
13 changes: 9 additions & 4 deletions Source/D3D12/SwapChainD3D12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ NRI_INLINE Result SwapChainD3D12::SetLatencySleepMode(const LatencySleepMode& la
params.bUseMarkersToOptimize = true;

NvAPI_Status status = NvAPI_D3D_SetSleepMode(m_Device.GetNativeObject(), &params);
NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetSleepMode() failed, result = %d", (int32_t)status);

return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE;
return Result::SUCCESS;
#else
MaybeUnused(latencySleepMode);

Expand All @@ -247,8 +248,9 @@ NRI_INLINE Result SwapChainD3D12::SetLatencyMarker(uint64_t presentId, LatencyMa
params.markerType = (NV_LATENCY_MARKER_TYPE)latencyMarker;

NvAPI_Status status = NvAPI_D3D_SetLatencyMarker(m_Device.GetNativeObject(), &params);
NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_SetLatencyMarker() failed, result = %d", (int32_t)status);

return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE;
return Result::SUCCESS;
#else
MaybeUnused(presentId);
MaybeUnused(latencyMarker);
Expand All @@ -262,8 +264,9 @@ NRI_INLINE Result SwapChainD3D12::LatencySleep(uint64_t presentId) {

#if NRI_ENABLE_NVAPI
NvAPI_Status status = NvAPI_D3D_Sleep(m_Device.GetNativeObject());
NRI_RETURN_ON_EXT_FAILURE(&m_Device, status == NVAPI_OK, Result::EXT_ERROR, "NvAPI_D3D_Sleep() failed, result = %d", (int32_t)status);

return status == NVAPI_OK ? Result::SUCCESS : Result::FAILURE;
return Result::SUCCESS;
#else
return Result::UNSUPPORTED;
#endif
Expand Down Expand Up @@ -294,7 +297,9 @@ NRI_INLINE Result SwapChainD3D12::GetLatencyReport(LatencyReport& latencyReport)
return Result::SUCCESS;
}

return Result::FAILURE;
NRI_REPORT_EXT_ERROR(&m_Device, "NvAPI_D3D_GetLatency() failed, result = %d", (int32_t)status);

return Result::EXT_ERROR;
#else
return Result::UNSUPPORTED;
#endif
Expand Down
7 changes: 7 additions & 0 deletions Source/Shared/SharedExternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,16 @@ struct ComPtr {
return returnCode; \
}

#define NRI_RETURN_ON_EXT_FAILURE(deviceBase, condition, returnCode, format, ...) \
if (!(condition)) { \
(deviceBase)->ReportMessage(Message::ERROR, Result::EXT_ERROR, __FILE__, __LINE__, "%s: " format, __FUNCTION__, ##__VA_ARGS__); \
return returnCode; \
}

#define NRI_REPORT_INFO(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::INFO, Result::SUCCESS, __FILE__, __LINE__, format, ##__VA_ARGS__)
#define NRI_REPORT_WARNING(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::WARNING, Result::SUCCESS, __FILE__, __LINE__, "%s(): " format, __FUNCTION__, ##__VA_ARGS__)
#define NRI_REPORT_ERROR(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::ERROR, Result::FAILURE, __FILE__, __LINE__, "%s(): " format, __FUNCTION__, ##__VA_ARGS__)
#define NRI_REPORT_EXT_ERROR(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::ERROR, Result::EXT_ERROR, __FILE__, __LINE__, "%s(): " format, __FUNCTION__, ##__VA_ARGS__)
#define NRI_REPORT_DEVICE_LOST_INFO(deviceBase, format, ...) (deviceBase)->ReportMessage(Message::INFO, Result::DEVICE_LOST, __FILE__, __LINE__, format, ##__VA_ARGS__)

// Array validation
Expand Down
Loading