Skip to content

Commit 535cfad

Browse files
Merge pull request #731 from Devsh-Graphics-Programming/tad_flatten_updates
FlattenRegionStreamHashImageFilter post merge stuff
2 parents 376d40d + ba5200d commit 535cfad

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

src/nbl/asset/ICPUImage.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "nbl/asset/filters/CMatchedSizeInOutImageFilterCommon.h"
44
#include "nbl/asset/filters/CFlattenRegionsImageFilter.h"
55

6+
#include <ranges>
7+
68
using namespace nbl;
79
using namespace asset;
810

@@ -132,10 +134,10 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
132134
{
133135
auto buffer = getScratchAsBuffer(state->scratch.size);
134136
const auto product = parameters.mipLevels * parameters.arrayLayers;
135-
136-
scratch.hashes = { .offset = 0u, .size = product * sizeof(CState::outHash), .buffer = buffer };
137-
scratch.hashers = { .offset = scratch.hashes.size, .size = product * sizeof(blake3_hasher), .buffer = buffer };
138-
scratch.flatten = { .offset = scratch.hashers.offset + scratch.hashers.size, .size = state->scratch.size - scratch.hashers.size - scratch.hashes.size, .buffer = buffer };
137+
138+
scratch.hashes = { static_cast<CState::hash_t*>(state->scratch.memory), product };
139+
scratch.hashers = { reinterpret_cast<blake3_hasher*>(scratch.hashes.data() + scratch.hashes.size()), product };
140+
scratch.flatten = { .offset = scratch.hashes.size_bytes() + scratch.hashers.size_bytes(), .size = state->scratch.size - scratch.hashers.size_bytes() - scratch.hashes.size_bytes(), .buffer = buffer};
139141
}
140142

141143
const auto isFullyFlatten = scratch.flatten.size == 0ull;
@@ -188,7 +190,8 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
188190
flatten.preFill = true;
189191
memset(flatten.fillValue.pointer, 0, sizeof(flatten.fillValue.pointer));
190192

191-
assert(CFlattenRegionsImageFilter::execute(policy, &proxy.flatten)); // this should never fail, at this point we are already validated
193+
auto status = CFlattenRegionsImageFilter::execute(policy, &proxy.flatten);
194+
assert(status); // this should never fail, at this point we are already validated
192195
}
193196

194197
/*
@@ -202,18 +205,15 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
202205
const auto texelOrBlockByteSize = asset::getTexelOrBlockBytesize(parameters.format);
203206
const uint8_t* inData = reinterpret_cast<const uint8_t*>(image->getBuffer()->getPointer());
204207

205-
std::vector<uint32_t> layers(parameters.arrayLayers);
206-
std::iota(layers.begin(), layers.end(), 0);
207-
208-
std::vector<uint32_t> levels(parameters.mipLevels);
209-
std::iota(levels.begin(), levels.end(), 0);
208+
auto layers = std::views::iota(0u, parameters.arrayLayers);
209+
auto levels = std::views::iota(0u, parameters.mipLevels);
210210

211211
/*
212212
we stream-hash texels per given mip level & layer
213213
*/
214214

215-
auto* const hashes = reinterpret_cast<CState::hash_t*>(getScratchAsBuffer(scratch.hashes.size, scratch.hashes.offset)->getPointer());
216-
auto* const hashers = reinterpret_cast<blake3_hasher*>(getScratchAsBuffer(scratch.hashers.size, scratch.hashers.offset)->getPointer());
215+
auto* const hashes = scratch.hashes.data();
216+
auto* const hashers = scratch.hashers.data();
217217

218218
auto executePerMipLevel = [&](const uint32_t miplevel)
219219
{
@@ -239,16 +239,7 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
239239
const auto regions = image->getRegions(miplevel);
240240
const bool performNullHash = regions.empty();
241241

242-
if (performNullHash)
243-
{
244-
const auto mipExtentInBlocks = info.convertTexelsToBlocks(image->getMipSize(miplevel));
245-
const auto zeroLength = info.getBlockByteSize() * mipExtentInBlocks.x;
246-
auto zeroArray = std::make_unique<uint8_t[]>(zeroLength);
247-
for (auto z = 0; z < mipExtentInBlocks.z; z++)
248-
for (auto y = 0; y < mipExtentInBlocks.y; y++)
249-
blake3_hasher_update(hasher, zeroArray.get(), zeroLength);
250-
}
251-
else
242+
if (!performNullHash)
252243
CBasicImageFilterCommon::executePerRegion(std::execution::seq, image, executePerTexelOrBlock, regions, clipFunctor); // fire the hasher for a layer, note we forcing seq policy because texels/blocks cannot be handled with par policies when we hash them
253244

254245
blake3_hasher_finalize(hasher, reinterpret_cast<uint8_t*>(hash), sizeof(CState::hash_t)); // finalize hash for layer + put it to heap for given mip level
@@ -292,8 +283,8 @@ class CFlattenRegionsStreamHashImageFilter : public CMatchedSizeInOutImageFilter
292283

293284
struct ScratchMap
294285
{
295-
asset::SBufferRange<asset::ICPUBuffer> hashes; // hashes, single hash is obtained from given miplevel & layer, full hash for an image is a hash of this hash buffer
296-
asset::SBufferRange<asset::ICPUBuffer> hashers; // hashers, used to produce a hash
286+
std::span<CState::hash_t> hashes; // hashes, single hash is obtained from given miplevel & layer, full hash for an image is a hash of this hash buffer
287+
std::span<blake3_hasher> hashers; // hashers, used to produce a hash
297288
asset::SBufferRange<asset::ICPUBuffer> flatten; // tightly packed texels from input, no memory gaps
298289
};
299290
};

src/nbl/asset/interchange/CGLILoader.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,13 @@ namespace nbl
193193
for (uint16_t mipLevel = 0; mipLevel < imageInfo.mipLevels; ++mipLevel)
194194
{
195195
const auto layerSize = getFullSizeOfLayer(mipLevel);
196-
const auto mipOffset = (mipLevel * imageInfo.arrayLayers);
197196

198197
for (uint16_t layer = 0; layer < imageInfo.arrayLayers; ++layer)
199198
{
200199
const auto layersData = getCurrentGliLayerAndFace(layer);
201200
const auto gliLayer = layersData.first;
202201
const auto gliFace = layersData.second;
203202

204-
const auto pOffset = mipOffset + layer;
205-
206203
auto regionData = (reinterpret_cast<uint8_t*>(data) + tmpDataSizePerRegionSum + (layer * layerSize));
207204
assignGLIDataToRegion(regionData, texture, gliLayer, gliFace, mipLevel, layerSize);
208205

0 commit comments

Comments
 (0)