载入中...
搜索中...
未找到
GraphicsSampler.cpp
浏览该文件的文档.
1// eve-hot-path
2#include <algorithm>
3#include <iterator>
4#include "graphics/Texture.h"
6
7namespace eve::graphics::vulkan {
9 if (!texture || texture->sampler == sampler) return;
10 if (std::none_of(ownedTextures.begin(), ownedTextures.end(),
11 [texture](const auto &owned) { return owned.get() == texture; }))
12 return;
13 texture->sampler = sampler;
14 samplerChangesPending_ = true;
15}
16
17void Graphics::applyPendingResourceChanges() {
18 if (!samplerChangesPending_) return;
19 bool changed = false;
20 for (auto &texture : ownedTextures) {
21 if (!texture->gpuHandle) continue;
22 auto *gpu = static_cast<GpuTexture *>(texture->gpuHandle);
23 if (gpu->samplerState == texture->sampler) continue;
24 auto found = std::find_if(cachedSamplers_.begin(), cachedSamplers_.end(), [&](const CachedSampler &entry) {
25 return entry.mipLevels == gpu->mipLevels && entry.state == texture->sampler;
26 });
27 if (found == cachedSamplers_.end()) {
28 cachedSamplers_.push_back(
29 {texture->sampler, gpu->mipLevels,
30 vk::UniqueSampler(createVkSampler(texture->sampler, gpu->mipLevels), device.instance)});
31 found = std::prev(cachedSamplers_.end());
32 }
34 if (gpu->sampler && !gpu->sharedSampler) device->destroySampler(gpu->sampler);
35 gpu->sampler = *found->sampler;
36 gpu->sharedSampler = true;
37 if (!gpu->isCube) writeCombinedImageDescriptor(gpu);
38 gpu->samplerState = texture->sampler;
39 changed = true;
40 }
41 samplerChangesPending_ = false;
42 if (changed) invalidateTextureBindings();
43}
44} // namespace eve::graphics::vulkan
ActiveSource owned
bool changed
vk::UniqueSampler sampler
std::shared_ptr< OceanGpuSpectrum > gpu
Texture * texture
bool found
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
void waitForSharedGpuResources()
Block until all in-flight GPU work (all frames) has completed.
Definition Graphics.cpp:943
void setTextureSampler(Texture *texture, const TextureSampler &sampler) override
Sets the texture sampler.
Sampler state for a Texture (filter, wrap, mip LOD, anisotropy). Defaults match historical engine beh...
GpuTexture public API.
Definition Graphics.h:264