Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ComputeBuffer.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9#include <Jolt/Core/Result.h>
10
12
13class ComputeBuffer;
15
17class JPH_EXPORT ComputeBuffer : public RefTarget<ComputeBuffer>, public NonCopyable
18{
19public:
21
23 enum class EType
24 {
25 UploadBuffer,
26 ReadbackBuffer,
27 ConstantBuffer,
28 Buffer,
29 RWBuffer,
30 };
31
33 ComputeBuffer(EType inType, uint64 inSize, uint inStride) : mType(inType), mSize(inSize), mStride(inStride) { }
34 virtual ~ComputeBuffer() { JPH_ASSERT(!mIsMapped); }
35
37 EType GetType() const { return mType; }
38 uint64 GetSize() const { return mSize; }
39 uint GetStride() const { return mStride; }
40
42 enum class EMode
43 {
44 Read,
45 Write,
46 };
47
49 void * Map(EMode inMode) { JPH_ASSERT(!mIsMapped); JPH_IF_ENABLE_ASSERTS(mIsMapped = true;) return MapInternal(inMode); }
50 template <typename T> T * Map(EMode inMode) { JPH_ASSERT(!mIsMapped); JPH_IF_ENABLE_ASSERTS(mIsMapped = true;) JPH_ASSERT(sizeof(T) == mStride); return reinterpret_cast<T *>(MapInternal(inMode)); }
51 void Unmap() { JPH_ASSERT(mIsMapped); JPH_IF_ENABLE_ASSERTS(mIsMapped = false;) UnmapInternal(); }
52
56
57protected:
61#ifdef JPH_ENABLE_ASSERTS
62 bool mIsMapped = false;
63#endif // JPH_ENABLE_ASSERTS
64
65 virtual void * MapInternal(EMode inMode) = 0;
66 virtual void UnmapInternal() = 0;
67};
68
#define JPH_EXPORT
Definition Core.h:275
std::uint64_t uint64
Definition Core.h:504
unsigned int uint
Definition Core.h:500
#define JPH_NAMESPACE_END
Definition Core.h:425
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_IF_ENABLE_ASSERTS(...)
Definition IssueReporting.h:35
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
Buffer that can be read from / written to by a compute shader.
Definition ComputeBuffer.h:18
uint mStride
Definition ComputeBuffer.h:60
virtual ~ComputeBuffer()
Definition ComputeBuffer.h:34
EType mType
Definition ComputeBuffer.h:58
virtual ComputeBufferResult CreateReadBackBuffer() const =0
uint64 mSize
Definition ComputeBuffer.h:59
virtual void * MapInternal(EMode inMode)=0
void Unmap()
Definition ComputeBuffer.h:51
EType GetType() const
Properties.
Definition ComputeBuffer.h:37
void * Map(EMode inMode)
Map / unmap buffer (get pointer to data).
Definition ComputeBuffer.h:49
ComputeBuffer(EType inType, uint64 inSize, uint inStride)
Constructor / Destructor.
Definition ComputeBuffer.h:33
EMode
Mode in which the buffer is accessed.
Definition ComputeBuffer.h:43
EType
Type of buffer.
Definition ComputeBuffer.h:24
uint GetStride() const
Definition ComputeBuffer.h:39
T * Map(EMode inMode)
Definition ComputeBuffer.h:50
virtual void UnmapInternal()=0
uint64 GetSize() const
Definition ComputeBuffer.h:38
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Definition Reference.h:35
Helper class that either contains a valid result or an error.
Definition Result.h:12