Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Clang-format proposal #2390

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Indentation
IndentWidth: 4
UseTab: Never
ContinuationIndentWidth: 4

# Braces
BreakBeforeBraces: Attach # Braces attach to control statements (if, while, for)

# Spacing
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeAssignmentOperators: true

# Line Breaking
ColumnLimit: 80 # Larger column limit to prevent premature breaks
PenaltyBreakBeforeFirstCallParameter: 1000 # Prevent breaking at the first call parameter
PenaltyBreakString: 1000 # Prevent breaking strings
PenaltyBreakComment: 1000 # Prevent breaking comments

# Allow Short If-Statements, Loops, and Functions on a Single Line
AllowShortIfStatementsOnASingleLine: true # Keep short if-statements on a single line
AllowShortLoopsOnASingleLine: true # Keep short loops on a single line
AllowShortFunctionsOnASingleLine: All # Keep short functions on a single line

# Comments
AlignTrailingComments: true

# Includes
SortIncludes: false

# Objective-C
ObjCSpaceBeforeProtocolList: true

# Space in Parentheses
SpacesInParens: Custom
SpacesInParensOptions:
ExceptDoubleParentheses: false
InConditionalStatements: false
Other: false

# Pointer alignment
PointerAlignment: Left

# Prevent line break for very short blocks
MaxEmptyLinesToKeep: 1 # Don't break up short blocks with many empty lines

# Function formatting
AlwaysBreakAfterReturnType: None # Avoid breaking the return type of functions
146 changes: 79 additions & 67 deletions MoltenVK/MoltenVK/GPUObjects/MVKBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -23,127 +23,139 @@

class MVKCommandEncoder;


#pragma mark MVKBuffer

