Add test for external texture in different group from sampler
This CL adds a test for an external texture which exists in a different
bind group from the sampler that is used with the texture.
The test is currently disabled on Metal as it fails to build the binding
map correctly.
Bug: chromium:1515439
Change-Id: I6694974581863cab4ad594308ca1c2d5afd6409e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/168200
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/dawn/tests/end2end/ExternalTextureTests.cpp b/src/dawn/tests/end2end/ExternalTextureTests.cpp
index 781cb7e..8f6d882 100644
--- a/src/dawn/tests/end2end/ExternalTextureTests.cpp
+++ b/src/dawn/tests/end2end/ExternalTextureTests.cpp
@@ -222,6 +222,87 @@
EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderTexture, 0, 0);
}
+// https://crbug.com/1515439
+TEST_P(ExternalTextureTests, SampleExternalTextureDifferingGroup) {
+ // TODO(crbug.com/dawn/2295): diagnose this failure on Pixel 4 OpenGLES
+ DAWN_SUPPRESS_TEST_IF(IsOpenGLES() && IsAndroid() && IsQualcomm());
+ DAWN_SUPPRESS_TEST_IF(IsMetal());
+
+ wgpu::Texture sampledTexture =
+ Create2DTexture(device, kWidth, kHeight, kFormat,
+ wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::RenderAttachment);
+ wgpu::Texture renderTexture =
+ Create2DTexture(device, kWidth, kHeight, kFormat,
+ wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::RenderAttachment);
+
+ // Create a texture view for the external texture
+ wgpu::TextureView externalView = sampledTexture.CreateView();
+
+ // Initialize texture with green to ensure it is sampled from later.
+ {
+ utils::ComboRenderPassDescriptor renderPass({externalView}, nullptr);
+ renderPass.cColorAttachments[0].clearValue = {0.0f, 1.0f, 0.0f, 1.0f};
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
+ pass.End();
+
+ wgpu::CommandBuffer commands = encoder.Finish();
+ queue.Submit(1, &commands);
+ }
+
+ wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
+ @group(0) @binding(0) var s : sampler;
+ @group(1) @binding(0) var t : texture_external;
+
+ @fragment fn main(@builtin(position) FragCoord : vec4f)
+ -> @location(0) vec4f {
+ return textureSampleBaseClampToEdge(t, s, FragCoord.xy / vec2f(4.0, 4.0));
+ })");
+
+ // Pipeline Creation
+ utils::ComboRenderPipelineDescriptor descriptor;
+ descriptor.vertex.module = vsModule;
+ descriptor.cFragment.module = fsModule;
+ descriptor.cTargets[0].format = kFormat;
+ wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
+
+ // Create an ExternalTextureDescriptor from the texture view
+ wgpu::ExternalTextureDescriptor externalDesc = CreateDefaultExternalTextureDescriptor();
+ externalDesc.plane0 = externalView;
+ externalDesc.visibleOrigin = {0, 0};
+ externalDesc.visibleSize = {kWidth, kHeight};
+
+ // Import the external texture
+ wgpu::ExternalTexture externalTexture = device.CreateExternalTexture(&externalDesc);
+
+ // Create a sampler and bind group
+ wgpu::Sampler sampler = device.CreateSampler();
+
+ wgpu::BindGroup samplerBindGroup =
+ utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0), {{0, sampler}});
+ wgpu::BindGroup texBindGroup =
+ utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(1), {{0, externalTexture}});
+
+ // Run the shader, which should sample from the external texture and draw a triangle into the
+ // upper left corner of the render texture.
+ wgpu::TextureView renderView = renderTexture.CreateView();
+ utils::ComboRenderPassDescriptor renderPass({renderView}, nullptr);
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
+ {
+ pass.SetPipeline(pipeline);
+ pass.SetBindGroup(0, samplerBindGroup);
+ pass.SetBindGroup(1, texBindGroup);
+ pass.Draw(3);
+ pass.End();
+ }
+
+ wgpu::CommandBuffer commands = encoder.Finish();
+ queue.Submit(1, &commands);
+
+ EXPECT_PIXEL_RGBA8_EQ(utils::RGBA8::kGreen, renderTexture, 0, 0);
+}
+
TEST_P(ExternalTextureTests, SampleMultiplanarExternalTexture) {
// TODO(crbug.com/dawn/2295): diagnose this failure on Pixel 4 OpenGLES
DAWN_SUPPRESS_TEST_IF(IsOpenGLES() && IsAndroid() && IsQualcomm());