Commit 8af24c5c by Nicolas Capens Committed by Nicolas Capens

Implement render target layers support.

This adds the ability to render to a specific layer of a 2D array texture. Change-Id: I3055d62c9964b2729704785efb068b82eef4f9ce Reviewed-on: https://swiftshader-review.googlesource.com/14668Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent bfa23b3f
...@@ -214,13 +214,13 @@ namespace sw ...@@ -214,13 +214,13 @@ namespace sw
float d = static_cast<float>(source->getDepth()) / static_cast<float>(dest->getDepth()); float d = static_cast<float>(source->getDepth()) / static_cast<float>(dest->getDepth());
float z = 0.5f * d; float z = 0.5f * d;
for(int k = 0; k < dest->getDepth(); ++k) for(int k = 0; k < dest->getDepth(); k++)
{ {
float y = 0.5f * h; float y = 0.5f * h;
for(int j = 0; j < dest->getHeight(); ++j) for(int j = 0; j < dest->getHeight(); j++)
{ {
float x = 0.5f * w; float x = 0.5f * w;
for(int i = 0; i < dest->getWidth(); ++i) for(int i = 0; i < dest->getWidth(); i++)
{ {
dest->copyInternal(source, i, j, k, x, y, z, true); dest->copyInternal(source, i, j, k, x, y, z, true);
x += w; x += w;
......
...@@ -465,8 +465,11 @@ namespace sw ...@@ -465,8 +465,11 @@ namespace sw
bool textureTransformProject[8]; bool textureTransformProject[8];
Surface *renderTarget[RENDERTARGETS]; Surface *renderTarget[RENDERTARGETS];
unsigned int renderTargetLayer[RENDERTARGETS];
Surface *depthBuffer; Surface *depthBuffer;
unsigned int depthBufferLayer;
Surface *stencilBuffer; Surface *stencilBuffer;
unsigned int stencilBufferLayer;
// Fog // Fog
bool fogEnable; bool fogEnable;
......
...@@ -159,19 +159,22 @@ namespace sw ...@@ -159,19 +159,22 @@ namespace sw
} }
} }
void PixelProcessor::setRenderTarget(int index, Surface *renderTarget) void PixelProcessor::setRenderTarget(int index, Surface *renderTarget, unsigned int layer)
{ {
context->renderTarget[index] = renderTarget; context->renderTarget[index] = renderTarget;
context->renderTargetLayer[index] = layer;
} }
void PixelProcessor::setDepthBuffer(Surface *depthBuffer) void PixelProcessor::setDepthBuffer(Surface *depthBuffer, unsigned int layer)
{ {
context->depthBuffer = depthBuffer; context->depthBuffer = depthBuffer;
context->depthBufferLayer = layer;
} }
void PixelProcessor::setStencilBuffer(Surface *stencilBuffer) void PixelProcessor::setStencilBuffer(Surface *stencilBuffer, unsigned int layer)
{ {
context->stencilBuffer = stencilBuffer; context->stencilBuffer = stencilBuffer;
context->stencilBufferLayer = layer;
} }
void PixelProcessor::setTexCoordIndex(unsigned int stage, int texCoordIndex) void PixelProcessor::setTexCoordIndex(unsigned int stage, int texCoordIndex)
......
...@@ -197,9 +197,9 @@ namespace sw ...@@ -197,9 +197,9 @@ namespace sw
void setUniformBuffer(int index, sw::Resource* buffer, int offset); void setUniformBuffer(int index, sw::Resource* buffer, int offset);
void lockUniformBuffers(byte** u, sw::Resource* uniformBuffers[]); void lockUniformBuffers(byte** u, sw::Resource* uniformBuffers[]);
void setRenderTarget(int index, Surface *renderTarget); void setRenderTarget(int index, Surface *renderTarget, unsigned int layer = 0);
void setDepthBuffer(Surface *depthBuffer); void setDepthBuffer(Surface *depthBuffer, unsigned int layer = 0);
void setStencilBuffer(Surface *stencilBuffer); void setStencilBuffer(Surface *stencilBuffer, unsigned int layer = 0);
void setTexCoordIndex(unsigned int stage, int texCoordIndex); void setTexCoordIndex(unsigned int stage, int texCoordIndex);
void setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation); void setStageOperation(unsigned int stage, TextureStage::StageOperation stageOperation);
......
...@@ -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, 0, LOCK_READWRITE, MANAGED); unsigned int layer = context->renderTargetLayer[index];
data->colorBuffer[index] = (unsigned int*)context->renderTarget[index]->lockInternal(0, 0, layer, LOCK_READWRITE, MANAGED);
data->colorBuffer[index] += q * ms * context->renderTarget[index]->getSliceB(true); 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();
...@@ -618,7 +619,8 @@ namespace sw ...@@ -618,7 +619,8 @@ namespace sw
if(draw->depthBuffer) if(draw->depthBuffer)
{ {
data->depthBuffer = (float*)context->depthBuffer->lockInternal(0, 0, 0, LOCK_READWRITE, MANAGED); unsigned int layer = context->depthBufferLayer;
data->depthBuffer = (float*)context->depthBuffer->lockInternal(0, 0, layer, LOCK_READWRITE, MANAGED);
data->depthBuffer += q * ms * context->depthBuffer->getSliceB(true); 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();
...@@ -626,7 +628,8 @@ namespace sw ...@@ -626,7 +628,8 @@ namespace sw
if(draw->stencilBuffer) if(draw->stencilBuffer)
{ {
data->stencilBuffer = (unsigned char*)context->stencilBuffer->lockStencil(0, 0, 0, MANAGED); unsigned int layer = context->stencilBufferLayer;
data->stencilBuffer = (unsigned char*)context->stencilBuffer->lockStencil(0, 0, layer, MANAGED);
data->stencilBuffer += q * ms * context->stencilBuffer->getSliceB(true); 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();
......
...@@ -694,10 +694,10 @@ namespace sw ...@@ -694,10 +694,10 @@ namespace sw
unsigned char mask = inst->dst.mask; unsigned char mask = inst->dst.mask;
unsigned char reg = inst->dst.index; unsigned char reg = inst->dst.index;
if(mask & 0x01) input[reg][0] = Semantic(usage, index); if(mask & 0x01) input[reg][0] = Semantic(usage, index);
if(mask & 0x02) input[reg][1] = Semantic(usage, index); if(mask & 0x02) input[reg][1] = Semantic(usage, index);
if(mask & 0x04) input[reg][2] = Semantic(usage, index); if(mask & 0x04) input[reg][2] = Semantic(usage, index);
if(mask & 0x08) input[reg][3] = Semantic(usage, index); if(mask & 0x08) input[reg][3] = Semantic(usage, index);
} }
else if(inst->dst.type == Shader::PARAMETER_MISCTYPE) else if(inst->dst.type == Shader::PARAMETER_MISCTYPE)
{ {
......
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