fix upload data may be invalidated by previous pipelines with the same memory on integrated device, fix #2640

This commit is contained in:
nihuini
2021-02-02 16:47:08 +08:00
parent 7c8c6d9ce9
commit 77db369cae
+16 -40
View File
@@ -378,14 +378,7 @@ void VkCompute::record_upload(const Mat& src, VkMat& dst, const Option& opt)
// upload
VkMat dst_staging;
if (opt.blob_vkallocator->mappable)
{
dst_staging.create_like(src_fp16, opt.blob_vkallocator);
}
else
{
dst_staging.create_like(src_fp16, opt.staging_vkallocator);
}
dst_staging.create_like(src_fp16, opt.staging_vkallocator);
if (dst_staging.empty())
return;
@@ -443,14 +436,7 @@ void VkCompute::record_upload(const Mat& src, VkImageMat& dst, const Option& opt
// upload
VkMat dst_staging;
if (opt.blob_vkallocator->mappable)
{
dst_staging.create_like(src_fp16, opt.blob_vkallocator);
}
else
{
dst_staging.create_like(src_fp16, opt.staging_vkallocator);
}
dst_staging.create_like(src_fp16, opt.staging_vkallocator);
if (dst_staging.empty())
return;
@@ -782,35 +768,25 @@ void VkCompute::record_clone(const Mat& src, VkMat& dst, const Option& opt)
{
// NCNN_LOGE("record_clone host to buffer");
if (!opt.blob_vkallocator->mappable)
{
// host to staging
VkMat dst_staging;
Option opt_staging = opt;
opt_staging.blob_vkallocator = opt.staging_vkallocator;
record_clone(src, dst_staging, opt_staging);
// staging to device
record_clone(dst_staging, dst, opt);
// stash staging
d->upload_staging_buffers.push_back(dst_staging);
return;
}
// create dst
dst.create_like(src, opt.blob_vkallocator);
if (dst.empty())
// host to staging
VkMat dst_staging;
dst_staging.create_like(src, opt.staging_vkallocator);
if (dst_staging.empty())
return;
// memcpy src to device
memcpy(dst.mapped_ptr(), src.data, src.total() * src.elemsize);
dst.allocator->flush(dst.data);
memcpy(dst_staging.mapped_ptr(), src.data, src.total() * src.elemsize);
dst_staging.allocator->flush(dst_staging.data);
// mark device host-write @ null
dst.data->access_flags = VK_ACCESS_HOST_WRITE_BIT;
dst.data->stage_flags = VK_PIPELINE_STAGE_HOST_BIT;
dst_staging.data->access_flags = VK_ACCESS_HOST_WRITE_BIT;
dst_staging.data->stage_flags = VK_PIPELINE_STAGE_HOST_BIT;
// staging to device
record_clone(dst_staging, dst, opt);
// stash staging
d->upload_staging_buffers.push_back(dst_staging);
}
void VkCompute::record_clone(const Mat& src, VkImageMat& dst, const Option& opt)