[YCbCr Samplers] Get supported SampleTypeBit for external format
Plumb supported SampleTypeBit for external format and set that when
validating the supported with required SampleTypeBits.
Change-Id: Id2cf5994e37c6ab5f2d9675111445aa73d5daef1
Bug: dawn:2476
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/192380
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Saifuddin Hitawala <hitawala@chromium.org>
diff --git a/src/dawn/native/BindGroup.cpp b/src/dawn/native/BindGroup.cpp
index 114fd47..d52be23 100644
--- a/src/dawn/native/BindGroup.cpp
+++ b/src/dawn/native/BindGroup.cpp
@@ -161,6 +161,11 @@
TextureBase* texture = view->GetTexture();
SampleTypeBit supportedTypes = texture->GetFormat().GetAspectInfo(aspect).supportedSampleTypes;
+ if (supportedTypes == SampleTypeBit::External) {
+ supportedTypes =
+ static_cast<SharedTextureMemoryContents*>(texture->GetSharedResourceMemoryContents())
+ ->GetExternalFormatSupportedSampleTypes();
+ }
DAWN_TRY(ValidateCanUseAs(texture, wgpu::TextureUsage::TextureBinding, mode));
DAWN_INVALID_IF(texture->IsMultisampledTexture() != layout.multisampled,
diff --git a/src/dawn/native/SharedTextureMemory.cpp b/src/dawn/native/SharedTextureMemory.cpp
index eafb189..b34eed2 100644
--- a/src/dawn/native/SharedTextureMemory.cpp
+++ b/src/dawn/native/SharedTextureMemory.cpp
@@ -29,6 +29,7 @@
#include <utility>
+#include "dawn/common/WeakRef.h"
#include "dawn/native/ChainUtils.h"
#include "dawn/native/Device.h"
#include "dawn/native/Queue.h"
@@ -201,6 +202,14 @@
return texture;
}
+Ref<SharedResourceMemoryContents> SharedTextureMemoryBase::CreateContents() {
+ return AcquireRef(new SharedTextureMemoryContents(GetWeakRef(this)));
+}
+
+SharedTextureMemoryContents* SharedTextureMemoryBase::GetContents() const {
+ return static_cast<SharedTextureMemoryContents*>(SharedResourceMemory::GetContents());
+}
+
void APISharedTextureMemoryEndAccessStateFreeMembers(WGPUSharedTextureMemoryEndAccessState cState) {
auto* state = reinterpret_cast<SharedTextureMemoryBase::EndAccessState*>(&cState);
for (size_t i = 0; i < state->fenceCount; ++i) {
@@ -210,4 +219,20 @@
delete[] state->signaledValues;
}
+// SharedTextureMemoryContents
+
+SharedTextureMemoryContents::SharedTextureMemoryContents(
+ WeakRef<SharedTextureMemoryBase> sharedTextureMemory)
+ : SharedResourceMemoryContents(sharedTextureMemory),
+ mSupportedExternalSampleTypes(SampleTypeBit::None) {}
+
+SampleTypeBit SharedTextureMemoryContents::GetExternalFormatSupportedSampleTypes() const {
+ return mSupportedExternalSampleTypes;
+}
+
+void SharedTextureMemoryContents::SetExternalFormatSupportedSampleTypes(
+ SampleTypeBit supportedSampleType) {
+ mSupportedExternalSampleTypes = supportedSampleType;
+}
+
} // namespace dawn::native
diff --git a/src/dawn/native/SharedTextureMemory.h b/src/dawn/native/SharedTextureMemory.h
index 839f2c8..8a61cdf 100644
--- a/src/dawn/native/SharedTextureMemory.h
+++ b/src/dawn/native/SharedTextureMemory.h
@@ -40,6 +40,7 @@
namespace dawn::native {
+class SharedTextureMemoryContents;
class SharedResourceMemoryContents;
struct SharedTextureMemoryDescriptor;
struct SharedTextureMemoryBeginAccessDescriptor;
@@ -60,6 +61,8 @@
ObjectType GetType() const override;
+ SharedTextureMemoryContents* GetContents() const;
+
protected:
SharedTextureMemoryBase(DeviceBase* device,
const char* label,
@@ -72,6 +75,8 @@
ResultOrError<Ref<TextureBase>> CreateTexture(const TextureDescriptor* rawDescriptor);
MaybeError GetProperties(SharedTextureMemoryProperties* properties) const;
+ Ref<SharedResourceMemoryContents> CreateContents() override;
+
virtual ResultOrError<Ref<TextureBase>> CreateTextureImpl(
const UnpackedPtr<TextureDescriptor>& descriptor) = 0;
@@ -83,6 +88,19 @@
SharedTextureMemoryProperties mProperties;
};
+class SharedTextureMemoryContents : public SharedResourceMemoryContents {
+ public:
+ explicit SharedTextureMemoryContents(WeakRef<SharedTextureMemoryBase> sharedTextureMemory);
+
+ SampleTypeBit GetExternalFormatSupportedSampleTypes() const;
+ void SetExternalFormatSupportedSampleTypes(SampleTypeBit supportedSampleType);
+
+ private:
+ friend class SharedTextureMemoryBase;
+
+ SampleTypeBit mSupportedExternalSampleTypes;
+};
+
} // namespace dawn::native
#endif // SRC_DAWN_NATIVE_SHAREDTEXTUREMEMORY_H_
diff --git a/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp b/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp
index c19f4b7..9e7ebf2 100644
--- a/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp
+++ b/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp
@@ -523,6 +523,7 @@
VkFormat vkFormat;
YCbCrVkDescriptor yCbCrAHBInfo;
+ SampleTypeBit externalSampleType;
VkAndroidHardwareBufferPropertiesANDROID bufferProperties = {
.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID,
};
@@ -574,10 +575,13 @@
yCbCrAHBInfo.vkYChromaOffset = bufferFormatProperties.suggestedYChromaOffset;
uint32_t formatFeatures = bufferFormatProperties.formatFeatures;
- yCbCrAHBInfo.vkChromaFilter =
- (formatFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT)
- ? wgpu::FilterMode::Linear
- : wgpu::FilterMode::Nearest;
+ if (formatFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT) {
+ yCbCrAHBInfo.vkChromaFilter = wgpu::FilterMode::Linear;
+ externalSampleType = SampleTypeBit::UnfilterableFloat | SampleTypeBit::Float;
+ } else {
+ yCbCrAHBInfo.vkChromaFilter = wgpu::FilterMode::Nearest;
+ externalSampleType = SampleTypeBit::UnfilterableFloat;
+ }
yCbCrAHBInfo.forceExplicitReconstruction =
formatFeatures &
VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT;
@@ -594,6 +598,7 @@
SharedTextureMemory::Create(device, label, properties, VK_QUEUE_FAMILY_FOREIGN_EXT);
sharedTextureMemory->mYCbCrAHBInfo = yCbCrAHBInfo;
+ sharedTextureMemory->GetContents()->SetExternalFormatSupportedSampleTypes(externalSampleType);
// Reflect properties to reify them.
sharedTextureMemory->APIGetProperties(&properties);