diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/third_party/dawn/src/utils | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/dawn/src/utils')
4 files changed, 241 insertions, 6 deletions
diff --git a/chromium/third_party/dawn/src/utils/TextureFormatUtils.cpp b/chromium/third_party/dawn/src/utils/TextureFormatUtils.cpp index 634417cd12c..795d1f948ac 100644 --- a/chromium/third_party/dawn/src/utils/TextureFormatUtils.cpp +++ b/chromium/third_party/dawn/src/utils/TextureFormatUtils.cpp @@ -86,4 +86,172 @@ namespace utils { return false; } } + + uint32_t GetTexelBlockSizeInBytes(wgpu::TextureFormat textureFormat) { + switch (textureFormat) { + case wgpu::TextureFormat::R8Unorm: + case wgpu::TextureFormat::R8Snorm: + case wgpu::TextureFormat::R8Uint: + case wgpu::TextureFormat::R8Sint: + return 1u; + + case wgpu::TextureFormat::R16Uint: + case wgpu::TextureFormat::R16Sint: + case wgpu::TextureFormat::R16Float: + case wgpu::TextureFormat::RG8Unorm: + case wgpu::TextureFormat::RG8Snorm: + case wgpu::TextureFormat::RG8Uint: + case wgpu::TextureFormat::RG8Sint: + return 2u; + + case wgpu::TextureFormat::R32Float: + case wgpu::TextureFormat::R32Uint: + case wgpu::TextureFormat::R32Sint: + case wgpu::TextureFormat::RG16Uint: + case wgpu::TextureFormat::RG16Sint: + case wgpu::TextureFormat::RG16Float: + case wgpu::TextureFormat::RGBA8Unorm: + case wgpu::TextureFormat::RGBA8UnormSrgb: + case wgpu::TextureFormat::RGBA8Snorm: + case wgpu::TextureFormat::RGBA8Uint: + case wgpu::TextureFormat::RGBA8Sint: + case wgpu::TextureFormat::BGRA8Unorm: + case wgpu::TextureFormat::BGRA8UnormSrgb: + case wgpu::TextureFormat::RGB10A2Unorm: + case wgpu::TextureFormat::RG11B10Float: + return 4u; + + case wgpu::TextureFormat::RG32Float: + case wgpu::TextureFormat::RG32Uint: + case wgpu::TextureFormat::RG32Sint: + case wgpu::TextureFormat::RGBA16Uint: + case wgpu::TextureFormat::RGBA16Sint: + case wgpu::TextureFormat::RGBA16Float: + return 8u; + + case wgpu::TextureFormat::RGBA32Float: + case wgpu::TextureFormat::RGBA32Uint: + case wgpu::TextureFormat::RGBA32Sint: + return 16u; + + case wgpu::TextureFormat::BC1RGBAUnorm: + case wgpu::TextureFormat::BC1RGBAUnormSrgb: + case wgpu::TextureFormat::BC4RUnorm: + case wgpu::TextureFormat::BC4RSnorm: + return 8u; + + case wgpu::TextureFormat::BC2RGBAUnorm: + case wgpu::TextureFormat::BC2RGBAUnormSrgb: + case wgpu::TextureFormat::BC3RGBAUnorm: + case wgpu::TextureFormat::BC3RGBAUnormSrgb: + case wgpu::TextureFormat::BC5RGUnorm: + case wgpu::TextureFormat::BC5RGSnorm: + case wgpu::TextureFormat::BC6HRGBUfloat: + case wgpu::TextureFormat::BC6HRGBSfloat: + case wgpu::TextureFormat::BC7RGBAUnorm: + case wgpu::TextureFormat::BC7RGBAUnormSrgb: + return 16u; + + case wgpu::TextureFormat::Depth32Float: + case wgpu::TextureFormat::Depth24Plus: + case wgpu::TextureFormat::Depth24PlusStencil8: + case wgpu::TextureFormat::Undefined: + default: + UNREACHABLE(); + return 0u; + } + } + + const char* GetGLSLImageFormatQualifier(wgpu::TextureFormat textureFormat) { + switch (textureFormat) { + case wgpu::TextureFormat::R8Unorm: + return "r8"; + case wgpu::TextureFormat::R8Snorm: + return "r8_snorm"; + case wgpu::TextureFormat::R8Uint: + return "r8ui"; + case wgpu::TextureFormat::R8Sint: + return "r8i"; + case wgpu::TextureFormat::R16Uint: + return "r16ui"; + case wgpu::TextureFormat::R16Sint: + return "r16i"; + case wgpu::TextureFormat::R16Float: + return "r16f"; + case wgpu::TextureFormat::RG8Unorm: + return "rg8"; + case wgpu::TextureFormat::RG8Snorm: + return "rg8_snorm"; + case wgpu::TextureFormat::RG8Uint: + return "rg8ui"; + case wgpu::TextureFormat::RG8Sint: + return "rg8i"; + case wgpu::TextureFormat::R32Float: + return "r32f"; + case wgpu::TextureFormat::R32Uint: + return "r32ui"; + case wgpu::TextureFormat::R32Sint: + return "r32i"; + case wgpu::TextureFormat::RG16Uint: + return "rg16ui"; + case wgpu::TextureFormat::RG16Sint: + return "rg16i"; + case wgpu::TextureFormat::RG16Float: + return "rg16f"; + case wgpu::TextureFormat::RGBA8Unorm: + return "rgba8"; + case wgpu::TextureFormat::RGBA8Snorm: + return "rgba8_snorm"; + case wgpu::TextureFormat::RGBA8Uint: + return "rgba8ui"; + case wgpu::TextureFormat::RGBA8Sint: + return "rgba8i"; + case wgpu::TextureFormat::RGB10A2Unorm: + return "rgb10_a2"; + case wgpu::TextureFormat::RG11B10Float: + return "r11f_g11f_b10f"; + case wgpu::TextureFormat::RG32Float: + return "rg32f"; + case wgpu::TextureFormat::RG32Uint: + return "rg32ui"; + case wgpu::TextureFormat::RG32Sint: + return "rg32i"; + case wgpu::TextureFormat::RGBA16Uint: + return "rgba16ui"; + case wgpu::TextureFormat::RGBA16Sint: + return "rgba16i"; + case wgpu::TextureFormat::RGBA16Float: + return "rgba16f"; + case wgpu::TextureFormat::RGBA32Float: + return "rgba32f"; + case wgpu::TextureFormat::RGBA32Uint: + return "rgba32ui"; + case wgpu::TextureFormat::RGBA32Sint: + return "rgba32i"; + + case wgpu::TextureFormat::RGBA8UnormSrgb: + case wgpu::TextureFormat::BGRA8Unorm: + case wgpu::TextureFormat::BGRA8UnormSrgb: + case wgpu::TextureFormat::BC1RGBAUnorm: + case wgpu::TextureFormat::BC1RGBAUnormSrgb: + case wgpu::TextureFormat::BC4RUnorm: + case wgpu::TextureFormat::BC4RSnorm: + case wgpu::TextureFormat::BC2RGBAUnorm: + case wgpu::TextureFormat::BC2RGBAUnormSrgb: + case wgpu::TextureFormat::BC3RGBAUnorm: + case wgpu::TextureFormat::BC3RGBAUnormSrgb: + case wgpu::TextureFormat::BC5RGUnorm: + case wgpu::TextureFormat::BC5RGSnorm: + case wgpu::TextureFormat::BC6HRGBUfloat: + case wgpu::TextureFormat::BC6HRGBSfloat: + case wgpu::TextureFormat::BC7RGBAUnorm: + case wgpu::TextureFormat::BC7RGBAUnormSrgb: + case wgpu::TextureFormat::Depth32Float: + case wgpu::TextureFormat::Depth24Plus: + case wgpu::TextureFormat::Depth24PlusStencil8: + case wgpu::TextureFormat::Undefined: + UNREACHABLE(); + return ""; + } + } } // namespace utils diff --git a/chromium/third_party/dawn/src/utils/TextureFormatUtils.h b/chromium/third_party/dawn/src/utils/TextureFormatUtils.h index bbd5f0c1846..2976e94d3fa 100644 --- a/chromium/third_party/dawn/src/utils/TextureFormatUtils.h +++ b/chromium/third_party/dawn/src/utils/TextureFormatUtils.h @@ -53,6 +53,9 @@ namespace utils { const char* GetColorTextureComponentTypePrefix(wgpu::TextureFormat textureFormat); bool TextureFormatSupportsStorageTexture(wgpu::TextureFormat format); + + uint32_t GetTexelBlockSizeInBytes(wgpu::TextureFormat textureFormat); + const char* GetGLSLImageFormatQualifier(wgpu::TextureFormat textureFormat); } // namespace utils #endif diff --git a/chromium/third_party/dawn/src/utils/WGPUHelpers.cpp b/chromium/third_party/dawn/src/utils/WGPUHelpers.cpp index 0d9b1f93fa9..686b223f35a 100644 --- a/chromium/third_party/dawn/src/utils/WGPUHelpers.cpp +++ b/chromium/third_party/dawn/src/utils/WGPUHelpers.cpp @@ -17,11 +17,14 @@ #include "common/Assert.h" #include "common/Constants.h" #include "common/Log.h" +#include "common/Math.h" +#include "utils/TextureFormatUtils.h" #include <shaderc/shaderc.hpp> #include <cstring> #include <iomanip> +#include <mutex> #include <sstream> namespace utils { @@ -160,9 +163,9 @@ namespace utils { wgpu::BufferDescriptor descriptor; descriptor.size = size; descriptor.usage = usage | wgpu::BufferUsage::CopyDst; - wgpu::Buffer buffer = device.CreateBuffer(&descriptor); - buffer.SetSubData(0, size, data); + + device.GetDefaultQueue().WriteBuffer(buffer, 0, data, size); return buffer; } @@ -251,7 +254,6 @@ namespace utils { descriptor.size.width = width; descriptor.size.height = height; descriptor.size.depth = 1; - descriptor.arrayLayerCount = 1; descriptor.sampleCount = 1; descriptor.format = BasicRenderPass::kDefaultColorFormat; descriptor.mipLevelCount = 1; @@ -276,12 +278,10 @@ namespace utils { wgpu::TextureCopyView CreateTextureCopyView(wgpu::Texture texture, uint32_t mipLevel, - uint32_t arrayLayer, wgpu::Origin3D origin) { wgpu::TextureCopyView textureCopyView; textureCopyView.texture = texture; textureCopyView.mipLevel = mipLevel; - textureCopyView.arrayLayer = arrayLayer; textureCopyView.origin = origin; return textureCopyView; @@ -374,4 +374,47 @@ namespace utils { return device.CreateBindGroup(&descriptor); } + uint32_t GetMinimumBytesPerRow(wgpu::TextureFormat format, uint32_t width) { + const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(format); + return Align(bytesPerTexel * width, kTextureBytesPerRowAlignment); + } + + uint32_t GetBytesInBufferTextureCopy(wgpu::TextureFormat format, + uint32_t width, + uint32_t bytesPerRow, + uint32_t rowsPerImage, + uint32_t copyArrayLayerCount) { + ASSERT(rowsPerImage > 0); + const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(format); + const uint32_t bytesAtLastImage = bytesPerRow * (rowsPerImage - 1) + bytesPerTexel * width; + return bytesPerRow * rowsPerImage * (copyArrayLayerCount - 1) + bytesAtLastImage; + } + + // TODO(jiawei.shao@intel.com): support compressed texture formats + BufferTextureCopyLayout GetBufferTextureCopyLayoutForTexture2DAtLevel( + wgpu::TextureFormat format, + wgpu::Extent3D textureSizeAtLevel0, + uint32_t mipmapLevel, + uint32_t rowsPerImage) { + BufferTextureCopyLayout layout; + + layout.mipSize = {textureSizeAtLevel0.width >> mipmapLevel, + textureSizeAtLevel0.height >> mipmapLevel, textureSizeAtLevel0.depth}; + + layout.bytesPerRow = GetMinimumBytesPerRow(format, layout.mipSize.width); + + uint32_t appliedRowsPerImage = rowsPerImage > 0 ? rowsPerImage : layout.mipSize.height; + layout.bytesPerImage = layout.bytesPerRow * appliedRowsPerImage; + + layout.byteLength = + GetBytesInBufferTextureCopy(format, layout.mipSize.width, layout.bytesPerRow, + appliedRowsPerImage, textureSizeAtLevel0.depth); + + const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(format); + layout.texelBlocksPerRow = layout.bytesPerRow / bytesPerTexel; + layout.texelBlocksPerImage = layout.bytesPerImage / bytesPerTexel; + layout.texelBlockCount = layout.byteLength / bytesPerTexel; + + return layout; + } } // namespace utils diff --git a/chromium/third_party/dawn/src/utils/WGPUHelpers.h b/chromium/third_party/dawn/src/utils/WGPUHelpers.h index 92bd518cc80..fdbd8648f77 100644 --- a/chromium/third_party/dawn/src/utils/WGPUHelpers.h +++ b/chromium/third_party/dawn/src/utils/WGPUHelpers.h @@ -53,7 +53,6 @@ namespace utils { uint32_t rowsPerImage); wgpu::TextureCopyView CreateTextureCopyView(wgpu::Texture texture, uint32_t level, - uint32_t slice, wgpu::Origin3D origin); struct ComboRenderPassDescriptor : public wgpu::RenderPassDescriptor { @@ -130,6 +129,28 @@ namespace utils { const wgpu::BindGroupLayout& layout, std::initializer_list<BindingInitializationHelper> entriesInitializer); + struct BufferTextureCopyLayout { + uint64_t byteLength; + uint64_t texelBlockCount; + uint32_t bytesPerRow; + uint32_t texelBlocksPerRow; + uint32_t bytesPerImage; + uint32_t texelBlocksPerImage; + wgpu::Extent3D mipSize; + }; + + uint32_t GetMinimumBytesPerRow(wgpu::TextureFormat format, uint32_t width); + uint32_t GetBytesInBufferTextureCopy(wgpu::TextureFormat format, + uint32_t width, + uint32_t bytesPerRow, + uint32_t rowsPerImage, + uint32_t copyArrayLayerCount); + BufferTextureCopyLayout GetBufferTextureCopyLayoutForTexture2DAtLevel( + wgpu::TextureFormat format, + wgpu::Extent3D textureSizeAtLevel0, + uint32_t mipmapLevel, + uint32_t rowsPerImage); + } // namespace utils #endif // UTILS_DAWNHELPERS_H_ |