diff options
author | Matthew Denton <mpdenton@chromium.org> | 2024-03-22 05:49:59 -0700 |
---|---|---|
committer | Angle LUCI CQ <angle-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-04-15 22:34:53 +0000 |
commit | 6557da03c85eee30448e1fefc2d89bdc348c580d (patch) | |
tree | 727ee316abc445d234feedca48eb3995e1ef0bb0 | |
parent | 50d95bfea3d144addf5eb3ce87a8257c20b2d796 (diff) | |
download | angle-6557da03c85eee30448e1fefc2d89bdc348c580d.tar.gz |
Implement TextureWgpu::getAttachmentRenderTarget()
Most of this is copied from TextureVk::getAttachmentRenderTarget() with
parts removed to make it simpler to start.
Need to check what happens when running a clear test.
Bug: angleproject:8582
Change-Id: Ia3b1f057add7714c7b192af1a3bf0edb41ccb649
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5388077
Reviewed-by: Liza Burakova <liza@chromium.org>
Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
-rw-r--r-- | src/libANGLE/renderer/wgpu/TextureWgpu.cpp | 155 | ||||
-rw-r--r-- | src/libANGLE/renderer/wgpu/TextureWgpu.h | 21 |
2 files changed, 176 insertions, 0 deletions
diff --git a/src/libANGLE/renderer/wgpu/TextureWgpu.cpp b/src/libANGLE/renderer/wgpu/TextureWgpu.cpp index ae14794212..0dbbc6c9cb 100644 --- a/src/libANGLE/renderer/wgpu/TextureWgpu.cpp +++ b/src/libANGLE/renderer/wgpu/TextureWgpu.cpp @@ -10,13 +10,71 @@ #include "libANGLE/renderer/wgpu/TextureWgpu.h" #include "common/debug.h" +#include "libANGLE/Error.h" #include "libANGLE/angletypes.h" #include "libANGLE/renderer/wgpu/ContextWgpu.h" #include "libANGLE/renderer/wgpu/DisplayWgpu.h" +#include "libANGLE/renderer/wgpu/RenderTargetWgpu.h" namespace rx { +namespace +{ + +void GetRenderTargetLayerCountAndIndex(webgpu::ImageHelper *image, + const gl::ImageIndex &index, + GLuint *layerIndex, + GLuint *layerCount, + GLuint *imageLayerCount) +{ + *layerIndex = index.hasLayer() ? index.getLayerIndex() : 0; + *layerCount = index.getLayerCount(); + + switch (index.getType()) + { + case gl::TextureType::_2D: + case gl::TextureType::_2DMultisample: + case gl::TextureType::External: + ASSERT(*layerIndex == 0 && + (*layerCount == 1 || + *layerCount == static_cast<GLuint>(gl::ImageIndex::kEntireLevel))); + *imageLayerCount = 1; + break; + + case gl::TextureType::CubeMap: + ASSERT(!index.hasLayer() || + *layerIndex == static_cast<GLuint>(index.cubeMapFaceIndex())); + *imageLayerCount = gl::kCubeFaceCount; + break; + + case gl::TextureType::_3D: + { + gl::LevelIndex levelGL(index.getLevelIndex()); + *imageLayerCount = image->getTextureDescriptor().size.depthOrArrayLayers; + break; + } + + case gl::TextureType::_2DArray: + case gl::TextureType::_2DMultisampleArray: + case gl::TextureType::CubeMapArray: + // NOTE: Not yet supported, should set *imageLayerCount. + UNIMPLEMENTED(); + break; + + default: + UNREACHABLE(); + } + + if (*layerCount == static_cast<GLuint>(gl::ImageIndex::kEntireLevel)) + { + ASSERT(*layerIndex == 0); + *layerCount = *imageLayerCount; + } +} + +} // namespace + TextureWgpu::TextureWgpu(const gl::TextureState &state) : TextureImpl(state) {} TextureWgpu::~TextureWgpu() {} @@ -236,6 +294,48 @@ angle::Result TextureWgpu::initializeContents(const gl::Context *context, return angle::Result::Continue; } +angle::Result TextureWgpu::getAttachmentRenderTarget(const gl::Context *context, + GLenum binding, + const gl::ImageIndex &imageIndex, + GLsizei samples, + FramebufferAttachmentRenderTarget **rtOut) +{ + GLuint layerIndex = 0, layerCount = 0, imageLayerCount = 0; + GetRenderTargetLayerCountAndIndex(mImage, imageIndex, &layerIndex, &layerCount, + &imageLayerCount); + + ContextWgpu *contextWgpu = GetImplAs<ContextWgpu>(context); + + // NOTE: Multisampling not yet supported + ASSERT(samples <= 1); + const gl::RenderToTextureImageIndex renderToTextureIndex = + gl::RenderToTextureImageIndex::Default; + + if (layerCount == 1) + { + initSingleLayerRenderTargets(contextWgpu, imageLayerCount, + gl::LevelIndex(imageIndex.getLevelIndex()), + renderToTextureIndex); + + std::vector<std::vector<RenderTargetWgpu>> &levelRenderTargets = + mSingleLayerRenderTargets[renderToTextureIndex]; + ASSERT(imageIndex.getLevelIndex() < static_cast<int32_t>(levelRenderTargets.size())); + + std::vector<RenderTargetWgpu> &layerRenderTargets = + levelRenderTargets[imageIndex.getLevelIndex()]; + ASSERT(imageIndex.getLayerIndex() < static_cast<int32_t>(layerRenderTargets.size())); + + *rtOut = &layerRenderTargets[layerIndex]; + } + else + { + // Not yet supported. + UNIMPLEMENTED(); + } + + return angle::Result::Continue; +} + angle::Result TextureWgpu::setImageImpl(const gl::Context *context, const gl::ImageIndex &index, const gl::Extents &size) @@ -280,4 +380,59 @@ angle::Result TextureWgpu::redefineLevel(const gl::Context *context, return angle::Result::Continue; } +void TextureWgpu::initSingleLayerRenderTargets(ContextWgpu *contextWgpu, + GLuint layerCount, + gl::LevelIndex levelIndex, + gl::RenderToTextureImageIndex renderToTextureIndex) +{ + std::vector<std::vector<RenderTargetWgpu>> &allLevelsRenderTargets = + mSingleLayerRenderTargets[renderToTextureIndex]; + + if (allLevelsRenderTargets.size() <= static_cast<uint32_t>(levelIndex.get())) + { + allLevelsRenderTargets.resize(levelIndex.get() + 1); + } + + std::vector<RenderTargetWgpu> &renderTargets = allLevelsRenderTargets[levelIndex.get()]; + + // Lazy init. Check if already initialized. + if (!renderTargets.empty()) + { + return; + } + + // There are |layerCount| render targets, one for each layer + renderTargets.resize(layerCount); + + for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) + { + wgpu::TextureViewDescriptor textureViewDesc; + textureViewDesc.aspect = wgpu::TextureAspect::All; + textureViewDesc.baseArrayLayer = layerIndex; + textureViewDesc.arrayLayerCount = 1; + textureViewDesc.baseMipLevel = mImage->toWgpuLevel(levelIndex).get(); + textureViewDesc.mipLevelCount = 1; + switch (mImage->getTextureDescriptor().dimension) + { + case wgpu::TextureDimension::Undefined: + textureViewDesc.dimension = wgpu::TextureViewDimension::Undefined; + break; + case wgpu::TextureDimension::e1D: + textureViewDesc.dimension = wgpu::TextureViewDimension::e1D; + break; + case wgpu::TextureDimension::e2D: + textureViewDesc.dimension = wgpu::TextureViewDimension::e2D; + break; + case wgpu::TextureDimension::e3D: + textureViewDesc.dimension = wgpu::TextureViewDimension::e3D; + break; + } + textureViewDesc.format = mImage->getTextureDescriptor().format; + wgpu::TextureView textureView = mImage->getTexture().CreateView(&textureViewDesc); + + renderTargets[layerIndex].set(textureView, mImage->toWgpuLevel(levelIndex), layerIndex, + mImage->toWgpuTextureFormat()); + } +} + } // namespace rx diff --git a/src/libANGLE/renderer/wgpu/TextureWgpu.h b/src/libANGLE/renderer/wgpu/TextureWgpu.h index d945cdfe42..9009a1659a 100644 --- a/src/libANGLE/renderer/wgpu/TextureWgpu.h +++ b/src/libANGLE/renderer/wgpu/TextureWgpu.h @@ -11,6 +11,8 @@ #define LIBANGLE_RENDERER_WGPU_TEXTUREWGPU_H_ #include "libANGLE/renderer/TextureImpl.h" +#include "libANGLE/renderer/wgpu/ContextWgpu.h" +#include "libANGLE/renderer/wgpu/RenderTargetWgpu.h" #include "libANGLE/renderer/wgpu/wgpu_helpers.h" namespace rx @@ -164,6 +166,12 @@ class TextureWgpu : public TextureImpl GLenum binding, const gl::ImageIndex &imageIndex) override; + angle::Result getAttachmentRenderTarget(const gl::Context *context, + GLenum binding, + const gl::ImageIndex &imageIndex, + GLsizei samples, + FramebufferAttachmentRenderTarget **rtOut) override; + webgpu::ImageHelper *getImage() { return mImage; } private: @@ -174,7 +182,20 @@ class TextureWgpu : public TextureImpl angle::Result redefineLevel(const gl::Context *context, const gl::ImageIndex &index, const gl::Extents &size); + + void initSingleLayerRenderTargets(ContextWgpu *contextWgpu, + GLuint layerCount, + gl::LevelIndex levelIndex, + gl::RenderToTextureImageIndex renderToTextureIndex); webgpu::ImageHelper *mImage; + + // Render targets stored as array of vector of vectors + // + // - First dimension: only RenderToTextureImageIndex::Default for now. + // - Second dimension: level + // - Third dimension: layer + gl::RenderToTextureImageMap<std::vector<std::vector<RenderTargetWgpu>>> + mSingleLayerRenderTargets; }; } // namespace rx |