/** Represents a Vulkan buffer. */
class MVKBuffer : public MVKResource {

public:
public:
/** Returns the Vulkan type of this object. */
VkObjectType getVkObjectType() override { return VK_OBJECT_TYPE_BUFFER; }

/** Returns the Vulkan type of this object. */
VkObjectType getVkObjectType() override { return VK_OBJECT_TYPE_BUFFER; }

/** Returns the debug report object type of this object. */
VkDebugReportObjectTypeEXT getVkDebugReportObjectType() override { return VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT; }
/** Returns the debug report object type of this object. */
VkDebugReportObjectTypeEXT getVkDebugReportObjectType() override {
return VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT;
}

#pragma mark Resource memory

/** Returns the memory requirements of this resource by populating the specified structure. */
VkResult getMemoryRequirements(VkMemoryRequirements* pMemoryRequirements);
/** Returns the memory requirements of this resource by populating the
* specified structure. */
VkResult getMemoryRequirements(VkMemoryRequirements* pMemoryRequirements);

/** Returns the memory requirements of this resource by populating the specified structure. */
VkResult getMemoryRequirements(const void* pInfo, VkMemoryRequirements2* pMemoryRequirements);
/** Returns the memory requirements of this resource by populating the
* specified structure. */
VkResult getMemoryRequirements(const void* pInfo,
VkMemoryRequirements2* pMemoryRequirements);

/** Binds this resource to the specified offset within the specified memory allocation. */
VkResult bindDeviceMemory(MVKDeviceMemory* mvkMem, VkDeviceSize memOffset) override;
/** Binds this resource to the specified offset within the specified memory
* allocation. */
VkResult bindDeviceMemory(MVKDeviceMemory* mvkMem,
VkDeviceSize memOffset) override;

/** Binds this resource to the specified offset within the specified memory allocation. */
VkResult bindDeviceMemory2(const VkBindBufferMemoryInfo* pBindInfo);
/** Binds this resource to the specified offset within the specified memory
* allocation. */
VkResult bindDeviceMemory2(const VkBindBufferMemoryInfo* pBindInfo);

/** Applies the specified global memory barrier. */
void applyMemoryBarrier(MVKPipelineBarrier& barrier,
MVKCommandEncoder* cmdEncoder,
MVKCommandUse cmdUse) override;
/** Applies the specified global memory barrier. */
void applyMemoryBarrier(MVKPipelineBarrier& barrier,
MVKCommandEncoder* cmdEncoder,
MVKCommandUse cmdUse) override;

/** Applies the specified buffer memory barrier. */
void applyBufferMemoryBarrier(MVKPipelineBarrier& barrier,
MVKCommandEncoder* cmdEncoder,
MVKCommandUse cmdUse);
/** Applies the specified buffer memory barrier. */
void applyBufferMemoryBarrier(MVKPipelineBarrier& barrier,
MVKCommandEncoder* cmdEncoder,
MVKCommandUse cmdUse);

/** Returns the intended usage of this buffer. */
VkBufferUsageFlags getUsage() const { return _usage; }


#pragma mark Metal

/** Returns the Metal buffer underlying this memory allocation. */
/** Returns the Metal buffer underlying this memory allocation. */
id<MTLBuffer> getMTLBuffer();

/** Returns the offset at which the contents of this instance starts within the underlying Metal buffer. */
inline NSUInteger getMTLBufferOffset() { return !_deviceMemory || _deviceMemory->getMTLHeap() ? 0 : _deviceMemoryOffset; }
/** Returns the offset at which the contents of this instance starts within
* the underlying Metal buffer. */
inline NSUInteger getMTLBufferOffset() {
return !_deviceMemory || _deviceMemory->getMTLHeap()
? 0
: _deviceMemoryOffset;
}

/** Returns the Metal buffer used as a cache for host-coherent texel buffers. */
/** Returns the Metal buffer used as a cache for host-coherent texel
* buffers. */
id<MTLBuffer> getMTLBufferCache();
/** Returns the GPU address for this MTLBuffer, respecting its offset. */
uint64_t getMTLBufferGPUAddress();

/** Returns the GPU address for this MTLBuffer, respecting its offset. */
uint64_t getMTLBufferGPUAddress();

#pragma mark Construction

MVKBuffer(MVKDevice* device, const VkBufferCreateInfo* pCreateInfo);

~MVKBuffer() override;
MVKBuffer(MVKDevice* device, const VkBufferCreateInfo* pCreateInfo);

void destroy() override;
~MVKBuffer() override;

protected:
friend class MVKDeviceMemory;
void destroy() override;

void propagateDebugName() override;
bool needsHostReadSync(MVKPipelineBarrier& barrier);
bool overlaps(VkDeviceSize offset, VkDeviceSize size, VkDeviceSize &overlapOffset, VkDeviceSize &overlapSize);
bool shouldFlushHostMemory();
VkResult flushToDevice(VkDeviceSize offset, VkDeviceSize size);
VkResult pullFromDevice(VkDeviceSize offset, VkDeviceSize size);
void initExternalMemory(VkExternalMemoryHandleTypeFlags handleTypes);
void detachMemory();
protected:
friend class MVKDeviceMemory;

VkBufferUsageFlags _usage;
bool _isHostCoherentTexelBuffer = false;
void propagateDebugName() override;
bool needsHostReadSync(MVKPipelineBarrier& barrier);
bool overlaps(VkDeviceSize offset, VkDeviceSize size,
VkDeviceSize& overlapOffset, VkDeviceSize& overlapSize);
bool shouldFlushHostMemory();
VkResult flushToDevice(VkDeviceSize offset, VkDeviceSize size);
VkResult pullFromDevice(VkDeviceSize offset, VkDeviceSize size);
void initExternalMemory(VkExternalMemoryHandleTypeFlags handleTypes);
void detachMemory();

VkBufferUsageFlags _usage;
bool _isHostCoherentTexelBuffer = false;
id<MTLBuffer> _mtlBufferCache = nil;
id<MTLBuffer> _mtlBuffer = nil;
id<MTLBuffer> _mtlBuffer = nil;
std::mutex _lock;
};


#pragma mark MVKBufferView

/** Represents a Vulkan buffer view. */
class MVKBufferView : public MVKVulkanAPIDeviceObject {

public:

/** Returns the Vulkan type of this object. */
VkObjectType getVkObjectType() override { return VK_OBJECT_TYPE_BUFFER_VIEW; }
public:
/** Returns the Vulkan type of this object. */
VkObjectType getVkObjectType() override {
return VK_OBJECT_TYPE_BUFFER_VIEW;
}

/** Returns the debug report object type of this object. */
VkDebugReportObjectTypeEXT getVkDebugReportObjectType() override { return VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT; }
/** Returns the debug report object type of this object. */
VkDebugReportObjectTypeEXT getVkDebugReportObjectType() override {
return VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT;
}

#pragma mark Metal

/** Returns a Metal texture that overlays this buffer view. */
id<MTLTexture> getMTLTexture();


#pragma mark Construction

MVKBufferView(MVKDevice* device, const VkBufferViewCreateInfo* pCreateInfo);

~MVKBufferView() override;

void destroy() override;
void destroy() override;

protected:
void propagateDebugName() override;
void detachMemory();
protected:
void propagateDebugName() override;
void detachMemory();

MVKBuffer* _buffer;
NSUInteger _offset;
id<MTLTexture> _mtlTexture;
MTLPixelFormat _mtlPixelFormat;
NSUInteger _mtlBytesPerRow;
id<MTLTexture> _mtlTexture;
MTLPixelFormat _mtlPixelFormat;
NSUInteger _mtlBytesPerRow;
VkExtent2D _textureSize;
std::mutex _lock;
std::mutex _lock;
};

Loading
Loading