Skip to content

Commit 4ec0a0b

Browse files
Jiawei-ShaoDawn LUCI CQ
authored andcommitted
Add validations on ReadWrite storage texture format
This patch adds the check on the storage texture format with ReadWrite storage texture access. Currently only R32Float, R32Uint and R32SInt are allowed with ReadWrite storage texture access. Bug: dawn:1972 Test: dawn_unittests Change-Id: I63dd73b7f93cee037baa8cb94bddd5229ea9312c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/146880 Reviewed-by: Corentin Wallez <[email protected]> Kokoro: Kokoro <[email protected]> Reviewed-by: Austin Eng <[email protected]> Commit-Queue: Jiawei Shao <[email protected]>
1 parent 6f138fe commit 4ec0a0b

File tree

6 files changed

+62
-17
lines changed

6 files changed

+62
-17
lines changed

src/dawn/native/BindGroupLayoutInternal.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ MaybeError ValidateReadWriteStorageTextureAccess(
8686
UNREACHABLE();
8787
}
8888

89+
if (storageTextureBindingLayout.access == wgpu::StorageTextureAccess::ReadWrite) {
90+
const Format* format = nullptr;
91+
DAWN_TRY_ASSIGN(format, device->GetInternalFormat(storageTextureBindingLayout.format));
92+
DAWN_INVALID_IF(!format->supportsReadWriteStorageUsage,
93+
"Texture format %s does not support storage texture access %s",
94+
storageTextureBindingLayout.format, wgpu::StorageTextureAccess::ReadWrite);
95+
}
96+
8997
return {};
9098
}
9199

