diff --git a/WickedEngine/wiAudio.cpp b/WickedEngine/wiAudio.cpp index 508a2707a..811d912bf 100644 --- a/WickedEngine/wiAudio.cpp +++ b/WickedEngine/wiAudio.cpp @@ -31,7 +31,9 @@ static constexpr T AlignTo(T value, T alignment) #define fourccXWMA 'AMWX' #define fourccDPDS 'sdpd' -#define xaudio_check(hr) wilog_assert(SUCCEEDED(hr), "XAudio2 error: %s, line %d, hr = %s", relative_path(__FILE__), __LINE__, wi::helper::GetPlatformErrorString(hr).c_str()) +#define xaudio_assert(cond, fname) { wilog_assert(cond, "XAudio2 error: %s failed with %s (%s:%d)", fname, wi::helper::GetPlatformErrorString(hr), relative_path(__FILE__), __LINE__); } + +#define xaudio_check(call) [&]() { HRESULT hr = call; char buf[256]; xaudio_assert(SUCCEEDED(hr), wi::backlog::internal::extract_function_name(buf, #call)); return hr; }() namespace wi::audio { @@ -87,17 +89,15 @@ namespace wi::audio wi::Timer timer; HRESULT hr; - hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + hr = xaudio_check(CoInitializeEx(NULL, COINIT_MULTITHREADED)); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: CoInitializeEx returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } - hr = XAudio2Create(&audioEngine, 0, XAUDIO2_USE_DEFAULT_PROCESSOR); + hr = xaudio_check(XAudio2Create(&audioEngine, 0, XAUDIO2_USE_DEFAULT_PROCESSOR)); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: XAudio2Create returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } @@ -108,10 +108,9 @@ namespace wi::audio audioEngine->SetDebugConfiguration(&debugConfig); #endif // _DEBUG - hr = audioEngine->CreateMasteringVoice(&masteringVoice); + hr = xaudio_check(audioEngine->CreateMasteringVoice(&masteringVoice)); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: CreateMasteringVoice returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } @@ -123,7 +122,7 @@ namespace wi::audio for (int i = 0; i < SUBMIX_TYPE_COUNT; ++i) { - hr = audioEngine->CreateSubmixVoice( + hr = xaudio_check(audioEngine->CreateSubmixVoice( &submixVoices[i], masteringVoiceDetails.InputChannels, masteringVoiceDetails.InputSampleRate, @@ -131,36 +130,33 @@ namespace wi::audio 0, 0, 0 - ); + )); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: CreateSubmixVoice returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } } DWORD channelMask; masteringVoice->GetChannelMask(&channelMask); - hr = X3DAudioInitialize(channelMask, X3DAUDIO_SPEED_OF_SOUND, audio3D); + hr = xaudio_check(X3DAudioInitialize(channelMask, X3DAUDIO_SPEED_OF_SOUND, audio3D)); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: X3DAudioInitialize returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } // Reverb setup: { - hr = XAudio2CreateReverb(&reverbEffect); + hr = xaudio_check(XAudio2CreateReverb(&reverbEffect)); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: XAudio2CreateReverb returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } XAUDIO2_EFFECT_DESCRIPTOR effects[] = { { reverbEffect.Get(), TRUE, 1 } }; XAUDIO2_EFFECT_CHAIN effectChain = { arraysize(effects), effects }; - hr = audioEngine->CreateSubmixVoice( + hr = xaudio_check(audioEngine->CreateSubmixVoice( &reverbSubmix, 1, // reverb is mono masteringVoiceDetails.InputSampleRate, @@ -168,19 +164,17 @@ namespace wi::audio 0, nullptr, &effectChain - ); + )); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: CreateSubmixVoice returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } XAUDIO2FX_REVERB_PARAMETERS native; ReverbConvertI3DL2ToNative(&reverbPresets[REVERB_PRESET_DEFAULT], &native); - HRESULT hr = reverbSubmix->SetEffectParameters(0, &native, sizeof(native)); + HRESULT hr = xaudio_check(reverbSubmix->SetEffectParameters(0, &native, sizeof(native))); if (!SUCCEEDED(hr)) { - wilog_error("XAudio2: SetEffectParameters returned error: %s", wi::helper::GetPlatformErrorString(hr).c_str()); return; } } @@ -443,18 +437,18 @@ namespace wi::audio instanceinternal->audio = audio_internal; instanceinternal->soundinternal = soundinternal; - XAUDIO2_SEND_DESCRIPTOR SFXSend[] = { + XAUDIO2_SEND_DESCRIPTOR SFXSend[] = { { XAUDIO2_SEND_USEFILTER, instanceinternal->audio->submixVoices[instance->type] }, { XAUDIO2_SEND_USEFILTER, instanceinternal->audio->reverbSubmix }, // this should be last to enable/disable reverb simply }; - XAUDIO2_VOICE_SENDS SFXSendList = { + XAUDIO2_VOICE_SENDS SFXSendList = { (instance->IsEnableReverb() && instanceinternal->audio->reverbSubmix != nullptr) ? (uint32_t)arraysize(SFXSend) : 1, - SFXSend + SFXSend }; - hr = instanceinternal->audio->audioEngine->CreateSourceVoice(&instanceinternal->sourceVoice, &soundinternal->wfx, - 0, XAUDIO2_DEFAULT_FREQ_RATIO, instanceinternal.get(), &SFXSendList, NULL); - xaudio_check(hr); + hr = xaudio_check(instanceinternal->audio->audioEngine->CreateSourceVoice(&instanceinternal->sourceVoice, &soundinternal->wfx, + 0, XAUDIO2_DEFAULT_FREQ_RATIO, instanceinternal.get(), &SFXSendList, NULL)); + if (FAILED(hr)) { return false; @@ -494,8 +488,8 @@ namespace wi::audio instanceinternal->buffer.Flags = XAUDIO2_END_OF_STREAM; instanceinternal->buffer.LoopCount = instance->IsLooped() ? XAUDIO2_LOOP_INFINITE : 0; - hr = instanceinternal->sourceVoice->SubmitSourceBuffer(&instanceinternal->buffer); - xaudio_check(hr); + hr = xaudio_check(instanceinternal->sourceVoice->SubmitSourceBuffer(&instanceinternal->buffer)); + if (FAILED(hr)) { return false; @@ -508,8 +502,8 @@ namespace wi::audio if (instance != nullptr && instance->IsValid()) { auto instanceinternal = to_internal(instance); - HRESULT hr = instanceinternal->sourceVoice->Start(); - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->Start()); + } } void Pause(SoundInstance* instance) @@ -517,8 +511,8 @@ namespace wi::audio if (instance != nullptr && instance->IsValid()) { auto instanceinternal = to_internal(instance); - HRESULT hr = instanceinternal->sourceVoice->Stop(); // preserves cursor position - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->Stop()); // preserves cursor position + } } void Stop(SoundInstance* instance) @@ -526,31 +520,31 @@ namespace wi::audio if (instance != nullptr && instance->IsValid()) { auto instanceinternal = to_internal(instance); - HRESULT hr = instanceinternal->sourceVoice->Stop(); // preserves cursor position - xaudio_check(hr); - hr = instanceinternal->sourceVoice->FlushSourceBuffers(); // reset submitted audio buffer - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->Stop()); // preserves cursor position + + xaudio_check(instanceinternal->sourceVoice->FlushSourceBuffers()); // reset submitted audio buffer + if (!instanceinternal->ended) // if already ended, don't submit end again, it can cause high pitched jerky sound { - hr = instanceinternal->sourceVoice->SubmitSourceBuffer(&audio_internal->termination_mark); // mark this as terminated, this resets XAUDIO2_VOICE_STATE::SamplesPlayed to zero - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->SubmitSourceBuffer(&audio_internal->termination_mark)); // mark this as terminated, this resets XAUDIO2_VOICE_STATE::SamplesPlayed to zero + } - hr = instanceinternal->sourceVoice->SubmitSourceBuffer(&instanceinternal->buffer); // resubmit - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->SubmitSourceBuffer(&instanceinternal->buffer)); // resubmit + } } void SetVolume(float volume, SoundInstance* instance) { if (instance == nullptr || !instance->IsValid()) { - HRESULT hr = audio_internal->masteringVoice->SetVolume(volume); - xaudio_check(hr); + xaudio_check(audio_internal->masteringVoice->SetVolume(volume)); + } else { auto instanceinternal = to_internal(instance); - HRESULT hr = instanceinternal->sourceVoice->SetVolume(volume); - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->SetVolume(volume)); + } } float GetVolume(const SoundInstance* instance) @@ -574,13 +568,13 @@ namespace wi::audio auto instanceinternal = to_internal(instance); if (instanceinternal->buffer.LoopCount == 0) return; - HRESULT hr = instanceinternal->sourceVoice->ExitLoop(); - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->ExitLoop()); + if (instanceinternal->ended) { instanceinternal->buffer.LoopCount = 0; - hr = instanceinternal->sourceVoice->SubmitSourceBuffer(&instanceinternal->buffer); - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->SubmitSourceBuffer(&instanceinternal->buffer)); + } } } @@ -621,8 +615,8 @@ namespace wi::audio void SetSubmixVolume(SUBMIX_TYPE type, float volume) { - HRESULT hr = audio_internal->submixVoices[type]->SetVolume(volume); - xaudio_check(hr); + xaudio_check(audio_internal->submixVoices[type]->SetVolume(volume)); + } float GetSubmixVolume(SUBMIX_TYPE type) { @@ -674,30 +668,27 @@ namespace wi::audio X3DAudioCalculate(instanceinternal->audio->audio3D, &listener, &emitter, flags, &settings); - HRESULT hr; + xaudio_check(instanceinternal->sourceVoice->SetFrequencyRatio(settings.DopplerFactor)); - hr = instanceinternal->sourceVoice->SetFrequencyRatio(settings.DopplerFactor); - xaudio_check(hr); - - hr = instanceinternal->sourceVoice->SetOutputMatrix( + xaudio_check(instanceinternal->sourceVoice->SetOutputMatrix( instanceinternal->audio->submixVoices[instance->type], - settings.SrcChannelCount, - settings.DstChannelCount, + settings.SrcChannelCount, + settings.DstChannelCount, settings.pMatrixCoefficients - ); - xaudio_check(hr); + )); + XAUDIO2_FILTER_PARAMETERS FilterParametersDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * settings.LPFDirectCoefficient), 1.0f }; - hr = instanceinternal->sourceVoice->SetOutputFilterParameters(instanceinternal->audio->submixVoices[instance->type], &FilterParametersDirect); - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->SetOutputFilterParameters(instanceinternal->audio->submixVoices[instance->type], &FilterParametersDirect)); + if (instance->IsEnableReverb() && instanceinternal->audio->reverbSubmix != nullptr) { - hr = instanceinternal->sourceVoice->SetOutputMatrix(instanceinternal->audio->reverbSubmix, settings.SrcChannelCount, 1, &settings.ReverbLevel); - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->SetOutputMatrix(instanceinternal->audio->reverbSubmix, settings.SrcChannelCount, 1, &settings.ReverbLevel)); + XAUDIO2_FILTER_PARAMETERS FilterParametersReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * settings.LPFReverbCoefficient), 1.0f }; - hr = instanceinternal->sourceVoice->SetOutputFilterParameters(instanceinternal->audio->reverbSubmix, &FilterParametersReverb); - xaudio_check(hr); + xaudio_check(instanceinternal->sourceVoice->SetOutputFilterParameters(instanceinternal->audio->reverbSubmix, &FilterParametersReverb)); + } } } @@ -706,8 +697,8 @@ namespace wi::audio { XAUDIO2FX_REVERB_PARAMETERS native; ReverbConvertI3DL2ToNative(&reverbPresets[preset], &native); - HRESULT hr = audio_internal->reverbSubmix->SetEffectParameters(0, &native, sizeof(native)); - xaudio_check(hr); + xaudio_check(audio_internal->reverbSubmix->SetEffectParameters(0, &native, sizeof(native))); + } } diff --git a/WickedEngine/wiBacklog.cpp b/WickedEngine/wiBacklog.cpp index ed3ecf240..53b3ffbfb 100644 --- a/WickedEngine/wiBacklog.cpp +++ b/WickedEngine/wiBacklog.cpp @@ -23,6 +23,16 @@ using namespace std::chrono_literals; namespace wi::backlog { + namespace internal { + char* extract_function_name(char* dst, const char* src) + { + int i = 0; + while (src[i] != '(') i++; + memcpy(dst, src, i); + dst[i] = 0; + return dst; + } + } bool enabled = false; bool was_ever_enabled = enabled; struct LogEntry diff --git a/WickedEngine/wiBacklog.h b/WickedEngine/wiBacklog.h index c5ce5501a..4f6111042 100644 --- a/WickedEngine/wiBacklog.h +++ b/WickedEngine/wiBacklog.h @@ -17,6 +17,11 @@ namespace wi::backlog { + namespace internal { + // Used by various *_check macros + char* extract_function_name(char* dst, const char* src); + } + // Do not modify the order, as this is exposed to LUA scripts as int! enum class LogLevel { diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 36483709c..4e9f4c034 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -1625,15 +1625,13 @@ std::mutex queue_locker; { if (queue == nullptr) return; - HRESULT hr = queue->Signal(semaphore.fence.Get(), semaphore.fenceValue); - dx12_check(hr); + dx12_check(queue->Signal(semaphore.fence.Get(), semaphore.fenceValue)); } void GraphicsDevice_DX12::CommandQueue::wait(const Semaphore& semaphore) { if (queue == nullptr) return; - HRESULT hr = queue->Wait(semaphore.fence.Get(), semaphore.fenceValue); - dx12_check(hr); + dx12_check(queue->Wait(semaphore.fence.Get(), semaphore.fenceValue)); } void GraphicsDevice_DX12::CommandQueue::submit() { @@ -1662,15 +1660,13 @@ std::mutex queue_locker; desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; desc.NodeMask = 0; - HRESULT hr = device->device->CreateCommandQueue(&desc, PPV_ARGS(queue)); - dx12_check(hr); + HRESULT hr = dx12_check(device->device->CreateCommandQueue(&desc, PPV_ARGS(queue))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandQueue[CopyAllocator] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); wi::platform::Exit(); } - hr = queue->SetName(L"CopyAllocator"); - dx12_check(hr); + dx12_check(queue->SetName(L"CopyAllocator")); #endif // PLATFORM_XBOX } GraphicsDevice_DX12::CopyAllocator::CopyCMD GraphicsDevice_DX12::CopyAllocator::allocate(uint64_t staging_size) @@ -1697,17 +1693,13 @@ std::mutex queue_locker; // If no buffer was found that fits the data, create one: if (!cmd.IsValid()) { - HRESULT hr = device->device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COPY, PPV_ARGS(cmd.commandAllocator)); - dx12_check(hr); - hr = device->device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, cmd.commandAllocator.Get(), nullptr, PPV_ARGS(cmd.commandList)); - dx12_check(hr); + dx12_check(device->device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COPY, PPV_ARGS(cmd.commandAllocator))); + dx12_check(device->device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, cmd.commandAllocator.Get(), nullptr, PPV_ARGS(cmd.commandList))); cmd.commandList->SetName(L"CopyAllocator::commandList"); - hr = cmd.commandList->Close(); - dx12_check(hr); + dx12_check(cmd.commandList->Close()); - hr = device->device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(cmd.fence)); - dx12_check(hr); + dx12_check(device->device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(cmd.fence))); GPUBufferDesc uploadBufferDesc; uploadBufferDesc.size = wi::math::GetNextPowerOfTwo(staging_size); @@ -1718,17 +1710,13 @@ std::mutex queue_locker; } // begin command list in valid state: - HRESULT hr = cmd.commandAllocator->Reset(); - dx12_check(hr); - hr = cmd.commandList->Reset(cmd.commandAllocator.Get(), nullptr); - dx12_check(hr); + dx12_check(cmd.commandAllocator->Reset()); + dx12_check(cmd.commandList->Reset(cmd.commandAllocator.Get(), nullptr)); return cmd; } void GraphicsDevice_DX12::CopyAllocator::submit(CopyCMD cmd) { - HRESULT hr; - locker.lock(); cmd.fenceValueSignaled++; freelist.push_back(cmd); @@ -1744,19 +1732,14 @@ std::mutex queue_locker; #endif // PLATFORM_XBOX queue->ExecuteCommandLists(1, commandlists); - hr = queue->Signal(cmd.fence.Get(), cmd.fenceValueSignaled); - dx12_check(hr); + dx12_check(queue->Signal(cmd.fence.Get(), cmd.fenceValueSignaled)); - hr = device->queues[QUEUE_GRAPHICS].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled); - dx12_check(hr); - hr = device->queues[QUEUE_COMPUTE].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled); - dx12_check(hr); - hr = device->queues[QUEUE_COPY].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled); - dx12_check(hr); + dx12_check(device->queues[QUEUE_GRAPHICS].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled)); + dx12_check(device->queues[QUEUE_COMPUTE].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled)); + dx12_check(device->queues[QUEUE_COPY].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled)); if (device->queues[QUEUE_VIDEO_DECODE].queue) { - hr = device->queues[QUEUE_VIDEO_DECODE].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled); - dx12_check(hr); + dx12_check(device->queues[QUEUE_VIDEO_DECODE].queue->Wait(cmd.fence.Get(), cmd.fenceValueSignaled)); } } @@ -1899,8 +1882,7 @@ std::mutex queue_locker; if ((wrapped_offset < wrapped_gpu_offset) && (wrapped_gpu_offset < wrapped_offset_end)) { // Third step is actual wait until GPU updates fence so that requested descriptors are free: - HRESULT hr = heap.fence->SetEventOnCompletion(heap.fenceValue, nullptr); - dx12_check(hr); + dx12_check(heap.fence->SetEventOnCompletion(heap.fenceValue, nullptr)); } } @@ -2162,8 +2144,7 @@ std::mutex queue_locker; } ComPtr newpso; - HRESULT hr = device->CreatePipelineState(&streamDesc, PPV_ARGS(newpso)); - dx12_check(hr); + dx12_check(device->CreatePipelineState(&streamDesc, PPV_ARGS(newpso))); commandlist.pipelines_worker.push_back(std::make_pair(pipeline_hash, newpso)); pipeline = newpso.Get(); @@ -2470,8 +2451,7 @@ std::mutex queue_locker; allocationhandler = std::make_shared(); allocationhandler->device = device; - hr = D3D12MA::CreateAllocator(&allocatorDesc, &allocationhandler->allocator); - dx12_check(hr); + hr = dx12_check(D3D12MA::CreateAllocator(&allocatorDesc, &allocationhandler->allocator)); if (FAILED(hr)) { wilog_messagebox("D3D12MA::CreateAllocator failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2483,15 +2463,13 @@ std::mutex queue_locker; queues[QUEUE_GRAPHICS].desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; queues[QUEUE_GRAPHICS].desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queues[QUEUE_GRAPHICS].desc.NodeMask = 0; - hr = device->CreateCommandQueue(&queues[QUEUE_GRAPHICS].desc, PPV_ARGS(queues[QUEUE_GRAPHICS].queue)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandQueue(&queues[QUEUE_GRAPHICS].desc, PPV_ARGS(queues[QUEUE_GRAPHICS].queue))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandQueue[QUEUE_GRAPHICS] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); wi::platform::Exit(); } - hr = queues[QUEUE_GRAPHICS].queue->SetName(L"QUEUE_GRAPHICS"); - dx12_check(hr); + dx12_check(queues[QUEUE_GRAPHICS].queue->SetName(L"QUEUE_GRAPHICS")); } { @@ -2499,15 +2477,13 @@ std::mutex queue_locker; queues[QUEUE_COMPUTE].desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; queues[QUEUE_COMPUTE].desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queues[QUEUE_COMPUTE].desc.NodeMask = 0; - hr = device->CreateCommandQueue(&queues[QUEUE_COMPUTE].desc, PPV_ARGS(queues[QUEUE_COMPUTE].queue)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandQueue(&queues[QUEUE_COMPUTE].desc, PPV_ARGS(queues[QUEUE_COMPUTE].queue))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandQueue[QUEUE_COMPUTE] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); wi::platform::Exit(); } - hr = queues[QUEUE_COMPUTE].queue->SetName(L"QUEUE_COMPUTE"); - dx12_check(hr); + dx12_check(queues[QUEUE_COMPUTE].queue->SetName(L"QUEUE_COMPUTE")); } { @@ -2515,15 +2491,13 @@ std::mutex queue_locker; queues[QUEUE_COPY].desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; queues[QUEUE_COPY].desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queues[QUEUE_COPY].desc.NodeMask = 0; - hr = device->CreateCommandQueue(&queues[QUEUE_COPY].desc, PPV_ARGS(queues[QUEUE_COPY].queue)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandQueue(&queues[QUEUE_COPY].desc, PPV_ARGS(queues[QUEUE_COPY].queue))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandQueue[QUEUE_COPY] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); wi::platform::Exit(); } - hr = queues[QUEUE_COPY].queue->SetName(L"QUEUE_COPY"); - dx12_check(hr); + dx12_check(queues[QUEUE_COPY].queue->SetName(L"QUEUE_COPY")); } if (SUCCEEDED(device.As(&video_device))) @@ -2532,13 +2506,11 @@ std::mutex queue_locker; queues[QUEUE_VIDEO_DECODE].desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; queues[QUEUE_VIDEO_DECODE].desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queues[QUEUE_VIDEO_DECODE].desc.NodeMask = 0; - hr = device->CreateCommandQueue(&queues[QUEUE_VIDEO_DECODE].desc, PPV_ARGS(queues[QUEUE_VIDEO_DECODE].queue)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandQueue(&queues[QUEUE_VIDEO_DECODE].desc, PPV_ARGS(queues[QUEUE_VIDEO_DECODE].queue))); if (SUCCEEDED(hr)) { capabilities |= GraphicsDeviceCapability::VIDEO_DECODE_H264; - hr = queues[QUEUE_VIDEO_DECODE].queue->SetName(L"QUEUE_VIDEO_DECODE"); - dx12_check(hr); + dx12_check(queues[QUEUE_VIDEO_DECODE].queue->SetName(L"QUEUE_VIDEO_DECODE")); } } @@ -2553,8 +2525,7 @@ std::mutex queue_locker; descriptorheap_res.heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; descriptorheap_res.heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; descriptorheap_res.heapDesc.NumDescriptors = 1000000; // tier 1 limit - hr = device->CreateDescriptorHeap(&descriptorheap_res.heapDesc, PPV_ARGS(descriptorheap_res.heap_GPU)); - dx12_check(hr); + hr = dx12_check(device->CreateDescriptorHeap(&descriptorheap_res.heapDesc, PPV_ARGS(descriptorheap_res.heap_GPU))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateDescriptorHeap[CBV_SRV_UAV] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2564,8 +2535,7 @@ std::mutex queue_locker; descriptorheap_res.start_cpu = descriptorheap_res.heap_GPU->GetCPUDescriptorHandleForHeapStart(); descriptorheap_res.start_gpu = descriptorheap_res.heap_GPU->GetGPUDescriptorHandleForHeapStart(); - hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(descriptorheap_res.fence)); - dx12_check(hr); + hr = dx12_check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(descriptorheap_res.fence))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateFence[CBV_SRV_UAV] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2586,8 +2556,7 @@ std::mutex queue_locker; descriptorheap_sam.heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; descriptorheap_sam.heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; descriptorheap_sam.heapDesc.NumDescriptors = 2048; // tier 1 limit - hr = device->CreateDescriptorHeap(&descriptorheap_sam.heapDesc, PPV_ARGS(descriptorheap_sam.heap_GPU)); - dx12_check(hr); + hr = dx12_check(device->CreateDescriptorHeap(&descriptorheap_sam.heapDesc, PPV_ARGS(descriptorheap_sam.heap_GPU))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateDescriptorHeap[SAMPLER] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2597,8 +2566,7 @@ std::mutex queue_locker; descriptorheap_sam.start_cpu = descriptorheap_sam.heap_GPU->GetCPUDescriptorHandleForHeapStart(); descriptorheap_sam.start_gpu = descriptorheap_sam.heap_GPU->GetGPUDescriptorHandleForHeapStart(); - hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(descriptorheap_sam.fence)); - dx12_check(hr); + hr = dx12_check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(descriptorheap_sam.fence))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateFence[SAMPLER] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2618,8 +2586,7 @@ std::mutex queue_locker; { for (int queue = 0; queue < QUEUE_COUNT; ++queue) { - hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(frame_fence[buffer][queue])); - dx12_check(hr); + hr = dx12_check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(frame_fence[buffer][queue]))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateFence[FRAME] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2664,14 +2631,12 @@ std::mutex queue_locker; #else // Init feature check (https://devblogs.microsoft.com/directx/introducing-a-new-api-for-checking-feature-support-in-direct3d-12/) CD3DX12FeatureSupport features; - hr = features.Init(device.Get()); - dx12_check(hr); + dx12_check(features.Init(device.Get())); // Init adapter properties { DXGI_ADAPTER_DESC1 adapterDesc; - hr = dxgiAdapter->GetDesc1(&adapterDesc); - dx12_check(hr); + dx12_check(dxgiAdapter->GetDesc1(&adapterDesc)); vendorId = adapterDesc.VendorId; deviceId = adapterDesc.DeviceId; @@ -2830,20 +2795,17 @@ std::mutex queue_locker; pool_desc.HeapProperties.Type = D3D12_HEAP_TYPE_CUSTOM; pool_desc.HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE; pool_desc.HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_L0; - hr = allocationhandler->allocator->CreatePool(&pool_desc, &allocationhandler->uma_pool); - dx12_check(hr); + dx12_check(allocationhandler->allocator->CreatePool(&pool_desc, &allocationhandler->uma_pool)); } #endif // PLATFORM_XBOX #ifdef PLATFORM_WINDOWS_DESKTOP // Create fence to detect device removal { - hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(deviceRemovedFence.GetAddressOf())); - dx12_check(hr); + dx12_check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(deviceRemovedFence.GetAddressOf()))); HANDLE deviceRemovedEvent = CreateEventW(NULL, FALSE, FALSE, NULL); - hr = deviceRemovedFence->SetEventOnCompletion(UINT64_MAX, deviceRemovedEvent); - dx12_check(hr); + dx12_check(deviceRemovedFence->SetEventOnCompletion(UINT64_MAX, deviceRemovedEvent)); RegisterWaitForSingleObject( &deviceRemovedWaitHandle, @@ -2872,8 +2834,7 @@ std::mutex queue_locker; cmd_desc.ByteStride = sizeof(D3D12_DISPATCH_ARGUMENTS); cmd_desc.NumArgumentDescs = 1; cmd_desc.pArgumentDescs = dispatchArgs; - hr = device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(dispatchIndirectCommandSignature)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(dispatchIndirectCommandSignature))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandSignature[dispatchIndirect] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2883,8 +2844,7 @@ std::mutex queue_locker; cmd_desc.ByteStride = sizeof(D3D12_DRAW_ARGUMENTS); cmd_desc.NumArgumentDescs = 1; cmd_desc.pArgumentDescs = drawInstancedArgs; - hr = device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(drawInstancedIndirectCommandSignature)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(drawInstancedIndirectCommandSignature))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandSignature[drawInstancedIndirect] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2894,8 +2854,7 @@ std::mutex queue_locker; cmd_desc.ByteStride = sizeof(D3D12_DRAW_INDEXED_ARGUMENTS); cmd_desc.NumArgumentDescs = 1; cmd_desc.pArgumentDescs = drawIndexedInstancedArgs; - hr = device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(drawIndexedInstancedIndirectCommandSignature)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(drawIndexedInstancedIndirectCommandSignature))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandSignature[drawIndexedInstancedIndirect] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2913,8 +2872,7 @@ std::mutex queue_locker; #endif // PLATFORM_XBOX cmd_desc.NumArgumentDescs = 1; cmd_desc.pArgumentDescs = dispatchMeshArgs; - hr = device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(dispatchMeshIndirectCommandSignature)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandSignature(&cmd_desc, nullptr, PPV_ARGS(dispatchMeshIndirectCommandSignature))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateCommandSignature[dispatchMeshIndirect] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2930,8 +2888,7 @@ std::mutex queue_locker; D3D12_DESCRIPTOR_HEAP_DESC nullHeapDesc = {}; nullHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; nullHeapDesc.NumDescriptors = DESCRIPTORBINDER_CBV_COUNT + DESCRIPTORBINDER_SRV_COUNT + DESCRIPTORBINDER_UAV_COUNT; - hr = device->CreateDescriptorHeap(&nullHeapDesc, PPV_ARGS(nulldescriptorheap_cbv_srv_uav)); - dx12_check(hr); + dx12_check(device->CreateDescriptorHeap(&nullHeapDesc, PPV_ARGS(nulldescriptorheap_cbv_srv_uav))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateDescriptorHeap[nulldescriptorheap_cbv_srv_uav] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -2939,8 +2896,7 @@ std::mutex queue_locker; nullHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; nullHeapDesc.NumDescriptors = DESCRIPTORBINDER_SAMPLER_COUNT; - device->CreateDescriptorHeap(&nullHeapDesc, PPV_ARGS(nulldescriptorheap_sampler)); - dx12_check(hr); + hr = dx12_check(device->CreateDescriptorHeap(&nullHeapDesc, PPV_ARGS(nulldescriptorheap_sampler))); if (FAILED(hr)) { wilog_messagebox("ID3D12Device::CreateDescriptorHeap[nulldescriptorheap_sampler] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -3015,8 +2971,7 @@ std::mutex queue_locker; device->CopyDescriptorsSimple(1, dst_bindless, nullSAM, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); } - hr = queues[QUEUE_GRAPHICS].queue->GetTimestampFrequency(&TIMESTAMP_FREQUENCY); - dx12_check(hr); + hr = dx12_check(queues[QUEUE_GRAPHICS].queue->GetTimestampFrequency(&TIMESTAMP_FREQUENCY)); if (FAILED(hr)) { wilog_messagebox("ID3D12CommandQueue::GetTimestampFrequency[QUEUE_GRAPHICS] failed! ERROR: %s", wi::helper::GetPlatformErrorString(hr).c_str()); @@ -3089,18 +3044,16 @@ std::mutex queue_locker; internal_state->backbufferRTV.resize(swapchain->desc.buffer_count); for (uint32_t i = 0; i < swapchain->desc.buffer_count; ++i) { - hr = device->CreateCommittedResource( - &heap_properties, + dx12_check(device->CreateCommittedResource( D3D12_HEAP_FLAG_ALLOW_DISPLAY, &resource_desc, D3D12_RESOURCE_STATE_PRESENT, &clear_value, PPV_ARGS(internal_state->backBuffers[i]) - ); - dx12_check(hr); + )); - hr = internal_state->backBuffers[i]->SetName(L"BackBufferXBOX"); - dx12_check(hr); + + dx12_check(internal_state->backBuffers[i]->SetName(L"BackBufferXBOX")); internal_state->backbufferRTV[i] = allocationhandler->descriptors_rtv.allocate(); device->CreateRenderTargetView(internal_state->backBuffers[i].Get(), &rtv_desc, internal_state->backbufferRTV[i]); @@ -3171,14 +3124,14 @@ std::mutex queue_locker; else { // Resize swapchain: - hr = internal_state->swapChain->ResizeBuffers( + dx12_check(internal_state->swapChain->ResizeBuffers( desc->buffer_count, desc->width, desc->height, _ConvertFormat(desc->format), swapChainFlags - ); - dx12_check(hr); + )); + } const bool hdr = desc->allow_hdr && IsSwapChainSupportsHDR(swapchain); @@ -3210,8 +3163,7 @@ std::mutex queue_locker; { if (colorSpaceSupport & DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT) { - hr = internal_state->swapChain->SetColorSpace1(colorSpace); - dx12_check(hr); + hr = dx12_check(internal_state->swapChain->SetColorSpace1(colorSpace)); if (SUCCEEDED(hr)) { switch (colorSpace) @@ -3243,8 +3195,7 @@ std::mutex queue_locker; for (uint32_t i = 0; i < desc->buffer_count; ++i) { - hr = internal_state->swapChain->GetBuffer(i, PPV_ARGS(internal_state->backBuffers[i])); - dx12_check(hr); + dx12_check(internal_state->swapChain->GetBuffer(i, PPV_ARGS(internal_state->backBuffers[i]))); internal_state->backbufferRTV[i] = allocationhandler->descriptors_rtv.allocate(); device->CreateRenderTargetView(internal_state->backBuffers[i].Get(), &rtvDesc, internal_state->backbufferRTV[i]); @@ -3342,35 +3293,35 @@ std::mutex queue_locker; allocationDesc.ExtraHeapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; } - hr = allocationhandler->allocator->AllocateMemory( + dx12_check(allocationhandler->allocator->AllocateMemory( &allocationDesc, &allocationInfo, &internal_state->allocation - ); - dx12_check(hr); + )); + if (allocationDesc.ExtraHeapFlags == D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS || allocationDesc.ExtraHeapFlags == D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES) { - hr = device->CreatePlacedResource( + dx12_check(device->CreatePlacedResource( internal_state->allocation->GetHeap(), internal_state->allocation->GetOffset(), &resourceDesc, resourceState, nullptr, PPV_ARGS(internal_state->resource) - ); - dx12_check(hr); + )); + } } else if (has_flag(desc->misc_flags, ResourceMiscFlag::SPARSE)) { - hr = device->CreateReservedResource( + dx12_check(device->CreateReservedResource( &resourceDesc, resourceState, nullptr, PPV_ARGS(internal_state->resource) - ); - dx12_check(hr); + )); + buffer->sparse_page_size = D3D12_TILED_RESOURCE_TILE_SIZE_IN_BYTES; } else @@ -3390,16 +3341,16 @@ std::mutex queue_locker; { // Aliasing: https://gpuopen-librariesandsdks.github.io/D3D12MemoryAllocator/html/resource_aliasing.html auto alias_internal = to_internal(alias); - hr = allocationhandler->allocator->CreateAliasingResource( + dx12_check(allocationhandler->allocator->CreateAliasingResource( alias_internal->allocation.Get(), alias_offset, &resourceDesc, resourceState, nullptr, PPV_ARGS(internal_state->resource) - ); + )); } - dx12_check(hr); + } if (!SUCCEEDED(hr)) @@ -3412,15 +3363,13 @@ std::mutex queue_locker; if (desc->usage == Usage::READBACK) { - hr = internal_state->resource->Map(0, nullptr, &buffer->mapped_data); - dx12_check(hr); + dx12_check(internal_state->resource->Map(0, nullptr, &buffer->mapped_data)); buffer->mapped_size = static_cast(desc->size); } else if (desc->usage == Usage::UPLOAD) { D3D12_RANGE read_range = {}; - hr = internal_state->resource->Map(0, &read_range, &buffer->mapped_data); - dx12_check(hr); + dx12_check(internal_state->resource->Map(0, &read_range, &buffer->mapped_data)); buffer->mapped_size = static_cast(desc->size); } @@ -3678,22 +3627,22 @@ std::mutex queue_locker; allocationDesc.ExtraHeapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; } - hr = allocationhandler->allocator->AllocateMemory( + dx12_check(allocationhandler->allocator->AllocateMemory( &allocationDesc, &allocationInfo, &internal_state->allocation - ); - dx12_check(hr); + )); - hr = device->CreatePlacedResource( + + dx12_check(device->CreatePlacedResource( internal_state->allocation->GetHeap(), internal_state->allocation->GetOffset(), &resourcedesc, resourceState, useClearValue ? &optimizedClearValue : nullptr, PPV_ARGS(internal_state->resource) - ); - dx12_check(hr); + )); + } else if (has_flag(texture->desc.misc_flags, ResourceMiscFlag::SPARSE)) { @@ -3758,39 +3707,37 @@ std::mutex queue_locker; { // Aliasing: https://gpuopen-librariesandsdks.github.io/D3D12MemoryAllocator/html/resource_aliasing.html auto alias_internal = to_internal(alias); - hr = allocationhandler->allocator->CreateAliasingResource( + dx12_check(allocationhandler->allocator->CreateAliasingResource( alias_internal->allocation.Get(), alias_offset, &resourcedesc, resourceState, useClearValue ? &optimizedClearValue : nullptr, PPV_ARGS(internal_state->resource) - ); + )); } } - dx12_check(hr); + if (texture->desc.usage == Usage::READBACK) { - hr = internal_state->resource->Map(0, nullptr, &texture->mapped_data); - dx12_check(hr); + dx12_check(internal_state->resource->Map(0, nullptr, &texture->mapped_data)); } else if(texture->desc.usage == Usage::UPLOAD) { D3D12_RANGE read_range = {}; - hr = internal_state->resource->Map(0, &read_range, &texture->mapped_data); - dx12_check(hr); + dx12_check(internal_state->resource->Map(0, &read_range, &texture->mapped_data)); } else if (has_flag(texture->desc.misc_flags, ResourceMiscFlag::SHARED)) { - hr = allocationhandler->device->CreateSharedHandle( + dx12_check(allocationhandler->device->CreateSharedHandle( internal_state->resource.Get(), nullptr, GENERIC_ALL, nullptr, - &texture->shared_handle); + &texture->shared_handle)); + - dx12_check(hr); } if (texture->mapped_data != nullptr) @@ -3817,14 +3764,14 @@ std::mutex queue_locker; { const SubresourceData& data = initial_data[i]; - hr = internal_state->resource->WriteToSubresource( + dx12_check(internal_state->resource->WriteToSubresource( (UINT)i, nullptr, data.data_ptr, data.row_pitch, data.slice_pitch - ); - dx12_check(hr); + )); + } } else @@ -3909,8 +3856,7 @@ std::mutex queue_locker; std::memcpy(internal_state->shadercode.data(), shadercode, shadercode_size); shader->stage = stage; - HRESULT hr = (internal_state->shadercode.empty() ? E_FAIL : S_OK); - dx12_check(hr); + HRESULT hr = dx12_check((internal_state->shadercode.empty() ? E_FAIL : S_OK)); hr = D3D12CreateVersionedRootSignatureDeserializer( internal_state->shadercode.data(), @@ -3924,13 +3870,13 @@ std::mutex queue_locker; { assert(internal_state->rootsig_desc->Version == D3D_ROOT_SIGNATURE_VERSION_1_1); - hr = device->CreateRootSignature( + dx12_check(device->CreateRootSignature( 0, internal_state->shadercode.data(), internal_state->shadercode.size(), PPV_ARGS(internal_state->rootSignature) - ); - dx12_check(hr); + )); + } } @@ -3956,8 +3902,7 @@ std::mutex queue_locker; streamDesc.pPipelineStateSubobjectStream = &stream; streamDesc.SizeInBytes = sizeof(stream); - HRESULT hr = device->CreatePipelineState(&streamDesc, PPV_ARGS(internal_state->resource)); - dx12_check(hr); + dx12_check(device->CreatePipelineState(&streamDesc, PPV_ARGS(internal_state->resource))); } return SUCCEEDED(hr); @@ -4030,8 +3975,7 @@ std::mutex queue_locker; break; } - HRESULT hr = allocationhandler->device->CreateQueryHeap(&queryheapdesc, PPV_ARGS(internal_state->heap)); - dx12_check(hr); + HRESULT hr = dx12_check(allocationhandler->device->CreateQueryHeap(&queryheapdesc, PPV_ARGS(internal_state->heap))); return SUCCEEDED(hr); } @@ -4278,8 +4222,7 @@ std::mutex queue_locker; streamDesc.SizeInBytes += sizeof(stream.stream2); } - HRESULT hr = device->CreatePipelineState(&streamDesc, PPV_ARGS(internal_state->resource)); - dx12_check(hr); + dx12_check(device->CreatePipelineState(&streamDesc, PPV_ARGS(internal_state->resource))); } return true; @@ -4395,15 +4338,15 @@ std::mutex queue_locker; D3D12MA::ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; - HRESULT hr = allocationhandler->allocator->CreateResource( + dx12_check(allocationhandler->allocator->CreateResource( &allocationDesc, &resourcedesc, resourceState, nullptr, &internal_state->allocation, PPV_ARGS(internal_state->resource) - ); - dx12_check(hr); + )); + internal_state->gpu_address = internal_state->resource->GetGPUVirtualAddress(); @@ -4528,11 +4471,9 @@ std::mutex queue_locker; stateobjectdesc.NumSubobjects = (UINT)subobjects.size(); stateobjectdesc.pSubobjects = subobjects.data(); - HRESULT hr = device->CreateStateObject(&stateobjectdesc, PPV_ARGS(internal_state->resource)); - dx12_check(hr); + dx12_check(device->CreateStateObject(&stateobjectdesc, PPV_ARGS(internal_state->resource))); - hr = internal_state->resource.As(&internal_state->stateObjectProperties); - dx12_check(hr); + HRESULT hr = dx12_check(internal_state->resource.As(&internal_state->stateObjectProperties)); return SUCCEEDED(hr); } @@ -4541,19 +4482,13 @@ std::mutex queue_locker; if (video_device == nullptr) return false; - HRESULT hr = E_FAIL; - D3D12_FEATURE_DATA_VIDEO_DECODE_PROFILE_COUNT video_decode_profile_count = {}; - hr = video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_PROFILE_COUNT, &video_decode_profile_count, sizeof(video_decode_profile_count)); - dx12_check(hr); - + dx12_check(video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_PROFILE_COUNT, &video_decode_profile_count, sizeof(video_decode_profile_count))); wi::vector profiles(video_decode_profile_count.ProfileCount); D3D12_FEATURE_DATA_VIDEO_DECODE_PROFILES video_decode_profiles = {}; video_decode_profiles.ProfileCount = video_decode_profile_count.ProfileCount; video_decode_profiles.pProfiles = profiles.data(); - hr = video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_PROFILES, &video_decode_profiles, sizeof(video_decode_profiles)); - dx12_check(hr); - + dx12_check(video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_PROFILES, &video_decode_profiles, sizeof(video_decode_profiles))); D3D12_VIDEO_DECODER_DESC decoder_desc = {}; switch (desc->profile) { @@ -4582,17 +4517,13 @@ std::mutex queue_locker; D3D12_FEATURE_DATA_VIDEO_DECODE_FORMAT_COUNT video_decode_format_count = {}; video_decode_format_count.Configuration = decoder_desc.Configuration; - hr = video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_FORMAT_COUNT, &video_decode_format_count, sizeof(video_decode_format_count)); - dx12_check(hr); - + dx12_check(video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_FORMAT_COUNT, &video_decode_format_count, sizeof(video_decode_format_count))); wi::vector formats(video_decode_format_count.FormatCount); D3D12_FEATURE_DATA_VIDEO_DECODE_FORMATS video_decode_formats = {}; video_decode_formats.Configuration = decoder_desc.Configuration; video_decode_formats.FormatCount = video_decode_format_count.FormatCount; video_decode_formats.pOutputFormats = formats.data(); - hr = video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_FORMATS, &video_decode_formats, sizeof(video_decode_formats)); - dx12_check(hr); - + dx12_check(video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_FORMATS, &video_decode_formats, sizeof(video_decode_formats))); D3D12_FEATURE_DATA_VIDEO_DECODE_SUPPORT video_decode_support = {}; video_decode_support.Configuration = decoder_desc.Configuration; video_decode_support.DecodeFormat = _ConvertFormat(desc->format); @@ -4611,9 +4542,7 @@ std::mutex queue_locker; video_decode_support.Height = desc->height; video_decode_support.BitRate = desc->bit_rate; video_decode_support.FrameRate = { 0, 1 }; - hr = video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_SUPPORT, &video_decode_support, sizeof(video_decode_support)); - dx12_check(hr); - + dx12_check(video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODE_SUPPORT, &video_decode_support, sizeof(video_decode_support))); bool reference_only = video_decode_support.ConfigurationFlags & D3D12_VIDEO_DECODE_CONFIGURATION_FLAG_REFERENCE_ONLY_ALLOCATIONS_REQUIRED; assert(!reference_only); // Not supported currently, will need to use resource flags: D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE, and do output decode conversion @@ -4643,15 +4572,11 @@ std::mutex queue_locker; #if 0 D3D12_FEATURE_DATA_VIDEO_DECODER_HEAP_SIZE video_decoder_heap_size = {}; video_decoder_heap_size.VideoDecoderHeapDesc = heap_desc; - hr = video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODER_HEAP_SIZE, &video_decoder_heap_size, sizeof(video_decoder_heap_size)); - dx12_check(hr); + dx12_check(video_device->CheckFeatureSupport(D3D12_FEATURE_VIDEO_DECODER_HEAP_SIZE, &video_decoder_heap_size, sizeof(video_decoder_heap_size))); #endif - hr = video_device->CreateVideoDecoderHeap(&heap_desc, PPV_ARGS(internal_state->decoder_heap)); - dx12_check(hr); - hr = video_device->CreateVideoDecoder(&decoder_desc, PPV_ARGS(internal_state->decoder)); - dx12_check(hr); - + dx12_check(video_device->CreateVideoDecoderHeap(&heap_desc, PPV_ARGS(internal_state->decoder_heap))); + HRESULT hr = dx12_check(video_device->CreateVideoDecoder(&decoder_desc, PPV_ARGS(internal_state->decoder))); return SUCCEEDED(hr); } @@ -5260,16 +5185,14 @@ std::mutex queue_locker; for (uint32_t buffer = 0; buffer < BUFFERCOUNT; ++buffer) { - hr = device->CreateCommandAllocator(queues[queue].desc.Type, PPV_ARGS(commandlist.commandAllocators[buffer][queue])); - dx12_check(hr); + dx12_check(device->CreateCommandAllocator(queues[queue].desc.Type, PPV_ARGS(commandlist.commandAllocators[buffer][queue]))); } if (queue == QUEUE_VIDEO_DECODE) { ComPtr videoCommandList; #ifdef PLATFORM_XBOX - hr = device->CreateCommandList(0, queues[queue].desc.Type, commandlist.commandAllocators[0][queue].Get(), nullptr, PPV_ARGS(videoCommandList)); - dx12_check(hr); + dx12_check(device->CreateCommandList(0, queues[queue].desc.Type, commandlist.commandAllocators[0][queue].Get(), nullptr, PPV_ARGS(videoCommandList))); hr = videoCommandList->Close(); #else hr = device->CreateCommandList1(0, queues[queue].desc.Type, D3D12_COMMAND_LIST_FLAG_NONE, PPV_ARGS(videoCommandList)); @@ -5280,8 +5203,7 @@ std::mutex queue_locker; { ComPtr copyCommandList; #ifdef PLATFORM_XBOX - hr = device->CreateCommandList(0, queues[queue].desc.Type, commandlist.commandAllocators[0][queue].Get(), nullptr, PPV_ARGS(copyCommandList)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandList(0, queues[queue].desc.Type, commandlist.commandAllocators[0][queue].Get(), nullptr, PPV_ARGS(copyCommandList))); hr = copyCommandList->Close(); #else hr = device->CreateCommandList1(0, queues[queue].desc.Type, D3D12_COMMAND_LIST_FLAG_NONE, PPV_ARGS(copyCommandList)); @@ -5292,15 +5214,15 @@ std::mutex queue_locker; { ComPtr graphicsCommandList; #ifdef PLATFORM_XBOX - hr = device->CreateCommandList(0, queues[queue].desc.Type, commandlist.commandAllocators[0][queue].Get(), nullptr, PPV_ARGS(graphicsCommandList)); - dx12_check(hr); + hr = dx12_check(device->CreateCommandList(0, queues[queue].desc.Type, commandlist.commandAllocators[0][queue].Get(), nullptr, PPV_ARGS(graphicsCommandList))); hr = graphicsCommandList->Close(); #else hr = device->CreateCommandList1(0, queues[queue].desc.Type, D3D12_COMMAND_LIST_FLAG_NONE, PPV_ARGS(graphicsCommandList)); #endif // PLATFORM_XBOX commandlist.commandLists[queue] = graphicsCommandList; } - dx12_check(hr); + dx12_assert(SUCCEEDED(hr), "CreateCommandList1"); + std::wstring ws = L"cmd" + std::to_wstring(commandlist.id); commandlist.GetCommandList()->SetName(ws.c_str()); @@ -5309,18 +5231,15 @@ std::mutex queue_locker; } // Start the command list in a default state: - hr = commandlist.GetCommandAllocator()->Reset(); - dx12_check(hr); + dx12_check(commandlist.GetCommandAllocator()->Reset()); if (queue == QUEUE_VIDEO_DECODE) { - hr = commandlist.GetVideoDecodeCommandList()->Reset(commandlist.GetCommandAllocator()); - dx12_check(hr); + dx12_check(commandlist.GetVideoDecodeCommandList()->Reset(commandlist.GetCommandAllocator())); } else { - hr = commandlist.GetGraphicsCommandList()->Reset(commandlist.GetCommandAllocator(), nullptr); - dx12_check(hr); + dx12_check(commandlist.GetGraphicsCommandList()->Reset(commandlist.GetCommandAllocator(), nullptr)); } if (queue == QUEUE_GRAPHICS || queue == QUEUE_COMPUTE) @@ -5368,9 +5287,8 @@ std::mutex queue_locker; } else { - hr = commandlist.GetGraphicsCommandList()->Close(); + hr = dx12_check(commandlist.GetGraphicsCommandList()->Close()); } - dx12_check(hr); CommandQueue& queue = queues[commandlist.queue]; const bool dependency = !commandlist.signals.empty() || !commandlist.waits.empty() || !commandlist.wait_queues.empty(); @@ -5450,8 +5368,7 @@ std::mutex queue_locker; queue.submit(); - hr = queue.queue->Signal(frame_fence[GetBufferIndex()][q].Get(), 1); - dx12_check(hr); + dx12_check(queue.queue->Signal(frame_fence[GetBufferIndex()][q].Get(), 1)); } for (uint32_t cmd = 0; cmd < cmd_last; ++cmd) @@ -5514,12 +5431,10 @@ std::mutex queue_locker; { // NULL event handle will simply wait immediately: // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12fence-seteventoncompletion#remarks - hr = frame_fence[bufferindex][queue]->SetEventOnCompletion(1, NULL); - dx12_check(hr); + dx12_check(frame_fence[bufferindex][queue]->SetEventOnCompletion(1, NULL)); } - hr = frame_fence[bufferindex][queue]->Signal(0); + dx12_check(frame_fence[bufferindex][queue]->Signal(0)); } - dx12_check(hr); allocationhandler->Update(FRAMECOUNT, BUFFERCOUNT); } @@ -5778,19 +5693,16 @@ std::mutex queue_locker; void GraphicsDevice_DX12::WaitForGPU() const { ComPtr fence; - HRESULT hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(fence)); - dx12_check(hr); + dx12_check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(fence))); for (auto& queue : queues) { if (queue.queue == nullptr) continue; - hr = queue.queue->Signal(fence.Get(), 1); - dx12_check(hr); + dx12_check(queue.queue->Signal(fence.Get(), 1)); if (fence->GetCompletedValue() < 1) { - hr = fence->SetEventOnCompletion(1, NULL); - dx12_check(hr); + dx12_check(fence->SetEventOnCompletion(1, NULL)); } fence->Signal(0); } @@ -7682,8 +7594,7 @@ std::mutex queue_locker; // Debug immediate submit-wait: #if 0 ComPtr fence; - HRESULT hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(fence)); - dx12_check(hr); + dx12_check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(fence))); //D3D12_RESOURCE_BARRIER bar = {}; //bar.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; @@ -7693,8 +7604,7 @@ std::mutex queue_locker; //bar.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; //commandlist.GetVideoDecodeCommandList()->ResourceBarrier(1, &bar); - hr = commandlist.GetVideoDecodeCommandList()->Close(); - dx12_check(hr); + dx12_check(commandlist.GetVideoDecodeCommandList()->Close()); CommandQueue& queue = queues[commandlist.queue]; queue.submit_cmds.push_back(commandlist.GetCommandList()); @@ -7704,19 +7614,15 @@ std::mutex queue_locker; ); queue.submit_cmds.clear(); - hr = queue.queue->Signal(fence.Get(), 1); - dx12_check(hr); + dx12_check(queue.queue->Signal(fence.Get(), 1)); if (fence->GetCompletedValue() < 1) { - hr = fence->SetEventOnCompletion(1, NULL); - dx12_check(hr); + dx12_check(fence->SetEventOnCompletion(1, NULL)); } fence->Signal(0); - hr = commandlist.GetCommandAllocator()->Reset(); - dx12_check(hr); - hr = commandlist.GetVideoDecodeCommandList()->Reset(commandlist.GetCommandAllocator()); - dx12_check(hr); + dx12_check(commandlist.GetCommandAllocator()->Reset()); + dx12_check(commandlist.GetVideoDecodeCommandList()->Reset(commandlist.GetCommandAllocator())); #endif } diff --git a/WickedEngine/wiGraphicsDevice_DX12.h b/WickedEngine/wiGraphicsDevice_DX12.h index c3482c866..787a3ee7b 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.h +++ b/WickedEngine/wiGraphicsDevice_DX12.h @@ -33,7 +33,9 @@ #include #include -#define dx12_check(hr) wilog_assert(SUCCEEDED(hr), "DX12 error: %s, line %d, hr = %s", relative_path(__FILE__), __LINE__, wi::helper::GetPlatformErrorString(hr).c_str()) +#define dx12_assert(cond, fname) { wilog_assert(cond, "DX 12 error: %s failed with %s (%s:%d)", fname, wi::helper::GetPlatformErrorString(hr), relative_path(__FILE__), __LINE__); } + +#define dx12_check(call) [&]() { HRESULT hr = call; char buf[256]; dx12_assert(SUCCEEDED(hr), wi::backlog::internal::extract_function_name(buf, #call)); return hr; }() namespace wi::graphics { @@ -141,8 +143,7 @@ namespace wi::graphics if (semaphore_pool.empty()) { Semaphore& dependency = semaphore_pool.emplace_back(); - HRESULT hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(dependency.fence)); - dx12_check(hr); + dx12_check(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, PPV_ARGS(dependency.fence))); } Semaphore semaphore = std::move(semaphore_pool.back()); semaphore_pool.pop_back(); @@ -456,8 +457,7 @@ namespace wi::graphics { // Descriptor heaps' progress is recorded by the GPU: fenceValue = allocationOffset.load(); - HRESULT hr = queue->Signal(fence.Get(), fenceValue); - dx12_check(hr); + dx12_check(queue->Signal(fence.Get(), fenceValue)); cached_completedValue = fence->GetCompletedValue(); } }; @@ -492,8 +492,7 @@ namespace wi::graphics void block_allocate() { heaps.emplace_back(); - HRESULT hr = device->device->CreateDescriptorHeap(&desc, PPV_ARGS(heaps.back())); - dx12_check(hr); + dx12_check(device->device->CreateDescriptorHeap(&desc, PPV_ARGS(heaps.back()))); D3D12_CPU_DESCRIPTOR_HANDLE heap_start = heaps.back()->GetCPUDescriptorHandleForHeapStart(); for (UINT i = 0; i < desc.NumDescriptors; ++i) { diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 965ef32c3..4483340ba 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -1124,28 +1124,21 @@ namespace vulkan_internal // so we have to be extra careful std::scoped_lock lock(internal_state->locker); - VkResult res; - VkSurfaceCapabilitiesKHR swapchain_capabilities; - res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, internal_state->surface, &swapchain_capabilities); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, internal_state->surface, &swapchain_capabilities)); uint32_t formatCount; - res = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, internal_state->surface, &formatCount, nullptr); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, internal_state->surface, &formatCount, nullptr)); wi::vector swapchain_formats(formatCount); - res = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, internal_state->surface, &formatCount, swapchain_formats.data()); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, internal_state->surface, &formatCount, swapchain_formats.data())); uint32_t presentModeCount; - res = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, internal_state->surface, &presentModeCount, nullptr); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, internal_state->surface, &presentModeCount, nullptr)); wi::vector swapchain_presentModes(presentModeCount); swapchain_presentModes.resize(presentModeCount); - res = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, internal_state->surface, &presentModeCount, swapchain_presentModes.data()); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, internal_state->surface, &presentModeCount, swapchain_presentModes.data())); VkSurfaceFormatKHR surfaceFormat = {}; surfaceFormat.format = _ConvertFormat(internal_state->desc.format); @@ -1192,8 +1185,7 @@ namespace vulkan_internal { // For some reason, if the swapchain gets recreated (via oldSwapChain) with different color space but same image format, // the color space change will not be applied - res = vkDeviceWaitIdle(device); - vulkan_check(res); + vulkan_check(vkDeviceWaitIdle(device)); vkDestroySwapchainKHR(device, internal_state->swapChain, nullptr); internal_state->swapChain = nullptr; } @@ -1249,8 +1241,7 @@ namespace vulkan_internal createInfo.clipped = VK_TRUE; createInfo.oldSwapchain = internal_state->swapChain; - res = vkCreateSwapchainKHR(device, &createInfo, nullptr, &internal_state->swapChain); - vulkan_check(res); + vulkan_check(vkCreateSwapchainKHR(device, &createInfo, nullptr, &internal_state->swapChain)); if (createInfo.oldSwapchain != VK_NULL_HANDLE) { @@ -1258,11 +1249,9 @@ namespace vulkan_internal allocationhandler->destroyer_swapchains.emplace_back(createInfo.oldSwapchain, allocationhandler->framecount); } - res = vkGetSwapchainImagesKHR(device, internal_state->swapChain, &imageCount, nullptr); - vulkan_check(res); + vulkan_check(vkGetSwapchainImagesKHR(device, internal_state->swapChain, &imageCount, nullptr)); internal_state->swapChainImages.resize(imageCount); - res = vkGetSwapchainImagesKHR(device, internal_state->swapChain, &imageCount, internal_state->swapChainImages.data()); - vulkan_check(res); + vulkan_check(vkGetSwapchainImagesKHR(device, internal_state->swapChain, &imageCount, internal_state->swapChainImages.data())); internal_state->swapChainImageFormat = surfaceFormat.format; // Create swap chain render targets: @@ -1290,8 +1279,7 @@ namespace vulkan_internal allocationhandler->destroyer_imageviews.push_back(std::make_pair(internal_state->swapChainImageViews[i], allocationhandler->framecount)); allocationhandler->destroylocker.unlock(); } - res = vkCreateImageView(device, &createInfo, nullptr, &internal_state->swapChainImageViews[i]); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &createInfo, nullptr, &internal_state->swapChainImageViews[i])); } @@ -1302,15 +1290,13 @@ namespace vulkan_internal { for (size_t i = 0; i < internal_state->swapChainImages.size(); ++i) { - res = vkCreateSemaphore(device, &semaphoreInfo, nullptr, &internal_state->swapchainAcquireSemaphores.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSemaphore(device, &semaphoreInfo, nullptr, &internal_state->swapchainAcquireSemaphores.emplace_back())); } } if (internal_state->swapchainReleaseSemaphore == VK_NULL_HANDLE) { - res = vkCreateSemaphore(device, &semaphoreInfo, nullptr, &internal_state->swapchainReleaseSemaphore); - vulkan_check(res); + vulkan_check(vkCreateSemaphore(device, &semaphoreInfo, nullptr, &internal_state->swapchainReleaseSemaphore)); } return true; @@ -1357,8 +1343,7 @@ using namespace vulkan_internal; submitInfo.signalSemaphoreInfoCount = (uint32_t)submit_signalSemaphoreInfos.size(); submitInfo.pSignalSemaphoreInfos = submit_signalSemaphoreInfos.data(); - VkResult res = vkQueueSubmit2(queue, 1, &submitInfo, fence); - vulkan_check(res); + vulkan_check(vkQueueSubmit2(queue, 1, &submitInfo, fence)); if (!submit_swapchains.empty()) { @@ -1369,7 +1354,7 @@ using namespace vulkan_internal; presentInfo.swapchainCount = (uint32_t)submit_swapchains.size(); presentInfo.pSwapchains = submit_swapchains.data(); presentInfo.pImageIndices = submit_swapChainImageIndices.data(); - res = vkQueuePresentKHR(queue, &presentInfo); + VkResult res = vkQueuePresentKHR(queue, &presentInfo); if (res != VK_SUCCESS) { // Handle outdated error in present: @@ -1384,7 +1369,7 @@ using namespace vulkan_internal; } else { - vulkan_check(res); + vulkan_assert(false, "vkQueuePresentKHR"); } } } @@ -1444,36 +1429,28 @@ using namespace vulkan_internal; poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; poolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; poolInfo.queueFamilyIndex = device->copyFamily; - VkResult res = vkCreateCommandPool(device->device, &poolInfo, nullptr, &cmd.transferCommandPool); - vulkan_check(res); + vulkan_check(vkCreateCommandPool(device->device, &poolInfo, nullptr, &cmd.transferCommandPool)); poolInfo.queueFamilyIndex = device->graphicsFamily; - res = vkCreateCommandPool(device->device, &poolInfo, nullptr, &cmd.transitionCommandPool); - vulkan_check(res); + vulkan_check(vkCreateCommandPool(device->device, &poolInfo, nullptr, &cmd.transitionCommandPool)); VkCommandBufferAllocateInfo commandBufferInfo = {}; commandBufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; commandBufferInfo.commandBufferCount = 1; commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; commandBufferInfo.commandPool = cmd.transferCommandPool; - res = vkAllocateCommandBuffers(device->device, &commandBufferInfo, &cmd.transferCommandBuffer); - vulkan_check(res); + vulkan_check(vkAllocateCommandBuffers(device->device, &commandBufferInfo, &cmd.transferCommandBuffer)); commandBufferInfo.commandPool = cmd.transitionCommandPool; - res = vkAllocateCommandBuffers(device->device, &commandBufferInfo, &cmd.transitionCommandBuffer); - vulkan_check(res); + vulkan_check(vkAllocateCommandBuffers(device->device, &commandBufferInfo, &cmd.transitionCommandBuffer)); VkFenceCreateInfo fenceInfo = {}; fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; - res = vkCreateFence(device->device, &fenceInfo, nullptr, &cmd.fence); - vulkan_check(res); + vulkan_check(vkCreateFence(device->device, &fenceInfo, nullptr, &cmd.fence)); VkSemaphoreCreateInfo semaphoreInfo = {}; semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - res = vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &cmd.semaphores[0]); - vulkan_check(res); - res = vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &cmd.semaphores[1]); - vulkan_check(res); - res = vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &cmd.semaphores[2]); - vulkan_check(res); + vulkan_check(vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &cmd.semaphores[0])); + vulkan_check(vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &cmd.semaphores[1])); + vulkan_check(vkCreateSemaphore(device->device, &semaphoreInfo, nullptr, &cmd.semaphores[2])); GPUBufferDesc uploaddesc; uploaddesc.size = wi::math::GetNextPowerOfTwo(staging_size); @@ -1485,31 +1462,24 @@ using namespace vulkan_internal; } // begin command list in valid state: - VkResult res = vkResetCommandPool(device->device, cmd.transferCommandPool, 0); - vulkan_check(res); - res = vkResetCommandPool(device->device, cmd.transitionCommandPool, 0); - vulkan_check(res); + vulkan_check(vkResetCommandPool(device->device, cmd.transferCommandPool, 0)); + vulkan_check(vkResetCommandPool(device->device, cmd.transitionCommandPool, 0)); VkCommandBufferBeginInfo beginInfo = {}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; beginInfo.pInheritanceInfo = nullptr; - res = vkBeginCommandBuffer(cmd.transferCommandBuffer, &beginInfo); - vulkan_check(res); - res = vkBeginCommandBuffer(cmd.transitionCommandBuffer, &beginInfo); - vulkan_check(res); + vulkan_check(vkBeginCommandBuffer(cmd.transferCommandBuffer, &beginInfo)); + vulkan_check(vkBeginCommandBuffer(cmd.transitionCommandBuffer, &beginInfo)); - res = vkResetFences(device->device, 1, &cmd.fence); - vulkan_check(res); + vulkan_check(vkResetFences(device->device, 1, &cmd.fence)); return cmd; } void GraphicsDevice_Vulkan::CopyAllocator::submit(CopyCMD cmd) { - VkResult res = vkEndCommandBuffer(cmd.transferCommandBuffer); - vulkan_check(res); - res = vkEndCommandBuffer(cmd.transitionCommandBuffer); - vulkan_check(res); + vulkan_check(vkEndCommandBuffer(cmd.transferCommandBuffer)); + vulkan_check(vkEndCommandBuffer(cmd.transitionCommandBuffer)); VkSubmitInfo2 submitInfo = {}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2; @@ -1535,8 +1505,7 @@ using namespace vulkan_internal; submitInfo.pSignalSemaphoreInfos = signalSemaphoreInfos; std::scoped_lock lock(*device->queues[QUEUE_COPY].locker); - res = vkQueueSubmit2(device->queues[QUEUE_COPY].queue, 1, &submitInfo, VK_NULL_HANDLE); - vulkan_check(res); + vulkan_check(vkQueueSubmit2(device->queues[QUEUE_COPY].queue, 1, &submitInfo, VK_NULL_HANDLE)); } { @@ -1564,8 +1533,7 @@ using namespace vulkan_internal; submitInfo.pSignalSemaphoreInfos = signalSemaphoreInfos; std::scoped_lock lock(*device->queues[QUEUE_GRAPHICS].locker); - res = vkQueueSubmit2(device->queues[QUEUE_GRAPHICS].queue, 1, &submitInfo, VK_NULL_HANDLE); - vulkan_check(res); + vulkan_check(vkQueueSubmit2(device->queues[QUEUE_GRAPHICS].queue, 1, &submitInfo, VK_NULL_HANDLE)); } if (device->queues[QUEUE_VIDEO_DECODE].queue != VK_NULL_HANDLE) @@ -1581,8 +1549,7 @@ using namespace vulkan_internal; submitInfo.pSignalSemaphoreInfos = nullptr; std::scoped_lock lock(*device->queues[QUEUE_VIDEO_DECODE].locker); - res = vkQueueSubmit2(device->queues[QUEUE_VIDEO_DECODE].queue, 1, &submitInfo, VK_NULL_HANDLE); - vulkan_check(res); + vulkan_check(vkQueueSubmit2(device->queues[QUEUE_VIDEO_DECODE].queue, 1, &submitInfo, VK_NULL_HANDLE)); } // This must be final submit in this function because it will also signal a fence for state tracking by CPU! @@ -1598,8 +1565,7 @@ using namespace vulkan_internal; submitInfo.pSignalSemaphoreInfos = nullptr; std::scoped_lock lock(*device->queues[QUEUE_COMPUTE].locker); - res = vkQueueSubmit2(device->queues[QUEUE_COMPUTE].queue, 1, &submitInfo, cmd.fence); // final submit also signals fence! - vulkan_check(res); + vulkan_check(vkQueueSubmit2(device->queues[QUEUE_COMPUTE].queue, 1, &submitInfo, cmd.fence)); // final submit also signals fence! } std::scoped_lock lock(locker); @@ -1666,16 +1632,14 @@ using namespace vulkan_internal; poolInfo.maxSets = poolSize; destroy(); // issues destroy if already exists, nop otherwise - res = vkCreateDescriptorPool(device->device, &poolInfo, nullptr, &descriptorPool); - vulkan_check(res); + vulkan_check(vkCreateDescriptorPool(device->device, &poolInfo, nullptr, &descriptorPool)); #if 0 VkDebugUtilsObjectNameInfoEXT info{ VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT }; info.pObjectName = "DescriptorBinderPool"; info.objectType = VK_OBJECT_TYPE_DESCRIPTOR_POOL; info.objectHandle = (uint64_t)descriptorPool; - res = vkSetDebugUtilsObjectNameEXT(device->device, &info); - vulkan_check(res); + vulkan_check(vkSetDebugUtilsObjectNameEXT(device->device, &info)); #endif // WARNING: MUST NOT CALL reset() HERE! @@ -1696,8 +1660,7 @@ using namespace vulkan_internal; { if (descriptorPool != VK_NULL_HANDLE) { - VkResult res = vkResetDescriptorPool(device->device, descriptorPool, 0); - vulkan_check(res); + vulkan_check(vkResetDescriptorPool(device->device, descriptorPool, 0)); } } @@ -1772,7 +1735,7 @@ using namespace vulkan_internal; allocInfo.descriptorPool = binder_pool.descriptorPool; res = vkAllocateDescriptorSets(device->device, &allocInfo, &descriptorSet); } - vulkan_check(res); + vulkan_assert(res >= VK_SUCCESS, "vkAllocateDescriptorSets"); descriptorWrites.clear(); bufferInfos.clear(); @@ -2345,8 +2308,7 @@ using namespace vulkan_internal; } pipelineInfo.pNext = &renderingInfo; - VkResult res = vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineInfo, nullptr, &pipeline); - vulkan_check(res); + vulkan_check(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineInfo, nullptr, &pipeline)); commandlist.pipelines_worker.push_back(std::make_pair(pipeline_hash, pipeline)); } @@ -2392,8 +2354,7 @@ using namespace vulkan_internal; VkResult res; - res = volkInitialize(); - vulkan_check(res); + res = vulkan_check(volkInitialize()); if (res != VK_SUCCESS) { wi::helper::messageBox("volkInitialize failed! ERROR: " + std::string(string_VkResult(res)), "Error!"); @@ -2411,18 +2372,14 @@ using namespace vulkan_internal; // Enumerate available layers and extensions: uint32_t instanceLayerCount; - res = vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr); - vulkan_check(res); + vulkan_check(vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr)); wi::vector availableInstanceLayers(instanceLayerCount); - res = vkEnumerateInstanceLayerProperties(&instanceLayerCount, availableInstanceLayers.data()); - vulkan_check(res); + vulkan_check(vkEnumerateInstanceLayerProperties(&instanceLayerCount, availableInstanceLayers.data())); uint32_t extensionCount = 0; - res = vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); - vulkan_check(res); + vulkan_check(vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr)); wi::vector availableInstanceExtensions(extensionCount); - res = vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, availableInstanceExtensions.data()); - vulkan_check(res); + vulkan_check(vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, availableInstanceExtensions.data())); wi::vector instanceLayers; wi::vector instanceExtensions; @@ -2526,8 +2483,7 @@ using namespace vulkan_internal; createInfo.pNext = &debugUtilsCreateInfo; } - res = vkCreateInstance(&createInfo, nullptr, &instance); - vulkan_check(res); + vulkan_check(vkCreateInstance(&createInfo, nullptr, &instance)); if (res != VK_SUCCESS) { wi::helper::messageBox("vkCreateInstance failed! ERROR: " + std::string(string_VkResult(res)), "Error!"); @@ -2538,16 +2494,14 @@ using namespace vulkan_internal; if (validationMode != ValidationMode::Disabled && debugUtils) { - res = vkCreateDebugUtilsMessengerEXT(instance, &debugUtilsCreateInfo, nullptr, &debugUtilsMessenger); - vulkan_check(res); + vulkan_check(vkCreateDebugUtilsMessengerEXT(instance, &debugUtilsCreateInfo, nullptr, &debugUtilsMessenger)); } } // Enumerating and creating devices: { uint32_t deviceCount = 0; - VkResult res = vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr); - vulkan_check(res); + vulkan_check(vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr)); if (deviceCount == 0) { wilog_messagebox("Failed to find GPU with Vulkan 1.3 support!"); @@ -2555,8 +2509,7 @@ using namespace vulkan_internal; } wi::vector devices(deviceCount); - res = vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data()); - vulkan_check(res); + vulkan_check(vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data())); const wi::vector required_deviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, @@ -2571,11 +2524,9 @@ using namespace vulkan_internal; suitable = true; uint32_t extensionCount; - VkResult res = vkEnumerateDeviceExtensionProperties(dev, nullptr, &extensionCount, nullptr); - vulkan_check(res); + vulkan_check(vkEnumerateDeviceExtensionProperties(dev, nullptr, &extensionCount, nullptr)); wi::vector available_deviceExtensions(extensionCount); - res = vkEnumerateDeviceExtensionProperties(dev, nullptr, &extensionCount, available_deviceExtensions.data()); - vulkan_check(res); + vulkan_check(vkEnumerateDeviceExtensionProperties(dev, nullptr, &extensionCount, available_deviceExtensions.data())); for (auto& x : required_deviceExtensions) { @@ -2948,8 +2899,7 @@ using namespace vulkan_internal; video_capability_h264.video_capabilities.sType = VK_STRUCTURE_TYPE_VIDEO_CAPABILITIES_KHR; video_capability_h264.video_capabilities.pNext = &video_capability_h264.decode_capabilities; video_capability_h264.decode_capabilities.pNext = &decode_h264_capabilities; - res = vkGetPhysicalDeviceVideoCapabilitiesKHR(physicalDevice, &video_capability_h264.profile, &video_capability_h264.video_capabilities); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceVideoCapabilitiesKHR(physicalDevice, &video_capability_h264.profile, &video_capability_h264.video_capabilities)); if (video_capability_h264.decode_capabilities.flags) { @@ -3083,8 +3033,7 @@ using namespace vulkan_internal; createInfo.enabledExtensionCount = static_cast(enabled_deviceExtensions.size()); createInfo.ppEnabledExtensionNames = enabled_deviceExtensions.data(); - res = vkCreateDevice(physicalDevice, &createInfo, nullptr, &device); - vulkan_check(res); + vulkan_check(vkCreateDevice(physicalDevice, &createInfo, nullptr, &device)); if (res != VK_SUCCESS) { wi::helper::messageBox("vkCreateDevice failed! ERROR: " + std::string(string_VkResult(res)), "Error!"); @@ -3155,8 +3104,7 @@ using namespace vulkan_internal; vulkanFunctions.vkGetDeviceProcAddr = vkGetDeviceProcAddr; allocatorInfo.pVulkanFunctions = &vulkanFunctions; #endif - res = vmaCreateAllocator(&allocatorInfo, &allocationhandler->allocator); - vulkan_check(res); + vulkan_check(vmaCreateAllocator(&allocatorInfo, &allocationhandler->allocator)); if (res != VK_SUCCESS) { wi::helper::messageBox("vmaCreateAllocator failed! ERROR: " + std::string(string_VkResult(res)), "Error!"); @@ -3172,8 +3120,7 @@ using namespace vulkan_internal; allocatorInfo.pTypeExternalMemoryHandleTypes = externalMemoryHandleTypes.data(); #endif - res = vmaCreateAllocator(&allocatorInfo, &allocationhandler->externalAllocator); - vulkan_check(res); + vulkan_check(vmaCreateAllocator(&allocatorInfo, &allocationhandler->externalAllocator)); if (res != VK_SUCCESS) { wi::helper::messageBox("Failed to create Vulkan external memory allocator, ERROR: " + std::string(string_VkResult(res)), "Error!"); @@ -3193,8 +3140,7 @@ using namespace vulkan_internal; VkFenceCreateInfo fenceInfo = {}; fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; //fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; - VkResult res = vkCreateFence(device, &fenceInfo, nullptr, &frame_fence[fr][queue]); - vulkan_check(res); + vulkan_check(vkCreateFence(device, &fenceInfo, nullptr, &frame_fence[fr][queue])); if (res != VK_SUCCESS) { wi::helper::messageBox("vkCreateFence[FRAME] failed! ERROR: " + std::string(string_VkResult(res)), "Error!"); @@ -3215,16 +3161,14 @@ using namespace vulkan_internal; VmaAllocationCreateInfo allocInfo = {}; allocInfo.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; - res = vmaCreateBuffer(allocationhandler->allocator, &bufferInfo, &allocInfo, &nullBuffer, &nullBufferAllocation, nullptr); - vulkan_check(res); + vulkan_check(vmaCreateBuffer(allocationhandler->allocator, &bufferInfo, &allocInfo, &nullBuffer, &nullBufferAllocation, nullptr)); VkBufferViewCreateInfo viewInfo = {}; viewInfo.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; viewInfo.format = VK_FORMAT_R32G32B32A32_SFLOAT; viewInfo.range = VK_WHOLE_SIZE; viewInfo.buffer = nullBuffer; - res = vkCreateBufferView(device, &viewInfo, nullptr, &nullBufferView); - vulkan_check(res); + vulkan_check(vkCreateBufferView(device, &viewInfo, nullptr, &nullBufferView)); } { VkImageCreateInfo imageInfo = {}; @@ -3245,20 +3189,17 @@ using namespace vulkan_internal; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; imageInfo.imageType = VK_IMAGE_TYPE_1D; - res = vmaCreateImage(allocationhandler->allocator, &imageInfo, &allocInfo, &nullImage1D, &nullImageAllocation1D, nullptr); - vulkan_check(res); + vulkan_check(vmaCreateImage(allocationhandler->allocator, &imageInfo, &allocInfo, &nullImage1D, &nullImageAllocation1D, nullptr)); imageInfo.imageType = VK_IMAGE_TYPE_2D; imageInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; imageInfo.arrayLayers = 6; - res = vmaCreateImage(allocationhandler->allocator, &imageInfo, &allocInfo, &nullImage2D, &nullImageAllocation2D, nullptr); - vulkan_check(res); + vulkan_check(vmaCreateImage(allocationhandler->allocator, &imageInfo, &allocInfo, &nullImage2D, &nullImageAllocation2D, nullptr)); imageInfo.imageType = VK_IMAGE_TYPE_3D; imageInfo.flags = 0; imageInfo.arrayLayers = 1; - res = vmaCreateImage(allocationhandler->allocator, &imageInfo, &allocInfo, &nullImage3D, &nullImageAllocation3D, nullptr); - vulkan_check(res); + vulkan_check(vmaCreateImage(allocationhandler->allocator, &imageInfo, &allocInfo, &nullImage3D, &nullImageAllocation3D, nullptr)); // Transitions: @@ -3310,48 +3251,40 @@ using namespace vulkan_internal; viewInfo.image = nullImage1D; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_1D; - res = vkCreateImageView(device, &viewInfo, nullptr, &nullImageView1D); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &viewInfo, nullptr, &nullImageView1D)); viewInfo.image = nullImage1D; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_1D_ARRAY; - res = vkCreateImageView(device, &viewInfo, nullptr, &nullImageView1DArray); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &viewInfo, nullptr, &nullImageView1DArray)); viewInfo.image = nullImage2D; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; - res = vkCreateImageView(device, &viewInfo, nullptr, &nullImageView2D); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &viewInfo, nullptr, &nullImageView2D)); viewInfo.image = nullImage2D; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; - res = vkCreateImageView(device, &viewInfo, nullptr, &nullImageView2DArray); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &viewInfo, nullptr, &nullImageView2DArray)); viewInfo.image = nullImage2D; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_CUBE; viewInfo.subresourceRange.layerCount = 6; - res = vkCreateImageView(device, &viewInfo, nullptr, &nullImageViewCube); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &viewInfo, nullptr, &nullImageViewCube)); viewInfo.image = nullImage2D; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY; viewInfo.subresourceRange.layerCount = 6; - res = vkCreateImageView(device, &viewInfo, nullptr, &nullImageViewCubeArray); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &viewInfo, nullptr, &nullImageViewCubeArray)); viewInfo.image = nullImage3D; viewInfo.subresourceRange.layerCount = 1; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_3D; - res = vkCreateImageView(device, &viewInfo, nullptr, &nullImageView3D); - vulkan_check(res); + vulkan_check(vkCreateImageView(device, &viewInfo, nullptr, &nullImageView3D)); } { VkSamplerCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - res = vkCreateSampler(device, &createInfo, nullptr, &nullSampler); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &nullSampler)); } TIMESTAMP_FREQUENCY = uint64_t(1.0 / double(properties2.properties.limits.timestampPeriod) * 1000 * 1000 * 1000); @@ -3478,8 +3411,7 @@ using namespace vulkan_internal; createInfo.pInitialData = pipelineData.data(); // Create Vulkan pipeline cache - res = vkCreatePipelineCache(device, &createInfo, nullptr, &pipelineCache); - vulkan_check(res); + vulkan_check(vkCreatePipelineCache(device, &createInfo, nullptr, &pipelineCache)); } // Static samplers: @@ -3503,8 +3435,7 @@ using namespace vulkan_internal; createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_linear_wrap: createInfo.minFilter = VK_FILTER_LINEAR; @@ -3513,8 +3444,7 @@ using namespace vulkan_internal; createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); //sampler_linear_mirror: createInfo.minFilter = VK_FILTER_LINEAR; @@ -3523,8 +3453,7 @@ using namespace vulkan_internal; createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_point_clamp: createInfo.minFilter = VK_FILTER_NEAREST; @@ -3533,8 +3462,7 @@ using namespace vulkan_internal; createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_point_wrap: createInfo.minFilter = VK_FILTER_NEAREST; @@ -3543,8 +3471,7 @@ using namespace vulkan_internal; createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_point_mirror: createInfo.minFilter = VK_FILTER_NEAREST; @@ -3553,8 +3480,7 @@ using namespace vulkan_internal; createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_aniso_clamp: createInfo.minFilter = VK_FILTER_LINEAR; @@ -3565,8 +3491,7 @@ using namespace vulkan_internal; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; createInfo.anisotropyEnable = true; createInfo.maxAnisotropy = 16; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_aniso_wrap: createInfo.minFilter = VK_FILTER_LINEAR; @@ -3577,8 +3502,7 @@ using namespace vulkan_internal; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; createInfo.anisotropyEnable = true; createInfo.maxAnisotropy = 16; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_aniso_mirror: createInfo.minFilter = VK_FILTER_LINEAR; @@ -3589,8 +3513,7 @@ using namespace vulkan_internal; createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT; createInfo.anisotropyEnable = true; createInfo.maxAnisotropy = 16; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); // sampler_cmp_depth: createInfo.minFilter = VK_FILTER_LINEAR; @@ -3605,16 +3528,14 @@ using namespace vulkan_internal; createInfo.compareOp = VK_COMPARE_OP_GREATER_OR_EQUAL; createInfo.minLod = 0; createInfo.maxLod = 0; - res = vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back()); - vulkan_check(res); + vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &immutable_samplers.emplace_back())); } wilog("Created GraphicsDevice_Vulkan (%d ms)\nAdapter: %s", (int)std::round(timer.elapsed()), adapterName.c_str()); } GraphicsDevice_Vulkan::~GraphicsDevice_Vulkan() { - VkResult res = vkDeviceWaitIdle(device); - vulkan_check(res); + vulkan_check(vkDeviceWaitIdle(device)); for (uint32_t fr = 0; fr < BUFFERCOUNT; ++fr) { @@ -3683,13 +3604,11 @@ using namespace vulkan_internal; { // Get size of pipeline cache size_t size{}; - res = vkGetPipelineCacheData(device, pipelineCache, &size, nullptr); - vulkan_check(res); + vulkan_check(vkGetPipelineCacheData(device, pipelineCache, &size, nullptr)); // Get data of pipeline cache wi::vector data(size); - res = vkGetPipelineCacheData(device, pipelineCache, &size, data.data()); - vulkan_check(res); + vulkan_check(vkGetPipelineCacheData(device, pipelineCache, &size, data.data())); // Write pipeline cache data to a file in binary format wi::helper::FileWrite(get_shader_cache_path(), data.data(), size); @@ -3728,8 +3647,7 @@ using namespace vulkan_internal; createInfo.hwnd = window; createInfo.hinstance = GetModuleHandle(nullptr); - res = vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr, &internal_state->surface); - vulkan_check(res); + vulkan_check(vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr, &internal_state->surface)); #elif SDL2 if (!SDL_Vulkan_CreateSurface(window, instance, &internal_state->surface)) { @@ -3745,8 +3663,7 @@ using namespace vulkan_internal; for (const auto& queueFamily : queueFamilies) { VkBool32 presentSupport = false; - res = vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, (uint32_t)familyIndex, internal_state->surface, &presentSupport); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, (uint32_t)familyIndex, internal_state->surface, &presentSupport)); if (presentFamily == VK_QUEUE_FAMILY_IGNORED && queueFamily.queueFamilyProperties.queueCount > 0 && presentSupport) { @@ -3887,30 +3804,27 @@ using namespace vulkan_internal; VmaAllocationInfo allocation_info = {}; - res = vmaAllocateMemory( + res = vulkan_check(vmaAllocateMemory( allocationhandler->allocator, &memory_requirements, &create_info, &internal_state->allocation, &allocation_info - ); - vulkan_check(res); + )); - res = vkCreateBuffer( + res = vulkan_check(vkCreateBuffer( device, &bufferInfo, nullptr, &internal_state->resource - ); - vulkan_check(res); + )); - res = vkBindBufferMemory( + res = vulkan_check(vkBindBufferMemory( device, internal_state->resource, internal_state->allocation->GetMemory(), internal_state->allocation->GetOffset() - ); - vulkan_check(res); + )); } else if (has_flag(desc->misc_flags, ResourceMiscFlag::SPARSE)) { @@ -3919,8 +3833,7 @@ using namespace vulkan_internal; bufferInfo.flags |= VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT; bufferInfo.flags |= VK_BUFFER_CREATE_SPARSE_ALIASED_BIT; - res = vkCreateBuffer(device, &bufferInfo, nullptr, &internal_state->resource); - vulkan_check(res); + res = vulkan_check(vkCreateBuffer(device, &bufferInfo, nullptr, &internal_state->resource)); VkMemoryRequirements memory_requirements = {}; vkGetBufferMemoryRequirements( @@ -3947,14 +3860,14 @@ using namespace vulkan_internal; if (alias == nullptr) { - res = vmaCreateBuffer( + res = vulkan_check(vmaCreateBuffer( allocationhandler->allocator, &bufferInfo, &allocInfo, &internal_state->resource, &internal_state->allocation, nullptr - ); + )); } else { @@ -3962,27 +3875,26 @@ using namespace vulkan_internal; if (alias->IsTexture()) { auto alias_internal = to_internal((const Texture*)alias); - res = vmaCreateAliasingBuffer2( + res = vulkan_check(vmaCreateAliasingBuffer2( allocationhandler->allocator, alias_internal->allocation, alias_offset, &bufferInfo, &internal_state->resource - ); + )); } else { auto alias_internal = to_internal((const GPUBuffer*)alias); - res = vmaCreateAliasingBuffer2( + res = vulkan_check(vmaCreateAliasingBuffer2( allocationhandler->allocator, alias_internal->allocation, alias_offset, &bufferInfo, &internal_state->resource - ); + )); } } - vulkan_check(res); } if (desc->usage == Usage::READBACK || desc->usage == Usage::UPLOAD) @@ -4208,16 +4120,14 @@ using namespace vulkan_internal; video_format_info.imageUsage = imageInfo.usage; video_format_info.pNext = &profile_list_info; uint32_t format_property_count = 0; - VkResult res = vkGetPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &video_format_info, &format_property_count, nullptr); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &video_format_info, &format_property_count, nullptr)); wi::vector video_format_properties(format_property_count); for (auto& x : video_format_properties) { x.sType = VK_STRUCTURE_TYPE_VIDEO_FORMAT_PROPERTIES_KHR; } - res = vkGetPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &video_format_info, &format_property_count, video_format_properties.data()); - vulkan_check(res); + vulkan_check(vkGetPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &video_format_info, &format_property_count, video_format_properties.data())); //assert(imageInfo.flags == 0 || (!video_format_properties.empty() && video_format_properties[0].imageCreateFlags & imageInfo.flags)); //assert(!video_format_properties.empty() && video_format_properties[0].imageUsageFlags & imageInfo.usage); @@ -4250,7 +4160,7 @@ using namespace vulkan_internal; break; } - VkResult res; + VkResult res = VK_SUCCESS; if (has_flag(texture->desc.misc_flags, ResourceMiscFlag::SPARSE)) { @@ -4260,10 +4170,10 @@ using namespace vulkan_internal; imageInfo.flags |= VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT; imageInfo.flags |= VK_IMAGE_CREATE_SPARSE_ALIASED_BIT; - res = vkCreateImage(device, &imageInfo, nullptr, &internal_state->resource); - vulkan_check(res); + vulkan_check(vkCreateImage(device, &imageInfo, nullptr, &internal_state->resource)); VkMemoryRequirements memory_requirements = {}; + // no check needed, returns void vkGetImageMemoryRequirements( device, internal_state->resource, @@ -4359,8 +4269,7 @@ using namespace vulkan_internal; bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; } - res = vmaCreateBuffer(allocationhandler->allocator, &bufferInfo, &allocInfo, &internal_state->staging_resource, &internal_state->allocation, nullptr); - vulkan_check(res); + res = vulkan_check(vmaCreateBuffer(allocationhandler->allocator, &bufferInfo, &allocInfo, &internal_state->staging_resource, &internal_state->allocation, nullptr)); if (texture->desc.usage == Usage::READBACK || texture->desc.usage == Usage::UPLOAD) { @@ -4415,14 +4324,14 @@ using namespace vulkan_internal; if (alias == nullptr) { - res = vmaCreateImage( + res = vulkan_check(vmaCreateImage( allocator, &imageInfo, &allocInfo, &internal_state->resource, &internal_state->allocation, nullptr - ); + )); } else { @@ -4430,27 +4339,26 @@ using namespace vulkan_internal; if (alias->IsTexture()) { auto alias_internal = to_internal((const Texture*)alias); - res = vmaCreateAliasingImage2( + res = vulkan_check(vmaCreateAliasingImage2( allocator, alias_internal->allocation, alias_offset, &imageInfo, &internal_state->resource - ); + )); } else { auto alias_internal = to_internal((const GPUBuffer*)alias); - res = vmaCreateAliasingImage2( + res = vulkan_check(vmaCreateAliasingImage2( allocator, alias_internal->allocation, alias_offset, &imageInfo, &internal_state->resource - ); + )); } } - vulkan_check(res); if (has_flag(texture->desc.misc_flags, ResourceMiscFlag::SHARED)) { @@ -4463,16 +4371,14 @@ using namespace vulkan_internal; getWin32HandleInfoKHR.pNext = nullptr; getWin32HandleInfoKHR.memory = allocationInfo.deviceMemory; getWin32HandleInfoKHR.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; - res = vkGetMemoryWin32HandleKHR(allocationhandler->device, &getWin32HandleInfoKHR, &texture->shared_handle); - vulkan_check(res); + res = vulkan_check(vkGetMemoryWin32HandleKHR(allocationhandler->device, &getWin32HandleInfoKHR, &texture->shared_handle)); #elif defined(__linux__) VkMemoryGetFdInfoKHR memoryGetFdInfoKHR = {}; memoryGetFdInfoKHR.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR; memoryGetFdInfoKHR.pNext = nullptr; memoryGetFdInfoKHR.memory = allocationInfo.deviceMemory; memoryGetFdInfoKHR.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; - res = vkGetMemoryFdKHR(allocationhandler->device, &memoryGetFdInfoKHR, &texture->shared_handle); - vulkan_check(res); + res = vulkan_check(vkGetMemoryFdKHR(allocationhandler->device, &memoryGetFdInfoKHR, &texture->shared_handle)); #endif } } @@ -4682,11 +4588,10 @@ using namespace vulkan_internal; viewUsageInfo.usage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_SRC_BIT_KHR | VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR; view_desc.pNext = &viewUsageInfo; - res = vkCreateImageView(device, &view_desc, nullptr, &internal_state->video_decode_view); - vulkan_check(res); + res = vulkan_check(vkCreateImageView(device, &view_desc, nullptr, &internal_state->video_decode_view)); } - return res == VK_SUCCESS; + return res >= VK_SUCCESS; } bool GraphicsDevice_Vulkan::CreateShader(ShaderStage stage, const void* shadercode, size_t shadercode_size, Shader* shader) const { @@ -4701,8 +4606,7 @@ using namespace vulkan_internal; moduleInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; moduleInfo.codeSize = shadercode_size; moduleInfo.pCode = (const uint32_t*)shadercode; - res = vkCreateShaderModule(device, &moduleInfo, nullptr, &internal_state->shaderModule); - vulkan_check(res); + vulkan_check(vkCreateShaderModule(device, &moduleInfo, nullptr, &internal_state->shaderModule)); internal_state->stageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; internal_state->stageInfo.module = internal_state->shaderModule; @@ -4900,8 +4804,7 @@ using namespace vulkan_internal; descriptorSetlayoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; descriptorSetlayoutInfo.pBindings = internal_state->layoutBindings.data(); descriptorSetlayoutInfo.bindingCount = uint32_t(internal_state->layoutBindings.size()); - res = vkCreateDescriptorSetLayout(device, &descriptorSetlayoutInfo, nullptr, &internal_state->descriptorSetLayout); - vulkan_check(res); + vulkan_check(vkCreateDescriptorSetLayout(device, &descriptorSetlayoutInfo, nullptr, &internal_state->descriptorSetLayout)); layouts.push_back(internal_state->descriptorSetLayout); } @@ -4961,8 +4864,7 @@ using namespace vulkan_internal; pipelineLayoutInfo.pPushConstantRanges = nullptr; } - res = vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &internal_state->pipelineLayout_cs); - vulkan_check(res); + vulkan_check(vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &internal_state->pipelineLayout_cs)); if (res == VK_SUCCESS) { pso_layout_cache[internal_state->binding_hash].descriptorSetLayout = internal_state->descriptorSetLayout; @@ -4995,8 +4897,7 @@ using namespace vulkan_internal; // Create compute pipeline state in place: pipelineInfo.stage = internal_state->stageInfo; - res = vkCreateComputePipelines(device, pipelineCache, 1, &pipelineInfo, nullptr, &internal_state->pipeline_cs); - vulkan_check(res); + vulkan_check(vkCreateComputePipelines(device, pipelineCache, 1, &pipelineInfo, nullptr, &internal_state->pipeline_cs)); } return res == VK_SUCCESS; @@ -5215,8 +5116,7 @@ using namespace vulkan_internal; createInfo.borderColor = _ConvertSamplerBorderColor(desc->border_color); createInfo.unnormalizedCoordinates = VK_FALSE; - VkResult res = vkCreateSampler(device, &createInfo, nullptr, &internal_state->resource); - vulkan_check(res); + VkResult res = vulkan_check(vkCreateSampler(device, &createInfo, nullptr, &internal_state->resource)); internal_state->index = allocationhandler->bindlessSamplers.allocate(); if (internal_state->index >= 0) @@ -5262,8 +5162,7 @@ using namespace vulkan_internal; break; } - VkResult res = vkCreateQueryPool(device, &poolInfo, nullptr, &internal_state->pool); - vulkan_check(res); + VkResult res = vulkan_check(vkCreateQueryPool(device, &poolInfo, nullptr, &internal_state->pool)); return res == VK_SUCCESS; } @@ -5423,8 +5322,7 @@ using namespace vulkan_internal; descriptorSetlayoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; descriptorSetlayoutInfo.pBindings = internal_state->layoutBindings.data(); descriptorSetlayoutInfo.bindingCount = static_cast(internal_state->layoutBindings.size()); - res = vkCreateDescriptorSetLayout(device, &descriptorSetlayoutInfo, nullptr, &internal_state->descriptorSetLayout); - vulkan_check(res); + vulkan_check(vkCreateDescriptorSetLayout(device, &descriptorSetlayoutInfo, nullptr, &internal_state->descriptorSetLayout)); layouts.push_back(internal_state->descriptorSetLayout); } @@ -5485,8 +5383,7 @@ using namespace vulkan_internal; pipelineLayoutInfo.pPushConstantRanges = nullptr; } - res = vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &internal_state->pipelineLayout); - vulkan_check(res); + vulkan_check(vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &internal_state->pipelineLayout)); if (res == VK_SUCCESS) { pso_layout_cache[internal_state->binding_hash].descriptorSetLayout = internal_state->descriptorSetLayout; @@ -5905,8 +5802,7 @@ using namespace vulkan_internal; } pipelineInfo.pNext = &renderingInfo; - VkResult res = vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineInfo, nullptr, &internal_state->pipeline); - vulkan_check(res); + vulkan_check(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineInfo, nullptr, &internal_state->pipeline)); } return res == VK_SUCCESS; @@ -6030,15 +5926,14 @@ using namespace vulkan_internal; VmaAllocationCreateInfo allocInfo = {}; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; - VkResult res = vmaCreateBuffer( + vulkan_check(vmaCreateBuffer( allocationhandler->allocator, &bufferInfo, &allocInfo, &internal_state->buffer, &internal_state->allocation, nullptr - ); - vulkan_check(res); + )); // Create the acceleration structure: internal_state->createInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR; @@ -6046,13 +5941,12 @@ using namespace vulkan_internal; internal_state->createInfo.buffer = internal_state->buffer; internal_state->createInfo.size = internal_state->sizeInfo.accelerationStructureSize; - res = vkCreateAccelerationStructureKHR( + VkResult res = vulkan_check(vkCreateAccelerationStructureKHR( device, &internal_state->createInfo, nullptr, &internal_state->resource - ); - vulkan_check(res); + )); // Get the device address for the acceleration structure: VkAccelerationStructureDeviceAddressInfoKHR addrinfo = {}; @@ -6189,7 +6083,7 @@ using namespace vulkan_internal; info.basePipelineHandle = VK_NULL_HANDLE; info.basePipelineIndex = 0; - VkResult res = vkCreateRayTracingPipelinesKHR( + VkResult res = vulkan_check(vkCreateRayTracingPipelinesKHR( device, VK_NULL_HANDLE, pipelineCache, @@ -6197,8 +6091,7 @@ using namespace vulkan_internal; &info, nullptr, &internal_state->pipeline - ); - vulkan_check(res); + )); return res == VK_SUCCESS; } @@ -6446,20 +6339,17 @@ using namespace vulkan_internal; info.pVideoProfile = &video_capability_h264.profile; info.pStdHeaderVersion = &video_capability_h264.video_capabilities.stdHeaderVersion; - res = vkCreateVideoSessionKHR(device, &info, nullptr, &internal_state->video_session); - vulkan_check(res); + vulkan_check(vkCreateVideoSessionKHR(device, &info, nullptr, &internal_state->video_session)); uint32_t requirement_count = 0; - res = vkGetVideoSessionMemoryRequirementsKHR(device, internal_state->video_session, &requirement_count, nullptr); - vulkan_check(res); + vulkan_check(vkGetVideoSessionMemoryRequirementsKHR(device, internal_state->video_session, &requirement_count, nullptr)); wi::vector requirements(requirement_count); for (auto& x : requirements) { x.sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_MEMORY_REQUIREMENTS_KHR; } - res = vkGetVideoSessionMemoryRequirementsKHR(device, internal_state->video_session, &requirement_count, requirements.data()); - vulkan_check(res); + vulkan_check(vkGetVideoSessionMemoryRequirementsKHR(device, internal_state->video_session, &requirement_count, requirements.data())); internal_state->allocations.resize(requirement_count); wi::vector bind_session_memory_infos(requirement_count); @@ -6470,14 +6360,13 @@ using namespace vulkan_internal; alloc_create_info.memoryTypeBits = video_req.memoryRequirements.memoryTypeBits; VmaAllocationInfo alloc_info = {}; - res = vmaAllocateMemory( + vulkan_check(vmaAllocateMemory( allocationhandler->allocator, &video_req.memoryRequirements, &alloc_create_info, &internal_state->allocations[i], &alloc_info - ); - vulkan_check(res); + )); VkBindVideoSessionMemoryInfoKHR& bind_info = bind_session_memory_infos[i]; bind_info.sType = VK_STRUCTURE_TYPE_BIND_VIDEO_SESSION_MEMORY_INFO_KHR; @@ -6486,8 +6375,7 @@ using namespace vulkan_internal; bind_info.memoryOffset = alloc_info.offset; bind_info.memorySize = alloc_info.size; } - res = vkBindVideoSessionMemoryKHR(device, internal_state->video_session, requirement_count, bind_session_memory_infos.data()); - vulkan_check(res); + vulkan_check(vkBindVideoSessionMemoryKHR(device, internal_state->video_session, requirement_count, bind_session_memory_infos.data())); VkVideoDecodeH264SessionParametersCreateInfoKHR session_parameters_info_h264 = {}; session_parameters_info_h264.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR; @@ -6500,8 +6388,7 @@ using namespace vulkan_internal; session_parameters_info.videoSession = internal_state->video_session; session_parameters_info.videoSessionParametersTemplate = VK_NULL_HANDLE; session_parameters_info.pNext = &session_parameters_info_h264; - res = vkCreateVideoSessionParametersKHR(device, &session_parameters_info, nullptr, &internal_state->session_parameters); - vulkan_check(res); + vulkan_check(vkCreateVideoSessionParametersKHR(device, &session_parameters_info, nullptr, &internal_state->session_parameters)); assert(video_capability_h264.decode_capabilities.flags & VK_VIDEO_DECODE_CAPABILITY_DPB_AND_OUTPUT_COINCIDE_BIT_KHR); // Currently the only method supported @@ -7049,8 +6936,7 @@ using namespace vulkan_internal; } void GraphicsDevice_Vulkan::WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) const { - VkResult res = vkGetRayTracingShaderGroupHandlesKHR(device, to_internal(rtpso)->pipeline, group_index, 1, SHADER_IDENTIFIER_SIZE, dest); - vulkan_check(res); + vulkan_check(vkGetRayTracingShaderGroupHandlesKHR(device, to_internal(rtpso)->pipeline, group_index, 1, SHADER_IDENTIFIER_SIZE, dest)); } void GraphicsDevice_Vulkan::SetName(GPUResource* pResource, const char* name) const @@ -7079,8 +6965,7 @@ using namespace vulkan_internal; if (info.objectHandle == (uint64_t)VK_NULL_HANDLE) return; - VkResult res = vkSetDebugUtilsObjectNameEXT(device, &info); - vulkan_check(res); + vulkan_check(vkSetDebugUtilsObjectNameEXT(device, &info)); } void GraphicsDevice_Vulkan::SetName(Shader* shader, const char* name) const { @@ -7095,8 +6980,7 @@ using namespace vulkan_internal; if (info.objectHandle == (uint64_t)VK_NULL_HANDLE) return; - VkResult res = vkSetDebugUtilsObjectNameEXT(device, &info); - vulkan_check(res); + vulkan_check(vkSetDebugUtilsObjectNameEXT(device, &info)); } CommandList GraphicsDevice_Vulkan::BeginCommandList(QUEUE_TYPE queue) @@ -7146,8 +7030,7 @@ using namespace vulkan_internal; } poolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; - res = vkCreateCommandPool(device, &poolInfo, nullptr, &commandlist.commandPools[buffer][queue]); - vulkan_check(res); + vulkan_check(vkCreateCommandPool(device, &poolInfo, nullptr, &commandlist.commandPools[buffer][queue])); VkCommandBufferAllocateInfo commandBufferInfo = {}; commandBufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; @@ -7155,8 +7038,7 @@ using namespace vulkan_internal; commandBufferInfo.commandPool = commandlist.commandPools[buffer][queue]; commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - res = vkAllocateCommandBuffers(device, &commandBufferInfo, &commandlist.commandBuffers[buffer][queue]); - vulkan_check(res); + vulkan_check(vkAllocateCommandBuffers(device, &commandBufferInfo, &commandlist.commandBuffers[buffer][queue])); commandlist.binder_pools[buffer].init(this); } @@ -7164,16 +7046,14 @@ using namespace vulkan_internal; commandlist.binder.init(this); } - res = vkResetCommandPool(device, commandlist.GetCommandPool(), 0); - vulkan_check(res); + vulkan_check(vkResetCommandPool(device, commandlist.GetCommandPool(), 0)); VkCommandBufferBeginInfo beginInfo = {}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; beginInfo.pInheritanceInfo = nullptr; // Optional - res = vkBeginCommandBuffer(commandlist.GetCommandBuffer(), &beginInfo); - vulkan_check(res); + vulkan_check(vkBeginCommandBuffer(commandlist.GetCommandBuffer(), &beginInfo)); if (queue == QUEUE_GRAPHICS) { @@ -7237,8 +7117,7 @@ using namespace vulkan_internal; for (uint32_t cmd = 0; cmd < cmd_last; ++cmd) { CommandList_Vulkan& commandlist = *commandlists[cmd].get(); - res = vkEndCommandBuffer(commandlist.GetCommandBuffer()); - vulkan_check(res); + vulkan_check(vkEndCommandBuffer(commandlist.GetCommandBuffer())); CommandQueue& queue = queues[commandlist.queue]; const bool dependency = !commandlist.signals.empty() || !commandlist.waits.empty() || !commandlist.wait_queues.empty(); @@ -7351,11 +7230,9 @@ using namespace vulkan_internal; if (frame_fence[bufferindex][queue] == VK_NULL_HANDLE) continue; - res = vkWaitForFences(device, 1, &frame_fence[bufferindex][queue], VK_TRUE, 0xFFFFFFFFFFFFFFFF); - vulkan_check(res); + vulkan_check(vkWaitForFences(device, 1, &frame_fence[bufferindex][queue], VK_TRUE, 0xFFFFFFFFFFFFFFFF)); - res = vkResetFences(device, 1, &frame_fence[bufferindex][queue]); - vulkan_check(res); + vulkan_check(vkResetFences(device, 1, &frame_fence[bufferindex][queue])); } } @@ -7364,8 +7241,7 @@ using namespace vulkan_internal; void GraphicsDevice_Vulkan::WaitForGPU() const { - VkResult res = vkDeviceWaitIdle(device); - vulkan_check(res); + vulkan_check(vkDeviceWaitIdle(device)); } void GraphicsDevice_Vulkan::ClearPipelineStateCache() { @@ -7405,8 +7281,7 @@ using namespace vulkan_internal; createInfo.pInitialData = nullptr; // Create Vulkan pipeline cache - VkResult res = vkCreatePipelineCache(device, &createInfo, nullptr, &pipelineCache); - vulkan_check(res); + vulkan_check(vkCreatePipelineCache(device, &createInfo, nullptr, &pipelineCache)); } Texture GraphicsDevice_Vulkan::GetBackBuffer(const SwapChain* swapchain) const @@ -7652,8 +7527,7 @@ using namespace vulkan_internal; std::scoped_lock lock(*q.locker); assert(q.sparse_binding_supported); - VkResult res = vkQueueBindSparse(q.queue, (uint32_t)sparse_infos.size(), sparse_infos.data(), VK_NULL_HANDLE); - vulkan_check(res); + vulkan_check(vkQueueBindSparse(q.queue, (uint32_t)sparse_infos.size(), sparse_infos.data(), VK_NULL_HANDLE)); } } diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.h b/WickedEngine/wiGraphicsDevice_Vulkan.h index 41ed76345..78784241a 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.h +++ b/WickedEngine/wiGraphicsDevice_Vulkan.h @@ -28,7 +28,13 @@ #include #include -#define vulkan_check(res) wilog_assert(res == VK_SUCCESS, "Vulkan error: %s, line %d, result = %s", relative_path(__FILE__), __LINE__, string_VkResult(res)) +#define vulkan_assert(cond, fname) { wilog_assert(cond, "Vulkan error: %s failed with %s (%s:%d)", fname, string_VkResult(res), relative_path(__FILE__), __LINE__); } + +#define vulkan_check_cond(cond, call) [&]() { VkResult res = call; char buf[256]; vulkan_assert(cond, wi::backlog::internal::extract_function_name(buf, #call)); return res; }() + +#define vulkan_check(call) vulkan_check_cond(res == VK_SUCCESS, call) + +#define vulkan_check_lenient(call) vulkan_check_cond(res >= VK_SUCCESS, call) namespace wi::graphics { @@ -210,8 +216,7 @@ namespace wi::graphics VkSemaphore& sema = semaphore_pool.emplace_back(); VkSemaphoreCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - VkResult res = vkCreateSemaphore(device, &info, nullptr, &sema); - vulkan_check(res); + vulkan_check(vkCreateSemaphore(device, &info, nullptr, &sema)); } VkSemaphore semaphore = semaphore_pool.back(); semaphore_pool.pop_back(); @@ -505,8 +510,7 @@ namespace wi::graphics poolInfo.maxSets = 1; poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT; - VkResult res = vkCreateDescriptorPool(device->device, &poolInfo, nullptr, &descriptorPool); - vulkan_check(res); + vulkan_check(vkCreateDescriptorPool(device->device, &poolInfo, nullptr, &descriptorPool)); #if 0 VkDebugUtilsObjectNameInfoEXT info{ VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT }; @@ -541,16 +545,14 @@ namespace wi::graphics bindingFlagsInfo.pBindingFlags = &bindingFlags; layoutInfo.pNext = &bindingFlagsInfo; - res = vkCreateDescriptorSetLayout(device->device, &layoutInfo, nullptr, &descriptorSetLayout); - vulkan_check(res); + vulkan_check(vkCreateDescriptorSetLayout(device->device, &layoutInfo, nullptr, &descriptorSetLayout)); VkDescriptorSetAllocateInfo allocInfo = {}; allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; allocInfo.descriptorPool = descriptorPool; allocInfo.descriptorSetCount = 1; allocInfo.pSetLayouts = &descriptorSetLayout; - res = vkAllocateDescriptorSets(device->device, &allocInfo, &descriptorSet); - vulkan_check(res); + vulkan_check(vkAllocateDescriptorSets(device->device, &allocInfo, &descriptorSet)); for (int i = 0; i < (int)descriptorCount; ++i) {