Commit 61e49a5c by Geoff Lang Committed by Shannon Woods

Added Functions for gathering all referenced D3D and DXGI formats. Renderers now…

Added Functions for gathering all referenced D3D and DXGI formats. Renderers now use these functions to generate the multisample support maps. TRAC #23212 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Geoff Lang
parent a9f52472
...@@ -273,38 +273,15 @@ EGLint Renderer11::initialize() ...@@ -273,38 +273,15 @@ EGLint Renderer11::initialize()
} }
#endif #endif
unsigned int maxSupportedSamples = 0; mMaxSupportedSamples = 0;
unsigned int rtFormatCount = ArraySize(RenderTargetFormats);
unsigned int dsFormatCount = ArraySize(DepthStencilFormats);
for (unsigned int i = 0; i < rtFormatCount + dsFormatCount; ++i)
{
DXGI_FORMAT format = (i < rtFormatCount) ? RenderTargetFormats[i] : DepthStencilFormats[i - rtFormatCount];
if (format != DXGI_FORMAT_UNKNOWN)
{
UINT formatSupport;
result = mDevice->CheckFormatSupport(format, &formatSupport);
if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET))
{
MultisampleSupportInfo supportInfo;
for (unsigned int j = 1; j <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; j++)
{
result = mDevice->CheckMultisampleQualityLevels(format, j, &supportInfo.qualityLevels[j - 1]);
if (SUCCEEDED(result) && supportInfo.qualityLevels[j - 1] > 0)
{
maxSupportedSamples = std::max(j, maxSupportedSamples);
}
else
{
supportInfo.qualityLevels[j - 1] = 0;
}
}
mMultisampleSupportMap.insert(std::make_pair(format, supportInfo)); 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);
} }
mMaxSupportedSamples = maxSupportedSamples;
initializeDevice(); initializeDevice();
...@@ -4004,4 +3981,31 @@ bool Renderer11::getLUID(LUID *adapterLuid) const ...@@ -4004,4 +3981,31 @@ bool Renderer11::getLUID(LUID *adapterLuid) const
return true; return true;
} }
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;
}
} }
...@@ -256,7 +256,9 @@ class Renderer11 : public Renderer ...@@ -256,7 +256,9 @@ class Renderer11 : public Renderer
struct MultisampleSupportInfo struct MultisampleSupportInfo
{ {
unsigned int qualityLevels[D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT]; unsigned int qualityLevels[D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT];
unsigned int maxSupportedSamples;
}; };
MultisampleSupportInfo getMultisampleSupportInfo(DXGI_FORMAT format);
typedef std::unordered_map<DXGI_FORMAT, MultisampleSupportInfo> MultisampleSupportMap; typedef std::unordered_map<DXGI_FORMAT, MultisampleSupportInfo> MultisampleSupportMap;
MultisampleSupportMap mMultisampleSupportMap; MultisampleSupportMap mMultisampleSupportMap;
......
...@@ -169,12 +169,6 @@ Renderer9::~Renderer9() ...@@ -169,12 +169,6 @@ Renderer9::~Renderer9()
{ {
mD3d9Module = NULL; mD3d9Module = NULL;
} }
while (!mMultiSampleSupport.empty())
{
delete [] mMultiSampleSupport.begin()->second;
mMultiSampleSupport.erase(mMultiSampleSupport.begin());
}
} }
Renderer9 *Renderer9::makeRenderer9(Renderer *renderer) Renderer9 *Renderer9::makeRenderer9(Renderer *renderer)
...@@ -308,42 +302,16 @@ EGLint Renderer9::initialize() ...@@ -308,42 +302,16 @@ EGLint Renderer9::initialize()
mMaxSwapInterval = std::max(mMaxSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);
} }
int max = 0; mMaxSupportedSamples = 0;
for (unsigned int i = 0; i < ArraySize(RenderTargetFormats); ++i)
{
bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1];
getMultiSampleSupport(RenderTargetFormats[i], multisampleArray);
mMultiSampleSupport[RenderTargetFormats[i]] = multisampleArray;
for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j)
{
if (multisampleArray[j] && j != D3DMULTISAMPLE_NONMASKABLE && j > max)
{
max = j;
}
}
}
for (unsigned int i = 0; i < ArraySize(DepthStencilFormats); ++i) const d3d9::D3DFormatSet &d3d9Formats = d3d9::GetAllUsedD3DFormats();
for (d3d9::D3DFormatSet::const_iterator i = d3d9Formats.begin(); i != d3d9Formats.end(); ++i)
{ {
if (DepthStencilFormats[i] == D3DFMT_UNKNOWN) MultisampleSupportInfo support = getMultiSampleSupport(*i);
continue; mMultiSampleSupport[*i] = support;
mMaxSupportedSamples = std::max(mMaxSupportedSamples, support.maxSupportedSamples);
bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1];
getMultiSampleSupport(DepthStencilFormats[i], multisampleArray);
mMultiSampleSupport[DepthStencilFormats[i]] = multisampleArray;
for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j)
{
if (multisampleArray[j] && j != D3DMULTISAMPLE_NONMASKABLE && j > max)
{
max = j;
}
}
} }
mMaxSupportedSamples = max;
static const TCHAR windowName[] = TEXT("AngleHiddenWindow"); static const TCHAR windowName[] = TEXT("AngleHiddenWindow");
static const TCHAR className[] = TEXT("STATIC"); static const TCHAR className[] = TEXT("STATIC");
...@@ -2193,15 +2161,30 @@ GUID Renderer9::getAdapterIdentifier() const ...@@ -2193,15 +2161,30 @@ GUID Renderer9::getAdapterIdentifier() const
return mAdapterIdentifier.DeviceIdentifier; return mAdapterIdentifier.DeviceIdentifier;
} }
void Renderer9::getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray) Renderer9::MultisampleSupportInfo Renderer9::getMultiSampleSupport(D3DFORMAT format)
{ {
for (int multiSampleIndex = 0; multiSampleIndex <= D3DMULTISAMPLE_16_SAMPLES; multiSampleIndex++) MultisampleSupportInfo support = { 0 };
for (unsigned int multiSampleIndex = 0; multiSampleIndex < ArraySize(support.supportedSamples); multiSampleIndex++)
{ {
HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format, HRESULT result = mD3d9->CheckDeviceMultiSampleType(mAdapter, mDeviceType, format, TRUE,
TRUE, (D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL); (D3DMULTISAMPLE_TYPE)multiSampleIndex, NULL);
multiSampleArray[multiSampleIndex] = SUCCEEDED(result); 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;
} }
bool Renderer9::getBGRATextureSupport() const bool Renderer9::getBGRATextureSupport() const
...@@ -2460,7 +2443,7 @@ int Renderer9::getNearestSupportedSamples(D3DFORMAT format, int requested) const ...@@ -2460,7 +2443,7 @@ int Renderer9::getNearestSupportedSamples(D3DFORMAT format, int requested) const
return requested; return requested;
} }
std::map<D3DFORMAT, bool *>::const_iterator itr = mMultiSampleSupport.find(format); MultisampleSupportMap::const_iterator itr = mMultiSampleSupport.find(format);
if (itr == mMultiSampleSupport.end()) if (itr == mMultiSampleSupport.end())
{ {
if (format == D3DFMT_UNKNOWN) if (format == D3DFMT_UNKNOWN)
...@@ -2468,9 +2451,9 @@ int Renderer9::getNearestSupportedSamples(D3DFORMAT format, int requested) const ...@@ -2468,9 +2451,9 @@ int Renderer9::getNearestSupportedSamples(D3DFORMAT format, int requested) const
return -1; return -1;
} }
for (int i = requested; i <= D3DMULTISAMPLE_16_SAMPLES; ++i) for (unsigned int i = requested; i < ArraySize(itr->second.supportedSamples); ++i)
{ {
if (itr->second[i] && i != D3DMULTISAMPLE_NONMASKABLE) if (itr->second.supportedSamples[i] && i != D3DMULTISAMPLE_NONMASKABLE)
{ {
return i; return i;
} }
......
...@@ -227,7 +227,6 @@ class Renderer9 : public Renderer ...@@ -227,7 +227,6 @@ class Renderer9 : public Renderer
void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer); void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer); void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer);
void getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray);
bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged); bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
gl::Renderbuffer *getNullColorbuffer(gl::Renderbuffer *depthbuffer); gl::Renderbuffer *getNullColorbuffer(gl::Renderbuffer *depthbuffer);
...@@ -287,8 +286,16 @@ class Renderer9 : public Renderer ...@@ -287,8 +286,16 @@ class Renderer9 : public Renderer
bool mLuminanceTextureSupport; bool mLuminanceTextureSupport;
bool mLuminanceAlphaTextureSupport; bool mLuminanceAlphaTextureSupport;
std::map<D3DFORMAT, bool *> mMultiSampleSupport; struct MultisampleSupportInfo
GLsizei mMaxSupportedSamples; {
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;
......
...@@ -512,9 +512,15 @@ static DXGIFormatInfoMap buildDXGIFormatInfoMap() ...@@ -512,9 +512,15 @@ static DXGIFormatInfoMap buildDXGIFormatInfoMap()
return map; return map;
} }
static bool getDXGIFormatInfo(DXGI_FORMAT format, DXGIFormatInfo *outFormatInfo) static const DXGIFormatInfoMap &GetDXGIFormatInfoMap()
{ {
static const DXGIFormatInfoMap infoMap = buildDXGIFormatInfoMap(); static const DXGIFormatInfoMap infoMap = buildDXGIFormatInfoMap();
return infoMap;
}
static bool getDXGIFormatInfo(DXGI_FORMAT format, DXGIFormatInfo *outFormatInfo)
{
const DXGIFormatInfoMap &infoMap = GetDXGIFormatInfoMap();
DXGIFormatInfoMap::const_iterator iter = infoMap.find(format); DXGIFormatInfoMap::const_iterator iter = infoMap.find(format);
if (iter != infoMap.end()) if (iter != infoMap.end())
{ {
...@@ -530,6 +536,19 @@ static bool getDXGIFormatInfo(DXGI_FORMAT format, DXGIFormatInfo *outFormatInfo) ...@@ -530,6 +536,19 @@ static bool getDXGIFormatInfo(DXGI_FORMAT format, DXGIFormatInfo *outFormatInfo)
} }
} }
static d3d11::DXGIFormatSet BuildAllDXGIFormatSet()
{
d3d11::DXGIFormatSet set;
const DXGIFormatInfoMap &infoMap = GetDXGIFormatInfoMap();
for (DXGIFormatInfoMap::const_iterator i = infoMap.begin(); i != infoMap.end(); ++i)
{
set.insert(i->first);
}
return set;
}
namespace d3d11 namespace d3d11
{ {
...@@ -653,6 +672,12 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi ...@@ -653,6 +672,12 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi
} }
} }
const DXGIFormatSet &GetAllUsedDXGIFormats()
{
static DXGIFormatSet formatSet = BuildAllDXGIFormatSet();
return formatSet;
}
} }
namespace gl_d3d11 namespace gl_d3d11
......
...@@ -18,6 +18,8 @@ namespace rx ...@@ -18,6 +18,8 @@ namespace rx
namespace d3d11 namespace d3d11
{ {
typedef std::set<DXGI_FORMAT> DXGIFormatSet;
MipGenerationFunction GetMipGenerationFunction(DXGI_FORMAT format); MipGenerationFunction GetMipGenerationFunction(DXGI_FORMAT format);
LoadImageFunction GetImageLoadFunction(GLint internalFormat, GLenum type, GLuint clientVersion); LoadImageFunction GetImageLoadFunction(GLint internalFormat, GLenum type, GLuint clientVersion);
...@@ -27,6 +29,8 @@ GLuint GetBlockHeight(DXGI_FORMAT format); ...@@ -27,6 +29,8 @@ GLuint GetBlockHeight(DXGI_FORMAT format);
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset); void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
const DXGIFormatSet &GetAllUsedDXGIFormats();
} }
namespace gl_d3d11 namespace gl_d3d11
......
...@@ -209,9 +209,15 @@ static D3D9FormatInfoMap buildD3D9FormatInfoMap() ...@@ -209,9 +209,15 @@ static D3D9FormatInfoMap buildD3D9FormatInfoMap()
return map; return map;
} }
static bool getD3D9FormatInfo(D3DFORMAT format, D3DFormatInfo *outFormatInfo) static const D3D9FormatInfoMap &GetD3D9FormatInfoMap()
{ {
static const D3D9FormatInfoMap infoMap = buildD3D9FormatInfoMap(); static const D3D9FormatInfoMap infoMap = buildD3D9FormatInfoMap();
return infoMap;
}
static bool getD3D9FormatInfo(D3DFORMAT format, D3DFormatInfo *outFormatInfo)
{
const D3D9FormatInfoMap &infoMap = GetD3D9FormatInfoMap();
D3D9FormatInfoMap::const_iterator iter = infoMap.find(format); D3D9FormatInfoMap::const_iterator iter = infoMap.find(format);
if (iter != infoMap.end()) if (iter != infoMap.end())
{ {
...@@ -226,6 +232,18 @@ static bool getD3D9FormatInfo(D3DFORMAT format, D3DFormatInfo *outFormatInfo) ...@@ -226,6 +232,18 @@ static bool getD3D9FormatInfo(D3DFORMAT format, D3DFormatInfo *outFormatInfo)
return false; return false;
} }
} }
static d3d9::D3DFormatSet BuildAllD3DFormatSet()
{
d3d9::D3DFormatSet set;
const D3D9FormatInfoMap &infoMap = GetD3D9FormatInfoMap();
for (D3D9FormatInfoMap::const_iterator i = infoMap.begin(); i != infoMap.end(); ++i)
{
set.insert(i->first);
}
return set;
}
namespace d3d9 namespace d3d9
{ {
...@@ -348,6 +366,12 @@ void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsize ...@@ -348,6 +366,12 @@ void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsize
} }
} }
const D3DFormatSet &GetAllUsedD3DFormats()
{
static const D3DFormatSet formatSet = BuildAllD3DFormatSet();
return formatSet;
}
} }
namespace gl_d3d9 namespace gl_d3d9
......
...@@ -20,6 +20,8 @@ class Renderer9; ...@@ -20,6 +20,8 @@ class Renderer9;
namespace d3d9 namespace d3d9
{ {
typedef std::set<D3DFORMAT> D3DFormatSet;
MipGenerationFunction GetMipGenerationFunction(D3DFORMAT format); MipGenerationFunction GetMipGenerationFunction(D3DFORMAT format);
LoadImageFunction GetImageLoadFunction(GLint internalFormat, const Renderer9 *renderer); LoadImageFunction GetImageLoadFunction(GLint internalFormat, const Renderer9 *renderer);
...@@ -30,6 +32,8 @@ GLuint GetBlockSize(D3DFORMAT format, GLuint width, GLuint height); ...@@ -30,6 +32,8 @@ GLuint GetBlockSize(D3DFORMAT format, GLuint width, GLuint height);
void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset); void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
const D3DFormatSet &GetAllUsedD3DFormats();
} }
namespace gl_d3d9 namespace gl_d3d9
......
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