Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions are hidden if DONUT_WITH_TASKFLOW is not defined #10

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions include/donut/engine/TextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,17 @@ namespace donut::engine
#ifdef DONUT_WITH_TASKFLOW
// Asynchronous read and decode, deferred upload and mip generation (in the ProcessRenderingThreadCommands queue).
std::shared_ptr<LoadedTexture> LoadTextureFromFileAsync(const std::filesystem::path& path, bool sRGB, tf::Executor& executor);

// Same as LoadTextureFromFileAsync, but using a memory blob and MIME type instead of file name, and uncached.
std::shared_ptr<LoadedTexture> LoadTextureFromMemoryAsync(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB, tf::Executor& executor);
#endif

// Same as LoadTextureFromFile, but using a memory blob and MIME type instead of file name, and uncached.
std::shared_ptr<LoadedTexture> LoadTextureFromMemory(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB, CommonRenderPasses* passes, nvrhi::ICommandList* commandList);

// Same as LoadTextureFromFileDeferred, but using a memory blob and MIME type instead of file name, and uncached.
std::shared_ptr<LoadedTexture> LoadTextureFromMemoryDeferred(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB);

#ifdef DONUT_WITH_TASKFLOW
// Same as LoadTextureFromFileAsync, but using a memory blob and MIME type instead of file name, and uncached.
std::shared_ptr<LoadedTexture> LoadTextureFromMemoryAsync(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB, tf::Executor& executor);
#endif


// Tells if the texture has been loaded from file successfully and its data is available in the texture object.
// After the texture is finalized and uploaded to the GPU, the data is no longer available on the CPU, and this function returns false.
bool IsTextureLoaded(const std::shared_ptr<LoadedTexture>& texture);
Expand Down
51 changes: 26 additions & 25 deletions src/engine/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,27 +573,33 @@ std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromFileAsync(const std:
return texture;
}

std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemory(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB, CommonRenderPasses* passes, nvrhi::ICommandList* commandList)
std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemoryAsync(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB, tf::Executor& executor)
{
std::shared_ptr<TextureData> texture = CreateTextureData();

texture->forceSRGB = sRGB;
texture->path = name;
texture->mimeType = mimeType;

if (FillTextureData(data, texture, "", mimeType))
{
TextureLoaded(texture);
executor.async([this, sRGB, texture, data, mimeType]()
{
if (FillTextureData(data, texture, "", mimeType))
{
TextureLoaded(texture);

FinalizeTexture(texture, passes, commandList);
}
std::lock_guard<std::mutex> guard(m_TexturesToFinalizeMutex);

++m_TexturesLoaded;
m_TexturesToFinalize.push(texture);
}

++m_TexturesLoaded;
});

return texture;
}
#endif

std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemoryDeferred(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB)
std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemory(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB, CommonRenderPasses* passes, nvrhi::ICommandList* commandList)
{
std::shared_ptr<TextureData> texture = CreateTextureData();

Expand All @@ -605,41 +611,36 @@ std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemoryDeferred(const
{
TextureLoaded(texture);

std::lock_guard<std::mutex> guard(m_TexturesToFinalizeMutex);

m_TexturesToFinalize.push(texture);
FinalizeTexture(texture, passes, commandList);
}

++m_TexturesLoaded;

return texture;
}

std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemoryAsync(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB, tf::Executor& executor)
std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemoryDeferred(const std::shared_ptr<vfs::IBlob>& data, const std::string& name, const std::string& mimeType, bool sRGB)
{
std::shared_ptr<TextureData> texture = CreateTextureData();

texture->forceSRGB = sRGB;
texture->path = name;
texture->mimeType = mimeType;

executor.async([this, sRGB, texture, data, mimeType]()
{
if (FillTextureData(data, texture, "", mimeType))
{
TextureLoaded(texture);

std::lock_guard<std::mutex> guard(m_TexturesToFinalizeMutex);
if (FillTextureData(data, texture, "", mimeType))
{
TextureLoaded(texture);

m_TexturesToFinalize.push(texture);
}
std::lock_guard<std::mutex> guard(m_TexturesToFinalizeMutex);

++m_TexturesLoaded;
});
m_TexturesToFinalize.push(texture);
}

++m_TexturesLoaded;

return texture;
}
#endif


std::shared_ptr<TextureData> TextureCache::GetLoadedTexture(std::filesystem::path const& path)
{
Expand Down
Loading