Commit 7d023dac by Shahbaz Youssefi Committed by Angle LUCI CQ

Vulkan: SPIR-V Gen: Basic support for fragment shaders

Fragment shader built-ins are implemented in this change and direct SPIR-V generation for fragment shaders is enabled. Bug: angleproject:4889 Change-Id: I6f92a5585f242122a81c97a9b1aa2763009161a0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2951625 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent c2449441
...@@ -311,6 +311,7 @@ SpirvTypeData SPIRVBuilder::declareType(const SpirvType &type, const TSymbol *bl ...@@ -311,6 +311,7 @@ SpirvTypeData SPIRVBuilder::declareType(const SpirvType &type, const TSymbol *bl
// Declaring a matrix. Declare the column type first, then create a matrix out of it. // Declaring a matrix. Declare the column type first, then create a matrix out of it.
SpirvType columnType = type; SpirvType columnType = type;
columnType.primarySize = columnType.secondarySize;
columnType.secondarySize = 1; columnType.secondarySize = 1;
columnType.blockStorage = EbsUnspecified; columnType.blockStorage = EbsUnspecified;
...@@ -318,7 +319,7 @@ SpirvTypeData SPIRVBuilder::declareType(const SpirvType &type, const TSymbol *bl ...@@ -318,7 +319,7 @@ SpirvTypeData SPIRVBuilder::declareType(const SpirvType &type, const TSymbol *bl
typeId = getNewId({}); typeId = getNewId({});
spirv::WriteTypeMatrix(&mSpirvTypeAndConstantDecls, typeId, columnTypeId, spirv::WriteTypeMatrix(&mSpirvTypeAndConstantDecls, typeId, columnTypeId,
spirv::LiteralInteger(type.secondarySize)); spirv::LiteralInteger(type.primarySize));
} }
else if (type.primarySize > 1) else if (type.primarySize > 1)
{ {
...@@ -1276,8 +1277,7 @@ uint32_t SPIRVBuilder::calculateBaseAlignmentAndSize(const SpirvType &type, ...@@ -1276,8 +1277,7 @@ uint32_t SPIRVBuilder::calculateBaseAlignmentAndSize(const SpirvType &type,
// Here, we always calculate the base alignment and size for column-major matrices. If a // Here, we always calculate the base alignment and size for column-major matrices. If a
// row-major matrix is used in a block, the columns and rows are simply swapped before // row-major matrix is used in a block, the columns and rows are simply swapped before
// looking up the base alignment and size. // looking up the base alignment and size.
//
// TODO: verify that ANGLE's primary size is 3 in the example above.
vectorType.primarySize = vectorType.secondarySize; vectorType.primarySize = vectorType.secondarySize;
vectorType.secondarySize = 1; vectorType.secondarySize = 1;
...@@ -1537,6 +1537,10 @@ void SPIRVBuilder::generateExecutionModes(spirv::Blob *blob) ...@@ -1537,6 +1537,10 @@ void SPIRVBuilder::generateExecutionModes(spirv::Blob *blob)
{ {
switch (mShaderType) switch (mShaderType)
{ {
case gl::ShaderType::Fragment:
spirv::WriteExecutionMode(blob, mEntryPointId, spv::ExecutionModeOriginUpperLeft, {});
break;
case gl::ShaderType::Compute: case gl::ShaderType::Compute:
{ {
const sh::WorkGroupSize &localSize = mCompiler->getComputeShaderLocalSize(); const sh::WorkGroupSize &localSize = mCompiler->getComputeShaderLocalSize();
......
...@@ -1341,10 +1341,8 @@ bool TranslatorVulkan::translate(TIntermBlock *root, ...@@ -1341,10 +1341,8 @@ bool TranslatorVulkan::translate(TIntermBlock *root,
} }
#if defined(ANGLE_ENABLE_DIRECT_SPIRV_GENERATION) #if defined(ANGLE_ENABLE_DIRECT_SPIRV_GENERATION)
constexpr ShCompileOptions kUnsupportedTransformations = SH_CLAMP_POINT_SIZE;
if ((compileOptions & SH_GENERATE_SPIRV_DIRECTLY) != 0 && if ((compileOptions & SH_GENERATE_SPIRV_DIRECTLY) != 0 &&
((getShaderType() == GL_VERTEX_SHADER && (getShaderType() == GL_VERTEX_SHADER || getShaderType() == GL_FRAGMENT_SHADER ||
(compileOptions & kUnsupportedTransformations) == 0) ||
getShaderType() == GL_COMPUTE_SHADER)) getShaderType() == GL_COMPUTE_SHADER))
{ {
// Declare the implicitly defined gl_PerVertex I/O blocks if not already. This will help // Declare the implicitly defined gl_PerVertex I/O blocks if not already. This will help
......
...@@ -99,7 +99,7 @@ TIntermTyped *GenerateMat2x2ArrayWithIndex(const Mat2x2EnumMap &matrix, TIntermS ...@@ -99,7 +99,7 @@ TIntermTyped *GenerateMat2x2ArrayWithIndex(const Mat2x2EnumMap &matrix, TIntermS
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated180Degrees), CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated180Degrees),
CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated270Degrees)}; CreateMat2x2(matrix, vk::SurfaceRotation::FlippedRotated270Degrees)};
TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeMat2Array, &sequences); TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeMat2Array, &sequences);
return new TIntermBinary(EOpIndexDirect, array, rotation); return new TIntermBinary(EOpIndexIndirect, array, rotation);
} }
using Vec2 = std::array<float, 2>; using Vec2 = std::array<float, 2>;
...@@ -156,7 +156,7 @@ TIntermTyped *CreateVec2ArrayWithIndex(Vec2EnumMap vec2Values, ...@@ -156,7 +156,7 @@ TIntermTyped *CreateVec2ArrayWithIndex(Vec2EnumMap vec2Values,
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated180Degrees), CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated180Degrees),
CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated270Degrees)}; CreateVec2(vec2Values, yscale, vk::SurfaceRotation::FlippedRotated270Degrees)};
TIntermTyped *vec2Array = TIntermAggregate::CreateConstructor(*typeVec2Array, &sequences); TIntermTyped *vec2Array = TIntermAggregate::CreateConstructor(*typeVec2Array, &sequences);
return new TIntermBinary(EOpIndexDirect, vec2Array, rotation); return new TIntermBinary(EOpIndexIndirect, vec2Array, rotation);
} }
// Returns [flipX*m0, flipY*m1], where [m0 m1] is the first column of kFragRotation matrix. // Returns [flipX*m0, flipY*m1], where [m0 m1] is the first column of kFragRotation matrix.
...@@ -229,7 +229,7 @@ TIntermTyped *CreateFloatArrayWithRotationIndex(const Vec2EnumMap &valuesEnumMap ...@@ -229,7 +229,7 @@ TIntermTyped *CreateFloatArrayWithRotationIndex(const Vec2EnumMap &valuesEnumMap
scale)}; scale)};
TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeFloat8, &sequences); TIntermTyped *array = TIntermAggregate::CreateConstructor(*typeFloat8, &sequences);
return new TIntermBinary(EOpIndexDirect, array, rotation); return new TIntermBinary(EOpIndexIndirect, array, rotation);
} }
const TType *MakeSpecConst(const TType &type, vk::SpecializationConstantId id) const TType *MakeSpecConst(const TType &type, vk::SpecializationConstantId id)
......
...@@ -41,6 +41,13 @@ ...@@ -41,6 +41,13 @@
// Mac // Mac
6025 MAC AMD OPENGL : IndexBufferOffsetTestES3.UseAsUBOThenUpdateThenUInt8Index/ES3_OpenGL = SKIP 6025 MAC AMD OPENGL : IndexBufferOffsetTestES3.UseAsUBOThenUpdateThenUInt8Index/ES3_OpenGL = SKIP
6025 MAC AMD OPENGL : IndexBufferOffsetTestES3.UseAsUBOThenUpdateThenUInt8IndexSmallUpdates/ES3_OpenGL = SKIP 6025 MAC AMD OPENGL : IndexBufferOffsetTestES3.UseAsUBOThenUpdateThenUInt8IndexSmallUpdates/ES3_OpenGL = SKIP
6096 MAC METAL : GLSLTest_ES3.InitGlobalComplexConstant/ES3_Metal = SKIP
// D3D
6091 WIN D3D11 : GLSLTest_ES3.InitGlobalComplexConstant/* = SKIP
// Android
6095 ANDROID GLES : GLSLTest_ES3.InitGlobalComplexConstant/ES3_OpenGLES = SKIP
// Pixel 4 expectations. // Pixel 4 expectations.
5981 PIXEL4ORXL GLES : BlitFramebufferTest.BlitSRGBToRGBOversizedDestArea/* = SKIP 5981 PIXEL4ORXL GLES : BlitFramebufferTest.BlitSRGBToRGBOversizedDestArea/* = SKIP
......
...@@ -11007,6 +11007,73 @@ void main() ...@@ -11007,6 +11007,73 @@ void main()
glDeleteShader(shader); glDeleteShader(shader);
} }
// Test that initializing global variables with complex constants work
TEST_P(GLSLTest_ES3, InitGlobalComplexConstant)
{
constexpr char kFS[] = R"(#version 300 es
precision highp float;
out vec4 color;
struct T
{
float f;
};
struct S
{
vec4 v;
mat3x4 m[2];
T t;
};
S s = S(
vec4(0, 1, 2, 3),
mat3x4[2](
mat3x4(
vec4(4, 5, 6, 7),
vec4(8, 9, 10, 11),
vec4(12, 13, 14, 15)
),
mat3x4(
vec4(16, 17, 18, 19),
vec4(20, 21, 22, 23),
vec4(24, 25, 26, 27)
)
),
T(28.0)
);
void main()
{
vec4 result = vec4(0, 1, 0, 1);
if (s.v != vec4(0, 1, 2, 3))
result = vec4(1, 0, 0, 0);
for (int index = 0; index < 2; ++index)
{
for (int column = 0; column < 3; ++column)
{
int expect = index * 12 + column * 4 + 4;
if (s.m[index][column] != vec4(expect, expect + 1, expect + 2, expect + 3))
result = vec4(float(index + 1) / 2.0, 0, float(column + 1) / 3.0, 1);
}
}
if (s.t.f != 28.0)
result = vec4(0, 0, 1, 0);
color = result;
})";
ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS);
drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
} // anonymous namespace } // anonymous namespace
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(GLSLTest); ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(GLSLTest);
......
...@@ -656,7 +656,7 @@ TEST_P(LineLoopIndirectTest, UseAsUBOThenUpdateThenUShortIndexIndirectBuffer) ...@@ -656,7 +656,7 @@ TEST_P(LineLoopIndirectTest, UseAsUBOThenUpdateThenUShortIndexIndirectBuffer)
} }
ANGLE_INSTANTIATE_TEST_ES2(LineLoopTest); ANGLE_INSTANTIATE_TEST_ES2(LineLoopTest);
ANGLE_INSTANTIATE_TEST_ES3(LineLoopTestES3); ANGLE_INSTANTIATE_TEST_ES3_AND(LineLoopTestES3, WithDirectSPIRVGeneration(ES3_VULKAN()));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(LineLoopPrimitiveRestartTest); GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(LineLoopPrimitiveRestartTest);
ANGLE_INSTANTIATE_TEST_ES3_AND( ANGLE_INSTANTIATE_TEST_ES3_AND(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment