Check sampler limits in random shader cases.
authorJarkko Pöyry <jpoyry@google.com>
Wed, 3 Jun 2015 00:30:08 +0000 (17:30 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Thu, 4 Jun 2015 00:42:49 +0000 (17:42 -0700)
Bug: 21526017
Change-Id: Iad3b19889e5f4d6c9b9ce6bc2337dd2a02ecc2cf

modules/glshared/glsRandomShaderCase.cpp
modules/glshared/glsRandomShaderCase.hpp

index 8f92bbd649139243a5dbb89aeb953a52238b09b5..5400661648a2a0b0417c69e6f4bb990c92a4a494 100644 (file)
 #include "gluShaderProgram.hpp"
 #include "gluPixelTransfer.hpp"
 #include "gluTextureUtil.hpp"
+#include "gluStrUtil.hpp"
 
 #include "tcuImageCompare.hpp"
 #include "tcuTestLog.hpp"
+
 #include "deRandom.hpp"
+#include "deStringUtil.hpp"
 
 #include "rsgProgramGenerator.hpp"
 #include "rsgProgramExecutor.hpp"
@@ -39,6 +42,7 @@
 #include "tcuRenderTarget.hpp"
 
 #include "glw.h"
+#include "glwFunctions.hpp"
 
 using std::vector;
 using std::string;
@@ -136,6 +140,10 @@ void RandomShaderCase::init (void)
        rsg::ProgramGenerator programGenerator;
        programGenerator.generate(m_parameters, m_vertexShader, m_fragmentShader);
 
+       checkShaderLimits(m_vertexShader);
+       checkShaderLimits(m_fragmentShader);
+       checkProgramLimits(m_vertexShader, m_fragmentShader);
+
        // Compute uniform values
        std::vector<const rsg::ShaderInput*>    unifiedUniforms;
        de::Random                                                              rnd(m_parameters.seed);
@@ -229,6 +237,60 @@ void RandomShaderCase::init (void)
        }
 }
 
+static int getNumSamplerUniforms (const std::vector<rsg::ShaderInput*>& uniforms)
+{
+       int numSamplers = 0;
+
+       for (std::vector<rsg::ShaderInput*>::const_iterator it = uniforms.begin(); it != uniforms.end(); ++it)
+       {
+               if ((*it)->getVariable()->getType().isSampler())
+                       ++numSamplers;
+       }
+
+       return numSamplers;
+}
+
+void RandomShaderCase::checkShaderLimits (const rsg::Shader& shader) const
+{
+       const int numRequiredSamplers = getNumSamplerUniforms(shader.getUniforms());
+
+       if (numRequiredSamplers > 0)
+       {
+               const GLenum    pname                   = (shader.getType() == rsg::Shader::TYPE_VERTEX) ? (GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS) : (GL_MAX_TEXTURE_IMAGE_UNITS);
+               int                             numSupported    = -1;
+               GLenum                  error;
+
+               m_renderCtx.getFunctions().getIntegerv(pname, &numSupported);
+               error = m_renderCtx.getFunctions().getError();
+
+               if (error != GL_NO_ERROR)
+                       throw tcu::TestError("Limit query failed: " + de::toString(glu::getErrorStr(error)));
+
+               if (numSupported < numRequiredSamplers)
+                       throw tcu::NotSupportedError("Shader requires " + de::toString(numRequiredSamplers) + " sampler(s). Implementation supports " + de::toString(numSupported));
+       }
+}
+
+void RandomShaderCase::checkProgramLimits (const rsg::Shader& vtxShader, const rsg::Shader& frgShader) const
+{
+       const int numRequiredCombinedSamplers = getNumSamplerUniforms(vtxShader.getUniforms()) + getNumSamplerUniforms(frgShader.getUniforms());
+
+       if (numRequiredCombinedSamplers > 0)
+       {
+               int                             numSupported    = -1;
+               GLenum                  error;
+
+               m_renderCtx.getFunctions().getIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &numSupported);
+               error = m_renderCtx.getFunctions().getError();
+
+               if (error != GL_NO_ERROR)
+                       throw tcu::TestError("Limit query failed: " + de::toString(glu::getErrorStr(error)));
+
+               if (numSupported < numRequiredCombinedSamplers)
+                       throw tcu::NotSupportedError("Program requires " + de::toString(numRequiredCombinedSamplers) + " sampler(s). Implementation supports " + de::toString(numSupported));
+       }
+}
+
 const glu::Texture2D* RandomShaderCase::getTex2D (void)
 {
        if (!m_tex2D)
index 08b59d3a6eb088bccab8b4b0e561fd9962718884..ee89e998b2abf20e5072b0c1a14078b94f1c818d 100644 (file)
@@ -85,6 +85,10 @@ public:
        virtual void                                    deinit                                  (void);
        virtual IterateResult                   iterate                                 (void);
 
+private:
+       void                                                    checkShaderLimits               (const rsg::Shader& shader) const;
+       void                                                    checkProgramLimits              (const rsg::Shader& vtxShader, const rsg::Shader& frgShader) const;
+
 protected:
        glu::RenderContext&                             m_renderCtx;