Skip to content

Commit bdabd11

Browse files
Jiawei-ShaoDawn LUCI CQ
authored andcommitted
Add ReadOnly and ReadWrite storage texture access in BindGroupLayout
This patch adds the support of ReadOnly and ReadWrite storage texture access in BindGroupLayout behind the experimental feature "chromium-experimental-read-write-storage-texture". Bug: dawn:1972 Test: dawn_unittests Change-Id: Ib81e61085aceba0a6212536e781eceb4c2821e1a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/146621 Reviewed-by: Austin Eng <[email protected]> Kokoro: Kokoro <[email protected]> Reviewed-by: Corentin Wallez <[email protected]> Commit-Queue: Jiawei Shao <[email protected]>
1 parent 46b54d9 commit bdabd11

File tree

12 files changed

+138
-31
lines changed

12 files changed

+138
-31
lines changed

dawn.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@
339339
"category": "enum",
340340
"values": [
341341
{"value": 0, "name": "undefined", "jsrepr": "undefined", "valid": false},
342-
{"value": 1, "name": "write only"}
342+
{"value": 1, "name": "write only"},
343+
{"value": 2, "name": "read only"},
344+
{"value": 3, "name": "read write"}
343345
]
344346
},
345347
"storage texture binding layout": {
@@ -1808,6 +1810,7 @@
18081810
{"value": 1013, "name": "ANGLE texture sharing", "tags": ["dawn", "native"]},
18091811
{"value": 1014, "name": "chromium experimental subgroups", "tags": ["dawn"]},
18101812
{"value": 1015, "name": "chromium experimental subgroup uniform control flow", "tags": ["dawn"]},
1813+
{"value": 1016, "name": "chromium experimental read write storage texture", "tags": ["dawn"]},
18111814

18121815
{"value": 1100, "name": "shared texture memory vk dedicated allocation", "tags": ["dawn", "native"]},
18131816
{"value": 1101, "name": "shared texture memory a hardware buffer", "tags": ["dawn", "native"]},

src/dawn/native/BindGroupLayoutInternal.cpp

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,31 @@ MaybeError ValidateStorageTextureViewDimension(wgpu::TextureViewDimension dimens
6464
UNREACHABLE();
6565
}
6666

67+
MaybeError ValidateReadWriteStorageTextureAccess(
68+
DeviceBase* device,
69+
const StorageTextureBindingLayout& storageTextureBindingLayout) {
70+
switch (storageTextureBindingLayout.access) {
71+
case wgpu::StorageTextureAccess::ReadOnly:
72+
case wgpu::StorageTextureAccess::ReadWrite:
73+
if (!device->APIHasFeature(
74+
wgpu::FeatureName::ChromiumExperimentalReadWriteStorageTexture)) {
75+
return DAWN_VALIDATION_ERROR(
76+
"storage texture access %s cannot be used without feature "
77+
"%s",
78+
storageTextureBindingLayout.access,
79+
wgpu::FeatureName::ChromiumExperimentalReadWriteStorageTexture);
80+
}
81+
break;
82+
83+
case wgpu::StorageTextureAccess::WriteOnly:
84+
break;
85+
default:
86+
UNREACHABLE();
87+
}
88+
89+
return {};
90+
}
91+
6792
MaybeError ValidateBindGroupLayoutEntry(DeviceBase* device,
6893
const BindGroupLayoutEntry& entry,
6994
bool allowInternalBinding) {
@@ -143,11 +168,20 @@ MaybeError ValidateBindGroupLayoutEntry(DeviceBase* device,
143168
DAWN_TRY(ValidateStorageTextureViewDimension(storageTexture.viewDimension));
144169
}
145170

146-
if (storageTexture.access == wgpu::StorageTextureAccess::WriteOnly) {
147-
DAWN_INVALID_IF(entry.visibility & wgpu::ShaderStage::Vertex,
148-
"Write-only storage texture binding is used with a visibility (%s) "
149-
"that contains %s.",
150-
entry.visibility, wgpu::ShaderStage::Vertex);
171+
DAWN_TRY(ValidateReadWriteStorageTextureAccess(device, storageTexture));
172+
173+
switch (storageTexture.access) {
174+
case wgpu::StorageTextureAccess::ReadOnly:
175+
break;
176+
case wgpu::StorageTextureAccess::ReadWrite:
177+
case wgpu::StorageTextureAccess::WriteOnly:
178+
DAWN_INVALID_IF(entry.visibility & wgpu::ShaderStage::Vertex,
179+
"Storage texture binding with %s is used with a visibility (%s) "
180+
"that contains %s.",
181+
storageTexture.access, entry.visibility, wgpu::ShaderStage::Vertex);
182+
break;
183+
default:
184+
UNREACHABLE();
151185
}
152186
}
153187

src/dawn/native/CommandBufferStateTracker.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ Return FindStorageBufferBindingAliasing(
157157
switch (bindingInfo.storageTexture.access) {
158158
case wgpu::StorageTextureAccess::WriteOnly:
159159
break;
160-
// Continue for other StorageTextureAccess type when we have any.
160+
161+
// TODO(dawn:1972): Implement ReadOnly and ReadWrite storage texture
162+
case wgpu::StorageTextureAccess::ReadOnly:
163+
case wgpu::StorageTextureAccess::ReadWrite:
164+
case wgpu::StorageTextureAccess::Undefined:
161165
default:
162166
UNREACHABLE();
163167
}

src/dawn/native/Features.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ static constexpr FeatureEnumAndInfoList kFeatureNameAndInfoList = {{
100100
"used to investigate the semantic of subgroups and should not be relied upon.",
101101
"https://bugs.chromium.org/p/dawn/issues/detail?id=464",
102102
FeatureInfo::FeatureState::Experimental}},
103+
{Feature::ChromiumExperimentalReadWriteStorageTexture,
104+
{"chromium-experimental-read-write-storage-texture",
105+
"Experimental, supports ReadOnly and ReadWrite as storage texture access mode.",
106+
"https://bugs.chromium.org/p/dawn/issues/detail?id=1972",
107+
FeatureInfo::FeatureState::Experimental}},
103108
{Feature::DawnInternalUsages,
104109
{"dawn-internal-usages",
105110
"Add internal usages to resources to affect how the texture is allocated, but not "
@@ -315,6 +320,8 @@ Feature FromAPIFeature(wgpu::FeatureName feature) {
315320
return Feature::ChromiumExperimentalSubgroups;
316321
case wgpu::FeatureName::ChromiumExperimentalSubgroupUniformControlFlow:
317322
return Feature::ChromiumExperimentalSubgroupUniformControlFlow;
323+
case wgpu::FeatureName::ChromiumExperimentalReadWriteStorageTexture:
324+
return Feature::ChromiumExperimentalReadWriteStorageTexture;
318325
}
319326
return Feature::InvalidEnum;
320327
}
@@ -401,6 +408,8 @@ wgpu::FeatureName ToAPIFeature(Feature feature) {
401408
return wgpu::FeatureName::ChromiumExperimentalSubgroups;
402409
case Feature::ChromiumExperimentalSubgroupUniformControlFlow:
403410
return wgpu::FeatureName::ChromiumExperimentalSubgroupUniformControlFlow;
411+
case Feature::ChromiumExperimentalReadWriteStorageTexture:
412+
return wgpu::FeatureName::ChromiumExperimentalReadWriteStorageTexture;
404413
case Feature::EnumCount:
405414
break;
406415
}

src/dawn/native/Features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum class Feature {
4343
Float32Filterable,
4444
ChromiumExperimentalSubgroups,
4545
ChromiumExperimentalSubgroupUniformControlFlow,
46+
ChromiumExperimentalReadWriteStorageTexture,
4647

4748
// Dawn-specific
4849
DawnInternalUsages,

src/dawn/native/PassResourceUsageTracker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ void SyncScopeUsageTracker::AddBindGroup(BindGroupBase* group) {
132132
case wgpu::StorageTextureAccess::WriteOnly:
133133
TextureViewUsedAs(view, wgpu::TextureUsage::StorageBinding);
134134
break;
135+
136+
// TODO(dawn:1972): Implement ReadOnly and ReadWrite storage texture
137+
case wgpu::StorageTextureAccess::ReadOnly:
138+
case wgpu::StorageTextureAccess::ReadWrite:
135139
case wgpu::StorageTextureAccess::Undefined:
136140
UNREACHABLE();
137141
}

src/dawn/native/PhysicalDevice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ MaybeError PhysicalDeviceBase::Initialize() {
3838
EnableFeature(Feature::DawnNative);
3939
EnableFeature(Feature::DawnInternalUsages);
4040
EnableFeature(Feature::ImplicitDeviceSynchronization);
41+
EnableFeature(Feature::ChromiumExperimentalReadWriteStorageTexture);
4142
InitializeSupportedFeaturesImpl();
4243

4344
DAWN_TRY_CONTEXT(

src/dawn/native/d3d12/BindGroupD3D12.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ BindGroup::BindGroup(Device* device,
171171
break;
172172
}
173173

174+
// TODO(dawn:1972): Implement ReadOnly and ReadWrite storage texture
175+
case wgpu::StorageTextureAccess::ReadOnly:
176+
case wgpu::StorageTextureAccess::ReadWrite:
174177
case wgpu::StorageTextureAccess::Undefined:
175178
UNREACHABLE();
176179
}

src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ D3D12_DESCRIPTOR_RANGE_TYPE WGPUBindingInfoToDescriptorRangeType(const BindingIn
4949
switch (bindingInfo.storageTexture.access) {
5050
case wgpu::StorageTextureAccess::WriteOnly:
5151
return D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
52+
53+
// TODO(dawn:1972): Implement ReadOnly and ReadWrite storage texture
54+
case wgpu::StorageTextureAccess::ReadOnly:
55+
case wgpu::StorageTextureAccess::ReadWrite:
5256
case wgpu::StorageTextureAccess::Undefined:
5357
UNREACHABLE();
5458
}

src/dawn/native/opengl/CommandBufferGL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ class BindGroupTracker : public BindGroupTrackerBase<false, uint64_t> {
349349
case wgpu::StorageTextureAccess::WriteOnly:
350350
access = GL_WRITE_ONLY;
351351
break;
352+
353+
// TODO(dawn:1972): Implement ReadOnly and ReadWrite storage texture
354+
case wgpu::StorageTextureAccess::ReadOnly:
355+
case wgpu::StorageTextureAccess::ReadWrite:
352356
case wgpu::StorageTextureAccess::Undefined:
353357
UNREACHABLE();
354358
}

0 commit comments

Comments
 (0)