Hash :
62fe36d3
Author :
Date :
2022-05-04T22:46:52
Vulkan: Emulate YUV built-ins In this change, the rgb_2_yuv and yuv_2_rgb built-ins are emulated with normal functions that perform matrix multiplication based on the given conversion function. Bug: angleproject:6818 Change-Id: I67adb029109aaf6a674b1ee75105c1b352325eb2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3630599 Reviewed-by: Shahbaz Youssefi <syoussefi@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ExtensionDirective_test.cpp:
// Miscellaneous tests for extension directives toggling functionality correctly.
//
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "compiler/translator/ExtensionBehavior.h"
#include "gtest/gtest.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
class FragmentShaderExtensionDirectiveTest : public ShaderCompileTreeTest
{
public:
FragmentShaderExtensionDirectiveTest() {}
protected:
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
void testCompileNeedsExtensionDirective(const std::string &shader, const std::string &extension)
{
testCompileNeedsExtensionDirective(shader, extension, "");
}
void testCompileNeedsExtensionDirective(const std::string &shader,
const std::string &extension,
const std::string &versionDirective)
{
if (compile(versionDirective + shader))
{
FAIL()
<< "Shader compilation without extension directive succeeded, expecting failure:\n"
<< mInfoLog;
}
if (compile(versionDirective + getExtensionDirective(extension, sh::EBhDisable) + shader))
{
FAIL() << "Shader compilation with extension disable directive succeeded, expecting "
"failure:\n"
<< mInfoLog;
}
if (!compile(versionDirective + getExtensionDirective(extension, sh::EBhEnable) + shader))
{
FAIL()
<< "Shader compilation with extension enable directive failed, expecting success:\n"
<< mInfoLog;
}
if (!compile(versionDirective + getExtensionDirective(extension, sh::EBhWarn) + shader))
{
FAIL()
<< "Shader compilation with extension warn directive failed, expecting success:\n"
<< mInfoLog;
}
else if (!hasWarning())
{
FAIL() << "Expected compilation to succeed with warning, but warning not present:\n"
<< mInfoLog;
}
}
private:
std::string getExtensionDirective(const std::string &extension, sh::TBehavior behavior)
{
std::string extensionDirective("#extension ");
extensionDirective += extension + " : ";
switch (behavior)
{
case EBhRequire:
extensionDirective += "require";
break;
case EBhEnable:
extensionDirective += "enable";
break;
case EBhWarn:
extensionDirective += "warn";
break;
case EBhDisable:
extensionDirective += "disable";
break;
default:
break;
}
extensionDirective += "\n";
return extensionDirective;
}
};
class OESEGLImageExternalExtensionTest : public FragmentShaderExtensionDirectiveTest
{
public:
OESEGLImageExternalExtensionTest() {}
protected:
void initResources(ShBuiltInResources *resources) override
{
resources->OES_EGL_image_external = 1;
}
};
// OES_EGL_image_external needs to be enabled in GLSL to be able to use samplerExternalOES.
TEST_F(OESEGLImageExternalExtensionTest, SamplerExternalOESUsageNeedsExtensionDirective)
{
const std::string &shaderString =
R"(
precision mediump float;
uniform samplerExternalOES s;
void main()
{})";
testCompileNeedsExtensionDirective(shaderString, "GL_OES_EGL_image_external");
}
class NVEGLStreamConsumerExternalExtensionTest : public FragmentShaderExtensionDirectiveTest
{
public:
NVEGLStreamConsumerExternalExtensionTest() {}
protected:
void initResources(ShBuiltInResources *resources) override
{
resources->NV_EGL_stream_consumer_external = 1;
}
};
// NV_EGL_stream_consumer_external needs to be enabled in GLSL to be able to use samplerExternalOES.
TEST_F(NVEGLStreamConsumerExternalExtensionTest, SamplerExternalOESUsageNeedsExtensionDirective)
{
const std::string &shaderString =
R"(
precision mediump float;
uniform samplerExternalOES s;
void main()
{})";
testCompileNeedsExtensionDirective(shaderString, "GL_NV_EGL_stream_consumer_external");
}
class EXTYUVTargetExtensionTest : public FragmentShaderExtensionDirectiveTest
{
public:
EXTYUVTargetExtensionTest() {}
protected:
void initResources(ShBuiltInResources *resources) override { resources->EXT_YUV_target = 1; }
};
// GL_EXT_YUV_target needs to be enabled in GLSL to be able to use samplerExternal2DY2YEXT.
TEST_F(EXTYUVTargetExtensionTest, SamplerExternal2DY2YEXTUsageNeedsExtensionDirective)
{
const std::string &shaderString =
R"(
precision mediump float;
uniform __samplerExternal2DY2YEXT s;
void main()
{})";
testCompileNeedsExtensionDirective(shaderString, "GL_EXT_YUV_target", "#version 300 es\n");
}
// GL_EXT_YUV_target needs to be enabled in GLSL to be able to use samplerExternal2DY2YEXT.
TEST_F(EXTYUVTargetExtensionTest, YUVLayoutNeedsExtensionDirective)
{
const std::string &shaderString =
R"(
precision mediump float;
layout(yuv) out vec4 color;
void main()
{})";
testCompileNeedsExtensionDirective(shaderString, "GL_EXT_YUV_target", "#version 300 es\n");
}