fix: 阴影光源错误绑定 FillLight + 截图 usage 警告 + nodiscard

- LightComponent 增加 castShadow 标志;灯收集排序键改为
  castShadow 方向光 > 方向光 > 点光(此前稳定排序把收集序靠前的
  FillLight 排到 lights[0],KeyLight 方向滑条自然不影响阴影)
- TextureDesc 增加 extraUsage:HDRColor 声明 TRANSFER_SRC,
  消除截图 copy 的 3 条 usage 不匹配运行时警告
- waitForFences nodiscard 返回值显式丢弃,消除编译警告
This commit is contained in:
2026-09-24 11:59:18 +08:00
parent 4d3963e291
commit 42fd9d5f30
9 changed files with 40 additions and 13 deletions
+5 -2
View File
@@ -290,9 +290,11 @@ namespace Engine
// HDR 颜色图:Forward 的输出(线性光照值 + 抖动),TAA 显式完成
// 时域累积后写入 TAAColor(对齐 UE/Unity 管线)
// extraUsage:调试截图需要 TRANSFER_SRC(第 60 帧 copy 到 buffer)
m_HDRColor = m_RenderGraph->CreateTexture(
"HDRColor",
RG::TextureDesc{vk::Format::eR16G16B16A16Sfloat});
RG::TextureDesc{vk::Format::eR16G16B16A16Sfloat, 0, 0, 1.0f,
vk::ImageUsageFlagBits::eTransferSrc});
// velocity:clip 空间运动向量(TAA 反推历史像素位置)
m_Velocity = m_RenderGraph->CreateTexture(
@@ -577,7 +579,8 @@ namespace Engine
// 调试截图落盘:等 fence(copy 已提交完成)→ fp16 → BMP
if (doCapture) {
m_Device->GetDevice().waitForFences(
// 诊断截图落盘:等 fence(copy 已提交完成)→ BMP(返回值仅超时标志)
(void)m_Device->GetDevice().waitForFences(
m_SyncManager->GetFrameFence(frameSlot), VK_TRUE,
UINT64_MAX);
WriteHdrBMP("capture.bmp", m_CaptureAlloc.MappedPtr,
+21 -6
View File
@@ -19,7 +19,6 @@
#include <chrono>
#include <limits>
#include <algorithm>
namespace Engine
{
@@ -180,6 +179,7 @@ namespace Engine
// 先收集到临时数组,方向光排前,再写入 UBO
glm::vec3 shadowDir{0.0f, -1.0f, 0.0f}; // 无灯兜底:头顶正射
LightData collected[kMaxLights];
f32 shadowKey[kMaxLights]; // 排序键:0=castShadow 方向光 1=方向光 2=点光
u32 collectedCount = 0;
scene.Each<TransformComponent, LightComponent>(
[&](Entity, TransformComponent& t, LightComponent& light) {
@@ -190,6 +190,12 @@ namespace Engine
dst.params = glm::vec4(
light.type == LightComponent::Type::Point ? 1.0f : 0.0f,
light.radius, 0.0f, 0.0f);
// 排序键:castShadow 方向光最优先(CSM 阴影光源契约),其余按类型
shadowKey[collectedCount - 1] =
(light.type == LightComponent::Type::Directional &&
light.castShadow) ? 0.0f
: (light.type == LightComponent::Type::Directional ? 1.0f
: 2.0f);
if (light.type == LightComponent::Type::Point) {
dst.position = glm::vec4(t.GetPosition(), 1.0f);
@@ -202,11 +208,20 @@ namespace Engine
}
});
// 方向光排前(稳定排序:同类保持收集序)→ lights[0] = CSM 光源
std::stable_sort(collected, collected + collectedCount,
[](const LightData& a, const LightData& b) {
return a.params.x < b.params.x; // 0=方向光 < 1=点光
});
// 排序(稳定):castShadow 方向光 → 方向光 → 点光
// 同时排序 shadowKey 保持键值对应
for (u32 i = 1; i < collectedCount; ++i) { // 插入排序(n≤4)
LightData ld = collected[i];
f32 key = shadowKey[i];
u32 j = i;
while (j > 0 && shadowKey[j - 1] > key) {
collected[j] = collected[j - 1];
shadowKey[j] = shadowKey[j - 1];
--j;
}
collected[j] = ld;
shadowKey[j] = key;
}
for (u32 i = 0; i < kMaxLights; ++i) {
if (i < collectedCount) {