Precompute all the Formats at Device creation in the FormatTable
This is needed for two reasons:
- TextureBase and TextureViewBase stored Formats by value which isn't too
much overhead at this time but will get bigger in the future.
- The OpenGL backends needs its own GLFormat structure to store data about
each format which will eventually contain complicated logic to detect
support in the GL driver so it shouldn't be duplicated in Textures.
The computations of the information about Format is moved from being done
whenever they are needed to being precomputed at DeviceBase initialization.
This makes each format have a constant "index" in that can be used in the
backends to address their own structure, for example a GLFormat table.
Also some DeviceBase pointers were made const for validation.
BUG=dawn:128
Change-Id: I37d1e9c739b87cddcea09cb1759e175704d90f9e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9101
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp
index ae373bf..8be70b0 100644
--- a/src/dawn_native/Device.cpp
+++ b/src/dawn_native/Device.cpp
@@ -63,6 +63,8 @@
mFenceSignalTracker = std::make_unique<FenceSignalTracker>(this);
mDynamicUploader = std::make_unique<DynamicUploader>(this);
SetDefaultToggles();
+
+ mFormatTable = BuildFormatTable(this);
}
DeviceBase::~DeviceBase() {
@@ -100,6 +102,27 @@
return mFenceSignalTracker.get();
}
+ ResultOrError<const Format*> DeviceBase::GetInternalFormat(dawn::TextureFormat format) const {
+ size_t index = ComputeFormatIndex(format);
+ if (index >= mFormatTable.size()) {
+ return DAWN_VALIDATION_ERROR("Unknown texture format");
+ }
+
+ const Format* internalFormat = &mFormatTable[index];
+ if (!internalFormat->isSupported) {
+ return DAWN_VALIDATION_ERROR("Unsupported texture format");
+ }
+
+ return internalFormat;
+ }
+
+ const Format& DeviceBase::GetValidInternalFormat(dawn::TextureFormat format) const {
+ size_t index = ComputeFormatIndex(format);
+ ASSERT(index < mFormatTable.size());
+ ASSERT(mFormatTable[index].isSupported);
+ return mFormatTable[index];
+ }
+
ResultOrError<BindGroupLayoutBase*> DeviceBase::GetOrCreateBindGroupLayout(
const BindGroupLayoutDescriptor* descriptor) {
BindGroupLayoutBase blueprint(this, descriptor, true);