ShaderModule: Don't use Format::Type for reflection.

Previously Format::Type was used instead of wgpu::TextureComponentType
so that ::Other could server as a tag value. This was confusing and
almost the single use of ::Other.

In a follow-up CL the format baseType is changed to be a per-aspect
value, and Format::Type. This CL is a self-contained step in that
direction.

Bug: dawn:527

Change-Id: Ida834087f45a8fca17670ffe8ebd4d5c4f1cd423
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30102
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2020-10-15 13:51:33 +00:00 committed by Commit Bot service account
parent 49c30a70e8
commit 5931c0ac3b
12 changed files with 34 additions and 45 deletions

View File

@ -114,7 +114,9 @@ namespace dawn_native {
switch (requiredUsage) { switch (requiredUsage) {
case wgpu::TextureUsage::Sampled: { case wgpu::TextureUsage::Sampled: {
if (!texture->GetFormat().HasComponentType(bindingInfo.textureComponentType)) { if (!texture->GetFormat().HasComponentType(
Format::TextureComponentTypeToFormatType(
bindingInfo.textureComponentType))) {
return DAWN_VALIDATION_ERROR("texture component type usage mismatch"); return DAWN_VALIDATION_ERROR("texture component type usage mismatch");
} }
break; break;

View File

@ -280,8 +280,7 @@ namespace dawn_native {
mBindingInfo[i].binding = BindingNumber(binding.binding); mBindingInfo[i].binding = BindingNumber(binding.binding);
mBindingInfo[i].type = binding.type; mBindingInfo[i].type = binding.type;
mBindingInfo[i].visibility = binding.visibility; mBindingInfo[i].visibility = binding.visibility;
mBindingInfo[i].textureComponentType = mBindingInfo[i].textureComponentType = binding.textureComponentType;
Format::TextureComponentTypeToFormatType(binding.textureComponentType);
mBindingInfo[i].storageTextureFormat = binding.storageTextureFormat; mBindingInfo[i].storageTextureFormat = binding.storageTextureFormat;
mBindingInfo[i].minBufferBindingSize = binding.minBufferBindingSize; mBindingInfo[i].minBufferBindingSize = binding.minBufferBindingSize;

View File

@ -52,7 +52,7 @@ namespace dawn_native {
BindingNumber binding; BindingNumber binding;
wgpu::ShaderStage visibility; wgpu::ShaderStage visibility;
wgpu::BindingType type; wgpu::BindingType type;
Format::Type textureComponentType = Format::Type::Float; wgpu::TextureComponentType textureComponentType = wgpu::TextureComponentType::Float;
wgpu::TextureViewDimension viewDimension = wgpu::TextureViewDimension::Undefined; wgpu::TextureViewDimension viewDimension = wgpu::TextureViewDimension::Undefined;
wgpu::TextureFormat storageTextureFormat = wgpu::TextureFormat::Undefined; wgpu::TextureFormat storageTextureFormat = wgpu::TextureFormat::Undefined;
bool hasDynamicOffset = false; bool hasDynamicOffset = false;

View File

@ -117,8 +117,7 @@ namespace dawn_native {
entry.type = shaderBinding.type; entry.type = shaderBinding.type;
entry.hasDynamicOffset = false; entry.hasDynamicOffset = false;
entry.viewDimension = shaderBinding.viewDimension; entry.viewDimension = shaderBinding.viewDimension;
entry.textureComponentType = entry.textureComponentType = shaderBinding.textureComponentType;
Format::FormatTypeToTextureComponentType(shaderBinding.textureComponentType);
entry.storageTextureFormat = shaderBinding.storageTextureFormat; entry.storageTextureFormat = shaderBinding.storageTextureFormat;
entry.minBufferBindingSize = shaderBinding.minBufferBindingSize; entry.minBufferBindingSize = shaderBinding.minBufferBindingSize;
return entry; return entry;

View File

@ -144,7 +144,8 @@ namespace dawn_native {
MaybeError ValidateColorStateDescriptor(const DeviceBase* device, MaybeError ValidateColorStateDescriptor(const DeviceBase* device,
const ColorStateDescriptor& descriptor, const ColorStateDescriptor& descriptor,
Format::Type fragmentOutputBaseType) { bool fragmentWritten,
wgpu::TextureComponentType fragmentOutputBaseType) {
if (descriptor.nextInChain != nullptr) { if (descriptor.nextInChain != nullptr) {
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr"); return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
} }
@ -161,8 +162,8 @@ namespace dawn_native {
if (!format->IsColor() || !format->isRenderable) { if (!format->IsColor() || !format->isRenderable) {
return DAWN_VALIDATION_ERROR("Color format must be color renderable"); return DAWN_VALIDATION_ERROR("Color format must be color renderable");
} }
if (fragmentOutputBaseType != Format::Type::Other && if (fragmentWritten &&
fragmentOutputBaseType != format->type) { fragmentOutputBaseType != Format::FormatTypeToTextureComponentType(format->type)) {
return DAWN_VALIDATION_ERROR( return DAWN_VALIDATION_ERROR(
"Color format must match the fragment stage output type"); "Color format must match the fragment stage output type");
} }
@ -356,6 +357,7 @@ namespace dawn_native {
i < ColorAttachmentIndex(static_cast<uint8_t>(descriptor->colorStateCount)); ++i) { i < ColorAttachmentIndex(static_cast<uint8_t>(descriptor->colorStateCount)); ++i) {
DAWN_TRY(ValidateColorStateDescriptor( DAWN_TRY(ValidateColorStateDescriptor(
device, descriptor->colorStates[static_cast<uint8_t>(i)], device, descriptor->colorStates[static_cast<uint8_t>(i)],
fragmentMetadata.fragmentOutputsWritten[i],
fragmentMetadata.fragmentOutputFormatBaseTypes[i])); fragmentMetadata.fragmentOutputFormatBaseTypes[i]));
} }

View File

@ -553,7 +553,7 @@ namespace dawn_native {
info->viewDimension = info->viewDimension =
SpirvDimToTextureViewDimension(imageType.dim, imageType.arrayed); SpirvDimToTextureViewDimension(imageType.dim, imageType.arrayed);
info->textureComponentType = info->textureComponentType =
SpirvBaseTypeToFormatType(textureComponentType); SpirvBaseTypeToTextureComponentType(textureComponentType);
if (imageType.ms) { if (imageType.ms) {
info->type = wgpu::BindingType::MultisampledTexture; info->type = wgpu::BindingType::MultisampledTexture;
} else { } else {
@ -682,12 +682,9 @@ namespace dawn_native {
spirv_cross::SPIRType::BaseType shaderFragmentOutputBaseType = spirv_cross::SPIRType::BaseType shaderFragmentOutputBaseType =
compiler.get_type(fragmentOutput.base_type_id).basetype; compiler.get_type(fragmentOutput.base_type_id).basetype;
Format::Type formatType = metadata->fragmentOutputFormatBaseTypes[attachment] =
SpirvBaseTypeToFormatType(shaderFragmentOutputBaseType); SpirvBaseTypeToTextureComponentType(shaderFragmentOutputBaseType);
if (formatType == Format::Type::Other) { metadata->fragmentOutputsWritten.set(attachment);
return DAWN_VALIDATION_ERROR("Unexpected Fragment output type");
}
metadata->fragmentOutputFormatBaseTypes[attachment] = formatType;
} }
} }
@ -771,12 +768,6 @@ namespace dawn_native {
return {}; return {};
} }
// EntryPointMetadata
EntryPointMetadata::EntryPointMetadata() {
fragmentOutputFormatBaseTypes.fill(Format::Type::Other);
}
// ShaderModuleBase // ShaderModuleBase
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor) ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor)

View File

@ -52,8 +52,6 @@ namespace dawn_native {
// pointers to EntryPointMetadata are safe to store as long as you also keep a Ref to the // pointers to EntryPointMetadata are safe to store as long as you also keep a Ref to the
// ShaderModuleBase. // ShaderModuleBase.
struct EntryPointMetadata { struct EntryPointMetadata {
EntryPointMetadata();
// Per-binding shader metadata contains some SPIRV specific information in addition to // Per-binding shader metadata contains some SPIRV specific information in addition to
// most of the frontend per-binding information. // most of the frontend per-binding information.
struct ShaderBindingInfo : BindingInfo { struct ShaderBindingInfo : BindingInfo {
@ -76,11 +74,10 @@ namespace dawn_native {
// The set of vertex attributes this entryPoint uses. // The set of vertex attributes this entryPoint uses.
std::bitset<kMaxVertexAttributes> usedVertexAttributes; std::bitset<kMaxVertexAttributes> usedVertexAttributes;
// An array to record the basic types (float, int and uint) of the fragment shader outputs // An array to record the basic types (float, int and uint) of the fragment shader outputs.
// or Format::Type::Other means the fragment shader output is unused. ityp::array<ColorAttachmentIndex, wgpu::TextureComponentType, kMaxColorAttachments>
using FragmentOutputBaseTypes = fragmentOutputFormatBaseTypes;
ityp::array<ColorAttachmentIndex, Format::Type, kMaxColorAttachments>; ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> fragmentOutputsWritten;
FragmentOutputBaseTypes fragmentOutputFormatBaseTypes;
// The local workgroup size declared for a compute entry point (or 0s otehrwise). // The local workgroup size declared for a compute entry point (or 0s otehrwise).
Origin3D localWorkgroupSize; Origin3D localWorkgroupSize;

View File

@ -134,14 +134,15 @@ namespace dawn_native {
} }
} }
Format::Type SpirvBaseTypeToFormatType(spirv_cross::SPIRType::BaseType spirvBaseType) { wgpu::TextureComponentType SpirvBaseTypeToTextureComponentType(
spirv_cross::SPIRType::BaseType spirvBaseType) {
switch (spirvBaseType) { switch (spirvBaseType) {
case spirv_cross::SPIRType::Float: case spirv_cross::SPIRType::Float:
return Format::Type::Float; return wgpu::TextureComponentType::Float;
case spirv_cross::SPIRType::Int: case spirv_cross::SPIRType::Int:
return Format::Type::Sint; return wgpu::TextureComponentType::Sint;
case spirv_cross::SPIRType::UInt: case spirv_cross::SPIRType::UInt:
return Format::Type::Uint; return wgpu::TextureComponentType::Uint;
default: default:
UNREACHABLE(); UNREACHABLE();
} }

View File

@ -37,7 +37,8 @@ namespace dawn_native {
wgpu::TextureFormat SpirvImageFormatToTextureFormat(spv::ImageFormat format); wgpu::TextureFormat SpirvImageFormatToTextureFormat(spv::ImageFormat format);
// Returns the format "component type" corresponding to the SPIRV base type. // Returns the format "component type" corresponding to the SPIRV base type.
Format::Type SpirvBaseTypeToFormatType(spirv_cross::SPIRType::BaseType spirvBaseType); wgpu::TextureComponentType SpirvBaseTypeToTextureComponentType(
spirv_cross::SPIRType::BaseType spirvBaseType);
} // namespace dawn_native } // namespace dawn_native

View File

@ -369,15 +369,14 @@ namespace dawn_native { namespace metal {
} }
} }
const EntryPointMetadata::FragmentOutputBaseTypes& fragmentOutputBaseTypes = const auto& fragmentOutputsWritten =
GetStage(SingleShaderStage::Fragment).metadata->fragmentOutputFormatBaseTypes; GetStage(SingleShaderStage::Fragment).metadata->fragmentOutputsWritten;
for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) { for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) {
descriptorMTL.colorAttachments[static_cast<uint8_t>(i)].pixelFormat = descriptorMTL.colorAttachments[static_cast<uint8_t>(i)].pixelFormat =
MetalPixelFormat(GetColorAttachmentFormat(i)); MetalPixelFormat(GetColorAttachmentFormat(i));
const ColorStateDescriptor* descriptor = GetColorStateDescriptor(i); const ColorStateDescriptor* descriptor = GetColorStateDescriptor(i);
bool isDeclaredInFragmentShader = fragmentOutputBaseTypes[i] != Format::Type::Other;
ComputeBlendDesc(descriptorMTL.colorAttachments[static_cast<uint8_t>(i)], descriptor, ComputeBlendDesc(descriptorMTL.colorAttachments[static_cast<uint8_t>(i)], descriptor,
isDeclaredInFragmentShader); fragmentOutputsWritten[i]);
} }
descriptorMTL.inputPrimitiveTopology = MTLInputPrimitiveTopology(GetPrimitiveTopology()); descriptorMTL.inputPrimitiveTopology = MTLInputPrimitiveTopology(GetPrimitiveTopology());

View File

@ -193,9 +193,8 @@ namespace dawn_native { namespace opengl {
GLuint textureIndex = indices[combined.textureLocation.group][bindingIndex]; GLuint textureIndex = indices[combined.textureLocation.group][bindingIndex];
mUnitsForTextures[textureIndex].push_back(textureUnit); mUnitsForTextures[textureIndex].push_back(textureUnit);
Format::Type componentType = shouldUseFiltering = bgl->GetBindingInfo(bindingIndex).textureComponentType ==
bgl->GetBindingInfo(bindingIndex).textureComponentType; wgpu::TextureComponentType::Float;
shouldUseFiltering = componentType == Format::Type::Float;
} }
{ {
const BindGroupLayoutBase* bgl = const BindGroupLayoutBase* bgl =

View File

@ -408,13 +408,12 @@ namespace dawn_native { namespace vulkan {
// pre-computed in the ColorState // pre-computed in the ColorState
ityp::array<ColorAttachmentIndex, VkPipelineColorBlendAttachmentState, kMaxColorAttachments> ityp::array<ColorAttachmentIndex, VkPipelineColorBlendAttachmentState, kMaxColorAttachments>
colorBlendAttachments; colorBlendAttachments;
const EntryPointMetadata::FragmentOutputBaseTypes& fragmentOutputBaseTypes = const auto& fragmentOutputsWritten =
GetStage(SingleShaderStage::Fragment).metadata->fragmentOutputFormatBaseTypes; GetStage(SingleShaderStage::Fragment).metadata->fragmentOutputsWritten;
for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) { for (ColorAttachmentIndex i : IterateBitSet(GetColorAttachmentsMask())) {
const ColorStateDescriptor* colorStateDescriptor = GetColorStateDescriptor(i); const ColorStateDescriptor* colorStateDescriptor = GetColorStateDescriptor(i);
bool isDeclaredInFragmentShader = fragmentOutputBaseTypes[i] != Format::Type::Other;
colorBlendAttachments[i] = colorBlendAttachments[i] =
ComputeColorDesc(colorStateDescriptor, isDeclaredInFragmentShader); ComputeColorDesc(colorStateDescriptor, fragmentOutputsWritten[i]);
} }
VkPipelineColorBlendStateCreateInfo colorBlend; VkPipelineColorBlendStateCreateInfo colorBlend;
colorBlend.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; colorBlend.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;