From a52dfbdae4b91f970793a0e3b1df6f210e3e1312 Mon Sep 17 00:00:00 2001 From: Alexis Hetu Date: Wed, 5 Oct 2016 17:03:30 -0400 Subject: [PATCH] Adding functionality to stencils MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Two minor features are required for the blitFramebuffer implementation in OpenGL ES 3: - lockStencil with x,y coordinates - getting the stencil format (new getStencilFormat function) Change-Id: I83ccccefe70dbbedd05b5d82bc75d30f689c4abe Reviewed-on: https://swiftshader-review.googlesource.com/7490 Tested-by: Alexis Hétu Reviewed-by: Nicolas Capens --- src/D3D9/Direct3DDevice9.cpp | 4 ++-- src/OpenGL/common/Image.cpp | 4 ++-- src/OpenGL/libGL/Device.cpp | 4 ++-- src/OpenGL/libGL/Image.cpp | 2 +- src/OpenGL/libGLES_CM/Device.cpp | 4 ++-- src/OpenGL/libGLESv2/Device.cpp | 4 ++-- src/Renderer/Renderer.cpp | 2 +- src/Renderer/Surface.cpp | 6 +++--- src/Renderer/Surface.hpp | 8 +++++++- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/D3D9/Direct3DDevice9.cpp b/src/D3D9/Direct3DDevice9.cpp index 515ab4bf5..126b0df6c 100644 --- a/src/D3D9/Direct3DDevice9.cpp +++ b/src/D3D9/Direct3DDevice9.cpp @@ -6271,8 +6271,8 @@ namespace D3D9 if(source->hasStencil()) { - byte *sourceBuffer = (byte*)source->lockStencil(0, sw::PUBLIC); - byte *destBuffer = (byte*)dest->lockStencil(0, sw::PUBLIC); + byte *sourceBuffer = (byte*)source->lockStencil(0, 0, 0, sw::PUBLIC); + byte *destBuffer = (byte*)dest->lockStencil(0, 0, 0, sw::PUBLIC); unsigned int width = source->getWidth(); unsigned int height = source->getHeight(); diff --git a/src/OpenGL/common/Image.cpp b/src/OpenGL/common/Image.cpp index b7362d8e0..c734ba234 100644 --- a/src/OpenGL/common/Image.cpp +++ b/src/OpenGL/common/Image.cpp @@ -1627,7 +1627,7 @@ namespace egl { LoadImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); - unsigned char *stencil = reinterpret_cast(lockStencil(0, sw::PUBLIC)); + unsigned char *stencil = reinterpret_cast(lockStencil(0, 0, 0, sw::PUBLIC)); if(stencil) { @@ -1641,7 +1641,7 @@ namespace egl { LoadImageData(xoffset, yoffset, zoffset, width, height, depth, inputPitch, inputHeight, getPitch(), getHeight(), input, buffer); - unsigned char *stencil = reinterpret_cast(lockStencil(0, sw::PUBLIC)); + unsigned char *stencil = reinterpret_cast(lockStencil(0, 0, 0, sw::PUBLIC)); if(stencil) { diff --git a/src/OpenGL/libGL/Device.cpp b/src/OpenGL/libGL/Device.cpp index 57c669f13..86d01b9e6 100644 --- a/src/OpenGL/libGL/Device.cpp +++ b/src/OpenGL/libGL/Device.cpp @@ -570,8 +570,8 @@ namespace gl if(source->hasStencil()) { - sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, PUBLIC); - sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, PUBLIC); + sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, 0, 0, PUBLIC); + sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, 0, 0, PUBLIC); unsigned int width = source->getWidth(); unsigned int height = source->getHeight(); diff --git a/src/OpenGL/libGL/Image.cpp b/src/OpenGL/libGL/Image.cpp index 49204f5aa..6a8c01dc8 100644 --- a/src/OpenGL/libGL/Image.cpp +++ b/src/OpenGL/libGL/Image.cpp @@ -672,7 +672,7 @@ namespace gl } } - unsigned char *stencil = reinterpret_cast(lockStencil(0, sw::PUBLIC)); + unsigned char *stencil = reinterpret_cast(lockStencil(0, 0, 0, sw::PUBLIC)); if(stencil) { diff --git a/src/OpenGL/libGLES_CM/Device.cpp b/src/OpenGL/libGLES_CM/Device.cpp index 6587d36bb..b66c32304 100644 --- a/src/OpenGL/libGLES_CM/Device.cpp +++ b/src/OpenGL/libGLES_CM/Device.cpp @@ -455,8 +455,8 @@ namespace es1 if(source->hasStencil()) { - sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, PUBLIC); - sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, PUBLIC); + sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, 0, 0, PUBLIC); + sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, 0, 0, PUBLIC); unsigned int width = source->getWidth(); unsigned int height = source->getHeight(); diff --git a/src/OpenGL/libGLESv2/Device.cpp b/src/OpenGL/libGLESv2/Device.cpp index 3307f45fd..225ceeb11 100644 --- a/src/OpenGL/libGLESv2/Device.cpp +++ b/src/OpenGL/libGLESv2/Device.cpp @@ -621,8 +621,8 @@ namespace es2 if(source->hasStencil()) { - sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, PUBLIC); - sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, PUBLIC); + sw::byte *sourceBuffer = (sw::byte*)source->lockStencil(0, 0, 0, PUBLIC); + sw::byte *destBuffer = (sw::byte*)dest->lockStencil(0, 0, 0, PUBLIC); copyBuffer(sourceBuffer, destBuffer, source->getWidth(), source->getHeight(), source->getInternalPitchB(), dest->getInternalPitchB(), egl::Image::bytes(source->getInternalFormat()), flipX, flipY); diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp index fe6c7f9ef..0700a887f 100644 --- a/src/Renderer/Renderer.cpp +++ b/src/Renderer/Renderer.cpp @@ -634,7 +634,7 @@ namespace sw if(draw->stencilBuffer) { - data->stencilBuffer = (unsigned char*)context->stencilBuffer->lockStencil(q * ms, MANAGED); + data->stencilBuffer = (unsigned char*)context->stencilBuffer->lockStencil(0, 0, q * ms, MANAGED); data->stencilPitchB = context->stencilBuffer->getStencilPitchB(); data->stencilSliceB = context->stencilBuffer->getStencilSliceB(); } diff --git a/src/Renderer/Surface.cpp b/src/Renderer/Surface.cpp index 5ddea4a47..d97257421 100644 --- a/src/Renderer/Surface.cpp +++ b/src/Renderer/Surface.cpp @@ -1426,7 +1426,7 @@ namespace sw internal.unlockRect(); } - void *Surface::lockStencil(int front, Accessor client) + void *Surface::lockStencil(int x, int y, int front, Accessor client) { resource->lock(client); @@ -1435,7 +1435,7 @@ namespace sw stencil.buffer = allocateBuffer(stencil.width, stencil.height, stencil.depth, stencil.format); } - return stencil.lockRect(0, 0, front, LOCK_READWRITE); // FIXME + return stencil.lockRect(x, y, front, LOCK_READWRITE); // FIXME } void Surface::unlockStencil() @@ -3258,7 +3258,7 @@ namespace sw unsigned int fill = maskedS; fill = fill | (fill << 8) | (fill << 16) + (fill << 24); - char *buffer = (char*)lockStencil(0, PUBLIC); + char *buffer = (char*)lockStencil(0, 0, 0, PUBLIC); // Stencil buffers are assumed to use quad layout for(int z = 0; z < stencil.depth; z++) diff --git a/src/Renderer/Surface.hpp b/src/Renderer/Surface.hpp index cd89d7482..dd96ffd9f 100644 --- a/src/Renderer/Surface.hpp +++ b/src/Renderer/Surface.hpp @@ -283,8 +283,9 @@ namespace sw inline int getInternalSliceB() const; inline int getInternalSliceP() const; - void *lockStencil(int front, Accessor client); + void *lockStencil(int x, int y, int front, Accessor client); void unlockStencil(); + inline Format getStencilFormat() const; inline int getStencilPitchB() const; inline int getStencilSliceB() const; @@ -573,6 +574,11 @@ namespace sw return internal.sliceP; } + Format Surface::getStencilFormat() const + { + return stencil.format; + } + int Surface::getStencilPitchB() const { return stencil.pitchB; -- 2.11.0