Mark pipeline overridable constants as unsafe

Until all backend implementations are done.

Bug: dawn:1169
Change-Id: I16d184bec03bbc9a255ad33cf11aa615b1986389
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/67422
Commit-Queue: Shrek Shao <shrekshao@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Shrek Shao 2021-10-26 02:06:36 +00:00 committed by Dawn LUCI CQ
parent 83d8966a26
commit f4c8a6ac9b
3 changed files with 50 additions and 0 deletions

View File

@ -45,6 +45,12 @@ namespace dawn_native {
DAWN_TRY(ValidateCompatibilityWithPipelineLayout(device, metadata, layout));
}
if (constantCount > 0u && device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
return DAWN_VALIDATION_ERROR(
"Pipeline overridable constants are disallowed because they are partially "
"implemented.");
}
// Validate if overridable constants exist in shader module
// pipelineBase is not yet constructed at this moment so iterate constants from descriptor
for (uint32_t i = 0; i < constantCount; i++) {

View File

@ -631,6 +631,10 @@ namespace dawn_native {
auto metadata = std::make_unique<EntryPointMetadata>();
if (!entryPoint.overridable_constants.empty()) {
DAWN_INVALID_IF(device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs),
"Pipeline overridable constants are disallowed because they "
"are partially implemented.");
const auto& name2Id = inspector.GetConstantNameToIdMap();
for (auto& c : entryPoint.overridable_constants) {

View File

@ -106,6 +106,46 @@ TEST_F(UnsafeAPIValidationTest, DynamicStorageBuffer) {
}
}
// Check that pipeline overridable constants are disallowed as part of unsafe APIs.
// TODO(dawn:1041) Remove when implementation for all backend is added
TEST_F(UnsafeAPIValidationTest, PipelineOverridableConstants) {
// Create the dummy compute pipeline.
wgpu::ComputePipelineDescriptor pipelineDescBase;
pipelineDescBase.compute.entryPoint = "main";
// Control case: shader without overridable constant is allowed.
{
wgpu::ComputePipelineDescriptor pipelineDesc = pipelineDescBase;
pipelineDesc.compute.module =
utils::CreateShaderModule(device, "[[stage(compute), workgroup_size(1)]] fn main() {}");
device.CreateComputePipeline(&pipelineDesc);
}
// Error case: shader with overridable constant with default value
{
ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"(
[[override(1000)]] let c0: u32 = 1u;
[[override(1000)]] let c1: u32;
[[stage(compute), workgroup_size(1)]] fn main() {
ignore(c0);
ignore(c1);
})"));
}
// Error case: pipeline stage with constant entry is disallowed
{
wgpu::ComputePipelineDescriptor pipelineDesc = pipelineDescBase;
pipelineDesc.compute.module =
utils::CreateShaderModule(device, "[[stage(compute), workgroup_size(1)]] fn main() {}");
std::vector<wgpu::ConstantEntry> constants{{nullptr, "c", 1u}};
pipelineDesc.compute.constants = constants.data();
pipelineDesc.compute.constantCount = constants.size();
ASSERT_DEVICE_ERROR(device.CreateComputePipeline(&pipelineDesc));
}
}
class UnsafeQueryAPIValidationTest : public ValidationTest {
protected:
WGPUDevice CreateTestDevice() override {