Commit de03e003 by Jamie Madill

Vulkan: Add shader handling for textures.

BUG=angleproject:2167 Change-Id: I33940288331a23b940753795e5e43b8cabcb87f5 Reviewed-on: https://chromium-review.googlesource.com/732189Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 89a69a03
...@@ -42,11 +42,11 @@ void TOutputVulkanGLSL::writeLayoutQualifier(TIntermTyped *variable) ...@@ -42,11 +42,11 @@ void TOutputVulkanGLSL::writeLayoutQualifier(TIntermTyped *variable)
{ {
const TType &type = variable->getType(); const TType &type = variable->getType();
bool forceLocation = bool needsCustomLayout =
(type.getQualifier() == EvqAttribute || type.getQualifier() == EvqFragmentOut || (type.getQualifier() == EvqAttribute || type.getQualifier() == EvqFragmentOut ||
type.getQualifier() == EvqVertexIn); type.getQualifier() == EvqVertexIn || IsSampler(type.getBasicType()));
if (!NeedsToWriteLayoutQualifier(type) && !forceLocation) if (!NeedsToWriteLayoutQualifier(type) && !needsCustomLayout)
{ {
return; return;
} }
...@@ -62,9 +62,9 @@ void TOutputVulkanGLSL::writeLayoutQualifier(TIntermTyped *variable) ...@@ -62,9 +62,9 @@ void TOutputVulkanGLSL::writeLayoutQualifier(TIntermTyped *variable)
TIntermSymbol *symbol = variable->getAsSymbolNode(); TIntermSymbol *symbol = variable->getAsSymbolNode();
ASSERT(symbol); ASSERT(symbol);
if (forceLocation) if (needsCustomLayout)
{ {
out << "location = @@ LOCATION-" << symbol->getName().getString() << " @@"; out << "@@ LAYOUT-" << symbol->getName().getString() << " @@";
} }
if (IsImage(type.getBasicType()) && layoutQualifier.imageInternalFormat != EiifUnspecified) if (IsImage(type.getBasicType()) && layoutQualifier.imageInternalFormat != EiifUnspecified)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "compiler/translator/TranslatorVulkan.h" #include "compiler/translator/TranslatorVulkan.h"
#include "angle_gl.h" #include "angle_gl.h"
#include "common/utilities.h"
#include "compiler/translator/OutputVulkanGLSL.h" #include "compiler/translator/OutputVulkanGLSL.h"
#include "compiler/translator/util.h" #include "compiler/translator/util.h"
...@@ -41,7 +42,7 @@ class DeclareDefaultUniformsTraverser : public TIntermTraverser ...@@ -41,7 +42,7 @@ class DeclareDefaultUniformsTraverser : public TIntermTraverser
TIntermTyped *variable = sequence.front()->getAsTyped(); TIntermTyped *variable = sequence.front()->getAsTyped();
const TType &type = variable->getType(); const TType &type = variable->getType();
bool isUniform = (type.getQualifier() == EvqUniform); bool isUniform = (type.getQualifier() == EvqUniform) && !IsOpaqueType(type.getBasicType());
if (visit == PreVisit) if (visit == PreVisit)
{ {
...@@ -103,7 +104,16 @@ void TranslatorVulkan::translate(TIntermBlock *root, ...@@ -103,7 +104,16 @@ void TranslatorVulkan::translate(TIntermBlock *root,
sink << "#version 450 core\n"; sink << "#version 450 core\n";
// Write out default uniforms into a uniform block assigned to a specific set/binding. // Write out default uniforms into a uniform block assigned to a specific set/binding.
if (!getUniforms().empty()) int defaultUniformCount = 0;
for (const auto &uniform : getUniforms())
{
if (!uniform.isBuiltIn() && uniform.staticUse && !gl::IsOpaqueType(uniform.type))
{
++defaultUniformCount;
}
}
if (defaultUniformCount > 0)
{ {
sink << "\nlayout(@@ DEFAULT-UNIFORMS-SET-BINDING @@) uniform defaultUniforms\n{\n"; sink << "\nlayout(@@ DEFAULT-UNIFORMS-SET-BINDING @@) uniform defaultUniforms\n{\n";
......
...@@ -19,10 +19,28 @@ ...@@ -19,10 +19,28 @@
#include <array> #include <array>
#include "common/string_utils.h" #include "common/string_utils.h"
#include "common/utilities.h"
namespace rx namespace rx
{ {
namespace
{
void InsertLayoutSpecifierString(std::string *shaderString,
const std::string &variableName,
const std::string &layoutString)
{
std::stringstream searchStringBuilder;
searchStringBuilder << "@@ LAYOUT-" << variableName << " @@";
std::string searchString = searchStringBuilder.str();
bool success = angle::ReplaceSubstring(shaderString, searchString, layoutString);
ASSERT(success);
}
} // anonymous namespace
// static // static
GlslangWrapper *GlslangWrapper::mInstance = nullptr; GlslangWrapper *GlslangWrapper::mInstance = nullptr;
...@@ -70,10 +88,11 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext, ...@@ -70,10 +88,11 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
std::vector<uint32_t> *vertexCodeOut, std::vector<uint32_t> *vertexCodeOut,
std::vector<uint32_t> *fragmentCodeOut) std::vector<uint32_t> *fragmentCodeOut)
{ {
std::string vertexSource = gl::Shader *glVertexShader = programState.getAttachedVertexShader();
programState.getAttachedVertexShader()->getTranslatedSource(glContext); gl::Shader *glFragmentShader = programState.getAttachedFragmentShader();
std::string fragmentSource =
programState.getAttachedFragmentShader()->getTranslatedSource(glContext); std::string vertexSource = glVertexShader->getTranslatedSource(glContext);
std::string fragmentSource = glFragmentShader->getTranslatedSource(glContext);
// Parse attribute locations and replace them in the vertex shader. // Parse attribute locations and replace them in the vertex shader.
// See corresponding code in OutputVulkanGLSL.cpp. // See corresponding code in OutputVulkanGLSL.cpp.
...@@ -83,14 +102,8 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext, ...@@ -83,14 +102,8 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
if (!attribute.staticUse) if (!attribute.staticUse)
continue; continue;
std::stringstream searchStringBuilder; std::string locationString = "location = " + Str(attribute.location);
searchStringBuilder << "@@ LOCATION-" << attribute.name << " @@"; InsertLayoutSpecifierString(&vertexSource, attribute.name, locationString);
std::string searchString = searchStringBuilder.str();
std::string locationString = Str(attribute.location);
bool success = angle::ReplaceSubstring(&vertexSource, searchString, locationString);
ASSERT(success);
} }
// Bind the default uniforms for vertex and fragment shaders. // Bind the default uniforms for vertex and fragment shaders.
...@@ -105,6 +118,29 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext, ...@@ -105,6 +118,29 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
angle::ReplaceSubstring(&vertexSource, searchString, vertexDefaultUniformsBinding); angle::ReplaceSubstring(&vertexSource, searchString, vertexDefaultUniformsBinding);
angle::ReplaceSubstring(&fragmentSource, searchString, fragmentDefaultUniformsBinding); angle::ReplaceSubstring(&fragmentSource, searchString, fragmentDefaultUniformsBinding);
// Assign textures to a descriptor set and binding.
int textureCount = 0;
const auto &uniforms = programState.getUniforms();
for (unsigned int uniformIndex : programState.getSamplerUniformRange())
{
const gl::LinkedUniform &samplerUniform = uniforms[uniformIndex];
std::string setBindingString = "set = 1, binding = " + Str(textureCount);
ASSERT(samplerUniform.vertexStaticUse || samplerUniform.fragmentStaticUse);
if (samplerUniform.vertexStaticUse)
{
InsertLayoutSpecifierString(&vertexSource, samplerUniform.name, setBindingString);
}
if (samplerUniform.fragmentStaticUse)
{
InsertLayoutSpecifierString(&fragmentSource, samplerUniform.name, setBindingString);
}
textureCount += samplerUniform.elementCount();
}
std::array<const char *, 2> strings = {{vertexSource.c_str(), fragmentSource.c_str()}}; std::array<const char *, 2> strings = {{vertexSource.c_str(), fragmentSource.c_str()}};
std::array<int, 2> lengths = { std::array<int, 2> lengths = {
......
...@@ -272,7 +272,11 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext) ...@@ -272,7 +272,11 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
const auto &location = locations[locationIndex]; const auto &location = locations[locationIndex];
if (location.used() && !location.ignored) if (location.used() && !location.ignored)
{ {
const auto &uniform = uniforms[location.index]; const auto &uniform = uniforms[location.index];
if (uniform.isSampler())
continue;
std::string uniformName = uniform.name; std::string uniformName = uniform.name;
if (uniform.isArray()) if (uniform.isArray())
{ {
......
...@@ -463,6 +463,13 @@ TEST_P(SimpleOperationTest, CreateTexture2DWithData) ...@@ -463,6 +463,13 @@ TEST_P(SimpleOperationTest, CreateTexture2DWithData)
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
} }
// Creates a program with a texture.
TEST_P(SimpleOperationTest, LinkProgramWithTexture)
{
ASSERT_NE(0u, get2DTexturedQuadProgram());
EXPECT_GL_NO_ERROR();
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(SimpleOperationTest, ANGLE_INSTANTIATE_TEST(SimpleOperationTest,
ES2_D3D9(), ES2_D3D9(),
......
...@@ -341,6 +341,8 @@ class ANGLETestBase ...@@ -341,6 +341,8 @@ class ANGLETestBase
static OSWindow *GetOSWindow() { return mOSWindow; } static OSWindow *GetOSWindow() { return mOSWindow; }
GLuint get2DTexturedQuadProgram();
angle::PlatformMethods mPlatformMethods; angle::PlatformMethods mPlatformMethods;
class ScopedIgnorePlatformMessages : angle::NonCopyable class ScopedIgnorePlatformMessages : angle::NonCopyable
...@@ -358,8 +360,6 @@ class ANGLETestBase ...@@ -358,8 +360,6 @@ class ANGLETestBase
void checkD3D11SDKLayersMessages(); void checkD3D11SDKLayersMessages();
GLuint get2DTexturedQuadProgram();
void drawQuad(GLuint program, void drawQuad(GLuint program,
const std::string &positionAttribName, const std::string &positionAttribName,
GLfloat positionAttribZ, GLfloat positionAttribZ,
......
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