Skip to content

Commit

Permalink
Merge branch 'main' of github.com:simul/Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
rvkennedy committed Nov 5, 2024
2 parents 9de790c + 5bd9bbd commit ee92af9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions CMake/Variables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Core/RuntimeError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace platform
void DebugBreak()
{
#ifdef _MSC_VER
::DebugBreak();
::DebugBreak();
#else
if (debugBreaksEnabled)
{
Expand Down
5 changes: 1 addition & 4 deletions CrossPlatform/MeshRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ void MeshRenderer::RestoreDeviceObjects(RenderPlatform *r)
cameraConstants.RestoreDeviceObjects(r);
solidConstants.RestoreDeviceObjects(r);
perObjectConstants.RestoreDeviceObjects(r);
effect = r->GetEffect("solid");
}

void MeshRenderer::InvalidateDeviceObjects()
{
cameraConstants.InvalidateDeviceObjects();
solidConstants.InvalidateDeviceObjects();
perObjectConstants.InvalidateDeviceObjects();
delete effect;
effect = nullptr;
}

Expand Down Expand Up @@ -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;

Expand Down
28 changes: 25 additions & 3 deletions CrossPlatform/RenderPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void RenderPlatform::ScheduleRecompileEffects(const std::vector<std::string> &ef
{
found = true;
break;
}
}
}

if (!found)
Expand Down Expand Up @@ -2026,17 +2026,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
Expand All @@ -2047,7 +2050,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);
Expand All @@ -2062,6 +2064,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;
Expand Down
9 changes: 6 additions & 3 deletions CrossPlatform/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CrossPlatform/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> CalculateSubresourceSlices(uint32_t Index, uint32_t MipSlice, uint32_t ArraySlice); // Returned as { MipSlice, ArraySlice, PlaneSlice }
Expand Down
7 changes: 3 additions & 4 deletions DirectX12/RenderPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion DirectX12/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenGL/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Vulkan/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ void Texture::LoadTextureData(LoadedTexture &lt,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);
}
Expand Down

0 comments on commit ee92af9

Please sign in to comment.