Fix NanoVDBLoader: reset command list before use

This commit is contained in:
2026-03-11 18:13:36 +08:00
parent 436ead8b34
commit 8a800f99a2
3 changed files with 16 additions and 5 deletions

View File

@@ -8,8 +8,13 @@
#include <cstring>
#include <iostream>
bool LoadNanoVDB(const char* filePath, NanoVDBData& outData, ID3D12GraphicsCommandList* cmdList) {
bool LoadNanoVDB(const char* filePath, NanoVDBData& outData, ID3D12GraphicsCommandList* cmdList, ID3D12CommandAllocator* cmdAlloc) {
try {
if (cmdAlloc && cmdList) {
cmdAlloc->Reset();
cmdList->Reset(cmdAlloc, nullptr);
}
nanovdb::GridHandle<nanovdb::HostBuffer> gridHandle = nanovdb::io::readGrid(filePath);
const uint64_t byteSize = gridHandle.buffer().bufferSize();

View File

@@ -10,6 +10,6 @@ struct NanoVDBData {
uint64_t elementCount;
};
bool LoadNanoVDB(const char* filePath, NanoVDBData& outData, ID3D12GraphicsCommandList* cmdList = nullptr);
bool LoadNanoVDB(const char* filePath, NanoVDBData& outData, ID3D12GraphicsCommandList* cmdList, ID3D12CommandAllocator* cmdAlloc = nullptr);
void FreeNanoVDB(NanoVDBData& data);

View File

@@ -17,26 +17,32 @@ LPCWSTR gWindowClassName = L"BattleFire";
void RunNanoVDBTest() {
ID3D12GraphicsCommandList* commandList = GetCommandList();
ID3D12CommandAllocator* commandAllocator = GetCommandAllocator();
const char* vdbFiles[] = {
"Res/NanoVDB/bunny.nvdb"
};
NanoVDBData vdbData = {};
for (int i = 0; i < sizeof(vdbFiles) / sizeof(vdbFiles[0]); i++) {
const char* currentVdbFile = vdbFiles[i];
printf("[NanoVDB Test] Loading: %s\n", currentVdbFile);
NanoVDBData vdbData;
bool loadSuccess = LoadNanoVDB(currentVdbFile, vdbData, commandList);
bool loadSuccess = LoadNanoVDB(currentVdbFile, vdbData, commandList, commandAllocator);
if (loadSuccess) {
printf(" SUCCESS - %llu bytes, %llu elements\n",
(unsigned long long)vdbData.byteSize,
(unsigned long long)vdbData.elementCount);
FreeNanoVDB(vdbData);
} else {
printf(" FAILED\n");
}
}
printf("[NanoVDB Test] Done.\n");
FreeNanoVDB(vdbData);
EndCommandList();
WaitForCompletionOfCommandList();
}
LRESULT CALLBACK WindowProc(HWND inHWND, UINT inMSG, WPARAM inWParam, LPARAM inLParam) {