MiraclePtr: Rewrite windows specifics
1. Run the clang rewriter:
./tools/clang/rewrite_raw_ptr_fields/rewrite.sh
2. Add manually the missing AllowPtrArithmetic and DanglingUntriaged.
3. Split the patch
This is step 6 of using MiraclePtr in third_party/dawn project:
https://docs.google.com/document/d/1wz45t0alQthsIU9P7_rQcfQyqnrBMXzrOjSzdQo-V-A/edit#heading=h.vn4i6wy373x7
Bug: chromium:1464560
Change-Id: I180e9af8f23be66d7f3eaed043652face737305c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/165960
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
diff --git a/src/dawn/native/d3d/PhysicalDeviceD3D.h b/src/dawn/native/d3d/PhysicalDeviceD3D.h
index 19c10bc..6f73b8d 100644
--- a/src/dawn/native/d3d/PhysicalDeviceD3D.h
+++ b/src/dawn/native/d3d/PhysicalDeviceD3D.h
@@ -29,6 +29,7 @@
#define SRC_DAWN_NATIVE_D3D_PHYSICALDEVICED3D_H_
#include "dawn/native/PhysicalDevice.h"
+#include "partition_alloc/pointers/raw_ptr.h"
#include "dawn/native/d3d/d3d_platform.h"
@@ -51,7 +52,7 @@
private:
ComPtr<IDXGIAdapter3> mHardwareAdapter;
- Backend* mBackend;
+ raw_ptr<Backend> mBackend;
};
} // namespace dawn::native::d3d
diff --git a/src/dawn/native/d3d11/BindGroupTrackerD3D11.h b/src/dawn/native/d3d11/BindGroupTrackerD3D11.h
index 56e461a..39193f9 100644
--- a/src/dawn/native/d3d11/BindGroupTrackerD3D11.h
+++ b/src/dawn/native/d3d11/BindGroupTrackerD3D11.h
@@ -32,6 +32,7 @@
#include "dawn/native/BindGroupTracker.h"
#include "dawn/native/d3d/d3d_platform.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::native::d3d11 {
@@ -55,7 +56,7 @@
MaybeError ApplyBindGroup(BindGroupIndex index);
void UnApplyBindGroup(BindGroupIndex index);
- const ScopedSwapStateCommandRecordingContext* mCommandContext;
+ raw_ptr<const ScopedSwapStateCommandRecordingContext> mCommandContext;
const bool mIsRenderPass;
const wgpu::ShaderStage mVisibleStages;
// All the pixel local storage UAVs
diff --git a/src/dawn/native/d3d11/BufferD3D11.cpp b/src/dawn/native/d3d11/BufferD3D11.cpp
index 2bc8118..80947d3 100644
--- a/src/dawn/native/d3d11/BufferD3D11.cpp
+++ b/src/dawn/native/d3d11/BufferD3D11.cpp
@@ -488,7 +488,7 @@
}
if (mMappedData) {
- memset(mMappedData + offset, clearValue, size);
+ memset(mMappedData.get() + offset, clearValue, size);
// The WebGPU uniform buffer is not mappable.
DAWN_ASSERT(!mD3d11ConstantBuffer);
return {};
@@ -710,7 +710,7 @@
}
uint8_t* Buffer::ScopedMap::GetMappedData() const {
- return mBuffer ? mBuffer->mMappedData : nullptr;
+ return mBuffer ? mBuffer->mMappedData.get() : nullptr;
}
} // namespace dawn::native::d3d11
diff --git a/src/dawn/native/d3d11/BufferD3D11.h b/src/dawn/native/d3d11/BufferD3D11.h
index bc9602a..09decf0 100644
--- a/src/dawn/native/d3d11/BufferD3D11.h
+++ b/src/dawn/native/d3d11/BufferD3D11.h
@@ -33,6 +33,7 @@
#include "dawn/native/Buffer.h"
#include "dawn/native/d3d/d3d_platform.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::native::d3d11 {
@@ -108,8 +109,8 @@
Buffer* buffer,
bool needsUnmap);
- const ScopedCommandRecordingContext* mCommandContext = nullptr;
- Buffer* mBuffer = nullptr;
+ raw_ptr<const ScopedCommandRecordingContext> mCommandContext = nullptr;
+ raw_ptr<Buffer> mBuffer = nullptr;
// Whether the buffer needs to be unmapped when the ScopedMap object is destroyed.
bool mNeedsUnmap = false;
};
@@ -154,7 +155,7 @@
// The buffer object for non-constant buffer usages(e.g. storage buffer, vertex buffer, etc.)
ComPtr<ID3D11Buffer> mD3d11NonConstantBuffer;
bool mConstantBufferIsUpdated = true;
- uint8_t* mMappedData = nullptr;
+ raw_ptr<uint8_t, AllowPtrArithmetic> mMappedData = nullptr;
};
} // namespace dawn::native::d3d11
diff --git a/src/dawn/native/d3d11/CommandBufferD3D11.cpp b/src/dawn/native/d3d11/CommandBufferD3D11.cpp
index 582bb37..7c8dd3c 100644
--- a/src/dawn/native/d3d11/CommandBufferD3D11.cpp
+++ b/src/dawn/native/d3d11/CommandBufferD3D11.cpp
@@ -54,6 +54,7 @@
#include "dawn/native/d3d11/SharedFenceD3D11.h"
#include "dawn/native/d3d11/TextureD3D11.h"
#include "dawn/native/d3d11/UtilsD3D11.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::native::d3d11 {
namespace {
@@ -103,8 +104,8 @@
}
private:
- const ScopedSwapStateCommandRecordingContext* mCommandContext;
- const RenderPipeline* mLastAppliedRenderPipeline = nullptr;
+ raw_ptr<const ScopedSwapStateCommandRecordingContext> mCommandContext;
+ raw_ptr<const RenderPipeline> mLastAppliedRenderPipeline = nullptr;
PerVertexBuffer<ID3D11Buffer*> mD3D11Buffers = {};
PerVertexBuffer<UINT> mStrides = {};
PerVertexBuffer<UINT> mOffsets = {};
diff --git a/src/dawn/native/d3d12/BindGroupLayoutD3D12.h b/src/dawn/native/d3d12/BindGroupLayoutD3D12.h
index b460927..5c8bc81 100644
--- a/src/dawn/native/d3d12/BindGroupLayoutD3D12.h
+++ b/src/dawn/native/d3d12/BindGroupLayoutD3D12.h
@@ -36,6 +36,7 @@
#include "dawn/native/BindGroupLayoutInternal.h"
#include "dawn/native/d3d12/BindGroupD3D12.h"
#include "dawn/native/d3d12/d3d12_platform.h"
+#include "partition_alloc/pointers/raw_ptr_exclusion.h"
namespace dawn::native::d3d12 {
@@ -96,8 +97,10 @@
MutexProtected<SlabAllocator<BindGroup>> mBindGroupAllocator;
- MutexProtected<StagingDescriptorAllocator>* mSamplerAllocator = nullptr;
- MutexProtected<StagingDescriptorAllocator>* mViewAllocator = nullptr;
+ // TODO(https://crbug.com/dawn/2361): Rewrite those members with raw_ptr<T>.
+ // This is currently failing with MSVC cl.exe compiler.
+ RAW_PTR_EXCLUSION MutexProtected<StagingDescriptorAllocator>* mSamplerAllocator = nullptr;
+ RAW_PTR_EXCLUSION MutexProtected<StagingDescriptorAllocator>* mViewAllocator = nullptr;
};
} // namespace dawn::native::d3d12
diff --git a/src/dawn/native/d3d12/BufferD3D12.cpp b/src/dawn/native/d3d12/BufferD3D12.cpp
index ab01e77..237e715 100644
--- a/src/dawn/native/d3d12/BufferD3D12.cpp
+++ b/src/dawn/native/d3d12/BufferD3D12.cpp
@@ -46,6 +46,7 @@
#include "dawn/native/d3d12/UtilsD3D12.h"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/platform/tracing/TraceEvent.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::native::d3d12 {
@@ -515,7 +516,7 @@
std::unique_ptr<Heap> heap;
wgpu::Callback callback;
- void* userdata;
+ raw_ptr<void> userdata;
};
std::unique_ptr<DisposeTask> request = std::make_unique<DisposeTask>(
std::move(mHostMappedHeap), mHostMappedDisposeCallback, mHostMappedDisposeUserdata);
diff --git a/src/dawn/native/d3d12/BufferD3D12.h b/src/dawn/native/d3d12/BufferD3D12.h
index a25d3e5..dcc25b0 100644
--- a/src/dawn/native/d3d12/BufferD3D12.h
+++ b/src/dawn/native/d3d12/BufferD3D12.h
@@ -32,6 +32,7 @@
#include <memory>
#include "dawn/native/Buffer.h"
+#include "partition_alloc/pointers/raw_ptr.h"
#include "dawn/native/d3d12/ResourceHeapAllocationD3D12.h"
#include "dawn/native/d3d12/d3d12_platform.h"
@@ -99,7 +100,7 @@
std::unique_ptr<Heap> mHostMappedHeap;
wgpu::Callback mHostMappedDisposeCallback = nullptr;
- void* mHostMappedDisposeUserdata = nullptr;
+ raw_ptr<void> mHostMappedDisposeUserdata = nullptr;
};
} // namespace dawn::native::d3d12
diff --git a/src/dawn/native/d3d12/CommandAllocatorManager.h b/src/dawn/native/d3d12/CommandAllocatorManager.h
index b0a29ed..767bf4f5 100644
--- a/src/dawn/native/d3d12/CommandAllocatorManager.h
+++ b/src/dawn/native/d3d12/CommandAllocatorManager.h
@@ -31,6 +31,7 @@
#include <bitset>
#include "dawn/native/d3d12/d3d12_platform.h"
+#include "partition_alloc/pointers/raw_ptr.h"
#include "dawn/common/SerialQueue.h"
#include "dawn/native/Error.h"
@@ -51,7 +52,7 @@
private:
// The allocator manager is owned by the queue so the queue outlives it.
- Queue* mQueue;
+ raw_ptr<Queue> mQueue;
// This must be at least 2 because the Device and Queue use separate command allocators
static constexpr unsigned int kMaxCommandAllocators = 32;
diff --git a/src/dawn/native/d3d12/CommandBufferD3D12.cpp b/src/dawn/native/d3d12/CommandBufferD3D12.cpp
index d8835dd..0842470 100644
--- a/src/dawn/native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn/native/d3d12/CommandBufferD3D12.cpp
@@ -51,6 +51,8 @@
#include "dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h"
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
#include "dawn/native/d3d12/UtilsD3D12.h"
+#include "partition_alloc/pointers/raw_ptr.h"
+#include "partition_alloc/pointers/raw_ptr_exclusion.h"
namespace dawn::native::d3d12 {
@@ -612,15 +614,17 @@
}
}
- Device* mDevice;
- DescriptorHeapState* mHeapState;
+ raw_ptr<Device> mDevice;
+ raw_ptr<DescriptorHeapState> mHeapState;
bool mInCompute = false;
PerBindGroup<D3D12_GPU_DESCRIPTOR_HANDLE> mBoundRootSamplerTables = {};
- MutexProtected<ShaderVisibleDescriptorAllocator>& mViewAllocator;
- MutexProtected<ShaderVisibleDescriptorAllocator>& mSamplerAllocator;
+ // TODO(https://crbug.com/dawn/2361): Rewrite those members with raw_ref<T>.
+ // This is currently failing with MSVC cl.exe compiler.
+ RAW_PTR_EXCLUSION MutexProtected<ShaderVisibleDescriptorAllocator>& mViewAllocator;
+ RAW_PTR_EXCLUSION MutexProtected<ShaderVisibleDescriptorAllocator>& mSamplerAllocator;
};
class DescriptorHeapState {
@@ -651,7 +655,7 @@
BindGroupStateTracker* GetGraphicsBindingTracker() { return &mGraphicsBindingTracker; }
private:
- Device* mDevice;
+ raw_ptr<Device> mDevice;
BindGroupStateTracker mComputeBindingTracker;
BindGroupStateTracker mGraphicsBindingTracker;
};
@@ -714,7 +718,7 @@
// If there are multiple calls to SetVertexBuffer, the start and end
// represent the union of the dirty ranges (the union may have non-dirty
// data in the middle of the range).
- const RenderPipeline* mLastAppliedRenderPipeline = nullptr;
+ raw_ptr<const RenderPipeline> mLastAppliedRenderPipeline = nullptr;
VertexBufferSlot mStartSlot{kMaxVertexBuffers};
VertexBufferSlot mEndSlot{};
PerVertexBuffer<D3D12_VERTEX_BUFFER_VIEW> mD3D12BufferViews = {};
diff --git a/src/dawn/native/d3d12/HeapAllocatorD3D12.h b/src/dawn/native/d3d12/HeapAllocatorD3D12.h
index cf7e9e2..06279b2 100644
--- a/src/dawn/native/d3d12/HeapAllocatorD3D12.h
+++ b/src/dawn/native/d3d12/HeapAllocatorD3D12.h
@@ -33,6 +33,7 @@
#include "dawn/native/D3D12Backend.h"
#include "dawn/native/ResourceHeapAllocator.h"
#include "dawn/native/d3d12/d3d12_platform.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::native::d3d12 {
@@ -51,7 +52,7 @@
void DeallocateResourceHeap(std::unique_ptr<ResourceHeapBase> allocation) override;
private:
- Device* mDevice;
+ raw_ptr<Device> mDevice;
D3D12_HEAP_TYPE mHeapType;
D3D12_HEAP_FLAGS mHeapFlags;
MemorySegment mMemorySegment;
diff --git a/src/dawn/native/d3d12/ResidencyManagerD3D12.h b/src/dawn/native/d3d12/ResidencyManagerD3D12.h
index c846e8c..abec6b5 100644
--- a/src/dawn/native/d3d12/ResidencyManagerD3D12.h
+++ b/src/dawn/native/d3d12/ResidencyManagerD3D12.h
@@ -32,6 +32,7 @@
#include "dawn/native/D3D12Backend.h"
#include "dawn/native/Error.h"
#include "dawn/native/dawn_platform.h"
+#include "partition_alloc/pointers/raw_ptr.h"
#include "dawn/native/d3d12/d3d12_platform.h"
@@ -83,7 +84,7 @@
void UpdateVideoMemoryInfo();
void UpdateMemorySegmentInfo(MemorySegmentInfo* segmentInfo);
- Device* mDevice;
+ raw_ptr<Device> mDevice;
bool mResidencyManagementEnabled = false;
bool mRestrictBudgetForTesting = false;
VideoMemoryInfo mVideoMemoryInfo = {};
diff --git a/src/dawn/native/d3d12/ResourceAllocatorManagerD3D12.h b/src/dawn/native/d3d12/ResourceAllocatorManagerD3D12.h
index 0c2b5c27..a839fce 100644
--- a/src/dawn/native/d3d12/ResourceAllocatorManagerD3D12.h
+++ b/src/dawn/native/d3d12/ResourceAllocatorManagerD3D12.h
@@ -37,6 +37,7 @@
#include "dawn/native/PooledResourceMemoryAllocator.h"
#include "dawn/native/d3d12/HeapAllocatorD3D12.h"
#include "dawn/native/d3d12/ResourceHeapAllocationD3D12.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::native::d3d12 {
@@ -102,7 +103,7 @@
void DestroyPool();
- Device* mDevice;
+ raw_ptr<Device> mDevice;
uint32_t mResourceHeapTier;
static constexpr uint64_t kMaxHeapSize = 32ll * 1024ll * 1024ll * 1024ll; // 32GB
diff --git a/src/dawn/native/d3d12/SamplerHeapCacheD3D12.h b/src/dawn/native/d3d12/SamplerHeapCacheD3D12.h
index 329cdee..af9baf2 100644
--- a/src/dawn/native/d3d12/SamplerHeapCacheD3D12.h
+++ b/src/dawn/native/d3d12/SamplerHeapCacheD3D12.h
@@ -37,6 +37,8 @@
#include "dawn/native/BindingInfo.h"
#include "dawn/native/d3d12/CPUDescriptorHeapAllocationD3D12.h"
#include "dawn/native/d3d12/GPUDescriptorHeapAllocationD3D12.h"
+#include "partition_alloc/pointers/raw_ptr_exclusion.h"
+#include "partition_alloc/pointers/raw_ref.h"
// |SamplerHeapCacheEntry| maintains a cache of sampler descriptor heap allocations.
// Each entry represents one or more sampler descriptors that co-exist in a CPU and
@@ -91,8 +93,10 @@
// by the device and will already be unique.
std::vector<Sampler*> mSamplers;
- MutexProtected<StagingDescriptorAllocator>& mAllocator;
- SamplerHeapCache* mCache = nullptr;
+ // TODO(https://crbug.com/dawn/2361): Rewrite this member with raw_ref<T>.
+ // This is currently failing with MSVC cl.exe compiler.
+ RAW_PTR_EXCLUSION MutexProtected<StagingDescriptorAllocator>& mAllocator;
+ raw_ptr<SamplerHeapCache> mCache = nullptr;
};
// Cache descriptor heap allocations so that we don't create duplicate ones for every
@@ -109,7 +113,7 @@
void RemoveCacheEntry(SamplerHeapCacheEntry* entry);
private:
- Device* mDevice;
+ raw_ptr<Device> mDevice;
using Cache = absl::flat_hash_set<SamplerHeapCacheEntry*,
SamplerHeapCacheEntry::HashFunc,
diff --git a/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h b/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h
index d219160..8c993f6 100644
--- a/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h
+++ b/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h
@@ -37,6 +37,7 @@
#include "dawn/native/d3d12/IntegerTypes.h"
#include "dawn/native/d3d12/PageableD3D12.h"
#include "dawn/native/d3d12/d3d12_platform.h"
+#include "partition_alloc/pointers/raw_ptr.h"
// |ShaderVisibleDescriptorAllocator| allocates a variable-sized block of descriptors from a GPU
// descriptor heap pool.
@@ -101,7 +102,7 @@
std::list<SerialDescriptorHeap> mPool;
D3D12_DESCRIPTOR_HEAP_TYPE mHeapType;
- Device* mDevice;
+ raw_ptr<Device> mDevice;
// The serial value of 0 means the shader-visible heaps have not been allocated.
// This value is never returned in the GPUDescriptorHeapAllocation after
diff --git a/src/dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h b/src/dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h
index 21fc8c0..88c33f4 100644
--- a/src/dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h
+++ b/src/dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h
@@ -34,6 +34,7 @@
#include "dawn/native/Error.h"
#include "dawn/native/IntegerTypes.h"
#include "dawn/native/d3d12/CPUDescriptorHeapAllocationD3D12.h"
+#include "partition_alloc/pointers/raw_ptr.h"
// |StagingDescriptorAllocator| allocates a fixed-size block of descriptors from a CPU
// descriptor heap pool.
@@ -83,7 +84,7 @@
std::vector<uint32_t> mAvailableHeaps; // Indices into the pool.
std::vector<NonShaderVisibleBuffer> mPool;
- Device const* mDevice = nullptr;
+ raw_ptr<const Device> mDevice = nullptr;
const uint32_t mSizeIncrement = 0; // Size of the descriptor (in bytes).
const uint32_t mBlockSize = 0; // Size of the block of descriptors (in bytes).
diff --git a/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp b/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp
index 6cff306..5080a38 100644
--- a/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp
+++ b/src/dawn/tests/white_box/D3D12DescriptorHeapTests.cpp
@@ -39,6 +39,7 @@
#include "dawn/tests/DawnTest.h"
#include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::native::d3d12 {
namespace {
@@ -114,8 +115,8 @@
return {r, g, b, 1};
}
- Device* mD3DDevice = nullptr;
- Queue* mD3DQueue = nullptr;
+ raw_ptr<Device> mD3DDevice = nullptr;
+ raw_ptr<Queue> mD3DQueue = nullptr;
wgpu::ShaderModule mSimpleVSModule;
wgpu::ShaderModule mSimpleFSModule;
diff --git a/src/dawn/tests/white_box/GPUTimestampCalibrationTests_D3D12.cpp b/src/dawn/tests/white_box/GPUTimestampCalibrationTests_D3D12.cpp
index 07ca216..e935920 100644
--- a/src/dawn/tests/white_box/GPUTimestampCalibrationTests_D3D12.cpp
+++ b/src/dawn/tests/white_box/GPUTimestampCalibrationTests_D3D12.cpp
@@ -30,6 +30,7 @@
#include "dawn/native/d3d12/DeviceD3D12.h"
#include "dawn/native/d3d12/QueueD3D12.h"
#include "dawn/tests/white_box/GPUTimestampCalibrationTests.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn {
namespace {
@@ -50,8 +51,8 @@
float GetTimestampPeriod() const override { return mBackendDevice->GetTimestampPeriodInNS(); }
private:
- native::d3d12::Device* mBackendDevice;
- native::d3d12::Queue* mBackendQueue;
+ raw_ptr<native::d3d12::Device> mBackendDevice;
+ raw_ptr<native::d3d12::Queue> mBackendQueue;
};
} // anonymous namespace