From 81bcbbc20ee522b3039d981d5d24aa8e82f4b94c Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 19 Mar 2020 14:25:51 +0000 Subject: [PATCH] Add storage texture format reflection to spvc path Roll third_party/shaderc/ 95185d920..362becca1 (2 commits) https://chromium.googlesource.com/external/github.com/google/shaderc/+log/95185d920a0b..362becca1ff2 $ git log 95185d920..362becca1 --date=short --no-merges --format='%ad %ae %s' 2020-03-18 rharrison Add support for storage texture format reflection (#1005) 2020-03-18 dgkoch Remove NV_EXTENSIONS conditionals (#1003) Created with: roll-dep third_party/shaderc BUG=dawn:337 Change-Id: I8b4dda98bcdac9eea170fe2a05bbeb75f48379e9 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/17300 Reviewed-by: Austin Eng Reviewed-by: Kai Ninomiya Reviewed-by: Jiawei Shao Commit-Queue: Ryan Harrison --- DEPS | 2 +- src/dawn_native/ShaderModule.cpp | 94 +++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index 9539518b1b..93cf72cb06 100644 --- a/DEPS +++ b/DEPS @@ -69,7 +69,7 @@ deps = { 'condition': 'dawn_standalone', }, 'third_party/shaderc': { - 'url': '{chromium_git}/external/github.com/google/shaderc@95185d920a0b3d5a493f6f705ad8f0245c7d55cf', + 'url': '{chromium_git}/external/github.com/google/shaderc@362becca1ff2a841c21fd675ac3a9c1ee9bb5612', 'condition': 'dawn_standalone', }, diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 9e0165c204..fc374ecd4d 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -209,6 +209,77 @@ namespace dawn_native { return wgpu::TextureFormat::Undefined; } } + + wgpu::TextureFormat ToWGPUTextureFormat(shaderc_spvc_storage_texture_format format) { + switch (format) { + case shaderc_spvc_storage_texture_format_r8unorm: + return wgpu::TextureFormat::R8Unorm; + case shaderc_spvc_storage_texture_format_r8snorm: + return wgpu::TextureFormat::R8Snorm; + case shaderc_spvc_storage_texture_format_r8uint: + return wgpu::TextureFormat::R8Uint; + case shaderc_spvc_storage_texture_format_r8sint: + return wgpu::TextureFormat::R8Sint; + case shaderc_spvc_storage_texture_format_r16uint: + return wgpu::TextureFormat::R16Uint; + case shaderc_spvc_storage_texture_format_r16sint: + return wgpu::TextureFormat::R16Sint; + case shaderc_spvc_storage_texture_format_r16float: + return wgpu::TextureFormat::R16Float; + case shaderc_spvc_storage_texture_format_rg8unorm: + return wgpu::TextureFormat::RG8Unorm; + case shaderc_spvc_storage_texture_format_rg8snorm: + return wgpu::TextureFormat::RG8Snorm; + case shaderc_spvc_storage_texture_format_rg8uint: + return wgpu::TextureFormat::RG8Uint; + case shaderc_spvc_storage_texture_format_rg8sint: + return wgpu::TextureFormat::RG8Sint; + case shaderc_spvc_storage_texture_format_r32float: + return wgpu::TextureFormat::R32Float; + case shaderc_spvc_storage_texture_format_r32uint: + return wgpu::TextureFormat::R32Uint; + case shaderc_spvc_storage_texture_format_r32sint: + return wgpu::TextureFormat::R32Sint; + case shaderc_spvc_storage_texture_format_rg16uint: + return wgpu::TextureFormat::RG16Uint; + case shaderc_spvc_storage_texture_format_rg16sint: + return wgpu::TextureFormat::RG16Sint; + case shaderc_spvc_storage_texture_format_rg16float: + return wgpu::TextureFormat::RG16Float; + case shaderc_spvc_storage_texture_format_rgba8unorm: + return wgpu::TextureFormat::RGBA8Unorm; + case shaderc_spvc_storage_texture_format_rgba8snorm: + return wgpu::TextureFormat::RGBA8Snorm; + case shaderc_spvc_storage_texture_format_rgba8uint: + return wgpu::TextureFormat::RGBA8Uint; + case shaderc_spvc_storage_texture_format_rgba8sint: + return wgpu::TextureFormat::RGBA8Sint; + case shaderc_spvc_storage_texture_format_rgb10a2unorm: + return wgpu::TextureFormat::RGB10A2Unorm; + case shaderc_spvc_storage_texture_format_rg11b10float: + return wgpu::TextureFormat::RG11B10Float; + case shaderc_spvc_storage_texture_format_rg32float: + return wgpu::TextureFormat::RG32Float; + case shaderc_spvc_storage_texture_format_rg32uint: + return wgpu::TextureFormat::RG32Uint; + case shaderc_spvc_storage_texture_format_rg32sint: + return wgpu::TextureFormat::RG32Sint; + case shaderc_spvc_storage_texture_format_rgba16uint: + return wgpu::TextureFormat::RGBA16Uint; + case shaderc_spvc_storage_texture_format_rgba16sint: + return wgpu::TextureFormat::RGBA16Sint; + case shaderc_spvc_storage_texture_format_rgba16float: + return wgpu::TextureFormat::RGBA16Float; + case shaderc_spvc_storage_texture_format_rgba32float: + return wgpu::TextureFormat::RGBA32Float; + case shaderc_spvc_storage_texture_format_rgba32uint: + return wgpu::TextureFormat::RGBA32Uint; + case shaderc_spvc_storage_texture_format_rgba32sint: + return wgpu::TextureFormat::RGBA32Sint; + default: + return wgpu::TextureFormat::Undefined; + } + } } // anonymous namespace MaybeError ValidateShaderModuleDescriptor(DeviceBase*, @@ -322,11 +393,32 @@ namespace dawn_native { info->textureComponentType = ToDawnFormatType(binding.texture_component_type); } info->type = ToWGPUBindingType(binding.binding_type); + + switch (info->type) { + case wgpu::BindingType::StorageTexture: + case wgpu::BindingType::ReadonlyStorageTexture: + case wgpu::BindingType::WriteonlyStorageTexture: { + wgpu::TextureFormat storageTextureFormat = + ToWGPUTextureFormat(binding.storage_texture_format); + if (storageTextureFormat == wgpu::TextureFormat::Undefined) { + return DAWN_VALIDATION_ERROR( + "Invalid image format declaration on storage image"); + } + const Format& format = + GetDevice()->GetValidInternalFormat(storageTextureFormat); + if (!format.supportsStorageUsage) { + return DAWN_VALIDATION_ERROR( + "The storage texture format is not supported"); + } + info->storageTextureFormat = storageTextureFormat; + } break; + default: + break; + } } return {}; }; - // TODO(jiawei.shao@intel.com): extract binding information about storage textures. std::vector resource_bindings; DAWN_TRY(CheckSpvcSuccess(mSpvcContext.GetBindingInfo( shaderc_spvc_shader_resource_uniform_buffers,