From 65671714d4ce5f6fa9daa8e1295edb0b8e8b0071 Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Thu, 24 Oct 2024 09:59:26 +0100 Subject: [PATCH 1/6] Whitespace changes. --- Core/RuntimeError.cpp | 2 +- DirectX12/Texture.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/RuntimeError.cpp b/Core/RuntimeError.cpp index 72ccd379..b2d29232 100644 --- a/Core/RuntimeError.cpp +++ b/Core/RuntimeError.cpp @@ -33,7 +33,7 @@ namespace platform void DebugBreak() { #ifdef _MSC_VER - ::DebugBreak(); + ::DebugBreak(); #else if (debugBreaksEnabled) { diff --git a/DirectX12/Texture.cpp b/DirectX12/Texture.cpp index 93fd363a..db2e08be 100644 --- a/DirectX12/Texture.cpp +++ b/DirectX12/Texture.cpp @@ -200,7 +200,7 @@ bool Texture::LoadFromFile(crossplatform::RenderPlatform *renderPlatform,const c wic.scratchImage=new DirectX::ScratchImage; if(name.find(".hdr")==name.length()-4) { - res= DirectX::LoadFromHDRMemory(f.ptr, (size_t)f.bytes, wic.metadata, *wic.scratchImage); + res = DirectX::LoadFromHDRMemory(f.ptr, (size_t)f.bytes, wic.metadata, *wic.scratchImage); } else if (name.find(".dds") != std::string::npos) { From 74e46103c950388af819cd1e967124ce8c8e417b Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Thu, 24 Oct 2024 10:09:48 +0100 Subject: [PATCH 2/6] Added support for loading hdr images. --- CrossPlatform/Texture.cpp | 9 ++++++--- CrossPlatform/Texture.h | 2 +- OpenGL/Texture.cpp | 2 +- Vulkan/Texture.cpp | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CrossPlatform/Texture.cpp b/CrossPlatform/Texture.cpp index d0bda30c..6805ce95 100644 --- a/CrossPlatform/Texture.cpp +++ b/CrossPlatform/Texture.cpp @@ -158,11 +158,14 @@ bool Texture::EnsureTexture(crossplatform::RenderPlatform* r, crossplatform::Tex return res; } -bool Texture::TranslateLoadedTextureData(void*& target, const void* src, size_t size, int& x, int& y, int& num_channels, int req_num_channels) +bool Texture::TranslateLoadedTextureData(void *&target, const void *src, size_t size, int &x, int &y, int &num_channels, int req_num_channels, const char *filename) { - target = stbi_load_from_memory((const unsigned char*)src, (int)size, &x, &y, &num_channels, 4); + if (stbi_is_hdr(filename)) + target = stbi_loadf_from_memory((const unsigned char *)src, (int)size, &x, &y, &num_channels, 4); + else + target = stbi_load_from_memory((const unsigned char *)src, (int)size, &x, &y, &num_channels, 4); stbi_loaded = true; - return(target!=nullptr); + return (target != nullptr); } void Texture::FreeTranslatedTextureData(void* data) diff --git a/CrossPlatform/Texture.h b/CrossPlatform/Texture.h index 4f426277..d7386b05 100644 --- a/CrossPlatform/Texture.h +++ b/CrossPlatform/Texture.h @@ -501,7 +501,7 @@ namespace platform // For API's that don't track resources: bool unfenceable; // a wrapper around stbi_load_from_memory. - bool TranslateLoadedTextureData(void *&target,const void *src,size_t size,int &x,int &y,int &num_channels,int req_num_channels); + bool TranslateLoadedTextureData(void *&target,const void *src,size_t size,int &x,int &y,int &num_channels,int req_num_channels,const char* filename); void FreeTranslatedTextureData(void *data); uint32_t CalculateSubresourceIndex(uint32_t MipSlice, uint32_t ArraySlice, uint32_t PlaneSlice, uint32_t MipLevels, uint32_t ArraySize); tvector3 CalculateSubresourceSlices(uint32_t Index, uint32_t MipSlice, uint32_t ArraySlice); // Returned as { MipSlice, ArraySlice, PlaneSlice } diff --git a/OpenGL/Texture.cpp b/OpenGL/Texture.cpp index 966d94be..9d5e128a 100644 --- a/OpenGL/Texture.cpp +++ b/OpenGL/Texture.cpp @@ -675,7 +675,7 @@ GLuint Texture::GetGLMainView() return; } void* data = nullptr; - TranslateLoadedTextureData(data, buffer, size, x, y, n, 4); + TranslateLoadedTextureData(data, buffer, size, x, y, n, 4, path); platform::core::FileLoader::GetFileLoader()->ReleaseFileContents(buffer); lt.data = (unsigned char *)data; lt.x = x; diff --git a/Vulkan/Texture.cpp b/Vulkan/Texture.cpp index 9226f6db..f2254693 100644 --- a/Vulkan/Texture.cpp +++ b/Vulkan/Texture.cpp @@ -884,7 +884,7 @@ void Texture::LoadTextureData(LoadedTexture <,const char* path) return; } void* data = nullptr; - TranslateLoadedTextureData(data,buffer,size,x,y,n,4); + TranslateLoadedTextureData(data,buffer,size,x,y,n,4,path); core::FileLoader::GetFileLoader()->ReleaseFileContents(buffer); SetTextureData(lt,data,x,y,1,n,crossplatform::PixelFormat::RGBA_8_UNORM); } From 018425fd3e48e1aa4044136c8fa4a6e595082c04 Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Mon, 28 Oct 2024 13:45:27 +0000 Subject: [PATCH 3/6] MeshRenderer updated effect pointer management. --- CrossPlatform/MeshRenderer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CrossPlatform/MeshRenderer.cpp b/CrossPlatform/MeshRenderer.cpp index 688281f2..670fd889 100644 --- a/CrossPlatform/MeshRenderer.cpp +++ b/CrossPlatform/MeshRenderer.cpp @@ -22,6 +22,7 @@ void MeshRenderer::RestoreDeviceObjects(RenderPlatform *r) cameraConstants.RestoreDeviceObjects(r); solidConstants.RestoreDeviceObjects(r); perObjectConstants.RestoreDeviceObjects(r); + effect = r->GetEffect("solid"); } void MeshRenderer::InvalidateDeviceObjects() @@ -29,7 +30,6 @@ void MeshRenderer::InvalidateDeviceObjects() cameraConstants.InvalidateDeviceObjects(); solidConstants.InvalidateDeviceObjects(); perObjectConstants.InvalidateDeviceObjects(); - delete effect; effect = nullptr; } @@ -68,9 +68,6 @@ void MeshRenderer::DrawSubNode(GraphicsDeviceContext& deviceContext, Mesh* mesh, void MeshRenderer::Render(GraphicsDeviceContext &deviceContext, Mesh *mesh, mat4 model, Texture *diffuseCubemap,Texture *specularCubemap,Texture *screenspaceShadowTexture) { - if (renderPlatform) - effect = renderPlatform->GetEffect("solid"); - if (!effect) return; From 8bd33dde06129e1943589868c7e755082dbf42ef Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Tue, 29 Oct 2024 13:13:07 +0000 Subject: [PATCH 4/6] RenderPlatform effect recompilation crash fixes. RenderPlatform::CreateEffect() adds the recompiled effect to the effect list. RenderPlatform::GetEffect() check the recompiled effects. --- CrossPlatform/RenderPlatform.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/CrossPlatform/RenderPlatform.cpp b/CrossPlatform/RenderPlatform.cpp index 1711cc03..3ad1ee5f 100644 --- a/CrossPlatform/RenderPlatform.cpp +++ b/CrossPlatform/RenderPlatform.cpp @@ -224,7 +224,7 @@ void RenderPlatform::ScheduleRecompileEffects(const std::vector &ef { found = true; break; -} + } } if (!found) @@ -2025,17 +2025,20 @@ void RenderPlatform::Destroy(Effect *&e) Effect *RenderPlatform::CreateEffect(const char *filename_utf8, bool checkRecompileShaders) { + std::string fn(filename_utf8); + //Check if the effect in being recompiled if (checkRecompileShaders) { std::lock_guard recompileEffectFutureGuard(recompileEffectFutureMutex); - const auto &it = effectsToCompileFutures.find(std::string(filename_utf8)); + const auto &it = effectsToCompileFutures.find(fn); if (it != effectsToCompileFutures.end()) { if (it->second.valid()) { Effect *e = it->second.get().newEffect; effectsToCompileFutures.erase(it); + effects[fn] = e; return e; } else @@ -2046,7 +2049,6 @@ Effect *RenderPlatform::CreateEffect(const char *filename_utf8, bool checkRecomp } //Else, load as normal - std::string fn(filename_utf8); crossplatform::Effect *e=CreateEffect(); effects[fn] = e; e->SetName(filename_utf8); @@ -2061,6 +2063,26 @@ Effect *RenderPlatform::CreateEffect(const char *filename_utf8, bool checkRecomp Effect* RenderPlatform::GetEffect(const char* filename_utf8) { + std::string fn(filename_utf8); + + // Check if the effect in being recompiled + std::lock_guard recompileEffectFutureGuard(recompileEffectFutureMutex); + const auto &it = effectsToCompileFutures.find(fn); + if (it != effectsToCompileFutures.end()) + { + if (it->second.valid()) + { + Effect *e = it->second.get().newEffect; + effectsToCompileFutures.erase(it); + effects[fn] = e; + return e; + } + else + { + effectsToCompileFutures.erase(it); + } + } + auto i = effects.find(filename_utf8); if (i == effects.end()) return nullptr; From 08d5fae24b48b2a85eb1d09f30f0b2c1aaea3f2b Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Tue, 29 Oct 2024 13:13:46 +0000 Subject: [PATCH 5/6] Better sampler heap checks in D3D12. --- DirectX12/RenderPlatform.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/DirectX12/RenderPlatform.cpp b/DirectX12/RenderPlatform.cpp index bd7b23ab..084134b2 100644 --- a/DirectX12/RenderPlatform.cpp +++ b/DirectX12/RenderPlatform.cpp @@ -3119,13 +3119,12 @@ bool RenderPlatform::ApplyContextState(crossplatform::DeviceContext &deviceConte // Set the frame descriptor heaps Heap *currentSamplerHeap = dx12Effect->GetEffectSamplerHeap(); - ID3D12DescriptorHeap *currentHeaps[2] = {mFrameHeap[frameHeapIndex].GetHeap(), currentSamplerHeap->GetHeap()}; // If we are overriding samplers, use the override heap instead: - if (cs->samplerStateOverrides.size() > 0) + if (cs->samplerStateOverrides.size() > 0 || !currentSamplerHeap) { currentSamplerHeap = &mFrameOverrideSamplerHeap[frameHeapIndex]; - currentHeaps[1] = currentSamplerHeap->GetHeap(); } + ID3D12DescriptorHeap *currentHeaps[2] = {mFrameHeap[frameHeapIndex].GetHeap(), currentSamplerHeap->GetHeap()}; cmdList->SetDescriptorHeaps(2, currentHeaps); // Apply the RootDescriptor tables: From 5bd9bbdf94efeb203dd6c9b0ff601f02f923f122 Mon Sep 17 00:00:00 2001 From: jamesevans14 Date: Tue, 29 Oct 2024 15:49:46 +0000 Subject: [PATCH 6/6] Ensure valid Vulkan path --- CMake/Variables.cmake | 1 + DirectX12/RenderPlatform.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMake/Variables.cmake b/CMake/Variables.cmake index 0f22bbe6..26acf1a7 100644 --- a/CMake/Variables.cmake +++ b/CMake/Variables.cmake @@ -28,6 +28,7 @@ set_property(CACHE PLATFORM_STD_FILESYSTEM PROPERTY STRINGS 0 1 2) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows" OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(ENV_VULKAN_SDK_DIR $ENV{VULKAN_SDK}) + cmake_path(NORMAL_PATH ENV_VULKAN_SDK_DIR OUTPUT_VARIABLE ENV_VULKAN_SDK_DIR) message("Environment VULKAN_SDK = ${ENV_VULKAN_SDK_DIR}") list(APPEND CMAKE_MODULE_PATH "${ENV_VULKAN_SDK_DIR}") find_package(Vulkan REQUIRED) diff --git a/DirectX12/RenderPlatform.cpp b/DirectX12/RenderPlatform.cpp index 084134b2..fd2b9bf1 100644 --- a/DirectX12/RenderPlatform.cpp +++ b/DirectX12/RenderPlatform.cpp @@ -42,7 +42,7 @@ using namespace platform; using namespace dx12; #if SIMUL_INTERNAL_CHECKS -#define PLATFORM_D3D12_RELEASE_MANAGER_CHECKS 1 +#define PLATFORM_D3D12_RELEASE_MANAGER_CHECKS 0 #else #define PLATFORM_D3D12_RELEASE_MANAGER_CHECKS 0 #endif