Skip to content

Commit

Permalink
remove the update api, re-impl later
Browse files Browse the repository at this point in the history
  • Loading branch information
gameknife committed Dec 31, 2024
1 parent e8d8fce commit 61eed7a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 74 deletions.
70 changes: 0 additions & 70 deletions src/Assets/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ namespace Assets
false);
}

void GlobalTexturePool::UpdateHDRTexture(uint32_t idx, const std::string& filename,
const Vulkan::SamplerConfig& samplerConfig)
{
GetInstance()->RequestUpdateTextureFileAsync(idx, filename, true);
}

TextureImage* GlobalTexturePool::GetTextureImage(uint32_t idx)
{
if (GetInstance()->textureImages_.size() > idx)
Expand Down Expand Up @@ -205,70 +199,6 @@ namespace Assets
return -1;
}

void GlobalTexturePool::RequestUpdateTextureFileAsync(uint32_t textureIdx, const std::string& filename, bool hdr)
{
TaskCoordinator::GetInstance()->AddTask([this, filename, hdr, textureIdx](ResTask& task)
{
TextureTaskContext taskContext{};
const auto timer = std::chrono::high_resolution_clock::now();

// Load the texture in normal host memory.
int width, height, channels;
void* pixels = nullptr;
uint32_t size = 0;
VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;

if (hdr)
{
pixels = stbi_loadf(
filename.c_str(), &width, &height, &channels,
STBI_rgb_alpha);
format = VK_FORMAT_R32G32B32A32_SFLOAT;
size = width * height * 4 * sizeof(float);
}
else
{
pixels = stbi_load(
filename.c_str(), &width, &height, &channels,
STBI_rgb_alpha);
format = VK_FORMAT_R8G8B8A8_UNORM;
size = width * height * 4 * sizeof(uint8_t);
}

if (!pixels)
{
Throw(std::runtime_error(
"failed to load texture image '" + filename + "'"));
}

// thread reset may cause crash, created the new texture here, but reset in later main thread phase
taskContext.transferPtr = new TextureImage(
commandPool_, width, height, 1, format,
static_cast<unsigned char*>((void*)pixels), size);
stbi_image_free(pixels);
taskContext.textureId = textureIdx;
taskContext.elapsed = std::chrono::duration<
float, std::chrono::seconds::period>(
std::chrono::high_resolution_clock::now() - timer).count();
std::string info = fmt::format(
"reloaded {} ({} x {} x {}) in {:.2f}ms", filename, width,
height, channels, taskContext.elapsed * 1000.f);
std::copy(info.begin(), info.end(), taskContext.outputInfo.data());
task.SetContext(taskContext);
}, [this](ResTask& task)
{
TextureTaskContext taskContext{};
task.GetContext(taskContext);

textureImages_[taskContext.textureId].
reset(taskContext.transferPtr);
BindTexture(taskContext.textureId,
*(textureImages_[taskContext.textureId]));

fmt::print("{}\n", taskContext.outputInfo.data());
}, 0);
}

uint32_t GlobalTexturePool::RequestNewTextureMemAsync(const std::string& texname, const std::string& mime, bool hdr,
const unsigned char* data, size_t bytelength, bool srgb)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Assets/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace Assets
void BindTexture(uint32_t textureIdx, const TextureImage& textureImage);
uint32_t TryGetTexureIndex(const std::string& textureName) const;
uint32_t RequestNewTextureFileAsync(const std::string& filename, bool hdr);
void RequestUpdateTextureFileAsync(uint32_t textureIdx, const std::string& filename, bool hdr);
uint32_t RequestNewTextureMemAsync(const std::string& texname, const std::string& mime, bool hdr, const unsigned char* data, size_t bytelength, bool srgb);

uint32_t TotalTextures() const {return static_cast<uint32_t>(textureImages_.size());}
Expand All @@ -38,8 +37,6 @@ namespace Assets
static uint32_t LoadTexture(const std::string& filename, const Vulkan::SamplerConfig& samplerConfig);
static uint32_t LoadHDRTexture(const std::string& filename, const Vulkan::SamplerConfig& samplerConfig);

static void UpdateHDRTexture(uint32_t idx, const std::string& filename, const Vulkan::SamplerConfig& samplerConfig);

static TextureImage* GetTextureImage(uint32_t idx);
static TextureImage* GetTextureImageByName(const std::string& name);
static uint32_t GetTextureIndexByName(const std::string& name);
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void NextEngine::OnRendererDeviceSet()
Assets::GlobalTexturePool::LoadHDRTexture("assets/textures/umhlanga_sunrise_1k.hdr", Vulkan::SamplerConfig());
Assets::GlobalTexturePool::LoadHDRTexture("assets/textures/shanghai_bund_1k.hdr", Vulkan::SamplerConfig());

if(GOption->HDRIfile != "") Assets::GlobalTexturePool::UpdateHDRTexture(0, GOption->HDRIfile.c_str(), Vulkan::SamplerConfig());
//if(GOption->HDRIfile != "") Assets::GlobalTexturePool::UpdateHDRTexture(0, GOption->HDRIfile.c_str(), Vulkan::SamplerConfig());

scene_.reset(new Assets::Scene(renderer_->CommandPool(), renderer_->supportRayTracing_));
renderer_->SetScene(scene_);
Expand Down

0 comments on commit 61eed7a

Please sign in to comment.