src/dawn/native/Format.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,15 @@ FormatTable BuildFormatTable(const DeviceBase* device) {
178178
bool supportsResolveTarget, uint32_t byteSize, SampleTypeBit sampleTypes,
179179
uint8_t componentCount, uint8_t renderTargetPixelByteCost = 0,
180180
uint8_t renderTargetComponentAlignment = 0,
181+
bool supportsReadWriteStorageUsage = false,
181182
wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
182183
Format internalFormat;
183184
internalFormat.format = format;
184185
internalFormat.isRenderable = renderable;
185186
internalFormat.isCompressed = false;
186187
internalFormat.unsupportedReason = unsupportedReason;
187188
internalFormat.supportsStorageUsage = supportsStorageUsage;
189+
internalFormat.supportsReadWriteStorageUsage = supportsReadWriteStorageUsage;
188190

189191
if (supportsMultisample) {
190192
ASSERT(renderable);
@@ -236,18 +238,20 @@ FormatTable BuildFormatTable(const DeviceBase* device) {
236238
AddFormat(internalFormat);
237239
};
238240

239-
auto AddColorFormat =
240-
[&AddConditionalColorFormat](
241-
wgpu::TextureFormat format, bool renderable, bool supportsStorageUsage,
242-
bool supportsMultisample, bool supportsResolveTarget, uint32_t byteSize,
243-
SampleTypeBit sampleTypes, uint8_t componentCount,
244-
uint8_t renderTargetPixelByteCost = 0, uint8_t renderTargetComponentAlignment = 0,
245-
wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
246-
AddConditionalColorFormat(format, std::monostate{}, renderable, supportsStorageUsage,
247-
supportsMultisample, supportsResolveTarget, byteSize,
248-
sampleTypes, componentCount, renderTargetPixelByteCost,
249-
renderTargetComponentAlignment, baseFormat);
250-
};
241+
auto AddColorFormat = [&AddConditionalColorFormat](
242+
wgpu::TextureFormat format, bool renderable,
243+
bool supportsStorageUsage, bool supportsMultisample,
244+
bool supportsResolveTarget, uint32_t byteSize,
245+
SampleTypeBit sampleTypes, uint8_t componentCount,
246+
uint8_t renderTargetPixelByteCost = 0,
247+
uint8_t renderTargetComponentAlignment = 0,
248+
bool supportsReadWriteStorageUsage = false,
249+
wgpu::TextureFormat baseFormat = wgpu::TextureFormat::Undefined) {
250+
AddConditionalColorFormat(
251+
format, std::monostate{}, renderable, supportsStorageUsage, supportsMultisample,
252+
supportsResolveTarget, byteSize, sampleTypes, componentCount, renderTargetPixelByteCost,
253+
renderTargetComponentAlignment, supportsReadWriteStorageUsage, baseFormat);
254+
};
251255

252256
auto AddDepthFormat = [&AddFormat](wgpu::TextureFormat format, uint32_t byteSize,
253257
UnsupportedReason unsupportedReason) {
@@ -388,21 +392,22 @@ FormatTable BuildFormatTable(const DeviceBase* device) {
388392

389393
// 4 bytes color formats
390394
SampleTypeBit sampleTypeFor32BitFloatFormats = device->HasFeature(Feature::Float32Filterable) ? kAnyFloat : SampleTypeBit::UnfilterableFloat;
391-
AddColorFormat(wgpu::TextureFormat::R32Uint, true, true, false, false, 4, SampleTypeBit::Uint, 1, 4, 4);
392-
AddColorFormat(wgpu::TextureFormat::R32Sint, true, true, false, false, 4, SampleTypeBit::Sint, 1, 4, 4);
393-
AddColorFormat(wgpu::TextureFormat::R32Float, true, true, true, false, 4, sampleTypeFor32BitFloatFormats, 1, 4, 4);
395+
bool SupportsReadWriteStorageUsage = device->HasFeature(Feature::ChromiumExperimentalReadWriteStorageTexture);
396+
AddColorFormat(wgpu::TextureFormat::R32Uint, true, true, false, false, 4, SampleTypeBit::Uint, 1, 4, 4, SupportsReadWriteStorageUsage);
397+
AddColorFormat(wgpu::TextureFormat::R32Sint, true, true, false, false, 4, SampleTypeBit::Sint, 1, 4, 4, SupportsReadWriteStorageUsage);
398+
AddColorFormat(wgpu::TextureFormat::R32Float, true, true, true, false, 4, sampleTypeFor32BitFloatFormats, 1, 4, 4, SupportsReadWriteStorageUsage);
394399
AddColorFormat(wgpu::TextureFormat::RG16Uint, true, false, true, false, 4, SampleTypeBit::Uint, 2, 4, 2);
395400
AddColorFormat(wgpu::TextureFormat::RG16Sint, true, false, true, false, 4, SampleTypeBit::Sint, 2, 4, 2);
396401
AddColorFormat(wgpu::TextureFormat::RG16Float, true, false, true, true, 4, kAnyFloat, 2, 4, 2);
397402
AddColorFormat(wgpu::TextureFormat::RGBA8Unorm, true, true, true, true, 4, kAnyFloat, 4, 8, 1);
398-
AddColorFormat(wgpu::TextureFormat::RGBA8UnormSrgb, true, false, true, true, 4, kAnyFloat, 4, 8, 1, wgpu::TextureFormat::RGBA8Unorm);
403+
AddColorFormat(wgpu::TextureFormat::RGBA8UnormSrgb, true, false, true, true, 4, kAnyFloat, 4, 8, 1, false, wgpu::TextureFormat::RGBA8Unorm);
399404
AddColorFormat(wgpu::TextureFormat::RGBA8Snorm, false, true, false, false, 4, kAnyFloat, 4);
400405
AddColorFormat(wgpu::TextureFormat::RGBA8Uint, true, true, true, false, 4, SampleTypeBit::Uint, 4, 4, 1);
401406
AddColorFormat(wgpu::TextureFormat::RGBA8Sint, true, true, true, false, 4, SampleTypeBit::Sint, 4, 4, 1);
402407

403408
bool BGRA8UnormSupportsStorageUsage = device->HasFeature(Feature::BGRA8UnormStorage);
404409
AddColorFormat(wgpu::TextureFormat::BGRA8Unorm, true, BGRA8UnormSupportsStorageUsage, true, true, 4, kAnyFloat, 4, 8, 1);
405-
AddConditionalColorFormat(wgpu::TextureFormat::BGRA8UnormSrgb, device->IsCompatibilityMode() ? UnsupportedReason(CompatibilityMode{}) : Format::supported, true, false, true, true, 4, kAnyFloat, 4, 8, 1, wgpu::TextureFormat::BGRA8Unorm);
410+
AddConditionalColorFormat(wgpu::TextureFormat::BGRA8UnormSrgb, device->IsCompatibilityMode() ? UnsupportedReason(CompatibilityMode{}) : Format::supported, true, false, true, true, 4, kAnyFloat, 4, 8, 1, false, wgpu::TextureFormat::BGRA8Unorm);
406411
AddColorFormat(wgpu::TextureFormat::RGB10A2Unorm, true, false, true, true, 4, kAnyFloat, 4, 8, 4);
407412

408413
bool isRG11B10UfloatRenderable = device->HasFeature(Feature::RG11B10UfloatRenderable);

src/dawn/native/Format.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct Format {
112112
// A format can be known but not supported because it is part of a disabled extension.
113113
UnsupportedReason unsupportedReason;
114114
bool supportsStorageUsage = false;
115+
bool supportsReadWriteStorageUsage = false;
115116
bool supportsMultisample = false;
116117
bool supportsResolveTarget = false;
117118
Aspect aspects{};

src/dawn/tests/unittests/validation/StorageTextureValidationTests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,5 +903,24 @@ TEST_F(ReadWriteStorageTextureValidationTests, BindGroupLayoutWithStorageTexture
903903
DoBindGroupLayoutTest(kTestSpecs);
904904
}
905905

906+
// Test that using read-only storage texture in BindGroupLayout is valid with all formats that
907+
// can be used as storage texture, while read-write storage texture access is only available on the
908+
// formats that support read-write storage texture access.
909+
TEST_F(ReadWriteStorageTextureValidationTests, ReadWriteStorageTextureFormat) {
910+
for (wgpu::TextureFormat format : utils::kAllTextureFormats) {
911+
if (!utils::TextureFormatSupportsStorageTexture(format, UseCompatibilityMode())) {
912+
continue;
913+
}
914+
915+
bool supportsReadWriteStorageTexture =
916+
utils::TextureFormatSupportsReadWriteStorageTexture(format);
917+
const std::vector<BindGroupLayoutTestSpec> kTestSpecs = {
918+
{{wgpu::ShaderStage::Compute, wgpu::StorageTextureAccess::ReadOnly, true, format},
919+
{wgpu::ShaderStage::Compute, wgpu::StorageTextureAccess::ReadWrite,
920+
supportsReadWriteStorageTexture, format}}};
921+
DoBindGroupLayoutTest(kTestSpecs);
922+
}
923+
}
924+
906925
} // anonymous namespace
907926
} // namespace dawn

src/dawn/utils/TextureUtils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ bool TextureFormatSupportsResolveTarget(wgpu::TextureFormat textureFormat) {
192192
}
193193
}
194194

195+
bool TextureFormatSupportsReadWriteStorageTexture(wgpu::TextureFormat format) {
196+
switch (format) {
197+
case wgpu::TextureFormat::R32Float:
198+
case wgpu::TextureFormat::R32Sint:
199+
case wgpu::TextureFormat::R32Uint:
200+
return true;
201+
default:
202+
return false;
203+
}
204+
}
205+
195206
bool IsStencilOnlyFormat(wgpu::TextureFormat textureFormat) {
196207
return textureFormat == wgpu::TextureFormat::Stencil8;
197208
}

src/dawn/utils/TextureUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ static constexpr std::array<wgpu::TextureFormat, 2> kDepthAndStencilFormats = {
221221
};
222222

223223
bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format, bool isCompatibilityMode);
224+
bool TextureFormatSupportsReadWriteStorageTexture(wgpu::TextureFormat format);
224225

225226
bool IsBCTextureFormat(wgpu::TextureFormat textureFormat);
226227
bool IsETC2TextureFormat(wgpu::TextureFormat textureFormat);

0 commit comments

Comments
 (0)