Namespace dawn/common/ and dawn/utils/ in dawn::

Only Constants.h remains in no namespace; but it may be addressed
in the future as well.

Bug: dawn:302
Change-Id: Ib9b9ab4b974ad1de1bb9f2302f4d24d8216f55e4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132841
Kokoro: Austin Eng <enga@chromium.org>
Auto-Submit: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2023-05-17 18:41:02 +00:00 committed by Dawn LUCI CQ
parent 0bb1bb3067
commit 2731b76ded
302 changed files with 2225 additions and 1255 deletions

View File

@ -21,7 +21,7 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace gpu_info { namespace dawn::gpu_info {
namespace { namespace {
@ -151,4 +151,4 @@ std::string GetArchitectureName(PCIVendorID vendorId, PCIDeviceID deviceId) {
return ""; return "";
} }
} // namespace gpu_info } // namespace dawn::gpu_info

View File

@ -21,7 +21,7 @@
using PCIVendorID = uint32_t; using PCIVendorID = uint32_t;
using PCIDeviceID = uint32_t; using PCIDeviceID = uint32_t;
namespace gpu_info { namespace dawn::gpu_info {
// Vendor IDs // Vendor IDs
{% for vendor in vendors %} {% for vendor in vendors %}
@ -51,5 +51,5 @@ namespace gpu_info {
std::string GetVendorName(PCIVendorID vendorId); std::string GetVendorName(PCIVendorID vendorId);
std::string GetArchitectureName(PCIVendorID vendorId, PCIDeviceID deviceId); std::string GetArchitectureName(PCIVendorID vendorId, PCIDeviceID deviceId);
} // namespace gpu_info } // namespace dawn::gpu_info
#endif // SRC_DAWN_COMMON_GPUINFO_AUTOGEN_H_ #endif // SRC_DAWN_COMMON_GPUINFO_AUTOGEN_H_

View File

@ -18,6 +18,8 @@
#include <cstddef> #include <cstddef>
#include <new> #include <new>
namespace dawn {
template <typename T> template <typename T>
T* AllocNoThrow(size_t count) { T* AllocNoThrow(size_t count) {
#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER)
@ -30,4 +32,6 @@ T* AllocNoThrow(size_t count) {
return new (std::nothrow) T[count]; return new (std::nothrow) T[count];
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_ALLOC_H_ #endif // SRC_DAWN_COMMON_ALLOC_H_

View File

@ -19,6 +19,12 @@
#include "dawn/common/Log.h" #include "dawn/common/Log.h"
#include "dawn/common/Platform.h" #include "dawn/common/Platform.h"
#if DAWN_COMPILER_IS(MSVC)
extern void __cdecl __debugbreak(void);
#endif
namespace dawn {
#if DAWN_COMPILER_IS(CLANG) || DAWN_COMPILER_IS(GCC) #if DAWN_COMPILER_IS(CLANG) || DAWN_COMPILER_IS(GCC)
void BreakPoint() { void BreakPoint() {
#if DAWN_PLATFORM_IS(X86) #if DAWN_PLATFORM_IS(X86)
@ -43,7 +49,6 @@ void BreakPoint() {
} }
#elif DAWN_COMPILER_IS(MSVC) #elif DAWN_COMPILER_IS(MSVC)
extern void __cdecl __debugbreak(void);
void BreakPoint() { void BreakPoint() {
__debugbreak(); __debugbreak();
} }
@ -64,3 +69,5 @@ void HandleAssertionFailure(const char* file,
BreakPoint(); BreakPoint();
#endif #endif
} }
} // namespace dawn

View File

@ -41,11 +41,11 @@
// expect of an assert and in release it tries to give hints to make the compiler generate better // expect of an assert and in release it tries to give hints to make the compiler generate better
// code. // code.
#if defined(DAWN_ENABLE_ASSERTS) #if defined(DAWN_ENABLE_ASSERTS)
#define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) \ #define DAWN_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
do { \ do { \
if (!(condition)) { \ if (!(condition)) { \
HandleAssertionFailure(file, func, line, #condition); \ dawn::HandleAssertionFailure(file, func, line, #condition); \
} \ } \
} while (DAWN_ASSERT_LOOP_CONDITION) } while (DAWN_ASSERT_LOOP_CONDITION)
#else #else
#if DAWN_COMPILER_IS(MSVC) #if DAWN_COMPILER_IS(MSVC)
@ -72,9 +72,13 @@
#define UNREACHABLE DAWN_UNREACHABLE #define UNREACHABLE DAWN_UNREACHABLE
#endif #endif
namespace dawn {
void HandleAssertionFailure(const char* file, void HandleAssertionFailure(const char* file,
const char* function, const char* function,
int line, int line,
const char* condition); const char* condition);
} // namespace dawn
#endif // SRC_DAWN_COMMON_ASSERT_H_ #endif // SRC_DAWN_COMMON_ASSERT_H_

View File

@ -22,6 +22,8 @@
#include "dawn/common/Math.h" #include "dawn/common/Math.h"
#include "dawn/common/UnderlyingType.h" #include "dawn/common/UnderlyingType.h"
namespace dawn {
// This is ANGLE's BitSetIterator class with a customizable return type. // This is ANGLE's BitSetIterator class with a customizable return type.
// Types have been updated to be more specific. // Types have been updated to be more specific.
// TODO(crbug.com/dawn/306): it could be optimized, in particular when N <= 64 // TODO(crbug.com/dawn/306): it could be optimized, in particular when N <= 64
@ -131,4 +133,6 @@ BitSetIterator<N, uint32_t> IterateBitSet(const std::bitset<N>& bitset) {
return BitSetIterator<N, uint32_t>(bitset); return BitSetIterator<N, uint32_t>(bitset);
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_BITSETITERATOR_H_ #endif // SRC_DAWN_COMMON_BITSETITERATOR_H_

View File

@ -21,6 +21,8 @@
#include "dawn/common/NonCopyable.h" #include "dawn/common/NonCopyable.h"
namespace dawn {
template <typename T> template <typename T>
class ConcurrentCache : public NonMovable { class ConcurrentCache : public NonMovable {
public: public:
@ -51,4 +53,6 @@ class ConcurrentCache : public NonMovable {
std::unordered_set<T*, typename T::HashFunc, typename T::EqualityFunc> mCache; std::unordered_set<T*, typename T::HashFunc, typename T::EqualityFunc> mCache;
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_CONCURRENTCACHE_H_ #endif // SRC_DAWN_COMMON_CONCURRENTCACHE_H_

View File

@ -19,6 +19,8 @@
#include "dawn/common/RefBase.h" #include "dawn/common/RefBase.h"
namespace dawn {
template <typename T> template <typename T>
struct CoreFoundationRefTraits { struct CoreFoundationRefTraits {
static constexpr T kNullValue = nullptr; static constexpr T kNullValue = nullptr;
@ -39,4 +41,6 @@ CFRef<T> AcquireCFRef(T pointee) {
return ref; return ref;
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_COREFOUNDATIONREF_H_ #endif // SRC_DAWN_COMMON_COREFOUNDATIONREF_H_

View File

@ -18,6 +18,8 @@
#include "dawn/common/Platform.h" #include "dawn/common/Platform.h"
namespace dawn {
#if DAWN_PLATFORM_IS(WINDOWS) #if DAWN_PLATFORM_IS(WINDOWS)
#include "dawn/common/windows_with_undefs.h" #include "dawn/common/windows_with_undefs.h"
#if DAWN_PLATFORM_IS(WINUWP) #if DAWN_PLATFORM_IS(WINUWP)
@ -106,3 +108,5 @@ void* DynamicLib::GetProc(const std::string& procName, std::string* error) const
return proc; return proc;
} }
} // namespace dawn

View File

@ -20,6 +20,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace dawn {
class DynamicLib { class DynamicLib {
public: public:
DynamicLib() = default; DynamicLib() = default;
@ -51,4 +53,6 @@ class DynamicLib {
void* mHandle = nullptr; void* mHandle = nullptr;
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_DYNAMICLIB_H_ #endif // SRC_DAWN_COMMON_DYNAMICLIB_H_

View File

@ -21,7 +21,7 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace gpu_info { namespace dawn::gpu_info {
namespace { namespace {
// Intel // Intel
// Referenced from the following Mesa source code: // Referenced from the following Mesa source code:
@ -105,4 +105,4 @@ bool IsSkylake(PCIDeviceID deviceId) {
return std::find(Skylake.cbegin(), Skylake.cend(), deviceId) != Skylake.cend(); return std::find(Skylake.cbegin(), Skylake.cend(), deviceId) != Skylake.cend();
} }
} // namespace gpu_info } // namespace dawn::gpu_info

View File

@ -20,7 +20,7 @@
#include "dawn/common/GPUInfo_autogen.h" #include "dawn/common/GPUInfo_autogen.h"
#include "dawn/common/StackContainer.h" #include "dawn/common/StackContainer.h"
namespace gpu_info { namespace dawn::gpu_info {
// Four uint16 fields could cover almost all driver version schemas: // Four uint16 fields could cover almost all driver version schemas:
// D3D12: AA.BB.CCC.DDDD // D3D12: AA.BB.CCC.DDDD
@ -61,5 +61,5 @@ int CompareIntelMesaDriverVersion(const DriverVersion& version1, const DriverVer
// Intel architectures // Intel architectures
bool IsSkylake(PCIDeviceID deviceId); bool IsSkylake(PCIDeviceID deviceId);
} // namespace gpu_info } // namespace dawn::gpu_info
#endif // SRC_DAWN_COMMON_GPUINFO_H_ #endif // SRC_DAWN_COMMON_GPUINFO_H_

View File

@ -22,6 +22,8 @@
#include "dawn/common/TypedInteger.h" #include "dawn/common/TypedInteger.h"
#include "dawn/common/ityp_bitset.h" #include "dawn/common/ityp_bitset.h"
namespace dawn {
// Wrapper around std::hash to make it a templated function instead of a functor. It is marginally // Wrapper around std::hash to make it a templated function instead of a functor. It is marginally
// nicer, and avoids adding to the std namespace to add hashing of other types. // nicer, and avoids adding to the std namespace to add hashing of other types.
template <typename T> template <typename T>
@ -88,12 +90,14 @@ size_t Hash(const std::bitset<N>& value) {
} }
#endif #endif
} // namespace dawn
namespace std { namespace std {
template <typename Index, size_t N> template <typename Index, size_t N>
struct hash<ityp::bitset<Index, N>> { struct hash<dawn::ityp::bitset<Index, N>> {
public: public:
size_t operator()(const ityp::bitset<Index, N>& value) const { size_t operator()(const dawn::ityp::bitset<Index, N>& value) const {
return Hash(static_cast<const std::bitset<N>&>(value)); return dawn::Hash(static_cast<const std::bitset<N>&>(value));
} }
}; };
} // namespace std } // namespace std

View File

@ -19,6 +19,8 @@
#include "dawn/common/RefBase.h" #include "dawn/common/RefBase.h"
namespace dawn {
template <typename T> template <typename T>
struct IOKitRefTraits { struct IOKitRefTraits {
static constexpr T kNullValue = IO_OBJECT_NULL; static constexpr T kNullValue = IO_OBJECT_NULL;
@ -39,4 +41,6 @@ IORef<T> AcquireIORef(T pointee) {
return ref; return ref;
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_IOKITREF_H_ #endif // SRC_DAWN_COMMON_IOKITREF_H_

View File

@ -13,6 +13,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace dawn {
// Simple LinkedList type. (See the Q&A section to understand how this // Simple LinkedList type. (See the Q&A section to understand how this
// differs from std::list). // differs from std::list).
// //
@ -247,4 +249,6 @@ LinkedListIterator<T> end(LinkedList<T>& l) {
return LinkedListIterator<T>(l.tail()->next()); return LinkedListIterator<T>(l.tail()->next());
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_LINKEDLIST_H_ #endif // SRC_DAWN_COMMON_LINKEDLIST_H_

View File

@ -25,6 +25,8 @@
#include <intrin.h> #include <intrin.h>
#endif #endif
namespace dawn {
uint32_t ScanForward(uint32_t bits) { uint32_t ScanForward(uint32_t bits) {
ASSERT(bits != 0); ASSERT(bits != 0);
#if DAWN_COMPILER_IS(MSVC) #if DAWN_COMPILER_IS(MSVC)
@ -162,3 +164,5 @@ uint64_t RoundUp(uint64_t n, uint64_t m) {
ASSERT(m <= std::numeric_limits<uint64_t>::max() - n); ASSERT(m <= std::numeric_limits<uint64_t>::max() - n);
return ((n + m - 1) / m) * m; return ((n + m - 1) / m) * m;
} }
} // namespace dawn

View File

@ -25,6 +25,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace dawn {
// The following are not valid for 0 // The following are not valid for 0
uint32_t ScanForward(uint32_t bits); uint32_t ScanForward(uint32_t bits);
uint32_t Log2(uint32_t value); uint32_t Log2(uint32_t value);
@ -125,4 +127,6 @@ constexpr bool IsSubset(T1 subset, T2 set) {
return bitsAlsoInSet == subset; return bitsAlsoInSet == subset;
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_MATH_H_ #endif // SRC_DAWN_COMMON_MATH_H_

View File

@ -23,6 +23,8 @@
#error "NSRef can only be used in Objective C/C++ code." #error "NSRef can only be used in Objective C/C++ code."
#endif #endif
namespace dawn {
// This file contains smart pointers that automatically reference and release Objective C objects // This file contains smart pointers that automatically reference and release Objective C objects
// and prototocals in a manner very similar to Ref<>. Note that NSRef<> and NSPRef's constructor add // and prototocals in a manner very similar to Ref<>. Note that NSRef<> and NSPRef's constructor add
// a reference to the object by default, so the pattern to get a reference for a newly created // a reference to the object by default, so the pattern to get a reference for a newly created
@ -108,4 +110,6 @@ NSPRef<T> AcquireNSPRef(T pointee) {
return ref; return ref;
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_NSREF_H_ #endif // SRC_DAWN_COMMON_NSREF_H_

View File

@ -15,6 +15,8 @@
#ifndef SRC_DAWN_COMMON_NONCOPYABLE_H_ #ifndef SRC_DAWN_COMMON_NONCOPYABLE_H_
#define SRC_DAWN_COMMON_NONCOPYABLE_H_ #define SRC_DAWN_COMMON_NONCOPYABLE_H_
namespace dawn {
// A base class to make a class non-copyable. // A base class to make a class non-copyable.
class NonCopyable { class NonCopyable {
protected: protected:
@ -40,4 +42,6 @@ class NonMovable : NonCopyable {
void operator=(NonMovable&&) = delete; void operator=(NonMovable&&) = delete;
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_NONCOPYABLE_H_ #endif // SRC_DAWN_COMMON_NONCOPYABLE_H_

View File

@ -21,6 +21,7 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace dawn {
namespace detail { namespace detail {
template <typename T> template <typename T>
@ -81,4 +82,6 @@ bool RangesOverlap(T x0, T x1, T y0, T y1) {
} }
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_NUMERIC_H_ #endif // SRC_DAWN_COMMON_NUMERIC_H_

View File

@ -17,6 +17,8 @@
#include <cstddef> #include <cstddef>
namespace dawn {
class PlacementAllocated { class PlacementAllocated {
public: public:
// Delete the default new operator so this can only be created with placement new. // Delete the default new operator so this can only be created with placement new.
@ -39,4 +41,6 @@ class PlacementAllocated {
} }
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_PLACEMENTALLOCATED_H_ #endif // SRC_DAWN_COMMON_PLACEMENTALLOCATED_H_

View File

@ -21,6 +21,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
#include "dawn/common/Compiler.h" #include "dawn/common/Compiler.h"
namespace dawn {
// A common class for various smart-pointers acting on referenceable/releasable pointer-like // A common class for various smart-pointers acting on referenceable/releasable pointer-like
// objects. Logic for each specialization can be customized using a Traits type that looks // objects. Logic for each specialization can be customized using a Traits type that looks
// like the following: // like the following:
@ -162,4 +164,6 @@ class RefBase {
T mValue; T mValue;
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_REFBASE_H_ #endif // SRC_DAWN_COMMON_REFBASE_H_

View File

@ -23,6 +23,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace dawn {
static constexpr size_t kPayloadBits = 1; static constexpr size_t kPayloadBits = 1;
static constexpr uint64_t kPayloadMask = (uint64_t(1) << kPayloadBits) - 1; static constexpr uint64_t kPayloadMask = (uint64_t(1) << kPayloadBits) - 1;
static constexpr uint64_t kRefCountIncrement = (uint64_t(1) << kPayloadBits); static constexpr uint64_t kRefCountIncrement = (uint64_t(1) << kPayloadBits);
@ -121,3 +123,5 @@ void RefCounted::DeleteThis() {
void RefCounted::LockAndDeleteThis() { void RefCounted::LockAndDeleteThis() {
DeleteThis(); DeleteThis();
} }
} // namespace dawn

View File

@ -20,6 +20,8 @@
#include "dawn/common/RefBase.h" #include "dawn/common/RefBase.h"
namespace dawn {
class RefCount { class RefCount {
public: public:
// Create a refcount with a payload. The refcount starts initially at one. // Create a refcount with a payload. The refcount starts initially at one.
@ -88,4 +90,6 @@ Ref<T> AcquireRef(T* pointee) {
return ref; return ref;
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_REFCOUNTED_H_ #endif // SRC_DAWN_COMMON_REFCOUNTED_H_

View File

@ -14,6 +14,8 @@
#include "dawn/common/Result.h" #include "dawn/common/Result.h"
namespace dawn {
// Implementation details of the tagged pointer Results // Implementation details of the tagged pointer Results
namespace detail { namespace detail {
@ -28,3 +30,4 @@ PayloadType GetPayloadType(intptr_t payload) {
} }
} // namespace detail } // namespace detail
} // namespace dawn

View File

@ -24,6 +24,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
#include "dawn/common/Compiler.h" #include "dawn/common/Compiler.h"
namespace dawn {
// Result<T, E> is the following sum type (Haskell notation): // Result<T, E> is the following sum type (Haskell notation):
// //
// data Result T E = Success T | Error E | Empty // data Result T E = Success T | Error E | Empty
@ -511,4 +513,6 @@ std::unique_ptr<E> Result<T, E>::AcquireError() {
return std::move(mError); return std::move(mError);
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_RESULT_H_ #endif // SRC_DAWN_COMMON_RESULT_H_

View File

@ -21,6 +21,8 @@
#include "dawn/common/SerialStorage.h" #include "dawn/common/SerialStorage.h"
namespace dawn {
template <typename Serial, typename Value> template <typename Serial, typename Value>
class SerialMap; class SerialMap;
@ -74,4 +76,6 @@ void SerialMap<Serial, Value>::Enqueue(std::vector<Value>&& values, Serial seria
} }
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_SERIALMAP_H_ #endif // SRC_DAWN_COMMON_SERIALMAP_H_

View File

@ -20,6 +20,8 @@
#include "dawn/common/SerialStorage.h" #include "dawn/common/SerialStorage.h"
namespace dawn {
template <typename Serial, typename Value> template <typename Serial, typename Value>
class SerialQueue; class SerialQueue;
@ -83,4 +85,6 @@ void SerialQueue<Serial, Value>::Enqueue(std::vector<Value>&& values, Serial ser
this->mStorage.emplace_back(serial, std::move(values)); this->mStorage.emplace_back(serial, std::move(values));
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_SERIALQUEUE_H_ #endif // SRC_DAWN_COMMON_SERIALQUEUE_H_

View File

@ -20,6 +20,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
namespace dawn {
template <typename T> template <typename T>
struct SerialStorageTraits {}; struct SerialStorageTraits {};
@ -315,4 +317,6 @@ const typename SerialStorage<Derived>::Value& SerialStorage<Derived>::ConstItera
return *mSerialIterator; return *mSerialIterator;
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_SERIALSTORAGE_H_ #endif // SRC_DAWN_COMMON_SERIALSTORAGE_H_

View File

@ -22,6 +22,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
#include "dawn/common/Math.h" #include "dawn/common/Math.h"
namespace dawn {
// IndexLinkNode // IndexLinkNode
SlabAllocatorImpl::IndexLinkNode::IndexLinkNode(Index index, Index nextIndex) SlabAllocatorImpl::IndexLinkNode::IndexLinkNode(Index index, Index nextIndex)
@ -241,3 +243,5 @@ void SlabAllocatorImpl::GetNewSlab() {
mAvailableSlabs.Prepend(new (alignedPtr) Slab(allocation, node)); mAvailableSlabs.Prepend(new (alignedPtr) Slab(allocation, node));
} }
} // namespace dawn

View File

@ -22,6 +22,8 @@
#include "dawn/common/Numeric.h" #include "dawn/common/Numeric.h"
#include "dawn/common/PlacementAllocated.h" #include "dawn/common/PlacementAllocated.h"
namespace dawn {
// The SlabAllocator allocates objects out of one or more fixed-size contiguous "slabs" of memory. // The SlabAllocator allocates objects out of one or more fixed-size contiguous "slabs" of memory.
// This makes it very quick to allocate and deallocate fixed-size objects because the allocator only // This makes it very quick to allocate and deallocate fixed-size objects because the allocator only
// needs to index an offset into pre-allocated memory. It is similar to a pool-allocator that // needs to index an offset into pre-allocated memory. It is similar to a pool-allocator that
@ -179,4 +181,6 @@ class SlabAllocator : public SlabAllocatorImpl {
void Deallocate(T* object) { SlabAllocatorImpl::Deallocate(object); } void Deallocate(T* object) { SlabAllocatorImpl::Deallocate(object); }
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_SLABALLOCATOR_H_ #endif // SRC_DAWN_COMMON_SLABALLOCATOR_H_

View File

@ -13,6 +13,8 @@
#include "dawn/common/Compiler.h" #include "dawn/common/Compiler.h"
namespace dawn {
// This allocator can be used with STL containers to provide a stack buffer // This allocator can be used with STL containers to provide a stack buffer
// from which to allocate memory and overflows onto the heap. This stack buffer // from which to allocate memory and overflows onto the heap. This stack buffer
// would be allocated on the stack and allows us to avoid heap operations in // would be allocated on the stack and allows us to avoid heap operations in
@ -235,4 +237,6 @@ class StackVector
StackVector& operator=(StackVector&& rhs) = delete; StackVector& operator=(StackVector&& rhs) = delete;
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_STACKCONTAINER_H_ #endif // SRC_DAWN_COMMON_STACKCONTAINER_H_

View File

@ -33,6 +33,8 @@
#include <array> #include <array>
namespace dawn {
#if DAWN_PLATFORM_IS(WINDOWS) #if DAWN_PLATFORM_IS(WINDOWS)
const char* GetPathSeparator() { const char* GetPathSeparator() {
return "\\"; return "\\";
@ -228,3 +230,5 @@ bool ScopedEnvironmentVar::Set(const char* variableName, const char* value) {
mIsSet = SetEnvironmentVar(variableName, value); mIsSet = SetEnvironmentVar(variableName, value);
return mIsSet; return mIsSet;
} }
} // namespace dawn

View File

@ -21,6 +21,8 @@
#include "dawn/common/Platform.h" #include "dawn/common/Platform.h"
namespace dawn {
const char* GetPathSeparator(); const char* GetPathSeparator();
// Returns a pair of the environment variable's value, and a boolean indicating whether the variable // Returns a pair of the environment variable's value, and a boolean indicating whether the variable
// was present. // was present.
@ -55,4 +57,6 @@ class ScopedEnvironmentVar {
bool mIsSet = false; bool mIsSet = false;
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_SYSTEMUTILS_H_ #endif // SRC_DAWN_COMMON_SYSTEMUTILS_H_

View File

@ -18,6 +18,8 @@
#import <Foundation/NSProcessInfo.h> #import <Foundation/NSProcessInfo.h>
namespace dawn {
void GetMacOSVersion(int32_t* majorVersion, int32_t* minorVersion) { void GetMacOSVersion(int32_t* majorVersion, int32_t* minorVersion) {
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
ASSERT(majorVersion != nullptr); ASSERT(majorVersion != nullptr);
@ -31,3 +33,5 @@ bool IsMacOSVersionAtLeast(uint32_t majorVersion, uint32_t minorVersion) {
return return
[NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:{majorVersion, minorVersion, 0}]; [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:{majorVersion, minorVersion, 0}];
} }
} // namespace dawn

View File

@ -17,6 +17,8 @@
#include <type_traits> #include <type_traits>
namespace dawn {
template <typename LHS, typename RHS = LHS, typename T = void> template <typename LHS, typename RHS = LHS, typename T = void>
struct HasEqualityOperator { struct HasEqualityOperator {
static constexpr const bool value = false; static constexpr const bool value = false;
@ -43,4 +45,6 @@ struct IsCString {
static constexpr const bool value = Eval(); static constexpr const bool value = Eval();
}; };
} // namespace dawn
#endif // SRC_DAWN_COMMON_TYPETRAITS_H_ #endif // SRC_DAWN_COMMON_TYPETRAITS_H_

View File

@ -21,6 +21,8 @@
#include "dawn/common/Assert.h" #include "dawn/common/Assert.h"
#include "dawn/common/UnderlyingType.h" #include "dawn/common/UnderlyingType.h"
namespace dawn {
// TypedInteger is helper class that provides additional type safety in Debug. // TypedInteger is helper class that provides additional type safety in Debug.
// - Integers of different (Tag, BaseIntegerType) may not be used interoperably // - Integers of different (Tag, BaseIntegerType) may not be used interoperably
// - Allows casts only to the underlying type. // - Allows casts only to the underlying type.
@ -31,8 +33,8 @@
// typedef of the underlying type. // typedef of the underlying type.
// //
// Example: // Example:
// using UintA = TypedInteger<struct TypeA, uint32_t>; // using UintA = dawn::TypedInteger<struct TypeA, uint32_t>;
// using UintB = TypedInteger<struct TypeB, uint32_t>; // using UintB = dawn::TypedInteger<struct TypeB, uint32_t>;
// //
// in Release: // in Release:
// using UintA = uint32_t; // using UintA = uint32_t;
@ -208,23 +210,24 @@ class alignas(T) TypedIntegerImpl {
}; };
} // namespace detail } // namespace detail
} // namespace dawn
namespace std { namespace std {
template <typename Tag, typename T> template <typename Tag, typename T>
class numeric_limits<detail::TypedIntegerImpl<Tag, T>> : public numeric_limits<T> { class numeric_limits<dawn::detail::TypedIntegerImpl<Tag, T>> : public numeric_limits<T> {
public: public:
static detail::TypedIntegerImpl<Tag, T> max() noexcept { static dawn::detail::TypedIntegerImpl<Tag, T> max() noexcept {
return detail::TypedIntegerImpl<Tag, T>(std::numeric_limits<T>::max()); return dawn::detail::TypedIntegerImpl<Tag, T>(std::numeric_limits<T>::max());
} }
static detail::TypedIntegerImpl<Tag, T> min() noexcept { static dawn::detail::TypedIntegerImpl<Tag, T> min() noexcept {
return detail::TypedIntegerImpl<Tag, T>(std::numeric_limits<T>::min()); return dawn::detail::TypedIntegerImpl<Tag, T>(std::numeric_limits<T>::min());
} }
}; };
} // namespace std } // namespace std
namespace ityp { namespace dawn::ityp {
// These helpers below are provided since the default arithmetic operators for small integer // These helpers below are provided since the default arithmetic operators for small integer
// types like uint8_t and uint16_t return integers, not their same type. To avoid lots of // types like uint8_t and uint16_t return integers, not their same type. To avoid lots of
@ -232,17 +235,19 @@ namespace ityp {
// ityp::Sub(a, b) instead. // ityp::Sub(a, b) instead.
template <typename Tag, typename T> template <typename Tag, typename T>
constexpr ::detail::TypedIntegerImpl<Tag, T> Add(::detail::TypedIntegerImpl<Tag, T> lhs, constexpr ::dawn::detail::TypedIntegerImpl<Tag, T> Add(
::detail::TypedIntegerImpl<Tag, T> rhs) { ::dawn::detail::TypedIntegerImpl<Tag, T> lhs,
return ::detail::TypedIntegerImpl<Tag, T>( ::dawn::detail::TypedIntegerImpl<Tag, T> rhs) {
static_cast<T>(::detail::TypedIntegerImpl<Tag, T>::AddImpl(lhs, rhs))); return ::dawn::detail::TypedIntegerImpl<Tag, T>(
static_cast<T>(::dawn::detail::TypedIntegerImpl<Tag, T>::AddImpl(lhs, rhs)));
} }
template <typename Tag, typename T> template <typename Tag, typename T>
constexpr ::detail::TypedIntegerImpl<Tag, T> Sub(::detail::TypedIntegerImpl<Tag, T> lhs, constexpr ::dawn::detail::TypedIntegerImpl<Tag, T> Sub(
::detail::TypedIntegerImpl<Tag, T> rhs) { ::dawn::detail::TypedIntegerImpl<Tag, T> lhs,
return ::detail::TypedIntegerImpl<Tag, T>( ::dawn::detail::TypedIntegerImpl<Tag, T> rhs) {
static_cast<T>(::detail::TypedIntegerImpl<Tag, T>::SubImpl(lhs, rhs))); return ::dawn::detail::TypedIntegerImpl<Tag, T>(
static_cast<T>(::dawn::detail::TypedIntegerImpl<Tag, T>::SubImpl(lhs, rhs)));
} }
template <typename T> template <typename T>
@ -255,6 +260,6 @@ constexpr std::enable_if_t<std::is_integral<T>::value, T> Sub(T lhs, T rhs) {
return static_cast<T>(lhs - rhs); return static_cast<T>(lhs - rhs);
} }
} // namespace ityp } // namespace dawn::ityp
#endif // SRC_DAWN_COMMON_TYPEDINTEGER_H_ #endif // SRC_DAWN_COMMON_TYPEDINTEGER_H_

View File

@ -17,6 +17,8 @@
#include <type_traits> #include <type_traits>
namespace dawn {
// UnderlyingType is similar to std::underlying_type_t. It is a passthrough for already // UnderlyingType is similar to std::underlying_type_t. It is a passthrough for already
// integer types which simplifies getting the underlying primitive type for an arbitrary // integer types which simplifies getting the underlying primitive type for an arbitrary
// template parameter. It includes a specialization for detail::TypedIntegerImpl which yields // template parameter. It includes a specialization for detail::TypedIntegerImpl which yields
@ -48,4 +50,6 @@ struct UnderlyingTypeImpl<TypedIntegerImpl<Tag, I>> {
template <typename T> template <typename T>
using UnderlyingType = typename detail::UnderlyingTypeImpl<T>::type; using UnderlyingType = typename detail::UnderlyingTypeImpl<T>::type;
} // namespace dawn
#endif // SRC_DAWN_COMMON_UNDERLYINGTYPE_H_ #endif // SRC_DAWN_COMMON_UNDERLYINGTYPE_H_

View File

@ -18,6 +18,8 @@
#include "dawn/common/windows_with_undefs.h" #include "dawn/common/windows_with_undefs.h"
namespace dawn {
std::string WCharToUTF8(const wchar_t* input) { std::string WCharToUTF8(const wchar_t* input) {
// The -1 argument asks WideCharToMultiByte to use the null terminator to know the size of // The -1 argument asks WideCharToMultiByte to use the null terminator to know the size of
// input. It will return a size that includes the null terminator. // input. It will return a size that includes the null terminator.
@ -41,3 +43,5 @@ std::wstring UTF8ToWStr(const char* input) {
return result; return result;
} }
} // namespace dawn

View File

@ -17,8 +17,12 @@
#include <string> #include <string>
namespace dawn {
std::string WCharToUTF8(const wchar_t* input); std::string WCharToUTF8(const wchar_t* input);
std::wstring UTF8ToWStr(const char* input); std::wstring UTF8ToWStr(const char* input);
} // namespace dawn
#endif // SRC_DAWN_COMMON_WINDOWSUTILS_H_ #endif // SRC_DAWN_COMMON_WINDOWSUTILS_H_

View File

@ -24,16 +24,16 @@
#include "dawn/common/TypedInteger.h" #include "dawn/common/TypedInteger.h"
#include "dawn/common/UnderlyingType.h" #include "dawn/common/UnderlyingType.h"
namespace ityp { namespace dawn::ityp {
// ityp::array is a helper class that wraps std::array with the restriction that // ityp::array is a helper class that wraps std::array with the restriction that
// indices must be a particular type |Index|. Dawn uses multiple flat maps of // indices must be a particular type |Index|. Dawn uses multiple flat maps of
// index-->data, and this class helps ensure an indices cannot be passed interchangably // index-->data, and this class helps ensure an indices cannot be passed interchangably
// to a flat map of a different type. // to a flat map of a different type.
template <typename Index, typename Value, size_t Size> template <typename Index, typename Value, size_t Size>
class array : private std::array<Value, Size> { class array : private ::std::array<Value, Size> {
using I = UnderlyingType<Index>; using I = UnderlyingType<Index>;
using Base = std::array<Value, Size>; using Base = ::std::array<Value, Size>;
static_assert(Size <= std::numeric_limits<I>::max()); static_assert(Size <= std::numeric_limits<I>::max());
@ -85,6 +85,6 @@ class array : private std::array<Value, Size> {
using Base::front; using Base::front;
}; };
} // namespace ityp } // namespace dawn::ityp
#endif // SRC_DAWN_COMMON_ITYP_ARRAY_H_ #endif // SRC_DAWN_COMMON_ITYP_ARRAY_H_

View File

@ -20,14 +20,15 @@
#include "dawn/common/TypedInteger.h" #include "dawn/common/TypedInteger.h"
#include "dawn/common/UnderlyingType.h" #include "dawn/common/UnderlyingType.h"
namespace dawn {
namespace ityp { namespace ityp {
// ityp::bitset is a helper class that wraps std::bitset with the restriction that // ityp::bitset is a helper class that wraps std::bitset with the restriction that
// indices must be a particular type |Index|. // indices must be a particular type |Index|.
template <typename Index, size_t N> template <typename Index, size_t N>
class bitset : private std::bitset<N> { class bitset : private ::std::bitset<N> {
using I = UnderlyingType<Index>; using I = UnderlyingType<Index>;
using Base = std::bitset<N>; using Base = ::std::bitset<N>;
static_assert(sizeof(I) <= sizeof(size_t)); static_assert(sizeof(I) <= sizeof(size_t));
@ -168,4 +169,6 @@ Index GetHighestBitIndexPlusOne(const ityp::bitset<Index, N>& bitset) {
#endif // DAWN_COMPILER_IS(MSVC) #endif // DAWN_COMPILER_IS(MSVC)
} }
} // namespace dawn
#endif // SRC_DAWN_COMMON_ITYP_BITSET_H_ #endif // SRC_DAWN_COMMON_ITYP_BITSET_H_

View File

@ -20,7 +20,7 @@
#include "dawn/common/TypedInteger.h" #include "dawn/common/TypedInteger.h"
#include "dawn/common/UnderlyingType.h" #include "dawn/common/UnderlyingType.h"
namespace ityp { namespace dawn::ityp {
// ityp::span is a helper class that wraps an unowned packed array of type |Value|. // ityp::span is a helper class that wraps an unowned packed array of type |Value|.
// It stores the size and pointer to first element. It has the restriction that // It stores the size and pointer to first element. It has the restriction that
@ -82,6 +82,6 @@ class span {
Index mSize; Index mSize;
}; };
} // namespace ityp } // namespace dawn::ityp
#endif // SRC_DAWN_COMMON_ITYP_SPAN_H_ #endif // SRC_DAWN_COMMON_ITYP_SPAN_H_

View File

@ -22,7 +22,7 @@
#include "dawn/common/StackContainer.h" #include "dawn/common/StackContainer.h"
#include "dawn/common/UnderlyingType.h" #include "dawn/common/UnderlyingType.h"
namespace ityp { namespace dawn::ityp {
template <typename Index, typename Value, size_t StaticCapacity> template <typename Index, typename Value, size_t StaticCapacity>
class stack_vec : private StackVector<Value, StaticCapacity> { class stack_vec : private StackVector<Value, StaticCapacity> {
@ -72,6 +72,6 @@ class stack_vec : private StackVector<Value, StaticCapacity> {
Index size() const { return Index(static_cast<I>(this->container().size())); } Index size() const { return Index(static_cast<I>(this->container().size())); }
}; };
} // namespace ityp } // namespace dawn::ityp
#endif // SRC_DAWN_COMMON_ITYP_STACK_VEC_H_ #endif // SRC_DAWN_COMMON_ITYP_STACK_VEC_H_

View File

@ -22,7 +22,7 @@
#include "dawn/common/TypedInteger.h" #include "dawn/common/TypedInteger.h"
#include "dawn/common/UnderlyingType.h" #include "dawn/common/UnderlyingType.h"
namespace ityp { namespace dawn::ityp {
// ityp::vector is a helper class that wraps std::vector with the restriction that // ityp::vector is a helper class that wraps std::vector with the restriction that
// indices must be a particular type |Index|. // indices must be a particular type |Index|.
@ -94,6 +94,6 @@ class vector : public std::vector<Value> {
void reserve(Index size) { Base::reserve(static_cast<I>(size)); } void reserve(Index size) { Base::reserve(static_cast<I>(size)); }
}; };
} // namespace ityp } // namespace dawn::ityp
#endif // SRC_DAWN_COMMON_ITYP_VECTOR_H_ #endif // SRC_DAWN_COMMON_ITYP_VECTOR_H_

View File

@ -30,7 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
wgpu::AdapterProperties properties; wgpu::AdapterProperties properties;
adapter.GetProperties(&properties); adapter.GetProperties(&properties);
return gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID); return dawn::gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
}, },
true /* supportsErrorInjection */); true /* supportsErrorInjection */);
} }

View File

@ -102,7 +102,8 @@ int Run(const fuzzing::Program& program, bool (*AdapterSupported)(const dawn::na
std::unique_ptr<dawn::wire::WireServer> wireServer(new dawn_wire::WireServer(serverDesc)); std::unique_ptr<dawn::wire::WireServer> wireServer(new dawn_wire::WireServer(serverDesc));
wireServer->InjectInstance(sInstance->Get(), kInstanceObjectId, 0); wireServer->InjectInstance(sInstance->Get(), kInstanceObjectId, 0);
static utils::TerribleCommandBuffer* mCommandBuffer = new utils::TerribleCommandBuffer(); static dawn::utilsTerribleCommandBuffer* mCommandBuffer =
new dawn::utilsTerribleCommandBuffer();
static dawn::wire::ChunkedCommandSerializer mSerializer = static dawn::wire::ChunkedCommandSerializer mSerializer =
dawn::wire::ChunkedCommandSerializer(mCommandBuffer); dawn::wire::ChunkedCommandSerializer(mCommandBuffer);
mCommandBuffer->SetHandler(wireServer.get()); mCommandBuffer->SetHandler(wireServer.get());

View File

@ -17,8 +17,10 @@
#include <cstdint> #include <cstdint>
namespace dawn {
template <typename T> template <typename T>
class Ref; class Ref;
} // namespace dawn
namespace dawn::native { namespace dawn::native {

View File

@ -164,8 +164,8 @@ class Stream<T, std::enable_if_t<std::is_enum_v<T>>> {
// Stream specialization for TypedInteger. // Stream specialization for TypedInteger.
template <typename Tag, typename Integer> template <typename Tag, typename Integer>
class Stream<::detail::TypedIntegerImpl<Tag, Integer>> { class Stream<::dawn::detail::TypedIntegerImpl<Tag, Integer>> {
using T = ::detail::TypedIntegerImpl<Tag, Integer>; using T = ::dawn::detail::TypedIntegerImpl<Tag, Integer>;
public: public:
static void Write(Sink* s, const T& t) { StreamIn(s, static_cast<Integer>(t)); } static void Write(Sink* s, const T& t) { StreamIn(s, static_cast<Integer>(t)); }

View File

@ -20,7 +20,9 @@
#include "dawn/native/Error.h" #include "dawn/native/Error.h"
namespace dawn {
class DynamicLib; class DynamicLib;
} // namespace dawn
namespace dawn::native::vulkan { namespace dawn::native::vulkan {

View File

@ -19,7 +19,7 @@
#include "dawn/native/dawn_platform.h" #include "dawn/native/dawn_platform.h"
#include "dawn/native/webgpu_absl_format_autogen.h" #include "dawn/native/webgpu_absl_format_autogen.h"
namespace ityp { namespace dawn::ityp {
template <typename Index, typename Value> template <typename Index, typename Value>
class span; class span;
} }

View File

@ -57,7 +57,7 @@ void init() {
queue = device.GetQueue(); queue = device.GetQueue();
swapchain = GetSwapChain(); swapchain = GetSwapChain();
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( wgpu::ShaderModule vsModule = dawn::utils::CreateShaderModule(device, R"(
struct Constants { struct Constants {
scale : f32, scale : f32,
time : f32, time : f32,
@ -112,16 +112,16 @@ void init() {
return output; return output;
})"); })");
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( wgpu::ShaderModule fsModule = dawn::utils::CreateShaderModule(device, R"(
@fragment fn main(@location(0) v_color : vec4f) -> @location(0) vec4f { @fragment fn main(@location(0) v_color : vec4f) -> @location(0) vec4f {
return v_color; return v_color;
})"); })");
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = dawn::utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Vertex, wgpu::BufferBindingType::Uniform, true}}); device, {{0, wgpu::ShaderStage::Vertex, wgpu::BufferBindingType::Uniform, true}});
utils::ComboRenderPipelineDescriptor descriptor; dawn::utils::ComboRenderPipelineDescriptor descriptor;
descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl); descriptor.layout = dawn::utils::MakeBasicPipelineLayout(device, &bgl);
descriptor.vertex.module = vsModule; descriptor.vertex.module = vsModule;
descriptor.cFragment.module = fsModule; descriptor.cFragment.module = fsModule;
descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat(); descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
@ -143,7 +143,7 @@ void init() {
bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Uniform; bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Uniform;
ubo = device.CreateBuffer(&bufferDesc); ubo = device.CreateBuffer(&bufferDesc);
bindGroup = utils::MakeBindGroup(device, bgl, {{0, ubo, 0, sizeof(ShaderData)}}); bindGroup = dawn::utils::MakeBindGroup(device, bgl, {{0, ubo, 0, sizeof(ShaderData)}});
} }
int frameCount = 0; int frameCount = 0;
@ -155,7 +155,7 @@ void frame() {
} }
queue.WriteBuffer(ubo, 0, shaderData.data(), kNumTriangles * sizeof(ShaderData)); queue.WriteBuffer(ubo, 0, shaderData.data(), kNumTriangles * sizeof(ShaderData));
utils::ComboRenderPassDescriptor renderPass({backbufferView}); dawn::utils::ComboRenderPassDescriptor renderPass({backbufferView});
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
@ -182,10 +182,10 @@ int main(int argc, const char* argv[]) {
} }
init(); init();
utils::Timer* timer = utils::CreateTimer(); dawn::utils::Timer* timer = dawn::utils::CreateTimer();
timer->Start(); timer->Start();
while (!ShouldQuit()) { while (!ShouldQuit()) {
utils::ScopedAutoreleasePool pool; dawn::utils::ScopedAutoreleasePool pool;
ProcessEvents(); ProcessEvents();
frameCount++; frameCount++;
frame(); frame();

View File

@ -42,13 +42,13 @@ void init() {
); );
return vec4f(pos[VertexIndex], 0.0, 1.0); return vec4f(pos[VertexIndex], 0.0, 1.0);
})"; })";
WGPUShaderModule vsModule = utils::CreateShaderModule(device, vs).MoveToCHandle(); WGPUShaderModule vsModule = dawn::utils::CreateShaderModule(device, vs).MoveToCHandle();
const char* fs = R"( const char* fs = R"(
@fragment fn main() -> @location(0) vec4f { @fragment fn main() -> @location(0) vec4f {
return vec4f(1.0, 0.0, 0.0, 1.0); return vec4f(1.0, 0.0, 0.0, 1.0);
})"; })";
WGPUShaderModule fsModule = utils::CreateShaderModule(device, fs).MoveToCHandle(); WGPUShaderModule fsModule = dawn::utils::CreateShaderModule(device, fs).MoveToCHandle();
{ {
WGPURenderPipelineDescriptor descriptor = {}; WGPURenderPipelineDescriptor descriptor = {};
@ -142,9 +142,9 @@ int main(int argc, const char* argv[]) {
init(); init();
while (!ShouldQuit()) { while (!ShouldQuit()) {
utils::ScopedAutoreleasePool pool; dawn::utils::ScopedAutoreleasePool pool;
ProcessEvents(); ProcessEvents();
frame(); frame();
utils::USleep(16000); dawn::utils::USleep(16000);
} }
} }

View File

@ -65,11 +65,11 @@ void initBuffers() {
{0.00, 0.02}, {0.00, 0.02},
}}; }};
modelBuffer = modelBuffer =
utils::CreateBufferFromData(device, &model, sizeof(model), wgpu::BufferUsage::Vertex); dawn::utils::CreateBufferFromData(device, &model, sizeof(model), wgpu::BufferUsage::Vertex);
SimParams params = {0.04f, 0.1f, 0.025f, 0.025f, 0.02f, 0.05f, 0.005f, kNumParticles}; SimParams params = {0.04f, 0.1f, 0.025f, 0.025f, 0.02f, 0.05f, 0.005f, kNumParticles};
updateParams = updateParams = dawn::utils::CreateBufferFromData(device, &params, sizeof(params),
utils::CreateBufferFromData(device, &params, sizeof(params), wgpu::BufferUsage::Uniform); wgpu::BufferUsage::Uniform);
std::vector<Particle> initialParticles(kNumParticles); std::vector<Particle> initialParticles(kNumParticles);
{ {
@ -95,7 +95,7 @@ void initBuffers() {
} }
void initRender() { void initRender() {
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( wgpu::ShaderModule vsModule = dawn::utils::CreateShaderModule(device, R"(
struct VertexIn { struct VertexIn {
@location(0) a_particlePos : vec2f, @location(0) a_particlePos : vec2f,
@location(1) a_particleVel : vec2f, @location(1) a_particleVel : vec2f,
@ -112,7 +112,7 @@ void initRender() {
} }
)"); )");
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( wgpu::ShaderModule fsModule = dawn::utils::CreateShaderModule(device, R"(
@fragment @fragment
fn main() -> @location(0) vec4f { fn main() -> @location(0) vec4f {
return vec4f(1.0, 1.0, 1.0, 1.0); return vec4f(1.0, 1.0, 1.0, 1.0);
@ -121,7 +121,7 @@ void initRender() {
depthStencilView = CreateDefaultDepthStencilView(device); depthStencilView = CreateDefaultDepthStencilView(device);
utils::ComboRenderPipelineDescriptor descriptor; dawn::utils::ComboRenderPipelineDescriptor descriptor;
descriptor.vertex.module = vsModule; descriptor.vertex.module = vsModule;
descriptor.vertex.bufferCount = 2; descriptor.vertex.bufferCount = 2;
@ -147,7 +147,7 @@ void initRender() {
} }
void initSim() { void initSim() {
wgpu::ShaderModule module = utils::CreateShaderModule(device, R"( wgpu::ShaderModule module = dawn::utils::CreateShaderModule(device, R"(
struct Particle { struct Particle {
pos : vec2f, pos : vec2f,
vel : vec2f, vel : vec2f,
@ -242,14 +242,14 @@ void initSim() {
} }
)"); )");
auto bgl = utils::MakeBindGroupLayout( auto bgl = dawn::utils::MakeBindGroupLayout(
device, { device, {
{0, wgpu::ShaderStage::Compute, wgpu::BufferBindingType::Uniform}, {0, wgpu::ShaderStage::Compute, wgpu::BufferBindingType::Uniform},
{1, wgpu::ShaderStage::Compute, wgpu::BufferBindingType::Storage}, {1, wgpu::ShaderStage::Compute, wgpu::BufferBindingType::Storage},
{2, wgpu::ShaderStage::Compute, wgpu::BufferBindingType::Storage}, {2, wgpu::ShaderStage::Compute, wgpu::BufferBindingType::Storage},
}); });
wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pl = dawn::utils::MakeBasicPipelineLayout(device, &bgl);
wgpu::ComputePipelineDescriptor csDesc; wgpu::ComputePipelineDescriptor csDesc;
csDesc.layout = pl; csDesc.layout = pl;
@ -258,7 +258,7 @@ void initSim() {
updatePipeline = device.CreateComputePipeline(&csDesc); updatePipeline = device.CreateComputePipeline(&csDesc);
for (uint32_t i = 0; i < 2; ++i) { for (uint32_t i = 0; i < 2; ++i) {
updateBGs[i] = utils::MakeBindGroup( updateBGs[i] = dawn::utils::MakeBindGroup(
device, bgl, device, bgl,
{ {
{0, updateParams, 0, sizeof(SimParams)}, {0, updateParams, 0, sizeof(SimParams)},
@ -281,7 +281,7 @@ wgpu::CommandBuffer createCommandBuffer(const wgpu::TextureView backbufferView,
} }
{ {
utils::ComboRenderPassDescriptor renderPass({backbufferView}, depthStencilView); dawn::utils::ComboRenderPassDescriptor renderPass({backbufferView}, depthStencilView);
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.SetPipeline(renderPipeline); pass.SetPipeline(renderPipeline);
pass.SetVertexBuffer(0, bufferDst); pass.SetVertexBuffer(0, bufferDst);
@ -322,9 +322,9 @@ int main(int argc, const char* argv[]) {
init(); init();
while (!ShouldQuit()) { while (!ShouldQuit()) {
utils::ScopedAutoreleasePool pool; dawn::utils::ScopedAutoreleasePool pool;
ProcessEvents(); ProcessEvents();
frame(); frame();
utils::USleep(16000); dawn::utils::USleep(16000);
} }
} }

View File

@ -41,14 +41,14 @@ void initBuffers() {
1, 1,
2, 2,
}; };
indexBuffer = indexBuffer = dawn::utils::CreateBufferFromData(device, indexData, sizeof(indexData),
utils::CreateBufferFromData(device, indexData, sizeof(indexData), wgpu::BufferUsage::Index); wgpu::BufferUsage::Index);
static const float vertexData[12] = { static const float vertexData[12] = {
0.0f, 0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f,
}; };
vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData), vertexBuffer = dawn::utils::CreateBufferFromData(device, vertexData, sizeof(vertexData),
wgpu::BufferUsage::Vertex); wgpu::BufferUsage::Vertex);
} }
void initTextures() { void initTextures() {
@ -71,11 +71,12 @@ void initTextures() {
data[i] = static_cast<uint8_t>(i % 253); data[i] = static_cast<uint8_t>(i % 253);
} }
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData( wgpu::Buffer stagingBuffer = dawn::utils::CreateBufferFromData(
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc); device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
wgpu::ImageCopyBuffer imageCopyBuffer = wgpu::ImageCopyBuffer imageCopyBuffer =
utils::CreateImageCopyBuffer(stagingBuffer, 0, 4 * 1024); dawn::utils::CreateImageCopyBuffer(stagingBuffer, 0, 4 * 1024);
wgpu::ImageCopyTexture imageCopyTexture = utils::CreateImageCopyTexture(texture, 0, {0, 0, 0}); wgpu::ImageCopyTexture imageCopyTexture =
dawn::utils::CreateImageCopyTexture(texture, 0, {0, 0, 0});
wgpu::Extent3D copySize = {1024, 1024, 1}; wgpu::Extent3D copySize = {1024, 1024, 1};
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@ -94,13 +95,13 @@ void init() {
initBuffers(); initBuffers();
initTextures(); initTextures();
wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( wgpu::ShaderModule vsModule = dawn::utils::CreateShaderModule(device, R"(
@vertex fn main(@location(0) pos : vec4f) @vertex fn main(@location(0) pos : vec4f)
-> @builtin(position) vec4f { -> @builtin(position) vec4f {
return pos; return pos;
})"); })");
wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( wgpu::ShaderModule fsModule = dawn::utils::CreateShaderModule(device, R"(
@group(0) @binding(0) var mySampler: sampler; @group(0) @binding(0) var mySampler: sampler;
@group(0) @binding(1) var myTexture : texture_2d<f32>; @group(0) @binding(1) var myTexture : texture_2d<f32>;
@ -109,18 +110,18 @@ void init() {
return textureSample(myTexture, mySampler, FragCoord.xy / vec2f(640.0, 480.0)); return textureSample(myTexture, mySampler, FragCoord.xy / vec2f(640.0, 480.0));
})"); })");
auto bgl = utils::MakeBindGroupLayout( auto bgl = dawn::utils::MakeBindGroupLayout(
device, { device, {
{0, wgpu::ShaderStage::Fragment, wgpu::SamplerBindingType::Filtering}, {0, wgpu::ShaderStage::Fragment, wgpu::SamplerBindingType::Filtering},
{1, wgpu::ShaderStage::Fragment, wgpu::TextureSampleType::Float}, {1, wgpu::ShaderStage::Fragment, wgpu::TextureSampleType::Float},
}); });
wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, &bgl); wgpu::PipelineLayout pl = dawn::utils::MakeBasicPipelineLayout(device, &bgl);
depthStencilView = CreateDefaultDepthStencilView(device); depthStencilView = CreateDefaultDepthStencilView(device);
utils::ComboRenderPipelineDescriptor descriptor; dawn::utils::ComboRenderPipelineDescriptor descriptor;
descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl); descriptor.layout = dawn::utils::MakeBasicPipelineLayout(device, &bgl);
descriptor.vertex.module = vsModule; descriptor.vertex.module = vsModule;
descriptor.vertex.bufferCount = 1; descriptor.vertex.bufferCount = 1;
descriptor.cBuffers[0].arrayStride = 4 * sizeof(float); descriptor.cBuffers[0].arrayStride = 4 * sizeof(float);
@ -134,7 +135,7 @@ void init() {
wgpu::TextureView view = texture.CreateView(); wgpu::TextureView view = texture.CreateView();
bindGroup = utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, view}}); bindGroup = dawn::utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, view}});
} }
struct { struct {
@ -149,7 +150,7 @@ void frame() {
} }
wgpu::TextureView backbufferView = swapchain.GetCurrentTextureView(); wgpu::TextureView backbufferView = swapchain.GetCurrentTextureView();
utils::ComboRenderPassDescriptor renderPass({backbufferView}, depthStencilView); dawn::utils::ComboRenderPassDescriptor renderPass({backbufferView}, depthStencilView);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{ {
@ -175,9 +176,9 @@ int main(int argc, const char* argv[]) {
init(); init();
while (!ShouldQuit()) { while (!ShouldQuit()) {
utils::ScopedAutoreleasePool pool; dawn::utils::ScopedAutoreleasePool pool;
ProcessEvents(); ProcessEvents();
frame(); frame();
utils::USleep(16000); dawn::utils::USleep(16000);
} }
} }

View File

@ -136,7 +136,7 @@ void DoRender(WindowData* data) {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
if (data->renderTriangle) { if (data->renderTriangle) {
utils::ComboRenderPassDescriptor desc({view}); dawn::utils::ComboRenderPassDescriptor desc({view});
// Use Load to check the swapchain is lazy cleared (we shouldn't see garbage from previous // Use Load to check the swapchain is lazy cleared (we shouldn't see garbage from previous
// frames). // frames).
desc.cColorAttachments[0].loadOp = wgpu::LoadOp::Load; desc.cColorAttachments[0].loadOp = wgpu::LoadOp::Load;
@ -151,7 +151,7 @@ void DoRender(WindowData* data) {
data->clearCycle = 1.0f; data->clearCycle = 1.0f;
} }
utils::ComboRenderPassDescriptor desc({view}); dawn::utils::ComboRenderPassDescriptor desc({view});
desc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear; desc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
desc.cColorAttachments[0].clearValue = {data->clearCycle, 1.0f - data->clearCycle, 0.0f, desc.cColorAttachments[0].clearValue = {data->clearCycle, 1.0f - data->clearCycle, 0.0f,
1.0f}; 1.0f};
@ -314,8 +314,8 @@ int main(int argc, const char* argv[]) {
queue = device.GetQueue(); queue = device.GetQueue();
// The hacky pipeline to render a triangle. // The hacky pipeline to render a triangle.
utils::ComboRenderPipelineDescriptor pipelineDesc; dawn::utils::ComboRenderPipelineDescriptor pipelineDesc;
pipelineDesc.vertex.module = utils::CreateShaderModule(device, R"( pipelineDesc.vertex.module = dawn::utils::CreateShaderModule(device, R"(
@vertex fn main(@builtin(vertex_index) VertexIndex : u32) @vertex fn main(@builtin(vertex_index) VertexIndex : u32)
-> @builtin(position) vec4f { -> @builtin(position) vec4f {
var pos = array( var pos = array(
@ -325,7 +325,7 @@ int main(int argc, const char* argv[]) {
); );
return vec4f(pos[VertexIndex], 0.0, 1.0); return vec4f(pos[VertexIndex], 0.0, 1.0);
})"); })");
pipelineDesc.cFragment.module = utils::CreateShaderModule(device, R"( pipelineDesc.cFragment.module = dawn::utils::CreateShaderModule(device, R"(
@fragment fn main() -> @location(0) vec4f { @fragment fn main() -> @location(0) vec4f {
return vec4f(1.0, 0.0, 0.0, 1.0); return vec4f(1.0, 0.0, 0.0, 1.0);
})"); })");
@ -337,7 +337,7 @@ int main(int argc, const char* argv[]) {
AddWindow(); AddWindow();
while (windows.size() != 0) { while (windows.size() != 0) {
utils::ScopedAutoreleasePool pool; dawn::utils::ScopedAutoreleasePool pool;
glfwPollEvents(); glfwPollEvents();
wgpuInstanceProcessEvents(instance->Get()); wgpuInstanceProcessEvents(instance->Get());

View File

@ -102,15 +102,15 @@ static GLFWwindow* window = nullptr;
static dawn::wire::WireServer* wireServer = nullptr; static dawn::wire::WireServer* wireServer = nullptr;
static dawn::wire::WireClient* wireClient = nullptr; static dawn::wire::WireClient* wireClient = nullptr;
static utils::TerribleCommandBuffer* c2sBuf = nullptr; static dawn::utils::TerribleCommandBuffer* c2sBuf = nullptr;
static utils::TerribleCommandBuffer* s2cBuf = nullptr; static dawn::utils::TerribleCommandBuffer* s2cBuf = nullptr;
static constexpr uint32_t kWidth = 640; static constexpr uint32_t kWidth = 640;
static constexpr uint32_t kHeight = 480; static constexpr uint32_t kHeight = 480;
wgpu::Device CreateCppDawnDevice() { wgpu::Device CreateCppDawnDevice() {
ScopedEnvironmentVar angleDefaultPlatform; dawn::ScopedEnvironmentVar angleDefaultPlatform;
if (GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM").first.empty()) { if (dawn::GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM").first.empty()) {
angleDefaultPlatform.Set("ANGLE_DEFAULT_PLATFORM", "swiftshader"); angleDefaultPlatform.Set("ANGLE_DEFAULT_PLATFORM", "swiftshader");
} }
@ -194,8 +194,8 @@ wgpu::Device CreateCppDawnDevice() {
break; break;
case CmdBufType::Terrible: { case CmdBufType::Terrible: {
c2sBuf = new utils::TerribleCommandBuffer(); c2sBuf = new dawn::utils::TerribleCommandBuffer();
s2cBuf = new utils::TerribleCommandBuffer(); s2cBuf = new dawn::utils::TerribleCommandBuffer();
dawn::wire::WireServerDescriptor serverDesc = {}; dawn::wire::WireServerDescriptor serverDesc = {};
serverDesc.procs = &backendProcs; serverDesc.procs = &backendProcs;

View File

@ -171,8 +171,8 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
ParseArgs(argc, argv); ParseArgs(argc, argv);
if (mBackendValidationLevel != dawn::native::BackendValidationLevel::Disabled) { if (mBackendValidationLevel != dawn::native::BackendValidationLevel::Disabled) {
mPlatformDebugLogger = mPlatformDebugLogger = std::unique_ptr<dawn::utils::PlatformDebugLogger>(
std::unique_ptr<utils::PlatformDebugLogger>(utils::CreatePlatformDebugLogger()); dawn::utils::CreatePlatformDebugLogger());
} }
// Create a temporary instance to select available and preferred adapters. This is done before // Create a temporary instance to select available and preferred adapters. This is done before
@ -397,7 +397,7 @@ std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDi
instance->EnableAdapterBlocklist(false); instance->EnableAdapterBlocklist(false);
#ifdef DAWN_ENABLE_BACKEND_OPENGLES #ifdef DAWN_ENABLE_BACKEND_OPENGLES
if (GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM").first.empty()) { if (dawn::GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM").first.empty()) {
const char* platform; const char* platform;
if (!mANGLEBackend.empty()) { if (!mANGLEBackend.empty()) {
platform = mANGLEBackend.c_str(); platform = mANGLEBackend.c_str();
@ -408,7 +408,7 @@ std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDi
platform = "swiftshader"; platform = "swiftshader";
#endif #endif
} }
SetEnvironmentVar("ANGLE_DEFAULT_PLATFORM", platform); dawn::SetEnvironmentVar("ANGLE_DEFAULT_PLATFORM", platform);
} }
#endif // DAWN_ENABLE_BACKEND_OPENGLES #endif // DAWN_ENABLE_BACKEND_OPENGLES
@ -718,7 +718,8 @@ DawnTestBase::DawnTestBase(const AdapterTestParam& param) : mParam(param) {
callback(WGPURequestDeviceStatus_Success, cDevice, nullptr, userdata); callback(WGPURequestDeviceStatus_Success, cDevice, nullptr, userdata);
}; };
mWireHelper = utils::CreateWireHelper(procs, gTestEnv->UsesWire(), gTestEnv->GetWireTraceDir()); mWireHelper =
dawn::utils::CreateWireHelper(procs, gTestEnv->UsesWire(), gTestEnv->GetWireTraceDir());
} }
DawnTestBase::~DawnTestBase() { DawnTestBase::~DawnTestBase() {
@ -770,36 +771,36 @@ bool DawnTestBase::IsVulkan() const {
} }
bool DawnTestBase::IsAMD() const { bool DawnTestBase::IsAMD() const {
return gpu_info::IsAMD(mParam.adapterProperties.vendorID); return dawn::gpu_info::IsAMD(mParam.adapterProperties.vendorID);
} }
bool DawnTestBase::IsApple() const { bool DawnTestBase::IsApple() const {
return gpu_info::IsApple(mParam.adapterProperties.vendorID); return dawn::gpu_info::IsApple(mParam.adapterProperties.vendorID);
} }
bool DawnTestBase::IsARM() const { bool DawnTestBase::IsARM() const {
return gpu_info::IsARM(mParam.adapterProperties.vendorID); return dawn::gpu_info::IsARM(mParam.adapterProperties.vendorID);
} }
bool DawnTestBase::IsImgTec() const { bool DawnTestBase::IsImgTec() const {
return gpu_info::IsImgTec(mParam.adapterProperties.vendorID); return dawn::gpu_info::IsImgTec(mParam.adapterProperties.vendorID);
} }
bool DawnTestBase::IsIntel() const { bool DawnTestBase::IsIntel() const {
return gpu_info::IsIntel(mParam.adapterProperties.vendorID); return dawn::gpu_info::IsIntel(mParam.adapterProperties.vendorID);
} }
bool DawnTestBase::IsNvidia() const { bool DawnTestBase::IsNvidia() const {
return gpu_info::IsNvidia(mParam.adapterProperties.vendorID); return dawn::gpu_info::IsNvidia(mParam.adapterProperties.vendorID);
} }
bool DawnTestBase::IsQualcomm() const { bool DawnTestBase::IsQualcomm() const {
return gpu_info::IsQualcomm(mParam.adapterProperties.vendorID); return dawn::gpu_info::IsQualcomm(mParam.adapterProperties.vendorID);
} }
bool DawnTestBase::IsSwiftshader() const { bool DawnTestBase::IsSwiftshader() const {
return gpu_info::IsGoogleSwiftshader(mParam.adapterProperties.vendorID, return dawn::gpu_info::IsGoogleSwiftshader(mParam.adapterProperties.vendorID,
mParam.adapterProperties.deviceID); mParam.adapterProperties.deviceID);
} }
bool DawnTestBase::IsANGLE() const { bool DawnTestBase::IsANGLE() const {
@ -812,15 +813,15 @@ bool DawnTestBase::IsANGLESwiftShader() const {
} }
bool DawnTestBase::IsWARP() const { bool DawnTestBase::IsWARP() const {
return gpu_info::IsMicrosoftWARP(mParam.adapterProperties.vendorID, return dawn::gpu_info::IsMicrosoftWARP(mParam.adapterProperties.vendorID,
mParam.adapterProperties.deviceID); mParam.adapterProperties.deviceID);
} }
bool DawnTestBase::IsIntelGen12() const { bool DawnTestBase::IsIntelGen12() const {
return gpu_info::IsIntelGen12LP(mParam.adapterProperties.vendorID, return dawn::gpu_info::IsIntelGen12LP(mParam.adapterProperties.vendorID,
mParam.adapterProperties.deviceID) || mParam.adapterProperties.deviceID) ||
gpu_info::IsIntelGen12HP(mParam.adapterProperties.vendorID, dawn::gpu_info::IsIntelGen12HP(mParam.adapterProperties.vendorID,
mParam.adapterProperties.deviceID); mParam.adapterProperties.deviceID);
} }
bool DawnTestBase::IsWindows() const { bool DawnTestBase::IsWindows() const {
@ -845,7 +846,7 @@ bool DawnTestBase::IsMacOS(int32_t majorVersion, int32_t minorVersion) const {
return true; return true;
} }
int32_t majorVersionOut, minorVersionOut = 0; int32_t majorVersionOut, minorVersionOut = 0;
GetMacOSVersion(&majorVersionOut, &minorVersionOut); dawn::GetMacOSVersion(&majorVersionOut, &minorVersionOut);
return (majorVersion != -1 && majorVersion == majorVersionOut) && return (majorVersion != -1 && majorVersion == majorVersionOut) &&
(minorVersion != -1 && minorVersion == minorVersionOut); (minorVersion != -1 && minorVersion == minorVersionOut);
#else #else
@ -1146,7 +1147,7 @@ std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,
uint64_t offset, uint64_t offset,
uint64_t size, uint64_t size,
detail::Expectation* expectation) { detail::Expectation* expectation) {
uint64_t alignedSize = Align(size, uint64_t(4)); uint64_t alignedSize = dawn::Align(size, uint64_t(4));
auto readback = ReserveReadback(device, alignedSize); auto readback = ReserveReadback(device, alignedSize);
// We need to enqueue the copy immediately because by the time we resolve the expectation, // We need to enqueue the copy immediately because by the time we resolve the expectation,
@ -1187,24 +1188,25 @@ std::ostringstream& DawnTestBase::AddTextureExpectationImpl(const char* file,
ASSERT(targetDevice != nullptr); ASSERT(targetDevice != nullptr);
if (bytesPerRow == 0) { if (bytesPerRow == 0) {
bytesPerRow = Align(extent.width * dataSize, kTextureBytesPerRowAlignment); bytesPerRow = dawn::Align(extent.width * dataSize, kTextureBytesPerRowAlignment);
} else { } else {
ASSERT(bytesPerRow >= extent.width * dataSize); ASSERT(bytesPerRow >= extent.width * dataSize);
ASSERT(bytesPerRow == Align(bytesPerRow, kTextureBytesPerRowAlignment)); ASSERT(bytesPerRow == dawn::Align(bytesPerRow, kTextureBytesPerRowAlignment));
} }
uint32_t rowsPerImage = extent.height; uint32_t rowsPerImage = extent.height;
uint32_t size = utils::RequiredBytesInCopy(bytesPerRow, rowsPerImage, extent.width, uint32_t size =
extent.height, extent.depthOrArrayLayers, dataSize); dawn::utils::RequiredBytesInCopy(bytesPerRow, rowsPerImage, extent.width, extent.height,
extent.depthOrArrayLayers, dataSize);
auto readback = ReserveReadback(targetDevice, Align(size, 4)); auto readback = ReserveReadback(targetDevice, dawn::Align(size, 4));
// We need to enqueue the copy immediately because by the time we resolve the expectation, // We need to enqueue the copy immediately because by the time we resolve the expectation,
// the texture might have been modified. // the texture might have been modified.
wgpu::ImageCopyTexture imageCopyTexture = wgpu::ImageCopyTexture imageCopyTexture =
utils::CreateImageCopyTexture(texture, level, origin, aspect); dawn::utils::CreateImageCopyTexture(texture, level, origin, aspect);
wgpu::ImageCopyBuffer imageCopyBuffer = wgpu::ImageCopyBuffer imageCopyBuffer = dawn::utils::CreateImageCopyBuffer(
utils::CreateImageCopyBuffer(readback.buffer, readback.offset, bytesPerRow, rowsPerImage); readback.buffer, readback.offset, bytesPerRow, rowsPerImage);
wgpu::CommandEncoder encoder = targetDevice.CreateCommandEncoder(); wgpu::CommandEncoder encoder = targetDevice.CreateCommandEncoder();
encoder.CopyTextureToBuffer(&imageCopyTexture, &imageCopyBuffer, &extent); encoder.CopyTextureToBuffer(&imageCopyTexture, &imageCopyBuffer, &extent);
@ -1284,7 +1286,8 @@ std::ostringstream& DawnTestBase::ExpectSampledFloatDataImpl(wgpu::TextureView t
} }
)"; )";
wgpu::ShaderModule csModule = utils::CreateShaderModule(device, shaderSource.str().c_str()); wgpu::ShaderModule csModule =
dawn::utils::CreateShaderModule(device, shaderSource.str().c_str());
wgpu::ComputePipelineDescriptor pipelineDescriptor; wgpu::ComputePipelineDescriptor pipelineDescriptor;
pipelineDescriptor.compute.module = csModule; pipelineDescriptor.compute.module = csModule;
@ -1295,12 +1298,12 @@ std::ostringstream& DawnTestBase::ExpectSampledFloatDataImpl(wgpu::TextureView t
// Create and initialize the slot buffer so that it won't unexpectedly affect the count of // Create and initialize the slot buffer so that it won't unexpectedly affect the count of
// resources lazily cleared. // resources lazily cleared.
const std::vector<float> initialBufferData(width * height * componentCount * sampleCount, 0.f); const std::vector<float> initialBufferData(width * height * componentCount * sampleCount, 0.f);
wgpu::Buffer readbackBuffer = utils::CreateBufferFromData( wgpu::Buffer readbackBuffer = dawn::utils::CreateBufferFromData(
device, initialBufferData.data(), sizeof(float) * initialBufferData.size(), device, initialBufferData.data(), sizeof(float) * initialBufferData.size(),
wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::Storage); wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::Storage);
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0), wgpu::BindGroup bindGroup = dawn::utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
{{0, textureView}, {1, readbackBuffer}}); {{0, textureView}, {1, readbackBuffer}});
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder(); wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
wgpu::ComputePassEncoder pass = commandEncoder.BeginComputePass(); wgpu::ComputePassEncoder pass = commandEncoder.BeginComputePass();
@ -1399,9 +1402,9 @@ std::ostringstream& DawnTestBase::ExpectAttachmentDepthStencilTestData(
// Upload the depth data. // Upload the depth data.
wgpu::ImageCopyTexture imageCopyTexture = wgpu::ImageCopyTexture imageCopyTexture =
utils::CreateImageCopyTexture(depthDataTexture, 0, {0, 0, 0}); dawn::utils::CreateImageCopyTexture(depthDataTexture, 0, {0, 0, 0});
wgpu::TextureDataLayout textureDataLayout = wgpu::TextureDataLayout textureDataLayout =
utils::CreateTextureDataLayout(0, sizeof(float) * width); dawn::utils::CreateTextureDataLayout(0, sizeof(float) * width);
wgpu::Extent3D copyExtent = {width, height, 1}; wgpu::Extent3D copyExtent = {width, height, 1};
queue.WriteTexture(&imageCopyTexture, expectedDepth.data(), queue.WriteTexture(&imageCopyTexture, expectedDepth.data(),
@ -1409,9 +1412,9 @@ std::ostringstream& DawnTestBase::ExpectAttachmentDepthStencilTestData(
} }
// Pipeline for a full screen quad. // Pipeline for a full screen quad.
utils::ComboRenderPipelineDescriptor pipelineDescriptor; dawn::utils::ComboRenderPipelineDescriptor pipelineDescriptor;
pipelineDescriptor.vertex.module = utils::CreateShaderModule(device, R"( pipelineDescriptor.vertex.module = dawn::utils::CreateShaderModule(device, R"(
@vertex @vertex
fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4f { fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4f {
var pos = array( var pos = array(
@ -1424,7 +1427,7 @@ std::ostringstream& DawnTestBase::ExpectAttachmentDepthStencilTestData(
if (depthDataTexture) { if (depthDataTexture) {
// Sample the input texture and write out depth. |result| will only be set to 1 if we // Sample the input texture and write out depth. |result| will only be set to 1 if we
// pass the depth test. // pass the depth test.
pipelineDescriptor.cFragment.module = utils::CreateShaderModule(device, R"( pipelineDescriptor.cFragment.module = dawn::utils::CreateShaderModule(device, R"(
@group(0) @binding(0) var texture0 : texture_2d<f32>; @group(0) @binding(0) var texture0 : texture_2d<f32>;
struct FragmentOut { struct FragmentOut {
@ -1440,7 +1443,7 @@ std::ostringstream& DawnTestBase::ExpectAttachmentDepthStencilTestData(
return output; return output;
})"); })");
} else { } else {
pipelineDescriptor.cFragment.module = utils::CreateShaderModule(device, R"( pipelineDescriptor.cFragment.module = dawn::utils::CreateShaderModule(device, R"(
@fragment @fragment
fn main() -> @location(0) u32 { fn main() -> @location(0) u32 {
return 1u; return 1u;
@ -1466,8 +1469,8 @@ std::ostringstream& DawnTestBase::ExpectAttachmentDepthStencilTestData(
viewDesc.baseArrayLayer = arrayLayer; viewDesc.baseArrayLayer = arrayLayer;
viewDesc.arrayLayerCount = 1; viewDesc.arrayLayerCount = 1;
utils::ComboRenderPassDescriptor passDescriptor({colorTexture.CreateView()}, dawn::utils::ComboRenderPassDescriptor passDescriptor({colorTexture.CreateView()},
texture.CreateView(&viewDesc)); texture.CreateView(&viewDesc));
passDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load; passDescriptor.cDepthStencilAttachmentInfo.depthLoadOp = wgpu::LoadOp::Load;
passDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load; passDescriptor.cDepthStencilAttachmentInfo.stencilLoadOp = wgpu::LoadOp::Load;
switch (format) { switch (format) {
@ -1494,8 +1497,8 @@ std::ostringstream& DawnTestBase::ExpectAttachmentDepthStencilTestData(
pass.SetPipeline(pipeline); pass.SetPipeline(pipeline);
if (depthDataTexture) { if (depthDataTexture) {
// Bind the depth data texture. // Bind the depth data texture.
pass.SetBindGroup(0, utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0), pass.SetBindGroup(0, dawn::utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
{{0, depthDataTexture.CreateView()}})); {{0, depthDataTexture.CreateView()}}));
} }
pass.Draw(3); pass.Draw(3);
pass.End(); pass.End();
@ -1516,7 +1519,7 @@ void DawnTestBase::WaitABit(wgpu::Instance targetInstance) {
} }
FlushWire(); FlushWire();
utils::USleep(100); dawn::utils::USleep(100);
} }
void DawnTestBase::FlushWire() { void DawnTestBase::FlushWire() {
@ -1553,8 +1556,8 @@ DawnTestBase::ReadbackReservation DawnTestBase::ReserveReadback(wgpu::Device tar
// resource lazy clear in the tests. // resource lazy clear in the tests.
const std::vector<uint8_t> initialBufferData(readbackSize, 0u); const std::vector<uint8_t> initialBufferData(readbackSize, 0u);
slot.buffer = slot.buffer =
utils::CreateBufferFromData(targetDevice, initialBufferData.data(), readbackSize, dawn::utils::CreateBufferFromData(targetDevice, initialBufferData.data(), readbackSize,
wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst); wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst);
// This readback might be called from multiple threads // This readback might be called from multiple threads
dawn::Mutex::AutoLock lg(&mMutex); dawn::Mutex::AutoLock lg(&mMutex);
@ -1675,19 +1678,19 @@ void DawnTestBase::ResolveDeferredExpectationsNow() {
} }
} }
bool utils::RGBA8::operator==(const utils::RGBA8& other) const { bool dawn::utils::RGBA8::operator==(const dawn::utils::RGBA8& other) const {
return r == other.r && g == other.g && b == other.b && a == other.a; return r == other.r && g == other.g && b == other.b && a == other.a;
} }
bool utils::RGBA8::operator!=(const utils::RGBA8& other) const { bool dawn::utils::RGBA8::operator!=(const dawn::utils::RGBA8& other) const {
return !(*this == other); return !(*this == other);
} }
bool utils::RGBA8::operator<=(const utils::RGBA8& other) const { bool dawn::utils::RGBA8::operator<=(const dawn::utils::RGBA8& other) const {
return (r <= other.r && g <= other.g && b <= other.b && a <= other.a); return (r <= other.r && g <= other.g && b <= other.b && a <= other.a);
} }
bool utils::RGBA8::operator>=(const utils::RGBA8& other) const { bool dawn::utils::RGBA8::operator>=(const dawn::utils::RGBA8& other) const {
return (r >= other.r && g >= other.g && b >= other.b && a >= other.a); return (r >= other.r && g >= other.g && b >= other.b && a >= other.a);
} }
@ -1724,12 +1727,12 @@ testing::AssertionResult CheckImpl(const T& expected, const U& actual, const T&
} }
template <> template <>
testing::AssertionResult CheckImpl<utils::RGBA8>(const utils::RGBA8& expected, testing::AssertionResult CheckImpl<dawn::utils::RGBA8>(const dawn::utils::RGBA8& expected,
const utils::RGBA8& actual, const dawn::utils::RGBA8& actual,
const utils::RGBA8& tolerance) { const dawn::utils::RGBA8& tolerance) {
if (abs(expected.r - actual.r) > tolerance.r || abs(expected.g - actual.g) > tolerance.g || if (abs(expected.r - actual.r) > tolerance.r || abs(expected.g - actual.g) > tolerance.g ||
abs(expected.b - actual.b) > tolerance.b || abs(expected.a - actual.a) > tolerance.a) { abs(expected.b - actual.b) > tolerance.b || abs(expected.a - actual.a) > tolerance.a) {
return tolerance == utils::RGBA8{} return tolerance == dawn::utils::RGBA8{}
? testing::AssertionFailure() << expected << ", actual " << actual ? testing::AssertionFailure() << expected << ", actual " << actual
: testing::AssertionFailure() : testing::AssertionFailure()
<< "within " << tolerance << " of " << expected << ", actual " << actual; << "within " << tolerance << " of " << expected << ", actual " << actual;
@ -1767,7 +1770,7 @@ template <>
testing::AssertionResult CheckImpl<float, uint16_t>(const float& expected, testing::AssertionResult CheckImpl<float, uint16_t>(const float& expected,
const uint16_t& actual, const uint16_t& actual,
const float& tolerance) { const float& tolerance) {
float actualF32 = Float16ToFloat32(actual); float actualF32 = dawn::Float16ToFloat32(actual);
if (abs(expected - actualF32) > tolerance) { if (abs(expected - actualF32) > tolerance) {
return tolerance == 0.0 return tolerance == 0.0
? testing::AssertionFailure() << expected << ", actual " << actualF32 ? testing::AssertionFailure() << expected << ", actual " << actualF32
@ -1835,7 +1838,7 @@ template class ExpectEq<uint8_t>;
template class ExpectEq<uint16_t>; template class ExpectEq<uint16_t>;
template class ExpectEq<uint32_t>; template class ExpectEq<uint32_t>;
template class ExpectEq<uint64_t>; template class ExpectEq<uint64_t>;
template class ExpectEq<utils::RGBA8>; template class ExpectEq<dawn::utils::RGBA8>;
template class ExpectEq<float>; template class ExpectEq<float>;
template class ExpectEq<float, uint16_t>; template class ExpectEq<float, uint16_t>;
@ -1892,5 +1895,5 @@ testing::AssertionResult ExpectBetweenColors<T>::Check(const void* data, size_t
return testing::AssertionSuccess(); return testing::AssertionSuccess();
} }
template class ExpectBetweenColors<utils::RGBA8>; template class ExpectBetweenColors<dawn::utils::RGBA8>;
} // namespace detail } // namespace detail

View File

@ -127,11 +127,11 @@
struct GLFWwindow; struct GLFWwindow;
namespace utils { namespace dawn::utils {
class PlatformDebugLogger; class PlatformDebugLogger;
class TerribleCommandBuffer; class TerribleCommandBuffer;
class WireHelper; class WireHelper;
} // namespace utils } // namespace dawn::utils
namespace detail { namespace detail {
class Expectation; class Expectation;
@ -214,7 +214,7 @@ class DawnTestEnvironment : public testing::Environment {
std::vector<wgpu::AdapterType> mDevicePreferences; std::vector<wgpu::AdapterType> mDevicePreferences;
std::vector<TestAdapterProperties> mAdapterProperties; std::vector<TestAdapterProperties> mAdapterProperties;
std::unique_ptr<utils::PlatformDebugLogger> mPlatformDebugLogger; std::unique_ptr<dawn::utils::PlatformDebugLogger> mPlatformDebugLogger;
}; };
class DawnTestBase { class DawnTestBase {
@ -352,8 +352,9 @@ class DawnTestBase {
uint32_t level = 0, uint32_t level = 0,
wgpu::TextureAspect aspect = wgpu::TextureAspect::All, wgpu::TextureAspect aspect = wgpu::TextureAspect::All,
uint32_t bytesPerRow = 0) { uint32_t bytesPerRow = 0) {
uint32_t texelBlockSize = utils::GetTexelBlockSizeInBytes(format); uint32_t texelBlockSize = dawn::utils::GetTexelBlockSizeInBytes(format);
uint32_t texelComponentCount = utils::GetWGSLRenderableColorTextureComponentCount(format); uint32_t texelComponentCount =
dawn::utils::GetWGSLRenderableColorTextureComponentCount(format);
return AddTextureExpectationImpl( return AddTextureExpectationImpl(
file, line, std::move(targetDevice), file, line, std::move(targetDevice),
@ -583,9 +584,9 @@ class DawnTestBase {
void* GetUniqueUserdata(); void* GetUniqueUserdata();
private: private:
utils::ScopedAutoreleasePool mObjCAutoreleasePool; dawn::utils::ScopedAutoreleasePool mObjCAutoreleasePool;
AdapterTestParam mParam; AdapterTestParam mParam;
std::unique_ptr<utils::WireHelper> mWireHelper; std::unique_ptr<dawn::utils::WireHelper> mWireHelper;
wgpu::Instance mInstance; wgpu::Instance mInstance;
wgpu::Adapter mAdapter; wgpu::Adapter mAdapter;
@ -836,7 +837,7 @@ extern template class ExpectEq<uint8_t>;
extern template class ExpectEq<int16_t>; extern template class ExpectEq<int16_t>;
extern template class ExpectEq<uint32_t>; extern template class ExpectEq<uint32_t>;
extern template class ExpectEq<uint64_t>; extern template class ExpectEq<uint64_t>;
extern template class ExpectEq<utils::RGBA8>; extern template class ExpectEq<dawn::utils::RGBA8>;
extern template class ExpectEq<float>; extern template class ExpectEq<float>;
extern template class ExpectEq<float, uint16_t>; extern template class ExpectEq<float, uint16_t>;
@ -858,7 +859,7 @@ class ExpectBetweenColors : public Expectation {
// A color is considered between color0 and color1 when all channel values are within range of // A color is considered between color0 and color1 when all channel values are within range of
// each counterparts. It doesn't matter which value is higher or lower. Essentially color = // each counterparts. It doesn't matter which value is higher or lower. Essentially color =
// lerp(color0, color1, t) where t is [0,1]. But I don't want to be too strict here. // lerp(color0, color1, t) where t is [0,1]. But I don't want to be too strict here.
extern template class ExpectBetweenColors<utils::RGBA8>; extern template class ExpectBetweenColors<dawn::utils::RGBA8>;
class CustomTextureExpectation : public Expectation { class CustomTextureExpectation : public Expectation {
public: public:

View File

@ -47,6 +47,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
namespace dawn {
namespace { namespace {
using testing::_; using testing::_;
@ -58,9 +59,9 @@ class AdapterDiscoveryTests : public ::testing::Test {};
#if defined(DAWN_ENABLE_BACKEND_VULKAN) #if defined(DAWN_ENABLE_BACKEND_VULKAN)
// Test only discovering the SwiftShader adapter // Test only discovering the SwiftShader adapter
TEST(AdapterDiscoveryTests, OnlySwiftShader) { TEST(AdapterDiscoveryTests, OnlySwiftShader) {
dawn::native::Instance instance; native::Instance instance;
dawn::native::vulkan::AdapterDiscoveryOptions options; native::vulkan::AdapterDiscoveryOptions options;
options.forceSwiftShader = true; options.forceSwiftShader = true;
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
@ -78,9 +79,9 @@ TEST(AdapterDiscoveryTests, OnlySwiftShader) {
// Test discovering only Vulkan adapters // Test discovering only Vulkan adapters
TEST(AdapterDiscoveryTests, OnlyVulkan) { TEST(AdapterDiscoveryTests, OnlyVulkan) {
dawn::native::Instance instance; native::Instance instance;
dawn::native::vulkan::AdapterDiscoveryOptions options; native::vulkan::AdapterDiscoveryOptions options;
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
const auto& adapters = instance.GetAdapters(); const auto& adapters = instance.GetAdapters();
@ -96,9 +97,9 @@ TEST(AdapterDiscoveryTests, OnlyVulkan) {
#if defined(DAWN_ENABLE_BACKEND_D3D11) #if defined(DAWN_ENABLE_BACKEND_D3D11)
// Test discovering only D3D11 adapters // Test discovering only D3D11 adapters
TEST(AdapterDiscoveryTests, OnlyD3D11) { TEST(AdapterDiscoveryTests, OnlyD3D11) {
dawn::native::Instance instance; native::Instance instance;
dawn::native::d3d11::AdapterDiscoveryOptions options; native::d3d11::AdapterDiscoveryOptions options;
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
const auto& adapters = instance.GetAdapters(); const auto& adapters = instance.GetAdapters();
@ -124,9 +125,9 @@ TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D11) {
break; // No more adapters to enumerate. break; // No more adapters to enumerate.
} }
dawn::native::Instance instance; native::Instance instance;
dawn::native::d3d11::AdapterDiscoveryOptions options; native::d3d11::AdapterDiscoveryOptions options;
options.dxgiAdapter = std::move(dxgiAdapter); options.dxgiAdapter = std::move(dxgiAdapter);
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
@ -144,9 +145,9 @@ TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D11) {
#if defined(DAWN_ENABLE_BACKEND_D3D12) #if defined(DAWN_ENABLE_BACKEND_D3D12)
// Test discovering only D3D12 adapters // Test discovering only D3D12 adapters
TEST(AdapterDiscoveryTests, OnlyD3D12) { TEST(AdapterDiscoveryTests, OnlyD3D12) {
dawn::native::Instance instance; native::Instance instance;
dawn::native::d3d12::AdapterDiscoveryOptions options; native::d3d12::AdapterDiscoveryOptions options;
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
const auto& adapters = instance.GetAdapters(); const auto& adapters = instance.GetAdapters();
@ -172,9 +173,9 @@ TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D12) {
break; // No more adapters to enumerate. break; // No more adapters to enumerate.
} }
dawn::native::Instance instance; native::Instance instance;
dawn::native::d3d12::AdapterDiscoveryOptions options; native::d3d12::AdapterDiscoveryOptions options;
options.dxgiAdapter = std::move(dxgiAdapter); options.dxgiAdapter = std::move(dxgiAdapter);
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
@ -192,9 +193,9 @@ TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D12) {
#if defined(DAWN_ENABLE_BACKEND_METAL) #if defined(DAWN_ENABLE_BACKEND_METAL)
// Test discovering only Metal adapters // Test discovering only Metal adapters
TEST(AdapterDiscoveryTests, OnlyMetal) { TEST(AdapterDiscoveryTests, OnlyMetal) {
dawn::native::Instance instance; native::Instance instance;
dawn::native::metal::AdapterDiscoveryOptions options; native::metal::AdapterDiscoveryOptions options;
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
const auto& adapters = instance.GetAdapters(); const auto& adapters = instance.GetAdapters();
@ -211,10 +212,10 @@ TEST(AdapterDiscoveryTests, OnlyMetal) {
// Test discovering the Metal backend, then the Vulkan backend // Test discovering the Metal backend, then the Vulkan backend
// does not duplicate adapters. // does not duplicate adapters.
TEST(AdapterDiscoveryTests, OneBackendThenTheOther) { TEST(AdapterDiscoveryTests, OneBackendThenTheOther) {
dawn::native::Instance instance; native::Instance instance;
uint32_t metalAdapterCount = 0; uint32_t metalAdapterCount = 0;
{ {
dawn::native::metal::AdapterDiscoveryOptions options; native::metal::AdapterDiscoveryOptions options;
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
const auto& adapters = instance.GetAdapters(); const auto& adapters = instance.GetAdapters();
@ -227,7 +228,7 @@ TEST(AdapterDiscoveryTests, OneBackendThenTheOther) {
} }
} }
{ {
dawn::native::vulkan::AdapterDiscoveryOptions options; native::vulkan::AdapterDiscoveryOptions options;
instance.DiscoverAdapters(&options); instance.DiscoverAdapters(&options);
uint32_t metalAdapterCount2 = 0; uint32_t metalAdapterCount2 = 0;
@ -445,3 +446,4 @@ TEST_F(AdapterCreationTest, GetInstance) {
} }
} // anonymous namespace } // anonymous namespace
} // namespace dawn

View File

@ -22,6 +22,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr static uint32_t kRTSize = 8; constexpr static uint32_t kRTSize = 8;
class BindGroupTests : public DawnTest { class BindGroupTests : public DawnTest {
@ -1330,8 +1333,8 @@ TEST_P(BindGroupTests, ArbitraryBindingNumbers) {
// This is a regression test for crbug.com/dawn/355 which tests that destruction of a bind group // This is a regression test for crbug.com/dawn/355 which tests that destruction of a bind group
// that holds the last reference to its bind group layout does not result in a use-after-free. In // that holds the last reference to its bind group layout does not result in a use-after-free. In
// the bug, the destructor of BindGroupBase, when destroying member mLayout, // the bug, the destructor of BindGroupBase, when destroying member mLayout,
// Ref<BindGroupLayoutBase> assigns to Ref::mPointee, AFTER calling Release(). After the BGL is // Ref<BindGroupLayoutBase> assigns to Ref::mPointee, AFTER calling Release(). After the BGL
// destroyed, the storage for |mPointee| has been freed. // is destroyed, the storage for |mPointee| has been freed.
TEST_P(BindGroupTests, LastReferenceToBindGroupLayout) { TEST_P(BindGroupTests, LastReferenceToBindGroupLayout) {
wgpu::BufferDescriptor bufferDesc; wgpu::BufferDescriptor bufferDesc;
bufferDesc.size = sizeof(float); bufferDesc.size = sizeof(float);
@ -1513,3 +1516,6 @@ DAWN_INSTANTIATE_TEST(BindGroupTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // namespace
} // namespace dawn

View File

@ -20,20 +20,21 @@
#include "dawn/utils/TestUtils.h" #include "dawn/utils/TestUtils.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
#define EXPECT_LAZY_CLEAR(N, statement) \ namespace dawn {
do { \
if (UsesWire()) { \
statement; \
} else { \
size_t lazyClearsBefore = dawn::native::GetLazyClearCountForTesting(device.Get()); \
statement; \
size_t lazyClearsAfter = dawn::native::GetLazyClearCountForTesting(device.Get()); \
EXPECT_EQ(N, lazyClearsAfter - lazyClearsBefore); \
} \
} while (0)
namespace { namespace {
#define EXPECT_LAZY_CLEAR(N, statement) \
do { \
if (UsesWire()) { \
statement; \
} else { \
size_t lazyClearsBefore = native::GetLazyClearCountForTesting(device.Get()); \
statement; \
size_t lazyClearsAfter = native::GetLazyClearCountForTesting(device.Get()); \
EXPECT_EQ(N, lazyClearsAfter - lazyClearsBefore); \
} \
} while (0)
struct BufferZeroInitInCopyT2BSpec { struct BufferZeroInitInCopyT2BSpec {
wgpu::Extent3D textureSize; wgpu::Extent3D textureSize;
uint64_t bufferOffset; uint64_t bufferOffset;
@ -43,8 +44,6 @@ struct BufferZeroInitInCopyT2BSpec {
uint32_t lazyClearCount; uint32_t lazyClearCount;
}; };
} // anonymous namespace
class BufferZeroInitTest : public DawnTest { class BufferZeroInitTest : public DawnTest {
protected: protected:
std::vector<wgpu::FeatureName> GetRequiredFeatures() override { std::vector<wgpu::FeatureName> GetRequiredFeatures() override {
@ -1388,3 +1387,6 @@ DAWN_INSTANTIATE_TEST(BufferZeroInitTest,
OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}), OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}),
OpenGLESBackend({"nonzero_clear_resources_on_creation_for_testing"}), OpenGLESBackend({"nonzero_clear_resources_on_creation_for_testing"}),
VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"})); VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}));
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class ClipSpaceTest : public DawnTest { class ClipSpaceTest : public DawnTest {
protected: protected:
wgpu::RenderPipeline CreatePipelineForTest() { wgpu::RenderPipeline CreatePipelineForTest() {
@ -99,3 +102,6 @@ DAWN_INSTANTIATE_TEST(ClipSpaceTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -24,6 +24,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr static unsigned int kRTSize = 64; constexpr static unsigned int kRTSize = 64;
class ColorStateTest : public DawnTest { class ColorStateTest : public DawnTest {
@ -1195,3 +1198,6 @@ DAWN_INSTANTIATE_TEST(ColorStateTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -15,6 +15,9 @@
#include "dawn/tests/DawnTest.h" #include "dawn/tests/DawnTest.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class CommandEncoderTests : public DawnTest {}; class CommandEncoderTests : public DawnTest {};
// Tests WriteBuffer commands on CommandEncoder. // Tests WriteBuffer commands on CommandEncoder.
@ -52,3 +55,6 @@ DAWN_INSTANTIATE_TEST(CommandEncoderTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -23,6 +23,9 @@
#include "dawn/utils/TextureUtils.h" #include "dawn/utils/TextureUtils.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
// The helper struct to configure the copies between buffers and textures. // The helper struct to configure the copies between buffers and textures.
struct CopyConfig { struct CopyConfig {
wgpu::TextureDescriptor textureDescriptor; wgpu::TextureDescriptor textureDescriptor;
@ -34,10 +37,8 @@ struct CopyConfig {
uint32_t rowsPerImage = wgpu::kCopyStrideUndefined; uint32_t rowsPerImage = wgpu::kCopyStrideUndefined;
}; };
namespace {
using TextureFormat = wgpu::TextureFormat; using TextureFormat = wgpu::TextureFormat;
DAWN_TEST_PARAM_STRUCT(CompressedTextureFormatTestParams, TextureFormat); DAWN_TEST_PARAM_STRUCT(CompressedTextureFormatTestParams, TextureFormat);
} // namespace
class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureFormatTestParams> { class CompressedTextureFormatTest : public DawnTestWithParams<CompressedTextureFormatTestParams> {
protected: protected:
@ -1324,3 +1325,6 @@ DAWN_INSTANTIATE_TEST_P(CompressedTextureWriteTextureTest,
OpenGLESBackend(), VulkanBackend()}, OpenGLESBackend(), VulkanBackend()},
std::vector<wgpu::TextureFormat>(utils::kCompressedFormats.begin(), std::vector<wgpu::TextureFormat>(utils::kCompressedFormats.begin(),
utils::kCompressedFormats.end())); utils::kCompressedFormats.end()));
} // anonymous namespace
} // namespace dawn

View File

@ -18,6 +18,9 @@
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class ComputeCopyStorageBufferTests : public DawnTest { class ComputeCopyStorageBufferTests : public DawnTest {
public: public:
static constexpr int kInstances = 4; static constexpr int kInstances = 4;
@ -151,3 +154,6 @@ DAWN_INSTANTIATE_TEST(ComputeCopyStorageBufferTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -18,6 +18,9 @@
#include "dawn/tests/DawnTest.h" #include "dawn/tests/DawnTest.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr static std::initializer_list<uint32_t> kSentinelData{0, 0, 0}; constexpr static std::initializer_list<uint32_t> kSentinelData{0, 0, 0};
class ComputeDispatchTests : public DawnTest { class ComputeDispatchTests : public DawnTest {
@ -319,3 +322,6 @@ DAWN_INSTANTIATE_TEST(ComputeDispatchTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -18,6 +18,9 @@
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
// Tests flow control in WGSL shaders. This helps to identify bugs either in Tint's WGSL // Tests flow control in WGSL shaders. This helps to identify bugs either in Tint's WGSL
// compilation, or driver shader compilation. // compilation, or driver shader compilation.
class ComputeFlowControlTests : public DawnTest { class ComputeFlowControlTests : public DawnTest {
@ -506,3 +509,6 @@ DAWN_INSTANTIATE_TEST(ComputeFlowControlTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -22,6 +22,7 @@
#include "dawn/tests/DawnTest.h" #include "dawn/tests/DawnTest.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
// Helper for replacing all occurrences of substr in str with replacement // Helper for replacing all occurrences of substr in str with replacement
@ -594,9 +595,9 @@ fn main() {
})"; })";
// https://www.w3.org/TR/WGSL/#alignment-and-size // https://www.w3.org/TR/WGSL/#alignment-and-size
// Structure size: roundUp(AlignOf(S), OffsetOf(S, L) + SizeOf(S, L)) // Structure size: RoundUp(AlignOf(S), OffsetOf(S, L) + SizeOf(S, L))
// https://www.w3.org/TR/WGSL/#storage-class-constraints // https://www.w3.org/TR/WGSL/#storage-class-constraints
// RequiredAlignOf(S, uniform): roundUp(16, max(AlignOf(T0), ..., AlignOf(TN))) // RequiredAlignOf(S, uniform): RoundUp(16, max(AlignOf(T0), ..., AlignOf(TN)))
uint32_t dataAlign = isUniform ? std::max(size_t(16u), field.GetAlign()) : field.GetAlign(); uint32_t dataAlign = isUniform ? std::max(size_t(16u), field.GetAlign()) : field.GetAlign();
// https://www.w3.org/TR/WGSL/#structure-layout-rules // https://www.w3.org/TR/WGSL/#structure-layout-rules
@ -1152,4 +1153,5 @@ INSTANTIATE_TEST_SUITE_P(,
DawnTestBase::PrintToStringParamName("ComputeLayoutMemoryBufferTests")); DawnTestBase::PrintToStringParamName("ComputeLayoutMemoryBufferTests"));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ComputeLayoutMemoryBufferTests); GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ComputeLayoutMemoryBufferTests);
} // namespace } // anonymous namespace
} // namespace dawn

View File

@ -18,6 +18,9 @@
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class ComputeSharedMemoryTests : public DawnTest { class ComputeSharedMemoryTests : public DawnTest {
public: public:
static constexpr uint32_t kInstances = 11; static constexpr uint32_t kInstances = 11;
@ -204,3 +207,6 @@ DAWN_INSTANTIATE_TEST(ComputeSharedMemoryTests,
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend(), VulkanBackend(),
VulkanBackend({}, {"use_vulkan_zero_initialize_workgroup_memory_extension"})); VulkanBackend({}, {"use_vulkan_zero_initialize_workgroup_memory_extension"}));
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/tests/DawnTest.h" #include "dawn/tests/DawnTest.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class ComputeStorageBufferBarrierTests : public DawnTest { class ComputeStorageBufferBarrierTests : public DawnTest {
protected: protected:
static constexpr uint32_t kNumValues = 100; static constexpr uint32_t kNumValues = 100;
@ -415,3 +418,6 @@ DAWN_INSTANTIATE_TEST(ComputeStorageBufferBarrierTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -18,6 +18,7 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
wgpu::Texture Create2DTexture(wgpu::Device device, wgpu::Texture Create2DTexture(wgpu::Device device,
@ -275,7 +276,6 @@ class CopyExternalTextureForBrowserTests_Basic
EXPECT_TEXTURE_EQ(expected.data(), dstTexture, dstOrigin, copySize); EXPECT_TEXTURE_EQ(expected.data(), dstTexture, dstOrigin, copySize);
} }
}; };
} // anonymous namespace
TEST_P(CopyExternalTextureForBrowserTests_Basic, Copy) { TEST_P(CopyExternalTextureForBrowserTests_Basic, Copy) {
DAWN_SUPPRESS_TEST_IF(IsOpenGLES()); DAWN_SUPPRESS_TEST_IF(IsOpenGLES());
@ -386,3 +386,6 @@ DAWN_INSTANTIATE_TEST_P(
CopyRect::BottomRight, CopyRect::FullSize}), CopyRect::BottomRight, CopyRect::FullSize}),
std::vector<ScaleType>({ScaleType::UpScale, ScaleType::DownScale, ScaleType::NoScale}), std::vector<ScaleType>({ScaleType::UpScale, ScaleType::DownScale, ScaleType::NoScale}),
std::vector<FlipY>({false, true})); std::vector<FlipY>({false, true}));
} // anonymous namespace
} // namespace dawn

View File

@ -23,6 +23,9 @@
#include "dawn/utils/TextureUtils.h" #include "dawn/utils/TextureUtils.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
// For MinimumBufferSpec bytesPerRow and rowsPerImage, compute a default from the copy extent. // For MinimumBufferSpec bytesPerRow and rowsPerImage, compute a default from the copy extent.
constexpr uint32_t kStrideComputeDefault = 0xFFFF'FFFEul; constexpr uint32_t kStrideComputeDefault = 0xFFFF'FFFEul;
@ -2922,3 +2925,6 @@ DAWN_INSTANTIATE_TEST(T2TCopyFromDirtyHeapTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -22,7 +22,9 @@
#include "dawn/utils/TextureUtils.h" #include "dawn/utils/TextureUtils.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
static constexpr wgpu::TextureFormat kTextureFormat = wgpu::TextureFormat::RGBA8Unorm; static constexpr wgpu::TextureFormat kTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
// Set default texture size to single line texture for color conversion tests. // Set default texture size to single line texture for color conversion tests.
@ -148,7 +150,6 @@ static constexpr std::array<ColorSpaceInfo, kSupportedColorSpaceCount> ColorSpac
} }
// //
}}; }};
} // anonymous namespace
template <typename Parent> template <typename Parent>
class CopyTextureForBrowserTests : public Parent { class CopyTextureForBrowserTests : public Parent {
@ -1225,3 +1226,6 @@ DAWN_INSTANTIATE_TEST_P(CopyTextureForBrowser_ColorSpace,
wgpu::AlphaMode::Unpremultiplied}), wgpu::AlphaMode::Unpremultiplied}),
std::vector<wgpu::AlphaMode>({wgpu::AlphaMode::Premultiplied, std::vector<wgpu::AlphaMode>({wgpu::AlphaMode::Premultiplied,
wgpu::AlphaMode::Unpremultiplied})); wgpu::AlphaMode::Unpremultiplied}));
} // anonymous namespace
} // namespace dawn

View File

@ -18,14 +18,15 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
struct CreatePipelineAsyncTask { struct CreatePipelineAsyncTask {
wgpu::ComputePipeline computePipeline = nullptr; wgpu::ComputePipeline computePipeline = nullptr;
wgpu::RenderPipeline renderPipeline = nullptr; wgpu::RenderPipeline renderPipeline = nullptr;
bool isCompleted = false; bool isCompleted = false;
std::string message; std::string message;
}; };
} // anonymous namespace
class CreatePipelineAsyncTest : public DawnTest { class CreatePipelineAsyncTest : public DawnTest {
protected: protected:
@ -961,3 +962,6 @@ DAWN_INSTANTIATE_TEST(CreatePipelineAsyncTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class CullingTest : public DawnTest { class CullingTest : public DawnTest {
protected: protected:
wgpu::RenderPipeline CreatePipelineForTest(wgpu::FrontFace frontFace, wgpu::CullMode cullMode) { wgpu::RenderPipeline CreatePipelineForTest(wgpu::FrontFace frontFace, wgpu::CullMode cullMode) {
@ -133,3 +136,6 @@ DAWN_INSTANTIATE_TEST(CullingTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -21,9 +21,10 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
using ::testing::NiceMock; using ::testing::NiceMock;
} // namespace
class D3D12CachingTests : public DawnTest { class D3D12CachingTests : public DawnTest {
protected: protected:
@ -33,7 +34,7 @@ class D3D12CachingTests : public DawnTest {
DAWN_SKIP_TEST_IF_BASE(true, "suppressed", "TODO(dawn:1341)"); DAWN_SKIP_TEST_IF_BASE(true, "suppressed", "TODO(dawn:1341)");
} }
std::unique_ptr<dawn::platform::Platform> CreateTestPlatform() override { std::unique_ptr<platform::Platform> CreateTestPlatform() override {
return std::make_unique<DawnCachingMockPlatform>(&mMockCache); return std::make_unique<DawnCachingMockPlatform>(&mMockCache);
} }
@ -181,3 +182,6 @@ TEST_P(D3D12CachingTests, ReuseShaderWithMultipleEntryPoints) {
} }
DAWN_INSTANTIATE_TEST(D3D12CachingTests, D3D12Backend()); DAWN_INSTANTIATE_TEST(D3D12CachingTests, D3D12Backend());
} // anonymous namespace
} // namespace dawn

View File

@ -32,6 +32,7 @@
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
namespace dawn {
namespace { namespace {
class D3DResourceTestBase : public DawnTest { class D3DResourceTestBase : public DawnTest {
@ -48,8 +49,7 @@ class D3DResourceTestBase : public DawnTest {
} }
// Create the D3D11 device/contexts that will be used in subsequent tests // Create the D3D11 device/contexts that will be used in subsequent tests
ComPtr<IDXGIAdapter> dxgiAdapter = ComPtr<IDXGIAdapter> dxgiAdapter = native::d3d::GetDXGIAdapter(device.GetAdapter().Get());
dawn::native::d3d::GetDXGIAdapter(device.GetAdapter().Get());
DXGI_ADAPTER_DESC adapterDesc; DXGI_ADAPTER_DESC adapterDesc;
HRESULT hr = dxgiAdapter->GetDesc(&adapterDesc); HRESULT hr = dxgiAdapter->GetDesc(&adapterDesc);
@ -98,7 +98,7 @@ class D3DResourceTestBase : public DawnTest {
} }
protected: protected:
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> CreateExternalImage( std::unique_ptr<native::d3d::ExternalImageDXGI> CreateExternalImage(
WGPUDevice targetDevice, WGPUDevice targetDevice,
ID3D11Texture2D* d3d11Texture, ID3D11Texture2D* d3d11Texture,
const wgpu::TextureDescriptor* dawnDesc) const { const wgpu::TextureDescriptor* dawnDesc) const {
@ -111,13 +111,13 @@ class D3DResourceTestBase : public DawnTest {
&textureSharedHandle), &textureSharedHandle),
S_OK); S_OK);
dawn::native::d3d::ExternalImageDescriptorDXGISharedHandle externalImageDesc; native::d3d::ExternalImageDescriptorDXGISharedHandle externalImageDesc;
externalImageDesc.cTextureDescriptor = externalImageDesc.cTextureDescriptor =
reinterpret_cast<const WGPUTextureDescriptor*>(dawnDesc); reinterpret_cast<const WGPUTextureDescriptor*>(dawnDesc);
externalImageDesc.sharedHandle = textureSharedHandle; externalImageDesc.sharedHandle = textureSharedHandle;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage = std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage =
dawn::native::d3d::ExternalImageDXGI::Create(targetDevice, &externalImageDesc); native::d3d::ExternalImageDXGI::Create(targetDevice, &externalImageDesc);
// Now that we've created all of our resources, we can close the handle // Now that we've created all of our resources, we can close the handle
// since we no longer need it. // since we no longer need it.
@ -126,17 +126,16 @@ class D3DResourceTestBase : public DawnTest {
return externalImage; return externalImage;
} }
void WrapSharedHandle( void WrapSharedHandle(const wgpu::TextureDescriptor* dawnDesc,
const wgpu::TextureDescriptor* dawnDesc, const D3D11_TEXTURE2D_DESC* baseD3dDescriptor,
const D3D11_TEXTURE2D_DESC* baseD3dDescriptor, wgpu::Texture* dawnTexture,
wgpu::Texture* dawnTexture, ID3D11Texture2D** d3d11TextureOut,
ID3D11Texture2D** d3d11TextureOut, std::unique_ptr<native::d3d::ExternalImageDXGI>* externalImageOut) const {
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI>* externalImageOut) const {
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
HRESULT hr = mD3d11Device->CreateTexture2D(baseD3dDescriptor, nullptr, &d3d11Texture); HRESULT hr = mD3d11Device->CreateTexture2D(baseD3dDescriptor, nullptr, &d3d11Texture);
ASSERT_EQ(hr, S_OK); ASSERT_EQ(hr, S_OK);
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage = std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage =
CreateExternalImage(device.Get(), d3d11Texture.Get(), dawnDesc); CreateExternalImage(device.Get(), d3d11Texture.Get(), dawnDesc);
// Cannot access a non-existent external image (ex. validation error). // Cannot access a non-existent external image (ex. validation error).
@ -144,7 +143,7 @@ class D3DResourceTestBase : public DawnTest {
return; return;
} }
dawn::native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc; native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc;
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(dawnDesc->usage); externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(dawnDesc->usage);
*dawnTexture = wgpu::Texture::Acquire(externalImage->BeginAccess(&externalAccessDesc)); *dawnTexture = wgpu::Texture::Acquire(externalImage->BeginAccess(&externalAccessDesc));
@ -165,8 +164,6 @@ class D3DResourceTestBase : public DawnTest {
wgpu::TextureDescriptor baseDawnDescriptor; wgpu::TextureDescriptor baseDawnDescriptor;
}; };
} // anonymous namespace
// A small fixture used to initialize default data for the D3DResource validation tests. // A small fixture used to initialize default data for the D3DResource validation tests.
// These tests are skipped if the harness is using the wire. // These tests are skipped if the harness is using the wire.
class D3DSharedHandleValidation : public D3DResourceTestBase {}; class D3DSharedHandleValidation : public D3DResourceTestBase {};
@ -177,13 +174,13 @@ TEST_P(D3DSharedHandleValidation, Success) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
texture.Destroy(); texture.Destroy();
} }
@ -199,13 +196,13 @@ TEST_P(D3DSharedHandleValidation, SuccessWithInternalUsageDescriptor) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
texture.Destroy(); texture.Destroy();
} }
@ -220,7 +217,7 @@ TEST_P(D3DSharedHandleValidation, InvalidTextureDescriptor) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -234,7 +231,7 @@ TEST_P(D3DSharedHandleValidation, InvalidMipLevelCount) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -248,7 +245,7 @@ TEST_P(D3DSharedHandleValidation, InvalidDepth) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -262,7 +259,7 @@ TEST_P(D3DSharedHandleValidation, InvalidSampleCount) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -276,7 +273,7 @@ TEST_P(D3DSharedHandleValidation, InvalidWidth) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -290,7 +287,7 @@ TEST_P(D3DSharedHandleValidation, InvalidHeight) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -304,7 +301,7 @@ TEST_P(D3DSharedHandleValidation, InvalidFormat) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -318,7 +315,7 @@ TEST_P(D3DSharedHandleValidation, InvalidNumD3DMipLevels) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -332,7 +329,7 @@ TEST_P(D3DSharedHandleValidation, InvalidD3DArraySize) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, ASSERT_DEVICE_ERROR(WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture,
&d3d11Texture, &externalImage)); &d3d11Texture, &externalImage));
@ -438,23 +435,22 @@ class D3DSharedHandleUsageTests : public D3DResourceTestBase {
d3d11DeviceContext4->Signal(d3d11Fence, fenceSignalValue); d3d11DeviceContext4->Signal(d3d11Fence, fenceSignalValue);
} }
void WaitAndWrapD3D11Texture( void WaitAndWrapD3D11Texture(const wgpu::TextureDescriptor& dawnDescriptor,
const wgpu::TextureDescriptor& dawnDescriptor, HANDLE sharedHandle,
HANDLE sharedHandle, HANDLE fenceSharedHandle,
HANDLE fenceSharedHandle, uint64_t fenceWaitValue,
uint64_t fenceWaitValue, wgpu::Texture* dawnTextureOut,
wgpu::Texture* dawnTextureOut, std::unique_ptr<native::d3d::ExternalImageDXGI>* externalImageOut,
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI>* externalImageOut, bool isInitialized) const {
bool isInitialized) const { native::d3d::ExternalImageDescriptorDXGISharedHandle externalImageDesc = {};
dawn::native::d3d::ExternalImageDescriptorDXGISharedHandle externalImageDesc = {};
externalImageDesc.sharedHandle = sharedHandle; externalImageDesc.sharedHandle = sharedHandle;
externalImageDesc.cTextureDescriptor = externalImageDesc.cTextureDescriptor =
reinterpret_cast<const WGPUTextureDescriptor*>(&dawnDescriptor); reinterpret_cast<const WGPUTextureDescriptor*>(&dawnDescriptor);
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage = std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage =
dawn::native::d3d::ExternalImageDXGI::Create(device.Get(), &externalImageDesc); native::d3d::ExternalImageDXGI::Create(device.Get(), &externalImageDesc);
dawn::native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc; native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc;
externalAccessDesc.isInitialized = isInitialized; externalAccessDesc.isInitialized = isInitialized;
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(dawnDescriptor.usage); externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(dawnDescriptor.usage);
if (fenceSharedHandle != nullptr) { if (fenceSharedHandle != nullptr) {
@ -465,14 +461,13 @@ class D3DSharedHandleUsageTests : public D3DResourceTestBase {
*externalImageOut = std::move(externalImage); *externalImageOut = std::move(externalImage);
} }
void WrapAndClearD3D11Texture( void WrapAndClearD3D11Texture(const wgpu::TextureDescriptor& dawnDescriptor,
const wgpu::TextureDescriptor& dawnDescriptor, const D3D11_TEXTURE2D_DESC& d3dDescriptor,
const D3D11_TEXTURE2D_DESC& d3dDescriptor, const wgpu::Color& clearColor,
const wgpu::Color& clearColor, wgpu::Texture* dawnTextureOut,
wgpu::Texture* dawnTextureOut, ID3D11Texture2D** d3d11TextureOut,
ID3D11Texture2D** d3d11TextureOut, std::unique_ptr<native::d3d::ExternalImageDXGI>* externalImageOut,
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI>* externalImageOut, bool isInitialized = true) const {
bool isInitialized = true) const {
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
ComPtr<ID3D11Fence> d3d11Fence; ComPtr<ID3D11Fence> d3d11Fence;
HANDLE sharedHandle = nullptr; HANDLE sharedHandle = nullptr;
@ -496,7 +491,7 @@ class D3DSharedHandleUsageTests : public D3DResourceTestBase {
void ExpectPixelRGBA8EQ(ID3D11Texture2D* d3d11Texture, void ExpectPixelRGBA8EQ(ID3D11Texture2D* d3d11Texture,
const wgpu::Color& color, const wgpu::Color& color,
const dawn::native::d3d::ExternalImageDXGIFenceDescriptor* waitFence) { const native::d3d::ExternalImageDXGIFenceDescriptor* waitFence) {
D3D11_TEXTURE2D_DESC texture2DDesc; D3D11_TEXTURE2D_DESC texture2DDesc;
d3d11Texture->GetDesc(&texture2DDesc); d3d11Texture->GetDesc(&texture2DDesc);
@ -573,7 +568,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearInD3D11CopyAndReadbackInD3D) {
const wgpu::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f};
wgpu::Texture dawnSrcTexture; wgpu::Texture dawnSrcTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, clearColor, &dawnSrcTexture, WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, clearColor, &dawnSrcTexture,
&d3d11Texture, &externalImage); &d3d11Texture, &externalImage);
ASSERT_NE(dawnSrcTexture.Get(), nullptr); ASSERT_NE(dawnSrcTexture.Get(), nullptr);
@ -582,7 +577,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearInD3D11CopyAndReadbackInD3D) {
wgpu::Texture dawnCopyDestTexture = device.CreateTexture(&baseDawnDescriptor); wgpu::Texture dawnCopyDestTexture = device.CreateTexture(&baseDawnDescriptor);
SimpleCopyTextureToTexture(dawnSrcTexture, dawnCopyDestTexture); SimpleCopyTextureToTexture(dawnSrcTexture, dawnCopyDestTexture);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(dawnSrcTexture.Get(), &signalFence); externalImage->EndAccess(dawnSrcTexture.Get(), &signalFence);
dawnSrcTexture.Destroy(); dawnSrcTexture.Destroy();
@ -601,7 +596,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearInD3D11ReadbackInD3D) {
const wgpu::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color clearColor{1.0f, 1.0f, 0.0f, 1.0f};
wgpu::Texture dawnTexture; wgpu::Texture dawnTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, clearColor, &dawnTexture, WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, clearColor, &dawnTexture,
&d3d11Texture, &externalImage); &d3d11Texture, &externalImage);
ASSERT_NE(dawnTexture.Get(), nullptr); ASSERT_NE(dawnTexture.Get(), nullptr);
@ -612,7 +607,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearInD3D11ReadbackInD3D) {
clearColor.a * 255), clearColor.a * 255),
dawnTexture, 0, 0); dawnTexture, 0, 0);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(dawnTexture.Get(), &signalFence); externalImage->EndAccess(dawnTexture.Get(), &signalFence);
dawnTexture.Destroy(); dawnTexture.Destroy();
} }
@ -630,7 +625,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearInD3DReadbackInD3D11) {
const wgpu::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f};
wgpu::Texture dawnTexture; wgpu::Texture dawnTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, d3d11ClearColor, &dawnTexture, WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, d3d11ClearColor, &dawnTexture,
&d3d11Texture, &externalImage, /*isInitialized=*/true); &d3d11Texture, &externalImage, /*isInitialized=*/true);
ASSERT_NE(dawnTexture.Get(), nullptr); ASSERT_NE(dawnTexture.Get(), nullptr);
@ -638,7 +633,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearInD3DReadbackInD3D11) {
const wgpu::Color d3dClearColor{0.0f, 0.0f, 1.0f, 1.0f}; const wgpu::Color d3dClearColor{0.0f, 0.0f, 1.0f, 1.0f};
ClearImage(dawnTexture, d3dClearColor, device); ClearImage(dawnTexture, d3dClearColor, device);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(dawnTexture.Get(), &signalFence); externalImage->EndAccess(dawnTexture.Get(), &signalFence);
dawnTexture.Destroy(); dawnTexture.Destroy();
@ -662,7 +657,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearTwiceInD3DReadbackInD3D11) {
const wgpu::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f}; const wgpu::Color d3d11ClearColor{1.0f, 1.0f, 0.0f, 1.0f};
wgpu::Texture dawnTexture; wgpu::Texture dawnTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, d3d11ClearColor, &dawnTexture, WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, d3d11ClearColor, &dawnTexture,
&d3d11Texture, &externalImage, /*isInitialized=*/true); &d3d11Texture, &externalImage, /*isInitialized=*/true);
ASSERT_NE(dawnTexture.Get(), nullptr); ASSERT_NE(dawnTexture.Get(), nullptr);
@ -673,7 +668,7 @@ TEST_P(D3DSharedHandleUsageTests, ClearTwiceInD3DReadbackInD3D11) {
const wgpu::Color d3dClearColor2{0.0f, 1.0f, 1.0f, 1.0f}; const wgpu::Color d3dClearColor2{0.0f, 1.0f, 1.0f, 1.0f};
ClearImage(dawnTexture, d3dClearColor2, device); ClearImage(dawnTexture, d3dClearColor2, device);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(dawnTexture.Get(), &signalFence); externalImage->EndAccess(dawnTexture.Get(), &signalFence);
dawnTexture.Destroy(); dawnTexture.Destroy();
@ -692,7 +687,7 @@ TEST_P(D3DSharedHandleUsageTests, UninitializedTextureIsCleared) {
const wgpu::Color clearColor{1.0f, 0.0f, 0.0f, 1.0f}; const wgpu::Color clearColor{1.0f, 0.0f, 0.0f, 1.0f};
wgpu::Texture dawnTexture; wgpu::Texture dawnTexture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, clearColor, &dawnTexture, WrapAndClearD3D11Texture(baseDawnDescriptor, baseD3dDescriptor, clearColor, &dawnTexture,
&d3d11Texture, &externalImage, /*isInitialized=*/false); &d3d11Texture, &externalImage, /*isInitialized=*/false);
ASSERT_NE(dawnTexture.Get(), nullptr); ASSERT_NE(dawnTexture.Get(), nullptr);
@ -701,7 +696,7 @@ TEST_P(D3DSharedHandleUsageTests, UninitializedTextureIsCleared) {
// to clear the source texture on the D3D device. // to clear the source texture on the D3D device.
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0, 0), dawnTexture, 0, 0); EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8(0, 0, 0, 0), dawnTexture, 0, 0);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(dawnTexture.Get(), &signalFence); externalImage->EndAccess(dawnTexture.Get(), &signalFence);
dawnTexture.Destroy(); dawnTexture.Destroy();
} }
@ -715,7 +710,7 @@ TEST_P(D3DSharedHandleUsageTests, ReuseExternalImage) {
// Create the first Dawn texture then clear it to red. // Create the first Dawn texture then clear it to red.
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
{ {
@ -728,12 +723,12 @@ TEST_P(D3DSharedHandleUsageTests, ReuseExternalImage) {
// Once finished with the first texture, destroy it so we may re-acquire the external image // Once finished with the first texture, destroy it so we may re-acquire the external image
// again. // again.
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
texture.Destroy(); texture.Destroy();
// Create another Dawn texture then clear it with another color. // Create another Dawn texture then clear it with another color.
dawn::native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc; native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc;
externalAccessDesc.isInitialized = true; externalAccessDesc.isInitialized = true;
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(baseDawnDescriptor.usage); externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(baseDawnDescriptor.usage);
externalAccessDesc.waitFences.push_back(signalFence); externalAccessDesc.waitFences.push_back(signalFence);
@ -774,7 +769,7 @@ TEST_P(D3DSharedHandleUsageTests, ConcurrentExternalImageReadAccess) {
// Create Dawn texture with write access, then clear it to red. // Create Dawn texture with write access, then clear it to red.
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
@ -783,35 +778,35 @@ TEST_P(D3DSharedHandleUsageTests, ConcurrentExternalImageReadAccess) {
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
ClearImage(texture.Get(), solidRed, device); ClearImage(texture.Get(), solidRed, device);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
texture.Destroy(); texture.Destroy();
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage2 = std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage2 =
CreateExternalImage(device2.Get(), d3d11Texture.Get(), &baseDawnDescriptor); CreateExternalImage(device2.Get(), d3d11Texture.Get(), &baseDawnDescriptor);
EXPECT_NE(externalImage2, nullptr); EXPECT_NE(externalImage2, nullptr);
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage3 = std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage3 =
CreateExternalImage(device3.Get(), d3d11Texture.Get(), &baseDawnDescriptor); CreateExternalImage(device3.Get(), d3d11Texture.Get(), &baseDawnDescriptor);
EXPECT_NE(externalImage3, nullptr); EXPECT_NE(externalImage3, nullptr);
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage4 = std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage4 =
CreateExternalImage(device4.Get(), d3d11Texture.Get(), &baseDawnDescriptor); CreateExternalImage(device4.Get(), d3d11Texture.Get(), &baseDawnDescriptor);
EXPECT_NE(externalImage4, nullptr); EXPECT_NE(externalImage4, nullptr);
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage5 = std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage5 =
CreateExternalImage(device5.Get(), d3d11Texture.Get(), &baseDawnDescriptor); CreateExternalImage(device5.Get(), d3d11Texture.Get(), &baseDawnDescriptor);
EXPECT_NE(externalImage5, nullptr); EXPECT_NE(externalImage5, nullptr);
// Create two Dawn textures for concurrent read on second device. // Create two Dawn textures for concurrent read on second device.
dawn::native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc; native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc;
externalAccessDesc.isInitialized = true; externalAccessDesc.isInitialized = true;
externalAccessDesc.usage = WGPUTextureUsage_CopySrc; externalAccessDesc.usage = WGPUTextureUsage_CopySrc;
externalAccessDesc.waitFences = {signalFence}; externalAccessDesc.waitFences = {signalFence};
// Concurrent read access on device 2 and 3. // Concurrent read access on device 2 and 3.
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence2; native::d3d::ExternalImageDXGIFenceDescriptor signalFence2;
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence3; native::d3d::ExternalImageDXGIFenceDescriptor signalFence3;
{ {
wgpu::Texture texture2 = wgpu::Texture texture2 =
wgpu::Texture::Acquire(externalImage2->BeginAccess(&externalAccessDesc)); wgpu::Texture::Acquire(externalImage2->BeginAccess(&externalAccessDesc));
@ -837,7 +832,7 @@ TEST_P(D3DSharedHandleUsageTests, ConcurrentExternalImageReadAccess) {
externalAccessDesc.waitFences = {signalFence2, signalFence3}; externalAccessDesc.waitFences = {signalFence2, signalFence3};
// Exclusive read-write access on device 4. // Exclusive read-write access on device 4.
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence4; native::d3d::ExternalImageDXGIFenceDescriptor signalFence4;
{ {
wgpu::Texture texture4 = wgpu::Texture texture4 =
wgpu::Texture::Acquire(externalImage4->BeginAccess(&externalAccessDesc)); wgpu::Texture::Acquire(externalImage4->BeginAccess(&externalAccessDesc));
@ -858,7 +853,7 @@ TEST_P(D3DSharedHandleUsageTests, ConcurrentExternalImageReadAccess) {
externalAccessDesc.waitFences = {signalFence4}; externalAccessDesc.waitFences = {signalFence4};
// Import texture on device 5, but do nothing with it. // Import texture on device 5, but do nothing with it.
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence5; native::d3d::ExternalImageDXGIFenceDescriptor signalFence5;
{ {
wgpu::Texture texture5 = wgpu::Texture texture5 =
wgpu::Texture::Acquire(externalImage5->BeginAccess(&externalAccessDesc)); wgpu::Texture::Acquire(externalImage5->BeginAccess(&externalAccessDesc));
@ -914,16 +909,16 @@ TEST_P(D3DSharedHandleUsageTests, ExternalImageUsage) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
texture.Destroy(); texture.Destroy();
dawn::native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc; native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc;
externalAccessDesc.isInitialized = true; externalAccessDesc.isInitialized = true;
externalAccessDesc.usage = WGPUTextureUsage_StorageBinding; externalAccessDesc.usage = WGPUTextureUsage_StorageBinding;
externalAccessDesc.waitFences.push_back(signalFence); externalAccessDesc.waitFences.push_back(signalFence);
@ -943,7 +938,7 @@ TEST_P(D3DSharedHandleUsageTests, InvalidateExternalImageOnDestroyDevice) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
// Create the Dawn texture then clear it to red. // Create the Dawn texture then clear it to red.
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
@ -952,14 +947,14 @@ TEST_P(D3DSharedHandleUsageTests, InvalidateExternalImageOnDestroyDevice) {
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
ClearImage(texture.Get(), solidRed, device); ClearImage(texture.Get(), solidRed, device);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
texture.Destroy(); texture.Destroy();
// Do not readback pixels since that requires device to be alive during DawnTest::TearDown(). // Do not readback pixels since that requires device to be alive during DawnTest::TearDown().
DestroyDevice(); DestroyDevice();
dawn::native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc; native::d3d::ExternalImageDXGIBeginAccessDescriptor externalAccessDesc;
externalAccessDesc.isInitialized = true; externalAccessDesc.isInitialized = true;
externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(baseDawnDescriptor.usage); externalAccessDesc.usage = static_cast<WGPUTextureUsageFlags>(baseDawnDescriptor.usage);
@ -972,7 +967,7 @@ TEST_P(D3DSharedHandleUsageTests, DisallowExternalImageAfterDestroyDevice) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
DestroyDevice(); DestroyDevice();
@ -990,7 +985,7 @@ TEST_P(D3DSharedHandleUsageTests, CallWriteBufferBeforeDestroyingExternalImage)
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
@ -1000,7 +995,7 @@ TEST_P(D3DSharedHandleUsageTests, CallWriteBufferBeforeDestroyingExternalImage)
wgpu::Buffer buffer = utils::CreateBufferFromData( wgpu::Buffer buffer = utils::CreateBufferFromData(
device, wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst, {kExpected}); device, wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst, {kExpected});
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
texture.Destroy(); texture.Destroy();
externalImage = nullptr; externalImage = nullptr;
@ -1015,7 +1010,7 @@ TEST_P(D3DSharedHandleUsageTests, SRGBReinterpretation) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
// The texture will be reinterpreted as sRGB. // The texture will be reinterpreted as sRGB.
wgpu::TextureViewDescriptor viewDesc = {}; wgpu::TextureViewDescriptor viewDesc = {};
@ -1071,13 +1066,13 @@ class D3DSharedHandleMultithreadTests : public D3DSharedHandleUsageTests {
TEST_P(D3DSharedHandleMultithreadTests, DestroyDeviceBeforeImageNoDeadLock) { TEST_P(D3DSharedHandleMultithreadTests, DestroyDeviceBeforeImageNoDeadLock) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
ASSERT_NE(texture.Get(), nullptr); ASSERT_NE(texture.Get(), nullptr);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
EXPECT_TRUE(externalImage->IsValid()); EXPECT_TRUE(externalImage->IsValid());
@ -1091,7 +1086,7 @@ TEST_P(D3DSharedHandleMultithreadTests, DestroyDeviceBeforeImageNoDeadLock) {
TEST_P(D3DSharedHandleMultithreadTests, DestroyDeviceAndUseImageInParallel) { TEST_P(D3DSharedHandleMultithreadTests, DestroyDeviceAndUseImageInParallel) {
wgpu::Texture texture; wgpu::Texture texture;
ComPtr<ID3D11Texture2D> d3d11Texture; ComPtr<ID3D11Texture2D> d3d11Texture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture, WrapSharedHandle(&baseDawnDescriptor, &baseD3dDescriptor, &texture, &d3d11Texture,
&externalImage); &externalImage);
@ -1099,7 +1094,7 @@ TEST_P(D3DSharedHandleMultithreadTests, DestroyDeviceAndUseImageInParallel) {
EXPECT_TRUE(externalImage->IsValid()); EXPECT_TRUE(externalImage->IsValid());
std::thread thread1([&] { std::thread thread1([&] {
dawn::native::d3d::ExternalImageDXGIFenceDescriptor signalFence; native::d3d::ExternalImageDXGIFenceDescriptor signalFence;
externalImage->EndAccess(texture.Get(), &signalFence); externalImage->EndAccess(texture.Get(), &signalFence);
}); });
@ -1133,11 +1128,11 @@ TEST_P(D3DSharedHandleMultithreadTests, ClearInD3D12ReadbackInD3D11_TwoThreads)
CreateSharedD3D11Texture(baseD3dDescriptor, &d3d11Texture, &d3d11Fence, &sharedHandle, CreateSharedD3D11Texture(baseD3dDescriptor, &d3d11Texture, &d3d11Fence, &sharedHandle,
&fenceSharedHandle); &fenceSharedHandle);
dawn::native::d3d::ExternalImageDXGIFenceDescriptor d3dSignalFence; native::d3d::ExternalImageDXGIFenceDescriptor d3dSignalFence;
std::thread d3dThread([=, &d3dSignalFence] { std::thread d3dThread([=, &d3dSignalFence] {
wgpu::Texture dawnTexture; wgpu::Texture dawnTexture;
std::unique_ptr<dawn::native::d3d::ExternalImageDXGI> externalImage; std::unique_ptr<native::d3d::ExternalImageDXGI> externalImage;
WaitAndWrapD3D11Texture(baseDawnDescriptor, sharedHandle, fenceSharedHandle, WaitAndWrapD3D11Texture(baseDawnDescriptor, sharedHandle, fenceSharedHandle,
/*fenceWaitValue=*/kD3D11FenceSignalValue, &dawnTexture, /*fenceWaitValue=*/kD3D11FenceSignalValue, &dawnTexture,
&externalImage, /*isInitialized=*/true); &externalImage, /*isInitialized=*/true);
@ -1176,3 +1171,6 @@ TEST_P(D3DSharedHandleMultithreadTests, ClearInD3D12ReadbackInD3D11_TwoThreads)
DAWN_INSTANTIATE_TEST(D3DSharedHandleValidation, D3D11Backend(), D3D12Backend()); DAWN_INSTANTIATE_TEST(D3DSharedHandleValidation, D3D11Backend(), D3D12Backend());
DAWN_INSTANTIATE_TEST(D3DSharedHandleUsageTests, D3D11Backend(), D3D12Backend()); DAWN_INSTANTIATE_TEST(D3DSharedHandleUsageTests, D3D11Backend(), D3D12Backend());
DAWN_INSTANTIATE_TEST(D3DSharedHandleMultithreadTests, D3D11Backend(), D3D12Backend()); DAWN_INSTANTIATE_TEST(D3DSharedHandleMultithreadTests, D3D11Backend(), D3D12Backend());
} // anonymous namespace
} // namespace dawn

View File

@ -16,6 +16,9 @@
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class DebugMarkerTests : public DawnTest {}; class DebugMarkerTests : public DawnTest {};
// Make sure that calling a marker API without a debugging tool attached doesn't cause a failure. // Make sure that calling a marker API without a debugging tool attached doesn't cause a failure.
@ -52,3 +55,6 @@ DAWN_INSTANTIATE_TEST(DebugMarkerTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -22,6 +22,9 @@
#include "dawn/utils/TextureUtils.h" #include "dawn/utils/TextureUtils.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr static unsigned int kRTSize = 2; constexpr static unsigned int kRTSize = 2;
enum class QuadAngle { Flat, TiltedX }; enum class QuadAngle { Flat, TiltedX };
@ -396,3 +399,6 @@ DAWN_INSTANTIATE_TEST(DepthBiasTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -25,7 +25,9 @@
#include "dawn/utils/TextureUtils.h" #include "dawn/utils/TextureUtils.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
using TextureFormat = wgpu::TextureFormat; using TextureFormat = wgpu::TextureFormat;
DAWN_TEST_PARAM_STRUCT(DepthStencilCopyTestParams, TextureFormat); DAWN_TEST_PARAM_STRUCT(DepthStencilCopyTestParams, TextureFormat);
@ -38,7 +40,6 @@ constexpr std::array<wgpu::TextureFormat, 3> kValidDepthCopyTextureFormats = {
constexpr std::array<wgpu::TextureFormat, 1> kValidDepthCopyFromBufferFormats = { constexpr std::array<wgpu::TextureFormat, 1> kValidDepthCopyFromBufferFormats = {
wgpu::TextureFormat::Depth16Unorm, wgpu::TextureFormat::Depth16Unorm,
}; };
} // namespace
class DepthStencilCopyTests : public DawnTestWithParams<DepthStencilCopyTestParams> { class DepthStencilCopyTests : public DawnTestWithParams<DepthStencilCopyTestParams> {
protected: protected:
@ -1093,3 +1094,6 @@ DAWN_INSTANTIATE_TEST_P(
std::vector<wgpu::TextureFormat>{wgpu::TextureFormat::Depth16Unorm, std::vector<wgpu::TextureFormat>{wgpu::TextureFormat::Depth16Unorm,
wgpu::TextureFormat::Depth32FloatStencil8, wgpu::TextureFormat::Depth32FloatStencil8,
wgpu::TextureFormat::Depth24Plus}); wgpu::TextureFormat::Depth24Plus});
} // anonymous namespace
} // namespace dawn

View File

@ -19,6 +19,7 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
using Format = wgpu::TextureFormat; using Format = wgpu::TextureFormat;
@ -420,4 +421,5 @@ DAWN_INSTANTIATE_TEST_P(DepthTextureClearTwiceTest,
wgpu::TextureFormat::Depth24PlusStencil8}, wgpu::TextureFormat::Depth24PlusStencil8},
{true, false}); {true, false});
} // namespace } // anonymous namespace
} // namespace dawn

View File

@ -20,7 +20,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
using TextureFormat = wgpu::TextureFormat; using TextureFormat = wgpu::TextureFormat;
DAWN_TEST_PARAM_STRUCT(DepthStencilSamplingTestParams, TextureFormat); DAWN_TEST_PARAM_STRUCT(DepthStencilSamplingTestParams, TextureFormat);
@ -40,8 +42,6 @@ const std::vector<float> kNormalizedTextureValues = {0.0, 0.3, 0.4, 0.5, 1.0};
// Test the limits, and some values in between. // Test the limits, and some values in between.
const std::vector<uint32_t> kStencilValues = {0, 1, 38, 255}; const std::vector<uint32_t> kStencilValues = {0, 1, 38, 255};
} // anonymous namespace
class DepthStencilSamplingTest : public DawnTestWithParams<DepthStencilSamplingTestParams> { class DepthStencilSamplingTest : public DawnTestWithParams<DepthStencilSamplingTestParams> {
protected: protected:
enum class TestAspectAndSamplerType { enum class TestAspectAndSamplerType {
@ -938,3 +938,6 @@ DAWN_INSTANTIATE_TEST_P(StencilSamplingTest,
OpenGLBackend(), OpenGLESBackend(), VulkanBackend()}, OpenGLBackend(), OpenGLESBackend(), VulkanBackend()},
std::vector<wgpu::TextureFormat>(utils::kStencilFormats.begin(), std::vector<wgpu::TextureFormat>(utils::kStencilFormats.begin(),
utils::kStencilFormats.end())); utils::kStencilFormats.end()));
} // anonymous namespace
} // namespace dawn

View File

@ -19,6 +19,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr static unsigned int kRTSize = 64; constexpr static unsigned int kRTSize = 64;
class DepthStencilStateTest : public DawnTest { class DepthStencilStateTest : public DawnTest {
@ -847,3 +850,6 @@ DAWN_INSTANTIATE_TEST(DepthStencilStateTest,
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend({"vulkan_use_d32s8"}, {}), VulkanBackend({"vulkan_use_d32s8"}, {}),
VulkanBackend({}, {"vulkan_use_d32s8"})); VulkanBackend({}, {"vulkan_use_d32s8"}));
} // anonymous namespace
} // namespace dawn

View File

@ -18,6 +18,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
using ::testing::HasSubstr; using ::testing::HasSubstr;
constexpr uint32_t kRTSize = 4; constexpr uint32_t kRTSize = 4;
@ -219,3 +222,6 @@ DAWN_INSTANTIATE_TEST(DestroyTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -21,9 +21,12 @@
#include "dawn/utils/SystemUtils.h" #include "dawn/utils/SystemUtils.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class DeviceInitializationTest : public testing::Test { class DeviceInitializationTest : public testing::Test {
protected: protected:
void SetUp() override { dawnProcSetProcs(&dawn::native::GetProcs()); } void SetUp() override { dawnProcSetProcs(&native::GetProcs()); }
void TearDown() override { dawnProcSetProcs(nullptr); } void TearDown() override { dawnProcSetProcs(nullptr); }
@ -73,10 +76,10 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) {
// We want to create a device on a fresh instance and adapter each time. // We want to create a device on a fresh instance and adapter each time.
std::vector<wgpu::AdapterProperties> availableAdapterProperties; std::vector<wgpu::AdapterProperties> availableAdapterProperties;
{ {
auto instance = std::make_unique<dawn::native::Instance>(); auto instance = std::make_unique<native::Instance>();
instance->EnableAdapterBlocklist(false); instance->EnableAdapterBlocklist(false);
instance->DiscoverDefaultAdapters(); instance->DiscoverDefaultAdapters();
for (const dawn::native::Adapter& adapter : instance->GetAdapters()) { for (const native::Adapter& adapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties; wgpu::AdapterProperties properties;
adapter.GetProperties(&properties); adapter.GetProperties(&properties);
@ -91,10 +94,10 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) {
for (const wgpu::AdapterProperties& desiredProperties : availableAdapterProperties) { for (const wgpu::AdapterProperties& desiredProperties : availableAdapterProperties) {
wgpu::Device device; wgpu::Device device;
auto instance = std::make_unique<dawn::native::Instance>(); auto instance = std::make_unique<native::Instance>();
instance->EnableAdapterBlocklist(false); instance->EnableAdapterBlocklist(false);
instance->DiscoverDefaultAdapters(); instance->DiscoverDefaultAdapters();
for (dawn::native::Adapter& adapter : instance->GetAdapters()) { for (native::Adapter& adapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties; wgpu::AdapterProperties properties;
adapter.GetProperties(&properties); adapter.GetProperties(&properties);
@ -122,10 +125,10 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) {
// We want to create a device on a fresh instance and adapter each time. // We want to create a device on a fresh instance and adapter each time.
std::vector<wgpu::AdapterProperties> availableAdapterProperties; std::vector<wgpu::AdapterProperties> availableAdapterProperties;
{ {
auto instance = std::make_unique<dawn::native::Instance>(); auto instance = std::make_unique<native::Instance>();
instance->EnableAdapterBlocklist(false); instance->EnableAdapterBlocklist(false);
instance->DiscoverDefaultAdapters(); instance->DiscoverDefaultAdapters();
for (const dawn::native::Adapter& adapter : instance->GetAdapters()) { for (const native::Adapter& adapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties; wgpu::AdapterProperties properties;
adapter.GetProperties(&properties); adapter.GetProperties(&properties);
@ -143,14 +146,14 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) {
for (const wgpu::AdapterProperties& desiredProperties : availableAdapterProperties) { for (const wgpu::AdapterProperties& desiredProperties : availableAdapterProperties) {
wgpu::Adapter adapter; wgpu::Adapter adapter;
auto instance = std::make_unique<dawn::native::Instance>(); auto instance = std::make_unique<native::Instance>();
instance->EnableAdapterBlocklist(false); instance->EnableAdapterBlocklist(false);
// Save a pointer to the instance. // Save a pointer to the instance.
// It will only be valid as long as the instance is alive. // It will only be valid as long as the instance is alive.
WGPUInstance unsafeInstancePtr = instance->Get(); WGPUInstance unsafeInstancePtr = instance->Get();
instance->DiscoverDefaultAdapters(); instance->DiscoverDefaultAdapters();
for (dawn::native::Adapter& nativeAdapter : instance->GetAdapters()) { for (native::Adapter& nativeAdapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties; wgpu::AdapterProperties properties;
nativeAdapter.GetProperties(&properties); nativeAdapter.GetProperties(&properties);
@ -164,9 +167,9 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) {
// holding onto the instance. The instance should have cleared all internal // holding onto the instance. The instance should have cleared all internal
// references to adapters when the last external ref is dropped. // references to adapters when the last external ref is dropped.
adapter = wgpu::Adapter(nativeAdapter.Get()); adapter = wgpu::Adapter(nativeAdapter.Get());
EXPECT_GT(dawn::native::GetAdapterCountForTesting(unsafeInstancePtr), 0u); EXPECT_GT(native::GetAdapterCountForTesting(unsafeInstancePtr), 0u);
instance.reset(); instance.reset();
EXPECT_EQ(dawn::native::GetAdapterCountForTesting(unsafeInstancePtr), 0u); EXPECT_EQ(native::GetAdapterCountForTesting(unsafeInstancePtr), 0u);
break; break;
} }
} }
@ -176,3 +179,6 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) {
} }
} }
} }
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/tests/DawnTest.h" #include "dawn/tests/DawnTest.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class DeviceLifetimeTests : public DawnTest {}; class DeviceLifetimeTests : public DawnTest {};
// Test that the device can be dropped before its queue. // Test that the device can be dropped before its queue.
@ -557,3 +560,6 @@ DAWN_INSTANTIATE_TEST(DeviceLifetimeTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -22,6 +22,9 @@
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
namespace dawn {
namespace {
using testing::_; using testing::_;
using testing::Exactly; using testing::Exactly;
using testing::MockCallback; using testing::MockCallback;
@ -540,3 +543,6 @@ DAWN_INSTANTIATE_TEST(DeviceLostTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -19,6 +19,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr uint32_t kRTSize = 4; constexpr uint32_t kRTSize = 4;
class DrawIndexedIndirectTest : public DawnTest { class DrawIndexedIndirectTest : public DawnTest {
@ -716,3 +719,6 @@ DAWN_INSTANTIATE_TEST(DrawIndexedIndirectTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr uint32_t kRTSize = 4; constexpr uint32_t kRTSize = 4;
class DrawIndexedTest : public DawnTest { class DrawIndexedTest : public DawnTest {
@ -162,3 +165,6 @@ DAWN_INSTANTIATE_TEST(DrawIndexedTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr uint32_t kRTSize = 4; constexpr uint32_t kRTSize = 4;
class DrawIndirectTest : public DawnTest { class DrawIndirectTest : public DawnTest {
@ -135,3 +138,6 @@ DAWN_INSTANTIATE_TEST(DrawIndirectTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr uint32_t kRTSize = 4; constexpr uint32_t kRTSize = 4;
class DrawTest : public DawnTest { class DrawTest : public DawnTest {
@ -107,3 +110,6 @@ DAWN_INSTANTIATE_TEST(DrawTest,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -22,6 +22,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr uint32_t kRTSize = 400; constexpr uint32_t kRTSize = 400;
constexpr uint32_t kBindingSize = 8; constexpr uint32_t kBindingSize = 8;
@ -586,3 +589,6 @@ DAWN_INSTANTIATE_TEST_P(ClampedOOBDynamicBufferOffsetTests,
{wgpu::BufferUsage::Uniform, wgpu::BufferUsage::Storage}, {wgpu::BufferUsage::Uniform, wgpu::BufferUsage::Storage},
{false, true}, {false, true},
{false, true}); {false, true});
} // anonymous namespace
} // namespace dawn

View File

@ -17,6 +17,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class EntryPointTests : public DawnTest {}; class EntryPointTests : public DawnTest {};
// Test creating a render pipeline from two entryPoints in the same module. // Test creating a render pipeline from two entryPoints in the same module.
@ -149,3 +152,6 @@ DAWN_INSTANTIATE_TEST(EntryPointTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -17,12 +17,12 @@
#include "dawn/tests/DawnTest.h" #include "dawn/tests/DawnTest.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
using RequestDP4aExtension = bool; using RequestDP4aExtension = bool;
DAWN_TEST_PARAM_STRUCT(ExperimentalDP4aTestsParams, RequestDP4aExtension); DAWN_TEST_PARAM_STRUCT(ExperimentalDP4aTestsParams, RequestDP4aExtension);
} // anonymous namespace
class ExperimentalDP4aTests : public DawnTestWithParams<ExperimentalDP4aTestsParams> { class ExperimentalDP4aTests : public DawnTestWithParams<ExperimentalDP4aTestsParams> {
protected: protected:
std::vector<wgpu::FeatureName> GetRequiredFeatures() override { std::vector<wgpu::FeatureName> GetRequiredFeatures() override {
@ -136,3 +136,6 @@ DAWN_INSTANTIATE_TEST_P(ExperimentalDP4aTests,
VulkanBackend(), VulkanBackend(),
}, },
{true, false}); {true, false});
} // anonymous namespace
} // namespace dawn

View File

@ -16,6 +16,7 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace { namespace {
wgpu::Texture Create2DTexture(wgpu::Device device, wgpu::Texture Create2DTexture(wgpu::Device device,
@ -107,7 +108,6 @@ class ExternalTextureTests : public DawnTest {
wgpu::ShaderModule vsModule; wgpu::ShaderModule vsModule;
wgpu::ShaderModule fsSampleExternalTextureModule; wgpu::ShaderModule fsSampleExternalTextureModule;
}; };
} // anonymous namespace
TEST_P(ExternalTextureTests, CreateExternalTextureSuccess) { TEST_P(ExternalTextureTests, CreateExternalTextureSuccess) {
wgpu::Texture texture = Create2DTexture(device, kWidth, kHeight, kFormat, kSampledUsage); wgpu::Texture texture = Create2DTexture(device, kWidth, kHeight, kFormat, kSampledUsage);
@ -1002,3 +1002,6 @@ DAWN_INSTANTIATE_TEST(ExternalTextureTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -21,6 +21,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr uint32_t kRTSize = 1; constexpr uint32_t kRTSize = 1;
enum class DrawMode { enum class DrawMode {
@ -39,12 +42,14 @@ bool IsIndirectDraw(DrawMode mode) {
return mode == DrawMode::NonIndexedIndirect || mode == DrawMode::IndexedIndirect; return mode == DrawMode::NonIndexedIndirect || mode == DrawMode::IndexedIndirect;
} }
namespace dawn { } // anonymous namespace
template <> template <>
struct IsDawnBitmask<CheckIndex> { struct IsDawnBitmask<CheckIndex> {
static constexpr bool enable = true; static constexpr bool enable = true;
}; };
} // namespace dawn
namespace {
class FirstIndexOffsetTests : public DawnTest { class FirstIndexOffsetTests : public DawnTest {
public: public:
@ -328,3 +333,6 @@ DAWN_INSTANTIATE_TEST(FirstIndexOffsetTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -16,6 +16,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
constexpr wgpu::TextureFormat kDepthFormat = wgpu::TextureFormat::Depth32Float; constexpr wgpu::TextureFormat kDepthFormat = wgpu::TextureFormat::Depth32Float;
class FragDepthTests : public DawnTest {}; class FragDepthTests : public DawnTest {};
@ -233,3 +236,6 @@ DAWN_INSTANTIATE_TEST(FragDepthTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

View File

@ -22,6 +22,9 @@
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h" #include "dawn/utils/WGPUHelpers.h"
namespace dawn {
namespace {
class GpuMemorySyncTests : public DawnTest { class GpuMemorySyncTests : public DawnTest {
protected: protected:
wgpu::Buffer CreateBuffer() { wgpu::Buffer CreateBuffer() {
@ -654,3 +657,6 @@ DAWN_INSTANTIATE_TEST(MultipleWriteThenMultipleReadTests,
OpenGLBackend(), OpenGLBackend(),
OpenGLESBackend(), OpenGLESBackend(),
VulkanBackend()); VulkanBackend());
} // anonymous namespace
} // namespace dawn

Some files were not shown because too many files have changed in this diff Show More