Commit bfa23b3f by Nicolas Capens Committed by Nicolas Capens

Separate image depth and samples count.

Previously, multisampled images used the 'depth' member of 3D images or 2D arrays as the number of samples. This caused rendering to a layer of a 2D array to be interpreted as rendering to a multisampled render target. This change adds a 'samples' member which is orthogonal to 'depth'. Note that write operations put the same color into each of the samples, while read operations (still) assume multisampled images have been resolved into the first slice. Change-Id: Ib33a0cf8194e19fcbb569b0c257ba1e1bd9c4821 Reviewed-on: https://swiftshader-review.googlesource.com/14808Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 7f72df96
...@@ -2660,7 +2660,7 @@ namespace D3D9 ...@@ -2660,7 +2660,7 @@ namespace D3D9
void *bitmap = cursorSurface->lockExternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); void *bitmap = cursorSurface->lockExternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
delete cursor; delete cursor;
cursor = sw::Surface::create(nullptr, width, height, 1, 0, sw::FORMAT_A8R8G8B8, false, false); cursor = sw::Surface::create(nullptr, width, height, 1, 0, 1, sw::FORMAT_A8R8G8B8, false, false);
void *buffer = cursor->lockExternal(0, 0, 0, sw::LOCK_DISCARD, sw::PUBLIC); void *buffer = cursor->lockExternal(0, 0, 0, sw::LOCK_DISCARD, sw::PUBLIC);
memcpy(buffer, bitmap, width * height * sizeof(unsigned int)); memcpy(buffer, bitmap, width * height * sizeof(unsigned int));
......
...@@ -77,7 +77,7 @@ namespace D3D9 ...@@ -77,7 +77,7 @@ namespace D3D9
} }
Direct3DSurface9::Direct3DSurface9(Direct3DDevice9 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, unsigned int quality, bool lockableOverride, unsigned long usage) Direct3DSurface9::Direct3DSurface9(Direct3DDevice9 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, unsigned int quality, bool lockableOverride, unsigned long usage)
: Direct3DResource9(device, D3DRTYPE_SURFACE, pool, memoryUsage(width, height, format)), Surface(getParentResource(container), width, height, sampleCount(multiSample, quality), 0, translateFormat(format), isLockable(pool, usage, lockableOverride), (usage & D3DUSAGE_RENDERTARGET) || (usage & D3DUSAGE_DEPTHSTENCIL)), container(container), width(width), height(height), format(format), pool(pool), multiSample(multiSample), quality(quality), lockable(isLockable(pool, usage, lockableOverride)), usage(usage) : Direct3DResource9(device, D3DRTYPE_SURFACE, pool, memoryUsage(width, height, multiSample, quality, format)), Surface(getParentResource(container), width, height, 1, 0, sampleCount(multiSample, quality), translateFormat(format), isLockable(pool, usage, lockableOverride), (usage & D3DUSAGE_RENDERTARGET) || (usage & D3DUSAGE_DEPTHSTENCIL)), container(container), width(width), height(height), format(format), pool(pool), multiSample(multiSample), quality(quality), lockable(isLockable(pool, usage, lockableOverride)), usage(usage)
{ {
parentTexture = dynamic_cast<Direct3DBaseTexture9*>(container); parentTexture = dynamic_cast<Direct3DBaseTexture9*>(container);
} }
...@@ -411,8 +411,8 @@ namespace D3D9 ...@@ -411,8 +411,8 @@ namespace D3D9
return Surface::bytes(translateFormat(format)); return Surface::bytes(translateFormat(format));
} }
unsigned int Direct3DSurface9::memoryUsage(int width, int height, D3DFORMAT format) unsigned int Direct3DSurface9::memoryUsage(int width, int height, D3DMULTISAMPLE_TYPE multiSample, unsigned int quality, D3DFORMAT format)
{ {
return Surface::size(width, height, 1, 0, translateFormat(format)); return Surface::size(width, height, 1, 0, sampleCount(multiSample, quality), translateFormat(format));
} }
} }
...@@ -64,7 +64,7 @@ namespace D3D9 ...@@ -64,7 +64,7 @@ namespace D3D9
static int bytes(D3DFORMAT format); static int bytes(D3DFORMAT format);
private: private:
static unsigned int memoryUsage(int width, int height, D3DFORMAT format); static unsigned int memoryUsage(int width, int height, D3DMULTISAMPLE_TYPE multiSample, unsigned int quality, D3DFORMAT format);
// Creation parameters // Creation parameters
Unknown *const container; Unknown *const container;
......
...@@ -31,7 +31,7 @@ namespace D3D9 ...@@ -31,7 +31,7 @@ namespace D3D9
} }
Direct3DVolume9::Direct3DVolume9(Direct3DDevice9 *device, Direct3DVolumeTexture9 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, unsigned long usage) Direct3DVolume9::Direct3DVolume9(Direct3DDevice9 *device, Direct3DVolumeTexture9 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, unsigned long usage)
: device(device), Surface(container->getResource(), width, height, depth, 0, translateFormat(format), isLockable(pool, usage), false), container(container), width(width), height(height), depth(depth), format(format), pool(pool), lockable(isLockable(pool, usage)), usage(usage) : device(device), Surface(container->getResource(), width, height, depth, 0, 1, translateFormat(format), isLockable(pool, usage), false), container(container), width(width), height(height), depth(depth), format(format), pool(pool), lockable(isLockable(pool, usage)), usage(usage)
{ {
resource = new Direct3DResource9(device, D3DRTYPE_VOLUME, pool, memoryUsage(width, height, depth, format)); resource = new Direct3DResource9(device, D3DRTYPE_VOLUME, pool, memoryUsage(width, height, depth, format));
resource->bind(); resource->bind();
...@@ -230,6 +230,6 @@ namespace D3D9 ...@@ -230,6 +230,6 @@ namespace D3D9
unsigned int Direct3DVolume9::memoryUsage(int width, int height, int depth, D3DFORMAT format) unsigned int Direct3DVolume9::memoryUsage(int width, int height, int depth, D3DFORMAT format)
{ {
return Surface::size(width, height, depth, 0, translateFormat(format)); return Surface::size(width, height, depth, 0, 1, translateFormat(format));
} }
} }
...@@ -52,7 +52,7 @@ class [[clang::lto_visibility_public]] Image : public sw::Surface, public gl::Ob ...@@ -52,7 +52,7 @@ class [[clang::lto_visibility_public]] Image : public sw::Surface, public gl::Ob
protected: protected:
// 2D texture image // 2D texture image
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type) Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: sw::Surface(parentTexture->getResource(), width, height, 1, 0, SelectInternalFormat(format, type), true, true), : sw::Surface(parentTexture->getResource(), width, height, 1, 0, 1, SelectInternalFormat(format, type), true, true),
width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(1), width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(1),
parentTexture(parentTexture) parentTexture(parentTexture)
{ {
...@@ -63,7 +63,7 @@ protected: ...@@ -63,7 +63,7 @@ protected:
// 3D/Cube texture image // 3D/Cube texture image
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, int border, GLenum format, GLenum type) Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, int border, GLenum format, GLenum type)
: sw::Surface(parentTexture->getResource(), width, height, depth, border, SelectInternalFormat(format, type), true, true), : sw::Surface(parentTexture->getResource(), width, height, depth, border, 1, SelectInternalFormat(format, type), true, true),
width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(depth), width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(depth),
parentTexture(parentTexture) parentTexture(parentTexture)
{ {
...@@ -74,7 +74,7 @@ protected: ...@@ -74,7 +74,7 @@ protected:
// Native EGL image // Native EGL image
Image(GLsizei width, GLsizei height, GLenum format, GLenum type, int pitchP) Image(GLsizei width, GLsizei height, GLenum format, GLenum type, int pitchP)
: sw::Surface(nullptr, width, height, 1, 0, SelectInternalFormat(format, type), true, true, pitchP), : sw::Surface(nullptr, width, height, 1, 0, 1, SelectInternalFormat(format, type), true, true, pitchP),
width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(1), width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(1),
parentTexture(nullptr) parentTexture(nullptr)
{ {
...@@ -84,8 +84,9 @@ protected: ...@@ -84,8 +84,9 @@ protected:
// Render target // Render target
Image(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable) Image(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable)
: sw::Surface(nullptr, width, height, multiSampleDepth, 0, internalFormat, lockable, true), : sw::Surface(nullptr, width, height, 1, 0, multiSampleDepth, internalFormat, lockable, true),
width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(multiSampleDepth), width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat),
depth(multiSampleDepth),
parentTexture(nullptr) parentTexture(nullptr)
{ {
shared = false; shared = false;
......
...@@ -39,14 +39,14 @@ namespace gl ...@@ -39,14 +39,14 @@ namespace gl
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type) Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: parentTexture(parentTexture), width(width), height(height), format(format), type(type) : parentTexture(parentTexture), width(width), height(height), format(format), type(type)
, internalFormat(selectInternalFormat(format, type)), multiSampleDepth(1) , internalFormat(selectInternalFormat(format, type)), multiSampleDepth(1)
, sw::Surface(getParentResource(parentTexture), width, height, 1, 0, selectInternalFormat(format, type), true, true) , sw::Surface(getParentResource(parentTexture), width, height, 1, 0, 1, selectInternalFormat(format, type), true, true)
{ {
referenceCount = 1; referenceCount = 1;
} }
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget) Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
: parentTexture(parentTexture), width(width), height(height), internalFormat(internalFormat), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), multiSampleDepth(multiSampleDepth) : parentTexture(parentTexture), width(width), height(height), internalFormat(internalFormat), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), multiSampleDepth(multiSampleDepth)
, sw::Surface(getParentResource(parentTexture), width, height, multiSampleDepth, 0, internalFormat, lockable, renderTarget) , sw::Surface(getParentResource(parentTexture), width, height, 1, 0, multiSampleDepth, internalFormat, lockable, renderTarget)
{ {
referenceCount = 1; referenceCount = 1;
} }
......
...@@ -836,17 +836,18 @@ namespace es2 ...@@ -836,17 +836,18 @@ namespace es2
unsigned int destPitch = dest->getInternalPitchB(); unsigned int destPitch = dest->getInternalPitchB();
unsigned int bytes = dWidth * Surface::bytes(source->getInternalFormat()); unsigned int bytes = dWidth * Surface::bytes(source->getInternalFormat());
for(int z = 0; z < dDepth; ++z) for(int z = 0; z < dDepth; z++)
{ {
unsigned char *sourceBytes = (unsigned char*)source->lockInternal(0, 0, z, LOCK_READONLY, PUBLIC); unsigned char *sourceBytes = (unsigned char*)source->lockInternal(0, 0, z, LOCK_READONLY, PUBLIC);
unsigned char *destBytes = (unsigned char*)dest->lockInternal(0, 0, z, LOCK_READWRITE, PUBLIC); unsigned char *destBytes = (unsigned char*)dest->lockInternal(0, 0, z, LOCK_READWRITE, PUBLIC);
for(int y = 0; y < dHeight; ++y)
for(int y = 0; y < dHeight; y++)
{ {
memcpy(destBytes, sourceBytes, bytes); memcpy(destBytes, sourceBytes, bytes);
if(alpha0xFF) if(alpha0xFF)
{ {
for(int x = 0; x < dWidth; ++x) for(int x = 0; x < dWidth; x++)
{ {
destBytes[4 * x + 3] = 0xFF; destBytes[4 * x + 3] = 0xFF;
} }
...@@ -855,10 +856,10 @@ namespace es2 ...@@ -855,10 +856,10 @@ namespace es2
sourceBytes += sourcePitch; sourceBytes += sourcePitch;
destBytes += destPitch; destBytes += destPitch;
} }
}
source->unlockInternal(); source->unlockInternal();
dest->unlockInternal(); dest->unlockInternal();
}
} }
else else
{ {
......
...@@ -30,7 +30,7 @@ namespace sw ...@@ -30,7 +30,7 @@ namespace sw
delete blitCache; delete blitCache;
} }
void Blitter::clear(void* pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask) void Blitter::clear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask)
{ {
if(fastClear(pixel, format, dest, dRect, rgbaMask)) if(fastClear(pixel, format, dest, dRect, rgbaMask))
{ {
...@@ -44,7 +44,7 @@ namespace sw ...@@ -44,7 +44,7 @@ namespace sw
delete color; delete color;
} }
bool Blitter::fastClear(void* pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask) bool Blitter::fastClear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask)
{ {
if(format != FORMAT_A32B32G32R32F) if(format != FORMAT_A32B32G32R32F)
{ {
...@@ -99,26 +99,33 @@ namespace sw ...@@ -99,26 +99,33 @@ namespace sw
return false; return false;
} }
uint8_t *d = (uint8_t*)dest->lockInternal(dRect.x0, dRect.y0, dRect.slice, sw::LOCK_WRITEONLY, sw::PUBLIC); uint8_t *slice = (uint8_t*)dest->lockInternal(dRect.x0, dRect.y0, dRect.slice, sw::LOCK_WRITEONLY, sw::PUBLIC);
switch(Surface::bytes(dest->getFormat())) for(int j = 0; j < dest->getSamples(); j++)
{ {
case 2: uint8_t *d = slice;
for(int i = dRect.y0; i < dRect.y1; i++)
{ switch(Surface::bytes(dest->getFormat()))
sw::clear((uint16_t*)d, packed, dRect.x1 - dRect.x0);
d += dest->getInternalPitchB();
}
break;
case 4:
for(int i = dRect.y0; i < dRect.y1; i++)
{ {
sw::clear((uint32_t*)d, packed, dRect.x1 - dRect.x0); case 2:
d += dest->getInternalPitchB(); for(int i = dRect.y0; i < dRect.y1; i++)
{
sw::clear((uint16_t*)d, packed, dRect.x1 - dRect.x0);
d += dest->getInternalPitchB();
}
break;
case 4:
for(int i = dRect.y0; i < dRect.y1; i++)
{
sw::clear((uint32_t*)d, packed, dRect.x1 - dRect.x0);
d += dest->getInternalPitchB();
}
break;
default:
assert(false);
} }
break;
default: slice += dest->getInternalSliceB();
assert(false);
} }
dest->unlockInternal(); dest->unlockInternal();
...@@ -1201,6 +1208,7 @@ namespace sw ...@@ -1201,6 +1208,7 @@ namespace sw
For(Int i = x0d, i < x1d, i++) For(Int i = x0d, i < x1d, i++)
{ {
Pointer<Byte> d = destLine + (dstQuadLayout ? (((j & Int(1)) << 1) + (i * 2) - (i & Int(1))) : RValue<Int>(i)) * dstBytes; Pointer<Byte> d = destLine + (dstQuadLayout ? (((j & Int(1)) << 1) + (i * 2) - (i & Int(1))) : RValue<Int>(i)) * dstBytes;
if(hasConstantColorI) if(hasConstantColorI)
{ {
if(!write(constantColorI, d, state.destFormat, state.options)) if(!write(constantColorI, d, state.destFormat, state.options))
...@@ -1281,10 +1289,20 @@ namespace sw ...@@ -1281,10 +1289,20 @@ namespace sw
(c10 * ix + c11 * fx) * fy; (c10 * ix + c11 * fx) * fy;
} }
if(!ApplyScaleAndClamp(color, state) || !write(color, d, state.destFormat, state.options)) if(!ApplyScaleAndClamp(color, state))
{ {
return nullptr; return nullptr;
} }
for(int s = 0; s < state.destSamples; s++)
{
if(!write(color, d, state.destFormat, state.options))
{
return nullptr;
}
d += *Pointer<Int>(blit + OFFSET(BlitData,dSliceB));
}
} }
if(!hasConstantColorI && !hasConstantColorF) { x += w; } if(!hasConstantColorI && !hasConstantColorF) { x += w; }
...@@ -1322,6 +1340,7 @@ namespace sw ...@@ -1322,6 +1340,7 @@ namespace sw
state.sourceFormat = isStencil ? source->getStencilFormat() : source->getFormat(useSourceInternal); state.sourceFormat = isStencil ? source->getStencilFormat() : source->getFormat(useSourceInternal);
state.destFormat = isStencil ? dest->getStencilFormat() : dest->getFormat(useDestInternal); state.destFormat = isStencil ? dest->getStencilFormat() : dest->getFormat(useDestInternal);
state.destSamples = dest->getSamples();
state.options = options; state.options = options;
criticalSection.lock(); criticalSection.lock();
...@@ -1355,6 +1374,7 @@ namespace sw ...@@ -1355,6 +1374,7 @@ namespace sw
dest->lock(0, 0, destRect.slice, isRGBA ? (isEntireDest ? sw::LOCK_DISCARD : sw::LOCK_WRITEONLY) : sw::LOCK_READWRITE, sw::PUBLIC, useDestInternal); dest->lock(0, 0, destRect.slice, isRGBA ? (isEntireDest ? sw::LOCK_DISCARD : sw::LOCK_WRITEONLY) : sw::LOCK_READWRITE, sw::PUBLIC, useDestInternal);
data.sPitchB = isStencil ? source->getStencilPitchB() : source->getPitchB(useSourceInternal); data.sPitchB = isStencil ? source->getStencilPitchB() : source->getPitchB(useSourceInternal);
data.dPitchB = isStencil ? dest->getStencilPitchB() : dest->getPitchB(useDestInternal); data.dPitchB = isStencil ? dest->getStencilPitchB() : dest->getPitchB(useDestInternal);
data.dSliceB = isStencil ? dest->getStencilSliceB() : dest->getSliceB(useDestInternal);
data.w = sRect.width() / dRect.width(); data.w = sRect.width() / dRect.width();
data.h = sRect.height() / dRect.height(); data.h = sRect.height() / dRect.height();
......
...@@ -47,6 +47,7 @@ namespace sw ...@@ -47,6 +47,7 @@ namespace sw
Format sourceFormat; Format sourceFormat;
Format destFormat; Format destFormat;
int destSamples;
Blitter::Options options; Blitter::Options options;
}; };
...@@ -56,6 +57,7 @@ namespace sw ...@@ -56,6 +57,7 @@ namespace sw
void *dest; void *dest;
int sPitchB; int sPitchB;
int dPitchB; int dPitchB;
int dSliceB;
float x0; float x0;
float y0; float y0;
...@@ -75,12 +77,12 @@ namespace sw ...@@ -75,12 +77,12 @@ namespace sw
Blitter(); Blitter();
virtual ~Blitter(); virtual ~Blitter();
void clear(void* pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask); void clear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
void blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil = false); void blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil = false);
void blit3D(Surface *source, Surface *dest); void blit3D(Surface *source, Surface *dest);
private: private:
bool fastClear(void* pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask); bool fastClear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
bool read(Float4 &color, Pointer<Byte> element, Format format); bool read(Float4 &color, Pointer<Byte> element, Format format);
bool write(Float4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options); bool write(Float4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options);
......
...@@ -606,7 +606,8 @@ namespace sw ...@@ -606,7 +606,8 @@ namespace sw
if(draw->renderTarget[index]) if(draw->renderTarget[index])
{ {
data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->lockInternal(0, 0, q * ms, LOCK_READWRITE, MANAGED); data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->lockInternal(0, 0, 0, LOCK_READWRITE, MANAGED);
data->colorBuffer[index] += q * ms * context->renderTarget[index]->getSliceB(true);
data->colorPitchB[index] = context->renderTarget[index]->getInternalPitchB(); data->colorPitchB[index] = context->renderTarget[index]->getInternalPitchB();
data->colorSliceB[index] = context->renderTarget[index]->getInternalSliceB(); data->colorSliceB[index] = context->renderTarget[index]->getInternalSliceB();
} }
...@@ -617,14 +618,16 @@ namespace sw ...@@ -617,14 +618,16 @@ namespace sw
if(draw->depthBuffer) if(draw->depthBuffer)
{ {
data->depthBuffer = (float*)context->depthBuffer->lockInternal(0, 0, q * ms, LOCK_READWRITE, MANAGED); data->depthBuffer = (float*)context->depthBuffer->lockInternal(0, 0, 0, LOCK_READWRITE, MANAGED);
data->depthBuffer += q * ms * context->depthBuffer->getSliceB(true);
data->depthPitchB = context->depthBuffer->getInternalPitchB(); data->depthPitchB = context->depthBuffer->getInternalPitchB();
data->depthSliceB = context->depthBuffer->getInternalSliceB(); data->depthSliceB = context->depthBuffer->getInternalSliceB();
} }
if(draw->stencilBuffer) if(draw->stencilBuffer)
{ {
data->stencilBuffer = (unsigned char*)context->stencilBuffer->lockStencil(0, 0, q * ms, MANAGED); data->stencilBuffer = (unsigned char*)context->stencilBuffer->lockStencil(0, 0, 0, MANAGED);
data->stencilBuffer += q * ms * context->stencilBuffer->getSliceB(true);
data->stencilPitchB = context->stencilBuffer->getStencilPitchB(); data->stencilPitchB = context->stencilBuffer->getStencilPitchB();
data->stencilSliceB = context->stencilBuffer->getStencilSliceB(); data->stencilSliceB = context->stencilBuffer->getStencilSliceB();
} }
...@@ -673,13 +676,7 @@ namespace sw ...@@ -673,13 +676,7 @@ namespace sw
void Renderer::clear(void *value, Format format, Surface *dest, const Rect &clearRect, unsigned int rgbaMask) void Renderer::clear(void *value, Format format, Surface *dest, const Rect &clearRect, unsigned int rgbaMask)
{ {
SliceRect rect = clearRect; blitter->clear(value, format, dest, clearRect, rgbaMask);
int samples = dest->getDepth();
for(rect.slice = 0; rect.slice < samples; rect.slice++)
{
blitter->clear(value, format, dest, rect, rgbaMask);
}
} }
void Renderer::blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil) void Renderer::blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil)
......
...@@ -48,7 +48,7 @@ namespace sw ...@@ -48,7 +48,7 @@ namespace sw
typedef RectT<int> Rect; typedef RectT<int> Rect;
typedef RectT<float> RectF; typedef RectT<float> RectF;
template <typename T> struct SliceRectT : public RectT<T> template<typename T> struct SliceRectT : public RectT<T>
{ {
SliceRectT() : slice(0) {} SliceRectT() : slice(0) {}
SliceRectT(const RectT<T>& rect) : RectT<T>(rect), slice(0) {} SliceRectT(const RectT<T>& rect) : RectT<T>(rect), slice(0) {}
...@@ -237,7 +237,9 @@ namespace sw ...@@ -237,7 +237,9 @@ namespace sw
private: private:
struct Buffer struct Buffer
{ {
public: friend Surface;
private:
void write(int x, int y, int z, const Color<float> &color); void write(int x, int y, int z, const Color<float> &color);
void write(int x, int y, const Color<float> &color); void write(int x, int y, const Color<float> &color);
void write(void *element, const Color<float> &color); void write(void *element, const Color<float> &color);
...@@ -245,7 +247,7 @@ namespace sw ...@@ -245,7 +247,7 @@ namespace sw
Color<float> read(int x, int y) const; Color<float> read(int x, int y) const;
Color<float> read(void *element) const; Color<float> read(void *element) const;
Color<float> sample(float x, float y, float z) const; Color<float> sample(float x, float y, float z) const;
Color<float> sample(float x, float y) const; Color<float> sample(float x, float y, int layer) const;
void *lockRect(int x, int y, int z, Lock lock); void *lockRect(int x, int y, int z, Lock lock);
void unlockRect(); void unlockRect();
...@@ -254,12 +256,15 @@ namespace sw ...@@ -254,12 +256,15 @@ namespace sw
int width; int width;
int height; int height;
int depth; int depth;
short border;
short samples;
int bytes; int bytes;
int pitchB; int pitchB;
int pitchP; int pitchP;
int sliceB; int sliceB;
int sliceP; int sliceP;
int border;
Format format; Format format;
AtomicInt lock; AtomicInt lock;
...@@ -268,11 +273,11 @@ namespace sw ...@@ -268,11 +273,11 @@ namespace sw
protected: protected:
Surface(int width, int height, int depth, Format format, void *pixels, int pitch, int slice); Surface(int width, int height, int depth, Format format, void *pixels, int pitch, int slice);
Surface(Resource *texture, int width, int height, int depth, int border, Format format, bool lockable, bool renderTarget, int pitchP = 0); Surface(Resource *texture, int width, int height, int depth, int border, int samples, Format format, bool lockable, bool renderTarget, int pitchP = 0);
public: public:
static Surface *create(int width, int height, int depth, Format format, void *pixels, int pitch, int slice); static Surface *create(int width, int height, int depth, Format format, void *pixels, int pitch, int slice);
static Surface *create(Resource *texture, int width, int height, int depth, int border, Format format, bool lockable, bool renderTarget, int pitchP = 0); static Surface *create(Resource *texture, int width, int height, int depth, int border, int samples, Format format, bool lockable, bool renderTarget, int pitchP = 0);
virtual ~Surface() = 0; virtual ~Surface() = 0;
...@@ -313,6 +318,7 @@ namespace sw ...@@ -313,6 +318,7 @@ namespace sw
void sync(); // Wait for lock(s) to be released. void sync(); // Wait for lock(s) to be released.
inline bool isUnlocked() const; // Only reliable after sync(). inline bool isUnlocked() const; // Only reliable after sync().
inline int getSamples() const;
inline int getMultiSampleCount() const; inline int getMultiSampleCount() const;
inline int getSuperSampleCount() const; inline int getSuperSampleCount() const;
...@@ -351,7 +357,7 @@ namespace sw ...@@ -351,7 +357,7 @@ namespace sw
static int pitchP(int width, int border, Format format, bool target); static int pitchP(int width, int border, Format format, bool target);
static int sliceB(int width, int height, int border, Format format, bool target); static int sliceB(int width, int height, int border, Format format, bool target);
static int sliceP(int width, int height, int border, Format format, bool target); static int sliceP(int width, int height, int border, Format format, bool target);
static unsigned int size(int width, int height, int depth, int border, Format format); // FIXME: slice * depth static unsigned int size(int width, int height, int depth, int border, int samples, Format format); // FIXME: slice * depth
static bool isStencil(Format format); static bool isStencil(Format format);
static bool isDepth(Format format); static bool isDepth(Format format);
...@@ -474,7 +480,7 @@ namespace sw ...@@ -474,7 +480,7 @@ namespace sw
static void update(Buffer &destination, Buffer &source); static void update(Buffer &destination, Buffer &source);
static void genericUpdate(Buffer &destination, Buffer &source); static void genericUpdate(Buffer &destination, Buffer &source);
static void *allocateBuffer(int width, int height, int depth, int border, Format format); static void *allocateBuffer(int width, int height, int depth, int border, int samples, Format format);
static void memfill4(void *buffer, int pattern, int bytes); static void memfill4(void *buffer, int pattern, int bytes);
bool identicalFormats() const; bool identicalFormats() const;
...@@ -625,14 +631,19 @@ namespace sw ...@@ -625,14 +631,19 @@ namespace sw
return stencil.sliceB; return stencil.sliceB;
} }
int Surface::getSamples() const
{
return internal.samples;
}
int Surface::getMultiSampleCount() const int Surface::getMultiSampleCount() const
{ {
return sw::min(internal.depth, 4); return sw::min((int)internal.samples, 4);
} }
int Surface::getSuperSampleCount() const int Surface::getSuperSampleCount() const
{ {
return internal.depth > 4 ? internal.depth / 4 : 1; return internal.samples > 4 ? internal.samples / 4 : 1;
} }
bool Surface::isUnlocked() const bool Surface::isUnlocked() 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