Compare commits
1 Commits
ImmediateG
...
GetMappedR
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c1167ddb8 |
@@ -94,15 +94,14 @@ void WebGPUBufferBase::updateGPUBuffer(BufferDescriptor const& bufferDescriptor,
|
|||||||
// .size = stagingBufferSize,
|
// .size = stagingBufferSize,
|
||||||
// .mappedAtCreation = true };
|
// .mappedAtCreation = true };
|
||||||
// wgpu::Buffer stagingBuffer = device.CreateBuffer(&descriptor);
|
// wgpu::Buffer stagingBuffer = device.CreateBuffer(&descriptor);
|
||||||
wgpu::Buffer stagingBuffer = webGPUStagePool->acquireBuffer(stagingBufferSize);
|
MappedStage mappedStage = webGPUStagePool->acquireBuffer(stagingBufferSize);
|
||||||
|
|
||||||
void* mappedRange = stagingBuffer.GetMappedRange();
|
std::string mappedRangeIsNull = mappedStage.mappedRange
|
||||||
std::string mappedRangeIsNull = mappedRange
|
|
||||||
? "no"
|
? "no"
|
||||||
: "yes";
|
: "yes";
|
||||||
std::cout << "Run Yu: got mapped range on the staging buffer with size "
|
std::cout << "Run Yu: got mapped range on the staging buffer with size "
|
||||||
<< stagingBuffer.GetSize() << " and it is null? " << mappedRangeIsNull << std::endl;
|
<< mappedStage.buffer.GetSize() << " and it is null? " << mappedRangeIsNull << std::endl;
|
||||||
memcpy(mappedRange, bufferDescriptor.buffer, bufferDescriptor.size);
|
memcpy(mappedStage.mappedRange, bufferDescriptor.buffer, bufferDescriptor.size);
|
||||||
|
|
||||||
// Make sure the padded memory is set to 0 to have deterministic behaviors
|
// Make sure the padded memory is set to 0 to have deterministic behaviors
|
||||||
// if (remainder != 0) {
|
// if (remainder != 0) {
|
||||||
@@ -117,13 +116,13 @@ void WebGPUBufferBase::updateGPUBuffer(BufferDescriptor const& bufferDescriptor,
|
|||||||
// memset(paddingStart, 0, FILAMENT_WEBGPU_BUFFER_SIZE_MODULUS - (stagingBuffer.GetSize() - bufferDescriptor.size));
|
// memset(paddingStart, 0, FILAMENT_WEBGPU_BUFFER_SIZE_MODULUS - (stagingBuffer.GetSize() - bufferDescriptor.size));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
stagingBuffer.Unmap();
|
mappedStage.buffer.Unmap();
|
||||||
|
|
||||||
std::cout << "Run Yu: about to issue copy command with actual staging buffer of size "
|
std::cout << "Run Yu: about to issue copy command with actual staging buffer of size "
|
||||||
<< stagingBuffer.GetSize() << ", and computed size of " << stagingBufferSize
|
<< mappedStage.buffer.GetSize() << ", and computed size of " << stagingBufferSize
|
||||||
<< ". The mBuffer size is " << mBuffer.GetSize() << std::endl;
|
<< ". The mBuffer size is " << mBuffer.GetSize() << std::endl;
|
||||||
// Copy the staging buffer contents to the destination buffer.
|
// Copy the staging buffer contents to the destination buffer.
|
||||||
webGPUQueueManager->getCommandEncoder().CopyBufferToBuffer(stagingBuffer, 0, mBuffer,
|
webGPUQueueManager->getCommandEncoder().CopyBufferToBuffer(mappedStage.buffer, 0, mBuffer,
|
||||||
byteOffset,
|
byteOffset,
|
||||||
remainder == 0 ? bufferDescriptor.size
|
remainder == 0 ? bufferDescriptor.size
|
||||||
: mainBulk + FILAMENT_WEBGPU_BUFFER_SIZE_MODULUS);
|
: mainBulk + FILAMENT_WEBGPU_BUFFER_SIZE_MODULUS);
|
||||||
@@ -134,8 +133,8 @@ void WebGPUBufferBase::updateGPUBuffer(BufferDescriptor const& bufferDescriptor,
|
|||||||
WebGPUStagePool* webGPUStagePool;
|
WebGPUStagePool* webGPUStagePool;
|
||||||
};
|
};
|
||||||
auto userData = std::make_unique<UserData>(
|
auto userData = std::make_unique<UserData>(
|
||||||
UserData{ .stagingBuffer = stagingBuffer, .webGPUStagePool = webGPUStagePool });
|
UserData{ .stagingBuffer = mappedStage.buffer, .webGPUStagePool = webGPUStagePool });
|
||||||
stagingBuffer.MapAsync(
|
mappedStage.buffer.MapAsync(
|
||||||
wgpu::MapMode::Write, 0, stagingBufferSize, wgpu::CallbackMode::AllowSpontaneous,
|
wgpu::MapMode::Write, 0, stagingBufferSize, wgpu::CallbackMode::AllowSpontaneous,
|
||||||
[](wgpu::MapAsyncStatus status, const char* message, UserData* userData) {
|
[](wgpu::MapAsyncStatus status, const char* message, UserData* userData) {
|
||||||
if (UTILS_LIKELY(status == wgpu::MapAsyncStatus::Success)) {
|
if (UTILS_LIKELY(status == wgpu::MapAsyncStatus::Success)) {
|
||||||
|
|||||||
@@ -26,24 +26,32 @@ WebGPUStagePool::WebGPUStagePool(wgpu::Device const& device) : mDevice(device) {
|
|||||||
|
|
||||||
WebGPUStagePool::~WebGPUStagePool() = default;
|
WebGPUStagePool::~WebGPUStagePool() = default;
|
||||||
|
|
||||||
wgpu::Buffer WebGPUStagePool::acquireBuffer(size_t requiredSize) {
|
MappedStage WebGPUStagePool::acquireBuffer(size_t requiredSize) {
|
||||||
std::cout << "Run Yu: required size in acquireBuffer: " << requiredSize << std::endl;
|
std::cout << "Run Yu: required size in acquireBuffer: " << requiredSize << std::endl;
|
||||||
std::cout << "Run Yu: the pool size is " << mBuffers.size() << std::endl;
|
std::cout << "Run Yu: the pool size is " << mBuffers.size() << std::endl;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mMutex);
|
std::lock_guard<std::mutex> lock(mMutex);
|
||||||
auto iter = mBuffers.lower_bound(requiredSize);
|
auto iter = mBuffers.lower_bound(requiredSize);
|
||||||
if (iter != mBuffers.end()) {
|
if (iter != mBuffers.end()) {
|
||||||
wgpu::Buffer bufferFromPool = iter->second;
|
std::cout << "Run Yu: found buffer in the pool with size " << iter->second.GetSize()
|
||||||
std::cout << "Run Yu: found buffer in the pool with size " << bufferFromPool.GetSize()
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
mBuffers.erase(iter);
|
if (iter->second.GetMapState() != wgpu::BufferMapState::Mapped) {
|
||||||
if (bufferFromPool.GetMapState() != wgpu::BufferMapState::Mapped) {
|
std::cout << "Run Yu: before GetMappedRange the buffer state is not mapped!\n";
|
||||||
std::cout << "Run Yu: buffer from pool is not mapped!!" << std::endl;
|
|
||||||
}
|
}
|
||||||
return bufferFromPool;
|
MappedStage mappedStage = { .buffer = iter->second,
|
||||||
|
.mappedRange = iter->second.GetMappedRange() };
|
||||||
|
if (!mappedStage.mappedRange) {
|
||||||
|
std::cout << "Run Yu: mapped range is null in acquireBuffer!\n";
|
||||||
|
}
|
||||||
|
if (mappedStage.buffer.GetMapState() != wgpu::BufferMapState::Mapped) {
|
||||||
|
std::cout << "Run Yu: after GetMappedRange the buffer state is not mapped!\n";
|
||||||
|
}
|
||||||
|
mBuffers.erase(iter);
|
||||||
|
return mappedStage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return createNewBuffer(requiredSize);
|
wgpu::Buffer newBuffer = createNewBuffer(requiredSize);
|
||||||
|
return { .buffer = newBuffer, .mappedRange = newBuffer.GetMappedRange() };
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGPUStagePool::addBufferToPool(wgpu::Buffer buffer) {
|
void WebGPUStagePool::addBufferToPool(wgpu::Buffer buffer) {
|
||||||
@@ -64,8 +72,6 @@ void WebGPUStagePool::addBufferToPool(wgpu::Buffer buffer) {
|
|||||||
}
|
}
|
||||||
if (!allMapped) {
|
if (!allMapped) {
|
||||||
std::cout << "Run Yu: found buffers that are not mapped\n";
|
std::cout << "Run Yu: found buffers that are not mapped\n";
|
||||||
} else {
|
|
||||||
std::cout << "Run Yu: all buffers are mapped\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,12 +24,17 @@
|
|||||||
|
|
||||||
namespace filament::backend {
|
namespace filament::backend {
|
||||||
|
|
||||||
|
struct MappedStage {
|
||||||
|
wgpu::Buffer buffer;
|
||||||
|
void* mappedRange;
|
||||||
|
};
|
||||||
|
|
||||||
class WebGPUStagePool {
|
class WebGPUStagePool {
|
||||||
public:
|
public:
|
||||||
WebGPUStagePool(wgpu::Device const& device);
|
WebGPUStagePool(wgpu::Device const& device);
|
||||||
~WebGPUStagePool();
|
~WebGPUStagePool();
|
||||||
|
|
||||||
wgpu::Buffer acquireBuffer(size_t requiredSize);
|
MappedStage acquireBuffer(size_t requiredSize);
|
||||||
void addBufferToPool(wgpu::Buffer buffer);
|
void addBufferToPool(wgpu::Buffer buffer);
|
||||||
private:
|
private:
|
||||||
wgpu::Buffer createNewBuffer(size_t bufferSize);
|
wgpu::Buffer createNewBuffer(size_t bufferSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user