Add check between color state format and fragment shader output

This patch adds the validation on the compatibility between the format
of the color states and the fragment shader output when we create a
render pipeline state object as is required in Vulkan (Vulkan SPEC
Chapter 14.3 "Fragment Output Interface"):
"if the type of the values written by the fragment shader do not match
the format of the corresponding color attachment, the resulting values
are undefined for those components".

BUG=dawn:202
TEST=dawn_unittests

Change-Id: I3a72baa11999bd07c69050c42b094720ef4708b2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11461
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao
2019-09-26 00:12:41 +00:00
committed by Commit Bot service account
parent 09cc2b92c7
commit 64f4dd7127
5 changed files with 86 additions and 3 deletions

View File

@@ -649,7 +649,7 @@ class SetBindGroupValidationTest : public ValidationTest {
layout(std140, set = 0, binding = 1) buffer SBuffer {
vec2 value2;
} sBuffer;
layout(location = 0) out uvec4 fragColor;
layout(location = 0) out vec4 fragColor;
void main() {
})");

View File

@@ -18,6 +18,8 @@
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
#include <sstream>
class RenderPipelineValidationTest : public ValidationTest {
protected:
void SetUp() override {
@@ -114,6 +116,39 @@ TEST_F(RenderPipelineValidationTest, NonRenderableFormat) {
}
}
// Tests that the format of the color state descriptor must match the output of the fragment shader.
TEST_F(RenderPipelineValidationTest, FragmentOutputFormatCompatibility) {
constexpr uint32_t kNumTextureFormatBaseType = 3u;
std::array<const char*, kNumTextureFormatBaseType> kVecPreFix = {{"", "i", "u"}};
std::array<dawn::TextureFormat, kNumTextureFormatBaseType> kColorFormats = {
{dawn::TextureFormat::RGBA8Unorm, dawn::TextureFormat::RGBA8Sint,
dawn::TextureFormat::RGBA8Uint}};
for (size_t i = 0; i < kNumTextureFormatBaseType; ++i) {
for (size_t j = 0; j < kNumTextureFormatBaseType; ++j) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
descriptor.cColorStates[0].format = kColorFormats[j];
std::ostringstream stream;
stream << R"(
#version 450
layout(location = 0) out )"
<< kVecPreFix[i] << R"(vec4 fragColor;
void main() {
})";
descriptor.cFragmentStage.module = utils::CreateShaderModule(
device, utils::SingleShaderStage::Fragment, stream.str().c_str());
if (i == j) {
device.CreateRenderPipeline(&descriptor);
} else {
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}
}
}
}
/// Tests that the sample count of the render pipeline must be valid.
TEST_F(RenderPipelineValidationTest, SampleCount) {
{