Commit dd3bf52e by Jamie Madill

Remove getSamplerStateWithNativeOffset.

This method returned a sampler state as normal, with the base level automatically offset by the one or two levels we use in the D3D workaround for small compressed textures. Since this is D3D-only, we can move all of the logic into the D3D classes themselves. BUG=angle:781 Change-Id: Ie0a60877efebb41f02f4e57625a44e5fb5cce074 Reviewed-on: https://chromium-review.googlesource.com/222923Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org>
parent 10ef2156
......@@ -1471,9 +1471,8 @@ Error Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderTyp
GLint textureUnit = programBinary->getSamplerMapping(shaderType, samplerIndex, getCaps());
if (textureUnit != -1)
{
SamplerState sampler;
Texture* texture = getSamplerTexture(textureUnit, textureType);
texture->getSamplerStateWithNativeOffset(&sampler);
Texture *texture = getSamplerTexture(textureUnit, textureType);
SamplerState sampler = texture->getSamplerState();
Sampler *samplerObject = mState.getSampler(textureUnit);
if (samplerObject)
......@@ -1485,7 +1484,7 @@ Error Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderTyp
if (texture->isSamplerComplete(sampler, mTextureCaps, mExtensions, mClientVersion) &&
!std::binary_search(framebufferSerials.begin(), framebufferSerials.begin() + framebufferSerialCount, texture->getTextureSerial()))
{
Error error = mRenderer->setSamplerState(shaderType, samplerIndex, sampler);
Error error = mRenderer->setSamplerState(shaderType, samplerIndex, texture, sampler);
if (error.isError())
{
return error;
......
......@@ -75,16 +75,6 @@ void Texture::setUsage(GLenum usage)
getImplementation()->setUsage(usage);
}
void Texture::getSamplerStateWithNativeOffset(SamplerState *sampler)
{
*sampler = mSamplerState;
// Offset the effective base level by the texture storage's top level
rx::TextureStorage *texture = getNativeTexture();
int topLevel = texture ? texture->getTopLevel() : 0;
sampler->baseLevel = topLevel + mSamplerState.baseLevel;
}
GLenum Texture::getUsage() const
{
return mUsage;
......
......@@ -52,7 +52,6 @@ class Texture : public RefCountObject
const SamplerState &getSamplerState() const { return mSamplerState; }
SamplerState &getSamplerState() { return mSamplerState; }
void getSamplerStateWithNativeOffset(SamplerState *sampler);
void setUsage(GLenum usage);
GLenum getUsage() const;
......
......@@ -113,7 +113,7 @@ class Renderer
virtual SwapChain *createSwapChain(rx::NativeWindow nativeWindow, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
virtual gl::Error generateSwizzle(gl::Texture *texture) = 0;
virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
virtual gl::Error setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &sampler) = 0;
virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0;
......
......@@ -293,6 +293,7 @@ int TextureD3D::mipLevels() const
TextureStorage *TextureD3D::getStorage()
{
ASSERT(mTexStorage);
return mTexStorage;
}
......
......@@ -483,16 +483,21 @@ gl::Error Renderer11::generateSwizzle(gl::Texture *texture)
return gl::Error(GL_NO_ERROR);
}
gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &samplerStateParam)
{
// Make sure to add the level offset for our tiny compressed texture workaround
TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation());
gl::SamplerState samplerStateInternal = samplerStateParam;
samplerStateInternal.baseLevel += textureD3D->getNativeTexture()->getTopLevel();
if (type == gl::SAMPLER_PIXEL)
{
ASSERT(static_cast<unsigned int>(index) < getRendererCaps().maxTextureImageUnits);
if (mForceSetPixelSamplerStates[index] || memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0)
if (mForceSetPixelSamplerStates[index] || memcmp(&samplerStateInternal, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{
ID3D11SamplerState *dxSamplerState = NULL;
gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
gl::Error error = mStateCache.getSamplerState(samplerStateInternal, &dxSamplerState);
if (error.isError())
{
return error;
......@@ -501,7 +506,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl:
ASSERT(dxSamplerState != NULL);
mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState);
mCurPixelSamplerStates[index] = samplerState;
mCurPixelSamplerStates[index] = samplerStateInternal;
}
mForceSetPixelSamplerStates[index] = false;
......@@ -510,10 +515,10 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl:
{
ASSERT(static_cast<unsigned int>(index) < getRendererCaps().maxVertexTextureImageUnits);
if (mForceSetVertexSamplerStates[index] || memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0)
if (mForceSetVertexSamplerStates[index] || memcmp(&samplerStateInternal, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{
ID3D11SamplerState *dxSamplerState = NULL;
gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
gl::Error error = mStateCache.getSamplerState(samplerStateInternal, &dxSamplerState);
if (error.isError())
{
return error;
......@@ -522,7 +527,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl:
ASSERT(dxSamplerState != NULL);
mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState);
mCurVertexSamplerStates[index] = samplerState;
mCurVertexSamplerStates[index] = samplerStateInternal;
}
mForceSetVertexSamplerStates[index] = false;
......@@ -544,8 +549,11 @@ gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *t
ASSERT(texStorage != NULL);
TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage);
gl::SamplerState samplerState;
texture->getSamplerStateWithNativeOffset(&samplerState);
// Make sure to add the level offset for our tiny compressed texture workaround
gl::SamplerState samplerState = texture->getSamplerState();
samplerState.baseLevel += storage11->getTopLevel();
gl::Error error = storage11->getSRV(samplerState, &textureSRV);
if (error.isError())
{
......
......@@ -61,7 +61,7 @@ class Renderer11 : public Renderer
virtual SwapChain *createSwapChain(rx::NativeWindow nativeWindow, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat);
virtual gl::Error generateSwizzle(gl::Texture *texture);
virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
virtual gl::Error setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &sampler);
virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture);
virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]);
......
......@@ -678,7 +678,7 @@ gl::Error Renderer9::generateSwizzle(gl::Texture *texture)
return gl::Error(GL_INVALID_OPERATION);
}
gl::Error Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
gl::Error Renderer9::setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &samplerState)
{
std::vector<bool> &forceSetSamplers = (type == gl::SAMPLER_PIXEL) ? mForceSetPixelSamplerStates : mForceSetVertexSamplerStates;
std::vector<gl::SamplerState> &appliedSamplers = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates: mCurVertexSamplerStates;
......@@ -688,6 +688,10 @@ gl::Error Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset;
// Make sure to add the level offset for our tiny compressed texture workaround
TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation());
DWORD baseLevel = samplerState.baseLevel + textureD3D->getNativeTexture()->getTopLevel();
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU, gl_d3d9::ConvertTextureWrap(samplerState.wrapS));
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSV, gl_d3d9::ConvertTextureWrap(samplerState.wrapT));
......@@ -696,7 +700,7 @@ gl::Error Renderer9::setSamplerState(gl::SamplerType type, int index, const gl::
gl_d3d9::ConvertMinFilter(samplerState.minFilter, &d3dMinFilter, &d3dMipFilter, samplerState.maxAnisotropy);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MINFILTER, d3dMinFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MIPFILTER, d3dMipFilter);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, samplerState.baseLevel);
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXMIPLEVEL, baseLevel);
if (getRendererExtensions().textureFilterAnisotropic)
{
mDevice->SetSamplerState(d3dSampler, D3DSAMP_MAXANISOTROPY, (DWORD)samplerState.maxAnisotropy);
......
......@@ -61,7 +61,7 @@ class Renderer9 : public Renderer
HRESULT createVertexBuffer(UINT Length, DWORD Usage, IDirect3DVertexBuffer9 **ppVertexBuffer);
HRESULT createIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, IDirect3DIndexBuffer9 **ppIndexBuffer);
virtual gl::Error generateSwizzle(gl::Texture *texture);
virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
virtual gl::Error setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &sampler);
virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture);
virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]);
......
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