Skip to content
Merged
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
11 changes: 6 additions & 5 deletions src/gpgmm/d3d12/EventRecordD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#define GPGMM_D3D12_EVENTRECORDD3D12_H_

#include "gpgmm/d3d12/d3d12_platform.h"
#include "gpgmm/utils/Flags.h"
#include "gpgmm/utils/EnumFlags.h"

#include <string>

namespace gpgmm::d3d12 {

Expand Down Expand Up @@ -57,8 +59,7 @@ namespace gpgmm::d3d12 {
EVENT_RECORD_FLAG_ALL_EVENTS = 0xFF,
};

using EVENT_RECORD_FLAGS_TYPE = Flags<EVENT_RECORD_FLAGS>;
DEFINE_OPERATORS_FOR_FLAGS(EVENT_RECORD_FLAGS_TYPE)
DEFINE_ENUM_FLAG_OPERATORS(EVENT_RECORD_FLAGS)

/** \enum EVENT_RECORD_SCOPE
Represents recording scopes to limit event recording.
Expand All @@ -82,7 +83,7 @@ namespace gpgmm::d3d12 {

Optional parameter. By default, nothing is recorded.
*/
EVENT_RECORD_FLAGS_TYPE Flags = EVENT_RECORD_FLAG_NONE;
EVENT_RECORD_FLAGS Flags = EVENT_RECORD_FLAG_NONE;

/** \brief Minimum severity level to record messages.

Expand Down Expand Up @@ -113,4 +114,4 @@ namespace gpgmm::d3d12 {

} // namespace gpgmm::d3d12

#endif // GPGMM_D3D12_EVENTRECORDD3D12_H_
#endif // GPGMM_D3D12_EVENTRECORDD3D12_H_
4 changes: 2 additions & 2 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace gpgmm::d3d12 {
uint64_t GetHeapAlignment(D3D12_HEAP_FLAGS heapFlags, bool allowMSAA) {
const D3D12_HEAP_FLAGS denyAllTexturesFlags =
D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES;
if (Flags(heapFlags).HasFlags(denyAllTexturesFlags)) {
if (HasAllFlags(heapFlags, denyAllTexturesFlags)) {
return D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
}

Expand Down Expand Up @@ -758,7 +758,7 @@ namespace gpgmm::d3d12 {
// Check memory requirements.
bool isAlwaysCommitted = mIsAlwaysCommitted;
D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(resourceHeapType, IsCreateHeapNotResident());
if (!Flags(heapFlags).HasFlags(allocationDescriptor.ExtraRequiredHeapFlags)) {
if (!HasAllFlags(heapFlags, allocationDescriptor.ExtraRequiredHeapFlags)) {
DebugEvent(GetTypename())
<< "Required heap flags are incompatible with resource heap type ("
<< std::to_string(allocationDescriptor.ExtraRequiredHeapFlags) << " vs "
Expand Down
15 changes: 6 additions & 9 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "gpgmm/common/MemoryAllocator.h"
#include "gpgmm/d3d12/EventRecordD3D12.h"
#include "gpgmm/d3d12/IUnknownImplD3D12.h"
#include "gpgmm/utils/Flags.h"
#include "gpgmm/utils/EnumFlags.h"
#include "include/gpgmm_export.h"

#include <array>
Expand Down Expand Up @@ -80,8 +80,7 @@ namespace gpgmm::d3d12 {
ALLOCATOR_FLAG_ALWAYS_ON_DEMAND = 0x8,
};

using ALLOCATOR_FLAGS_TYPE = Flags<ALLOCATOR_FLAGS>;
DEFINE_OPERATORS_FOR_FLAGS(ALLOCATOR_FLAGS_TYPE)
DEFINE_ENUM_FLAG_OPERATORS(ALLOCATOR_FLAGS)

/** \enum ALLOCATOR_ALGORITHM
Specify the algorithms used for allocation.
Expand Down Expand Up @@ -127,8 +126,7 @@ namespace gpgmm::d3d12 {
ALLOCATOR_ALGORITHM_SEGMENTED_POOL = 0x3,
};

using ALLOCATOR_ALGORITHM_TYPE = Flags<ALLOCATOR_ALGORITHM>;
DEFINE_OPERATORS_FOR_FLAGS(ALLOCATOR_ALGORITHM_TYPE)
DEFINE_ENUM_FLAG_OPERATORS(ALLOCATOR_ALGORITHM)

/** \struct ALLOCATOR_DESC
Specify parameters for creating allocators.
Expand All @@ -151,7 +149,7 @@ namespace gpgmm::d3d12 {
For example, whether the allocator can reuse memory, or resources should be resident upon
creation.
*/
ALLOCATOR_FLAGS_TYPE Flags = ALLOCATOR_FLAG_NONE;
ALLOCATOR_FLAGS Flags = ALLOCATOR_FLAG_NONE;

/** \brief Minimum severity level to log messages to console.

Expand Down Expand Up @@ -303,8 +301,7 @@ namespace gpgmm::d3d12 {
ALLOCATION_FLAG_ALWAYS_CACHE_SIZE = 0x10,
};

using ALLOCATION_FLAGS_TYPE = Flags<ALLOCATION_FLAGS>;
DEFINE_OPERATORS_FOR_FLAGS(ALLOCATION_FLAGS_TYPE)
DEFINE_ENUM_FLAG_OPERATORS(ALLOCATION_FLAGS)

/** \struct ALLOCATION_FLAGS
Specifies how allocations should be created.
Expand All @@ -314,7 +311,7 @@ namespace gpgmm::d3d12 {

Optional parameter. By default, GPGMM will decide automatically.
*/
ALLOCATION_FLAGS_TYPE Flags = ALLOCATION_FLAG_NONE;
ALLOCATION_FLAGS Flags = ALLOCATION_FLAG_NONE;

/** \brief Heap type that the resource to be allocated requires.

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/utils/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (is_win || is_linux || is_chromeos || is_mac || is_fuchsia || is_android) {
"Assert.cpp",
"Assert.h",
"Compiler.h",
"Flags.h",
"EnumFlags.h",
"JSONEncoder.cpp",
"JSONEncoder.h",
"Limits.h",
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target_sources(gpgmm_utils PRIVATE
"Assert.cpp"
"Assert.h"
"Compiler.h"
"Flags.h"
"EnumFlags.h"
"JSONEncoder.cpp"
"JSONEncoder.h"
"Limits.h"
Expand Down
93 changes: 93 additions & 0 deletions src/gpgmm/utils/EnumFlags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2021 The GPGMM Authors
//
// 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.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GPGMM_UTILS_ENUMFLAGS_H_
#define GPGMM_UTILS_ENUMFLAGS_H_

#include <cstdint>

namespace gpgmm {

// Returns true if all flags of B are in A.
template <typename EnumFlagsType1, typename EnumFlagsType2>
bool HasAllFlags(const EnumFlagsType1& a, const EnumFlagsType2& b) {
return (a & b) == b;
}

// Define enum-operator overloads to enable bit-wise operations on enum types that are used to
// define flags. Use DEFINE_ENUM_FLAG_OPERATORS(MyType) to enable these operators for MyType.
#ifndef DEFINE_ENUM_FLAG_OPERATORS

template <size_t SizeInBytes>
struct EnumFlagTrait;

template <>
struct EnumFlagTrait<1> {
typedef int8_t SizeType;
};

template <>
struct EnumFlagTrait<2> {
typedef int16_t SizeType;
};

template <>
struct EnumFlagTrait<4> {
typedef int32_t SizeType;
};

template <class EnumFlag>
struct EnumFlagInteger {
typedef typename EnumFlagTrait<sizeof(EnumFlag)>::SizeType SizeType;
};

// Overloaded operations are inline to avoid duplicate symbols from being
// generated and failing to link when using the macro across multiple cpps.
# define DEFINE_ENUM_FLAG_OPERATORS(EnumType) \
inline EnumType operator|(EnumType a, EnumType b) { \
return EnumType((static_cast<EnumFlagInteger<EnumType>::SizeType>(a)) | \
static_cast<EnumFlagInteger<EnumType>::SizeType>(b)); \
} \
inline EnumType& operator|=(EnumType& a, EnumType b) { \
return reinterpret_cast<EnumType&>( \
(reinterpret_cast<EnumFlagInteger<EnumType>::SizeType&>(a)) |= \
(static_cast<EnumFlagInteger<EnumType>::SizeType>(b))); \
} \
inline EnumType operator&(EnumType a, EnumType b) { \
return EnumType((static_cast<EnumFlagInteger<EnumType>::SizeType>(a)) & \
(static_cast<EnumFlagInteger<EnumType>::SizeType>(b))); \
} \
inline EnumType& operator&=(EnumType& a, EnumType b) { \
return reinterpret_cast<EnumType&>( \
(reinterpret_cast<EnumFlagInteger<EnumType>::SizeType&>(a)) &= \
(static_cast<EnumFlagInteger<EnumType>::SizeType>(b))); \
} \
inline EnumType operator~(EnumType a) { \
return EnumType(~(static_cast<EnumFlagInteger<EnumType>::SizeType>(a))); \
} \
inline EnumType operator^(EnumType a, EnumType b) { \
return EnumType((static_cast<EnumFlagInteger<EnumType>::SizeType>(a)) ^ \
(static_cast<EnumFlagInteger<EnumType>::SizeType>(b))); \
} \
inline EnumType& operator^=(EnumType& a, EnumType b) { \
return reinterpret_cast<EnumType&>( \
(reinterpret_cast<EnumFlagInteger<EnumType>::SizeType&>(a)) ^= \
(static_cast<EnumFlagInteger<EnumType>::SizeType>(b))); \
}

#endif // DEFINE_ENUM_FLAG_OPERATORS

} // namespace gpgmm

#endif // GPGMM_UTILS_ENUMFLAGS_H_
165 changes: 0 additions & 165 deletions src/gpgmm/utils/Flags.h

This file was deleted.

1 change: 0 additions & 1 deletion src/gpgmm/vk/ResourceAllocatorVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define GPGMM_VK_RESOURCEALLOCATORVK_H_

#include "gpgmm/common/MemoryAllocator.h"
#include "gpgmm/utils/Flags.h"
#include "gpgmm/vk/FunctionsVk.h"
#include "include/gpgmm_export.h"

Expand Down
Loading