Add a toggle to disable Dawn validation
Trusted users of Dawn should be able to use it without the overhead of command validation. This patch adds the toggle and skips validation for object creation. Bug: dawn:271 Change-Id: Ica9a1988177685d73e2c36e05c4d525ad1ab0fdb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13802 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
parent
98ba76af00
commit
4d15609d26
|
@ -617,6 +617,10 @@ namespace dawn_native {
|
||||||
return mTogglesSet.IsEnabled(toggle);
|
return mTogglesSet.IsEnabled(toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DeviceBase::IsValidationEnabled() const {
|
||||||
|
return !IsToggleEnabled(Toggle::SkipValidation);
|
||||||
|
}
|
||||||
|
|
||||||
size_t DeviceBase::GetLazyClearCountForTesting() {
|
size_t DeviceBase::GetLazyClearCountForTesting() {
|
||||||
return mLazyClearCountForTesting;
|
return mLazyClearCountForTesting;
|
||||||
}
|
}
|
||||||
|
@ -634,7 +638,9 @@ namespace dawn_native {
|
||||||
|
|
||||||
MaybeError DeviceBase::CreateBindGroupInternal(BindGroupBase** result,
|
MaybeError DeviceBase::CreateBindGroupInternal(BindGroupBase** result,
|
||||||
const BindGroupDescriptor* descriptor) {
|
const BindGroupDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateBindGroupDescriptor(this, descriptor));
|
DAWN_TRY(ValidateBindGroupDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, CreateBindGroupImpl(descriptor));
|
DAWN_TRY_ASSIGN(*result, CreateBindGroupImpl(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -642,14 +648,18 @@ namespace dawn_native {
|
||||||
MaybeError DeviceBase::CreateBindGroupLayoutInternal(
|
MaybeError DeviceBase::CreateBindGroupLayoutInternal(
|
||||||
BindGroupLayoutBase** result,
|
BindGroupLayoutBase** result,
|
||||||
const BindGroupLayoutDescriptor* descriptor) {
|
const BindGroupLayoutDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor));
|
DAWN_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(descriptor));
|
DAWN_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError DeviceBase::CreateBufferInternal(BufferBase** result,
|
MaybeError DeviceBase::CreateBufferInternal(BufferBase** result,
|
||||||
const BufferDescriptor* descriptor) {
|
const BufferDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateBufferDescriptor(this, descriptor));
|
DAWN_TRY(ValidateBufferDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, CreateBufferImpl(descriptor));
|
DAWN_TRY_ASSIGN(*result, CreateBufferImpl(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -657,7 +667,9 @@ namespace dawn_native {
|
||||||
MaybeError DeviceBase::CreateComputePipelineInternal(
|
MaybeError DeviceBase::CreateComputePipelineInternal(
|
||||||
ComputePipelineBase** result,
|
ComputePipelineBase** result,
|
||||||
const ComputePipelineDescriptor* descriptor) {
|
const ComputePipelineDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateComputePipelineDescriptor(this, descriptor));
|
DAWN_TRY(ValidateComputePipelineDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, GetOrCreateComputePipeline(descriptor));
|
DAWN_TRY_ASSIGN(*result, GetOrCreateComputePipeline(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -665,7 +677,9 @@ namespace dawn_native {
|
||||||
MaybeError DeviceBase::CreatePipelineLayoutInternal(
|
MaybeError DeviceBase::CreatePipelineLayoutInternal(
|
||||||
PipelineLayoutBase** result,
|
PipelineLayoutBase** result,
|
||||||
const PipelineLayoutDescriptor* descriptor) {
|
const PipelineLayoutDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidatePipelineLayoutDescriptor(this, descriptor));
|
DAWN_TRY(ValidatePipelineLayoutDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, GetOrCreatePipelineLayout(descriptor));
|
DAWN_TRY_ASSIGN(*result, GetOrCreatePipelineLayout(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -678,7 +692,9 @@ namespace dawn_native {
|
||||||
MaybeError DeviceBase::CreateRenderBundleEncoderInternal(
|
MaybeError DeviceBase::CreateRenderBundleEncoderInternal(
|
||||||
RenderBundleEncoder** result,
|
RenderBundleEncoder** result,
|
||||||
const RenderBundleEncoderDescriptor* descriptor) {
|
const RenderBundleEncoderDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateRenderBundleEncoderDescriptor(this, descriptor));
|
DAWN_TRY(ValidateRenderBundleEncoderDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
*result = new RenderBundleEncoder(this, descriptor);
|
*result = new RenderBundleEncoder(this, descriptor);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -686,35 +702,45 @@ namespace dawn_native {
|
||||||
MaybeError DeviceBase::CreateRenderPipelineInternal(
|
MaybeError DeviceBase::CreateRenderPipelineInternal(
|
||||||
RenderPipelineBase** result,
|
RenderPipelineBase** result,
|
||||||
const RenderPipelineDescriptor* descriptor) {
|
const RenderPipelineDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateRenderPipelineDescriptor(this, descriptor));
|
DAWN_TRY(ValidateRenderPipelineDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(descriptor));
|
DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result,
|
MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result,
|
||||||
const SamplerDescriptor* descriptor) {
|
const SamplerDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateSamplerDescriptor(this, descriptor));
|
DAWN_TRY(ValidateSamplerDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, GetOrCreateSampler(descriptor));
|
DAWN_TRY_ASSIGN(*result, GetOrCreateSampler(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError DeviceBase::CreateShaderModuleInternal(ShaderModuleBase** result,
|
MaybeError DeviceBase::CreateShaderModuleInternal(ShaderModuleBase** result,
|
||||||
const ShaderModuleDescriptor* descriptor) {
|
const ShaderModuleDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateShaderModuleDescriptor(this, descriptor));
|
DAWN_TRY(ValidateShaderModuleDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, GetOrCreateShaderModule(descriptor));
|
DAWN_TRY_ASSIGN(*result, GetOrCreateShaderModule(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError DeviceBase::CreateSwapChainInternal(SwapChainBase** result,
|
MaybeError DeviceBase::CreateSwapChainInternal(SwapChainBase** result,
|
||||||
const SwapChainDescriptor* descriptor) {
|
const SwapChainDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateSwapChainDescriptor(this, descriptor));
|
DAWN_TRY(ValidateSwapChainDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, CreateSwapChainImpl(descriptor));
|
DAWN_TRY_ASSIGN(*result, CreateSwapChainImpl(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError DeviceBase::CreateTextureInternal(TextureBase** result,
|
MaybeError DeviceBase::CreateTextureInternal(TextureBase** result,
|
||||||
const TextureDescriptor* descriptor) {
|
const TextureDescriptor* descriptor) {
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateTextureDescriptor(this, descriptor));
|
DAWN_TRY(ValidateTextureDescriptor(this, descriptor));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, CreateTextureImpl(descriptor));
|
DAWN_TRY_ASSIGN(*result, CreateTextureImpl(descriptor));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -724,7 +750,9 @@ namespace dawn_native {
|
||||||
const TextureViewDescriptor* descriptor) {
|
const TextureViewDescriptor* descriptor) {
|
||||||
DAWN_TRY(ValidateObject(texture));
|
DAWN_TRY(ValidateObject(texture));
|
||||||
TextureViewDescriptor desc = GetTextureViewDescriptorWithDefaults(texture, descriptor);
|
TextureViewDescriptor desc = GetTextureViewDescriptorWithDefaults(texture, descriptor);
|
||||||
|
if (IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateTextureViewDescriptor(texture, &desc));
|
DAWN_TRY(ValidateTextureViewDescriptor(texture, &desc));
|
||||||
|
}
|
||||||
DAWN_TRY_ASSIGN(*result, CreateTextureViewImpl(texture, &desc));
|
DAWN_TRY_ASSIGN(*result, CreateTextureViewImpl(texture, &desc));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,7 @@ namespace dawn_native {
|
||||||
std::vector<const char*> GetTogglesUsed() const;
|
std::vector<const char*> GetTogglesUsed() const;
|
||||||
bool IsExtensionEnabled(Extension extension) const;
|
bool IsExtensionEnabled(Extension extension) const;
|
||||||
bool IsToggleEnabled(Toggle toggle) const;
|
bool IsToggleEnabled(Toggle toggle) const;
|
||||||
|
bool IsValidationEnabled() const;
|
||||||
size_t GetLazyClearCountForTesting();
|
size_t GetLazyClearCountForTesting();
|
||||||
void IncrementLazyClearCountForTesting();
|
void IncrementLazyClearCountForTesting();
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,9 @@ namespace dawn_native {
|
||||||
{"use_d3d12_render_pass",
|
{"use_d3d12_render_pass",
|
||||||
"Use the D3D12 render pass API introduced in Windows build 1809 by default. On "
|
"Use the D3D12 render pass API introduced in Windows build 1809 by default. On "
|
||||||
"versions of Windows prior to build 1809, or when this toggle is turned off, Dawn "
|
"versions of Windows prior to build 1809, or when this toggle is turned off, Dawn "
|
||||||
"will emulate a render pass."}}}};
|
"will emulate a render pass."}},
|
||||||
|
{Toggle::SkipValidation,
|
||||||
|
{"skip_validation", "Skip expensive validation of Dawn commands."}}}};
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
void TogglesSet::SetToggle(Toggle toggle, bool enabled) {
|
void TogglesSet::SetToggle(Toggle toggle, bool enabled) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace dawn_native {
|
||||||
UseTemporaryBufferInCompressedTextureToTextureCopy,
|
UseTemporaryBufferInCompressedTextureToTextureCopy,
|
||||||
UseD3D12ResourceHeapTier2,
|
UseD3D12ResourceHeapTier2,
|
||||||
UseD3D12RenderPass,
|
UseD3D12RenderPass,
|
||||||
|
SkipValidation,
|
||||||
|
|
||||||
EnumCount,
|
EnumCount,
|
||||||
InvalidEnum = EnumCount,
|
InvalidEnum = EnumCount,
|
||||||
|
|
|
@ -137,6 +137,11 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp("--skip-validation", argv[i]) == 0) {
|
||||||
|
mSkipDawnValidation = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr const char kVendorIdFilterArg[] = "--adapter-vendor-id=";
|
constexpr const char kVendorIdFilterArg[] = "--adapter-vendor-id=";
|
||||||
if (strstr(argv[i], kVendorIdFilterArg) == argv[i]) {
|
if (strstr(argv[i], kVendorIdFilterArg) == argv[i]) {
|
||||||
const char* vendorIdFilter = argv[i] + strlen(kVendorIdFilterArg);
|
const char* vendorIdFilter = argv[i] + strlen(kVendorIdFilterArg);
|
||||||
|
@ -156,6 +161,7 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
||||||
" to disabled)\n"
|
" to disabled)\n"
|
||||||
" -c, --begin-capture-on-startup: Begin debug capture on startup "
|
" -c, --begin-capture-on-startup: Begin debug capture on startup "
|
||||||
"(defaults to no capture)\n"
|
"(defaults to no capture)\n"
|
||||||
|
" --skip-validation: Skip Dawn validation\n"
|
||||||
" --adapter-vendor-id: Select adapter by vendor id to run end2end tests"
|
" --adapter-vendor-id: Select adapter by vendor id to run end2end tests"
|
||||||
"on multi-GPU systems \n"
|
"on multi-GPU systems \n"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@ -184,6 +190,9 @@ void DawnTestEnvironment::SetUp() {
|
||||||
<< "\n"
|
<< "\n"
|
||||||
"EnableBackendValidation: "
|
"EnableBackendValidation: "
|
||||||
<< (mEnableBackendValidation ? "true" : "false")
|
<< (mEnableBackendValidation ? "true" : "false")
|
||||||
|
<< "\n"
|
||||||
|
"SkipDawnValidation: "
|
||||||
|
<< (mSkipDawnValidation ? "true" : "false")
|
||||||
<< "\n"
|
<< "\n"
|
||||||
"BeginCaptureOnStartup: "
|
"BeginCaptureOnStartup: "
|
||||||
<< (mBeginCaptureOnStartup ? "true" : "false")
|
<< (mBeginCaptureOnStartup ? "true" : "false")
|
||||||
|
@ -228,6 +237,10 @@ bool DawnTestEnvironment::IsBackendValidationEnabled() const {
|
||||||
return mEnableBackendValidation;
|
return mEnableBackendValidation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DawnTestEnvironment::IsDawnValidationSkipped() const {
|
||||||
|
return mSkipDawnValidation;
|
||||||
|
}
|
||||||
|
|
||||||
dawn_native::Instance* DawnTestEnvironment::GetInstance() const {
|
dawn_native::Instance* DawnTestEnvironment::GetInstance() const {
|
||||||
return mInstance.get();
|
return mInstance.get();
|
||||||
}
|
}
|
||||||
|
@ -353,6 +366,10 @@ bool DawnTestBase::IsBackendValidationEnabled() const {
|
||||||
return gTestEnv->IsBackendValidationEnabled();
|
return gTestEnv->IsBackendValidationEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DawnTestBase::IsDawnValidationSkipped() const {
|
||||||
|
return gTestEnv->IsDawnValidationSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
bool DawnTestBase::HasVendorIdFilter() const {
|
bool DawnTestBase::HasVendorIdFilter() const {
|
||||||
return gTestEnv->HasVendorIdFilter();
|
return gTestEnv->HasVendorIdFilter();
|
||||||
}
|
}
|
||||||
|
@ -431,6 +448,13 @@ void DawnTestBase::SetUp() {
|
||||||
deviceDescriptor.forceEnabledToggles = mParam.forceEnabledWorkarounds;
|
deviceDescriptor.forceEnabledToggles = mParam.forceEnabledWorkarounds;
|
||||||
deviceDescriptor.forceDisabledToggles = mParam.forceDisabledWorkarounds;
|
deviceDescriptor.forceDisabledToggles = mParam.forceDisabledWorkarounds;
|
||||||
deviceDescriptor.requiredExtensions = GetRequiredExtensions();
|
deviceDescriptor.requiredExtensions = GetRequiredExtensions();
|
||||||
|
|
||||||
|
static constexpr char kSkipValidationToggle[] = "skip_validation";
|
||||||
|
if (gTestEnv->IsDawnValidationSkipped()) {
|
||||||
|
ASSERT(gTestEnv->GetInstance()->GetToggleInfo(kSkipValidationToggle) != nullptr);
|
||||||
|
deviceDescriptor.forceEnabledToggles.push_back(kSkipValidationToggle);
|
||||||
|
}
|
||||||
|
|
||||||
backendDevice = mBackendAdapter.CreateDevice(&deviceDescriptor);
|
backendDevice = mBackendAdapter.CreateDevice(&deviceDescriptor);
|
||||||
ASSERT_NE(nullptr, backendDevice);
|
ASSERT_NE(nullptr, backendDevice);
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,7 @@ class DawnTestEnvironment : public testing::Environment {
|
||||||
|
|
||||||
bool UsesWire() const;
|
bool UsesWire() const;
|
||||||
bool IsBackendValidationEnabled() const;
|
bool IsBackendValidationEnabled() const;
|
||||||
|
bool IsDawnValidationSkipped() const;
|
||||||
dawn_native::Instance* GetInstance() const;
|
dawn_native::Instance* GetInstance() const;
|
||||||
bool HasVendorIdFilter() const;
|
bool HasVendorIdFilter() const;
|
||||||
uint32_t GetVendorIdFilter() const;
|
uint32_t GetVendorIdFilter() const;
|
||||||
|
@ -146,6 +147,7 @@ class DawnTestEnvironment : public testing::Environment {
|
||||||
|
|
||||||
bool mUseWire = false;
|
bool mUseWire = false;
|
||||||
bool mEnableBackendValidation = false;
|
bool mEnableBackendValidation = false;
|
||||||
|
bool mSkipDawnValidation = false;
|
||||||
bool mBeginCaptureOnStartup = false;
|
bool mBeginCaptureOnStartup = false;
|
||||||
bool mHasVendorIdFilter = false;
|
bool mHasVendorIdFilter = false;
|
||||||
uint32_t mVendorIdFilter = 0;
|
uint32_t mVendorIdFilter = 0;
|
||||||
|
@ -179,6 +181,7 @@ class DawnTestBase {
|
||||||
|
|
||||||
bool UsesWire() const;
|
bool UsesWire() const;
|
||||||
bool IsBackendValidationEnabled() const;
|
bool IsBackendValidationEnabled() const;
|
||||||
|
bool IsDawnValidationSkipped() const;
|
||||||
|
|
||||||
void StartExpectDeviceError();
|
void StartExpectDeviceError();
|
||||||
bool EndExpectDeviceError();
|
bool EndExpectDeviceError();
|
||||||
|
|
|
@ -23,6 +23,7 @@ class DestroyTest : public DawnTest {
|
||||||
protected:
|
protected:
|
||||||
void TestSetUp() override {
|
void TestSetUp() override {
|
||||||
DawnTest::TestSetUp();
|
DawnTest::TestSetUp();
|
||||||
|
DAWN_SKIP_TEST_IF(IsDawnValidationSkipped());
|
||||||
|
|
||||||
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
|
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,8 @@ TEST_P(ObjectCachingTest, BindGroupLayoutTextureDimension) {
|
||||||
|
|
||||||
// Test that an error object doesn't try to uncache itself
|
// Test that an error object doesn't try to uncache itself
|
||||||
TEST_P(ObjectCachingTest, ErrorObjectDoesntUncache) {
|
TEST_P(ObjectCachingTest, ErrorObjectDoesntUncache) {
|
||||||
|
DAWN_SKIP_TEST_IF(IsDawnValidationSkipped());
|
||||||
|
|
||||||
ASSERT_DEVICE_ERROR(
|
ASSERT_DEVICE_ERROR(
|
||||||
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
|
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
|
||||||
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
|
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::UniformBuffer},
|
||||||
|
|
Loading…
Reference in New Issue