In a D3D12 program, I encounter a DGXI_ERROR (CreateSharedHandle return an int <0), but I could not find a way to translate it into the "error description" or "error name" (or both).

I have a description by Microsoft: https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-error

Is there such function out there ?

if (result < 0)
    LPWSTR errorText{};
    auto result2 = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, nullptr, result,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
    wstringstream o;
    auto justfile = JustFile(file);
    o << caller << "(): " << func << " at " << justfile.c_str() << ":" << line <<
        " [" << GetErrorDescr(result).c_str() << "][" << errorText << "]";
    LogMessage(L"%s\n", o.str().c_str());
    //throw exception();

and with:

inline string GetErrorDescr(int error)
    switch (error)
            return string("DXGI_ERROR_INVALID_CALL: The method call is invalid. For example, a method's parameter may not be a valid pointer.");
            return string("DXGI_ERROR_WAS_STILL_DRAWING: The previous blit operation that is transferring information to or from this surface is incomplete.");
        case E_FAIL:
            return string("E_FAIL: Attempted to create a device with the debug layer enabled and the layer is not installed.");
        case E_INVALIDARG:
            return string("E_INVALIDARG: An invalid parameter was passed to the returning function.");
        case E_OUTOFMEMORY:
            return string("E_OUTOFMEMORY: Direct3D could not allocate sufficient memory to complete the call.");
        case E_NOTIMPL:
            return string("E_NOTIMPL: The method call isn't implemented with the passed parameter combination.");
        case S_FALSE:
            return string("S_FALSE: Alternate success value, indicating a successful but nonstandard completion (the precise meaning depends on context).");
        case S_OK:
            return string("S_OK: No error occurred.");
            return string("Some other D3D11 error (file not found|too many unique state objects|too many unique view objects).");


inline string JustFile(const char* file)-> string
    auto f = string(file);
    replace(f.begin(), f.end(), '\\', '/');
    auto justfile = string(f.substr(f.find_last_of('/') + 1));
    return justfile;

If more details are required, enable the DGXI debug controller:

#if defined(_DEBUG)
    // Enable the debug layer (requires the Graphics Tools "optional feature").
    // NOTE: Enabling the debug layer after device creation will invalidate the active device.
        ComPtr<ID3D12Debug> debugController;
        if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
            dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;

More here: https://walbourn.github.io/dxgi-debug-device/


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.