Skip to content

Commit 7823d71

Browse files
committed
fixes
1 parent 0fdc67d commit 7823d71

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

WickedEngine/wiGraphicsDevice_DX12.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,20 +1732,18 @@ using namespace dx12_internal;
17321732
const uint64_t wrapped_offset_end = wrapped_offset + stats.descriptorCopyCount;
17331733

17341734
// Check that gpu offset doesn't intersect with our newly allocated range, if it does, we need to wait until gpu finishes with it:
1735+
// First check is with the cached completed value to avoid API call into fence object
17351736
uint64_t wrapped_gpu_offset = heap.cached_completedValue % wrap_effective_size;
1736-
int loop_cnt = 0; // safety
1737-
while (wrapped_offset < wrapped_gpu_offset && wrapped_gpu_offset <= wrapped_offset_end)
1737+
if ((wrapped_offset < wrapped_gpu_offset) && (wrapped_gpu_offset < wrapped_offset_end))
17381738
{
1739-
wrapped_gpu_offset = device->descriptorheap_res.fence->GetCompletedValue() % wrap_effective_size;
1740-
1741-
// Check that the GPU has even a chance of freeing up the requested descriptors:
1742-
const uint64_t wrapped_signaled_offset = heap.fenceValue % wrap_effective_size;
1743-
if (wrapped_signaled_offset <= wrapped_offset_end || loop_cnt > 10)
1739+
// Second check is with current fence value with API call:
1740+
wrapped_gpu_offset = heap.fence->GetCompletedValue() % wrap_effective_size;
1741+
if ((wrapped_offset < wrapped_gpu_offset) && (wrapped_gpu_offset < wrapped_offset_end))
17441742
{
1745-
assert(0);
1746-
break; // break out from waiting for GPU, because it might cause infinite loop
1743+
// Third step is actual wait until GPU updates fence so that requested descriptors are free:
1744+
HRESULT hr = heap.fence->SetEventOnCompletion(heap.fenceValue, nullptr);
1745+
assert(SUCCEEDED(hr));
17471746
}
1748-
loop_cnt++;
17491747
}
17501748

17511749
gpu_handle.ptr += (size_t)ringoffset;

WickedEngine/wiHelper.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,53 @@ namespace wi::helper
732732

733733
bool FileExists(const std::string& fileName)
734734
{
735+
#ifndef PLATFORM_UWP
735736
bool exists = std::filesystem::exists(fileName);
736737
return exists;
738+
#else
739+
using namespace winrt::Windows::Storage;
740+
using namespace winrt::Windows::Storage::Streams;
741+
using namespace winrt::Windows::Foundation;
742+
std::wstring wstr;
743+
std::filesystem::path filepath = fileName;
744+
filepath = std::filesystem::absolute(filepath);
745+
StringConvert(filepath.string(), wstr);
746+
bool success = false;
747+
748+
auto async_helper = [&]() -> IAsyncAction {
749+
try
750+
{
751+
auto file = co_await StorageFile::GetFileFromPathAsync(wstr);
752+
success = true;
753+
}
754+
catch (winrt::hresult_error const& ex)
755+
{
756+
switch (ex.code())
757+
{
758+
case E_ACCESSDENIED:
759+
wi::backlog::post("Opening file failed: " + fileName + " | Reason: Permission Denied!");
760+
break;
761+
default:
762+
break;
763+
}
764+
}
765+
766+
};
767+
768+
if (winrt::impl::is_sta_thread())
769+
{
770+
std::thread([&] { async_helper().get(); }).join(); // can't block coroutine from ui thread
771+
}
772+
else
773+
{
774+
async_helper().get();
775+
}
776+
777+
if (success)
778+
{
779+
return true;
780+
}
781+
#endif // PLATFORM_UWP
737782
}
738783

739784
std::string GetTempDirectoryPath()

0 commit comments

Comments
 (0)