Fix builtin pass layout metadata lifetime

This commit is contained in:
2026-04-11 03:24:32 +08:00
parent fac6e588a8
commit 3622bf3aa2
2 changed files with 77 additions and 2 deletions

View File

@@ -525,8 +525,7 @@ inline void RefreshBuiltinPassSetLayoutMetadata(BuiltinPassSetLayoutMetadata& se
return left.binding < right.binding;
});
setLayout.shaderVisible = IsBuiltinPassShaderVisibleSet(setLayout.bindings);
setLayout.layout.bindings = setLayout.bindings.empty() ? nullptr : setLayout.bindings.data();
setLayout.layout.bindingCount = static_cast<Core::uint32>(setLayout.bindings.size());
setLayout.SyncLayoutView();
}
inline void RefreshBuiltinPassSetLayouts(std::vector<BuiltinPassSetLayoutMetadata>& setLayouts) {

View File

@@ -7,6 +7,7 @@
#include <XCEngine/Resources/Shader/Shader.h>
#include <cstdint>
#include <utility>
#include <vector>
namespace XCEngine {
@@ -142,6 +143,81 @@ struct BuiltinPassSetLayoutMetadata {
bool usesSampler = false;
bool usesLinearClampSampler = false;
bool usesShadowMapSampler = false;
BuiltinPassSetLayoutMetadata() = default;
BuiltinPassSetLayoutMetadata(const BuiltinPassSetLayoutMetadata& other)
: bindings(other.bindings)
, materialBufferBindings(other.materialBufferBindings) {
CopyFlagsFrom(other);
SyncLayoutView();
}
BuiltinPassSetLayoutMetadata(BuiltinPassSetLayoutMetadata&& other) noexcept
: bindings(std::move(other.bindings))
, materialBufferBindings(std::move(other.materialBufferBindings)) {
CopyFlagsFrom(other);
SyncLayoutView();
other.layout = {};
}
BuiltinPassSetLayoutMetadata& operator=(const BuiltinPassSetLayoutMetadata& other) {
if (this != &other) {
bindings = other.bindings;
materialBufferBindings = other.materialBufferBindings;
CopyFlagsFrom(other);
SyncLayoutView();
}
return *this;
}
BuiltinPassSetLayoutMetadata& operator=(BuiltinPassSetLayoutMetadata&& other) noexcept {
if (this != &other) {
bindings = std::move(other.bindings);
materialBufferBindings = std::move(other.materialBufferBindings);
CopyFlagsFrom(other);
SyncLayoutView();
other.layout = {};
}
return *this;
}
void SyncLayoutView() {
layout.bindings = bindings.empty() ? nullptr : bindings.data();
layout.bindingCount = static_cast<Core::uint32>(bindings.size());
}
private:
void CopyFlagsFrom(const BuiltinPassSetLayoutMetadata& other) {
heapType = other.heapType;
shaderVisible = other.shaderVisible;
usesPerObject = other.usesPerObject;
usesMaterial = other.usesMaterial;
usesLighting = other.usesLighting;
usesShadowReceiver = other.usesShadowReceiver;
usesEnvironment = other.usesEnvironment;
usesPassConstants = other.usesPassConstants;
usesMaterialBuffers = other.usesMaterialBuffers;
usesVolumeField = other.usesVolumeField;
usesGaussianSplatSortDistanceBuffer = other.usesGaussianSplatSortDistanceBuffer;
usesGaussianSplatOrderBuffer = other.usesGaussianSplatOrderBuffer;
usesGaussianSplatPositionBuffer = other.usesGaussianSplatPositionBuffer;
usesGaussianSplatOtherBuffer = other.usesGaussianSplatOtherBuffer;
usesGaussianSplatColorBuffer = other.usesGaussianSplatColorBuffer;
usesGaussianSplatSHBuffer = other.usesGaussianSplatSHBuffer;
usesGaussianSplatViewDataBuffer = other.usesGaussianSplatViewDataBuffer;
usesTexture = other.usesTexture;
usesBaseColorTexture = other.usesBaseColorTexture;
usesSourceColorTexture = other.usesSourceColorTexture;
usesSkyboxPanoramicTexture = other.usesSkyboxPanoramicTexture;
usesSkyboxTexture = other.usesSkyboxTexture;
usesShadowMapTexture = other.usesShadowMapTexture;
usesSampler = other.usesSampler;
usesLinearClampSampler = other.usesLinearClampSampler;
usesShadowMapSampler = other.usesShadowMapSampler;
}
};
} // namespace Rendering