Commit 37584b36 by Xinghua Cao Committed by Commit Bot

Refactor: replace SamplerType with ShaderType

BUG=angleproject:1987 Change-Id: I189e1606bd966eb369e8192a6866c8e90810e937 Reviewed-on: https://chromium-review.googlesource.com/802956 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYunchao He <yunchao.he@intel.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 1f679cc6
......@@ -40,13 +40,6 @@ enum PrimitiveType
PrimitiveType GetPrimitiveType(GLenum drawMode);
enum SamplerType
{
SAMPLER_PIXEL,
SAMPLER_VERTEX,
SAMPLER_COMPUTE
};
enum ShaderType
{
SHADER_VERTEX,
......
......@@ -651,7 +651,7 @@ bool ProgramD3D::usesInstancedPointSpriteEmulation() const
return mRenderer->getWorkarounds().useInstancedPointSpriteEmulation;
}
GLint ProgramD3D::getSamplerMapping(gl::SamplerType type,
GLint ProgramD3D::getSamplerMapping(gl::ShaderType type,
unsigned int samplerIndex,
const gl::Caps &caps) const
{
......@@ -659,21 +659,21 @@ GLint ProgramD3D::getSamplerMapping(gl::SamplerType type,
switch (type)
{
case gl::SAMPLER_PIXEL:
case gl::SHADER_FRAGMENT:
ASSERT(samplerIndex < caps.maxTextureImageUnits);
if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
{
logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
}
break;
case gl::SAMPLER_VERTEX:
case gl::SHADER_VERTEX:
ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
{
logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
}
break;
case gl::SAMPLER_COMPUTE:
case gl::SHADER_COMPUTE:
ASSERT(samplerIndex < caps.maxComputeTextureImageUnits);
if (samplerIndex < mSamplersCS.size() && mSamplersCS[samplerIndex].active)
{
......@@ -695,19 +695,19 @@ GLint ProgramD3D::getSamplerMapping(gl::SamplerType type,
// Returns the texture type for a given Direct3D 9 sampler type and
// index (0-15 for the pixel shader and 0-3 for the vertex shader).
GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const
GLenum ProgramD3D::getSamplerTextureType(gl::ShaderType type, unsigned int samplerIndex) const
{
switch (type)
{
case gl::SAMPLER_PIXEL:
case gl::SHADER_FRAGMENT:
ASSERT(samplerIndex < mSamplersPS.size());
ASSERT(mSamplersPS[samplerIndex].active);
return mSamplersPS[samplerIndex].textureType;
case gl::SAMPLER_VERTEX:
case gl::SHADER_VERTEX:
ASSERT(samplerIndex < mSamplersVS.size());
ASSERT(mSamplersVS[samplerIndex].active);
return mSamplersVS[samplerIndex].textureType;
case gl::SAMPLER_COMPUTE:
case gl::SHADER_COMPUTE:
ASSERT(samplerIndex < mSamplersCS.size());
ASSERT(mSamplersCS[samplerIndex].active);
return mSamplersCS[samplerIndex].textureType;
......@@ -718,15 +718,15 @@ GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samp
return GL_TEXTURE_2D;
}
GLuint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const
GLuint ProgramD3D::getUsedSamplerRange(gl::ShaderType type) const
{
switch (type)
{
case gl::SAMPLER_PIXEL:
case gl::SHADER_FRAGMENT:
return mUsedPixelSamplerRange;
case gl::SAMPLER_VERTEX:
case gl::SHADER_VERTEX:
return mUsedVertexSamplerRange;
case gl::SAMPLER_COMPUTE:
case gl::SHADER_COMPUTE:
return mUsedComputeSamplerRange;
default:
UNREACHABLE();
......
......@@ -161,11 +161,11 @@ class ProgramD3D : public ProgramImpl
const std::vector<PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
GLint getSamplerMapping(gl::SamplerType type,
GLint getSamplerMapping(gl::ShaderType type,
unsigned int samplerIndex,
const gl::Caps &caps) const;
GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const;
GLuint getUsedSamplerRange(gl::SamplerType type) const;
GLenum getSamplerTextureType(gl::ShaderType type, unsigned int samplerIndex) const;
GLuint getUsedSamplerRange(gl::ShaderType type) const;
enum SamplerMapping
{
......
......@@ -1960,7 +1960,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveDepth(const gl::Context *conte
stateManager->setSimpleViewport(extents);
// Set the viewport
stateManager->setShaderResourceShared(gl::SAMPLER_PIXEL, 0, &depth->getShaderResourceView());
stateManager->setShaderResourceShared(gl::SHADER_FRAGMENT, 0, &depth->getShaderResourceView());
// Trigger the blit on the GPU.
deviceContext->Draw(6, 0);
......@@ -2118,9 +2118,9 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(const gl::Context *con
// Set the viewport
stateManager->setSimpleViewport(extents);
stateManager->setShaderResourceShared(gl::SAMPLER_PIXEL, 0,
stateManager->setShaderResourceShared(gl::SHADER_FRAGMENT, 0,
&depthStencil->getShaderResourceView());
stateManager->setShaderResource(gl::SAMPLER_PIXEL, 1, &mStencilSRV);
stateManager->setShaderResource(gl::SHADER_FRAGMENT, 1, &mStencilSRV);
// Trigger the blit on the GPU.
deviceContext->Draw(6, 0);
......
......@@ -191,7 +191,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context,
StateManager11 *stateManager = mRenderer->getStateManager();
stateManager->setDrawShaders(&mBufferToTextureVS, geometryShader, pixelShader);
stateManager->setShaderResource(gl::SAMPLER_PIXEL, 0, bufferSRV);
stateManager->setShaderResource(gl::SHADER_FRAGMENT, 0, bufferSRV);
stateManager->setInputLayout(nullptr);
stateManager->setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
......
......@@ -34,7 +34,7 @@ class ShaderConstants11 : angle::NonCopyable
~ShaderConstants11();
void init(const gl::Caps &caps);
size_t getRequiredBufferSize(gl::SamplerType samplerType) const;
size_t getRequiredBufferSize(gl::ShaderType shaderType) const;
void markDirty();
void setComputeWorkGroups(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ);
......@@ -43,12 +43,12 @@ class ShaderConstants11 : angle::NonCopyable
const D3D11_VIEWPORT &dxViewport,
bool is9_3,
bool presentPathFast);
void onSamplerChange(gl::SamplerType samplerType,
void onSamplerChange(gl::ShaderType shaderType,
unsigned int samplerIndex,
const gl::Texture &texture);
gl::Error updateBuffer(ID3D11DeviceContext *deviceContext,
gl::SamplerType samplerType,
gl::ShaderType shaderType,
const ProgramD3D &programD3D,
const d3d11::Buffer &driverConstantBuffer);
......@@ -236,10 +236,10 @@ class StateManager11 final : angle::NonCopyable
gl::Error updateState(const gl::Context *context, GLenum drawMode);
void setShaderResourceShared(gl::SamplerType shaderType,
void setShaderResourceShared(gl::ShaderType shaderType,
UINT resourceSlot,
const d3d11::SharedSRV *srv);
void setShaderResource(gl::SamplerType shaderType,
void setShaderResource(gl::ShaderType shaderType,
UINT resourceSlot,
const d3d11::ShaderResourceView *srv);
void setPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY primitiveTopology);
......@@ -289,12 +289,12 @@ class StateManager11 final : angle::NonCopyable
private:
template <typename SRVType>
void setShaderResourceInternal(gl::SamplerType shaderType,
void setShaderResourceInternal(gl::ShaderType shaderType,
UINT resourceSlot,
const SRVType *srv);
bool unsetConflictingView(ID3D11View *view);
bool unsetConflictingSRVs(gl::SamplerType shaderType,
bool unsetConflictingSRVs(gl::ShaderType shaderType,
uintptr_t resource,
const gl::ImageIndex *index);
void unsetConflictingAttachmentResources(const gl::FramebufferAttachment *attachment,
......@@ -320,26 +320,26 @@ class StateManager11 final : angle::NonCopyable
gl::Error syncProgram(const gl::Context *context, GLenum drawMode);
gl::Error syncTextures(const gl::Context *context);
gl::Error applyTextures(const gl::Context *context, gl::SamplerType shaderType);
gl::Error applyTextures(const gl::Context *context, gl::ShaderType shaderType);
gl::Error setSamplerState(const gl::Context *context,
gl::SamplerType type,
gl::ShaderType type,
int index,
gl::Texture *texture,
const gl::SamplerState &sampler);
gl::Error setTexture(const gl::Context *context,
gl::SamplerType type,
gl::ShaderType type,
int index,
gl::Texture *texture);
// Faster than calling setTexture a jillion times
gl::Error clearTextures(gl::SamplerType samplerType, size_t rangeStart, size_t rangeEnd);
gl::Error clearTextures(gl::ShaderType shaderType, size_t rangeStart, size_t rangeEnd);
void handleMultiviewDrawFramebufferChange(const gl::Context *context);
gl::Error syncCurrentValueAttribs(const gl::State &glState);
gl::Error generateSwizzle(const gl::Context *context, gl::Texture *texture);
gl::Error generateSwizzlesForShader(const gl::Context *context, gl::SamplerType type);
gl::Error generateSwizzlesForShader(const gl::Context *context, gl::ShaderType type);
gl::Error generateSwizzles(const gl::Context *context);
gl::Error applyDriverUniforms(const ProgramD3D &programD3D);
......
......@@ -935,13 +935,14 @@ gl::Error Renderer9::fastCopyBufferToTexture(const gl::Context *context,
}
gl::Error Renderer9::setSamplerState(const gl::Context *context,
gl::SamplerType type,
gl::ShaderType type,
int index,
gl::Texture *texture,
const gl::SamplerState &samplerState)
{
CurSamplerState &appliedSampler = (type == gl::SAMPLER_PIXEL) ? mCurPixelSamplerStates[index]
: mCurVertexSamplerStates[index];
CurSamplerState &appliedSampler = (type == gl::SHADER_FRAGMENT)
? mCurPixelSamplerStates[index]
: mCurVertexSamplerStates[index];
// Make sure to add the level offset for our tiny compressed texture workaround
TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture);
......@@ -957,7 +958,7 @@ gl::Error Renderer9::setSamplerState(const gl::Context *context,
if (appliedSampler.forceSet || appliedSampler.baseLevel != baseLevel ||
memcmp(&samplerState, &appliedSampler, sizeof(gl::SamplerState)) != 0)
{
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSamplerOffset = (type == gl::SHADER_FRAGMENT) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset;
mDevice->SetSamplerState(d3dSampler, D3DSAMP_ADDRESSU,
......@@ -993,17 +994,17 @@ gl::Error Renderer9::setSamplerState(const gl::Context *context,
}
gl::Error Renderer9::setTexture(const gl::Context *context,
gl::SamplerType type,
gl::ShaderType type,
int index,
gl::Texture *texture)
{
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSamplerOffset = (type == gl::SHADER_FRAGMENT) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset;
IDirect3DBaseTexture9 *d3dTexture = nullptr;
bool forceSetTexture = false;
std::vector<uintptr_t> &appliedTextures =
(type == gl::SAMPLER_PIXEL) ? mCurPixelTextures : mCurVertexTextures;
(type == gl::SHADER_FRAGMENT) ? mCurPixelTextures : mCurVertexTextures;
if (texture)
{
......@@ -3244,7 +3245,7 @@ bool Renderer9::canSelectViewInVertexShader() const
// looks up the corresponding OpenGL texture image unit and texture type,
// and sets the texture and its addressing/filtering state (or NULL when inactive).
// Sampler mapping needs to be up-to-date on the program object before this is called.
gl::Error Renderer9::applyTextures(const gl::Context *context, gl::SamplerType shaderType)
gl::Error Renderer9::applyTextures(const gl::Context *context, gl::ShaderType shaderType)
{
const auto &glState = context->getGLState();
const auto &caps = context->getCaps();
......@@ -3288,8 +3289,8 @@ gl::Error Renderer9::applyTextures(const gl::Context *context, gl::SamplerType s
}
// Set all the remaining textures to NULL
size_t samplerCount = (shaderType == gl::SAMPLER_PIXEL) ? caps.maxTextureImageUnits
: caps.maxVertexTextureImageUnits;
size_t samplerCount = (shaderType == gl::SHADER_FRAGMENT) ? caps.maxTextureImageUnits
: caps.maxVertexTextureImageUnits;
// TODO(jmadill): faster way?
for (size_t samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++)
......@@ -3302,8 +3303,8 @@ gl::Error Renderer9::applyTextures(const gl::Context *context, gl::SamplerType s
gl::Error Renderer9::applyTextures(const gl::Context *context)
{
ANGLE_TRY(applyTextures(context, gl::SAMPLER_VERTEX));
ANGLE_TRY(applyTextures(context, gl::SAMPLER_PIXEL));
ANGLE_TRY(applyTextures(context, gl::SHADER_VERTEX));
ANGLE_TRY(applyTextures(context, gl::SHADER_FRAGMENT));
return gl::NoError();
}
......
......@@ -120,12 +120,12 @@ class Renderer9 : public RendererD3D
D3DFORMAT Format,
IDirect3DIndexBuffer9 **ppIndexBuffer);
gl::Error setSamplerState(const gl::Context *context,
gl::SamplerType type,
gl::ShaderType type,
int index,
gl::Texture *texture,
const gl::SamplerState &sampler);
gl::Error setTexture(const gl::Context *context,
gl::SamplerType type,
gl::ShaderType type,
int index,
gl::Texture *texture);
......@@ -404,7 +404,7 @@ class Renderer9 : public RendererD3D
gl::Error applyShaders(const gl::Context *context, GLenum drawMode);
gl::Error applyTextures(const gl::Context *context);
gl::Error applyTextures(const gl::Context *context, gl::SamplerType shaderType);
gl::Error applyTextures(const gl::Context *context, gl::ShaderType shaderType);
void generateCaps(gl::Caps *outCaps,
gl::TextureCapsMap *outTextureCaps,
......
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