mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 17:05:31 +00:00
Adds new chained struct for device creation to specify cache options.
- Adds isolation key option, DawnNative support, and relevant unit tests. Bug: dawn:549 Change-Id: I16344581c7956ce8576c0a4c14655fbdb4e15a54 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/81920 Reviewed-by: Shrek Shao <shrekshao@google.com> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
@@ -184,6 +184,12 @@ namespace dawn::native {
|
||||
}
|
||||
ApplyFeatures(descriptor);
|
||||
|
||||
const DawnCacheDeviceDescriptor* cacheDesc = nullptr;
|
||||
FindInChain(descriptor->nextInChain, &cacheDesc);
|
||||
if (cacheDesc != nullptr) {
|
||||
mCacheIsolationKey = cacheDesc->isolationKey;
|
||||
}
|
||||
|
||||
if (descriptor->requiredLimits != nullptr) {
|
||||
mLimits.v1 = ReifyDefaultLimits(descriptor->requiredLimits->limits);
|
||||
} else {
|
||||
@@ -1738,6 +1744,10 @@ namespace dawn::native {
|
||||
return PipelineCompatibilityToken(mNextPipelineCompatibilityToken++);
|
||||
}
|
||||
|
||||
const std::string& DeviceBase::GetCacheIsolationKey() const {
|
||||
return mCacheIsolationKey;
|
||||
}
|
||||
|
||||
const std::string& DeviceBase::GetLabel() const {
|
||||
return mLabel;
|
||||
}
|
||||
|
||||
@@ -366,6 +366,7 @@ namespace dawn::native {
|
||||
|
||||
PipelineCompatibilityToken GetNextPipelineCompatibilityToken();
|
||||
|
||||
const std::string& GetCacheIsolationKey() const;
|
||||
const std::string& GetLabel() const;
|
||||
void APISetLabel(const char* label);
|
||||
void APIDestroy();
|
||||
@@ -540,6 +541,7 @@ namespace dawn::native {
|
||||
std::unique_ptr<CallbackTaskManager> mCallbackTaskManager;
|
||||
std::unique_ptr<dawn::platform::WorkerTaskPool> mWorkerTaskPool;
|
||||
std::string mLabel;
|
||||
std::string mCacheIsolationKey = "";
|
||||
};
|
||||
|
||||
} // namespace dawn::native
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "dawn/dawn_proc.h"
|
||||
#include "dawn/native/DawnNative.h"
|
||||
#include "dawn/native/Device.h"
|
||||
#include "dawn/native/dawn_platform.h"
|
||||
#include "dawn/tests/MockCallback.h"
|
||||
#include "dawn/utils/SystemUtils.h"
|
||||
#include "dawn/utils/WGPUHelpers.h"
|
||||
@@ -24,7 +26,7 @@ namespace {
|
||||
|
||||
using namespace testing;
|
||||
|
||||
class DeviceCreationTest : public testing::Test {
|
||||
class DeviceCreationTest : public Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
dawnProcSetProcs(&dawn::native::GetProcs());
|
||||
@@ -83,6 +85,45 @@ namespace {
|
||||
EXPECT_THAT(toggles, testing::Contains(testing::StrEq(toggle)));
|
||||
}
|
||||
|
||||
TEST_F(DeviceCreationTest, CreateDeviceWithCacheSuccess) {
|
||||
// Default device descriptor should have an empty cache isolation key.
|
||||
{
|
||||
wgpu::DeviceDescriptor desc = {};
|
||||
wgpu::Device device = adapter.CreateDevice(&desc);
|
||||
EXPECT_NE(device, nullptr);
|
||||
|
||||
EXPECT_THAT(dawn::native::FromAPI(device.Get())->GetCacheIsolationKey(),
|
||||
testing::StrEq(""));
|
||||
}
|
||||
// Device descriptor with empty cache descriptor should have an empty cache isolation key.
|
||||
{
|
||||
wgpu::DeviceDescriptor desc = {};
|
||||
wgpu::DawnCacheDeviceDescriptor cacheDesc = {};
|
||||
desc.nextInChain = &cacheDesc;
|
||||
|
||||
wgpu::Device device = adapter.CreateDevice(&desc);
|
||||
EXPECT_NE(device, nullptr);
|
||||
|
||||
EXPECT_THAT(dawn::native::FromAPI(device.Get())->GetCacheIsolationKey(),
|
||||
testing::StrEq(""));
|
||||
}
|
||||
// Specified cache isolation key should be retained.
|
||||
{
|
||||
wgpu::DeviceDescriptor desc = {};
|
||||
wgpu::DawnCacheDeviceDescriptor cacheDesc = {};
|
||||
desc.nextInChain = &cacheDesc;
|
||||
|
||||
const char* isolationKey = "isolation key";
|
||||
cacheDesc.isolationKey = isolationKey;
|
||||
|
||||
wgpu::Device device = adapter.CreateDevice(&desc);
|
||||
EXPECT_NE(device, nullptr);
|
||||
|
||||
EXPECT_THAT(dawn::native::FromAPI(device.Get())->GetCacheIsolationKey(),
|
||||
testing::StrEq(isolationKey));
|
||||
}
|
||||
}
|
||||
|
||||
// Test successful call to RequestDevice with descriptor
|
||||
TEST_F(DeviceCreationTest, RequestDeviceSuccess) {
|
||||
WGPUDevice cDevice;
|
||||
|
||||
Reference in New Issue
Block a user