Commit f8bf583b by Olli Etuaho Committed by Commit Bot

Pass integer texture format bit count to shaders on D3D11

This will be needed in the future when integer texture wrap mode support will be added by sampling integer textures through FLOAT/UNORM/SNORM SRVs. The bit count needs to be passed for 8-, 10- and 16-bit textures. 32-bit integer textures are the ones left over. Only passing the bit counts for the absolute minimum number of formats avoids unnecessary driver constant buffer updates. BUG=angleproject:1244 BUG=angleproject:1095 TEST=angle_end2end_tests Change-Id: I28a84588842b2eb9a1661454437d21c22ce794b7 Reviewed-on: https://chromium-review.googlesource.com/326944Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 72e6606d
......@@ -858,7 +858,7 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
if (textureFunction->method == TextureFunction::SIZE)
{
out << "int baseLevel = samplerMetadata[samplerIndex];\n";
out << "int baseLevel = samplerMetadata[samplerIndex].x;\n";
if (IsSampler2D(textureFunction->sampler) || IsSamplerCube(textureFunction->sampler))
{
if (IsSamplerArray(textureFunction->sampler) ||
......
......@@ -251,7 +251,8 @@ void UniformHLSL::samplerMetadataUniforms(TInfoSinkBase &out, const char *reg)
// If mSamplerRegister is 0 the shader doesn't use any textures.
if (mSamplerRegister > 0)
{
out << " int samplerMetadata[" << mSamplerRegister << "] : packoffset(" << reg << ");\n";
out << " int4 samplerMetadata[" << mSamplerRegister << "] : packoffset(" << reg
<< ");\n";
}
}
......
......@@ -1212,7 +1212,8 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type,
else UNREACHABLE();
ASSERT(metadata != nullptr);
metadata->update(index, texture->getBaseLevel());
metadata->update(index, texture->getBaseLevel(),
texture->getInternalFormat(texture->getTarget(), texture->getBaseLevel()));
return gl::Error(GL_NO_ERROR);
}
......@@ -2287,12 +2288,68 @@ void Renderer11::SamplerMetadataD3D11::initData(unsigned int samplerCount)
mSamplerMetadata.resize(samplerCount);
}
void Renderer11::SamplerMetadataD3D11::update(unsigned int samplerIndex, unsigned int baseLevel)
void Renderer11::SamplerMetadataD3D11::update(unsigned int samplerIndex,
unsigned int baseLevel,
GLenum internalFormat)
{
if (mSamplerMetadata[samplerIndex].baseLevel[0] != static_cast<int>(baseLevel))
if (mSamplerMetadata[samplerIndex].parameters[0] != static_cast<int>(baseLevel))
{
mSamplerMetadata[samplerIndex].parameters[0] = static_cast<int>(baseLevel);
mDirty = true;
}
// internalFormatBits == 0 means a 32-bit texture in the case of integer textures. In the case
// of non-integer textures, internalFormatBits is meaningless. We avoid updating the constant
// buffer unnecessarily by changing the data only in case the texture is an integer texture and
// the value has changed.
bool needInternalFormatBits = false;
int internalFormatBits = 0;
switch (internalFormat)
{
case GL_RGBA32I:
case GL_RGBA32UI:
case GL_RGB32I:
case GL_RGB32UI:
case GL_RG32I:
case GL_RG32UI:
case GL_R32I:
case GL_R32UI:
needInternalFormatBits = true;
break;
case GL_RGBA16I:
case GL_RGBA16UI:
case GL_RGB16I:
case GL_RGB16UI:
case GL_RG16I:
case GL_RG16UI:
case GL_R16I:
case GL_R16UI:
needInternalFormatBits = true;
internalFormatBits = 16;
break;
case GL_RGBA8I:
case GL_RGBA8UI:
case GL_RGB8I:
case GL_RGB8UI:
case GL_RG8I:
case GL_RG8UI:
case GL_R8I:
case GL_R8UI:
needInternalFormatBits = true;
internalFormatBits = 8;
break;
case GL_RGB10_A2UI:
needInternalFormatBits = true;
internalFormatBits = 10;
break;
default:
break;
}
if (needInternalFormatBits &&
mSamplerMetadata[samplerIndex].parameters[1] != internalFormatBits)
{
mSamplerMetadata[samplerIndex].baseLevel[0] = static_cast<int>(baseLevel);
mDirty = true;
mSamplerMetadata[samplerIndex].parameters[1] = internalFormatBits;
mDirty = true;
}
}
......
......@@ -345,11 +345,11 @@ class Renderer11 : public RendererD3D
struct dx_SamplerMetadata
{
int baseLevel[4];
int parameters[4];
};
void initData(unsigned int samplerCount);
void update(unsigned int samplerIndex, unsigned int baseLevel);
void update(unsigned int samplerIndex, unsigned int baseLevel, GLenum internalFormat);
const dx_SamplerMetadata *getData() const;
size_t sizeBytes() const;
......
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