Commit 5f4c4636 by Geoff Lang

Use the FormatCaps for multisample validation and queries.

BUG=angle:658 Change-Id: Ic9fa53fb62d7eff62f07b68d7ddada461ecad859 Reviewed-on: https://chromium-review.googlesource.com/206832Tested-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 8d62bcc4
...@@ -24,6 +24,30 @@ TextureCaps::TextureCaps() ...@@ -24,6 +24,30 @@ TextureCaps::TextureCaps()
{ {
} }
GLuint TextureCaps::getMaxSamples() const
{
return !sampleCounts.empty() ? *sampleCounts.rbegin() : 0;
}
GLuint TextureCaps::getNearestSamples(GLuint requestedSamples) const
{
if (requestedSamples == 0)
{
return 0;
}
for (SupportedSampleSet::const_iterator i = sampleCounts.begin(); i != sampleCounts.end(); i++)
{
GLuint samples = *i;
if (samples >= requestedSamples)
{
return samples;
}
}
return 0;
}
void TextureCapsMap::insert(GLenum internalFormat, const TextureCaps &caps) void TextureCapsMap::insert(GLenum internalFormat, const TextureCaps &caps)
{ {
mCapsMap.insert(std::make_pair(internalFormat, caps)); mCapsMap.insert(std::make_pair(internalFormat, caps));
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
namespace gl namespace gl
{ {
typedef std::set<GLuint> SupportedSampleSet;
struct TextureCaps struct TextureCaps
{ {
TextureCaps(); TextureCaps();
...@@ -30,7 +32,14 @@ struct TextureCaps ...@@ -30,7 +32,14 @@ struct TextureCaps
// Support for being used as a framebuffer attachment or renderbuffer format // Support for being used as a framebuffer attachment or renderbuffer format
bool renderable; bool renderable;
std::set<GLuint> sampleCounts; SupportedSampleSet sampleCounts;
// Get the maximum number of samples supported
GLuint getMaxSamples() const;
// Get the number of supported samples that is at least as many as requested. Returns 0 if
// there are no sample counts available
GLuint getNearestSamples(GLuint requestedSamples) const;
}; };
class TextureCapsMap class TextureCapsMap
...@@ -166,6 +175,7 @@ struct Extensions ...@@ -166,6 +175,7 @@ struct Extensions
// GL_ANGLE_framebuffer_multisample // GL_ANGLE_framebuffer_multisample
bool framebufferMultisample; bool framebufferMultisample;
GLuint maxSamples;
// GL_ANGLE_instanced_arrays // GL_ANGLE_instanced_arrays
bool instancedArrays; bool instancedArrays;
......
...@@ -957,9 +957,7 @@ void Context::getIntegerv(GLenum pname, GLint *params) ...@@ -957,9 +957,7 @@ void Context::getIntegerv(GLenum pname, GLint *params)
case GL_NUM_COMPRESSED_TEXTURE_FORMATS: case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
params[0] = mNumCompressedTextureFormats; params[0] = mNumCompressedTextureFormats;
break; break;
case GL_MAX_SAMPLES_ANGLE: case GL_MAX_SAMPLES_ANGLE: *params = mExtensions.maxSamples; break;
*params = static_cast<GLint>(getMaxSupportedSamples());
break;
case GL_IMPLEMENTATION_COLOR_READ_TYPE: case GL_IMPLEMENTATION_COLOR_READ_TYPE:
case GL_IMPLEMENTATION_COLOR_READ_FORMAT: case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
{ {
...@@ -2003,26 +2001,6 @@ unsigned int Context::getMaximumCombinedUniformBufferBindings() const ...@@ -2003,26 +2001,6 @@ unsigned int Context::getMaximumCombinedUniformBufferBindings() const
mRenderer->getMaxFragmentShaderUniformBuffers(); mRenderer->getMaxFragmentShaderUniformBuffers();
} }
int Context::getMaxSupportedSamples() const
{
return mRenderer->getMaxSupportedSamples();
}
GLsizei Context::getMaxSupportedFormatSamples(GLenum internalFormat) const
{
return mRenderer->getMaxSupportedFormatSamples(internalFormat);
}
GLsizei Context::getNumSampleCounts(GLenum internalFormat) const
{
return mRenderer->getNumSampleCounts(internalFormat);
}
void Context::getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const
{
mRenderer->getSampleCounts(internalFormat, bufSize, params);
}
unsigned int Context::getMaxTransformFeedbackBufferBindings() const unsigned int Context::getMaxTransformFeedbackBufferBindings() const
{ {
return mRenderer->getMaxTransformFeedbackBuffers(); return mRenderer->getMaxTransformFeedbackBuffers();
...@@ -2522,6 +2500,7 @@ void Context::initCaps(GLuint clientVersion) ...@@ -2522,6 +2500,7 @@ void Context::initCaps(GLuint clientVersion)
//mExtensions.sRGB = false; //mExtensions.sRGB = false;
} }
GLuint maxSamples = 0;
const TextureCapsMap &rendererFormats = mRenderer->getRendererTextureCaps(); const TextureCapsMap &rendererFormats = mRenderer->getRendererTextureCaps();
for (TextureCapsMap::const_iterator i = rendererFormats.begin(); i != rendererFormats.end(); i++) for (TextureCapsMap::const_iterator i = rendererFormats.begin(); i != rendererFormats.end(); i++)
{ {
...@@ -2533,9 +2512,20 @@ void Context::initCaps(GLuint clientVersion) ...@@ -2533,9 +2512,20 @@ void Context::initCaps(GLuint clientVersion)
// Update the format caps based on the client version and extensions // Update the format caps based on the client version and extensions
formatCaps.renderable = IsRenderingSupported(format, mExtensions, clientVersion); formatCaps.renderable = IsRenderingSupported(format, mExtensions, clientVersion);
formatCaps.filterable = IsFilteringSupported(format, mExtensions, clientVersion); formatCaps.filterable = IsFilteringSupported(format, mExtensions, clientVersion);
// OpenGL ES does not support multisampling with integer formats
GLenum componentType = GetComponentType(format);
if (componentType == GL_INT || componentType == GL_UNSIGNED_INT)
{
formatCaps.sampleCounts.clear();
}
maxSamples = std::max(maxSamples, formatCaps.getMaxSamples());
mTextureCaps.insert(format, formatCaps); mTextureCaps.insert(format, formatCaps);
} }
} }
mExtensions.maxSamples = maxSamples;
} }
} }
......
...@@ -215,10 +215,6 @@ class Context ...@@ -215,10 +215,6 @@ class Context
int getMajorShaderModel() const; int getMajorShaderModel() const;
unsigned int getMaximumCombinedTextureImageUnits() const; unsigned int getMaximumCombinedTextureImageUnits() const;
unsigned int getMaximumCombinedUniformBufferBindings() const; unsigned int getMaximumCombinedUniformBufferBindings() const;
GLsizei getMaxSupportedSamples() const;
GLsizei getMaxSupportedFormatSamples(GLenum internalFormat) const;
GLsizei getNumSampleCounts(GLenum internalFormat) const;
void getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const;
unsigned int getMaxTransformFeedbackBufferBindings() const; unsigned int getMaxTransformFeedbackBufferBindings() const;
GLintptr getUniformBufferOffsetAlignment() const; GLintptr getUniformBufferOffsetAlignment() const;
const std::string &getRendererString() const; const std::string &getRendererString() const;
......
...@@ -7904,10 +7904,12 @@ void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenu ...@@ -7904,10 +7904,12 @@ void __stdcall glGetInternalformativ(GLenum target, GLenum internalformat, GLenu
{ {
case GL_NUM_SAMPLE_COUNTS: case GL_NUM_SAMPLE_COUNTS:
if (bufSize != 0) if (bufSize != 0)
*params = context->getNumSampleCounts(internalformat); {
*params = formatCaps.sampleCounts.size();
}
break; break;
case GL_SAMPLES: case GL_SAMPLES:
context->getSampleCounts(internalformat, bufSize, params); std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
break; break;
default: default:
return gl::error(GL_INVALID_ENUM); return gl::error(GL_INVALID_ENUM);
......
...@@ -182,11 +182,6 @@ class Renderer ...@@ -182,11 +182,6 @@ class Renderer
virtual int getMinSwapInterval() const = 0; virtual int getMinSwapInterval() const = 0;
virtual int getMaxSwapInterval() const = 0; virtual int getMaxSwapInterval() const = 0;
virtual GLsizei getMaxSupportedSamples() const = 0;
virtual GLsizei getMaxSupportedFormatSamples(GLenum internalFormat) const = 0;
virtual GLsizei getNumSampleCounts(GLenum internalFormat) const = 0;
virtual void getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const = 0;
// Pixel operations // Pixel operations
virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0; virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0;
virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0; virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0;
......
...@@ -283,13 +283,8 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height ...@@ -283,13 +283,8 @@ RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height
DXGI_FORMAT rtvFormat = gl_d3d11::GetRTVFormat(internalFormat); DXGI_FORMAT rtvFormat = gl_d3d11::GetRTVFormat(internalFormat);
DXGI_FORMAT dsvFormat = gl_d3d11::GetDSVFormat(internalFormat); DXGI_FORMAT dsvFormat = gl_d3d11::GetDSVFormat(internalFormat);
DXGI_FORMAT multisampleFormat = (dsvFormat != DXGI_FORMAT_UNKNOWN ? dsvFormat : rtvFormat); const gl::TextureCaps &textureCaps = mRenderer->getRendererTextureCaps().get(internalFormat);
int supportedSamples = mRenderer->getNearestSupportedSamples(multisampleFormat, samples); GLuint supportedSamples = textureCaps.getNearestSamples(samples);
if (supportedSamples < 0)
{
gl::error(GL_OUT_OF_MEMORY);
return;
}
if (width > 0 && height > 0) if (width > 0 && height > 0)
{ {
......
...@@ -91,8 +91,6 @@ Renderer11::Renderer11(egl::Display *display, EGLNativeDisplayType hDc, EGLint r ...@@ -91,8 +91,6 @@ Renderer11::Renderer11(egl::Display *display, EGLNativeDisplayType hDc, EGLint r
mDeviceLost = false; mDeviceLost = false;
mMaxSupportedSamples = 0;
mDevice = NULL; mDevice = NULL;
mDeviceContext = NULL; mDeviceContext = NULL;
mDxgiAdapter = NULL; mDxgiAdapter = NULL;
...@@ -283,16 +281,6 @@ EGLint Renderer11::initialize() ...@@ -283,16 +281,6 @@ EGLint Renderer11::initialize()
} }
#endif #endif
mMaxSupportedSamples = 0;
const d3d11::DXGIFormatSet &dxgiFormats = d3d11::GetAllUsedDXGIFormats();
for (d3d11::DXGIFormatSet::const_iterator i = dxgiFormats.begin(); i != dxgiFormats.end(); ++i)
{
MultisampleSupportInfo support = getMultisampleSupportInfo(*i);
mMultisampleSupportMap.insert(std::make_pair(*i, support));
mMaxSupportedSamples = std::max(mMaxSupportedSamples, support.maxSupportedSamples);
}
initializeDevice(); initializeDevice();
return EGL_SUCCESS; return EGL_SUCCESS;
...@@ -2041,94 +2029,6 @@ int Renderer11::getMaxSwapInterval() const ...@@ -2041,94 +2029,6 @@ int Renderer11::getMaxSwapInterval() const
return 4; return 4;
} }
int Renderer11::getMaxSupportedSamples() const
{
return mMaxSupportedSamples;
}
GLsizei Renderer11::getMaxSupportedFormatSamples(GLenum internalFormat) const
{
DXGI_FORMAT format = gl_d3d11::GetRenderableFormat(internalFormat);
MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format);
return (iter != mMultisampleSupportMap.end()) ? iter->second.maxSupportedSamples : 0;
}
GLsizei Renderer11::getNumSampleCounts(GLenum internalFormat) const
{
unsigned int numCounts = 0;
// D3D11 supports multisampling for signed and unsigned format, but ES 3.0 does not
GLenum componentType = gl::GetComponentType(internalFormat);
if (componentType != GL_INT && componentType != GL_UNSIGNED_INT)
{
DXGI_FORMAT format = gl_d3d11::GetRenderableFormat(internalFormat);
MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format);
if (iter != mMultisampleSupportMap.end())
{
const MultisampleSupportInfo& info = iter->second;
for (int i = 0; i < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++)
{
if (info.qualityLevels[i] > 0)
{
numCounts++;
}
}
}
}
return numCounts;
}
void Renderer11::getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const
{
// D3D11 supports multisampling for signed and unsigned format, but ES 3.0 does not
GLenum componentType = gl::GetComponentType(internalFormat);
if (componentType == GL_INT || componentType == GL_UNSIGNED_INT)
{
return;
}
DXGI_FORMAT format = gl_d3d11::GetRenderableFormat(internalFormat);
MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format);
if (iter != mMultisampleSupportMap.end())
{
const MultisampleSupportInfo& info = iter->second;
int bufPos = 0;
for (int i = D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT - 1; i >= 0 && bufPos < bufSize; i--)
{
if (info.qualityLevels[i] > 0)
{
params[bufPos++] = i + 1;
}
}
}
}
int Renderer11::getNearestSupportedSamples(DXGI_FORMAT format, unsigned int requested) const
{
if (requested == 0)
{
return 0;
}
MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format);
if (iter != mMultisampleSupportMap.end())
{
const MultisampleSupportInfo& info = iter->second;
for (unsigned int i = requested - 1; i < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++)
{
if (info.qualityLevels[i] > 0)
{
return i + 1;
}
}
}
return -1;
}
bool Renderer11::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) bool Renderer11::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source)
{ {
if (source && dest) if (source && dest)
...@@ -3410,33 +3310,6 @@ GLenum Renderer11::getVertexComponentType(const gl::VertexFormat &vertexFormat) ...@@ -3410,33 +3310,6 @@ GLenum Renderer11::getVertexComponentType(const gl::VertexFormat &vertexFormat)
return d3d11::GetComponentType(gl_d3d11::GetNativeVertexFormat(vertexFormat)); return d3d11::GetComponentType(gl_d3d11::GetNativeVertexFormat(vertexFormat));
} }
Renderer11::MultisampleSupportInfo Renderer11::getMultisampleSupportInfo(DXGI_FORMAT format)
{
MultisampleSupportInfo supportInfo = { 0 };
UINT formatSupport;
HRESULT result;
result = mDevice->CheckFormatSupport(format, &formatSupport);
if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET))
{
for (unsigned int i = 1; i <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++)
{
result = mDevice->CheckMultisampleQualityLevels(format, i, &supportInfo.qualityLevels[i - 1]);
if (SUCCEEDED(result) && supportInfo.qualityLevels[i - 1] > 0)
{
supportInfo.maxSupportedSamples = std::max(supportInfo.maxSupportedSamples, i);
}
else
{
supportInfo.qualityLevels[i - 1] = 0;
}
}
}
return supportInfo;
}
void Renderer11::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const void Renderer11::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const
{ {
d3d11_gl::GenerateCaps(mDevice, outCaps, outTextureCaps, outExtensions); d3d11_gl::GenerateCaps(mDevice, outCaps, outTextureCaps, outExtensions);
......
...@@ -129,12 +129,6 @@ class Renderer11 : public Renderer ...@@ -129,12 +129,6 @@ class Renderer11 : public Renderer
virtual int getMinSwapInterval() const; virtual int getMinSwapInterval() const;
virtual int getMaxSwapInterval() const; virtual int getMaxSwapInterval() const;
virtual GLsizei getMaxSupportedSamples() const;
virtual GLsizei getMaxSupportedFormatSamples(GLenum internalFormat) const;
virtual GLsizei getNumSampleCounts(GLenum internalFormat) const;
virtual void getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const;
int getNearestSupportedSamples(DXGI_FORMAT format, unsigned int requested) const;
// Pixel operations // Pixel operations
virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source); virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source);
virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source); virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source);
...@@ -252,19 +246,6 @@ class Renderer11 : public Renderer ...@@ -252,19 +246,6 @@ class Renderer11 : public Renderer
RenderStateCache mStateCache; RenderStateCache mStateCache;
// Multisample format support
struct MultisampleSupportInfo
{
unsigned int qualityLevels[D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT];
unsigned int maxSupportedSamples;
};
MultisampleSupportInfo getMultisampleSupportInfo(DXGI_FORMAT format);
typedef std::unordered_map<DXGI_FORMAT, MultisampleSupportInfo> MultisampleSupportMap;
MultisampleSupportMap mMultisampleSupportMap;
unsigned int mMaxSupportedSamples;
// current render target states // current render target states
unsigned int mAppliedRenderTargetSerials[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS]; unsigned int mAppliedRenderTargetSerials[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS];
unsigned int mAppliedDepthbufferSerial; unsigned int mAppliedDepthbufferSerial;
......
...@@ -498,11 +498,14 @@ static size_t GetMaximumViewportSize(D3D_FEATURE_LEVEL featureLevel) ...@@ -498,11 +498,14 @@ static size_t GetMaximumViewportSize(D3D_FEATURE_LEVEL featureLevel)
void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *textureCapsMap, gl::Extensions *extensions) void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *textureCapsMap, gl::Extensions *extensions)
{ {
GLuint maxSamples = 0;
const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats(); const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats();
for (gl::FormatSet::const_iterator internalFormat = allFormats.begin(); internalFormat != allFormats.end(); ++internalFormat) for (gl::FormatSet::const_iterator internalFormat = allFormats.begin(); internalFormat != allFormats.end(); ++internalFormat)
{ {
gl::TextureCaps textureCaps = GenerateTextureFormatCaps(*internalFormat, device); gl::TextureCaps textureCaps = GenerateTextureFormatCaps(*internalFormat, device);
textureCapsMap->insert(*internalFormat, textureCaps); textureCapsMap->insert(*internalFormat, textureCaps);
maxSamples = std::max(maxSamples, textureCaps.getMaxSamples());
} }
D3D_FEATURE_LEVEL featureLevel = device->GetFeatureLevel(); D3D_FEATURE_LEVEL featureLevel = device->GetFeatureLevel();
...@@ -559,6 +562,7 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text ...@@ -559,6 +562,7 @@ void GenerateCaps(ID3D11Device *device, gl::Caps *caps, gl::TextureCapsMap *text
extensions->blendMinMax = true; extensions->blendMinMax = true;
extensions->framebufferBlit = true; extensions->framebufferBlit = true;
extensions->framebufferMultisample = true; extensions->framebufferMultisample = true;
extensions->maxSamples = maxSamples;
extensions->instancedArrays = GetInstancingSupport(featureLevel); extensions->instancedArrays = GetInstancingSupport(featureLevel);
extensions->packReverseRowOrder = true; extensions->packReverseRowOrder = true;
extensions->standardDerivatives = GetDerivativeInstructionSupport(featureLevel); extensions->standardDerivatives = GetDerivativeInstructionSupport(featureLevel);
......
...@@ -45,14 +45,9 @@ RenderTarget9::RenderTarget9(Renderer *renderer, GLsizei width, GLsizei height, ...@@ -45,14 +45,9 @@ RenderTarget9::RenderTarget9(Renderer *renderer, GLsizei width, GLsizei height,
mRenderTarget = NULL; mRenderTarget = NULL;
D3DFORMAT renderFormat = gl_d3d9::GetRenderFormat(internalFormat); D3DFORMAT renderFormat = gl_d3d9::GetRenderFormat(internalFormat);
int supportedSamples = mRenderer->getNearestSupportedSamples(renderFormat, samples);
if (supportedSamples == -1) const gl::TextureCaps &textureCaps = mRenderer->getRendererTextureCaps().get(internalFormat);
{ GLuint supportedSamples = textureCaps.getNearestSamples(samples);
gl::error(GL_OUT_OF_MEMORY);
return;
}
HRESULT result = D3DERR_INVALIDCALL; HRESULT result = D3DERR_INVALIDCALL;
......
...@@ -117,8 +117,6 @@ Renderer9::Renderer9(egl::Display *display, EGLNativeDisplayType hDc, EGLint req ...@@ -117,8 +117,6 @@ Renderer9::Renderer9(egl::Display *display, EGLNativeDisplayType hDc, EGLint req
mDeviceLost = false; mDeviceLost = false;
mMaxSupportedSamples = 0;
mMaskedClearSavedState = NULL; mMaskedClearSavedState = NULL;
mVertexDataManager = NULL; mVertexDataManager = NULL;
...@@ -297,17 +295,6 @@ EGLint Renderer9::initialize() ...@@ -297,17 +295,6 @@ EGLint Renderer9::initialize()
mMaxSwapInterval = std::max(mMaxSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);
} }
mMaxSupportedSamples = 0;
const d3d9::D3DFormatSet &d3d9Formats = d3d9::GetAllUsedD3DFormats();
for (d3d9::D3DFormatSet::const_iterator i = d3d9Formats.begin(); i != d3d9Formats.end(); ++i)
{
TRACE_EVENT0("gpu", "getMultiSampleSupport");
MultisampleSupportInfo support = getMultiSampleSupport(*i);
mMultiSampleSupport[*i] = support;
mMaxSupportedSamples = std::max(mMaxSupportedSamples, support.maxSupportedSamples);
}
static const TCHAR windowName[] = TEXT("AngleHiddenWindow"); static const TCHAR windowName[] = TEXT("AngleHiddenWindow");
static const TCHAR className[] = TEXT("STATIC"); static const TCHAR className[] = TEXT("STATIC");
...@@ -2218,32 +2205,6 @@ GUID Renderer9::getAdapterIdentifier() const ...@@ -2218,32 +2205,6 @@ GUID Renderer9::getAdapterIdentifier() const
return mAdapterIdentifier.DeviceIdentifier; return mAdapterIdentifier.DeviceIdentifier;
} }
Renderer9::MultisampleSupportInfo Renderer9::getMultiSampleSupport(D3DFORMAT format)
{
MultisampleSupportInfo support = { 0 };
for (unsigned int multiSampleIndex = 0; multiSampleIndex < ArraySize(support.supportedSamples); multiSampleIndex++)
{
HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format, TRUE,
(D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL);
if (SUCCEEDED(result))
{
support.supportedSamples[multiSampleIndex] = true;
if (multiSampleIndex != D3DMULTISAMPLE_NONMASKABLE)
{
support.maxSupportedSamples = std::max(support.maxSupportedSamples, multiSampleIndex);
}
}
else
{
support.supportedSamples[multiSampleIndex] = false;
}
}
return support;
}
unsigned int Renderer9::getMaxVertexTextureImageUnits() const unsigned int Renderer9::getMaxVertexTextureImageUnits() const
{ {
META_ASSERT(MAX_TEXTURE_IMAGE_UNITS_VTF_SM3 <= gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS); META_ASSERT(MAX_TEXTURE_IMAGE_UNITS_VTF_SM3 <= gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS);
...@@ -2372,84 +2333,6 @@ int Renderer9::getMaxSwapInterval() const ...@@ -2372,84 +2333,6 @@ int Renderer9::getMaxSwapInterval() const
return mMaxSwapInterval; return mMaxSwapInterval;
} }
int Renderer9::getMaxSupportedSamples() const
{
return mMaxSupportedSamples;
}
GLsizei Renderer9::getMaxSupportedFormatSamples(GLenum internalFormat) const
{
D3DFORMAT format = gl_d3d9::GetTextureFormat(internalFormat);
MultisampleSupportMap::const_iterator itr = mMultiSampleSupport.find(format);
return (itr != mMultiSampleSupport.end()) ? mMaxSupportedSamples : 0;
}
GLsizei Renderer9::getNumSampleCounts(GLenum internalFormat) const
{
D3DFORMAT format = gl_d3d9::GetTextureFormat(internalFormat);
MultisampleSupportMap::const_iterator iter = mMultiSampleSupport.find(format);
unsigned int numCounts = 0;
if (iter != mMultiSampleSupport.end())
{
const MultisampleSupportInfo& info = iter->second;
for (int i = 0; i < D3DMULTISAMPLE_16_SAMPLES; i++)
{
if (i != D3DMULTISAMPLE_NONMASKABLE && info.supportedSamples[i])
{
numCounts++;
}
}
}
return numCounts;
}
void Renderer9::getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const
{
D3DFORMAT format = gl_d3d9::GetTextureFormat(internalFormat);
MultisampleSupportMap::const_iterator iter = mMultiSampleSupport.find(format);
if (iter != mMultiSampleSupport.end())
{
const MultisampleSupportInfo& info = iter->second;
int bufPos = 0;
for (int i = D3DMULTISAMPLE_16_SAMPLES; i >= 0 && bufPos < bufSize; i--)
{
if (i != D3DMULTISAMPLE_NONMASKABLE && info.supportedSamples[i])
{
params[bufPos++] = i;
}
}
}
}
int Renderer9::getNearestSupportedSamples(D3DFORMAT format, int requested) const
{
if (requested == 0)
{
return requested;
}
MultisampleSupportMap::const_iterator itr = mMultiSampleSupport.find(format);
if (itr == mMultiSampleSupport.end())
{
if (format == D3DFMT_UNKNOWN)
return 0;
return -1;
}
for (unsigned int i = requested; i < ArraySize(itr->second.supportedSamples); ++i)
{
if (itr->second.supportedSamples[i] && i != D3DMULTISAMPLE_NONMASKABLE)
{
return i;
}
}
return -1;
}
bool Renderer9::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) bool Renderer9::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source)
{ {
bool result = false; bool result = false;
......
...@@ -131,12 +131,6 @@ class Renderer9 : public Renderer ...@@ -131,12 +131,6 @@ class Renderer9 : public Renderer
virtual int getMinSwapInterval() const; virtual int getMinSwapInterval() const;
virtual int getMaxSwapInterval() const; virtual int getMaxSwapInterval() const;
virtual GLsizei getMaxSupportedSamples() const;
virtual GLsizei getMaxSupportedFormatSamples(GLenum internalFormat) const;
virtual GLsizei getNumSampleCounts(GLenum internalFormat) const;
virtual void getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const;
int getNearestSupportedSamples(D3DFORMAT format, int requested) const;
// Pixel operations // Pixel operations
virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source); virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source);
virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source); virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source);
...@@ -269,17 +263,6 @@ class Renderer9 : public Renderer ...@@ -269,17 +263,6 @@ class Renderer9 : public Renderer
bool mVertexTextureSupport; bool mVertexTextureSupport;
struct MultisampleSupportInfo
{
bool supportedSamples[D3DMULTISAMPLE_16_SAMPLES + 1];
unsigned int maxSupportedSamples;
};
typedef std::map<D3DFORMAT, MultisampleSupportInfo> MultisampleSupportMap;
MultisampleSupportMap mMultiSampleSupport;
unsigned int mMaxSupportedSamples;
MultisampleSupportInfo getMultiSampleSupport(D3DFORMAT format);
// current render target states // current render target states
unsigned int mAppliedRenderTargetSerial; unsigned int mAppliedRenderTargetSerial;
unsigned int mAppliedDepthbufferSerial; unsigned int mAppliedDepthbufferSerial;
......
...@@ -757,7 +757,7 @@ D3DFORMAT GetRenderFormat(GLenum internalFormat) ...@@ -757,7 +757,7 @@ D3DFORMAT GetRenderFormat(GLenum internalFormat)
} }
} }
D3DMULTISAMPLE_TYPE GetMultisampleType(GLsizei samples) D3DMULTISAMPLE_TYPE GetMultisampleType(GLuint samples)
{ {
return (samples > 1) ? static_cast<D3DMULTISAMPLE_TYPE>(samples) : D3DMULTISAMPLE_NONE; return (samples > 1) ? static_cast<D3DMULTISAMPLE_TYPE>(samples) : D3DMULTISAMPLE_NONE;
} }
......
...@@ -56,7 +56,7 @@ namespace gl_d3d9 ...@@ -56,7 +56,7 @@ namespace gl_d3d9
D3DFORMAT GetTextureFormat(GLenum internalForma); D3DFORMAT GetTextureFormat(GLenum internalForma);
D3DFORMAT GetRenderFormat(GLenum internalFormat); D3DFORMAT GetRenderFormat(GLenum internalFormat);
D3DMULTISAMPLE_TYPE GetMultisampleType(GLsizei samples); D3DMULTISAMPLE_TYPE GetMultisampleType(GLuint samples);
bool RequiresTextureDataInitialization(GLint internalFormat); bool RequiresTextureDataInitialization(GLint internalFormat);
InitializeTextureDataFunction GetTextureDataInitializationFunction(GLint internalFormat); InitializeTextureDataFunction GetTextureDataInitializationFunction(GLint internalFormat);
......
...@@ -302,12 +302,15 @@ void GenerateCaps(IDirect3D9 *d3d9, IDirect3DDevice9 *device, D3DDEVTYPE deviceT ...@@ -302,12 +302,15 @@ void GenerateCaps(IDirect3D9 *d3d9, IDirect3DDevice9 *device, D3DDEVTYPE deviceT
D3DDISPLAYMODE currentDisplayMode; D3DDISPLAYMODE currentDisplayMode;
d3d9->GetAdapterDisplayMode(adapter, &currentDisplayMode); d3d9->GetAdapterDisplayMode(adapter, &currentDisplayMode);
GLuint maxSamples = 0;
const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats(); const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats();
for (gl::FormatSet::const_iterator internalFormat = allFormats.begin(); internalFormat != allFormats.end(); ++internalFormat) for (gl::FormatSet::const_iterator internalFormat = allFormats.begin(); internalFormat != allFormats.end(); ++internalFormat)
{ {
gl::TextureCaps textureCaps = GenerateTextureFormatCaps(*internalFormat, d3d9, deviceType, adapter, gl::TextureCaps textureCaps = GenerateTextureFormatCaps(*internalFormat, d3d9, deviceType, adapter,
currentDisplayMode.Format); currentDisplayMode.Format);
textureCapsMap->insert(*internalFormat, textureCaps); textureCapsMap->insert(*internalFormat, textureCaps);
maxSamples = std::max(maxSamples, textureCaps.getMaxSamples());
} }
// GL core feature limits // GL core feature limits
...@@ -394,6 +397,7 @@ void GenerateCaps(IDirect3D9 *d3d9, IDirect3DDevice9 *device, D3DDEVTYPE deviceT ...@@ -394,6 +397,7 @@ void GenerateCaps(IDirect3D9 *d3d9, IDirect3DDevice9 *device, D3DDEVTYPE deviceT
extensions->blendMinMax = true; extensions->blendMinMax = true;
extensions->framebufferBlit = true; extensions->framebufferBlit = true;
extensions->framebufferMultisample = true; extensions->framebufferMultisample = true;
extensions->maxSamples = maxSamples;
extensions->instancedArrays = deviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0); extensions->instancedArrays = deviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0);
extensions->packReverseRowOrder = true; extensions->packReverseRowOrder = true;
extensions->standardDerivatives = (deviceCaps.PS20Caps.Caps & D3DPS20CAPS_GRADIENTINSTRUCTIONS) != 0; extensions->standardDerivatives = (deviceCaps.PS20Caps.Caps & D3DPS20CAPS_GRADIENTINSTRUCTIONS) != 0;
......
...@@ -335,14 +335,21 @@ bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum ta ...@@ -335,14 +335,21 @@ bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum ta
// internal format. // internal format.
if (angleExtension) if (angleExtension)
{ {
if (samples > context->getMaxSupportedSamples()) ASSERT(context->getExtensions().framebufferMultisample);
if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples)
{ {
return gl::error(GL_INVALID_VALUE, false); return gl::error(GL_INVALID_VALUE, false);
} }
// Check if this specific format supports enough samples
if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
{
return gl::error(GL_OUT_OF_MEMORY, false);
}
} }
else else
{ {
if (samples > context->getMaxSupportedFormatSamples(internalformat)) if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
{ {
return gl::error(GL_INVALID_VALUE, false); return gl::error(GL_INVALID_VALUE, false);
} }
......
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