Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 646d0d1

Browse files
MarijnS95claude
andauthored
Address post-merge review comments on CommandBuffer (#1033) (#1086)
Address post-review comments from @bogner on #1033. These felt significant enough that they weren't worth cramming into an "unrelated" PR but deserve their own clean follow-up in three individual commits. - Add virtual method anchors for all polymorphic types (`Buffer`, `CommandBuffer`, `Fence`, `ImageComparatorBase`, `ImageComparatorDiffImage`, `Texture`) per LLVM coding standards - Add file description to header comment - Switch to LLVM-style RTTI (`classof()`) instead of hand-rolled `as<T>()` + `BackendAPI`, fixing `-Wunused-const-variable` Adding `-Werror` to the build is left for a separate PR as it requires a warning audit first — the project inherits compile flags from LLVM's CMake infrastructure and backend SDK headers may introduce additional warnings. --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 0d8251f commit 646d0d1

12 files changed

Lines changed: 34 additions & 23 deletions

File tree

include/API/Buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct BufferCreateDesc {
2222

2323
class Buffer {
2424
public:
25-
virtual ~Buffer() = default;
25+
virtual ~Buffer();
2626

2727
Buffer(const Buffer &) = delete;
2828
Buffer &operator=(const Buffer &) = delete;

include/API/CommandBuffer.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9+
// Defines the CommandBuffer base class for recording and submitting GPU work.
10+
// Each backend (DirectX, Vulkan, Metal) provides a concrete subclass that
11+
// wraps the native command recording objects. LLVM-style RTTI is provided for
12+
// downcasting to the backend-specific type.
913
//
1014
//===----------------------------------------------------------------------===//
1115

@@ -14,29 +18,18 @@
1418

1519
#include "API/API.h"
1620

17-
#include <cassert>
18-
1921
namespace offloadtest {
2022

2123
class CommandBuffer {
22-
GPUAPI API;
24+
GPUAPI Kind;
2325

2426
public:
25-
explicit CommandBuffer(GPUAPI API) : API(API) {}
26-
virtual ~CommandBuffer() = default;
27+
explicit CommandBuffer(GPUAPI Kind) : Kind(Kind) {}
28+
virtual ~CommandBuffer();
2729
CommandBuffer(const CommandBuffer &) = delete;
2830
CommandBuffer &operator=(const CommandBuffer &) = delete;
2931

30-
GPUAPI getAPI() const { return API; }
31-
32-
template <typename T> T &as() {
33-
assert(API == T::BackendAPI && "CommandBuffer backend mismatch");
34-
return static_cast<T &>(*this);
35-
}
36-
template <typename T> const T &as() const {
37-
assert(API == T::BackendAPI && "CommandBuffer backend mismatch");
38-
return static_cast<const T &>(*this);
39-
}
32+
GPUAPI getKind() const { return Kind; }
4033
};
4134

4235
} // namespace offloadtest

include/API/Device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct DeviceConfig {
4242

4343
class Fence {
4444
public:
45-
virtual ~Fence() = default;
45+
virtual ~Fence();
4646

4747
Fence(const Fence &) = delete;
4848
Fence &operator=(const Fence &) = delete;

include/API/Texture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ inline llvm::Error validateTextureCreateDesc(const TextureCreateDesc &Desc) {
141141

142142
class Texture {
143143
public:
144-
virtual ~Texture() = default;
144+
virtual ~Texture();
145145

146146
Texture(const Texture &) = delete;
147147
Texture &operator=(const Texture &) = delete;

include/Image/Image.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace offloadtest {
3030

3131
class ImageComparatorBase {
3232
public:
33-
virtual ~ImageComparatorBase() {}
33+
virtual ~ImageComparatorBase();
3434
virtual void processPixel(Color L, Color R) = 0;
3535
virtual void print(llvm::raw_ostream &OS) {}
3636
virtual bool result() { return true; }

include/Image/ImageComparators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ImageComparatorDiffImage : public ImageComparatorBase {
113113
llvm::StringRef OutputFilename;
114114

115115
public:
116-
virtual ~ImageComparatorDiffImage() {}
116+
~ImageComparatorDiffImage() override;
117117
ImageComparatorDiffImage(uint32_t Height, uint32_t Width, llvm::StringRef OF)
118118
: DiffImg(Height, Width, 4, 3, true), OutputFilename(OF) {
119119
DiffPtr = reinterpret_cast<float *>(DiffImg.data());

lib/API/DX/Device.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ class DXQueue : public offloadtest::Queue {
414414

415415
class DXCommandBuffer : public offloadtest::CommandBuffer {
416416
public:
417-
static constexpr GPUAPI BackendAPI = GPUAPI::DirectX;
417+
static bool classof(const CommandBuffer *CB) {
418+
return CB->getKind() == GPUAPI::DirectX;
419+
}
418420

419421
ComPtr<ID3D12CommandAllocator> Allocator;
420422
ComPtr<ID3D12GraphicsCommandList> CmdList;

lib/API/Device.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121

2222
using namespace offloadtest;
2323

24+
Buffer::~Buffer() {}
25+
26+
CommandBuffer::~CommandBuffer() {}
27+
28+
Fence::~Fence() {}
29+
2430
Queue::~Queue() {}
2531

32+
Texture::~Texture() {}
33+
2634
Device::~Device() {}
2735

2836
llvm::Expected<llvm::SmallVector<std::unique_ptr<Device>>>

lib/API/MTL/MTLDevice.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ class MTLTexture : public offloadtest::Texture {
150150

151151
class MTLCommandBuffer : public offloadtest::CommandBuffer {
152152
public:
153-
static constexpr GPUAPI BackendAPI = GPUAPI::Metal;
153+
static bool classof(const CommandBuffer *CB) {
154+
return CB->getKind() == GPUAPI::Metal;
155+
}
154156

155157
MTL::CommandBuffer *CmdBuffer = nullptr;
156158

lib/API/VK/Device.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ class VulkanQueue : public offloadtest::Queue {
480480

481481
class VulkanCommandBuffer : public offloadtest::CommandBuffer {
482482
public:
483-
static constexpr GPUAPI BackendAPI = GPUAPI::Vulkan;
483+
static bool classof(const CommandBuffer *CB) {
484+
return CB->getKind() == GPUAPI::Vulkan;
485+
}
484486

485487
VkDevice Device = VK_NULL_HANDLE;
486488
// Owned per command buffer so that recording, submission, and lifetime

0 commit comments

Comments
 (0)