summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/libGLESv2/renderer
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@theqtcompany.com>2014-11-14 10:52:01 +0200
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2014-11-14 19:01:38 +0100
commitc6df5fe3ed0f2a722931be098914978cf17a666f (patch)
tree23abe340dbc427a3afd255c79316f79fef937059 /src/3rdparty/angle/src/libGLESv2/renderer
parent32db2f425a0b85bc03d7de42d7b44337d0aa16f4 (diff)
ANGLE: Upgrade to version 1.2.30d6c255d238
The following patches have been changed: 0001-Fix-compilation-for-MSVC-2008-and-std-tuple.patch Removed because it is no longer possible to build ANGLE with MSVC2008 0002-Fix-compilation-of-ANGLE-with-mingw-tdm64-gcc-4.8.1.patch Removed because the minimum version of MinGW moved to 4.8.2 0005-Fix-build-when-SSE2-is-not-available.patch Removed because it was fixed upstream 0006-Fix-compilation-of-libGLESv2-with-older-MinGW-w64-he.patch Removed because older versions of MinGW are not supported 0007-Fix-ANGLE-build-with-Microsoft-Visual-Studio-14-CTP.patch Removed because it was fixed upstream Task-number: QTBUG-41903 Change-Id: I976d30802f7f6fee725cf9a9f1325d5e82609835 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com> Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
Diffstat (limited to 'src/3rdparty/angle/src/libGLESv2/renderer')
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/BufferImpl.h3
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/FenceImpl.h36
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/Image.cpp22
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/Image.h25
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.cpp146
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.h127
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.cpp36
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.h41
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.cpp21
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.h41
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/Renderer.cpp45
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/Renderer.h237
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/ShaderExecutable.h13
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/ShaderImpl.h3
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/SwapChain.h25
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/TextureImpl.h24
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/Workarounds.h39
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/copyimage.cpp2
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.cpp12
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.h17
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp68
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.h35
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.cpp245
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.h28
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.cpp4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.h15
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.cpp8
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.h10
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.cpp24
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.h6
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp1814
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.h184
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.cpp108
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.h51
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.cpp796
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.h195
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.cpp118
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.h22
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.cpp1711
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.h227
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.cpp18
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.h21
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.cpp12
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.h10
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.cpp36
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.h13
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.cpp108
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.h38
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp88
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h8
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.cpp19
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.h2
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.cpp214
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.h48
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp549
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.h40
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/IndexBuffer11.h2
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp14
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.cpp116
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.h12
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.cpp3
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.h4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp15
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h3
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.cpp327
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.h84
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp1298
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h152
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/SwapChain11.cpp169
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/SwapChain11.h10
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.cpp1817
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.h177
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexArray11.h4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp13
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.h4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/formatutils11.cpp2
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/renderer11_utils.cpp94
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/renderer11_utils.h6
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Blit9.cpp227
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Blit9.h32
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Buffer9.cpp13
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Buffer9.h8
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Fence9.cpp63
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Fence9.h19
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Image9.cpp654
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Image9.h43
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/IndexBuffer9.h2
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Query9.cpp2
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Query9.h4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/RenderTarget9.cpp165
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/RenderTarget9.h60
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp756
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h134
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/ShaderCache.h12
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/SwapChain9.cpp26
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/SwapChain9.h7
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.cpp377
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.h46
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/VertexArray9.h4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.cpp16
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/VertexBuffer9.h4
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/renderer9_utils.cpp28
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d9/renderer9_utils.h5
-rw-r--r--src/3rdparty/angle/src/libGLESv2/renderer/loadimageSSE2.cpp18
105 files changed, 10046 insertions, 4817 deletions
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/BufferImpl.h b/src/3rdparty/angle/src/libGLESv2/renderer/BufferImpl.h
index f0b5f02227..c031effabd 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/BufferImpl.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/BufferImpl.h
@@ -12,6 +12,8 @@
#include "common/angleutils.h"
#include "libGLESv2/Buffer.h"
+#include <cstdint>
+
namespace rx
{
@@ -21,7 +23,6 @@ class BufferImpl
virtual ~BufferImpl() { }
virtual gl::Error setData(const void* data, size_t size, GLenum usage) = 0;
- virtual void *getData() = 0;
virtual gl::Error setSubData(const void* data, size_t size, size_t offset) = 0;
virtual gl::Error copySubData(BufferImpl* source, GLintptr sourceOffset, GLintptr destOffset, GLsizeiptr size) = 0;
virtual gl::Error map(size_t offset, size_t length, GLbitfield access, GLvoid **mapPtr) = 0;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/FenceImpl.h b/src/3rdparty/angle/src/libGLESv2/renderer/FenceImpl.h
index d54e6becd3..1dd46785d9 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/FenceImpl.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/FenceImpl.h
@@ -4,29 +4,47 @@
// found in the LICENSE file.
//
-// FenceImpl.h: Defines the rx::FenceImpl class.
+// FenceImpl.h: Defines the rx::FenceNVImpl and rx::FenceSyncImpl classes.
#ifndef LIBGLESV2_RENDERER_FENCEIMPL_H_
#define LIBGLESV2_RENDERER_FENCEIMPL_H_
+#include "libGLESv2/Error.h"
+
#include "common/angleutils.h"
+#include "angle_gl.h"
+
namespace rx
{
-class FenceImpl
+class FenceNVImpl
+{
+ public:
+ FenceNVImpl() { };
+ virtual ~FenceNVImpl() { };
+
+ virtual gl::Error set() = 0;
+ virtual gl::Error test(bool flushCommandBuffer, GLboolean *outFinished) = 0;
+ virtual gl::Error finishFence(GLboolean *outFinished) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FenceNVImpl);
+};
+
+class FenceSyncImpl
{
public:
- FenceImpl() { };
- virtual ~FenceImpl() { };
+ FenceSyncImpl() { };
+ virtual ~FenceSyncImpl() { };
- virtual bool isSet() const = 0;
- virtual void set() = 0;
- virtual bool test(bool flushCommandBuffer) = 0;
- virtual bool hasError() const = 0;
+ virtual gl::Error set() = 0;
+ virtual gl::Error clientWait(GLbitfield flags, GLuint64 timeout, GLenum *outResult) = 0;
+ virtual gl::Error serverWait(GLbitfield flags, GLuint64 timeout) = 0;
+ virtual gl::Error getStatus(GLint *outResult) = 0;
private:
- DISALLOW_COPY_AND_ASSIGN(FenceImpl);
+ DISALLOW_COPY_AND_ASSIGN(FenceSyncImpl);
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/Image.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/Image.cpp
index 370b086233..5b9b75f562 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/Image.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/Image.cpp
@@ -4,18 +4,20 @@
// found in the LICENSE file.
//
-// Image.h: Implements the rx::Image class, an abstract base class for the
+// Image.h: Implements the rx::Image class, an abstract base class for the
// renderer-specific classes which will define the interface to the underlying
// surfaces or resources.
#include "libGLESv2/renderer/Image.h"
+#include "libGLESv2/Framebuffer.h"
+#include "libGLESv2/main.h"
namespace rx
{
Image::Image()
{
- mWidth = 0;
+ mWidth = 0;
mHeight = 0;
mDepth = 0;
mInternalFormat = GL_NONE;
@@ -25,4 +27,20 @@ Image::Image()
mDirty = false;
}
+gl::Error Image::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &area, gl::Framebuffer *source)
+{
+ gl::FramebufferAttachment *colorbuffer = source->getReadColorbuffer();
+ ASSERT(colorbuffer);
+
+ RenderTarget *renderTarget = NULL;
+ gl::Error error = GetAttachmentRenderTarget(colorbuffer, &renderTarget);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ ASSERT(renderTarget);
+ return copy(xoffset, yoffset, zoffset, area, renderTarget);
+}
+
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/Image.h b/src/3rdparty/angle/src/libGLESv2/renderer/Image.h
index 3bfc663762..9071a88c67 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/Image.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/Image.h
@@ -4,7 +4,7 @@
// found in the LICENSE file.
//
-// Image.h: Defines the rx::Image class, an abstract base class for the
+// Image.h: Defines the rx::Image class, an abstract base class for the
// renderer-specific classes which will define the interface to the underlying
// surfaces or resources.
@@ -12,18 +12,22 @@
#define LIBGLESV2_RENDERER_IMAGE_H_
#include "common/debug.h"
+#include "libGLESv2/Error.h"
#include <GLES2/gl2.h>
namespace gl
{
class Framebuffer;
+struct Rectangle;
+struct ImageIndex;
}
namespace rx
{
-
-class Renderer;
+class RendererD3D;
+class RenderTarget;
+class TextureStorage;
class Image
{
@@ -43,14 +47,17 @@ class Image
void markClean() {mDirty = false;}
virtual bool isDirty() const = 0;
- virtual bool redefine(Renderer *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease) = 0;
+ virtual bool redefine(RendererD3D *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease) = 0;
- virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- GLint unpackAlignment, GLenum type, const void *input) = 0;
- virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- const void *input) = 0;
+ virtual gl::Error loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ GLint unpackAlignment, GLenum type, const void *input) = 0;
+ virtual gl::Error loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ const void *input) = 0;
- virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source) = 0;
+ gl::Error copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea, gl::Framebuffer *source);
+ virtual gl::Error copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea, RenderTarget *source) = 0;
+ virtual gl::Error copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea,
+ const gl::ImageIndex &sourceIndex, TextureStorage *source) = 0;
protected:
GLsizei mWidth;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp
index f68ac383de..d472e1499e 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/IndexRangeCache.cpp
@@ -111,11 +111,7 @@ IndexRangeCache::IndexRange::IndexRange(GLenum typ, intptr_t off, GLsizei c)
bool IndexRangeCache::IndexRange::operator<(const IndexRange& rhs) const
{
-#if defined(_MSC_VER) && _MSC_VER < 1600
- return std::tr1::make_tuple(type, offset, count) < std::tr1::make_tuple(rhs.type, rhs.offset, rhs.count);
-#else
return std::make_tuple(type, offset, count) < std::make_tuple(rhs.type, rhs.offset, rhs.count);
-#endif
}
IndexRangeCache::IndexBounds::IndexBounds()
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.cpp
new file mode 100644
index 0000000000..f9fcad38a4
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.cpp
@@ -0,0 +1,146 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// ProgramD3D.cpp: Defines the rx::ProgramD3D class which implements rx::ProgramImpl.
+
+#include "libGLESv2/renderer/ProgramImpl.h"
+
+#include "common/utilities.h"
+#include "libGLESv2/main.h"
+
+namespace rx
+{
+
+namespace
+{
+
+unsigned int ParseAndStripArrayIndex(std::string* name)
+{
+ unsigned int subscript = GL_INVALID_INDEX;
+
+ // Strip any trailing array operator and retrieve the subscript
+ size_t open = name->find_last_of('[');
+ size_t close = name->find_last_of(']');
+ if (open != std::string::npos && close == name->length() - 1)
+ {
+ subscript = atoi(name->substr(open + 1).c_str());
+ name->erase(open);
+ }
+
+ return subscript;
+}
+
+}
+
+ProgramImpl::~ProgramImpl()
+{
+ // Ensure that reset was called by the inherited class during destruction
+ ASSERT(mUniformIndex.size() == 0);
+}
+
+gl::LinkedUniform *ProgramImpl::getUniformByLocation(GLint location) const
+{
+ ASSERT(location >= 0 && static_cast<size_t>(location) < mUniformIndex.size());
+ return mUniforms[mUniformIndex[location].index];
+}
+
+gl::LinkedUniform *ProgramImpl::getUniformByName(const std::string &name) const
+{
+ for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
+ {
+ if (mUniforms[uniformIndex]->name == name)
+ {
+ return mUniforms[uniformIndex];
+ }
+ }
+
+ return NULL;
+}
+
+gl::UniformBlock *ProgramImpl::getUniformBlockByIndex(GLuint blockIndex) const
+{
+ ASSERT(blockIndex < mUniformBlocks.size());
+ return mUniformBlocks[blockIndex];
+}
+
+GLint ProgramImpl::getUniformLocation(std::string name)
+{
+ unsigned int subscript = ParseAndStripArrayIndex(&name);
+
+ unsigned int numUniforms = mUniformIndex.size();
+ for (unsigned int location = 0; location < numUniforms; location++)
+ {
+ if (mUniformIndex[location].name == name)
+ {
+ const int index = mUniformIndex[location].index;
+ const bool isArray = mUniforms[index]->isArray();
+
+ if ((isArray && mUniformIndex[location].element == subscript) ||
+ (subscript == GL_INVALID_INDEX))
+ {
+ return location;
+ }
+ }
+ }
+
+ return -1;
+}
+
+GLuint ProgramImpl::getUniformIndex(std::string name)
+{
+ unsigned int subscript = ParseAndStripArrayIndex(&name);
+
+ // The app is not allowed to specify array indices other than 0 for arrays of basic types
+ if (subscript != 0 && subscript != GL_INVALID_INDEX)
+ {
+ return GL_INVALID_INDEX;
+ }
+
+ unsigned int numUniforms = mUniforms.size();
+ for (unsigned int index = 0; index < numUniforms; index++)
+ {
+ if (mUniforms[index]->name == name)
+ {
+ if (mUniforms[index]->isArray() || subscript == GL_INVALID_INDEX)
+ {
+ return index;
+ }
+ }
+ }
+
+ return GL_INVALID_INDEX;
+}
+
+GLuint ProgramImpl::getUniformBlockIndex(std::string name) const
+{
+ unsigned int subscript = ParseAndStripArrayIndex(&name);
+
+ unsigned int numUniformBlocks = mUniformBlocks.size();
+ for (unsigned int blockIndex = 0; blockIndex < numUniformBlocks; blockIndex++)
+ {
+ const gl::UniformBlock &uniformBlock = *mUniformBlocks[blockIndex];
+ if (uniformBlock.name == name)
+ {
+ const bool arrayElementZero = (subscript == GL_INVALID_INDEX && uniformBlock.elementIndex == 0);
+ if (subscript == uniformBlock.elementIndex || arrayElementZero)
+ {
+ return blockIndex;
+ }
+ }
+ }
+
+ return GL_INVALID_INDEX;
+}
+
+void ProgramImpl::reset()
+{
+ SafeDeleteContainer(mUniforms);
+ mUniformIndex.clear();
+ SafeDeleteContainer(mUniformBlocks);
+ mTransformFeedbackLinkedVaryings.clear();
+}
+
+}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.h b/src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.h
index ba0955fdf8..6aaa23cf89 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/ProgramImpl.h
@@ -13,44 +13,113 @@
#include "libGLESv2/BinaryStream.h"
#include "libGLESv2/Constants.h"
#include "libGLESv2/ProgramBinary.h"
+#include "libGLESv2/Shader.h"
+#include "libGLESv2/renderer/Renderer.h"
+
+#include <map>
namespace rx
{
-class DynamicHLSL;
-class Renderer;
-
class ProgramImpl
{
-public:
- virtual ~ProgramImpl() { }
+ public:
+ ProgramImpl() { }
+ virtual ~ProgramImpl();
+
+ const std::vector<gl::LinkedUniform*> &getUniforms() const { return mUniforms; }
+ const std::vector<gl::VariableLocation> &getUniformIndices() const { return mUniformIndex; }
+ const std::vector<gl::UniformBlock*> &getUniformBlocks() const { return mUniformBlocks; }
+ const std::vector<gl::LinkedVarying> &getTransformFeedbackLinkedVaryings() const { return mTransformFeedbackLinkedVaryings; }
+ const sh::Attribute *getShaderAttributes() const { return mShaderAttributes; }
+
+ std::vector<gl::LinkedUniform*> &getUniforms() { return mUniforms; }
+ std::vector<gl::VariableLocation> &getUniformIndices() { return mUniformIndex; }
+ std::vector<gl::UniformBlock*> &getUniformBlocks() { return mUniformBlocks; }
+ std::vector<gl::LinkedVarying> &getTransformFeedbackLinkedVaryings() { return mTransformFeedbackLinkedVaryings; }
+ sh::Attribute *getShaderAttributes() { return mShaderAttributes; }
+
+ gl::LinkedUniform *getUniformByLocation(GLint location) const;
+ gl::LinkedUniform *getUniformByName(const std::string &name) const;
+ gl::UniformBlock *getUniformBlockByIndex(GLuint blockIndex) const;
- // TODO: Temporary interfaces to ease migration. Remove soon!
- virtual Renderer *getRenderer() = 0;
- virtual DynamicHLSL *getDynamicHLSL() = 0;
- virtual const std::vector<rx::PixelShaderOutputVariable> &getPixelShaderKey() = 0;
+ GLint getUniformLocation(std::string name);
+ GLuint getUniformIndex(std::string name);
+ GLuint getUniformBlockIndex(std::string name) const;
+
+ virtual bool usesPointSize() const = 0;
+ virtual int getShaderVersion() const = 0;
+ virtual GLenum getTransformFeedbackBufferMode() const = 0;
virtual GLenum getBinaryFormat() = 0;
- virtual bool load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) = 0;
- virtual bool save(gl::BinaryOutputStream *stream) = 0;
-
- virtual rx::ShaderExecutable *getPixelExecutableForOutputLayout(gl::InfoLog &infoLog, const std::vector<GLenum> &outputSignature,
- const std::vector<gl::LinkedVarying> &transformFeedbackLinkedVaryings,
- bool separatedOutputBuffers) = 0;
- virtual rx::ShaderExecutable *getVertexExecutableForInputLayout(gl::InfoLog &infoLog,
- const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
- const sh::Attribute shaderAttributes[],
- const std::vector<gl::LinkedVarying> &transformFeedbackLinkedVaryings,
- bool separatedOutputBuffers) = 0;
-
- virtual bool link(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
- const std::vector<std::string> &transformFeedbackVaryings, int *registers,
- std::vector<gl::LinkedVarying> *linkedVaryings, std::map<int,
- gl::VariableLocation> *outputVariables) = 0;
-
- virtual void initializeUniformStorage(const std::vector<gl::LinkedUniform*> &uniforms) = 0;
-
- virtual void reset() = 0;
+ virtual gl::LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) = 0;
+ virtual gl::Error save(gl::BinaryOutputStream *stream) = 0;
+
+ virtual gl::LinkResult link(const gl::Data &data, gl::InfoLog &infoLog,
+ gl::Shader *fragmentShader, gl::Shader *vertexShader,
+ const std::vector<std::string> &transformFeedbackVaryings,
+ GLenum transformFeedbackBufferMode,
+ int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
+ std::map<int, gl::VariableLocation> *outputVariables) = 0;
+
+ virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0;
+ virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0;
+ virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0;
+ virtual void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) = 0;
+ virtual void setUniform1iv(GLint location, GLsizei count, const GLint *v) = 0;
+ virtual void setUniform2iv(GLint location, GLsizei count, const GLint *v) = 0;
+ virtual void setUniform3iv(GLint location, GLsizei count, const GLint *v) = 0;
+ virtual void setUniform4iv(GLint location, GLsizei count, const GLint *v) = 0;
+ virtual void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) = 0;
+ virtual void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) = 0;
+ virtual void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) = 0;
+ virtual void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) = 0;
+ virtual void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+ virtual void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
+
+ virtual void getUniformfv(GLint location, GLfloat *params) = 0;
+ virtual void getUniformiv(GLint location, GLint *params) = 0;
+ virtual void getUniformuiv(GLint location, GLuint *params) = 0;
+
+ virtual void reset();
+
+ // TODO: The following functions are possibly only applicable to D3D backends. The should be carefully evaluated to
+ // determine if they can be removed from this interface.
+ virtual GLint getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const = 0;
+ virtual GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const = 0;
+ virtual GLint getUsedSamplerRange(gl::SamplerType type) const = 0;
+ virtual void updateSamplerMapping() = 0;
+ virtual bool validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) = 0;
+
+ virtual gl::LinkResult compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
+ int registers) = 0;
+
+ virtual bool linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader,
+ const gl::Caps &caps) = 0;
+ virtual bool defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock,
+ const gl::Caps &caps) = 0;
+
+ virtual gl::Error applyUniforms() = 0;
+ virtual gl::Error applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const gl::Caps &caps) = 0;
+ virtual bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
+ unsigned int registerIndex, const gl::Caps &caps) = 0;
+
+ protected:
+ DISALLOW_COPY_AND_ASSIGN(ProgramImpl);
+
+ std::vector<gl::LinkedUniform*> mUniforms;
+ std::vector<gl::VariableLocation> mUniformIndex;
+ std::vector<gl::UniformBlock*> mUniformBlocks;
+ std::vector<gl::LinkedVarying> mTransformFeedbackLinkedVaryings;
+
+ sh::Attribute mShaderAttributes[gl::MAX_VERTEX_ATTRIBS];
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.cpp
new file mode 100644
index 0000000000..857fdc9dae
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.cpp
@@ -0,0 +1,36 @@
+//
+// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// RenderTarget.cpp: Implements serial handling for rx::RenderTarget
+
+#include "libGLESv2/renderer/RenderTarget.h"
+
+namespace rx
+{
+unsigned int RenderTarget::mCurrentSerial = 1;
+
+RenderTarget::RenderTarget()
+ : mSerial(issueSerials(1))
+{
+}
+
+RenderTarget::~RenderTarget()
+{
+}
+
+unsigned int RenderTarget::getSerial() const
+{
+ return mSerial;
+}
+
+unsigned int RenderTarget::issueSerials(unsigned int count)
+{
+ unsigned int firstSerial = mCurrentSerial;
+ mCurrentSerial += count;
+ return firstSerial;
+}
+
+}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.h b/src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.h
index 44637ec7de..3bdfb0cc98 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/RenderTarget.h
@@ -18,28 +18,22 @@ namespace rx
class RenderTarget
{
public:
- RenderTarget()
- {
- mWidth = 0;
- mHeight = 0;
- mDepth = 0;
- mInternalFormat = GL_NONE;
- mActualFormat = GL_NONE;
- mSamples = 0;
- }
+ RenderTarget();
+ virtual ~RenderTarget();
- virtual ~RenderTarget() {};
-
- GLsizei getWidth() const { return mWidth; }
- GLsizei getHeight() const { return mHeight; }
- GLsizei getDepth() const { return mDepth; }
- GLenum getInternalFormat() const { return mInternalFormat; }
- GLenum getActualFormat() const { return mActualFormat; }
- GLsizei getSamples() const { return mSamples; }
- gl::Extents getExtents() const { return gl::Extents(mWidth, mHeight, mDepth); }
+ virtual GLsizei getWidth() const = 0;
+ virtual GLsizei getHeight() const = 0;
+ virtual GLsizei getDepth() const = 0;
+ virtual GLenum getInternalFormat() const = 0;
+ virtual GLenum getActualFormat() const = 0;
+ virtual GLsizei getSamples() const = 0;
+ gl::Extents getExtents() const { return gl::Extents(getWidth(), getHeight(), getDepth()); }
virtual void invalidate(GLint x, GLint y, GLsizei width, GLsizei height) = 0;
+ virtual unsigned int getSerial() const;
+ static unsigned int issueSerials(unsigned int count);
+
struct Desc {
GLsizei width;
GLsizei height;
@@ -47,16 +41,11 @@ class RenderTarget
GLenum format;
};
- protected:
- GLsizei mWidth;
- GLsizei mHeight;
- GLsizei mDepth;
- GLenum mInternalFormat;
- GLenum mActualFormat;
- GLsizei mSamples;
-
private:
DISALLOW_COPY_AND_ASSIGN(RenderTarget);
+
+ const unsigned int mSerial;
+ static unsigned int mCurrentSerial;
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.cpp
new file mode 100644
index 0000000000..770ae8e9c6
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.cpp
@@ -0,0 +1,21 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// RenderbufferImpl.h: Implements the shared methods of the abstract class gl::RenderbufferImpl
+
+#include "libGLESv2/renderer/RenderbufferImpl.h"
+
+namespace rx
+{
+RenderbufferImpl::RenderbufferImpl()
+{
+}
+
+RenderbufferImpl::~RenderbufferImpl()
+{
+}
+
+}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.h b/src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.h
new file mode 100644
index 0000000000..52e070f1d3
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/RenderbufferImpl.h
@@ -0,0 +1,41 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// RenderbufferImpl.h: Defines the abstract class gl::RenderbufferImpl
+
+#ifndef LIBGLESV2_RENDERER_RENDERBUFFERIMPL_H_
+#define LIBGLESV2_RENDERER_RENDERBUFFERIMPL_H_
+
+#include "angle_gl.h"
+
+#include "libGLESv2/Error.h"
+
+#include "common/angleutils.h"
+
+namespace rx
+{
+
+class RenderbufferImpl
+{
+ public:
+ RenderbufferImpl();
+ virtual ~RenderbufferImpl() = 0;
+
+ virtual gl::Error setStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples) = 0;
+
+ virtual GLsizei getWidth() const = 0;
+ virtual GLsizei getHeight() const = 0;
+ virtual GLenum getInternalFormat() const = 0;
+ virtual GLenum getActualFormat() const = 0;
+ virtual GLsizei getSamples() const = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RenderbufferImpl);
+};
+
+}
+
+#endif // LIBGLESV2_RENDERER_RENDERBUFFERIMPL_H_
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.cpp
index 910d0285f1..df3dae1e38 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.cpp
@@ -6,11 +6,12 @@
// Renderer.cpp: Implements EGL dependencies for creating and destroying Renderer instances.
+#include "common/utilities.h"
+#include "libEGL/AttributeMap.h"
#include "libGLESv2/main.h"
-#include "libGLESv2/Program.h"
#include "libGLESv2/renderer/Renderer.h"
-#include "common/utilities.h"
-#include "libGLESv2/Shader.h"
+
+#include <EGL/eglext.h>
#if defined (ANGLE_ENABLE_D3D9)
#include "libGLESv2/renderer/d3d/d3d9/Renderer9.h"
@@ -29,15 +30,12 @@
#define ANGLE_DEFAULT_D3D11 0
#endif
-#include <EGL/eglext.h>
-
namespace rx
{
-Renderer::Renderer(egl::Display *display)
- : mDisplay(display),
- mCapsInitialized(false),
- mCurrentClientVersion(2)
+Renderer::Renderer()
+ : mCapsInitialized(false),
+ mWorkaroundsInitialized(false)
{
}
@@ -78,12 +76,23 @@ const gl::Extensions &Renderer::getRendererExtensions() const
return mExtensions;
}
-typedef Renderer *(*CreateRendererFunction)(egl::Display*, EGLNativeDisplayType, EGLint);
+const Workarounds &Renderer::getWorkarounds() const
+{
+ if (!mWorkaroundsInitialized)
+ {
+ mWorkarounds = generateWorkarounds();
+ mWorkaroundsInitialized = true;
+ }
+
+ return mWorkarounds;
+}
+
+typedef Renderer *(*CreateRendererFunction)(egl::Display*, EGLNativeDisplayType, const egl::AttributeMap &);
template <typename RendererType>
-Renderer *CreateRenderer(egl::Display *display, EGLNativeDisplayType nativeDisplay, EGLint requestedDisplayType)
+Renderer *CreateRenderer(egl::Display *display, EGLNativeDisplayType nativeDisplay, const egl::AttributeMap &attributes)
{
- return new RendererType(display, nativeDisplay, requestedDisplayType);
+ return new RendererType(display, nativeDisplay, attributes);
}
}
@@ -91,15 +100,16 @@ Renderer *CreateRenderer(egl::Display *display, EGLNativeDisplayType nativeDispl
extern "C"
{
-rx::Renderer *glCreateRenderer(egl::Display *display, EGLNativeDisplayType nativeDisplay, EGLint requestedDisplayType)
+rx::Renderer *glCreateRenderer(egl::Display *display, EGLNativeDisplayType nativeDisplay, const egl::AttributeMap &attribMap)
{
std::vector<rx::CreateRendererFunction> rendererCreationFunctions;
+ EGLint requestedDisplayType = attribMap.get(EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE);
+
# if defined(ANGLE_ENABLE_D3D11)
if (nativeDisplay == EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE ||
nativeDisplay == EGL_D3D11_ONLY_DISPLAY_ANGLE ||
- requestedDisplayType == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE ||
- requestedDisplayType == EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE)
+ requestedDisplayType == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
{
rendererCreationFunctions.push_back(rx::CreateRenderer<rx::Renderer11>);
}
@@ -138,7 +148,7 @@ rx::Renderer *glCreateRenderer(egl::Display *display, EGLNativeDisplayType nativ
for (size_t i = 0; i < rendererCreationFunctions.size(); i++)
{
- rx::Renderer *renderer = rendererCreationFunctions[i](display, nativeDisplay, requestedDisplayType);
+ rx::Renderer *renderer = rendererCreationFunctions[i](display, nativeDisplay, attribMap);
if (renderer->initialize() == EGL_SUCCESS)
{
return renderer;
@@ -155,7 +165,8 @@ rx::Renderer *glCreateRenderer(egl::Display *display, EGLNativeDisplayType nativ
void glDestroyRenderer(rx::Renderer *renderer)
{
- delete renderer;
+ ASSERT(renderer);
+ SafeDelete(renderer);
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.h b/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.h
index b2249741ab..b85895a938 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/Renderer.h
@@ -10,10 +10,13 @@
#ifndef LIBGLESV2_RENDERER_RENDERER_H_
#define LIBGLESV2_RENDERER_RENDERER_H_
-#include "libGLESv2/Uniform.h"
-#include "libGLESv2/angletypes.h"
#include "libGLESv2/Caps.h"
#include "libGLESv2/Error.h"
+#include "libGLESv2/Uniform.h"
+#include "libGLESv2/angletypes.h"
+#include "libGLESv2/renderer/Workarounds.h"
+#include "common/NativeWindow.h"
+#include "common/mathutil.h"
#include <cstdint>
@@ -32,37 +35,26 @@ class Display;
namespace gl
{
-class InfoLog;
-class ProgramBinary;
-struct LinkedVarying;
-struct VertexAttribute;
class Buffer;
-class Texture;
class Framebuffer;
-struct VertexAttribCurrentValueData;
+struct Data;
}
namespace rx
{
-class TextureStorage;
-class VertexBuffer;
-class IndexBuffer;
class QueryImpl;
-class FenceImpl;
+class FenceNVImpl;
+class FenceSyncImpl;
class BufferImpl;
class VertexArrayImpl;
-class BufferStorage;
-struct TranslatedIndexData;
class ShaderImpl;
class ProgramImpl;
-class ShaderExecutable;
-class SwapChain;
-class RenderTarget;
-class Image;
-class TextureStorage;
-class UniformStorage;
class TextureImpl;
class TransformFeedbackImpl;
+class RenderbufferImpl;
+struct TranslatedIndexData;
+struct Workarounds;
+class SwapChain;
struct ConfigDesc
{
@@ -73,30 +65,10 @@ struct ConfigDesc
bool es3Capable;
};
-struct dx_VertexConstants
-{
- float depthRange[4];
- float viewAdjust[4];
-};
-
-struct dx_PixelConstants
-{
- float depthRange[4];
- float viewCoords[4];
- float depthFront[4];
-};
-
-enum ShaderType
-{
- SHADER_VERTEX,
- SHADER_PIXEL,
- SHADER_GEOMETRY
-};
-
class Renderer
{
public:
- explicit Renderer(egl::Display *display);
+ Renderer();
virtual ~Renderer();
virtual EGLint initialize() = 0;
@@ -105,163 +77,116 @@ class Renderer
virtual int generateConfigs(ConfigDesc **configDescList) = 0;
virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
- virtual void sync(bool block) = 0;
-
- virtual SwapChain *createSwapChain(EGLNativeWindowType window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
+ virtual gl::Error sync(bool block) = 0;
- virtual gl::Error generateSwizzle(gl::Texture *texture) = 0;
- virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
- virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
+ virtual gl::Error drawArrays(const gl::Data &data, GLenum mode,
+ GLint first, GLsizei count, GLsizei instances) = 0;
+ virtual gl::Error drawElements(const gl::Data &data, GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices, GLsizei instances,
+ const RangeUI &indexRange) = 0;
- virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0;
+ virtual gl::Error clear(const gl::Data &data, GLbitfield mask) = 0;
+ virtual gl::Error clearBufferfv(const gl::Data &data, GLenum buffer, GLint drawbuffer, const GLfloat *values) = 0;
+ virtual gl::Error clearBufferuiv(const gl::Data &data, GLenum buffer, GLint drawbuffer, const GLuint *values) = 0;
+ virtual gl::Error clearBufferiv(const gl::Data &data, GLenum buffer, GLint drawbuffer, const GLint *values) = 0;
+ virtual gl::Error clearBufferfi(const gl::Data &data, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) = 0;
- virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState) = 0;
- virtual gl::Error setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
- unsigned int sampleMask) = 0;
- virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
- int stencilBackRef, bool frontFaceCCW) = 0;
+ virtual gl::Error readPixels(const gl::Data &data, GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLsizei *bufSize, void* pixels) = 0;
- virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
- virtual void setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
- bool ignoreViewport) = 0;
-
- virtual gl::Error applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
- virtual gl::Error applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
- bool rasterizerDiscard, bool transformFeedbackActive) = 0;
- virtual gl::Error applyUniforms(const gl::ProgramBinary &programBinary) = 0;
- virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
- virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances) = 0;
- virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
- virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) = 0;
-
- virtual gl::Error drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) = 0;
- virtual gl::Error drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
- gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
-
- virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
-
- virtual void markAllStateDirty() = 0;
-
- // lost device
- virtual void notifyDeviceLost() = 0;
- virtual bool isDeviceLost() = 0;
- virtual bool testDeviceLost(bool notify) = 0;
- virtual bool testDeviceResettable() = 0;
-
- // Renderer capabilities (virtual because it is used by egl::Display, do not override)
- virtual const gl::Caps &getRendererCaps() const;
- virtual const gl::TextureCapsMap &getRendererTextureCaps() const;
- virtual const gl::Extensions &getRendererExtensions() const;
-
- virtual DWORD getAdapterVendor() const = 0;
- virtual std::string getRendererDescription() const = 0;
- virtual GUID getAdapterIdentifier() const = 0;
+ virtual gl::Error blitFramebuffer(const gl::Data &data,
+ GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ GLbitfield mask, GLenum filter) = 0;
- virtual unsigned int getReservedVertexUniformVectors() const = 0;
- virtual unsigned int getReservedFragmentUniformVectors() const = 0;
- virtual unsigned int getReservedVertexUniformBuffers() const = 0;
- virtual unsigned int getReservedFragmentUniformBuffers() const = 0;
+ // TODO(jmadill): caps? and virtual for egl::Display
virtual bool getShareHandleSupport() const = 0;
virtual bool getPostSubBufferSupport() const = 0;
- virtual int getMajorShaderModel() const = 0;
- virtual int getMinSwapInterval() const = 0;
- virtual int getMaxSwapInterval() const = 0;
-
- // Pixel operations
- virtual bool copyToRenderTarget2D(TextureStorage *dest, TextureStorage *source) = 0;
- virtual bool copyToRenderTargetCube(TextureStorage *dest, TextureStorage *source) = 0;
- virtual bool copyToRenderTarget3D(TextureStorage *dest, TextureStorage *source) = 0;
- virtual bool copyToRenderTarget2DArray(TextureStorage *dest, TextureStorage *source) = 0;
-
- virtual bool copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level) = 0;
- virtual bool copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level) = 0;
- virtual bool copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level) = 0;
- virtual bool copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level) = 0;
-
- virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
- const gl::Rectangle *scissor, bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter) = 0;
-
- virtual gl::Error readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
- GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels) = 0;
-
- // RenderTarget creation
- virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
- virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples) = 0;
-
// Shader creation
- virtual ShaderImpl *createShader(GLenum type) = 0;
+ virtual ShaderImpl *createShader(const gl::Data &data, GLenum type) = 0;
virtual ProgramImpl *createProgram() = 0;
// Shader operations
virtual void releaseShaderCompiler() = 0;
- virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type,
- const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
- bool separatedOutputBuffers) = 0;
- virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type,
- const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
- bool separatedOutputBuffers, D3DWorkaroundType workaround) = 0;
- virtual UniformStorage *createUniformStorage(size_t storageSize) = 0;
-
- // Image operations
- virtual Image *createImage() = 0;
- virtual void generateMipmap(Image *dest, Image *source) = 0;
- virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
- virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels) = 0;
- virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels) = 0;
- virtual TextureStorage *createTextureStorage3D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
- virtual TextureStorage *createTextureStorage2DArray(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
// Texture creation
virtual TextureImpl *createTexture(GLenum target) = 0;
+ // Renderbuffer creation
+ virtual RenderbufferImpl *createRenderbuffer() = 0;
+ virtual RenderbufferImpl *createRenderbuffer(SwapChain *swapChain, bool depth) = 0;
+
// Buffer creation
virtual BufferImpl *createBuffer() = 0;
- virtual VertexBuffer *createVertexBuffer() = 0;
- virtual IndexBuffer *createIndexBuffer() = 0;
// Vertex Array creation
virtual VertexArrayImpl *createVertexArray() = 0;
// Query and Fence creation
virtual QueryImpl *createQuery(GLenum type) = 0;
- virtual FenceImpl *createFence() = 0;
+ virtual FenceNVImpl *createFenceNV() = 0;
+ virtual FenceSyncImpl *createFenceSync() = 0;
// Transform Feedback creation
- virtual TransformFeedbackImpl* createTransformFeedback() = 0;
+ virtual TransformFeedbackImpl *createTransformFeedback() = 0;
- // Current GLES client version
- void setCurrentClientVersion(int clientVersion) { mCurrentClientVersion = clientVersion; }
- int getCurrentClientVersion() const { return mCurrentClientVersion; }
+ // lost device
+ //TODO(jmadill): investigate if this stuff is necessary in GL
+ virtual void notifyDeviceLost() = 0;
+ virtual bool isDeviceLost() = 0;
+ virtual bool testDeviceLost(bool notify) = 0;
+ virtual bool testDeviceResettable() = 0;
- // Buffer-to-texture and Texture-to-buffer copies
- virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const = 0;
- virtual bool fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
- GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
+ virtual DWORD getAdapterVendor() const = 0;
+ virtual std::string getRendererDescription() const = 0;
+ virtual GUID getAdapterIdentifier() const = 0;
- virtual bool getLUID(LUID *adapterLuid) const = 0;
- virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const = 0;
- virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const = 0;
+ // Renderer capabilities (virtual because of egl::Display)
+ virtual const gl::Caps &getRendererCaps() const;
+ const gl::TextureCapsMap &getRendererTextureCaps() const;
+ virtual const gl::Extensions &getRendererExtensions() const;
+ const Workarounds &getWorkarounds() const;
- protected:
- egl::Display *mDisplay;
+ // TODO(jmadill): needed by egl::Display, probably should be removed
+ virtual int getMajorShaderModel() const = 0;
+ virtual int getMinSwapInterval() const = 0;
+ virtual int getMaxSwapInterval() const = 0;
+ virtual bool getLUID(LUID *adapterLuid) const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Renderer);
virtual void generateCaps(gl::Caps *outCaps, gl::TextureCapsMap* outTextureCaps, gl::Extensions *outExtensions) const = 0;
+ virtual Workarounds generateWorkarounds() const = 0;
mutable bool mCapsInitialized;
mutable gl::Caps mCaps;
mutable gl::TextureCapsMap mTextureCaps;
mutable gl::Extensions mExtensions;
- int mCurrentClientVersion;
+ mutable bool mWorkaroundsInitialized;
+ mutable Workarounds mWorkarounds;
+};
+
+struct dx_VertexConstants
+{
+ float depthRange[4];
+ float viewAdjust[4];
+};
+
+struct dx_PixelConstants
+{
+ float depthRange[4];
+ float viewCoords[4];
+ float depthFront[4];
+};
+
+enum ShaderType
+{
+ SHADER_VERTEX,
+ SHADER_PIXEL,
+ SHADER_GEOMETRY
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/ShaderExecutable.h b/src/3rdparty/angle/src/libGLESv2/renderer/ShaderExecutable.h
index f17195673d..f1a96d74fb 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/ShaderExecutable.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/ShaderExecutable.h
@@ -40,10 +40,21 @@ class ShaderExecutable
return mFunctionBuffer.size();
}
+ const std::string &getDebugInfo() const
+ {
+ return mDebugInfo;
+ }
+
+ void appendDebugInfo(const std::string &info)
+ {
+ mDebugInfo += info;
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(ShaderExecutable);
std::vector<uint8_t> mFunctionBuffer;
+ std::string mDebugInfo;
};
class UniformStorage
@@ -64,4 +75,4 @@ class UniformStorage
}
-#endif // LIBGLESV2_RENDERER_SHADEREXECUTABLE9_H_
+#endif // LIBGLESV2_RENDERER_SHADEREXECUTABLE_H_
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/ShaderImpl.h b/src/3rdparty/angle/src/libGLESv2/renderer/ShaderImpl.h
index de5d30e6fe..cb0d360f0b 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/ShaderImpl.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/ShaderImpl.h
@@ -23,9 +23,10 @@ class ShaderImpl
ShaderImpl() { }
virtual ~ShaderImpl() { }
- virtual bool compile(const std::string &source) = 0;
+ virtual bool compile(const gl::Data &data, const std::string &source) = 0;
virtual const std::string &getInfoLog() const = 0;
virtual const std::string &getTranslatedSource() const = 0;
+ virtual std::string getDebugInfo() const = 0;
const std::vector<gl::PackedVarying> &getVaryings() const { return mVaryings; }
const std::vector<sh::Uniform> &getUniforms() const { return mUniforms; }
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/SwapChain.h b/src/3rdparty/angle/src/libGLESv2/renderer/SwapChain.h
index 1ec702f299..1417e0bdf6 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/SwapChain.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/SwapChain.h
@@ -11,28 +11,24 @@
#define LIBGLESV2_RENDERER_SWAPCHAIN_H_
#include "common/angleutils.h"
+#include "common/NativeWindow.h"
#include "common/platform.h"
#include <GLES2/gl2.h>
#include <EGL/egl.h>
-#include <EGL/eglplatform.h>
+
+#if !defined(ANGLE_FORCE_VSYNC_OFF)
+#define ANGLE_FORCE_VSYNC_OFF 0
+#endif
namespace rx
{
-enum SwapFlags
-{
- SWAP_NORMAL = 0,
- SWAP_ROTATE_90 = 1,
- SWAP_ROTATE_270 = 2,
- SWAP_ROTATE_180 = SWAP_ROTATE_90|SWAP_ROTATE_270,
-};
-
class SwapChain
{
public:
- SwapChain(EGLNativeWindowType window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat)
- : mWindow(window), mShareHandle(shareHandle), mBackBufferFormat(backBufferFormat), mDepthBufferFormat(depthBufferFormat)
+ SwapChain(rx::NativeWindow nativeWindow, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat)
+ : mNativeWindow(nativeWindow), mShareHandle(shareHandle), mBackBufferFormat(backBufferFormat), mDepthBufferFormat(depthBufferFormat)
{
}
@@ -40,13 +36,16 @@ class SwapChain
virtual EGLint resize(EGLint backbufferWidth, EGLint backbufferSize) = 0;
virtual EGLint reset(EGLint backbufferWidth, EGLint backbufferHeight, EGLint swapInterval) = 0;
- virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height, EGLint flags) = 0;
+ virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height) = 0;
virtual void recreate() = 0;
+ GLenum GetBackBufferInternalFormat() const { return mBackBufferFormat; }
+ GLenum GetDepthBufferInternalFormat() const { return mDepthBufferFormat; }
+
virtual HANDLE getShareHandle() {return mShareHandle;};
protected:
- const EGLNativeWindowType mWindow; // Window that the surface is created for.
+ rx::NativeWindow mNativeWindow; // Handler for the Window that the surface is created for.
const GLenum mBackBufferFormat;
const GLenum mDepthBufferFormat;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/TextureImpl.h b/src/3rdparty/angle/src/libGLESv2/renderer/TextureImpl.h
index e3cc50d680..3e662557e4 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/TextureImpl.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/TextureImpl.h
@@ -10,6 +10,7 @@
#define LIBGLESV2_RENDERER_TEXTUREIMPL_H_
#include "common/angleutils.h"
+#include "libGLESv2/Error.h"
#include "angle_gl.h"
@@ -31,19 +32,12 @@ namespace rx
{
class Image;
-class Renderer;
-class TextureStorage;
class TextureImpl
{
public:
virtual ~TextureImpl() {};
- // TODO: If this methods could go away that would be ideal;
- // TextureStorage should only be necessary for the D3D backend, and as such
- // higher level code should not rely on it.
- virtual TextureStorage *getNativeTexture() = 0;
-
// Deprecated in favour of the ImageIndex method
virtual Image *getImage(int level, int layer) const = 0;
virtual Image *getImage(const gl::ImageIndex &index) const = 0;
@@ -51,15 +45,15 @@ class TextureImpl
virtual void setUsage(GLenum usage) = 0;
- virtual void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels) = 0;
- virtual void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) = 0;
- virtual void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels) = 0;
- virtual void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels) = 0;
- virtual void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source) = 0;
- virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source) = 0;
- virtual void storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) = 0;
+ virtual gl::Error setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels) = 0;
+ virtual gl::Error setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels) = 0;
+ virtual gl::Error subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels) = 0;
+ virtual gl::Error subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels) = 0;
+ virtual gl::Error copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source) = 0;
+ virtual gl::Error copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source) = 0;
+ virtual gl::Error storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) = 0;
- virtual void generateMipmaps() = 0;
+ virtual gl::Error generateMipmaps() = 0;
virtual void bindTexImage(egl::Surface *surface) = 0;
virtual void releaseTexImage() = 0;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/Workarounds.h b/src/3rdparty/angle/src/libGLESv2/renderer/Workarounds.h
new file mode 100644
index 0000000000..20a166fb7a
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/Workarounds.h
@@ -0,0 +1,39 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// angletypes.h: Workarounds for driver bugs and other issues.
+
+#ifndef LIBGLESV2_RENDERER_WORKAROUNDS_H_
+#define LIBGLESV2_RENDERER_WORKAROUNDS_H_
+
+// TODO(jmadill,zmo,geofflang): make a workarounds library that can operate
+// independent of ANGLE's renderer. Workarounds should also be accessible
+// outside of the Renderer.
+
+namespace rx
+{
+
+enum D3DWorkaroundType
+{
+ ANGLE_D3D_WORKAROUND_NONE,
+ ANGLE_D3D_WORKAROUND_SKIP_OPTIMIZATION,
+ ANGLE_D3D_WORKAROUND_MAX_OPTIMIZATION
+};
+
+struct Workarounds
+{
+ Workarounds()
+ : mrtPerfWorkaround(false),
+ setDataFasterThanImageUpload(false)
+ {}
+
+ bool mrtPerfWorkaround;
+ bool setDataFasterThanImageUpload;
+};
+
+}
+
+#endif // LIBGLESV2_RENDERER_WORKAROUNDS_H_
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/copyimage.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/copyimage.cpp
index 004223d70f..aabc9f04e9 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/copyimage.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/copyimage.cpp
@@ -6,7 +6,7 @@
// copyimage.cpp: Defines image copying functions
-#include "libGLESv2/renderer/copyImage.h"
+#include "libGLESv2/renderer/copyimage.h"
namespace rx
{
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.cpp
index a34ef03fb8..dd0d3f52ad 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.cpp
@@ -9,7 +9,6 @@
#include "libGLESv2/renderer/d3d/BufferD3D.h"
#include "libGLESv2/renderer/d3d/VertexBuffer.h"
#include "libGLESv2/renderer/d3d/IndexBuffer.h"
-#include "libGLESv2/renderer/Renderer.h"
#include "libGLESv2/main.h"
namespace rx
@@ -37,6 +36,13 @@ BufferD3D *BufferD3D::makeBufferD3D(BufferImpl *buffer)
return static_cast<BufferD3D*>(buffer);
}
+BufferD3D *BufferD3D::makeFromBuffer(gl::Buffer *buffer)
+{
+ BufferImpl *impl = buffer->getImplementation();
+ ASSERT(impl);
+ return makeBufferD3D(impl);
+}
+
void BufferD3D::updateSerial()
{
mSerial = mNextSerial++;
@@ -46,11 +52,11 @@ void BufferD3D::initializeStaticData()
{
if (!mStaticVertexBuffer)
{
- mStaticVertexBuffer = new rx::StaticVertexBufferInterface(getRenderer());
+ mStaticVertexBuffer = new StaticVertexBufferInterface(getRenderer());
}
if (!mStaticIndexBuffer)
{
- mStaticIndexBuffer = new rx::StaticIndexBufferInterface(getRenderer());
+ mStaticIndexBuffer = new StaticIndexBufferInterface(getRenderer());
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.h
index 44f14cee58..1a1308c545 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/BufferD3D.h
@@ -12,10 +12,11 @@
#include "libGLESv2/renderer/BufferImpl.h"
#include "libGLESv2/angletypes.h"
+#include <cstdint>
+
namespace rx
{
-
-class Renderer;
+class RendererD3D;
class StaticIndexBufferInterface;
class StaticVertexBufferInterface;
@@ -26,15 +27,17 @@ class BufferD3D : public BufferImpl
virtual ~BufferD3D();
static BufferD3D *makeBufferD3D(BufferImpl *buffer);
+ static BufferD3D *makeFromBuffer(gl::Buffer *buffer);
unsigned int getSerial() const { return mSerial; }
+ virtual gl::Error getData(const uint8_t **outData) = 0;
virtual size_t getSize() const = 0;
virtual bool supportsDirectBinding() const = 0;
- virtual Renderer* getRenderer() = 0;
+ virtual RendererD3D *getRenderer() = 0;
- rx::StaticVertexBufferInterface *getStaticVertexBuffer() { return mStaticVertexBuffer; }
- rx::StaticIndexBufferInterface *getStaticIndexBuffer() { return mStaticIndexBuffer; }
+ StaticVertexBufferInterface *getStaticVertexBuffer() { return mStaticVertexBuffer; }
+ StaticIndexBufferInterface *getStaticIndexBuffer() { return mStaticIndexBuffer; }
void initializeStaticData();
void invalidateStaticData();
@@ -46,8 +49,8 @@ class BufferD3D : public BufferImpl
void updateSerial();
- rx::StaticVertexBufferInterface *mStaticVertexBuffer;
- rx::StaticIndexBufferInterface *mStaticIndexBuffer;
+ StaticVertexBufferInterface *mStaticVertexBuffer;
+ StaticIndexBufferInterface *mStaticIndexBuffer;
unsigned int mUnmodifiedDataUse;
};
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp
index 13411ebe64..3d5bfe0cbe 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.cpp
@@ -8,10 +8,10 @@
#include "libGLESv2/renderer/d3d/DynamicHLSL.h"
#include "libGLESv2/renderer/d3d/ShaderD3D.h"
-#include "libGLESv2/renderer/Renderer.h"
-#include "libGLESv2/Shader.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
#include "libGLESv2/Program.h"
#include "libGLESv2/ProgramBinary.h"
+#include "libGLESv2/Shader.h"
#include "libGLESv2/formatutils.h"
#include "common/utilities.h"
@@ -22,6 +22,9 @@ META_ASSERT(GL_INVALID_INDEX == UINT_MAX);
using namespace gl;
+namespace rx
+{
+
namespace
{
@@ -70,7 +73,7 @@ std::string HLSLTypeString(GLenum type)
return HLSLComponentTypeString(gl::VariableComponentType(type), gl::VariableComponentCount(type));
}
-const rx::PixelShaderOutputVariable &GetOutputAtLocation(const std::vector<rx::PixelShaderOutputVariable> &outputVariables,
+const PixelShaderOutputVariable &GetOutputAtLocation(const std::vector<PixelShaderOutputVariable> &outputVariables,
unsigned int location)
{
for (size_t variableIndex = 0; variableIndex < outputVariables.size(); ++variableIndex)
@@ -85,15 +88,12 @@ const rx::PixelShaderOutputVariable &GetOutputAtLocation(const std::vector<rx::P
return outputVariables[0];
}
-}
-
-namespace rx
-{
-
const std::string VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@";
const std::string PIXEL_OUTPUT_STUB_STRING = "@@ PIXEL OUTPUT @@";
-DynamicHLSL::DynamicHLSL(rx::Renderer *const renderer)
+}
+
+DynamicHLSL::DynamicHLSL(RendererD3D *const renderer)
: mRenderer(renderer)
{
}
@@ -225,8 +225,8 @@ static bool packVarying(PackedVarying *varying, const int maxVaryingVectors, Var
// Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
// Returns the number of used varying registers, or -1 if unsuccesful
-int DynamicHLSL::packVaryings(InfoLog &infoLog, VaryingPacking packing, rx::ShaderD3D *fragmentShader,
- rx::ShaderD3D *vertexShader, const std::vector<std::string>& transformFeedbackVaryings)
+int DynamicHLSL::packVaryings(InfoLog &infoLog, VaryingPacking packing, ShaderD3D *fragmentShader,
+ ShaderD3D *vertexShader, const std::vector<std::string> &transformFeedbackVaryings)
{
// TODO (geofflang): Use context's caps
const int maxVaryingVectors = mRenderer->getRendererCaps().maxVaryingVectors;
@@ -262,6 +262,13 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog, VaryingPacking packing, rx::Shad
for (unsigned int feedbackVaryingIndex = 0; feedbackVaryingIndex < transformFeedbackVaryings.size(); feedbackVaryingIndex++)
{
const std::string &transformFeedbackVarying = transformFeedbackVaryings[feedbackVaryingIndex];
+
+ if (transformFeedbackVarying == "gl_Position" || transformFeedbackVarying == "gl_PointSize")
+ {
+ // do not pack builtin XFB varyings
+ continue;
+ }
+
if (packedVaryings.find(transformFeedbackVarying) == packedVaryings.end())
{
bool found = false;
@@ -281,7 +288,7 @@ int DynamicHLSL::packVaryings(InfoLog &infoLog, VaryingPacking packing, rx::Shad
}
}
- if (!found && transformFeedbackVarying != "gl_Position" && transformFeedbackVarying != "gl_PointSize")
+ if (!found)
{
infoLog.append("Transform feedback varying %s does not exist in the vertex shader.", transformFeedbackVarying.c_str());
return -1;
@@ -400,7 +407,7 @@ std::string DynamicHLSL::generateVertexShaderForInputLayout(const std::string &s
// data reinterpretation (eg for pure integer->float, float->pure integer)
// TODO: issue warning with gl debug info extension, when supported
if (IsMatrixType(shaderAttribute.type) ||
- (mRenderer->getVertexConversionType(vertexFormat) & rx::VERTEX_CONVERT_GPU) != 0)
+ (mRenderer->getVertexConversionType(vertexFormat) & VERTEX_CONVERT_GPU) != 0)
{
initHLSL += generateAttributeConversionHLSL(vertexFormat, shaderAttribute);
}
@@ -639,7 +646,7 @@ void DynamicHLSL::storeBuiltinLinkedVaryings(const SemanticInfo &info,
}
}
-void DynamicHLSL::storeUserLinkedVaryings(const rx::ShaderD3D *vertexShader,
+void DynamicHLSL::storeUserLinkedVaryings(const ShaderD3D *vertexShader,
std::vector<LinkedVarying> *linkedVaryings) const
{
const std::string &varyingSemantic = getVaryingSemantic(vertexShader->mUsesPointSize);
@@ -662,10 +669,11 @@ void DynamicHLSL::storeUserLinkedVaryings(const rx::ShaderD3D *vertexShader,
}
}
-bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const VaryingPacking packing,
- std::string& pixelHLSL, std::string& vertexHLSL,
- rx::ShaderD3D *fragmentShader, rx::ShaderD3D *vertexShader,
- const std::vector<std::string>& transformFeedbackVaryings,
+bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, InfoLog &infoLog, int registers,
+ const VaryingPacking packing,
+ std::string &pixelHLSL, std::string &vertexHLSL,
+ ShaderD3D *fragmentShader, ShaderD3D *vertexShader,
+ const std::vector<std::string> &transformFeedbackVaryings,
std::vector<LinkedVarying> *linkedVaryings,
std::map<int, VariableLocation> *programOutputVars,
std::vector<PixelShaderOutputVariable> *outPixelShaderKey,
@@ -691,21 +699,17 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
// Write the HLSL input/output declarations
const int shaderModel = mRenderer->getMajorShaderModel();
-
- // TODO (geofflang): Use context's caps
- const int maxVaryingVectors = mRenderer->getRendererCaps().maxVaryingVectors;
-
const int registersNeeded = registers + (usesFragCoord ? 1 : 0) + (usesPointCoord ? 1 : 0);
// Two cases when writing to gl_FragColor and using ESSL 1.0:
// - with a 3.0 context, the output color is copied to channel 0
// - with a 2.0 context, the output color is broadcast to all channels
- const bool broadcast = (fragmentShader->mUsesFragColor && mRenderer->getCurrentClientVersion() < 3);
- const unsigned int numRenderTargets = (broadcast || usesMRT ? mRenderer->getRendererCaps().maxDrawBuffers : 1);
+ const bool broadcast = (fragmentShader->mUsesFragColor && data.clientVersion < 3);
+ const unsigned int numRenderTargets = (broadcast || usesMRT ? data.caps->maxDrawBuffers : 1);
int shaderVersion = vertexShader->getShaderVersion();
- if (registersNeeded > maxVaryingVectors)
+ if (static_cast<GLuint>(registersNeeded) > data.caps->maxVaryingVectors)
{
infoLog.append("No varying registers left to support gl_FragCoord/gl_PointCoord");
return false;
@@ -772,7 +776,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
for (int row = 0; row < variableRows; row++)
{
- int r = varying.registerIndex + varying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors + elementIndex * variableRows + row;
+ int r = varying.registerIndex + varying.columnIndex * data.caps->maxVaryingVectors + elementIndex * variableRows + row;
vertexHLSL += " output.v" + Str(r);
vertexHLSL += " = _" + varying.name;
@@ -920,7 +924,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
int variableRows = (varying.isStruct() ? 1 : VariableRowCount(transposedType));
for (int row = 0; row < variableRows; row++)
{
- std::string n = Str(varying.registerIndex + varying.columnIndex * mRenderer->getRendererCaps().maxVaryingVectors + elementIndex * variableRows + row);
+ std::string n = Str(varying.registerIndex + varying.columnIndex * data.caps->maxVaryingVectors + elementIndex * variableRows + row);
pixelHLSL += " _" + varying.name;
if (varying.isArray())
@@ -966,7 +970,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const
return true;
}
-void DynamicHLSL::defineOutputVariables(rx::ShaderD3D *fragmentShader, std::map<int, VariableLocation> *programOutputVars) const
+void DynamicHLSL::defineOutputVariables(ShaderD3D *fragmentShader, std::map<int, VariableLocation> *programOutputVars) const
{
const std::vector<sh::Attribute> &shaderOutputVars = fragmentShader->getActiveOutputVariables();
@@ -994,14 +998,14 @@ void DynamicHLSL::defineOutputVariables(rx::ShaderD3D *fragmentShader, std::map<
}
}
-std::string DynamicHLSL::generateGeometryShaderHLSL(int registers, rx::ShaderD3D *fragmentShader, rx::ShaderD3D *vertexShader) const
+std::string DynamicHLSL::generateGeometryShaderHLSL(int registers, ShaderD3D *fragmentShader, ShaderD3D *vertexShader) const
{
// for now we only handle point sprite emulation
ASSERT(vertexShader->mUsesPointSize && mRenderer->getMajorShaderModel() >= 4);
return generatePointSpriteHLSL(registers, fragmentShader, vertexShader);
}
-std::string DynamicHLSL::generatePointSpriteHLSL(int registers, rx::ShaderD3D *fragmentShader, rx::ShaderD3D *vertexShader) const
+std::string DynamicHLSL::generatePointSpriteHLSL(int registers, ShaderD3D *fragmentShader, ShaderD3D *vertexShader) const
{
ASSERT(registers >= 0);
ASSERT(vertexShader->mUsesPointSize);
@@ -1047,7 +1051,7 @@ std::string DynamicHLSL::generatePointSpriteHLSL(int registers, rx::ShaderD3D *f
"void main(point GS_INPUT input[1], inout TriangleStream<GS_OUTPUT> outStream)\n"
"{\n"
" GS_OUTPUT output = (GS_OUTPUT)0;\n"
- " output.gl_Position = input[0].gl_Position;\n";
+ " output.gl_Position = input[0].gl_Position;\n"
" output.gl_PointSize = input[0].gl_PointSize;\n";
for (int r = 0; r < registers; r++)
@@ -1135,7 +1139,7 @@ void DynamicHLSL::getInputLayoutSignature(const VertexFormat inputLayout[], GLen
}
else
{
- bool gpuConverted = ((mRenderer->getVertexConversionType(vertexFormat) & rx::VERTEX_CONVERT_GPU) != 0);
+ bool gpuConverted = ((mRenderer->getVertexConversionType(vertexFormat) & VERTEX_CONVERT_GPU) != 0);
signature[inputIndex] = (gpuConverted ? GL_TRUE : GL_FALSE);
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.h
index f68ed98401..c46bbf6ce0 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/DynamicHLSL.h
@@ -10,18 +10,13 @@
#define LIBGLESV2_RENDERER_DYNAMIC_HLSL_H_
#include "common/angleutils.h"
-#include "libGLESv2/constants.h"
+#include "libGLESv2/Constants.h"
#include "angle_gl.h"
#include <vector>
#include <map>
-namespace rx
-{
-class Renderer;
-}
-
namespace sh
{
struct Attribute;
@@ -36,11 +31,12 @@ struct LinkedVarying;
struct VertexAttribute;
struct VertexFormat;
struct PackedVarying;
+struct Data;
}
namespace rx
{
-class Renderer;
+class RendererD3D;
class ShaderD3D;
typedef const gl::PackedVarying *VaryingPacking[gl::IMPLEMENTATION_MAX_VARYING_VECTORS][4];
@@ -56,30 +52,31 @@ struct PixelShaderOutputVariable
class DynamicHLSL
{
public:
- explicit DynamicHLSL(rx::Renderer *const renderer);
+ explicit DynamicHLSL(RendererD3D *const renderer);
- int packVaryings(gl::InfoLog &infoLog, VaryingPacking packing, rx::ShaderD3D *fragmentShader,
- rx::ShaderD3D *vertexShader, const std::vector<std::string>& transformFeedbackVaryings);
+ int packVaryings(gl::InfoLog &infoLog, VaryingPacking packing, ShaderD3D *fragmentShader,
+ ShaderD3D *vertexShader, const std::vector<std::string>& transformFeedbackVaryings);
std::string generateVertexShaderForInputLayout(const std::string &sourceShader, const gl::VertexFormat inputLayout[],
const sh::Attribute shaderAttributes[]) const;
std::string generatePixelShaderForOutputSignature(const std::string &sourceShader, const std::vector<PixelShaderOutputVariable> &outputVariables,
bool usesFragDepth, const std::vector<GLenum> &outputLayout) const;
- bool generateShaderLinkHLSL(gl::InfoLog &infoLog, int registers, const VaryingPacking packing,
- std::string& pixelHLSL, std::string& vertexHLSL,
- rx::ShaderD3D *fragmentShader, rx::ShaderD3D *vertexShader,
- const std::vector<std::string>& transformFeedbackVaryings,
+ bool generateShaderLinkHLSL(const gl::Data &data, gl::InfoLog &infoLog, int registers,
+ const VaryingPacking packing,
+ std::string &pixelHLSL, std::string &vertexHLSL,
+ ShaderD3D *fragmentShader, ShaderD3D *vertexShader,
+ const std::vector<std::string> &transformFeedbackVaryings,
std::vector<gl::LinkedVarying> *linkedVaryings,
std::map<int, gl::VariableLocation> *programOutputVars,
std::vector<PixelShaderOutputVariable> *outPixelShaderKey,
bool *outUsesFragDepth) const;
- std::string generateGeometryShaderHLSL(int registers, rx::ShaderD3D *fragmentShader, rx::ShaderD3D *vertexShader) const;
+ std::string generateGeometryShaderHLSL(int registers, ShaderD3D *fragmentShader, ShaderD3D *vertexShader) const;
void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const;
private:
DISALLOW_COPY_AND_ASSIGN(DynamicHLSL);
- rx::Renderer *const mRenderer;
+ RendererD3D *const mRenderer;
struct SemanticInfo;
@@ -88,10 +85,10 @@ class DynamicHLSL
bool pixelShader) const;
std::string generateVaryingLinkHLSL(const SemanticInfo &info, const std::string &varyingHLSL) const;
std::string generateVaryingHLSL(const ShaderD3D *shader) const;
- void storeUserLinkedVaryings(const rx::ShaderD3D *vertexShader, std::vector<gl::LinkedVarying> *linkedVaryings) const;
+ void storeUserLinkedVaryings(const ShaderD3D *vertexShader, std::vector<gl::LinkedVarying> *linkedVaryings) const;
void storeBuiltinLinkedVaryings(const SemanticInfo &info, std::vector<gl::LinkedVarying> *linkedVaryings) const;
- void defineOutputVariables(rx::ShaderD3D *fragmentShader, std::map<int, gl::VariableLocation> *programOutputVars) const;
- std::string generatePointSpriteHLSL(int registers, rx::ShaderD3D *fragmentShader, rx::ShaderD3D *vertexShader) const;
+ void defineOutputVariables(ShaderD3D *fragmentShader, std::map<int, gl::VariableLocation> *programOutputVars) const;
+ std::string generatePointSpriteHLSL(int registers, ShaderD3D *fragmentShader, ShaderD3D *vertexShader) const;
// Prepend an underscore
static std::string decorateVariable(const std::string &name);
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.cpp
index d0131974ee..776d92b202 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.cpp
@@ -8,34 +8,116 @@
#include "libGLESv2/Program.h"
#include "libGLESv2/main.h"
+#include "common/features.h"
#include "common/utilities.h"
-#include "common/platform.h"
-#if defined(__MINGW32__) && !defined(D3DCOMPILER_DLL)
+#ifndef QT_D3DCOMPILER_DLL
+#define QT_D3DCOMPILER_DLL D3DCOMPILER_DLL
+#endif
+#ifndef D3DCOMPILE_RESERVED16
+#define D3DCOMPILE_RESERVED16 (1 << 16)
+#endif
+#ifndef D3DCOMPILE_RESERVED17
+#define D3DCOMPILE_RESERVED17 (1 << 17)
+#endif
-// Add define + typedefs for older MinGW-w64 headers (pre 5783)
+// Definitions local to the translation unit
+namespace
+{
-#define D3DCOMPILER_DLL L"d3dcompiler_43.dll"
+#ifdef CREATE_COMPILER_FLAG_INFO
+ #undef CREATE_COMPILER_FLAG_INFO
+#endif
-HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename,
- const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
- const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages);
-typedef HRESULT (WINAPI *pD3DCompile)(const void *data, SIZE_T data_size, const char *filename,
- const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint,
- const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages);
+#define CREATE_COMPILER_FLAG_INFO(flag) { flag, #flag }
-#endif // __MINGW32__ && !D3DCOMPILER_DLL
+struct CompilerFlagInfo
+{
+ UINT mFlag;
+ const char *mName;
+};
-#ifndef QT_D3DCOMPILER_DLL
-#define QT_D3DCOMPILER_DLL D3DCOMPILER_DLL
-#endif
+CompilerFlagInfo CompilerFlagInfos[] =
+{
+ // NOTE: The data below is copied from d3dcompiler.h
+ // If something changes there it should be changed here as well
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_DEBUG), // (1 << 0)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_SKIP_VALIDATION), // (1 << 1)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_SKIP_OPTIMIZATION), // (1 << 2)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_PACK_MATRIX_ROW_MAJOR), // (1 << 3)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR), // (1 << 4)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_PARTIAL_PRECISION), // (1 << 5)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT), // (1 << 6)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT), // (1 << 7)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_NO_PRESHADER), // (1 << 8)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_AVOID_FLOW_CONTROL), // (1 << 9)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_PREFER_FLOW_CONTROL), // (1 << 10)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_ENABLE_STRICTNESS), // (1 << 11)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY), // (1 << 12)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_IEEE_STRICTNESS), // (1 << 13)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_OPTIMIZATION_LEVEL0), // (1 << 14)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_OPTIMIZATION_LEVEL1), // 0
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_OPTIMIZATION_LEVEL2), // ((1 << 14) | (1 << 15))
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_OPTIMIZATION_LEVEL3), // (1 << 15)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_RESERVED16), // (1 << 16)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_RESERVED17), // (1 << 17)
+ CREATE_COMPILER_FLAG_INFO(D3DCOMPILE_WARNINGS_ARE_ERRORS) // (1 << 18)
+};
+
+#undef CREATE_COMPILER_FLAG_INFO
+
+bool IsCompilerFlagSet(UINT mask, UINT flag)
+{
+ bool isFlagSet = IsMaskFlagSet(mask, flag);
+
+ switch(flag)
+ {
+ case D3DCOMPILE_OPTIMIZATION_LEVEL0:
+ return isFlagSet && !IsMaskFlagSet(mask, UINT(D3DCOMPILE_OPTIMIZATION_LEVEL3));
+
+ case D3DCOMPILE_OPTIMIZATION_LEVEL1:
+ return (mask & D3DCOMPILE_OPTIMIZATION_LEVEL2) == UINT(0);
+
+ case D3DCOMPILE_OPTIMIZATION_LEVEL3:
+ return isFlagSet && !IsMaskFlagSet(mask, UINT(D3DCOMPILE_OPTIMIZATION_LEVEL0));
+
+ default:
+ return isFlagSet;
+ }
+}
+
+const char *GetCompilerFlagName(UINT mask, size_t flagIx)
+{
+ const CompilerFlagInfo &flagInfo = CompilerFlagInfos[flagIx];
+ if (IsCompilerFlagSet(mask, flagInfo.mFlag))
+ {
+ return flagInfo.mName;
+ }
+
+ return nullptr;
+}
+
+}
namespace rx
{
+CompileConfig::CompileConfig()
+ : flags(0),
+ name()
+{
+}
+
+CompileConfig::CompileConfig(UINT flags, const std::string &name)
+ : flags(flags),
+ name(name)
+{
+}
+
HLSLCompiler::HLSLCompiler()
: mD3DCompilerModule(NULL),
- mD3DCompileFunc(NULL)
+ mD3DCompileFunc(NULL),
+ mD3DDisassembleFunc(NULL)
{
}
@@ -46,7 +128,7 @@ HLSLCompiler::~HLSLCompiler()
bool HLSLCompiler::initialize()
{
-#if !defined(ANGLE_PLATFORM_WINRT)
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
#if defined(ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES)
// Find a D3DCompiler module that had already been loaded based on a predefined list of versions.
static const char *d3dCompilerNames[] = ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES;
@@ -85,15 +167,30 @@ bool HLSLCompiler::initialize()
if (!mD3DCompilerModule)
{
+ // Load the version of the D3DCompiler DLL associated with the Direct3D version ANGLE was built with.
+ mD3DCompilerModule = LoadLibrary(D3DCOMPILER_DLL);
+ }
+
+ if (!mD3DCompilerModule)
+ {
ERR("No D3D compiler module found - aborting!\n");
return false;
}
- mD3DCompileFunc = reinterpret_cast<CompileFuncPtr>(GetProcAddress(mD3DCompilerModule, "D3DCompile"));
+ mD3DCompileFunc = reinterpret_cast<pD3DCompile>(GetProcAddress(mD3DCompilerModule, "D3DCompile"));
ASSERT(mD3DCompileFunc);
+
+ mD3DDisassembleFunc = reinterpret_cast<pD3DDisassemble>(GetProcAddress(mD3DCompilerModule, "D3DDisassemble"));
+ ASSERT(mD3DDisassembleFunc);
+
#else
- mD3DCompileFunc = reinterpret_cast<CompileFuncPtr>(&D3DCompile);
+ // D3D Shader compiler is linked already into this module, so the export
+ // can be directly assigned.
+ mD3DCompilerModule = NULL;
+ mD3DCompileFunc = reinterpret_cast<pD3DCompile>(D3DCompile);
+ mD3DDisassembleFunc = reinterpret_cast<pD3DDisassemble>(D3DDisassemble);
#endif
+
return mD3DCompileFunc != NULL;
}
@@ -104,61 +201,133 @@ void HLSLCompiler::release()
FreeLibrary(mD3DCompilerModule);
mD3DCompilerModule = NULL;
mD3DCompileFunc = NULL;
+ mD3DDisassembleFunc = NULL;
}
}
-ShaderBlob *HLSLCompiler::compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile,
- const UINT optimizationFlags[], const char *flagNames[], int attempts) const
+gl::Error HLSLCompiler::compileToBinary(gl::InfoLog &infoLog, const std::string &hlsl, const std::string &profile,
+ const std::vector<CompileConfig> &configs, const D3D_SHADER_MACRO *overrideMacros,
+ ID3DBlob **outCompiledBlob, std::string *outDebugInfo) const
{
-#if !defined(ANGLE_PLATFORM_WINRT)
- ASSERT(mD3DCompilerModule && mD3DCompileFunc);
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
+ ASSERT(mD3DCompilerModule);
#endif
+ ASSERT(mD3DCompileFunc);
- if (!hlsl)
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
+ if (gl::perfActive())
{
- return NULL;
+ std::string sourcePath = getTempPath();
+ std::string sourceText = FormatString("#line 2 \"%s\"\n\n%s", sourcePath.c_str(), hlsl.c_str());
+ writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size());
}
+#endif
+
+ const D3D_SHADER_MACRO *macros = overrideMacros ? overrideMacros : NULL;
- pD3DCompile compileFunc = reinterpret_cast<pD3DCompile>(mD3DCompileFunc);
- for (int i = 0; i < attempts; ++i)
+ for (size_t i = 0; i < configs.size(); ++i)
{
ID3DBlob *errorMessage = NULL;
ID3DBlob *binary = NULL;
- HRESULT result = compileFunc(hlsl, strlen(hlsl), gl::g_fakepath, NULL, NULL, "main", profile, optimizationFlags[i], 0, &binary, &errorMessage);
+ HRESULT result = mD3DCompileFunc(hlsl.c_str(), hlsl.length(), gl::g_fakepath, macros, NULL, "main", profile.c_str(),
+ configs[i].flags, 0, &binary, &errorMessage);
if (errorMessage)
{
- const char *message = (const char*)errorMessage->GetBufferPointer();
+ std::string message = reinterpret_cast<const char*>(errorMessage->GetBufferPointer());
+ SafeRelease(errorMessage);
- infoLog.appendSanitized(message);
- TRACE("\n%s", hlsl);
- TRACE("\n%s", message);
+ infoLog.appendSanitized(message.c_str());
+ TRACE("\n%s", hlsl.c_str());
+ TRACE("\n%s", message.c_str());
- SafeRelease(errorMessage);
+ if (message.find("error X3531:") != std::string::npos) // "can't unroll loops marked with loop attribute"
+ {
+ macros = NULL; // Disable [loop] and [flatten]
+
+ // Retry without changing compiler flags
+ i--;
+ continue;
+ }
}
if (SUCCEEDED(result))
{
- return (ShaderBlob*)binary;
+ *outCompiledBlob = binary;
+
+#if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED
+ (*outDebugInfo) += "// COMPILER INPUT HLSL BEGIN\n\n" + hlsl + "\n// COMPILER INPUT HLSL END\n";
+ (*outDebugInfo) += "\n\n// ASSEMBLY BEGIN\n\n";
+ (*outDebugInfo) += "// Compiler configuration: " + configs[i].name + "\n// Flags:\n";
+ for (size_t fIx = 0; fIx < ArraySize(CompilerFlagInfos); ++fIx)
+ {
+ const char *flagName = GetCompilerFlagName(configs[i].flags, fIx);
+ if (flagName != nullptr)
+ {
+ (*outDebugInfo) += std::string("// ") + flagName + "\n";
+ }
+ }
+
+ (*outDebugInfo) += "// Macros:\n";
+ if (macros == nullptr)
+ {
+ (*outDebugInfo) += "// - : -\n";
+ }
+ else
+ {
+ for (const D3D_SHADER_MACRO *mIt = macros; mIt->Name != nullptr; ++mIt)
+ {
+ (*outDebugInfo) += std::string("// ") + mIt->Name + " : " + mIt->Definition + "\n";
+ }
+ }
+
+ (*outDebugInfo) += "\n" + disassembleBinary(binary) + "\n// ASSEMBLY END\n";
+#endif
+
+ return gl::Error(GL_NO_ERROR);
}
else
{
if (result == E_OUTOFMEMORY)
{
- return gl::error(GL_OUT_OF_MEMORY, (ShaderBlob*)NULL);
+ *outCompiledBlob = NULL;
+ return gl::Error(GL_OUT_OF_MEMORY, "HLSL compiler had an unexpected failure, result: 0x%X.", result);
}
- infoLog.append("Warning: D3D shader compilation failed with %s flags.", flagNames[i]);
+ infoLog.append("Warning: D3D shader compilation failed with %s flags.", configs[i].name.c_str());
- if (i + 1 < attempts)
+ if (i + 1 < configs.size())
{
- infoLog.append(" Retrying with %s.\n", flagNames[i + 1]);
+ infoLog.append(" Retrying with %s.\n", configs[i + 1].name.c_str());
}
}
}
- return NULL;
+ // None of the configurations succeeded in compiling this shader but the compiler is still intact
+ *outCompiledBlob = NULL;
+ return gl::Error(GL_NO_ERROR);
+}
+
+std::string HLSLCompiler::disassembleBinary(ID3DBlob *shaderBinary) const
+{
+ // Retrieve disassembly
+ UINT flags = D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS | D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING;
+ ID3DBlob *disassembly = NULL;
+ pD3DDisassemble disassembleFunc = reinterpret_cast<pD3DDisassemble>(mD3DDisassembleFunc);
+ LPCVOID buffer = shaderBinary->GetBufferPointer();
+ SIZE_T bufSize = shaderBinary->GetBufferSize();
+ HRESULT result = disassembleFunc(buffer, bufSize, flags, "", &disassembly);
+
+ std::string asmSrc;
+ if (SUCCEEDED(result))
+ {
+ asmSrc = reinterpret_cast<const char*>(disassembly->GetBufferPointer());
+ }
+
+ SafeRelease(disassembly);
+
+ return asmSrc;
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.h
index 0ce9e44be5..ff56f8035a 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/HLSLCompiler.h
@@ -1,7 +1,13 @@
#ifndef LIBGLESV2_RENDERER_HLSL_D3DCOMPILER_H_
#define LIBGLESV2_RENDERER_HLSL_D3DCOMPILER_H_
+#include "libGLESv2/Error.h"
+
#include "common/angleutils.h"
+#include "common/platform.h"
+
+#include <vector>
+#include <string>
namespace gl
{
@@ -11,8 +17,14 @@ class InfoLog;
namespace rx
{
-typedef void* ShaderBlob;
-typedef void(*CompileFuncPtr)();
+struct CompileConfig
+{
+ UINT flags;
+ std::string name;
+
+ CompileConfig();
+ CompileConfig(UINT flags, const std::string &name);
+};
class HLSLCompiler
{
@@ -23,14 +35,20 @@ class HLSLCompiler
bool initialize();
void release();
- ShaderBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile,
- const UINT optimizationFlags[], const char *flagNames[], int attempts) const;
+ // Attempt to compile a HLSL shader using the supplied configurations, may output a NULL compiled blob
+ // even if no GL errors are returned.
+ gl::Error compileToBinary(gl::InfoLog &infoLog, const std::string &hlsl, const std::string &profile,
+ const std::vector<CompileConfig> &configs, const D3D_SHADER_MACRO *overrideMacros,
+ ID3DBlob **outCompiledBlob, std::string *outDebugInfo) const;
+
+ std::string disassembleBinary(ID3DBlob* shaderBinary) const;
private:
DISALLOW_COPY_AND_ASSIGN(HLSLCompiler);
HMODULE mD3DCompilerModule;
- CompileFuncPtr mD3DCompileFunc;
+ pD3DCompile mD3DCompileFunc;
+ pD3DDisassemble mD3DDisassembleFunc;
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.cpp
index 0854b968da..12b919ab5a 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.cpp
@@ -19,8 +19,8 @@ ImageD3D::ImageD3D()
ImageD3D *ImageD3D::makeImageD3D(Image *img)
{
- ASSERT(HAS_DYNAMIC_TYPE(rx::ImageD3D*, img));
- return static_cast<rx::ImageD3D*>(img);
+ ASSERT(HAS_DYNAMIC_TYPE(ImageD3D*, img));
+ return static_cast<ImageD3D*>(img);
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.h
index 60a6ffdf37..554ca0cee0 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ImageD3D.h
@@ -17,6 +17,8 @@
namespace gl
{
class Framebuffer;
+struct ImageIndex;
+struct Box;
}
namespace rx
@@ -33,14 +35,11 @@ class ImageD3D : public Image
virtual bool isDirty() const = 0;
- virtual void setManagedSurface2D(TextureStorage *storage, int level) {};
- virtual void setManagedSurfaceCube(TextureStorage *storage, int face, int level) {};
- virtual void setManagedSurface3D(TextureStorage *storage, int level) {};
- virtual void setManagedSurface2DArray(TextureStorage *storage, int layer, int level) {};
- virtual bool copyToStorage2D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height) = 0;
- virtual bool copyToStorageCube(TextureStorage *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height) = 0;
- virtual bool copyToStorage3D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth) = 0;
- virtual bool copyToStorage2DArray(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height) = 0;
+ virtual gl::Error setManagedSurface2D(TextureStorage *storage, int level) { return gl::Error(GL_NO_ERROR); };
+ virtual gl::Error setManagedSurfaceCube(TextureStorage *storage, int face, int level) { return gl::Error(GL_NO_ERROR); };
+ virtual gl::Error setManagedSurface3D(TextureStorage *storage, int level) { return gl::Error(GL_NO_ERROR); };
+ virtual gl::Error setManagedSurface2DArray(TextureStorage *storage, int layer, int level) { return gl::Error(GL_NO_ERROR); };
+ virtual gl::Error copyToStorage(TextureStorage *storage, const gl::ImageIndex &index, const gl::Box &region) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(ImageD3D);
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.cpp
index 1dce1270d8..aa614f6cc4 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.cpp
@@ -8,7 +8,7 @@
// class with derivations, classes that perform graphics API agnostic index buffer operations.
#include "libGLESv2/renderer/d3d/IndexBuffer.h"
-#include "libGLESv2/renderer/Renderer.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
namespace rx
{
@@ -35,7 +35,7 @@ void IndexBuffer::updateSerial()
}
-IndexBufferInterface::IndexBufferInterface(Renderer *renderer, bool dynamic) : mRenderer(renderer)
+IndexBufferInterface::IndexBufferInterface(RendererD3D *renderer, bool dynamic) : mRenderer(renderer)
{
mIndexBuffer = renderer->createIndexBuffer();
@@ -130,7 +130,7 @@ gl::Error IndexBufferInterface::setBufferSize(unsigned int bufferSize, GLenum in
}
}
-StreamingIndexBufferInterface::StreamingIndexBufferInterface(Renderer *renderer) : IndexBufferInterface(renderer, true)
+StreamingIndexBufferInterface::StreamingIndexBufferInterface(RendererD3D *renderer) : IndexBufferInterface(renderer, true)
{
}
@@ -165,7 +165,7 @@ gl::Error StreamingIndexBufferInterface::reserveBufferSpace(unsigned int size, G
}
-StaticIndexBufferInterface::StaticIndexBufferInterface(Renderer *renderer) : IndexBufferInterface(renderer, false)
+StaticIndexBufferInterface::StaticIndexBufferInterface(RendererD3D *renderer) : IndexBufferInterface(renderer, false)
{
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.h
index 1bb5ae2c4a..a34d30bbf3 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexBuffer.h
@@ -16,7 +16,7 @@
namespace rx
{
-class Renderer;
+class RendererD3D;
class IndexBuffer
{
@@ -50,7 +50,7 @@ class IndexBuffer
class IndexBufferInterface
{
public:
- IndexBufferInterface(Renderer *renderer, bool dynamic);
+ IndexBufferInterface(RendererD3D *renderer, bool dynamic);
virtual ~IndexBufferInterface();
virtual gl::Error reserveBufferSpace(unsigned int size, GLenum indexType) = 0;
@@ -76,7 +76,7 @@ class IndexBufferInterface
private:
DISALLOW_COPY_AND_ASSIGN(IndexBufferInterface);
- rx::Renderer *const mRenderer;
+ RendererD3D *const mRenderer;
IndexBuffer* mIndexBuffer;
@@ -87,7 +87,7 @@ class IndexBufferInterface
class StreamingIndexBufferInterface : public IndexBufferInterface
{
public:
- StreamingIndexBufferInterface(Renderer *renderer);
+ StreamingIndexBufferInterface(RendererD3D *renderer);
~StreamingIndexBufferInterface();
virtual gl::Error reserveBufferSpace(unsigned int size, GLenum indexType);
@@ -96,7 +96,7 @@ class StreamingIndexBufferInterface : public IndexBufferInterface
class StaticIndexBufferInterface : public IndexBufferInterface
{
public:
- explicit StaticIndexBufferInterface(Renderer *renderer);
+ explicit StaticIndexBufferInterface(RendererD3D *renderer);
~StaticIndexBufferInterface();
virtual gl::Error reserveBufferSpace(unsigned int size, GLenum indexType);
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
index 8d455b4bf3..eddd9de887 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.cpp
@@ -10,7 +10,7 @@
#include "libGLESv2/renderer/d3d/IndexDataManager.h"
#include "libGLESv2/renderer/d3d/BufferD3D.h"
#include "libGLESv2/renderer/d3d/IndexBuffer.h"
-#include "libGLESv2/renderer/Renderer.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
#include "libGLESv2/Buffer.h"
#include "libGLESv2/main.h"
#include "libGLESv2/formatutils.h"
@@ -57,7 +57,7 @@ static void ConvertIndices(GLenum sourceType, GLenum destinationType, const void
else UNREACHABLE();
}
-IndexDataManager::IndexDataManager(Renderer *renderer)
+IndexDataManager::IndexDataManager(RendererD3D *renderer)
: mRenderer(renderer),
mStreamingBufferShort(NULL),
mStreamingBufferInt(NULL)
@@ -97,7 +97,14 @@ gl::Error IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buf
ASSERT(typeInfo.bytes * static_cast<unsigned int>(count) + offset <= storage->getSize());
- indices = static_cast<const GLubyte*>(storage->getData()) + offset;
+ const uint8_t *bufferData = NULL;
+ gl::Error error = storage->getData(&bufferData);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ indices = bufferData + offset;
}
StaticIndexBufferInterface *staticBuffer = storage ? storage->getStaticIndexBuffer() : NULL;
@@ -183,7 +190,16 @@ gl::Error IndexDataManager::prepareIndexData(GLenum type, GLsizei count, gl::Buf
return error;
}
- ConvertIndices(type, destinationIndexType, staticBuffer ? storage->getData() : indices, convertCount, output);
+ const uint8_t *dataPointer = reinterpret_cast<const uint8_t*>(indices);
+ if (staticBuffer)
+ {
+ error = storage->getData(&dataPointer);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ ConvertIndices(type, destinationIndexType, dataPointer, convertCount, output);
error = indexBuffer->unmapBuffer();
if (error.isError())
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.h
index 6d0b89e6d4..a1aee1588b 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/IndexDataManager.h
@@ -33,7 +33,7 @@ class StaticIndexBufferInterface;
class StreamingIndexBufferInterface;
class IndexBuffer;
class BufferD3D;
-class Renderer;
+class RendererD3D;
struct TranslatedIndexData
{
@@ -50,7 +50,7 @@ struct TranslatedIndexData
class IndexDataManager
{
public:
- explicit IndexDataManager(Renderer *renderer);
+ explicit IndexDataManager(RendererD3D *renderer);
virtual ~IndexDataManager();
gl::Error prepareIndexData(GLenum type, GLsizei count, gl::Buffer *arrayElementBuffer, const GLvoid *indices, TranslatedIndexData *translated);
@@ -60,7 +60,7 @@ class IndexDataManager
DISALLOW_COPY_AND_ASSIGN(IndexDataManager);
- Renderer *const mRenderer;
+ RendererD3D *const mRenderer;
StreamingIndexBufferInterface *mStreamingBufferShort;
StreamingIndexBufferInterface *mStreamingBufferInt;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp
index d7d97cc2bd..75da78110e 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp
@@ -8,27 +8,163 @@
#include "libGLESv2/renderer/d3d/ProgramD3D.h"
+#include "common/features.h"
#include "common/utilities.h"
+#include "libGLESv2/Framebuffer.h"
+#include "libGLESv2/FramebufferAttachment.h"
+#include "libGLESv2/Program.h"
#include "libGLESv2/ProgramBinary.h"
-#include "libGLESv2/renderer/Renderer.h"
+#include "libGLESv2/main.h"
#include "libGLESv2/renderer/ShaderExecutable.h"
#include "libGLESv2/renderer/d3d/DynamicHLSL.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
#include "libGLESv2/renderer/d3d/ShaderD3D.h"
-#include "libGLESv2/main.h"
namespace rx
{
-ProgramD3D::ProgramD3D(rx::Renderer *renderer)
+namespace
+{
+
+GLenum GetTextureType(GLenum samplerType)
+{
+ switch (samplerType)
+ {
+ case GL_SAMPLER_2D:
+ case GL_INT_SAMPLER_2D:
+ case GL_UNSIGNED_INT_SAMPLER_2D:
+ case GL_SAMPLER_2D_SHADOW:
+ return GL_TEXTURE_2D;
+ case GL_SAMPLER_3D:
+ case GL_INT_SAMPLER_3D:
+ case GL_UNSIGNED_INT_SAMPLER_3D:
+ return GL_TEXTURE_3D;
+ case GL_SAMPLER_CUBE:
+ case GL_SAMPLER_CUBE_SHADOW:
+ return GL_TEXTURE_CUBE_MAP;
+ case GL_INT_SAMPLER_CUBE:
+ case GL_UNSIGNED_INT_SAMPLER_CUBE:
+ return GL_TEXTURE_CUBE_MAP;
+ case GL_SAMPLER_2D_ARRAY:
+ case GL_INT_SAMPLER_2D_ARRAY:
+ case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
+ case GL_SAMPLER_2D_ARRAY_SHADOW:
+ return GL_TEXTURE_2D_ARRAY;
+ default: UNREACHABLE();
+ }
+
+ return GL_TEXTURE_2D;
+}
+
+void GetDefaultInputLayoutFromShader(const std::vector<sh::Attribute> &shaderAttributes, gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS])
+{
+ size_t layoutIndex = 0;
+ for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); attributeIndex++)
+ {
+ ASSERT(layoutIndex < gl::MAX_VERTEX_ATTRIBS);
+
+ const sh::Attribute &shaderAttr = shaderAttributes[attributeIndex];
+
+ if (shaderAttr.type != GL_NONE)
+ {
+ GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type);
+
+ for (size_t rowIndex = 0; static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); rowIndex++, layoutIndex++)
+ {
+ gl::VertexFormat *defaultFormat = &inputLayout[layoutIndex];
+
+ defaultFormat->mType = gl::VariableComponentType(transposedType);
+ defaultFormat->mNormalized = false;
+ defaultFormat->mPureInteger = (defaultFormat->mType != GL_FLOAT); // note: inputs can not be bool
+ defaultFormat->mComponents = gl::VariableColumnCount(transposedType);
+ }
+ }
+ }
+}
+
+std::vector<GLenum> GetDefaultOutputLayoutFromShader(const std::vector<PixelShaderOutputVariable> &shaderOutputVars)
+{
+ std::vector<GLenum> defaultPixelOutput(1);
+
+ ASSERT(!shaderOutputVars.empty());
+ defaultPixelOutput[0] = GL_COLOR_ATTACHMENT0 + shaderOutputVars[0].outputIndex;
+
+ return defaultPixelOutput;
+}
+
+bool IsRowMajorLayout(const sh::InterfaceBlockField &var)
+{
+ return var.isRowMajorLayout;
+}
+
+bool IsRowMajorLayout(const sh::ShaderVariable &var)
+{
+ return false;
+}
+
+}
+
+ProgramD3D::VertexExecutable::VertexExecutable(const gl::VertexFormat inputLayout[],
+ const GLenum signature[],
+ ShaderExecutable *shaderExecutable)
+ : mShaderExecutable(shaderExecutable)
+{
+ for (size_t attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
+ {
+ mInputs[attributeIndex] = inputLayout[attributeIndex];
+ mSignature[attributeIndex] = signature[attributeIndex];
+ }
+}
+
+ProgramD3D::VertexExecutable::~VertexExecutable()
+{
+ SafeDelete(mShaderExecutable);
+}
+
+bool ProgramD3D::VertexExecutable::matchesSignature(const GLenum signature[]) const
+{
+ for (size_t attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
+ {
+ if (mSignature[attributeIndex] != signature[attributeIndex])
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature, ShaderExecutable *shaderExecutable)
+ : mOutputSignature(outputSignature),
+ mShaderExecutable(shaderExecutable)
+{
+}
+
+ProgramD3D::PixelExecutable::~PixelExecutable()
+{
+ SafeDelete(mShaderExecutable);
+}
+
+ProgramD3D::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(GL_TEXTURE_2D)
+{
+}
+
+ProgramD3D::ProgramD3D(RendererD3D *renderer)
: ProgramImpl(),
mRenderer(renderer),
mDynamicHLSL(NULL),
- mVertexWorkarounds(rx::ANGLE_D3D_WORKAROUND_NONE),
- mPixelWorkarounds(rx::ANGLE_D3D_WORKAROUND_NONE),
+ mGeometryExecutable(NULL),
+ mVertexWorkarounds(ANGLE_D3D_WORKAROUND_NONE),
+ mPixelWorkarounds(ANGLE_D3D_WORKAROUND_NONE),
+ mUsesPointSize(false),
mVertexUniformStorage(NULL),
- mFragmentUniformStorage(NULL)
+ mFragmentUniformStorage(NULL),
+ mUsedVertexSamplerRange(0),
+ mUsedPixelSamplerRange(0),
+ mDirtySamplerMapping(true),
+ mShaderVersion(100)
{
- mDynamicHLSL = new rx::DynamicHLSL(renderer);
+ mDynamicHLSL = new DynamicHLSL(renderer);
}
ProgramD3D::~ProgramD3D()
@@ -49,13 +185,344 @@ const ProgramD3D *ProgramD3D::makeProgramD3D(const ProgramImpl *impl)
return static_cast<const ProgramD3D*>(impl);
}
-bool ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
+bool ProgramD3D::usesPointSpriteEmulation() const
+{
+ return mUsesPointSize && mRenderer->getMajorShaderModel() >= 4;
+}
+
+bool ProgramD3D::usesGeometryShader() const
+{
+ return usesPointSpriteEmulation();
+}
+
+GLint ProgramD3D::getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const
+{
+ GLint logicalTextureUnit = -1;
+
+ switch (type)
+ {
+ case gl::SAMPLER_PIXEL:
+ ASSERT(samplerIndex < caps.maxTextureImageUnits);
+ if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
+ {
+ logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
+ }
+ break;
+ case gl::SAMPLER_VERTEX:
+ ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
+ if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
+ {
+ logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
+ }
+ break;
+ default: UNREACHABLE();
+ }
+
+ if (logicalTextureUnit >= 0 && logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
+ {
+ return logicalTextureUnit;
+ }
+
+ return -1;
+}
+
+// Returns the texture type for a given Direct3D 9 sampler type and
+// index (0-15 for the pixel shader and 0-3 for the vertex shader).
+GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const
+{
+ switch (type)
+ {
+ case gl::SAMPLER_PIXEL:
+ ASSERT(samplerIndex < mSamplersPS.size());
+ ASSERT(mSamplersPS[samplerIndex].active);
+ return mSamplersPS[samplerIndex].textureType;
+ case gl::SAMPLER_VERTEX:
+ ASSERT(samplerIndex < mSamplersVS.size());
+ ASSERT(mSamplersVS[samplerIndex].active);
+ return mSamplersVS[samplerIndex].textureType;
+ default: UNREACHABLE();
+ }
+
+ return GL_TEXTURE_2D;
+}
+
+GLint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const
+{
+ switch (type)
+ {
+ case gl::SAMPLER_PIXEL:
+ return mUsedPixelSamplerRange;
+ case gl::SAMPLER_VERTEX:
+ return mUsedVertexSamplerRange;
+ default:
+ UNREACHABLE();
+ return 0;
+ }
+}
+
+void ProgramD3D::updateSamplerMapping()
+{
+ if (!mDirtySamplerMapping)
+ {
+ return;
+ }
+
+ mDirtySamplerMapping = false;
+
+ // Retrieve sampler uniform values
+ for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
+ {
+ gl::LinkedUniform *targetUniform = mUniforms[uniformIndex];
+
+ if (targetUniform->dirty)
+ {
+ if (gl::IsSampler(targetUniform->type))
+ {
+ int count = targetUniform->elementCount();
+ GLint (*v)[4] = reinterpret_cast<GLint(*)[4]>(targetUniform->data);
+
+ if (targetUniform->isReferencedByFragmentShader())
+ {
+ unsigned int firstIndex = targetUniform->psRegisterIndex;
+
+ for (int i = 0; i < count; i++)
+ {
+ unsigned int samplerIndex = firstIndex + i;
+
+ if (samplerIndex < mSamplersPS.size())
+ {
+ ASSERT(mSamplersPS[samplerIndex].active);
+ mSamplersPS[samplerIndex].logicalTextureUnit = v[i][0];
+ }
+ }
+ }
+
+ if (targetUniform->isReferencedByVertexShader())
+ {
+ unsigned int firstIndex = targetUniform->vsRegisterIndex;
+
+ for (int i = 0; i < count; i++)
+ {
+ unsigned int samplerIndex = firstIndex + i;
+
+ if (samplerIndex < mSamplersVS.size())
+ {
+ ASSERT(mSamplersVS[samplerIndex].active);
+ mSamplersVS[samplerIndex].logicalTextureUnit = v[i][0];
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
{
+ // if any two active samplers in a program are of different types, but refer to the same
+ // texture image unit, and this is the current program, then ValidateProgram will fail, and
+ // DrawArrays and DrawElements will issue the INVALID_OPERATION error.
+ updateSamplerMapping();
+
+ std::vector<GLenum> textureUnitTypes(caps.maxCombinedTextureImageUnits, GL_NONE);
+
+ for (unsigned int i = 0; i < mUsedPixelSamplerRange; ++i)
+ {
+ if (mSamplersPS[i].active)
+ {
+ unsigned int unit = mSamplersPS[i].logicalTextureUnit;
+
+ if (unit >= textureUnitTypes.size())
+ {
+ if (infoLog)
+ {
+ infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, textureUnitTypes.size());
+ }
+
+ return false;
+ }
+
+ if (textureUnitTypes[unit] != GL_NONE)
+ {
+ if (mSamplersPS[i].textureType != textureUnitTypes[unit])
+ {
+ if (infoLog)
+ {
+ infoLog->append("Samplers of conflicting types refer to the same texture image unit (%d).", unit);
+ }
+
+ return false;
+ }
+ }
+ else
+ {
+ textureUnitTypes[unit] = mSamplersPS[i].textureType;
+ }
+ }
+ }
+
+ for (unsigned int i = 0; i < mUsedVertexSamplerRange; ++i)
+ {
+ if (mSamplersVS[i].active)
+ {
+ unsigned int unit = mSamplersVS[i].logicalTextureUnit;
+
+ if (unit >= textureUnitTypes.size())
+ {
+ if (infoLog)
+ {
+ infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, textureUnitTypes.size());
+ }
+
+ return false;
+ }
+
+ if (textureUnitTypes[unit] != GL_NONE)
+ {
+ if (mSamplersVS[i].textureType != textureUnitTypes[unit])
+ {
+ if (infoLog)
+ {
+ infoLog->append("Samplers of conflicting types refer to the same texture image unit (%d).", unit);
+ }
+
+ return false;
+ }
+ }
+ else
+ {
+ textureUnitTypes[unit] = mSamplersVS[i].textureType;
+ }
+ }
+ }
+
+ return true;
+}
+
+gl::LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
+{
+ stream->readInt(&mShaderVersion);
+
+ const unsigned int psSamplerCount = stream->readInt<unsigned int>();
+ for (unsigned int i = 0; i < psSamplerCount; ++i)
+ {
+ Sampler sampler;
+ stream->readBool(&sampler.active);
+ stream->readInt(&sampler.logicalTextureUnit);
+ stream->readInt(&sampler.textureType);
+ mSamplersPS.push_back(sampler);
+ }
+ const unsigned int vsSamplerCount = stream->readInt<unsigned int>();
+ for (unsigned int i = 0; i < vsSamplerCount; ++i)
+ {
+ Sampler sampler;
+ stream->readBool(&sampler.active);
+ stream->readInt(&sampler.logicalTextureUnit);
+ stream->readInt(&sampler.textureType);
+ mSamplersVS.push_back(sampler);
+ }
+
+ stream->readInt(&mUsedVertexSamplerRange);
+ stream->readInt(&mUsedPixelSamplerRange);
+
+ const unsigned int uniformCount = stream->readInt<unsigned int>();
+ if (stream->error())
+ {
+ infoLog.append("Invalid program binary.");
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
+ }
+
+ mUniforms.resize(uniformCount);
+ for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++)
+ {
+ GLenum type = stream->readInt<GLenum>();
+ GLenum precision = stream->readInt<GLenum>();
+ std::string name = stream->readString();
+ unsigned int arraySize = stream->readInt<unsigned int>();
+ int blockIndex = stream->readInt<int>();
+
+ int offset = stream->readInt<int>();
+ int arrayStride = stream->readInt<int>();
+ int matrixStride = stream->readInt<int>();
+ bool isRowMajorMatrix = stream->readBool();
+
+ const sh::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix);
+
+ gl::LinkedUniform *uniform = new gl::LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo);
+
+ stream->readInt(&uniform->psRegisterIndex);
+ stream->readInt(&uniform->vsRegisterIndex);
+ stream->readInt(&uniform->registerCount);
+ stream->readInt(&uniform->registerElement);
+
+ mUniforms[uniformIndex] = uniform;
+ }
+
+ const unsigned int uniformIndexCount = stream->readInt<unsigned int>();
+ if (stream->error())
+ {
+ infoLog.append("Invalid program binary.");
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
+ }
+
+ mUniformIndex.resize(uniformIndexCount);
+ for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount; uniformIndexIndex++)
+ {
+ stream->readString(&mUniformIndex[uniformIndexIndex].name);
+ stream->readInt(&mUniformIndex[uniformIndexIndex].element);
+ stream->readInt(&mUniformIndex[uniformIndexIndex].index);
+ }
+
+ unsigned int uniformBlockCount = stream->readInt<unsigned int>();
+ if (stream->error())
+ {
+ infoLog.append("Invalid program binary.");
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
+ }
+
+ mUniformBlocks.resize(uniformBlockCount);
+ for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount; ++uniformBlockIndex)
+ {
+ std::string name = stream->readString();
+ unsigned int elementIndex = stream->readInt<unsigned int>();
+ unsigned int dataSize = stream->readInt<unsigned int>();
+
+ gl::UniformBlock *uniformBlock = new gl::UniformBlock(name, elementIndex, dataSize);
+
+ stream->readInt(&uniformBlock->psRegisterIndex);
+ stream->readInt(&uniformBlock->vsRegisterIndex);
+
+ unsigned int numMembers = stream->readInt<unsigned int>();
+ uniformBlock->memberUniformIndexes.resize(numMembers);
+ for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++)
+ {
+ stream->readInt(&uniformBlock->memberUniformIndexes[blockMemberIndex]);
+ }
+
+ mUniformBlocks[uniformBlockIndex] = uniformBlock;
+ }
+
+ stream->readInt(&mTransformFeedbackBufferMode);
+ const unsigned int transformFeedbackVaryingCount = stream->readInt<unsigned int>();
+ mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount);
+ for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++)
+ {
+ gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex];
+
+ stream->readString(&varying.name);
+ stream->readInt(&varying.type);
+ stream->readInt(&varying.size);
+ stream->readString(&varying.semanticName);
+ stream->readInt(&varying.semanticIndex);
+ stream->readInt(&varying.semanticIndexCount);
+ }
+
stream->readString(&mVertexHLSL);
stream->readInt(&mVertexWorkarounds);
stream->readString(&mPixelHLSL);
stream->readInt(&mPixelWorkarounds);
stream->readBool(&mUsesFragDepth);
+ stream->readBool(&mUsesPointSize);
const size_t pixelShaderKeySize = stream->readInt<unsigned int>();
mPixelShaderKey.resize(pixelShaderKeySize);
@@ -67,109 +534,513 @@ bool ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].outputIndex);
}
- return true;
+ const unsigned char* binary = reinterpret_cast<const unsigned char*>(stream->data());
+
+ const unsigned int vertexShaderCount = stream->readInt<unsigned int>();
+ for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++)
+ {
+ gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS];
+
+ for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++)
+ {
+ gl::VertexFormat *vertexInput = &inputLayout[inputIndex];
+ stream->readInt(&vertexInput->mType);
+ stream->readInt(&vertexInput->mNormalized);
+ stream->readInt(&vertexInput->mComponents);
+ stream->readBool(&vertexInput->mPureInteger);
+ }
+
+ unsigned int vertexShaderSize = stream->readInt<unsigned int>();
+ const unsigned char *vertexShaderFunction = binary + stream->offset();
+
+ ShaderExecutable *shaderExecutable = NULL;
+ gl::Error error = mRenderer->loadExecutable(vertexShaderFunction, vertexShaderSize,
+ SHADER_VERTEX,
+ mTransformFeedbackLinkedVaryings,
+ (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
+ &shaderExecutable);
+ if (error.isError())
+ {
+ return gl::LinkResult(false, error);
+ }
+
+ if (!shaderExecutable)
+ {
+ infoLog.append("Could not create vertex shader.");
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
+ }
+
+ // generated converted input layout
+ GLenum signature[gl::MAX_VERTEX_ATTRIBS];
+ getInputLayoutSignature(inputLayout, signature);
+
+ // add new binary
+ mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, shaderExecutable));
+
+ stream->skip(vertexShaderSize);
+ }
+
+ const size_t pixelShaderCount = stream->readInt<unsigned int>();
+ for (size_t pixelShaderIndex = 0; pixelShaderIndex < pixelShaderCount; pixelShaderIndex++)
+ {
+ const size_t outputCount = stream->readInt<unsigned int>();
+ std::vector<GLenum> outputs(outputCount);
+ for (size_t outputIndex = 0; outputIndex < outputCount; outputIndex++)
+ {
+ stream->readInt(&outputs[outputIndex]);
+ }
+
+ const size_t pixelShaderSize = stream->readInt<unsigned int>();
+ const unsigned char *pixelShaderFunction = binary + stream->offset();
+ ShaderExecutable *shaderExecutable = NULL;
+ gl::Error error = mRenderer->loadExecutable(pixelShaderFunction, pixelShaderSize, SHADER_PIXEL,
+ mTransformFeedbackLinkedVaryings,
+ (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
+ &shaderExecutable);
+ if (error.isError())
+ {
+ return gl::LinkResult(false, error);
+ }
+
+ if (!shaderExecutable)
+ {
+ infoLog.append("Could not create pixel shader.");
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
+ }
+
+ // add new binary
+ mPixelExecutables.push_back(new PixelExecutable(outputs, shaderExecutable));
+
+ stream->skip(pixelShaderSize);
+ }
+
+ unsigned int geometryShaderSize = stream->readInt<unsigned int>();
+
+ if (geometryShaderSize > 0)
+ {
+ const unsigned char *geometryShaderFunction = binary + stream->offset();
+ gl::Error error = mRenderer->loadExecutable(geometryShaderFunction, geometryShaderSize, SHADER_GEOMETRY,
+ mTransformFeedbackLinkedVaryings,
+ (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
+ &mGeometryExecutable);
+ if (error.isError())
+ {
+ return gl::LinkResult(false, error);
+ }
+
+ if (!mGeometryExecutable)
+ {
+ infoLog.append("Could not create geometry shader.");
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
+ }
+ stream->skip(geometryShaderSize);
+ }
+
+ GUID binaryIdentifier = {0};
+ stream->readBytes(reinterpret_cast<unsigned char*>(&binaryIdentifier), sizeof(GUID));
+
+ GUID identifier = mRenderer->getAdapterIdentifier();
+ if (memcmp(&identifier, &binaryIdentifier, sizeof(GUID)) != 0)
+ {
+ infoLog.append("Invalid program binary.");
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
+ }
+
+ initializeUniformStorage();
+
+ return gl::LinkResult(true, gl::Error(GL_NO_ERROR));
}
-bool ProgramD3D::save(gl::BinaryOutputStream *stream)
+gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
{
+ stream->writeInt(mShaderVersion);
+
+ stream->writeInt(mSamplersPS.size());
+ for (unsigned int i = 0; i < mSamplersPS.size(); ++i)
+ {
+ stream->writeInt(mSamplersPS[i].active);
+ stream->writeInt(mSamplersPS[i].logicalTextureUnit);
+ stream->writeInt(mSamplersPS[i].textureType);
+ }
+
+ stream->writeInt(mSamplersVS.size());
+ for (unsigned int i = 0; i < mSamplersVS.size(); ++i)
+ {
+ stream->writeInt(mSamplersVS[i].active);
+ stream->writeInt(mSamplersVS[i].logicalTextureUnit);
+ stream->writeInt(mSamplersVS[i].textureType);
+ }
+
+ stream->writeInt(mUsedVertexSamplerRange);
+ stream->writeInt(mUsedPixelSamplerRange);
+
+ stream->writeInt(mUniforms.size());
+ for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); ++uniformIndex)
+ {
+ const gl::LinkedUniform &uniform = *mUniforms[uniformIndex];
+
+ stream->writeInt(uniform.type);
+ stream->writeInt(uniform.precision);
+ stream->writeString(uniform.name);
+ stream->writeInt(uniform.arraySize);
+ stream->writeInt(uniform.blockIndex);
+
+ stream->writeInt(uniform.blockInfo.offset);
+ stream->writeInt(uniform.blockInfo.arrayStride);
+ stream->writeInt(uniform.blockInfo.matrixStride);
+ stream->writeInt(uniform.blockInfo.isRowMajorMatrix);
+
+ stream->writeInt(uniform.psRegisterIndex);
+ stream->writeInt(uniform.vsRegisterIndex);
+ stream->writeInt(uniform.registerCount);
+ stream->writeInt(uniform.registerElement);
+ }
+
+ stream->writeInt(mUniformIndex.size());
+ for (size_t i = 0; i < mUniformIndex.size(); ++i)
+ {
+ stream->writeString(mUniformIndex[i].name);
+ stream->writeInt(mUniformIndex[i].element);
+ stream->writeInt(mUniformIndex[i].index);
+ }
+
+ stream->writeInt(mUniformBlocks.size());
+ for (size_t uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); ++uniformBlockIndex)
+ {
+ const gl::UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex];
+
+ stream->writeString(uniformBlock.name);
+ stream->writeInt(uniformBlock.elementIndex);
+ stream->writeInt(uniformBlock.dataSize);
+
+ stream->writeInt(uniformBlock.memberUniformIndexes.size());
+ for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++)
+ {
+ stream->writeInt(uniformBlock.memberUniformIndexes[blockMemberIndex]);
+ }
+
+ stream->writeInt(uniformBlock.psRegisterIndex);
+ stream->writeInt(uniformBlock.vsRegisterIndex);
+ }
+
+ stream->writeInt(mTransformFeedbackBufferMode);
+ stream->writeInt(mTransformFeedbackLinkedVaryings.size());
+ for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++)
+ {
+ const gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i];
+
+ stream->writeString(varying.name);
+ stream->writeInt(varying.type);
+ stream->writeInt(varying.size);
+ stream->writeString(varying.semanticName);
+ stream->writeInt(varying.semanticIndex);
+ stream->writeInt(varying.semanticIndexCount);
+ }
+
stream->writeString(mVertexHLSL);
stream->writeInt(mVertexWorkarounds);
stream->writeString(mPixelHLSL);
stream->writeInt(mPixelWorkarounds);
stream->writeInt(mUsesFragDepth);
+ stream->writeInt(mUsesPointSize);
- const std::vector<rx::PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey;
+ const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey;
stream->writeInt(pixelShaderKey.size());
for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKey.size(); pixelShaderKeyIndex++)
{
- const rx::PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex];
+ const PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex];
stream->writeInt(variable.type);
stream->writeString(variable.name);
stream->writeString(variable.source);
stream->writeInt(variable.outputIndex);
}
- return true;
+ stream->writeInt(mVertexExecutables.size());
+ for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size(); vertexExecutableIndex++)
+ {
+ VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex];
+
+ for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++)
+ {
+ const gl::VertexFormat &vertexInput = vertexExecutable->inputs()[inputIndex];
+ stream->writeInt(vertexInput.mType);
+ stream->writeInt(vertexInput.mNormalized);
+ stream->writeInt(vertexInput.mComponents);
+ stream->writeInt(vertexInput.mPureInteger);
+ }
+
+ size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
+ stream->writeInt(vertexShaderSize);
+
+ const uint8_t *vertexBlob = vertexExecutable->shaderExecutable()->getFunction();
+ stream->writeBytes(vertexBlob, vertexShaderSize);
+ }
+
+ stream->writeInt(mPixelExecutables.size());
+ for (size_t pixelExecutableIndex = 0; pixelExecutableIndex < mPixelExecutables.size(); pixelExecutableIndex++)
+ {
+ PixelExecutable *pixelExecutable = mPixelExecutables[pixelExecutableIndex];
+
+ const std::vector<GLenum> outputs = pixelExecutable->outputSignature();
+ stream->writeInt(outputs.size());
+ for (size_t outputIndex = 0; outputIndex < outputs.size(); outputIndex++)
+ {
+ stream->writeInt(outputs[outputIndex]);
+ }
+
+ size_t pixelShaderSize = pixelExecutable->shaderExecutable()->getLength();
+ stream->writeInt(pixelShaderSize);
+
+ const uint8_t *pixelBlob = pixelExecutable->shaderExecutable()->getFunction();
+ stream->writeBytes(pixelBlob, pixelShaderSize);
+ }
+
+ size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
+ stream->writeInt(geometryShaderSize);
+
+ if (mGeometryExecutable != NULL && geometryShaderSize > 0)
+ {
+ const uint8_t *geometryBlob = mGeometryExecutable->getFunction();
+ stream->writeBytes(geometryBlob, geometryShaderSize);
+ }
+
+ GUID binaryIdentifier = mRenderer->getAdapterIdentifier();
+ stream->writeBytes(reinterpret_cast<unsigned char*>(&binaryIdentifier), sizeof(GUID));
+
+ return gl::Error(GL_NO_ERROR);
}
-rx::ShaderExecutable *ProgramD3D::getPixelExecutableForOutputLayout(gl::InfoLog &infoLog, const std::vector<GLenum> &outputSignature,
- const std::vector<gl::LinkedVarying> &transformFeedbackLinkedVaryings,
- bool separatedOutputBuffers)
+gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutable **outExecutable)
{
+ std::vector<GLenum> outputs;
+
+ const gl::ColorbufferInfo &colorbuffers = fbo->getColorbuffersForRender(mRenderer->getWorkarounds());
+
+ for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment)
+ {
+ const gl::FramebufferAttachment *colorbuffer = colorbuffers[colorAttachment];
+
+ if (colorbuffer)
+ {
+ outputs.push_back(colorbuffer->getBinding() == GL_BACK ? GL_COLOR_ATTACHMENT0 : colorbuffer->getBinding());
+ }
+ else
+ {
+ outputs.push_back(GL_NONE);
+ }
+ }
+
+ return getPixelExecutableForOutputLayout(outputs, outExecutable);
+}
+
+gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputSignature, ShaderExecutable **outExectuable)
+{
+ for (size_t executableIndex = 0; executableIndex < mPixelExecutables.size(); executableIndex++)
+ {
+ if (mPixelExecutables[executableIndex]->matchesSignature(outputSignature))
+ {
+ *outExectuable = mPixelExecutables[executableIndex]->shaderExecutable();
+ return gl::Error(GL_NO_ERROR);
+ }
+ }
+
std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(mPixelHLSL, mPixelShaderKey, mUsesFragDepth,
outputSignature);
// Generate new pixel executable
- rx::ShaderExecutable *pixelExecutable = mRenderer->compileToExecutable(infoLog, finalPixelHLSL.c_str(), rx::SHADER_PIXEL,
- transformFeedbackLinkedVaryings, separatedOutputBuffers,
- mPixelWorkarounds);
+ gl::InfoLog tempInfoLog;
+ ShaderExecutable *pixelExecutable = NULL;
+ gl::Error error = mRenderer->compileToExecutable(tempInfoLog, finalPixelHLSL, SHADER_PIXEL,
+ mTransformFeedbackLinkedVaryings,
+ (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
+ mPixelWorkarounds, &pixelExecutable);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!pixelExecutable)
+ {
+ std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3);
+ tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]);
+ ERR("Error compiling dynamic pixel executable:\n%s\n", &tempCharBuffer[0]);
+ }
+ else
+ {
+ mPixelExecutables.push_back(new PixelExecutable(outputSignature, pixelExecutable));
+ }
- return pixelExecutable;
+ *outExectuable = pixelExecutable;
+ return gl::Error(GL_NO_ERROR);
}
-rx::ShaderExecutable *ProgramD3D::getVertexExecutableForInputLayout(gl::InfoLog &infoLog,
- const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
- const sh::Attribute shaderAttributes[],
- const std::vector<gl::LinkedVarying> &transformFeedbackLinkedVaryings,
- bool separatedOutputBuffers)
+gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS], ShaderExecutable **outExectuable)
{
+ GLenum signature[gl::MAX_VERTEX_ATTRIBS];
+ getInputLayoutSignature(inputLayout, signature);
+
+ for (size_t executableIndex = 0; executableIndex < mVertexExecutables.size(); executableIndex++)
+ {
+ if (mVertexExecutables[executableIndex]->matchesSignature(signature))
+ {
+ *outExectuable = mVertexExecutables[executableIndex]->shaderExecutable();
+ return gl::Error(GL_NO_ERROR);
+ }
+ }
+
// Generate new dynamic layout with attribute conversions
- std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(mVertexHLSL, inputLayout, shaderAttributes);
+ std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(mVertexHLSL, inputLayout, mShaderAttributes);
// Generate new vertex executable
- rx::ShaderExecutable *vertexExecutable = mRenderer->compileToExecutable(infoLog, finalVertexHLSL.c_str(),
- rx::SHADER_VERTEX,
- transformFeedbackLinkedVaryings, separatedOutputBuffers,
- mVertexWorkarounds);
+ gl::InfoLog tempInfoLog;
+ ShaderExecutable *vertexExecutable = NULL;
+ gl::Error error = mRenderer->compileToExecutable(tempInfoLog, finalVertexHLSL, SHADER_VERTEX,
+ mTransformFeedbackLinkedVaryings,
+ (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
+ mVertexWorkarounds, &vertexExecutable);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!vertexExecutable)
+ {
+ std::vector<char> tempCharBuffer(tempInfoLog.getLength()+3);
+ tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]);
+ ERR("Error compiling dynamic vertex executable:\n%s\n", &tempCharBuffer[0]);
+ }
+ else
+ {
+ mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, vertexExecutable));
+ }
+
+ *outExectuable = vertexExecutable;
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
+ int registers)
+{
+ ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader->getImplementation());
+ ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader->getImplementation());
+
+ gl::VertexFormat defaultInputLayout[gl::MAX_VERTEX_ATTRIBS];
+ GetDefaultInputLayoutFromShader(vertexShader->getActiveAttributes(), defaultInputLayout);
+ ShaderExecutable *defaultVertexExecutable = NULL;
+ gl::Error error = getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable);
+ if (error.isError())
+ {
+ return gl::LinkResult(false, error);
+ }
+
+ std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey());
+ ShaderExecutable *defaultPixelExecutable = NULL;
+ error = getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable);
+ if (error.isError())
+ {
+ return gl::LinkResult(false, error);
+ }
+
+ if (usesGeometryShader())
+ {
+ std::string geometryHLSL = mDynamicHLSL->generateGeometryShaderHLSL(registers, fragmentShaderD3D, vertexShaderD3D);
+
+
+ error = mRenderer->compileToExecutable(infoLog, geometryHLSL, SHADER_GEOMETRY, mTransformFeedbackLinkedVaryings,
+ (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
+ ANGLE_D3D_WORKAROUND_NONE, &mGeometryExecutable);
+ if (error.isError())
+ {
+ return gl::LinkResult(false, error);
+ }
+ }
+
+#if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED
+ if (usesGeometryShader() && mGeometryExecutable)
+ {
+ // Geometry shaders are currently only used internally, so there is no corresponding shader object at the interface level
+ // For now the geometry shader debug info is pre-pended to the vertex shader, this is a bit of a clutch
+ vertexShaderD3D->appendDebugInfo("// GEOMETRY SHADER BEGIN\n\n");
+ vertexShaderD3D->appendDebugInfo(mGeometryExecutable->getDebugInfo());
+ vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n");
+ }
+
+ if (defaultVertexExecutable)
+ {
+ vertexShaderD3D->appendDebugInfo(defaultVertexExecutable->getDebugInfo());
+ }
+
+ if (defaultPixelExecutable)
+ {
+ fragmentShaderD3D->appendDebugInfo(defaultPixelExecutable->getDebugInfo());
+ }
+#endif
- return vertexExecutable;
+ bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable && (!usesGeometryShader() || mGeometryExecutable));
+ return gl::LinkResult(linkSuccess, gl::Error(GL_NO_ERROR));
}
-bool ProgramD3D::link(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
- const std::vector<std::string> &transformFeedbackVaryings, int *registers,
- std::vector<gl::LinkedVarying> *linkedVaryings, std::map<int, gl::VariableLocation> *outputVariables)
+gl::LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog,
+ gl::Shader *fragmentShader, gl::Shader *vertexShader,
+ const std::vector<std::string> &transformFeedbackVaryings,
+ GLenum transformFeedbackBufferMode,
+ int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
+ std::map<int, gl::VariableLocation> *outputVariables)
{
- rx::ShaderD3D *vertexShaderD3D = rx::ShaderD3D::makeShaderD3D(vertexShader->getImplementation());
- rx::ShaderD3D *fragmentShaderD3D = rx::ShaderD3D::makeShaderD3D(fragmentShader->getImplementation());
+ ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader->getImplementation());
+ ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader->getImplementation());
+
+ mSamplersPS.resize(data.caps->maxTextureImageUnits);
+ mSamplersVS.resize(data.caps->maxVertexTextureImageUnits);
+
+ mTransformFeedbackBufferMode = transformFeedbackBufferMode;
mPixelHLSL = fragmentShaderD3D->getTranslatedSource();
mPixelWorkarounds = fragmentShaderD3D->getD3DWorkarounds();
mVertexHLSL = vertexShaderD3D->getTranslatedSource();
mVertexWorkarounds = vertexShaderD3D->getD3DWorkarounds();
+ mShaderVersion = vertexShaderD3D->getShaderVersion();
// Map the varyings to the register file
- rx::VaryingPacking packing = { NULL };
+ VaryingPacking packing = { NULL };
*registers = mDynamicHLSL->packVaryings(infoLog, packing, fragmentShaderD3D, vertexShaderD3D, transformFeedbackVaryings);
if (*registers < 0)
{
- return false;
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
}
if (!gl::ProgramBinary::linkVaryings(infoLog, fragmentShader, vertexShader))
{
- return false;
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
}
- if (!mDynamicHLSL->generateShaderLinkHLSL(infoLog, *registers, packing, mPixelHLSL, mVertexHLSL,
+ if (!mDynamicHLSL->generateShaderLinkHLSL(data, infoLog, *registers, packing, mPixelHLSL, mVertexHLSL,
fragmentShaderD3D, vertexShaderD3D, transformFeedbackVaryings,
linkedVaryings, outputVariables, &mPixelShaderKey, &mUsesFragDepth))
{
- return false;
+ return gl::LinkResult(false, gl::Error(GL_NO_ERROR));
}
- return true;
+ mUsesPointSize = vertexShaderD3D->usesPointSize();
+
+ return gl::LinkResult(true, gl::Error(GL_NO_ERROR));
+}
+
+void ProgramD3D::getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const
+{
+ mDynamicHLSL->getInputLayoutSignature(inputLayout, signature);
}
-void ProgramD3D::initializeUniformStorage(const std::vector<gl::LinkedUniform*> &uniforms)
+void ProgramD3D::initializeUniformStorage()
{
// Compute total default block size
unsigned int vertexRegisters = 0;
unsigned int fragmentRegisters = 0;
- for (size_t uniformIndex = 0; uniformIndex < uniforms.size(); uniformIndex++)
+ for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
{
- const gl::LinkedUniform &uniform = *uniforms[uniformIndex];
+ const gl::LinkedUniform &uniform = *mUniforms[uniformIndex];
if (!gl::IsSampler(uniform.type))
{
@@ -188,18 +1059,867 @@ void ProgramD3D::initializeUniformStorage(const std::vector<gl::LinkedUniform*>
mFragmentUniformStorage = mRenderer->createUniformStorage(fragmentRegisters * 16u);
}
+gl::Error ProgramD3D::applyUniforms()
+{
+ updateSamplerMapping();
+
+ gl::Error error = mRenderer->applyUniforms(*this, mUniforms);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
+ {
+ mUniforms[uniformIndex]->dirty = false;
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error ProgramD3D::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const gl::Caps &caps)
+{
+ ASSERT(boundBuffers.size() == mUniformBlocks.size());
+
+ const gl::Buffer *vertexUniformBuffers[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS] = {NULL};
+ const gl::Buffer *fragmentUniformBuffers[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS] = {NULL};
+
+ const unsigned int reservedBuffersInVS = mRenderer->getReservedVertexUniformBuffers();
+ const unsigned int reservedBuffersInFS = mRenderer->getReservedFragmentUniformBuffers();
+
+ for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); uniformBlockIndex++)
+ {
+ gl::UniformBlock *uniformBlock = mUniformBlocks[uniformBlockIndex];
+ gl::Buffer *uniformBuffer = boundBuffers[uniformBlockIndex];
+
+ ASSERT(uniformBlock && uniformBuffer);
+
+ if (uniformBuffer->getSize() < uniformBlock->dataSize)
+ {
+ // undefined behaviour
+ return gl::Error(GL_INVALID_OPERATION, "It is undefined behaviour to use a uniform buffer that is too small.");
+ }
+
+ // Unnecessary to apply an unreferenced standard or shared UBO
+ if (!uniformBlock->isReferencedByVertexShader() && !uniformBlock->isReferencedByFragmentShader())
+ {
+ continue;
+ }
+
+ if (uniformBlock->isReferencedByVertexShader())
+ {
+ unsigned int registerIndex = uniformBlock->vsRegisterIndex - reservedBuffersInVS;
+ ASSERT(vertexUniformBuffers[registerIndex] == NULL);
+ ASSERT(registerIndex < caps.maxVertexUniformBlocks);
+ vertexUniformBuffers[registerIndex] = uniformBuffer;
+ }
+
+ if (uniformBlock->isReferencedByFragmentShader())
+ {
+ unsigned int registerIndex = uniformBlock->psRegisterIndex - reservedBuffersInFS;
+ ASSERT(fragmentUniformBuffers[registerIndex] == NULL);
+ ASSERT(registerIndex < caps.maxFragmentUniformBlocks);
+ fragmentUniformBuffers[registerIndex] = uniformBuffer;
+ }
+ }
+
+ return mRenderer->setUniformBuffers(vertexUniformBuffers, fragmentUniformBuffers);
+}
+
+bool ProgramD3D::assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
+ unsigned int registerIndex, const gl::Caps &caps)
+{
+ if (shader == GL_VERTEX_SHADER)
+ {
+ uniformBlock->vsRegisterIndex = registerIndex;
+ if (registerIndex - mRenderer->getReservedVertexUniformBuffers() >= caps.maxVertexUniformBlocks)
+ {
+ infoLog.append("Vertex shader uniform block count exceed GL_MAX_VERTEX_UNIFORM_BLOCKS (%u)", caps.maxVertexUniformBlocks);
+ return false;
+ }
+ }
+ else if (shader == GL_FRAGMENT_SHADER)
+ {
+ uniformBlock->psRegisterIndex = registerIndex;
+ if (registerIndex - mRenderer->getReservedFragmentUniformBuffers() >= caps.maxFragmentUniformBlocks)
+ {
+ infoLog.append("Fragment shader uniform block count exceed GL_MAX_FRAGMENT_UNIFORM_BLOCKS (%u)", caps.maxFragmentUniformBlocks);
+ return false;
+ }
+ }
+ else UNREACHABLE();
+
+ return true;
+}
+
+void ProgramD3D::dirtyAllUniforms()
+{
+ unsigned int numUniforms = mUniforms.size();
+ for (unsigned int index = 0; index < numUniforms; index++)
+ {
+ mUniforms[index]->dirty = true;
+ }
+}
+
+void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat* v)
+{
+ setUniform(location, count, v, GL_FLOAT);
+}
+
+void ProgramD3D::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
+{
+ setUniform(location, count, v, GL_FLOAT_VEC2);
+}
+
+void ProgramD3D::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
+{
+ setUniform(location, count, v, GL_FLOAT_VEC3);
+}
+
+void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
+{
+ setUniform(location, count, v, GL_FLOAT_VEC4);
+}
+
+void ProgramD3D::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2);
+}
+
+void ProgramD3D::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3);
+}
+
+void ProgramD3D::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4);
+}
+
+void ProgramD3D::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3);
+}
+
+void ProgramD3D::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2);
+}
+
+void ProgramD3D::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4);
+}
+
+void ProgramD3D::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2);
+}
+
+void ProgramD3D::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4);
+}
+
+void ProgramD3D::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
+{
+ setUniformMatrixfv<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3);
+}
+
+void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v)
+{
+ setUniform(location, count, v, GL_INT);
+}
+
+void ProgramD3D::setUniform2iv(GLint location, GLsizei count, const GLint *v)
+{
+ setUniform(location, count, v, GL_INT_VEC2);
+}
+
+void ProgramD3D::setUniform3iv(GLint location, GLsizei count, const GLint *v)
+{
+ setUniform(location, count, v, GL_INT_VEC3);
+}
+
+void ProgramD3D::setUniform4iv(GLint location, GLsizei count, const GLint *v)
+{
+ setUniform(location, count, v, GL_INT_VEC4);
+}
+
+void ProgramD3D::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ setUniform(location, count, v, GL_UNSIGNED_INT);
+}
+
+void ProgramD3D::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ setUniform(location, count, v, GL_UNSIGNED_INT_VEC2);
+}
+
+void ProgramD3D::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ setUniform(location, count, v, GL_UNSIGNED_INT_VEC3);
+}
+
+void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
+{
+ setUniform(location, count, v, GL_UNSIGNED_INT_VEC4);
+}
+
+void ProgramD3D::getUniformfv(GLint location, GLfloat *params)
+{
+ getUniformv(location, params, GL_FLOAT);
+}
+
+void ProgramD3D::getUniformiv(GLint location, GLint *params)
+{
+ getUniformv(location, params, GL_INT);
+}
+
+void ProgramD3D::getUniformuiv(GLint location, GLuint *params)
+{
+ getUniformv(location, params, GL_UNSIGNED_INT);
+}
+
+bool ProgramD3D::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader,
+ const gl::Caps &caps)
+{
+ const ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader.getImplementation());
+ const ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader.getImplementation());
+
+ const std::vector<sh::Uniform> &vertexUniforms = vertexShader.getUniforms();
+ const std::vector<sh::Uniform> &fragmentUniforms = fragmentShader.getUniforms();
+
+ // Check that uniforms defined in the vertex and fragment shaders are identical
+ typedef std::map<std::string, const sh::Uniform*> UniformMap;
+ UniformMap linkedUniforms;
+
+ for (unsigned int vertexUniformIndex = 0; vertexUniformIndex < vertexUniforms.size(); vertexUniformIndex++)
+ {
+ const sh::Uniform &vertexUniform = vertexUniforms[vertexUniformIndex];
+ linkedUniforms[vertexUniform.name] = &vertexUniform;
+ }
+
+ for (unsigned int fragmentUniformIndex = 0; fragmentUniformIndex < fragmentUniforms.size(); fragmentUniformIndex++)
+ {
+ const sh::Uniform &fragmentUniform = fragmentUniforms[fragmentUniformIndex];
+ UniformMap::const_iterator entry = linkedUniforms.find(fragmentUniform.name);
+ if (entry != linkedUniforms.end())
+ {
+ const sh::Uniform &vertexUniform = *entry->second;
+ const std::string &uniformName = "uniform '" + vertexUniform.name + "'";
+ if (!gl::ProgramBinary::linkValidateUniforms(infoLog, uniformName, vertexUniform, fragmentUniform))
+ {
+ return false;
+ }
+ }
+ }
+
+ for (unsigned int uniformIndex = 0; uniformIndex < vertexUniforms.size(); uniformIndex++)
+ {
+ const sh::Uniform &uniform = vertexUniforms[uniformIndex];
+
+ if (uniform.staticUse)
+ {
+ defineUniformBase(GL_VERTEX_SHADER, uniform, vertexShaderD3D->getUniformRegister(uniform.name));
+ }
+ }
+
+ for (unsigned int uniformIndex = 0; uniformIndex < fragmentUniforms.size(); uniformIndex++)
+ {
+ const sh::Uniform &uniform = fragmentUniforms[uniformIndex];
+
+ if (uniform.staticUse)
+ {
+ defineUniformBase(GL_FRAGMENT_SHADER, uniform, fragmentShaderD3D->getUniformRegister(uniform.name));
+ }
+ }
+
+ if (!indexUniforms(infoLog, caps))
+ {
+ return false;
+ }
+
+ initializeUniformStorage();
+
+ // special case for gl_DepthRange, the only built-in uniform (also a struct)
+ if (vertexShaderD3D->usesDepthRange() || fragmentShaderD3D->usesDepthRange())
+ {
+ const sh::BlockMemberInfo &defaultInfo = sh::BlockMemberInfo::getDefaultBlockInfo();
+
+ mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.near", 0, -1, defaultInfo));
+ mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.far", 0, -1, defaultInfo));
+ mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, defaultInfo));
+ }
+
+ return true;
+}
+
+void ProgramD3D::defineUniformBase(GLenum shader, const sh::Uniform &uniform, unsigned int uniformRegister)
+{
+ ShShaderOutput outputType = ShaderD3D::getCompilerOutputType(shader);
+ sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType));
+ encoder.skipRegisters(uniformRegister);
+
+ defineUniform(shader, uniform, uniform.name, &encoder);
+}
+
+void ProgramD3D::defineUniform(GLenum shader, const sh::ShaderVariable &uniform,
+ const std::string &fullName, sh::HLSLBlockEncoder *encoder)
+{
+ if (uniform.isStruct())
+ {
+ for (unsigned int elementIndex = 0; elementIndex < uniform.elementCount(); elementIndex++)
+ {
+ const std::string &elementString = (uniform.isArray() ? ArrayString(elementIndex) : "");
+
+ encoder->enterAggregateType();
+
+ for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
+ {
+ const sh::ShaderVariable &field = uniform.fields[fieldIndex];
+ const std::string &fieldFullName = (fullName + elementString + "." + field.name);
+
+ defineUniform(shader, field, fieldFullName, encoder);
+ }
+
+ encoder->exitAggregateType();
+ }
+ }
+ else // Not a struct
+ {
+ // Arrays are treated as aggregate types
+ if (uniform.isArray())
+ {
+ encoder->enterAggregateType();
+ }
+
+ gl::LinkedUniform *linkedUniform = getUniformByName(fullName);
+
+ if (!linkedUniform)
+ {
+ linkedUniform = new gl::LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize,
+ -1, sh::BlockMemberInfo::getDefaultBlockInfo());
+ ASSERT(linkedUniform);
+ linkedUniform->registerElement = encoder->getCurrentElement();
+ mUniforms.push_back(linkedUniform);
+ }
+
+ ASSERT(linkedUniform->registerElement == encoder->getCurrentElement());
+
+ if (shader == GL_FRAGMENT_SHADER)
+ {
+ linkedUniform->psRegisterIndex = encoder->getCurrentRegister();
+ }
+ else if (shader == GL_VERTEX_SHADER)
+ {
+ linkedUniform->vsRegisterIndex = encoder->getCurrentRegister();
+ }
+ else UNREACHABLE();
+
+ // Advance the uniform offset, to track registers allocation for structs
+ encoder->encodeType(uniform.type, uniform.arraySize, false);
+
+ // Arrays are treated as aggregate types
+ if (uniform.isArray())
+ {
+ encoder->exitAggregateType();
+ }
+ }
+}
+
+template <typename T>
+static inline void SetIfDirty(T *dest, const T& source, bool *dirtyFlag)
+{
+ ASSERT(dest != NULL);
+ ASSERT(dirtyFlag != NULL);
+
+ *dirtyFlag = *dirtyFlag || (memcmp(dest, &source, sizeof(T)) != 0);
+ *dest = source;
+}
+
+template <typename T>
+void ProgramD3D::setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType)
+{
+ const int components = gl::VariableComponentCount(targetUniformType);
+ const GLenum targetBoolType = gl::VariableBoolVectorType(targetUniformType);
+
+ gl::LinkedUniform *targetUniform = getUniformByLocation(location);
+
+ int elementCount = targetUniform->elementCount();
+
+ count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+
+ if (targetUniform->type == targetUniformType)
+ {
+ T *target = reinterpret_cast<T*>(targetUniform->data) + mUniformIndex[location].element * 4;
+
+ for (int i = 0; i < count; i++)
+ {
+ T *dest = target + (i * 4);
+ const T *source = v + (i * components);
+
+ for (int c = 0; c < components; c++)
+ {
+ SetIfDirty(dest + c, source[c], &targetUniform->dirty);
+ }
+ for (int c = components; c < 4; c++)
+ {
+ SetIfDirty(dest + c, T(0), &targetUniform->dirty);
+ }
+ }
+ }
+ else if (targetUniform->type == targetBoolType)
+ {
+ GLint *boolParams = reinterpret_cast<GLint*>(targetUniform->data) + mUniformIndex[location].element * 4;
+
+ for (int i = 0; i < count; i++)
+ {
+ GLint *dest = boolParams + (i * 4);
+ const T *source = v + (i * components);
+
+ for (int c = 0; c < components; c++)
+ {
+ SetIfDirty(dest + c, (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE, &targetUniform->dirty);
+ }
+ for (int c = components; c < 4; c++)
+ {
+ SetIfDirty(dest + c, GL_FALSE, &targetUniform->dirty);
+ }
+ }
+ }
+ else if (gl::IsSampler(targetUniform->type))
+ {
+ ASSERT(targetUniformType == GL_INT);
+
+ GLint *target = reinterpret_cast<GLint*>(targetUniform->data) + mUniformIndex[location].element * 4;
+
+ bool wasDirty = targetUniform->dirty;
+
+ for (int i = 0; i < count; i++)
+ {
+ GLint *dest = target + (i * 4);
+ const GLint *source = reinterpret_cast<const GLint*>(v) + (i * components);
+
+ SetIfDirty(dest + 0, source[0], &targetUniform->dirty);
+ SetIfDirty(dest + 1, 0, &targetUniform->dirty);
+ SetIfDirty(dest + 2, 0, &targetUniform->dirty);
+ SetIfDirty(dest + 3, 0, &targetUniform->dirty);
+ }
+
+ if (!wasDirty && targetUniform->dirty)
+ {
+ mDirtySamplerMapping = true;
+ }
+ }
+ else UNREACHABLE();
+}
+
+template<typename T>
+bool transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
+{
+ bool dirty = false;
+ int copyWidth = std::min(targetHeight, srcWidth);
+ int copyHeight = std::min(targetWidth, srcHeight);
+
+ for (int x = 0; x < copyWidth; x++)
+ {
+ for (int y = 0; y < copyHeight; y++)
+ {
+ SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]), &dirty);
+ }
+ }
+ // clear unfilled right side
+ for (int y = 0; y < copyWidth; y++)
+ {
+ for (int x = copyHeight; x < targetWidth; x++)
+ {
+ SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
+ }
+ }
+ // clear unfilled bottom.
+ for (int y = copyWidth; y < targetHeight; y++)
+ {
+ for (int x = 0; x < targetWidth; x++)
+ {
+ SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
+ }
+ }
+
+ return dirty;
+}
+
+template<typename T>
+bool expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
+{
+ bool dirty = false;
+ int copyWidth = std::min(targetWidth, srcWidth);
+ int copyHeight = std::min(targetHeight, srcHeight);
+
+ for (int y = 0; y < copyHeight; y++)
+ {
+ for (int x = 0; x < copyWidth; x++)
+ {
+ SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]), &dirty);
+ }
+ }
+ // clear unfilled right side
+ for (int y = 0; y < copyHeight; y++)
+ {
+ for (int x = copyWidth; x < targetWidth; x++)
+ {
+ SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
+ }
+ }
+ // clear unfilled bottom.
+ for (int y = copyHeight; y < targetHeight; y++)
+ {
+ for (int x = 0; x < targetWidth; x++)
+ {
+ SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
+ }
+ }
+
+ return dirty;
+}
+
+template <int cols, int rows>
+void ProgramD3D::setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType)
+{
+ gl::LinkedUniform *targetUniform = getUniformByLocation(location);
+
+ int elementCount = targetUniform->elementCount();
+
+ count = std::min(elementCount - (int)mUniformIndex[location].element, count);
+ const unsigned int targetMatrixStride = (4 * rows);
+ GLfloat *target = (GLfloat*)(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * targetMatrixStride);
+
+ for (int i = 0; i < count; i++)
+ {
+ // Internally store matrices as transposed versions to accomodate HLSL matrix indexing
+ if (transpose == GL_FALSE)
+ {
+ targetUniform->dirty = transposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) || targetUniform->dirty;
+ }
+ else
+ {
+ targetUniform->dirty = expandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty;
+ }
+ target += targetMatrixStride;
+ value += cols * rows;
+ }
+}
+
+template <typename T>
+void ProgramD3D::getUniformv(GLint location, T *params, GLenum uniformType)
+{
+ gl::LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
+
+ if (gl::IsMatrixType(targetUniform->type))
+ {
+ const int rows = gl::VariableRowCount(targetUniform->type);
+ const int cols = gl::VariableColumnCount(targetUniform->type);
+ transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4 * rows, rows, cols, 4, rows);
+ }
+ else if (uniformType == gl::VariableComponentType(targetUniform->type))
+ {
+ unsigned int size = gl::VariableComponentCount(targetUniform->type);
+ memcpy(params, targetUniform->data + mUniformIndex[location].element * 4 * sizeof(T),
+ size * sizeof(T));
+ }
+ else
+ {
+ unsigned int size = gl::VariableComponentCount(targetUniform->type);
+ switch (gl::VariableComponentType(targetUniform->type))
+ {
+ case GL_BOOL:
+ {
+ GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
+
+ for (unsigned int i = 0; i < size; i++)
+ {
+ params[i] = (boolParams[i] == GL_FALSE) ? static_cast<T>(0) : static_cast<T>(1);
+ }
+ }
+ break;
+
+ case GL_FLOAT:
+ {
+ GLfloat *floatParams = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
+
+ for (unsigned int i = 0; i < size; i++)
+ {
+ params[i] = static_cast<T>(floatParams[i]);
+ }
+ }
+ break;
+
+ case GL_INT:
+ {
+ GLint *intParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
+
+ for (unsigned int i = 0; i < size; i++)
+ {
+ params[i] = static_cast<T>(intParams[i]);
+ }
+ }
+ break;
+
+ case GL_UNSIGNED_INT:
+ {
+ GLuint *uintParams = (GLuint*)targetUniform->data + mUniformIndex[location].element * 4;
+
+ for (unsigned int i = 0; i < size; i++)
+ {
+ params[i] = static_cast<T>(uintParams[i]);
+ }
+ }
+ break;
+
+ default: UNREACHABLE();
+ }
+ }
+}
+
+template <typename VarT>
+void ProgramD3D::defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex,
+ sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes,
+ bool inRowMajorLayout)
+{
+ for (unsigned int uniformIndex = 0; uniformIndex < fields.size(); uniformIndex++)
+ {
+ const VarT &field = fields[uniformIndex];
+ const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name);
+
+ if (field.isStruct())
+ {
+ bool rowMajorLayout = (inRowMajorLayout || IsRowMajorLayout(field));
+
+ for (unsigned int arrayElement = 0; arrayElement < field.elementCount(); arrayElement++)
+ {
+ encoder->enterAggregateType();
+
+ const std::string uniformElementName = fieldName + (field.isArray() ? ArrayString(arrayElement) : "");
+ defineUniformBlockMembers(field.fields, uniformElementName, blockIndex, encoder, blockUniformIndexes, rowMajorLayout);
+
+ encoder->exitAggregateType();
+ }
+ }
+ else
+ {
+ bool isRowMajorMatrix = (gl::IsMatrixType(field.type) && inRowMajorLayout);
+
+ sh::BlockMemberInfo memberInfo = encoder->encodeType(field.type, field.arraySize, isRowMajorMatrix);
+
+ gl::LinkedUniform *newUniform = new gl::LinkedUniform(field.type, field.precision, fieldName, field.arraySize,
+ blockIndex, memberInfo);
+
+ // add to uniform list, but not index, since uniform block uniforms have no location
+ blockUniformIndexes->push_back(mUniforms.size());
+ mUniforms.push_back(newUniform);
+ }
+ }
+}
+
+bool ProgramD3D::defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock,
+ const gl::Caps &caps)
+{
+ const ShaderD3D* shaderD3D = ShaderD3D::makeShaderD3D(shader.getImplementation());
+
+ // create uniform block entries if they do not exist
+ if (getUniformBlockIndex(interfaceBlock.name) == GL_INVALID_INDEX)
+ {
+ std::vector<unsigned int> blockUniformIndexes;
+ const unsigned int blockIndex = mUniformBlocks.size();
+
+ // define member uniforms
+ sh::BlockLayoutEncoder *encoder = NULL;
+
+ if (interfaceBlock.layout == sh::BLOCKLAYOUT_STANDARD)
+ {
+ encoder = new sh::Std140BlockEncoder;
+ }
+ else
+ {
+ encoder = new sh::HLSLBlockEncoder(sh::HLSLBlockEncoder::ENCODE_PACKED);
+ }
+ ASSERT(encoder);
+
+ defineUniformBlockMembers(interfaceBlock.fields, "", blockIndex, encoder, &blockUniformIndexes, interfaceBlock.isRowMajorLayout);
+
+ size_t dataSize = encoder->getBlockSize();
+
+ // create all the uniform blocks
+ if (interfaceBlock.arraySize > 0)
+ {
+ for (unsigned int uniformBlockElement = 0; uniformBlockElement < interfaceBlock.arraySize; uniformBlockElement++)
+ {
+ gl::UniformBlock *newUniformBlock = new gl::UniformBlock(interfaceBlock.name, uniformBlockElement, dataSize);
+ newUniformBlock->memberUniformIndexes = blockUniformIndexes;
+ mUniformBlocks.push_back(newUniformBlock);
+ }
+ }
+ else
+ {
+ gl::UniformBlock *newUniformBlock = new gl::UniformBlock(interfaceBlock.name, GL_INVALID_INDEX, dataSize);
+ newUniformBlock->memberUniformIndexes = blockUniformIndexes;
+ mUniformBlocks.push_back(newUniformBlock);
+ }
+ }
+
+ if (interfaceBlock.staticUse)
+ {
+ // Assign registers to the uniform blocks
+ const GLuint blockIndex = getUniformBlockIndex(interfaceBlock.name);
+ const unsigned int elementCount = std::max(1u, interfaceBlock.arraySize);
+ ASSERT(blockIndex != GL_INVALID_INDEX);
+ ASSERT(blockIndex + elementCount <= mUniformBlocks.size());
+
+ unsigned int interfaceBlockRegister = shaderD3D->getInterfaceBlockRegister(interfaceBlock.name);
+
+ for (unsigned int uniformBlockElement = 0; uniformBlockElement < elementCount; uniformBlockElement++)
+ {
+ gl::UniformBlock *uniformBlock = mUniformBlocks[blockIndex + uniformBlockElement];
+ ASSERT(uniformBlock->name == interfaceBlock.name);
+
+ if (!assignUniformBlockRegister(infoLog, uniformBlock, shader.getType(),
+ interfaceBlockRegister + uniformBlockElement, caps))
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool ProgramD3D::assignSamplers(unsigned int startSamplerIndex,
+ GLenum samplerType,
+ unsigned int samplerCount,
+ std::vector<Sampler> &outSamplers,
+ GLuint *outUsedRange)
+{
+ unsigned int samplerIndex = startSamplerIndex;
+
+ do
+ {
+ if (samplerIndex < outSamplers.size())
+ {
+ Sampler& sampler = outSamplers[samplerIndex];
+ sampler.active = true;
+ sampler.textureType = GetTextureType(samplerType);
+ sampler.logicalTextureUnit = 0;
+ *outUsedRange = std::max(samplerIndex + 1, *outUsedRange);
+ }
+ else
+ {
+ return false;
+ }
+
+ samplerIndex++;
+ } while (samplerIndex < startSamplerIndex + samplerCount);
+
+ return true;
+}
+
+bool ProgramD3D::indexSamplerUniform(const gl::LinkedUniform &uniform, gl::InfoLog &infoLog, const gl::Caps &caps)
+{
+ ASSERT(gl::IsSampler(uniform.type));
+ ASSERT(uniform.vsRegisterIndex != GL_INVALID_INDEX || uniform.psRegisterIndex != GL_INVALID_INDEX);
+
+ if (uniform.vsRegisterIndex != GL_INVALID_INDEX)
+ {
+ if (!assignSamplers(uniform.vsRegisterIndex, uniform.type, uniform.arraySize, mSamplersVS,
+ &mUsedVertexSamplerRange))
+ {
+ infoLog.append("Vertex shader sampler count exceeds the maximum vertex texture units (%d).",
+ mSamplersVS.size());
+ return false;
+ }
+
+ unsigned int maxVertexVectors = mRenderer->getReservedVertexUniformVectors() + caps.maxVertexUniformVectors;
+ if (uniform.vsRegisterIndex + uniform.registerCount > maxVertexVectors)
+ {
+ infoLog.append("Vertex shader active uniforms exceed GL_MAX_VERTEX_UNIFORM_VECTORS (%u)",
+ caps.maxVertexUniformVectors);
+ return false;
+ }
+ }
+
+ if (uniform.psRegisterIndex != GL_INVALID_INDEX)
+ {
+ if (!assignSamplers(uniform.psRegisterIndex, uniform.type, uniform.arraySize, mSamplersPS,
+ &mUsedPixelSamplerRange))
+ {
+ infoLog.append("Pixel shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS (%d).",
+ mSamplersPS.size());
+ return false;
+ }
+
+ unsigned int maxFragmentVectors = mRenderer->getReservedFragmentUniformVectors() + caps.maxFragmentUniformVectors;
+ if (uniform.psRegisterIndex + uniform.registerCount > maxFragmentVectors)
+ {
+ infoLog.append("Fragment shader active uniforms exceed GL_MAX_FRAGMENT_UNIFORM_VECTORS (%u)",
+ caps.maxFragmentUniformVectors);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool ProgramD3D::indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps)
+{
+ for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
+ {
+ const gl::LinkedUniform &uniform = *mUniforms[uniformIndex];
+
+ if (gl::IsSampler(uniform.type))
+ {
+ if (!indexSamplerUniform(uniform, infoLog, caps))
+ {
+ return false;
+ }
+ }
+
+ for (unsigned int arrayElementIndex = 0; arrayElementIndex < uniform.elementCount(); arrayElementIndex++)
+ {
+ mUniformIndex.push_back(gl::VariableLocation(uniform.name, arrayElementIndex, uniformIndex));
+ }
+ }
+
+ return true;
+}
+
void ProgramD3D::reset()
{
+ ProgramImpl::reset();
+
+ SafeDeleteContainer(mVertexExecutables);
+ SafeDeleteContainer(mPixelExecutables);
+ SafeDelete(mGeometryExecutable);
+
+ mTransformFeedbackBufferMode = GL_NONE;
+
mVertexHLSL.clear();
- mVertexWorkarounds = rx::ANGLE_D3D_WORKAROUND_NONE;
+ mVertexWorkarounds = ANGLE_D3D_WORKAROUND_NONE;
+ mShaderVersion = 100;
mPixelHLSL.clear();
- mPixelWorkarounds = rx::ANGLE_D3D_WORKAROUND_NONE;
+ mPixelWorkarounds = ANGLE_D3D_WORKAROUND_NONE;
mUsesFragDepth = false;
mPixelShaderKey.clear();
+ mUsesPointSize = false;
SafeDelete(mVertexUniformStorage);
SafeDelete(mFragmentUniformStorage);
+
+ mSamplersPS.clear();
+ mSamplersVS.clear();
+
+ mUsedVertexSamplerRange = 0;
+ mUsedPixelSamplerRange = 0;
+ mDirtySamplerMapping = true;
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.h
index d645c57daa..4baab9aa19 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ProgramD3D.h
@@ -10,6 +10,7 @@
#define LIBGLESV2_RENDERER_PROGRAMD3D_H_
#include "libGLESv2/renderer/ProgramImpl.h"
+#include "libGLESv2/renderer/Workarounds.h"
#include <string>
#include <vector>
@@ -23,63 +24,194 @@ struct VertexFormat;
namespace rx
{
-
+class RendererD3D;
class UniformStorage;
class ProgramD3D : public ProgramImpl
{
public:
- ProgramD3D(rx::Renderer *renderer);
+ ProgramD3D(RendererD3D *renderer);
virtual ~ProgramD3D();
static ProgramD3D *makeProgramD3D(ProgramImpl *impl);
static const ProgramD3D *makeProgramD3D(const ProgramImpl *impl);
- Renderer *getRenderer() { return mRenderer; }
- DynamicHLSL *getDynamicHLSL() { return mDynamicHLSL; }
- const std::vector<rx::PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
-
- GLenum getBinaryFormat() { return GL_PROGRAM_BINARY_ANGLE; }
- bool load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream);
- bool save(gl::BinaryOutputStream *stream);
+ const std::vector<PixelShaderOutputVariable> &getPixelShaderKey() { return mPixelShaderKey; }
+ int getShaderVersion() const { return mShaderVersion; }
+ GLenum getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; }
- ShaderExecutable *getPixelExecutableForOutputLayout(gl::InfoLog &infoLog, const std::vector<GLenum> &outputSignature,
- const std::vector<gl::LinkedVarying> &transformFeedbackLinkedVaryings,
- bool separatedOutputBuffers);
- ShaderExecutable *getVertexExecutableForInputLayout(gl::InfoLog &infoLog,
- const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
- const sh::Attribute shaderAttributes[],
- const std::vector<gl::LinkedVarying> &transformFeedbackLinkedVaryings,
- bool separatedOutputBuffers);
+ GLint getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const;
+ GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const;
+ GLint getUsedSamplerRange(gl::SamplerType type) const;
+ void updateSamplerMapping();
+ bool validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps);
- bool link(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
- const std::vector<std::string> &transformFeedbackVaryings, int *registers,
- std::vector<gl::LinkedVarying> *linkedVaryings, std::map<int, gl::VariableLocation> *outputVariables);
+ bool usesPointSize() const { return mUsesPointSize; }
+ bool usesPointSpriteEmulation() const;
+ bool usesGeometryShader() const;
- // D3D only
- void initializeUniformStorage(const std::vector<gl::LinkedUniform*> &uniforms);
+ GLenum getBinaryFormat() { return GL_PROGRAM_BINARY_ANGLE; }
+ gl::LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream);
+ gl::Error save(gl::BinaryOutputStream *stream);
+
+ gl::Error getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutable **outExectuable);
+ gl::Error getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputLayout, ShaderExecutable **outExectuable);
+ gl::Error getVertexExecutableForInputLayout(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS], ShaderExecutable **outExectuable);
+ ShaderExecutable *getGeometryExecutable() const { return mGeometryExecutable; }
+
+ gl::LinkResult compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
+ int registers);
+
+ gl::LinkResult link(const gl::Data &data, gl::InfoLog &infoLog,
+ gl::Shader *fragmentShader, gl::Shader *vertexShader,
+ const std::vector<std::string> &transformFeedbackVaryings,
+ GLenum transformFeedbackBufferMode,
+ int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
+ std::map<int, gl::VariableLocation> *outputVariables);
+
+ void getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const;
+
+ void initializeUniformStorage();
+ gl::Error applyUniforms();
+ gl::Error applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const gl::Caps &caps);
+ bool assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
+ unsigned int registerIndex, const gl::Caps &caps);
+ void dirtyAllUniforms();
+
+ void setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
+ void setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
+ void setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
+ void setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
+ void setUniform1iv(GLint location, GLsizei count, const GLint *v);
+ void setUniform2iv(GLint location, GLsizei count, const GLint *v);
+ void setUniform3iv(GLint location, GLsizei count, const GLint *v);
+ void setUniform4iv(GLint location, GLsizei count, const GLint *v);
+ void setUniform1uiv(GLint location, GLsizei count, const GLuint *v);
+ void setUniform2uiv(GLint location, GLsizei count, const GLuint *v);
+ void setUniform3uiv(GLint location, GLsizei count, const GLuint *v);
+ void setUniform4uiv(GLint location, GLsizei count, const GLuint *v);
+ void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+ void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+
+ void getUniformfv(GLint location, GLfloat *params);
+ void getUniformiv(GLint location, GLint *params);
+ void getUniformuiv(GLint location, GLuint *params);
const UniformStorage &getVertexUniformStorage() const { return *mVertexUniformStorage; }
const UniformStorage &getFragmentUniformStorage() const { return *mFragmentUniformStorage; }
+ bool linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader,
+ const gl::Caps &caps);
+ bool defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock, const gl::Caps &caps);
+
void reset();
private:
DISALLOW_COPY_AND_ASSIGN(ProgramD3D);
- Renderer *mRenderer;
+ class VertexExecutable
+ {
+ public:
+ VertexExecutable(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS],
+ const GLenum signature[gl::MAX_VERTEX_ATTRIBS],
+ ShaderExecutable *shaderExecutable);
+ ~VertexExecutable();
+
+ bool matchesSignature(const GLenum convertedLayout[gl::MAX_VERTEX_ATTRIBS]) const;
+
+ const gl::VertexFormat *inputs() const { return mInputs; }
+ const GLenum *signature() const { return mSignature; }
+ ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
+
+ private:
+ gl::VertexFormat mInputs[gl::MAX_VERTEX_ATTRIBS];
+ GLenum mSignature[gl::MAX_VERTEX_ATTRIBS];
+ ShaderExecutable *mShaderExecutable;
+ };
+
+ class PixelExecutable
+ {
+ public:
+ PixelExecutable(const std::vector<GLenum> &outputSignature, ShaderExecutable *shaderExecutable);
+ ~PixelExecutable();
+
+ bool matchesSignature(const std::vector<GLenum> &signature) const { return mOutputSignature == signature; }
+
+ const std::vector<GLenum> &outputSignature() const { return mOutputSignature; }
+ ShaderExecutable *shaderExecutable() const { return mShaderExecutable; }
+
+ private:
+ std::vector<GLenum> mOutputSignature;
+ ShaderExecutable *mShaderExecutable;
+ };
+
+ struct Sampler
+ {
+ Sampler();
+
+ bool active;
+ GLint logicalTextureUnit;
+ GLenum textureType;
+ };
+
+ void defineUniformBase(GLenum shader, const sh::Uniform &uniform, unsigned int uniformRegister);
+ void defineUniform(GLenum shader, const sh::ShaderVariable &uniform, const std::string &fullName,
+ sh::HLSLBlockEncoder *encoder);
+ bool indexSamplerUniform(const gl::LinkedUniform &uniform, gl::InfoLog &infoLog, const gl::Caps &caps);
+ bool indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps);
+ static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount,
+ std::vector<Sampler> &outSamplers, GLuint *outUsedRange);
+
+ template <typename T>
+ void setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType);
+
+ template <int cols, int rows>
+ void setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType);
+
+ template <typename T>
+ void getUniformv(GLint location, T *params, GLenum uniformType);
+
+ template <typename VarT>
+ void defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex,
+ sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes,
+ bool inRowMajorLayout);
+
+ RendererD3D *mRenderer;
DynamicHLSL *mDynamicHLSL;
+ std::vector<VertexExecutable *> mVertexExecutables;
+ std::vector<PixelExecutable *> mPixelExecutables;
+ ShaderExecutable *mGeometryExecutable;
+
std::string mVertexHLSL;
- rx::D3DWorkaroundType mVertexWorkarounds;
+ D3DWorkaroundType mVertexWorkarounds;
std::string mPixelHLSL;
- rx::D3DWorkaroundType mPixelWorkarounds;
+ D3DWorkaroundType mPixelWorkarounds;
bool mUsesFragDepth;
- std::vector<rx::PixelShaderOutputVariable> mPixelShaderKey;
+ std::vector<PixelShaderOutputVariable> mPixelShaderKey;
+
+ bool mUsesPointSize;
UniformStorage *mVertexUniformStorage;
UniformStorage *mFragmentUniformStorage;
+
+ GLenum mTransformFeedbackBufferMode;
+
+ std::vector<Sampler> mSamplersPS;
+ std::vector<Sampler> mSamplersVS;
+ GLuint mUsedVertexSamplerRange;
+ GLuint mUsedPixelSamplerRange;
+ bool mDirtySamplerMapping;
+
+ int mShaderVersion;
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.cpp
new file mode 100644
index 0000000000..cb4af367a2
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.cpp
@@ -0,0 +1,108 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// RenderbufferD3d.cpp: Implements the RenderbufferD3D class, a specialization of RenderbufferImpl
+
+
+#include "libGLESv2/renderer/d3d/RenderbufferD3D.h"
+
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
+#include "libGLESv2/renderer/RenderTarget.h"
+
+namespace rx
+{
+RenderbufferD3D::RenderbufferD3D(RendererD3D *renderer) : mRenderer(renderer)
+{
+ mRenderTarget = NULL;
+}
+
+RenderbufferD3D::~RenderbufferD3D()
+{
+ SafeDelete(mRenderTarget);
+}
+
+RenderbufferD3D *RenderbufferD3D::makeRenderbufferD3D(RenderbufferImpl *renderbuffer)
+{
+ ASSERT(HAS_DYNAMIC_TYPE(RenderbufferD3D*, renderbuffer));
+ return static_cast<RenderbufferD3D*>(renderbuffer);
+}
+
+gl::Error RenderbufferD3D::setStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples)
+{
+ // If the renderbuffer parameters are queried, the calling function
+ // will expect one of the valid renderbuffer formats for use in
+ // glRenderbufferStorage, but we should create depth and stencil buffers
+ // as DEPTH24_STENCIL8
+ GLenum creationFormat = internalformat;
+ if (internalformat == GL_DEPTH_COMPONENT16 || internalformat == GL_STENCIL_INDEX8)
+ {
+ creationFormat = GL_DEPTH24_STENCIL8_OES;
+ }
+
+ RenderTarget *newRT = NULL;
+ gl::Error error = mRenderer->createRenderTarget(width, height, creationFormat, samples, &newRT);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ SafeDelete(mRenderTarget);
+ mRenderTarget = newRT;
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error RenderbufferD3D::setStorage(SwapChain *swapChain, bool depth)
+{
+ RenderTarget *newRT = NULL;
+ gl::Error error = mRenderer->createRenderTarget(swapChain, depth, &newRT);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ SafeDelete(mRenderTarget);
+ mRenderTarget = newRT;
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+GLsizei RenderbufferD3D::getWidth() const
+{
+ return (mRenderTarget ? mRenderTarget->getWidth() : 0);
+}
+
+GLsizei RenderbufferD3D::getHeight() const
+{
+ return (mRenderTarget ? mRenderTarget->getHeight() : 0);
+}
+
+GLenum RenderbufferD3D::getInternalFormat() const
+{
+ return (mRenderTarget ? mRenderTarget->getInternalFormat() : GL_RGBA4);
+}
+
+GLenum RenderbufferD3D::getActualFormat() const
+{
+ return (mRenderTarget ? mRenderTarget->getActualFormat() : GL_RGBA4);
+}
+
+GLsizei RenderbufferD3D::getSamples() const
+{
+ return (mRenderTarget ? mRenderTarget->getSamples() : 0);
+}
+
+RenderTarget *RenderbufferD3D::getRenderTarget()
+{
+ return mRenderTarget;
+}
+
+unsigned int RenderbufferD3D::getRenderTargetSerial() const
+{
+ return (mRenderTarget ? mRenderTarget->getSerial() : 0);
+}
+
+}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.h
new file mode 100644
index 0000000000..9440a449f2
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RenderbufferD3D.h
@@ -0,0 +1,51 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// RenderbufferD3d.h: Defines the RenderbufferD3D class which implements RenderbufferImpl.
+
+#ifndef LIBGLESV2_RENDERER_RENDERBUFFERD3D_H_
+#define LIBGLESV2_RENDERER_RENDERBUFFERD3D_H_
+
+#include "angle_gl.h"
+
+#include "common/angleutils.h"
+#include "libGLESv2/renderer/RenderbufferImpl.h"
+
+namespace rx
+{
+class RendererD3D;
+class RenderTarget;
+class SwapChain;
+
+class RenderbufferD3D : public RenderbufferImpl
+{
+ public:
+ RenderbufferD3D(RendererD3D *renderer);
+ virtual ~RenderbufferD3D();
+
+ static RenderbufferD3D *makeRenderbufferD3D(RenderbufferImpl *renderbuffer);
+
+ virtual gl::Error setStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples) override;
+ gl::Error setStorage(SwapChain *swapChain, bool depth);
+
+ virtual GLsizei getWidth() const;
+ virtual GLsizei getHeight() const;
+ virtual GLenum getInternalFormat() const;
+ virtual GLenum getActualFormat() const;
+ virtual GLsizei getSamples() const;
+
+ RenderTarget *getRenderTarget();
+ unsigned int getRenderTargetSerial() const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RenderbufferD3D);
+
+ RendererD3D *mRenderer;
+ RenderTarget *mRenderTarget;
+};
+}
+
+#endif // LIBGLESV2_RENDERER_RENDERBUFFERD3D_H_
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.cpp
new file mode 100644
index 0000000000..97da6da7fd
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.cpp
@@ -0,0 +1,796 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// RendererD3D.cpp: Implementation of the base D3D Renderer.
+
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
+
+#include "libGLESv2/renderer/d3d/IndexDataManager.h"
+#include "libGLESv2/Framebuffer.h"
+#include "libGLESv2/FramebufferAttachment.h"
+#include "libGLESv2/ResourceManager.h"
+#include "libGLESv2/State.h"
+#include "libGLESv2/VertexArray.h"
+#include "libGLESv2/formatutils.h"
+#include "common/utilities.h"
+
+namespace rx
+{
+
+RendererD3D::RendererD3D(egl::Display *display)
+ : mDisplay(display)
+{
+}
+
+RendererD3D::~RendererD3D()
+{
+ for (gl::TextureMap::iterator i = mIncompleteTextures.begin(); i != mIncompleteTextures.end(); ++i)
+ {
+ i->second.set(NULL);
+ }
+ mIncompleteTextures.clear();
+}
+
+// static
+RendererD3D *RendererD3D::makeRendererD3D(Renderer *renderer)
+{
+ ASSERT(HAS_DYNAMIC_TYPE(RendererD3D*, renderer));
+ return static_cast<RendererD3D*>(renderer);
+}
+
+gl::Error RendererD3D::drawElements(const gl::Data &data,
+ GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices, GLsizei instances,
+ const RangeUI &indexRange)
+{
+ ASSERT(data.state->getCurrentProgramId() != 0);
+
+ gl::ProgramBinary *programBinary = data.state->getCurrentProgramBinary();
+ programBinary->updateSamplerMapping();
+
+ gl::Error error = generateSwizzles(data);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!applyPrimitiveType(mode, count))
+ {
+ return gl::Error(GL_NO_ERROR);
+ }
+
+ error = applyRenderTarget(data, mode, false);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyState(data, mode);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ gl::VertexArray *vao = data.state->getVertexArray();
+ TranslatedIndexData indexInfo;
+ indexInfo.indexRange = indexRange;
+ error = applyIndexBuffer(indices, vao->getElementArrayBuffer(), count, mode, type, &indexInfo);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ GLsizei vertexCount = indexInfo.indexRange.length() + 1;
+ error = applyVertexBuffer(*data.state, indexInfo.indexRange.start, vertexCount, instances);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ bool transformFeedbackActive = applyTransformFeedbackBuffers(data);
+ // Transform feedback is not allowed for DrawElements, this error should have been caught at the API validation
+ // layer.
+ ASSERT(!transformFeedbackActive);
+
+ error = applyShaders(data, transformFeedbackActive);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyTextures(data);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyUniformBuffers(data);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!skipDraw(data, mode))
+ {
+ error = drawElements(mode, count, type, indices, vao->getElementArrayBuffer(), indexInfo, instances);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error RendererD3D::drawArrays(const gl::Data &data,
+ GLenum mode, GLint first,
+ GLsizei count, GLsizei instances)
+{
+ ASSERT(data.state->getCurrentProgramId() != 0);
+
+ gl::ProgramBinary *programBinary = data.state->getCurrentProgramBinary();
+ programBinary->updateSamplerMapping();
+
+ gl::Error error = generateSwizzles(data);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!applyPrimitiveType(mode, count))
+ {
+ return gl::Error(GL_NO_ERROR);
+ }
+
+ error = applyRenderTarget(data, mode, false);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyState(data, mode);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyVertexBuffer(*data.state, first, count, instances);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ bool transformFeedbackActive = applyTransformFeedbackBuffers(data);
+
+ error = applyShaders(data, transformFeedbackActive);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyTextures(data);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyUniformBuffers(data);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!skipDraw(data, mode))
+ {
+ error = drawArrays(mode, count, instances, transformFeedbackActive);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (transformFeedbackActive)
+ {
+ markTransformFeedbackUsage(data);
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error RendererD3D::generateSwizzles(const gl::Data &data, gl::SamplerType type)
+{
+ gl::ProgramBinary *programBinary = data.state->getCurrentProgramBinary();
+
+ size_t samplerRange = programBinary->getUsedSamplerRange(type);
+
+ for (size_t i = 0; i < samplerRange; i++)
+ {
+ GLenum textureType = programBinary->getSamplerTextureType(type, i);
+ GLint textureUnit = programBinary->getSamplerMapping(type, i, *data.caps);
+ if (textureUnit != -1)
+ {
+ gl::Texture *texture = data.state->getSamplerTexture(textureUnit, textureType);
+ ASSERT(texture);
+ if (texture->getSamplerState().swizzleRequired())
+ {
+ gl::Error error = generateSwizzle(texture);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error RendererD3D::generateSwizzles(const gl::Data &data)
+{
+ gl::Error error = generateSwizzles(data, gl::SAMPLER_VERTEX);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = generateSwizzles(data, gl::SAMPLER_PIXEL);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+// Applies the render target surface, depth stencil surface, viewport rectangle and
+// scissor rectangle to the renderer
+gl::Error RendererD3D::applyRenderTarget(const gl::Data &data, GLenum drawMode, bool ignoreViewport)
+{
+ const gl::Framebuffer *framebufferObject = data.state->getDrawFramebuffer();
+ ASSERT(framebufferObject && framebufferObject->completeness(data) == GL_FRAMEBUFFER_COMPLETE);
+
+ gl::Error error = applyRenderTarget(framebufferObject);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ float nearZ, farZ;
+ data.state->getDepthRange(&nearZ, &farZ);
+ setViewport(data.state->getViewport(), nearZ, farZ, drawMode,
+ data.state->getRasterizerState().frontFace, ignoreViewport);
+
+ setScissorRectangle(data.state->getScissor(), data.state->isScissorTestEnabled());
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+// Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc) to the Direct3D device
+gl::Error RendererD3D::applyState(const gl::Data &data, GLenum drawMode)
+{
+ const gl::Framebuffer *framebufferObject = data.state->getDrawFramebuffer();
+ int samples = framebufferObject->getSamples(data);
+
+ gl::RasterizerState rasterizer = data.state->getRasterizerState();
+ rasterizer.pointDrawMode = (drawMode == GL_POINTS);
+ rasterizer.multiSample = (samples != 0);
+
+ gl::Error error = setRasterizerState(rasterizer);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ unsigned int mask = 0;
+ if (data.state->isSampleCoverageEnabled())
+ {
+ GLclampf coverageValue;
+ bool coverageInvert = false;
+ data.state->getSampleCoverageParams(&coverageValue, &coverageInvert);
+ if (coverageValue != 0)
+ {
+ float threshold = 0.5f;
+
+ for (int i = 0; i < samples; ++i)
+ {
+ mask <<= 1;
+
+ if ((i + 1) * coverageValue >= threshold)
+ {
+ threshold += 1.0f;
+ mask |= 1;
+ }
+ }
+ }
+
+ if (coverageInvert)
+ {
+ mask = ~mask;
+ }
+ }
+ else
+ {
+ mask = 0xFFFFFFFF;
+ }
+ error = setBlendState(framebufferObject, data.state->getBlendState(), data.state->getBlendColor(), mask);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = setDepthStencilState(data.state->getDepthStencilState(), data.state->getStencilRef(),
+ data.state->getStencilBackRef(), rasterizer.frontFace == GL_CCW);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+bool RendererD3D::applyTransformFeedbackBuffers(const gl::Data &data)
+{
+ gl::TransformFeedback *curTransformFeedback = data.state->getCurrentTransformFeedback();
+ if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
+ {
+ applyTransformFeedbackBuffers(*data.state);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+// Applies the shaders and shader constants to the Direct3D device
+gl::Error RendererD3D::applyShaders(const gl::Data &data, bool transformFeedbackActive)
+{
+ gl::ProgramBinary *programBinary = data.state->getCurrentProgramBinary();
+
+ gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS];
+ gl::VertexFormat::GetInputLayout(inputLayout, programBinary, *data.state);
+
+ const gl::Framebuffer *fbo = data.state->getDrawFramebuffer();
+
+ gl::Error error = applyShaders(programBinary, inputLayout, fbo, data.state->getRasterizerState().rasterizerDiscard, transformFeedbackActive);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return programBinary->applyUniforms();
+}
+
+// For each Direct3D sampler of either the pixel or vertex stage,
+// looks up the corresponding OpenGL texture image unit and texture type,
+// and sets the texture and its addressing/filtering state (or NULL when inactive).
+gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shaderType,
+ const FramebufferTextureSerialArray &framebufferSerials, size_t framebufferSerialCount)
+{
+ gl::ProgramBinary *programBinary = data.state->getCurrentProgramBinary();
+
+ size_t samplerRange = programBinary->getUsedSamplerRange(shaderType);
+ for (size_t samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
+ {
+ GLenum textureType = programBinary->getSamplerTextureType(shaderType, samplerIndex);
+ GLint textureUnit = programBinary->getSamplerMapping(shaderType, samplerIndex, *data.caps);
+ if (textureUnit != -1)
+ {
+ gl::Texture *texture = data.state->getSamplerTexture(textureUnit, textureType);
+ ASSERT(texture);
+ gl::SamplerState sampler = texture->getSamplerState();
+
+ gl::Sampler *samplerObject = data.state->getSampler(textureUnit);
+ if (samplerObject)
+ {
+ samplerObject->getState(&sampler);
+ }
+
+ // TODO: std::binary_search may become unavailable using older versions of GCC
+ if (texture->isSamplerComplete(sampler, *data.textureCaps, *data.extensions, data.clientVersion) &&
+ !std::binary_search(framebufferSerials.begin(), framebufferSerials.begin() + framebufferSerialCount, texture->getTextureSerial()))
+ {
+ gl::Error error = setSamplerState(shaderType, samplerIndex, texture, sampler);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = setTexture(shaderType, samplerIndex, texture);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ else
+ {
+ // Texture is not sampler complete or it is in use by the framebuffer. Bind the incomplete texture.
+ gl::Texture *incompleteTexture = getIncompleteTexture(textureType);
+ gl::Error error = setTexture(shaderType, samplerIndex, incompleteTexture);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ }
+ else
+ {
+ // No texture bound to this slot even though it is used by the shader, bind a NULL texture
+ gl::Error error = setTexture(shaderType, samplerIndex, NULL);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ }
+
+ // Set all the remaining textures to NULL
+ size_t samplerCount = (shaderType == gl::SAMPLER_PIXEL) ? data.caps->maxTextureImageUnits
+ : data.caps->maxVertexTextureImageUnits;
+ for (size_t samplerIndex = samplerRange; samplerIndex < samplerCount; samplerIndex++)
+ {
+ gl::Error error = setTexture(shaderType, samplerIndex, NULL);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error RendererD3D::applyTextures(const gl::Data &data)
+{
+ FramebufferTextureSerialArray framebufferSerials;
+ size_t framebufferSerialCount = getBoundFramebufferTextureSerials(data, &framebufferSerials);
+
+ gl::Error error = applyTextures(data, gl::SAMPLER_VERTEX, framebufferSerials, framebufferSerialCount);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = applyTextures(data, gl::SAMPLER_PIXEL, framebufferSerials, framebufferSerialCount);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error RendererD3D::applyUniformBuffers(const gl::Data &data)
+{
+ gl::Program *programObject = data.resourceManager->getProgram(data.state->getCurrentProgramId());
+ gl::ProgramBinary *programBinary = programObject->getProgramBinary();
+
+ std::vector<gl::Buffer*> boundBuffers;
+
+ for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < programBinary->getActiveUniformBlockCount(); uniformBlockIndex++)
+ {
+ GLuint blockBinding = programObject->getUniformBlockBinding(uniformBlockIndex);
+
+ if (data.state->getIndexedUniformBuffer(blockBinding)->id() == 0)
+ {
+ // undefined behaviour
+ return gl::Error(GL_INVALID_OPERATION, "It is undefined behaviour to have a used but unbound uniform buffer.");
+ }
+ else
+ {
+ gl::Buffer *uniformBuffer = data.state->getIndexedUniformBuffer(blockBinding);
+ ASSERT(uniformBuffer);
+ boundBuffers.push_back(uniformBuffer);
+ }
+ }
+
+ return programBinary->applyUniformBuffers(boundBuffers, *data.caps);
+}
+
+bool RendererD3D::skipDraw(const gl::Data &data, GLenum drawMode)
+{
+ if (drawMode == GL_POINTS)
+ {
+ // ProgramBinary assumes non-point rendering if gl_PointSize isn't written,
+ // which affects varying interpolation. Since the value of gl_PointSize is
+ // undefined when not written, just skip drawing to avoid unexpected results.
+ if (!data.state->getCurrentProgramBinary()->usesPointSize())
+ {
+ // This is stictly speaking not an error, but developers should be
+ // notified of risking undefined behavior.
+ ERR("Point rendering without writing to gl_PointSize.");
+
+ return true;
+ }
+ }
+ else if (gl::IsTriangleMode(drawMode))
+ {
+ if (data.state->getRasterizerState().cullFace && data.state->getRasterizerState().cullMode == GL_FRONT_AND_BACK)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void RendererD3D::markTransformFeedbackUsage(const gl::Data &data)
+{
+ for (size_t i = 0; i < data.caps->maxTransformFeedbackSeparateAttributes; i++)
+ {
+ gl::Buffer *buffer = data.state->getIndexedTransformFeedbackBuffer(i);
+ if (buffer)
+ {
+ buffer->markTransformFeedbackUsage();
+ }
+ }
+}
+
+size_t RendererD3D::getBoundFramebufferTextureSerials(const gl::Data &data,
+ FramebufferTextureSerialArray *outSerialArray)
+{
+ size_t serialCount = 0;
+
+ const gl::Framebuffer *drawFramebuffer = data.state->getDrawFramebuffer();
+ for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
+ {
+ gl::FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(i);
+ if (attachment && attachment->isTexture())
+ {
+ gl::Texture *texture = attachment->getTexture();
+ (*outSerialArray)[serialCount++] = texture->getTextureSerial();
+ }
+ }
+
+ gl::FramebufferAttachment *depthStencilAttachment = drawFramebuffer->getDepthOrStencilbuffer();
+ if (depthStencilAttachment && depthStencilAttachment->isTexture())
+ {
+ gl::Texture *depthStencilTexture = depthStencilAttachment->getTexture();
+ (*outSerialArray)[serialCount++] = depthStencilTexture->getTextureSerial();
+ }
+
+ std::sort(outSerialArray->begin(), outSerialArray->begin() + serialCount);
+
+ return serialCount;
+}
+
+gl::Texture *RendererD3D::getIncompleteTexture(GLenum type)
+{
+ if (mIncompleteTextures.find(type) == mIncompleteTextures.end())
+ {
+ const GLubyte color[] = { 0, 0, 0, 255 };
+ const gl::PixelUnpackState incompleteUnpackState(1);
+
+ gl::Texture* t = NULL;
+ switch (type)
+ {
+ default:
+ UNREACHABLE();
+ // default falls through to TEXTURE_2D
+
+ case GL_TEXTURE_2D:
+ {
+ gl::Texture2D *incomplete2d = new gl::Texture2D(createTexture(GL_TEXTURE_2D), gl::Texture::INCOMPLETE_TEXTURE_ID);
+ incomplete2d->setImage(0, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+ t = incomplete2d;
+ }
+ break;
+
+ case GL_TEXTURE_CUBE_MAP:
+ {
+ gl::TextureCubeMap *incompleteCube = new gl::TextureCubeMap(createTexture(GL_TEXTURE_CUBE_MAP), gl::Texture::INCOMPLETE_TEXTURE_ID);
+
+ incompleteCube->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+ incompleteCube->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+ incompleteCube->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+ incompleteCube->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+ incompleteCube->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+ incompleteCube->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+
+ t = incompleteCube;
+ }
+ break;
+
+ case GL_TEXTURE_3D:
+ {
+ gl::Texture3D *incomplete3d = new gl::Texture3D(createTexture(GL_TEXTURE_3D), gl::Texture::INCOMPLETE_TEXTURE_ID);
+ incomplete3d->setImage(0, 1, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+
+ t = incomplete3d;
+ }
+ break;
+
+ case GL_TEXTURE_2D_ARRAY:
+ {
+ gl::Texture2DArray *incomplete2darray = new gl::Texture2DArray(createTexture(GL_TEXTURE_2D_ARRAY), gl::Texture::INCOMPLETE_TEXTURE_ID);
+ incomplete2darray->setImage(0, 1, 1, 1, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, incompleteUnpackState, color);
+
+ t = incomplete2darray;
+ }
+ break;
+ }
+
+ mIncompleteTextures[type].set(t);
+ }
+
+ return mIncompleteTextures[type].get();
+}
+
+gl::Error RendererD3D::clear(const gl::Data &data, GLbitfield mask)
+{
+ gl::ClearParameters clearParams = data.state->getClearParameters(mask);
+
+ // Clips the clear to the scissor rectangle but not the viewport
+ gl::Error error = applyRenderTarget(data, GL_TRIANGLES, true);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return clear(clearParams, data.state->getDrawFramebuffer());
+}
+
+gl::Error RendererD3D::clearBufferfv(const gl::Data &data, GLenum buffer, GLint drawbuffer, const GLfloat *values)
+{
+ // glClearBufferfv can be called to clear the color buffer or depth buffer
+ gl::ClearParameters clearParams = data.state->getClearParameters(0);
+
+ if (buffer == GL_COLOR)
+ {
+ for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
+ {
+ clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i));
+ }
+ clearParams.colorFClearValue = gl::ColorF(values[0], values[1], values[2], values[3]);
+ clearParams.colorClearType = GL_FLOAT;
+ }
+
+ if (buffer == GL_DEPTH)
+ {
+ clearParams.clearDepth = true;
+ clearParams.depthClearValue = values[0];
+ }
+
+ // Clips the clear to the scissor rectangle but not the viewport
+ gl::Error error = applyRenderTarget(data, GL_TRIANGLES, true);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return clear(clearParams, data.state->getDrawFramebuffer());
+}
+
+gl::Error RendererD3D::clearBufferuiv(const gl::Data &data, GLenum buffer, GLint drawbuffer, const GLuint *values)
+{
+ // glClearBufferuiv can only be called to clear a color buffer
+ gl::ClearParameters clearParams = data.state->getClearParameters(0);
+ for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
+ {
+ clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i));
+ }
+ clearParams.colorUIClearValue = gl::ColorUI(values[0], values[1], values[2], values[3]);
+ clearParams.colorClearType = GL_UNSIGNED_INT;
+
+ // Clips the clear to the scissor rectangle but not the viewport
+ gl::Error error = applyRenderTarget(data, GL_TRIANGLES, true);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return clear(clearParams, data.state->getDrawFramebuffer());
+}
+
+gl::Error RendererD3D::clearBufferiv(const gl::Data &data, GLenum buffer, GLint drawbuffer, const GLint *values)
+{
+ // glClearBufferiv can be called to clear the color buffer or stencil buffer
+ gl::ClearParameters clearParams = data.state->getClearParameters(0);
+
+ if (buffer == GL_COLOR)
+ {
+ for (unsigned int i = 0; i < ArraySize(clearParams.clearColor); i++)
+ {
+ clearParams.clearColor[i] = (drawbuffer == static_cast<int>(i));
+ }
+ clearParams.colorIClearValue = gl::ColorI(values[0], values[1], values[2], values[3]);
+ clearParams.colorClearType = GL_INT;
+ }
+
+ if (buffer == GL_STENCIL)
+ {
+ clearParams.clearStencil = true;
+ clearParams.stencilClearValue = values[1];
+ }
+
+ // Clips the clear to the scissor rectangle but not the viewport
+ gl::Error error = applyRenderTarget(data, GL_TRIANGLES, true);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return clear(clearParams, data.state->getDrawFramebuffer());
+}
+
+gl::Error RendererD3D::clearBufferfi(const gl::Data &data, GLenum buffer, GLint drawbuffer,
+ GLfloat depth, GLint stencil)
+{
+ if (data.state->isRasterizerDiscardEnabled())
+ {
+ return gl::Error(GL_NO_ERROR);
+ }
+
+ // glClearBufferfi can only be called to clear a depth stencil buffer
+ gl::ClearParameters clearParams = data.state->getClearParameters(0);
+ clearParams.clearDepth = true;
+ clearParams.depthClearValue = depth;
+ clearParams.clearStencil = true;
+ clearParams.stencilClearValue = stencil;
+
+ // Clips the clear to the scissor rectangle but not the viewport
+ gl::Error error = applyRenderTarget(data, GL_TRIANGLES, true);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return clear(clearParams, data.state->getDrawFramebuffer());
+}
+
+gl::Error RendererD3D::blitFramebuffer(const gl::Data &data,
+ GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ GLbitfield mask, GLenum filter)
+{
+ const gl::Framebuffer *readFramebuffer = data.state->getReadFramebuffer();
+ const gl::Framebuffer *drawFramebuffer = data.state->getDrawFramebuffer();
+
+ bool blitRenderTarget = false;
+ bool blitDepth = false;
+ bool blitStencil = false;
+ if ((mask & GL_COLOR_BUFFER_BIT) && readFramebuffer->getReadColorbuffer() && drawFramebuffer->getFirstColorbuffer())
+ {
+ blitRenderTarget = true;
+ }
+ if ((mask & GL_STENCIL_BUFFER_BIT) && readFramebuffer->getStencilbuffer() && drawFramebuffer->getStencilbuffer())
+ {
+ blitStencil = true;
+ }
+ if ((mask & GL_DEPTH_BUFFER_BIT) && readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer())
+ {
+ blitDepth = true;
+ }
+
+ gl::Rectangle srcRect(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
+ gl::Rectangle dstRect(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
+ if (blitRenderTarget || blitDepth || blitStencil)
+ {
+ const gl::Rectangle *scissor = data.state->isScissorTestEnabled() ? &data.state->getScissor() : NULL;
+ gl::Error error = blitRect(readFramebuffer, srcRect, drawFramebuffer, dstRect, scissor,
+ blitRenderTarget, blitDepth, blitStencil, filter);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error RendererD3D::readPixels(const gl::Data &data, GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLsizei *bufSize, void* pixels)
+{
+ const gl::Framebuffer *framebuffer = data.state->getReadFramebuffer();
+
+ GLenum sizedInternalFormat = gl::GetSizedInternalFormat(format, type);
+ const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(sizedInternalFormat);
+ GLuint outputPitch = sizedFormatInfo.computeRowPitch(type, width, data.state->getPackAlignment());
+
+ return readPixels(framebuffer, x, y, width, height, format, type, outputPitch, data.state->getPackState(),
+ reinterpret_cast<uint8_t*>(pixels));
+}
+
+}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.h
new file mode 100644
index 0000000000..9919207667
--- /dev/null
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/RendererD3D.h
@@ -0,0 +1,195 @@
+
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// RendererD3D.h: Defines a back-end specific class for the DirectX renderer.
+
+#ifndef LIBGLESV2_RENDERER_RENDERERD3D_H_
+#define LIBGLESV2_RENDERER_RENDERERD3D_H_
+
+#include "libGLESv2/renderer/Renderer.h"
+#include "libGLESv2/Data.h"
+
+//FIXME(jmadill): std::array is currently prohibited by Chromium style guide
+#include <array>
+
+namespace gl
+{
+class InfoLog;
+struct LinkedVarying;
+class Texture;
+}
+
+namespace rx
+{
+class TextureStorage;
+class VertexBuffer;
+class IndexBuffer;
+class ShaderExecutable;
+class SwapChain;
+class RenderTarget;
+class Image;
+class TextureStorage;
+class UniformStorage;
+
+class RendererD3D : public Renderer
+{
+ public:
+ explicit RendererD3D(egl::Display *display);
+ virtual ~RendererD3D();
+
+ static RendererD3D *makeRendererD3D(Renderer *renderer);
+
+ gl::Error drawArrays(const gl::Data &data,
+ GLenum mode, GLint first,
+ GLsizei count, GLsizei instances) override;
+
+ gl::Error drawElements(const gl::Data &data,
+ GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices, GLsizei instances,
+ const RangeUI &indexRange) override;
+
+ gl::Error clear(const gl::Data &data, GLbitfield mask) override;
+ gl::Error clearBufferfv(const gl::Data &data, GLenum buffer, int drawbuffer, const GLfloat *values) override;
+ gl::Error clearBufferuiv(const gl::Data &data, GLenum buffer, int drawbuffer, const GLuint *values) override;
+ gl::Error clearBufferiv(const gl::Data &data, GLenum buffer, int drawbuffer, const GLint *values) override;
+ gl::Error clearBufferfi(const gl::Data &data, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) override;
+
+ gl::Error readPixels(const gl::Data &data, GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLsizei *bufSize, void* pixels) override;
+
+ gl::Error blitFramebuffer(const gl::Data &data,
+ GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+ GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
+ GLbitfield mask, GLenum filter) override;
+
+ // Direct3D Specific methods
+ virtual SwapChain *createSwapChain(NativeWindow nativeWindow, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
+
+ virtual gl::Error generateSwizzle(gl::Texture *texture) = 0;
+ virtual gl::Error setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &sampler) = 0;
+ virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
+
+ virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0;
+
+ virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState) = 0;
+ virtual gl::Error setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
+ unsigned int sampleMask) = 0;
+ virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
+ int stencilBackRef, bool frontFaceCCW) = 0;
+
+ virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
+ virtual void setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
+ bool ignoreViewport) = 0;
+
+ virtual gl::Error applyRenderTarget(const gl::Framebuffer *frameBuffer) = 0;
+ virtual gl::Error applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
+ bool rasterizerDiscard, bool transformFeedbackActive) = 0;
+ virtual gl::Error applyUniforms(const ProgramImpl &program, const std::vector<gl::LinkedUniform*> &uniformArray) = 0;
+ virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
+ virtual gl::Error applyVertexBuffer(const gl::State &state, GLint first, GLsizei count, GLsizei instances) = 0;
+ virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
+ virtual void applyTransformFeedbackBuffers(const gl::State& state) = 0;
+
+ virtual void markAllStateDirty() = 0;
+
+ virtual unsigned int getReservedVertexUniformVectors() const = 0;
+ virtual unsigned int getReservedFragmentUniformVectors() const = 0;
+ virtual unsigned int getReservedVertexUniformBuffers() const = 0;
+ virtual unsigned int getReservedFragmentUniformBuffers() const = 0;
+ virtual bool getShareHandleSupport() const = 0;
+ virtual bool getPostSubBufferSupport() const = 0;
+
+ // Pixel operations
+ virtual gl::Error copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level) = 0;
+ virtual gl::Error copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level) = 0;
+ virtual gl::Error copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level) = 0;
+ virtual gl::Error copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level) = 0;
+
+ virtual gl::Error readPixels(const gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
+ GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels) = 0;
+
+ // RenderTarget creation
+ virtual gl::Error createRenderTarget(SwapChain *swapChain, bool depth, RenderTarget **outRT) = 0;
+ virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT) = 0;
+
+ // Shader operations
+ virtual void releaseShaderCompiler() = 0;
+ virtual gl::Error loadExecutable(const void *function, size_t length, ShaderType type,
+ const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
+ bool separatedOutputBuffers, ShaderExecutable **outExecutable) = 0;
+ virtual gl::Error compileToExecutable(gl::InfoLog &infoLog, const std::string &shaderHLSL, ShaderType type,
+ const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
+ bool separatedOutputBuffers, D3DWorkaroundType workaround,
+ ShaderExecutable **outExectuable) = 0;
+ virtual UniformStorage *createUniformStorage(size_t storageSize) = 0;
+
+ // Image operations
+ virtual Image *createImage() = 0;
+ virtual gl::Error generateMipmap(Image *dest, Image *source) = 0;
+ virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
+ virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels) = 0;
+ virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels) = 0;
+ virtual TextureStorage *createTextureStorage3D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
+ virtual TextureStorage *createTextureStorage2DArray(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
+
+ // Buffer-to-texture and Texture-to-buffer copies
+ virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const = 0;
+ virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
+ GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
+
+ virtual VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const = 0;
+ virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const = 0;
+
+ virtual VertexBuffer *createVertexBuffer() = 0;
+ virtual IndexBuffer *createIndexBuffer() = 0;
+
+ protected:
+ virtual gl::Error drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) = 0;
+ virtual gl::Error drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
+ gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
+ virtual gl::Error clear(const gl::ClearParameters &clearParams, const gl::Framebuffer *frameBuffer) = 0;
+ virtual gl::Error blitRect(const gl::Framebuffer *readTarget, const gl::Rectangle &readRect,
+ const gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
+ const gl::Rectangle *scissor, bool blitRenderTarget,
+ bool blitDepth, bool blitStencil, GLenum filter) = 0;
+
+ egl::Display *mDisplay;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RendererD3D);
+
+ //FIXME(jmadill): std::array is currently prohibited by Chromium style guide
+ typedef std::array<unsigned int, gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS> FramebufferTextureSerialArray;
+
+ gl::Error generateSwizzles(const gl::Data &data, gl::SamplerType type);
+ gl::Error generateSwizzles(const gl::Data &data);
+
+ gl::Error applyRenderTarget(const gl::Data &data, GLenum drawMode, bool ignoreViewport);
+ gl::Error applyState(const gl::Data &data, GLenum drawMode);
+ bool applyTransformFeedbackBuffers(const gl::Data &data);
+ gl::Error applyShaders(const gl::Data &data, bool transformFeedbackActive);
+ gl::Error applyTextures(const gl::Data &data, gl::SamplerType shaderType,
+ const FramebufferTextureSerialArray &framebufferSerials, size_t framebufferSerialCount);
+ gl::Error applyTextures(const gl::Data &data);
+ gl::Error applyUniformBuffers(const gl::Data &data);
+
+ bool skipDraw(const gl::Data &data, GLenum drawMode);
+ void markTransformFeedbackUsage(const gl::Data &data);
+
+ size_t getBoundFramebufferTextureSerials(const gl::Data &data,
+ FramebufferTextureSerialArray *outSerialArray);
+ gl::Texture *getIncompleteTexture(GLenum type);
+
+ gl::TextureMap mIncompleteTextures;
+};
+
+}
+
+#endif // LIBGLESV2_RENDERER_RENDERERD3D_H_
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.cpp
index c472113eba..8a97579e16 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.cpp
@@ -6,13 +6,36 @@
// ShaderD3D.cpp: Defines the rx::ShaderD3D class which implements rx::ShaderImpl.
-#include "libGLESv2/renderer/d3d/ShaderD3D.h"
-#include "libGLESv2/renderer/Renderer.h"
#include "libGLESv2/Shader.h"
#include "libGLESv2/main.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
+#include "libGLESv2/renderer/d3d/ShaderD3D.h"
+#include "common/features.h"
#include "common/utilities.h"
+// Definitions local to the translation unit
+namespace
+{
+
+const char *GetShaderTypeString(GLenum type)
+{
+ switch (type)
+ {
+ case GL_VERTEX_SHADER:
+ return "VERTEX";
+
+ case GL_FRAGMENT_SHADER:
+ return "FRAGMENT";
+
+ default:
+ UNREACHABLE();
+ return "";
+ }
+}
+
+}
+
namespace rx
{
@@ -44,13 +67,13 @@ const std::vector<VarT> *GetShaderVariables(const std::vector<VarT> *variableLis
return variableList;
}
-ShaderD3D::ShaderD3D(GLenum type, rx::Renderer *renderer)
+ShaderD3D::ShaderD3D(const gl::Data &data, GLenum type, RendererD3D *renderer)
: mType(type),
mRenderer(renderer),
mShaderVersion(100)
{
uncompile();
- initializeCompiler();
+ initializeCompiler(data);
}
ShaderD3D::~ShaderD3D()
@@ -69,23 +92,28 @@ const ShaderD3D *ShaderD3D::makeShaderD3D(const ShaderImpl *impl)
return static_cast<const ShaderD3D*>(impl);
}
+std::string ShaderD3D::getDebugInfo() const
+{
+ return mDebugInfo + std::string("\n// ") + GetShaderTypeString(mType) + " SHADER END\n";
+}
+
// Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler)
-void ShaderD3D::initializeCompiler()
+void ShaderD3D::initializeCompiler(const gl::Data &data)
{
if (!mFragmentCompiler)
{
- int result = ShInitialize();
+ bool result = ShInitialize();
if (result)
{
+ ShShaderSpec specVersion = (data.clientVersion >= 3) ? SH_GLES3_SPEC : SH_GLES2_SPEC;
ShShaderOutput hlslVersion = (mRenderer->getMajorShaderModel() >= 4) ? SH_HLSL11_OUTPUT : SH_HLSL9_OUTPUT;
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
- // TODO(geofflang): use context's caps
- const gl::Caps &caps = mRenderer->getRendererCaps();
- const gl::Extensions &extensions = mRenderer->getRendererExtensions();
+ const gl::Caps &caps = *data.caps;
+ const gl::Extensions &extensions = *data.extensions;
resources.MaxVertexAttribs = caps.maxVertexAttributes;
resources.MaxVertexUniformVectors = caps.maxVertexUniformVectors;
@@ -107,8 +135,8 @@ void ShaderD3D::initializeCompiler()
resources.MinProgramTexelOffset = caps.minProgramTexelOffset;
resources.MaxProgramTexelOffset = caps.maxProgramTexelOffset;
- mFragmentCompiler = ShConstructCompiler(GL_FRAGMENT_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
- mVertexCompiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
+ mFragmentCompiler = ShConstructCompiler(GL_FRAGMENT_SHADER, specVersion, hlslVersion, &resources);
+ mVertexCompiler = ShConstructCompiler(GL_VERTEX_SHADER, specVersion, hlslVersion, &resources);
}
}
}
@@ -126,7 +154,7 @@ void ShaderD3D::releaseCompiler()
void ShaderD3D::parseVaryings(void *compiler)
{
- if (!mHlsl.empty())
+ if (!mHlsl.empty())
{
const std::vector<sh::Varying> *varyings = ShGetVaryings(compiler);
ASSERT(varyings);
@@ -183,21 +211,25 @@ void ShaderD3D::uncompile()
mInterfaceBlocks.clear();
mActiveAttributes.clear();
mActiveOutputVariables.clear();
+ mDebugInfo.clear();
}
-void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
+void ShaderD3D::compileToHLSL(const gl::Data &data, void *compiler, const std::string &source)
{
// ensure the compiler is loaded
- initializeCompiler();
+ initializeCompiler(data);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES);
std::string sourcePath;
+
+#if !defined (ANGLE_ENABLE_WINDOWS_STORE)
if (gl::perfActive())
{
sourcePath = getTempPath();
writeFile(sourcePath.c_str(), source.c_str(), source.length());
compileOptions |= SH_LINE_DIRECTIVES;
}
+#endif
int result;
if (sourcePath.empty())
@@ -220,25 +252,20 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions | SH_SOURCE_PATH);
}
- size_t shaderVersion = 100;
- ShGetInfo(compiler, SH_SHADER_VERSION, &shaderVersion);
+ mShaderVersion = ShGetShaderVersion(compiler);
- mShaderVersion = static_cast<int>(shaderVersion);
-
- if (shaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
+ if (mShaderVersion == 300 && data.clientVersion < 3)
{
mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts";
TRACE("\n%s", mInfoLog.c_str());
}
else if (result)
{
- size_t objCodeLen = 0;
- ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
-
- char* outputHLSL = new char[objCodeLen];
- ShGetObjectCode(compiler, outputHLSL);
+ mHlsl = ShGetObjectCode(compiler);
#ifdef _DEBUG
+ // Prefix hlsl shader with commented out glsl shader
+ // Useful in diagnostics tools like pix which capture the hlsl shaders
std::ostringstream hlslStream;
hlslStream << "// GLSL\n";
hlslStream << "//\n";
@@ -254,14 +281,10 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
}
hlslStream << "\n\n";
- hlslStream << outputHLSL;
+ hlslStream << mHlsl;
mHlsl = hlslStream.str();
-#else
- mHlsl = outputHLSL;
#endif
- SafeDeleteArray(outputHLSL);
-
mUniforms = *GetShaderVariables(ShGetUniforms(compiler));
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
@@ -271,7 +294,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
if (uniform.staticUse)
{
unsigned int index = -1;
- bool result = ShGetUniformRegister(compiler, uniform.name.c_str(), &index);
+ bool result = ShGetUniformRegister(compiler, uniform.name, &index);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(result);
@@ -288,7 +311,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
if (interfaceBlock.staticUse)
{
unsigned int index = -1;
- bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name.c_str(), &index);
+ bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name, &index);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(result);
@@ -298,24 +321,19 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
}
else
{
- size_t infoLogLen = 0;
- ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
-
- char* infoLog = new char[infoLogLen];
- ShGetInfoLog(compiler, infoLog);
- mInfoLog = infoLog;
+ mInfoLog = ShGetInfoLog(compiler);
TRACE("\n%s", mInfoLog.c_str());
}
}
-rx::D3DWorkaroundType ShaderD3D::getD3DWorkarounds() const
+D3DWorkaroundType ShaderD3D::getD3DWorkarounds() const
{
if (mUsesDiscardRewriting)
{
// ANGLE issue 486:
// Work-around a D3D9 compiler bug that presents itself when using conditional discard, by disabling optimization
- return rx::ANGLE_D3D_WORKAROUND_SKIP_OPTIMIZATION;
+ return ANGLE_D3D_WORKAROUND_SKIP_OPTIMIZATION;
}
if (mUsesNestedBreak)
@@ -323,10 +341,10 @@ rx::D3DWorkaroundType ShaderD3D::getD3DWorkarounds() const
// ANGLE issue 603:
// Work-around a D3D9 compiler bug that presents itself when using break in a nested loop, by maximizing optimization
// We want to keep the use of ANGLE_D3D_WORKAROUND_MAX_OPTIMIZATION minimal to prevent hangs, so usesDiscard takes precedence
- return rx::ANGLE_D3D_WORKAROUND_MAX_OPTIMIZATION;
+ return ANGLE_D3D_WORKAROUND_MAX_OPTIMIZATION;
}
- return rx::ANGLE_D3D_WORKAROUND_NONE;
+ return ANGLE_D3D_WORKAROUND_NONE;
}
// true if varying x has a higher priority in packing than y
@@ -387,19 +405,16 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader)
default: UNREACHABLE(); return SH_HLSL9_OUTPUT;
}
- size_t outputType = 0;
- ShGetInfo(compiler, SH_OUTPUT_TYPE, &outputType);
-
- return static_cast<ShShaderOutput>(outputType);
+ return ShGetShaderOutputType(compiler);
}
-bool ShaderD3D::compile(const std::string &source)
+bool ShaderD3D::compile(const gl::Data &data, const std::string &source)
{
uncompile();
void *compiler = getCompiler();
- compileToHLSL(compiler, source);
+ compileToHLSL(data, compiler, source);
if (mType == GL_VERTEX_SHADER)
{
@@ -420,6 +435,15 @@ bool ShaderD3D::compile(const std::string &source)
}
}
+#if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED
+ mDebugInfo += std::string("// ") + GetShaderTypeString(mType) + " SHADER BEGIN\n";
+ mDebugInfo += "\n// GLSL BEGIN\n\n" + source + "\n\n// GLSL END\n\n\n";
+ mDebugInfo += "// INITIAL HLSL BEGIN\n\n" + getTranslatedSource() + "\n// INITIAL HLSL END\n\n\n";
+ // Successive steps will append more info
+#else
+ mDebugInfo += getTranslatedSource();
+#endif
+
return !getTranslatedSource().empty();
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.h
index 40e64cf36c..3c9aac2c12 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/ShaderD3D.h
@@ -10,6 +10,7 @@
#define LIBGLESV2_RENDERER_SHADERD3D_H_
#include "libGLESv2/renderer/ShaderImpl.h"
+#include "libGLESv2/renderer/Workarounds.h"
#include "libGLESv2/Shader.h"
#include <map>
@@ -17,22 +18,23 @@
namespace rx
{
class DynamicHLSL;
-class Renderer;
+class RendererD3D;
class ShaderD3D : public ShaderImpl
{
friend class DynamicHLSL;
public:
- ShaderD3D(GLenum type, rx::Renderer *renderer);
+ ShaderD3D(const gl::Data &data, GLenum type, RendererD3D *renderer);
virtual ~ShaderD3D();
static ShaderD3D *makeShaderD3D(ShaderImpl *impl);
static const ShaderD3D *makeShaderD3D(const ShaderImpl *impl);
// ShaderImpl implementation
- const std::string &getInfoLog() const { return mInfoLog; }
- const std::string &getTranslatedSource() const { return mHlsl; }
+ virtual const std::string &getInfoLog() const { return mInfoLog; }
+ virtual const std::string &getTranslatedSource() const { return mHlsl; }
+ virtual std::string getDebugInfo() const;
// D3D-specific methods
virtual void uncompile();
@@ -40,8 +42,9 @@ class ShaderD3D : public ShaderImpl
unsigned int getUniformRegister(const std::string &uniformName) const;
unsigned int getInterfaceBlockRegister(const std::string &blockName) const;
int getSemanticIndex(const std::string &attributeName) const;
+ void appendDebugInfo(const std::string &info) { mDebugInfo += info; }
- rx::D3DWorkaroundType getD3DWorkarounds() const;
+ D3DWorkaroundType getD3DWorkarounds() const;
int getShaderVersion() const { return mShaderVersion; }
bool usesDepthRange() const { return mUsesDepthRange; }
bool usesPointSize() const { return mUsesPointSize; }
@@ -49,15 +52,15 @@ class ShaderD3D : public ShaderImpl
static void releaseCompiler();
static ShShaderOutput getCompilerOutputType(GLenum shader);
- virtual bool compile(const std::string &source);
+ virtual bool compile(const gl::Data &data, const std::string &source);
private:
DISALLOW_COPY_AND_ASSIGN(ShaderD3D);
- void compileToHLSL(void *compiler, const std::string &source);
+ void compileToHLSL(const gl::Data &data, void *compiler, const std::string &source);
void parseVaryings(void *compiler);
- void initializeCompiler();
+ void initializeCompiler(const gl::Data &data);
void parseAttributes(void *compiler);
void *getCompiler();
@@ -67,7 +70,7 @@ class ShaderD3D : public ShaderImpl
static void *mVertexCompiler;
GLenum mType;
- rx::Renderer *mRenderer;
+ RendererD3D *mRenderer;
int mShaderVersion;
@@ -85,6 +88,7 @@ class ShaderD3D : public ShaderImpl
std::string mHlsl;
std::string mInfoLog;
+ std::string mDebugInfo;
std::map<std::string, unsigned int> mUniformRegisterMap;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
};
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.cpp
index 96c84977cb..4a67701fdf 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.cpp
@@ -6,9 +6,6 @@
// TextureD3D.cpp: Implementations of the Texture interfaces shared betweeen the D3D backends.
-#include "libGLESv2/renderer/d3d/TextureD3D.h"
-#include "libGLESv2/renderer/d3d/TextureStorage.h"
-#include "libGLESv2/renderer/d3d/ImageD3D.h"
#include "libGLESv2/Buffer.h"
#include "libGLESv2/Framebuffer.h"
#include "libGLESv2/Texture.h"
@@ -16,7 +13,11 @@
#include "libGLESv2/formatutils.h"
#include "libGLESv2/renderer/BufferImpl.h"
#include "libGLESv2/renderer/RenderTarget.h"
-#include "libGLESv2/renderer/Renderer.h"
+#include "libGLESv2/renderer/d3d/BufferD3D.h"
+#include "libGLESv2/renderer/d3d/TextureD3D.h"
+#include "libGLESv2/renderer/d3d/TextureStorage.h"
+#include "libGLESv2/renderer/d3d/ImageD3D.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
#include "libEGL/Surface.h"
@@ -26,16 +27,51 @@
namespace rx
{
+namespace
+{
+
+gl::Error GetUnpackPointer(const gl::PixelUnpackState &unpack, const void *pixels, const uint8_t **pointerOut)
+{
+ if (unpack.pixelBuffer.id() != 0)
+ {
+ // Do a CPU readback here, if we have an unpack buffer bound and the fast GPU path is not supported
+ gl::Buffer *pixelBuffer = unpack.pixelBuffer.get();
+ ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(pixels);
+
+ // TODO: this is the only place outside of renderer that asks for a buffers raw data.
+ // This functionality should be moved into renderer and the getData method of BufferImpl removed.
+ BufferD3D *bufferD3D = BufferD3D::makeBufferD3D(pixelBuffer->getImplementation());
+ ASSERT(bufferD3D);
+ const uint8_t *bufferData = NULL;
+ gl::Error error = bufferD3D->getData(&bufferData);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ *pointerOut = bufferData + offset;
+ }
+ else
+ {
+ *pointerOut = static_cast<const uint8_t *>(pixels);
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
bool IsRenderTargetUsage(GLenum usage)
{
return (usage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
}
-TextureD3D::TextureD3D(Renderer *renderer)
+}
+
+TextureD3D::TextureD3D(RendererD3D *renderer)
: mRenderer(renderer),
mUsage(GL_NONE),
mDirtyImages(true),
- mImmutable(false)
+ mImmutable(false),
+ mTexStorage(NULL)
{
}
@@ -54,13 +90,12 @@ TextureStorage *TextureD3D::getNativeTexture()
// ensure the underlying texture is created
initializeStorage(false);
- TextureStorage *storage = getBaseLevelStorage();
- if (storage)
+ if (mTexStorage)
{
updateStorage();
}
- return storage;
+ return mTexStorage;
}
GLint TextureD3D::getBaseLevelWidth() const
@@ -90,50 +125,79 @@ GLenum TextureD3D::getBaseLevelInternalFormat() const
return (baseImage ? baseImage->getInternalFormat() : GL_NONE);
}
-void TextureD3D::setImage(const gl::PixelUnpackState &unpack, GLenum type, const void *pixels, Image *image)
+bool TextureD3D::shouldUseSetData(const Image *image) const
+{
+ if (!mRenderer->getWorkarounds().setDataFasterThanImageUpload)
+ {
+ return false;
+ }
+
+ gl::InternalFormat internalFormat = gl::GetInternalFormatInfo(image->getInternalFormat());
+
+ // We can only handle full updates for depth-stencil textures, so to avoid complications
+ // disable them entirely.
+ if (internalFormat.depthBits > 0 || internalFormat.stencilBits > 0)
+ {
+ return false;
+ }
+
+ // TODO(jmadill): Handle compressed internal formats
+ return (mTexStorage && !internalFormat.compressed);
+}
+
+gl::Error TextureD3D::setImage(const gl::PixelUnpackState &unpack, GLenum type, const void *pixels, const gl::ImageIndex &index)
{
+ Image *image = getImage(index);
+ ASSERT(image);
+
// No-op
if (image->getWidth() == 0 || image->getHeight() == 0 || image->getDepth() == 0)
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
// We no longer need the "GLenum format" parameter to TexImage to determine what data format "pixels" contains.
// From our image internal format we know how many channels to expect, and "type" gives the format of pixel's components.
- const void *pixelData = pixels;
-
- if (unpack.pixelBuffer.id() != 0)
+ const uint8_t *pixelData = NULL;
+ gl::Error error = GetUnpackPointer(unpack, pixels, &pixelData);
+ if (error.isError())
{
- // Do a CPU readback here, if we have an unpack buffer bound and the fast GPU path is not supported
- gl::Buffer *pixelBuffer = unpack.pixelBuffer.get();
- ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(pixels);
- // TODO: setImage/subImage is the only place outside of renderer that asks for a buffers raw data.
- // This functionality should be moved into renderer and the getData method of BufferImpl removed.
- const void *bufferData = pixelBuffer->getImplementation()->getData();
- pixelData = static_cast<const unsigned char *>(bufferData) + offset;
+ return error;
}
if (pixelData != NULL)
{
- image->loadData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), unpack.alignment, type, pixelData);
+ gl::Error error(GL_NO_ERROR);
+
+ if (shouldUseSetData(image))
+ {
+ error = mTexStorage->setData(index, image, NULL, type, unpack, pixelData);
+ }
+ else
+ {
+ error = image->loadData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), unpack.alignment, type, pixelData);
+ }
+
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
+
+ return gl::Error(GL_NO_ERROR);
}
-bool TextureD3D::subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels, const gl::ImageIndex &index)
+gl::Error TextureD3D::subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels, const gl::ImageIndex &index)
{
- const void *pixelData = pixels;
-
// CPU readback & copy where direct GPU copy is not supported
- if (unpack.pixelBuffer.id() != 0)
+ const uint8_t *pixelData = NULL;
+ gl::Error error = GetUnpackPointer(unpack, pixels, &pixelData);
+ if (error.isError())
{
- gl::Buffer *pixelBuffer = unpack.pixelBuffer.get();
- ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(pixels);
- // TODO: setImage/subImage is the only place outside of renderer that asks for a buffers raw data.
- // This functionality should be moved into renderer and the getData method of BufferImpl removed.
- const void *bufferData = pixelBuffer->getImplementation()->getData();
- pixelData = static_cast<const unsigned char *>(bufferData) + offset;
+ return error;
}
if (pixelData != NULL)
@@ -141,32 +205,78 @@ bool TextureD3D::subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei w
Image *image = getImage(index);
ASSERT(image);
- image->loadData(xoffset, yoffset, zoffset, width, height, depth, unpack.alignment, type, pixelData);
+ gl::Box region(xoffset, yoffset, zoffset, width, height, depth);
+ if (shouldUseSetData(image))
+ {
+ return mTexStorage->setData(index, image, &region, type, unpack, pixelData);
+ }
+
+ gl::Error error = image->loadData(xoffset, yoffset, zoffset, width, height, depth, unpack.alignment,
+ type, pixelData);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = commitRegion(index, region);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D::setCompressedImage(GLsizei imageSize, const void *pixels, Image *image)
+gl::Error TextureD3D::setCompressedImage(const gl::PixelUnpackState &unpack, GLsizei imageSize, const void *pixels, Image *image)
{
- if (pixels != NULL)
+ // We no longer need the "GLenum format" parameter to TexImage to determine what data format "pixels" contains.
+ // From our image internal format we know how many channels to expect, and "type" gives the format of pixel's components.
+ const uint8_t *pixelData = NULL;
+ gl::Error error = GetUnpackPointer(unpack, pixels, &pixelData);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (pixelData != NULL)
{
- image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), pixels);
+ gl::Error error = image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), pixelData);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
+
+ return gl::Error(GL_NO_ERROR);
}
-bool TextureD3D::subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLsizei imageSize, const void *pixels, Image *image)
+gl::Error TextureD3D::subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels, Image *image)
{
- if (pixels != NULL)
+ const uint8_t *pixelData = NULL;
+ gl::Error error = GetUnpackPointer(unpack, pixels, &pixelData);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (pixelData != NULL)
{
- image->loadCompressedData(xoffset, yoffset, zoffset, width, height, depth, pixels);
+ gl::Error error = image->loadCompressedData(xoffset, yoffset, zoffset, width, height, depth, pixelData);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
bool TextureD3D::isFastUnpackable(const gl::PixelUnpackState &unpack, GLenum sizedInternalFormat)
@@ -174,21 +284,28 @@ bool TextureD3D::isFastUnpackable(const gl::PixelUnpackState &unpack, GLenum siz
return unpack.pixelBuffer.id() != 0 && mRenderer->supportsFastCopyBufferToTexture(sizedInternalFormat);
}
-bool TextureD3D::fastUnpackPixels(const gl::PixelUnpackState &unpack, const void *pixels, const gl::Box &destArea,
- GLenum sizedInternalFormat, GLenum type, RenderTarget *destRenderTarget)
+gl::Error TextureD3D::fastUnpackPixels(const gl::PixelUnpackState &unpack, const void *pixels, const gl::Box &destArea,
+ GLenum sizedInternalFormat, GLenum type, RenderTarget *destRenderTarget)
{
+ // No-op
if (destArea.width <= 0 && destArea.height <= 0 && destArea.depth <= 0)
{
- return true;
+ return gl::Error(GL_NO_ERROR);
}
// In order to perform the fast copy through the shader, we must have the right format, and be able
// to create a render target.
ASSERT(mRenderer->supportsFastCopyBufferToTexture(sizedInternalFormat));
- ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(pixels);
+ uintptr_t offset = reinterpret_cast<uintptr_t>(pixels);
- return mRenderer->fastCopyBufferToTexture(unpack, offset, destRenderTarget, sizedInternalFormat, type, destArea);
+ gl::Error error = mRenderer->fastCopyBufferToTexture(unpack, offset, destRenderTarget, sizedInternalFormat, type, destArea);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
}
GLint TextureD3D::creationLevels(GLsizei width, GLsizei height, GLsizei depth) const
@@ -210,10 +327,192 @@ int TextureD3D::mipLevels() const
return gl::log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1;
}
+TextureStorage *TextureD3D::getStorage()
+{
+ ASSERT(mTexStorage);
+ return mTexStorage;
+}
-TextureD3D_2D::TextureD3D_2D(Renderer *renderer)
- : TextureD3D(renderer),
- mTexStorage(NULL)
+Image *TextureD3D::getBaseLevelImage() const
+{
+ return getImage(getImageIndex(0, 0));
+}
+
+gl::Error TextureD3D::generateMipmaps()
+{
+ GLint mipCount = mipLevels();
+
+ if (mipCount == 1)
+ {
+ return gl::Error(GL_NO_ERROR); // no-op
+ }
+
+ // Set up proper mipmap chain in our Image array.
+ initMipmapsImages();
+
+ // We know that all layers have the same dimension, for the texture to be complete
+ GLint layerCount = static_cast<GLint>(getLayerCount(0));
+
+ // When making mipmaps with the setData workaround enabled, the texture storage has
+ // the image data already. For non-render-target storage, we have to pull it out into
+ // an image layer.
+ if (mRenderer->getWorkarounds().setDataFasterThanImageUpload && mTexStorage)
+ {
+ if (!mTexStorage->isRenderTarget())
+ {
+ // Copy from the storage mip 0 to Image mip 0
+ for (GLint layer = 0; layer < layerCount; ++layer)
+ {
+ gl::ImageIndex srcIndex = getImageIndex(0, layer);
+
+ Image *image = getImage(srcIndex);
+ gl::Rectangle area(0, 0, image->getWidth(), image->getHeight());
+ gl::Error error = image->copy(0, 0, 0, area, srcIndex, mTexStorage);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ }
+ else
+ {
+ gl::Error error = updateStorage();
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ }
+
+ bool renderableStorage = (mTexStorage && mTexStorage->isRenderTarget());
+
+ for (GLint layer = 0; layer < layerCount; ++layer)
+ {
+ for (GLint mip = 1; mip < mipCount; ++mip)
+ {
+ ASSERT(getLayerCount(mip) == layerCount);
+
+ gl::ImageIndex sourceIndex = getImageIndex(mip - 1, layer);
+ gl::ImageIndex destIndex = getImageIndex(mip, layer);
+
+ if (renderableStorage)
+ {
+ // GPU-side mipmapping
+ gl::Error error = mTexStorage->generateMipmap(sourceIndex, destIndex);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ else
+ {
+ // CPU-side mipmapping
+ gl::Error error = mRenderer->generateMipmap(getImage(destIndex), getImage(sourceIndex));
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+bool TextureD3D::isBaseImageZeroSize() const
+{
+ Image *baseImage = getBaseLevelImage();
+
+ if (!baseImage || baseImage->getWidth() <= 0)
+ {
+ return true;
+ }
+
+ if (!gl::IsCubemapTextureTarget(baseImage->getTarget()) && baseImage->getHeight() <= 0)
+ {
+ return true;
+ }
+
+ if (baseImage->getTarget() == GL_TEXTURE_3D && baseImage->getDepth() <= 0)
+ {
+ return true;
+ }
+
+ if (baseImage->getTarget() == GL_TEXTURE_2D_ARRAY && getLayerCount(0) <= 0)
+ {
+ return true;
+ }
+
+ return false;
+}
+
+gl::Error TextureD3D::ensureRenderTarget()
+{
+ gl::Error error = initializeStorage(true);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!isBaseImageZeroSize())
+ {
+ ASSERT(mTexStorage);
+ if (!mTexStorage->isRenderTarget())
+ {
+ TextureStorage *newRenderTargetStorage = NULL;
+ error = createCompleteStorage(true, &newRenderTargetStorage);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = mTexStorage->copyToStorage(newRenderTargetStorage);
+ if (error.isError())
+ {
+ SafeDelete(newRenderTargetStorage);
+ return error;
+ }
+
+ error = setCompleteTexStorage(newRenderTargetStorage);
+ if (error.isError())
+ {
+ SafeDelete(newRenderTargetStorage);
+ return error;
+ }
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+bool TextureD3D::canCreateRenderTargetForImage(const gl::ImageIndex &index) const
+{
+ Image *image = getImage(index);
+ bool levelsComplete = (isImageComplete(index) && isImageComplete(getImageIndex(0, 0)));
+ return (image->isRenderableFormat() && levelsComplete);
+}
+
+gl::Error TextureD3D::commitRegion(const gl::ImageIndex &index, const gl::Box &region)
+{
+ if (mTexStorage)
+ {
+ ASSERT(isValidIndex(index));
+ Image *image = getImage(index);
+ ImageD3D *imageD3D = ImageD3D::makeImageD3D(image);
+ gl::Error error = imageD3D->copyToStorage(mTexStorage, index, region);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ image->markClean();
+ }
+
+ return gl::Error(GL_NO_ERROR);
+}
+
+TextureD3D_2D::TextureD3D_2D(RendererD3D *renderer)
+ : TextureD3D(renderer)
{
for (int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; ++i)
{
@@ -292,7 +591,9 @@ bool TextureD3D_2D::isDepth(GLint level) const
return gl::GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
}
-void TextureD3D_2D::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_2D::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack,
+ const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D && depth == 1);
@@ -302,142 +603,209 @@ void TextureD3D_2D::setImage(GLenum target, GLint level, GLsizei width, GLsizei
redefineImage(level, sizedInternalFormat, width, height);
+ gl::ImageIndex index = gl::ImageIndex::Make2D(level);
+
// Attempt a fast gpu copy of the pixel data to the surface
if (isFastUnpackable(unpack, sizedInternalFormat) && isLevelComplete(level))
{
- gl::ImageIndex index = gl::ImageIndex::Make2D(level);
-
// Will try to create RT storage if it does not exist
- RenderTarget *destRenderTarget = getRenderTarget(index);
+ RenderTarget *destRenderTarget = NULL;
+ gl::Error error = getRenderTarget(index, &destRenderTarget);
+ if (error.isError())
+ {
+ return error;
+ }
+
gl::Box destArea(0, 0, 0, getWidth(level), getHeight(level), 1);
- if (destRenderTarget && fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget))
+ error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
+ if (error.isError())
{
- // Ensure we don't overwrite our newly initialized data
- mImageArray[level]->markClean();
-
- fastUnpacked = true;
+ return error;
}
+
+ // Ensure we don't overwrite our newly initialized data
+ mImageArray[level]->markClean();
+
+ fastUnpacked = true;
}
if (!fastUnpacked)
{
- TextureD3D::setImage(unpack, type, pixels, mImageArray[level]);
+ gl::Error error = TextureD3D::setImage(unpack, type, pixels, index);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2D::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_2D::setCompressedImage(GLenum target, GLint level, GLenum format,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D && depth == 1);
// compressed formats don't have separate sized internal formats-- we can just use the compressed format directly
redefineImage(level, format, width, height);
- TextureD3D::setCompressedImage(imageSize, pixels, mImageArray[level]);
+ return TextureD3D::setCompressedImage(unpack, imageSize, pixels, mImageArray[level]);
}
-void TextureD3D_2D::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_2D::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
+ const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D && depth == 1 && zoffset == 0);
bool fastUnpacked = false;
gl::ImageIndex index = gl::ImageIndex::Make2D(level);
+ gl::Box destArea(xoffset, yoffset, 0, width, height, 1);
if (isFastUnpackable(unpack, getInternalFormat(level)) && isLevelComplete(level))
{
- RenderTarget *renderTarget = getRenderTarget(index);
- gl::Box destArea(xoffset, yoffset, 0, width, height, 1);
-
- if (renderTarget && fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, renderTarget))
+ RenderTarget *renderTarget = NULL;
+ gl::Error error = getRenderTarget(index, &renderTarget);
+ if (error.isError())
{
- // Ensure we don't overwrite our newly initialized data
- mImageArray[level]->markClean();
+ return error;
+ }
- fastUnpacked = true;
+ error = fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, renderTarget);
+ if (error.isError())
+ {
+ return error;
}
+
+ // Ensure we don't overwrite our newly initialized data
+ mImageArray[level]->markClean();
+
+ fastUnpacked = true;
}
- if (!fastUnpacked && TextureD3D::subImage(xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels, index))
+ if (!fastUnpacked)
{
- commitRect(level, xoffset, yoffset, width, height);
+ return TextureD3D::subImage(xoffset, yoffset, 0, width, height, 1, format, type,
+ unpack, pixels, index);
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2D::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_2D::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D && depth == 1 && zoffset == 0);
- if (TextureD3D::subImageCompressed(xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels, mImageArray[level]))
+ gl::Error error = TextureD3D::subImageCompressed(xoffset, yoffset, 0, width, height, 1, format, imageSize, unpack, pixels, mImageArray[level]);
+ if (error.isError())
{
- commitRect(level, xoffset, yoffset, width, height);
+ return error;
}
+
+ gl::ImageIndex index = gl::ImageIndex::Make2D(level);
+ gl::Box region(xoffset, yoffset, 0, width, height, 1);
+ return commitRegion(index, region);
}
-void TextureD3D_2D::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_2D::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height,
+ gl::Framebuffer *source)
{
ASSERT(target == GL_TEXTURE_2D);
GLenum sizedInternalFormat = gl::GetSizedInternalFormat(format, GL_UNSIGNED_BYTE);
redefineImage(level, sizedInternalFormat, width, height);
- if (!mImageArray[level]->isRenderableFormat())
+ gl::Rectangle sourceRect(x, y, width, height);
+ gl::ImageIndex index = gl::ImageIndex::Make2D(level);
+
+ if (!canCreateRenderTargetForImage(index))
{
- mImageArray[level]->copy(0, 0, 0, x, y, width, height, source);
+ gl::Error error = mImageArray[level]->copy(0, 0, 0, sourceRect, source);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
else
{
- ensureRenderTarget();
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
+
mImageArray[level]->markClean();
if (width != 0 && height != 0 && isValidLevel(level))
{
- gl::Rectangle sourceRect;
- sourceRect.x = x;
- sourceRect.width = width;
- sourceRect.y = y;
- sourceRect.height = height;
-
- mRenderer->copyImage2D(source, sourceRect, format, 0, 0, mTexStorage, level);
+ gl::Error error = mRenderer->copyImage2D(source, sourceRect, format, 0, 0, mTexStorage, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
{
ASSERT(target == GL_TEXTURE_2D && zoffset == 0);
// can only make our texture storage to a render target if level 0 is defined (with a width & height) and
// the current level we're copying to is defined (with appropriate format, width & height)
- bool canCreateRenderTarget = isLevelComplete(level) && isLevelComplete(0);
- if (!mImageArray[level]->isRenderableFormat() || (!mTexStorage && !canCreateRenderTarget))
+ gl::Rectangle sourceRect(x, y, width, height);
+ gl::ImageIndex index = gl::ImageIndex::Make2D(level);
+
+ if (!canCreateRenderTargetForImage(index))
{
- mImageArray[level]->copy(xoffset, yoffset, 0, x, y, width, height, source);
+ gl::Error error = mImageArray[level]->copy(xoffset, yoffset, 0, sourceRect, source);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
else
{
- ensureRenderTarget();
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
if (isValidLevel(level))
{
- updateStorageLevel(level);
-
- gl::Rectangle sourceRect;
- sourceRect.x = x;
- sourceRect.width = width;
- sourceRect.y = y;
- sourceRect.height = height;
+ error = updateStorageLevel(level);
+ if (error.isError())
+ {
+ return error;
+ }
- mRenderer->copyImage2D(source, sourceRect,
- gl::GetInternalFormatInfo(getBaseLevelInternalFormat()).format,
- xoffset, yoffset, mTexStorage, level);
+ error = mRenderer->copyImage2D(source, sourceRect,
+ gl::GetInternalFormatInfo(getBaseLevelInternalFormat()).format,
+ xoffset, yoffset, mTexStorage, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2D::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
+gl::Error TextureD3D_2D::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
{
ASSERT(target == GL_TEXTURE_2D && depth == 1);
@@ -453,11 +821,20 @@ void TextureD3D_2D::storage(GLenum target, GLsizei levels, GLenum internalformat
mImageArray[level]->redefine(mRenderer, GL_TEXTURE_2D, GL_NONE, 0, 0, 0, true);
}
- mImmutable = true;
-
+ // TODO(geofflang): Verify storage creation had no errors
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storage = mRenderer->createTextureStorage2D(internalformat, renderTarget, width, height, levels);
- setCompleteTexStorage(storage);
+
+ gl::Error error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
+ mImmutable = true;
+
+ return gl::Error(GL_NO_ERROR);
}
void TextureD3D_2D::bindTexImage(egl::Surface *surface)
@@ -489,7 +866,7 @@ void TextureD3D_2D::releaseTexImage()
}
}
-void TextureD3D_2D::generateMipmaps()
+void TextureD3D_2D::initMipmapsImages()
{
// Purge array levels 1 through q and reset them to represent the generated mipmap levels.
int levelCount = mipLevels();
@@ -499,42 +876,32 @@ void TextureD3D_2D::generateMipmaps()
std::max(getBaseLevelWidth() >> level, 1),
std::max(getBaseLevelHeight() >> level, 1));
}
-
- if (mTexStorage && mTexStorage->isRenderTarget())
- {
- mTexStorage->generateMipmaps();
- for (int level = 1; level < levelCount; level++)
- {
- mImageArray[level]->markClean();
- }
- }
- else
- {
- for (int level = 1; level < levelCount; level++)
- {
- mRenderer->generateMipmap(mImageArray[level], mImageArray[level - 1]);
- }
- }
}
unsigned int TextureD3D_2D::getRenderTargetSerial(const gl::ImageIndex &index)
{
ASSERT(!index.hasLayer());
- return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
+ return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
-RenderTarget *TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index)
+gl::Error TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{
ASSERT(!index.hasLayer());
// ensure the underlying texture is created
- if (!ensureRenderTarget())
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = updateStorageLevel(index.mipIndex);
+ if (error.isError())
{
- return NULL;
+ return error;
}
- updateStorageLevel(index.mipIndex);
- return mTexStorage->getRenderTarget(index);
+ return mTexStorage->getRenderTarget(index, outRT);
}
bool TextureD3D_2D::isValidLevel(int level) const
@@ -586,31 +953,55 @@ bool TextureD3D_2D::isLevelComplete(int level) const
return true;
}
+bool TextureD3D_2D::isImageComplete(const gl::ImageIndex &index) const
+{
+ return isLevelComplete(index.mipIndex);
+}
+
// Constructs a native texture resource from the texture images
-void TextureD3D_2D::initializeStorage(bool renderTarget)
+gl::Error TextureD3D_2D::initializeStorage(bool renderTarget)
{
// Only initialize the first time this texture is used as a render target or shader resource
if (mTexStorage)
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
// do not attempt to create storage for nonexistant data
if (!isLevelComplete(0))
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
bool createRenderTarget = (renderTarget || IsRenderTargetUsage(mUsage));
- setCompleteTexStorage(createCompleteStorage(createRenderTarget));
+ TextureStorage *storage = NULL;
+ gl::Error error = createCompleteStorage(createRenderTarget, &storage);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
ASSERT(mTexStorage);
// flush image data to the storage
- updateStorage();
+ error = updateStorage();
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
}
-TextureStorage *TextureD3D_2D::createCompleteStorage(bool renderTarget) const
+gl::Error TextureD3D_2D::createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const
{
GLsizei width = getBaseLevelWidth();
GLsizei height = getBaseLevelHeight();
@@ -621,26 +1012,35 @@ TextureStorage *TextureD3D_2D::createCompleteStorage(bool renderTarget) const
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(width, height, 1));
- return mRenderer->createTextureStorage2D(internalFormat, renderTarget, width, height, levels);
+ // TODO(geofflang): Determine if the texture creation succeeded
+ *outTexStorage = mRenderer->createTextureStorage2D(internalFormat, renderTarget, width, height, levels);
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2D::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
+gl::Error TextureD3D_2D::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
{
- SafeDelete(mTexStorage);
- mTexStorage = newCompleteTexStorage;
-
- if (mTexStorage && mTexStorage->isManaged())
+ if (newCompleteTexStorage && newCompleteTexStorage->isManaged())
{
- for (int level = 0; level < mTexStorage->getLevelCount(); level++)
+ for (int level = 0; level < newCompleteTexStorage->getLevelCount(); level++)
{
- mImageArray[level]->setManagedSurface2D(mTexStorage, level);
+ gl::Error error = mImageArray[level]->setManagedSurface2D(newCompleteTexStorage, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+ SafeDelete(mTexStorage);
+ mTexStorage = newCompleteTexStorage;
+
mDirtyImages = true;
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2D::updateStorage()
+gl::Error TextureD3D_2D::updateStorage()
{
ASSERT(mTexStorage != NULL);
GLint storageLevels = mTexStorage->getLevelCount();
@@ -648,54 +1048,34 @@ void TextureD3D_2D::updateStorage()
{
if (mImageArray[level]->isDirty() && isLevelComplete(level))
{
- updateStorageLevel(level);
- }
- }
-}
-
-bool TextureD3D_2D::ensureRenderTarget()
-{
- initializeStorage(true);
-
- if (getBaseLevelWidth() > 0 && getBaseLevelHeight() > 0)
- {
- ASSERT(mTexStorage);
- if (!mTexStorage->isRenderTarget())
- {
- TextureStorage *newRenderTargetStorage = createCompleteStorage(true);
-
- if (!mRenderer->copyToRenderTarget2D(newRenderTargetStorage, mTexStorage))
+ gl::Error error = updateStorageLevel(level);
+ if (error.isError())
{
- delete newRenderTargetStorage;
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
-
- setCompleteTexStorage(newRenderTargetStorage);
}
}
- return (mTexStorage && mTexStorage->isRenderTarget());
-}
-
-TextureStorage *TextureD3D_2D::getBaseLevelStorage()
-{
- return mTexStorage;
+ return gl::Error(GL_NO_ERROR);
}
-const ImageD3D *TextureD3D_2D::getBaseLevelImage() const
-{
- return mImageArray[0];
-}
-
-void TextureD3D_2D::updateStorageLevel(int level)
+gl::Error TextureD3D_2D::updateStorageLevel(int level)
{
ASSERT(level <= (int)ArraySize(mImageArray) && mImageArray[level] != NULL);
ASSERT(isLevelComplete(level));
if (mImageArray[level]->isDirty())
{
- commitRect(level, 0, 0, getWidth(level), getHeight(level));
+ gl::ImageIndex index = gl::ImageIndex::Make2D(level);
+ gl::Box region(0, 0, 0, getWidth(level), getHeight(level), 1);
+ gl::Error error = commitRegion(index, region);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
void TextureD3D_2D::redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height)
@@ -727,22 +1107,25 @@ void TextureD3D_2D::redefineImage(GLint level, GLenum internalformat, GLsizei wi
}
}
-void TextureD3D_2D::commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
+gl::ImageIndexIterator TextureD3D_2D::imageIterator() const
{
- if (isValidLevel(level))
- {
- ImageD3D *image = mImageArray[level];
- if (image->copyToStorage2D(mTexStorage, level, xoffset, yoffset, width, height))
- {
- image->markClean();
- }
- }
+ return gl::ImageIndexIterator::Make2D(0, mTexStorage->getLevelCount());
+}
+
+gl::ImageIndex TextureD3D_2D::getImageIndex(GLint mip, GLint /*layer*/) const
+{
+ // "layer" does not apply to 2D Textures.
+ return gl::ImageIndex::Make2D(mip);
}
+bool TextureD3D_2D::isValidIndex(const gl::ImageIndex &index) const
+{
+ return (mTexStorage && index.type == GL_TEXTURE_2D &&
+ index.mipIndex >= 0 && index.mipIndex < mTexStorage->getLevelCount());
+}
-TextureD3D_Cube::TextureD3D_Cube(Renderer *renderer)
- : TextureD3D(renderer),
- mTexStorage(NULL)
+TextureD3D_Cube::TextureD3D_Cube(RendererD3D *renderer)
+ : TextureD3D(renderer)
{
for (int i = 0; i < 6; i++)
{
@@ -802,19 +1185,23 @@ bool TextureD3D_Cube::isDepth(GLint level, GLint layer) const
return gl::GetInternalFormatInfo(getInternalFormat(level, layer)).depthBits > 0;
}
-void TextureD3D_Cube::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_Cube::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack,
+ const void *pixels)
{
ASSERT(depth == 1);
- int faceIndex = gl::TextureCubeMap::targetToLayerIndex(target);
GLenum sizedInternalFormat = gl::GetSizedInternalFormat(internalFormat, type);
+ gl::ImageIndex index = gl::ImageIndex::MakeCube(target, level);
- redefineImage(faceIndex, level, sizedInternalFormat, width, height);
+ redefineImage(index.layerIndex, level, sizedInternalFormat, width, height);
- TextureD3D::setImage(unpack, type, pixels, mImageArray[faceIndex][level]);
+ return TextureD3D::setImage(unpack, type, pixels, index);
}
-void TextureD3D_Cube::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_Cube::setCompressedImage(GLenum target, GLint level, GLenum format,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(depth == 1);
@@ -823,101 +1210,129 @@ void TextureD3D_Cube::setCompressedImage(GLenum target, GLint level, GLenum form
redefineImage(faceIndex, level, format, width, height);
- TextureD3D::setCompressedImage(imageSize, pixels, mImageArray[faceIndex][level]);
+ return TextureD3D::setCompressedImage(unpack, imageSize, pixels, mImageArray[faceIndex][level]);
}
-void TextureD3D_Cube::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_Cube::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
+ const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(depth == 1 && zoffset == 0);
-
- int faceIndex = gl::TextureCubeMap::targetToLayerIndex(target);
-
gl::ImageIndex index = gl::ImageIndex::MakeCube(target, level);
- if (TextureD3D::subImage(xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels, index))
- {
- commitRect(faceIndex, level, xoffset, yoffset, width, height);
- }
+ return TextureD3D::subImage(xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels, index);
}
-void TextureD3D_Cube::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_Cube::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(depth == 1 && zoffset == 0);
- int faceIndex = gl::TextureCubeMap::targetToLayerIndex(target);
+ gl::ImageIndex index = gl::ImageIndex::MakeCube(target, level);
- if (TextureD3D::subImageCompressed(xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels, mImageArray[faceIndex][level]))
+ gl::Error error = TextureD3D::subImageCompressed(xoffset, yoffset, 0, width, height, 1, format, imageSize, unpack, pixels, mImageArray[index.layerIndex][level]);
+ if (error.isError())
{
- commitRect(faceIndex, level, xoffset, yoffset, width, height);
+ return error;
}
+
+ gl::Box region(xoffset, yoffset, 0, width, height, 1);
+ return commitRegion(index, region);
}
-void TextureD3D_Cube::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_Cube::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y,
+ GLsizei width, GLsizei height, gl::Framebuffer *source)
{
int faceIndex = gl::TextureCubeMap::targetToLayerIndex(target);
GLenum sizedInternalFormat = gl::GetSizedInternalFormat(format, GL_UNSIGNED_BYTE);
redefineImage(faceIndex, level, sizedInternalFormat, width, height);
- if (!mImageArray[faceIndex][level]->isRenderableFormat())
+ gl::Rectangle sourceRect(x, y, width, height);
+ gl::ImageIndex index = gl::ImageIndex::MakeCube(target, level);
+
+ if (!canCreateRenderTargetForImage(index))
{
- mImageArray[faceIndex][level]->copy(0, 0, 0, x, y, width, height, source);
+ gl::Error error = mImageArray[faceIndex][level]->copy(0, 0, 0, sourceRect, source);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
else
{
- ensureRenderTarget();
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
+
mImageArray[faceIndex][level]->markClean();
ASSERT(width == height);
if (width > 0 && isValidFaceLevel(faceIndex, level))
{
- gl::Rectangle sourceRect;
- sourceRect.x = x;
- sourceRect.width = width;
- sourceRect.y = y;
- sourceRect.height = height;
-
- mRenderer->copyImageCube(source, sourceRect, format, 0, 0, mTexStorage, target, level);
+ error = mRenderer->copyImageCube(source, sourceRect, format, 0, 0, mTexStorage, target, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_Cube::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_Cube::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
{
int faceIndex = gl::TextureCubeMap::targetToLayerIndex(target);
- // We can only make our texture storage to a render target if the level we're copying *to* is complete
- // and the base level is cube-complete. The base level must be cube complete (common case) because we cannot
- // rely on the "getBaseLevel*" methods reliably otherwise.
- bool canCreateRenderTarget = isFaceLevelComplete(faceIndex, level) && isCubeComplete();
+ gl::Rectangle sourceRect(x, y, width, height);
+ gl::ImageIndex index = gl::ImageIndex::MakeCube(target, level);
- if (!mImageArray[faceIndex][level]->isRenderableFormat() || (!mTexStorage && !canCreateRenderTarget))
+ if (!canCreateRenderTargetForImage(index))
{
- mImageArray[faceIndex][level]->copy(0, 0, 0, x, y, width, height, source);
+ gl::Error error =mImageArray[faceIndex][level]->copy(0, 0, 0, sourceRect, source);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
else
{
- ensureRenderTarget();
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
if (isValidFaceLevel(faceIndex, level))
{
- updateStorageFaceLevel(faceIndex, level);
-
- gl::Rectangle sourceRect;
- sourceRect.x = x;
- sourceRect.width = width;
- sourceRect.y = y;
- sourceRect.height = height;
+ error = updateStorageFaceLevel(faceIndex, level);
+ if (error.isError())
+ {
+ return error;
+ }
- mRenderer->copyImageCube(source, sourceRect, gl::GetInternalFormatInfo(getBaseLevelInternalFormat()).format,
- xoffset, yoffset, mTexStorage, target, level);
+ error = mRenderer->copyImageCube(source, sourceRect, gl::GetInternalFormatInfo(getBaseLevelInternalFormat()).format,
+ xoffset, yoffset, mTexStorage, target, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_Cube::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
+gl::Error TextureD3D_Cube::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
{
ASSERT(width == height);
ASSERT(depth == 1);
@@ -939,11 +1354,20 @@ void TextureD3D_Cube::storage(GLenum target, GLsizei levels, GLenum internalform
}
}
- mImmutable = true;
-
+ // TODO(geofflang): Verify storage creation had no errors
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storage = mRenderer->createTextureStorageCube(internalformat, renderTarget, width, levels);
- setCompleteTexStorage(storage);
+
+ gl::Error error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
+ mImmutable = true;
+
+ return gl::Error(GL_NO_ERROR);
}
// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
@@ -984,7 +1408,7 @@ void TextureD3D_Cube::releaseTexImage()
}
-void TextureD3D_Cube::generateMipmaps()
+void TextureD3D_Cube::initMipmapsImages()
{
// Purge array levels 1 through q and reset them to represent the generated mipmap levels.
int levelCount = mipLevels();
@@ -996,74 +1420,76 @@ void TextureD3D_Cube::generateMipmaps()
redefineImage(faceIndex, level, mImageArray[faceIndex][0]->getInternalFormat(), faceLevelSize, faceLevelSize);
}
}
-
- if (mTexStorage && mTexStorage->isRenderTarget())
- {
- mTexStorage->generateMipmaps();
-
- for (int faceIndex = 0; faceIndex < 6; faceIndex++)
- {
- for (int level = 1; level < levelCount; level++)
- {
- mImageArray[faceIndex][level]->markClean();
- }
- }
- }
- else
- {
- for (int faceIndex = 0; faceIndex < 6; faceIndex++)
- {
- for (int level = 1; level < levelCount; level++)
- {
- mRenderer->generateMipmap(mImageArray[faceIndex][level], mImageArray[faceIndex][level - 1]);
- }
- }
- }
}
unsigned int TextureD3D_Cube::getRenderTargetSerial(const gl::ImageIndex &index)
{
- return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
+ return (ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
-RenderTarget *TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index)
+gl::Error TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{
ASSERT(gl::IsCubemapTextureTarget(index.type));
// ensure the underlying texture is created
- if (!ensureRenderTarget())
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = updateStorageFaceLevel(index.layerIndex, index.mipIndex);
+ if (error.isError())
{
- return NULL;
+ return error;
}
- updateStorageFaceLevel(index.layerIndex, index.mipIndex);
- return mTexStorage->getRenderTarget(index);
+ return mTexStorage->getRenderTarget(index, outRT);
}
-void TextureD3D_Cube::initializeStorage(bool renderTarget)
+gl::Error TextureD3D_Cube::initializeStorage(bool renderTarget)
{
// Only initialize the first time this texture is used as a render target or shader resource
if (mTexStorage)
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
// do not attempt to create storage for nonexistant data
if (!isFaceLevelComplete(0, 0))
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
bool createRenderTarget = (renderTarget || IsRenderTargetUsage(mUsage));
- setCompleteTexStorage(createCompleteStorage(createRenderTarget));
+ TextureStorage *storage = NULL;
+ gl::Error error = createCompleteStorage(createRenderTarget, &storage);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
ASSERT(mTexStorage);
// flush image data to the storage
- updateStorage();
+ error = updateStorage();
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
}
-TextureStorage *TextureD3D_Cube::createCompleteStorage(bool renderTarget) const
+gl::Error TextureD3D_Cube::createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const
{
GLsizei size = getBaseLevelWidth();
@@ -1072,29 +1498,37 @@ TextureStorage *TextureD3D_Cube::createCompleteStorage(bool renderTarget) const
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(size, size, 1));
- return mRenderer->createTextureStorageCube(getBaseLevelInternalFormat(), renderTarget, size, levels);
+ // TODO (geofflang): detect if storage creation succeeded
+ *outTexStorage = mRenderer->createTextureStorageCube(getBaseLevelInternalFormat(), renderTarget, size, levels);
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_Cube::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
+gl::Error TextureD3D_Cube::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
{
- SafeDelete(mTexStorage);
- mTexStorage = newCompleteTexStorage;
-
- if (mTexStorage && mTexStorage->isManaged())
+ if (newCompleteTexStorage && newCompleteTexStorage->isManaged())
{
for (int faceIndex = 0; faceIndex < 6; faceIndex++)
{
- for (int level = 0; level < mTexStorage->getLevelCount(); level++)
+ for (int level = 0; level < newCompleteTexStorage->getLevelCount(); level++)
{
- mImageArray[faceIndex][level]->setManagedSurfaceCube(mTexStorage, faceIndex, level);
+ gl::Error error = mImageArray[faceIndex][level]->setManagedSurfaceCube(newCompleteTexStorage, faceIndex, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
}
+ SafeDelete(mTexStorage);
+ mTexStorage = newCompleteTexStorage;
+
mDirtyImages = true;
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_Cube::updateStorage()
+gl::Error TextureD3D_Cube::updateStorage()
{
ASSERT(mTexStorage != NULL);
GLint storageLevels = mTexStorage->getLevelCount();
@@ -1104,46 +1538,16 @@ void TextureD3D_Cube::updateStorage()
{
if (mImageArray[face][level]->isDirty() && isFaceLevelComplete(face, level))
{
- updateStorageFaceLevel(face, level);
- }
- }
- }
-}
-
-bool TextureD3D_Cube::ensureRenderTarget()
-{
- initializeStorage(true);
-
- if (getBaseLevelWidth() > 0)
- {
- ASSERT(mTexStorage);
- if (!mTexStorage->isRenderTarget())
- {
- TextureStorage *newRenderTargetStorage = createCompleteStorage(true);
-
- if (!mRenderer->copyToRenderTargetCube(newRenderTargetStorage, mTexStorage))
- {
- delete newRenderTargetStorage;
- return gl::error(GL_OUT_OF_MEMORY, false);
+ gl::Error error = updateStorageFaceLevel(face, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
-
- setCompleteTexStorage(newRenderTargetStorage);
}
}
- return (mTexStorage && mTexStorage->isRenderTarget());
-}
-
-TextureStorage *TextureD3D_Cube::getBaseLevelStorage()
-{
- return mTexStorage;
-}
-
-const ImageD3D *TextureD3D_Cube::getBaseLevelImage() const
-{
- // Note: if we are not cube-complete, there is no single base level image that can describe all
- // cube faces, so this method is only well-defined for a cube-complete base level.
- return mImageArray[0][0];
+ return gl::Error(GL_NO_ERROR);
}
bool TextureD3D_Cube::isValidFaceLevel(int faceIndex, int level) const
@@ -1191,15 +1595,29 @@ bool TextureD3D_Cube::isFaceLevelComplete(int faceIndex, int level) const
return true;
}
-void TextureD3D_Cube::updateStorageFaceLevel(int faceIndex, int level)
+bool TextureD3D_Cube::isImageComplete(const gl::ImageIndex &index) const
+{
+ return isFaceLevelComplete(index.layerIndex, index.mipIndex);
+}
+
+gl::Error TextureD3D_Cube::updateStorageFaceLevel(int faceIndex, int level)
{
ASSERT(level >= 0 && faceIndex < 6 && level < (int)ArraySize(mImageArray[faceIndex]) && mImageArray[faceIndex][level] != NULL);
ImageD3D *image = mImageArray[faceIndex][level];
if (image->isDirty())
{
- commitRect(faceIndex, level, 0, 0, image->getWidth(), image->getHeight());
+ GLenum faceTarget = gl::TextureCubeMap::layerIndexToTarget(faceIndex);
+ gl::ImageIndex index = gl::ImageIndex::MakeCube(faceTarget, level);
+ gl::Box region(0, 0, 0, image->getWidth(), image->getHeight(), 1);
+ gl::Error error = commitRegion(index, region);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
void TextureD3D_Cube::redefineImage(int faceIndex, GLint level, GLenum internalformat, GLsizei width, GLsizei height)
@@ -1235,20 +1653,25 @@ void TextureD3D_Cube::redefineImage(int faceIndex, GLint level, GLenum internalf
}
}
-void TextureD3D_Cube::commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
+gl::ImageIndexIterator TextureD3D_Cube::imageIterator() const
{
- if (isValidFaceLevel(faceIndex, level))
- {
- ImageD3D *image = mImageArray[faceIndex][level];
- if (image->copyToStorageCube(mTexStorage, faceIndex, level, xoffset, yoffset, width, height))
- image->markClean();
- }
+ return gl::ImageIndexIterator::MakeCube(0, mTexStorage->getLevelCount());
}
+gl::ImageIndex TextureD3D_Cube::getImageIndex(GLint mip, GLint layer) const
+{
+ // The "layer" of the image index corresponds to the cube face
+ return gl::ImageIndex::MakeCube(gl::TextureCubeMap::layerIndexToTarget(layer), mip);
+}
-TextureD3D_3D::TextureD3D_3D(Renderer *renderer)
- : TextureD3D(renderer),
- mTexStorage(NULL)
+bool TextureD3D_Cube::isValidIndex(const gl::ImageIndex &index) const
+{
+ return (mTexStorage && gl::IsCubemapTextureTarget(index.type) &&
+ index.mipIndex >= 0 && index.mipIndex < mTexStorage->getLevelCount());
+}
+
+TextureD3D_3D::TextureD3D_3D(RendererD3D *renderer)
+ : TextureD3D(renderer)
{
for (int i = 0; i < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; ++i)
{
@@ -1327,7 +1750,9 @@ bool TextureD3D_3D::isDepth(GLint level) const
return gl::GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
}
-void TextureD3D_3D::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_3D::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack,
+ const void *pixels)
{
ASSERT(target == GL_TEXTURE_3D);
GLenum sizedInternalFormat = gl::GetSizedInternalFormat(internalFormat, type);
@@ -1336,40 +1761,60 @@ void TextureD3D_3D::setImage(GLenum target, GLint level, GLsizei width, GLsizei
bool fastUnpacked = false;
+ gl::ImageIndex index = gl::ImageIndex::Make3D(level);
+
// Attempt a fast gpu copy of the pixel data to the surface if the app bound an unpack buffer
if (isFastUnpackable(unpack, sizedInternalFormat))
{
// Will try to create RT storage if it does not exist
- gl::ImageIndex index = gl::ImageIndex::Make3D(level);
- RenderTarget *destRenderTarget = getRenderTarget(index);
+ RenderTarget *destRenderTarget = NULL;
+ gl::Error error = getRenderTarget(index, &destRenderTarget);
+ if (error.isError())
+ {
+ return error;
+ }
+
gl::Box destArea(0, 0, 0, getWidth(level), getHeight(level), getDepth(level));
- if (destRenderTarget && fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget))
+ error = fastUnpackPixels(unpack, pixels, destArea, sizedInternalFormat, type, destRenderTarget);
+ if (error.isError())
{
- // Ensure we don't overwrite our newly initialized data
- mImageArray[level]->markClean();
-
- fastUnpacked = true;
+ return error;
}
+
+ // Ensure we don't overwrite our newly initialized data
+ mImageArray[level]->markClean();
+
+ fastUnpacked = true;
}
if (!fastUnpacked)
{
- TextureD3D::setImage(unpack, type, pixels, mImageArray[level]);
+ gl::Error error = TextureD3D::setImage(unpack, type, pixels, index);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_3D::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_3D::setCompressedImage(GLenum target, GLint level, GLenum format,
+ GLsizei width, GLsizei height,GLsizei depth,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_3D);
// compressed formats don't have separate sized internal formats-- we can just use the compressed format directly
redefineImage(level, format, width, height, depth);
- TextureD3D::setCompressedImage(imageSize, pixels, mImageArray[level]);
+ return TextureD3D::setCompressedImage(unpack, imageSize, pixels, mImageArray[level]);
}
-void TextureD3D_3D::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_3D::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
+ const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_3D);
@@ -1380,74 +1825,108 @@ void TextureD3D_3D::subImage(GLenum target, GLint level, GLint xoffset, GLint yo
// Attempt a fast gpu copy of the pixel data to the surface if the app bound an unpack buffer
if (isFastUnpackable(unpack, getInternalFormat(level)))
{
- RenderTarget *destRenderTarget = getRenderTarget(index);
- gl::Box destArea(xoffset, yoffset, zoffset, width, height, depth);
-
- if (destRenderTarget && fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, destRenderTarget))
+ RenderTarget *destRenderTarget = NULL;
+ gl::Error error = getRenderTarget(index, &destRenderTarget);
+ if (error.isError())
{
- // Ensure we don't overwrite our newly initialized data
- mImageArray[level]->markClean();
+ return error;
+ }
- fastUnpacked = true;
+ gl::Box destArea(xoffset, yoffset, zoffset, width, height, depth);
+ error = fastUnpackPixels(unpack, pixels, destArea, getInternalFormat(level), type, destRenderTarget);
+ if (error.isError())
+ {
+ return error;
}
+
+ // Ensure we don't overwrite our newly initialized data
+ mImageArray[level]->markClean();
+
+ fastUnpacked = true;
}
- if (!fastUnpacked && TextureD3D::subImage(xoffset, yoffset, zoffset, width, height, depth, format, type, unpack, pixels, index))
+ if (!fastUnpacked)
{
- commitRect(level, xoffset, yoffset, zoffset, width, height, depth);
+ return TextureD3D::subImage(xoffset, yoffset, zoffset, width, height, depth, format, type,
+ unpack, pixels, index);
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_3D::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_3D::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_3D);
- if (TextureD3D::subImageCompressed(xoffset, yoffset, zoffset, width, height, depth, format, imageSize, pixels, mImageArray[level]))
+ gl::Error error = TextureD3D::subImageCompressed(xoffset, yoffset, zoffset, width, height, depth,
+ format, imageSize, unpack, pixels, mImageArray[level]);
+ if (error.isError())
{
- commitRect(level, xoffset, yoffset, zoffset, width, height, depth);
+ return error;
}
+
+ gl::ImageIndex index = gl::ImageIndex::Make3D(level);
+ gl::Box region(xoffset, yoffset, zoffset, width, height, depth);
+ return commitRegion(index, region);
}
-void TextureD3D_3D::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_3D::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y,
+ GLsizei width, GLsizei height, gl::Framebuffer *source)
{
UNIMPLEMENTED();
+ return gl::Error(GL_INVALID_OPERATION, "Copying 3D textures is unimplemented.");
}
-void TextureD3D_3D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_3D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
{
ASSERT(target == GL_TEXTURE_3D);
- // can only make our texture storage to a render target if level 0 is defined (with a width & height) and
- // the current level we're copying to is defined (with appropriate format, width & height)
- bool canCreateRenderTarget = isLevelComplete(level) && isLevelComplete(0);
+ gl::Rectangle sourceRect(x, y, width, height);
+ gl::ImageIndex index = gl::ImageIndex::Make3D(level);
- if (!mImageArray[level]->isRenderableFormat() || (!mTexStorage && !canCreateRenderTarget))
+ if (canCreateRenderTargetForImage(index))
{
- mImageArray[level]->copy(xoffset, yoffset, zoffset, x, y, width, height, source);
+ gl::Error error = mImageArray[level]->copy(xoffset, yoffset, zoffset, sourceRect, source);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
else
{
- ensureRenderTarget();
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
if (isValidLevel(level))
{
- updateStorageLevel(level);
-
- gl::Rectangle sourceRect;
- sourceRect.x = x;
- sourceRect.width = width;
- sourceRect.y = y;
- sourceRect.height = height;
+ error = updateStorageLevel(level);
+ if (error.isError())
+ {
+ return error;
+ }
- mRenderer->copyImage3D(source, sourceRect,
- gl::GetInternalFormatInfo(getBaseLevelInternalFormat()).format,
- xoffset, yoffset, zoffset, mTexStorage, level);
+ error = mRenderer->copyImage3D(source, sourceRect,
+ gl::GetInternalFormatInfo(getBaseLevelInternalFormat()).format,
+ xoffset, yoffset, zoffset, mTexStorage, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_3D::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
+gl::Error TextureD3D_3D::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
{
ASSERT(target == GL_TEXTURE_3D);
@@ -1464,11 +1943,20 @@ void TextureD3D_3D::storage(GLenum target, GLsizei levels, GLenum internalformat
mImageArray[level]->redefine(mRenderer, GL_TEXTURE_3D, GL_NONE, 0, 0, 0, true);
}
- mImmutable = true;
-
+ // TODO(geofflang): Verify storage creation had no errors
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storage = mRenderer->createTextureStorage3D(internalformat, renderTarget, width, height, depth, levels);
- setCompleteTexStorage(storage);
+
+ gl::Error error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
+ mImmutable = true;
+
+ return gl::Error(GL_NO_ERROR);
}
void TextureD3D_3D::bindTexImage(egl::Surface *surface)
@@ -1482,7 +1970,7 @@ void TextureD3D_3D::releaseTexImage()
}
-void TextureD3D_3D::generateMipmaps()
+void TextureD3D_3D::initMipmapsImages()
{
// Purge array levels 1 through q and reset them to represent the generated mipmap levels.
int levelCount = mipLevels();
@@ -1493,74 +1981,85 @@ void TextureD3D_3D::generateMipmaps()
std::max(getBaseLevelHeight() >> level, 1),
std::max(getBaseLevelDepth() >> level, 1));
}
-
- if (mTexStorage && mTexStorage->isRenderTarget())
- {
- mTexStorage->generateMipmaps();
-
- for (int level = 1; level < levelCount; level++)
- {
- mImageArray[level]->markClean();
- }
- }
- else
- {
- for (int level = 1; level < levelCount; level++)
- {
- mRenderer->generateMipmap(mImageArray[level], mImageArray[level - 1]);
- }
- }
}
unsigned int TextureD3D_3D::getRenderTargetSerial(const gl::ImageIndex &index)
{
- return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
+ return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
-RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index)
+gl::Error TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{
// ensure the underlying texture is created
- if (!ensureRenderTarget())
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
{
- return NULL;
+ return error;
}
if (index.hasLayer())
{
- updateStorage();
+ error = updateStorage();
+ if (error.isError())
+ {
+ return error;
+ }
}
else
{
- updateStorageLevel(index.mipIndex);
+ error = updateStorageLevel(index.mipIndex);
+ if (error.isError())
+ {
+ return error;
+ }
}
- return mTexStorage->getRenderTarget(index);
+ return mTexStorage->getRenderTarget(index, outRT);
}
-void TextureD3D_3D::initializeStorage(bool renderTarget)
+gl::Error TextureD3D_3D::initializeStorage(bool renderTarget)
{
// Only initialize the first time this texture is used as a render target or shader resource
if (mTexStorage)
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
// do not attempt to create storage for nonexistant data
if (!isLevelComplete(0))
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
bool createRenderTarget = (renderTarget || mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
- setCompleteTexStorage(createCompleteStorage(createRenderTarget));
+ TextureStorage *storage = NULL;
+ gl::Error error = createCompleteStorage(createRenderTarget, &storage);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
ASSERT(mTexStorage);
// flush image data to the storage
- updateStorage();
+ error = updateStorage();
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
}
-TextureStorage *TextureD3D_3D::createCompleteStorage(bool renderTarget) const
+gl::Error TextureD3D_3D::createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const
{
GLsizei width = getBaseLevelWidth();
GLsizei height = getBaseLevelHeight();
@@ -1572,10 +2071,13 @@ TextureStorage *TextureD3D_3D::createCompleteStorage(bool renderTarget) const
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(width, height, depth));
- return mRenderer->createTextureStorage3D(internalFormat, renderTarget, width, height, depth, levels);
+ // TODO: Verify creation of the storage succeeded
+ *outStorage = mRenderer->createTextureStorage3D(internalFormat, renderTarget, width, height, depth, levels);
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_3D::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
+gl::Error TextureD3D_3D::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
{
SafeDelete(mTexStorage);
mTexStorage = newCompleteTexStorage;
@@ -1583,9 +2085,11 @@ void TextureD3D_3D::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
// We do not support managed 3D storage, as that is D3D9/ES2-only
ASSERT(!mTexStorage->isManaged());
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_3D::updateStorage()
+gl::Error TextureD3D_3D::updateStorage()
{
ASSERT(mTexStorage != NULL);
GLint storageLevels = mTexStorage->getLevelCount();
@@ -1593,43 +2097,15 @@ void TextureD3D_3D::updateStorage()
{
if (mImageArray[level]->isDirty() && isLevelComplete(level))
{
- updateStorageLevel(level);
- }
- }
-}
-
-bool TextureD3D_3D::ensureRenderTarget()
-{
- initializeStorage(true);
-
- if (getBaseLevelWidth() > 0 && getBaseLevelHeight() > 0 && getBaseLevelDepth() > 0)
- {
- ASSERT(mTexStorage);
- if (!mTexStorage->isRenderTarget())
- {
- TextureStorage *newRenderTargetStorage = createCompleteStorage(true);
-
- if (!mRenderer->copyToRenderTarget3D(newRenderTargetStorage, mTexStorage))
+ gl::Error error = updateStorageLevel(level);
+ if (error.isError())
{
- delete newRenderTargetStorage;
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
-
- setCompleteTexStorage(newRenderTargetStorage);
}
}
- return (mTexStorage && mTexStorage->isRenderTarget());
-}
-
-TextureStorage *TextureD3D_3D::getBaseLevelStorage()
-{
- return mTexStorage;
-}
-
-const ImageD3D *TextureD3D_3D::getBaseLevelImage() const
-{
- return mImageArray[0];
+ return gl::Error(GL_NO_ERROR);
}
bool TextureD3D_3D::isValidLevel(int level) const
@@ -1685,15 +2161,28 @@ bool TextureD3D_3D::isLevelComplete(int level) const
return true;
}
-void TextureD3D_3D::updateStorageLevel(int level)
+bool TextureD3D_3D::isImageComplete(const gl::ImageIndex &index) const
+{
+ return isLevelComplete(index.mipIndex);
+}
+
+gl::Error TextureD3D_3D::updateStorageLevel(int level)
{
ASSERT(level >= 0 && level < (int)ArraySize(mImageArray) && mImageArray[level] != NULL);
ASSERT(isLevelComplete(level));
if (mImageArray[level]->isDirty())
{
- commitRect(level, 0, 0, 0, getWidth(level), getHeight(level), getDepth(level));
+ gl::ImageIndex index = gl::ImageIndex::Make3D(level);
+ gl::Box region(0, 0, 0, getWidth(level), getHeight(level), getDepth(level));
+ gl::Error error = commitRegion(index, region);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
void TextureD3D_3D::redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
@@ -1727,22 +2216,26 @@ void TextureD3D_3D::redefineImage(GLint level, GLenum internalformat, GLsizei wi
}
}
-void TextureD3D_3D::commitRect(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth)
+gl::ImageIndexIterator TextureD3D_3D::imageIterator() const
{
- if (isValidLevel(level))
- {
- ImageD3D *image = mImageArray[level];
- if (image->copyToStorage3D(mTexStorage, level, xoffset, yoffset, zoffset, width, height, depth))
- {
- image->markClean();
- }
- }
+ return gl::ImageIndexIterator::Make3D(0, mTexStorage->getLevelCount(),
+ gl::ImageIndex::ENTIRE_LEVEL, gl::ImageIndex::ENTIRE_LEVEL);
}
+gl::ImageIndex TextureD3D_3D::getImageIndex(GLint mip, GLint /*layer*/) const
+{
+ // The "layer" here does not apply to 3D images. We use one Image per mip.
+ return gl::ImageIndex::Make3D(mip);
+}
-TextureD3D_2DArray::TextureD3D_2DArray(Renderer *renderer)
- : TextureD3D(renderer),
- mTexStorage(NULL)
+bool TextureD3D_3D::isValidIndex(const gl::ImageIndex &index) const
+{
+ return (mTexStorage && index.type == GL_TEXTURE_3D &&
+ index.mipIndex >= 0 && index.mipIndex < mTexStorage->getLevelCount());
+}
+
+TextureD3D_2DArray::TextureD3D_2DArray(RendererD3D *renderer)
+ : TextureD3D(renderer)
{
for (int level = 0; level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS; ++level)
{
@@ -1791,11 +2284,6 @@ GLsizei TextureD3D_2DArray::getHeight(GLint level) const
return (level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS && mLayerCounts[level] > 0) ? mImageArray[level][0]->getHeight() : 0;
}
-GLsizei TextureD3D_2DArray::getLayers(GLint level) const
-{
- return (level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mLayerCounts[level] : 0;
-}
-
GLenum TextureD3D_2DArray::getInternalFormat(GLint level) const
{
return (level < gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS && mLayerCounts[level] > 0) ? mImageArray[level][0]->getInternalFormat() : GL_NONE;
@@ -1806,7 +2294,9 @@ bool TextureD3D_2DArray::isDepth(GLint level) const
return gl::GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
}
-void TextureD3D_2DArray::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_2DArray::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack,
+ const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D_ARRAY);
@@ -1820,11 +2310,20 @@ void TextureD3D_2DArray::setImage(GLenum target, GLint level, GLsizei width, GLs
for (int i = 0; i < depth; i++)
{
const void *layerPixels = pixels ? (reinterpret_cast<const unsigned char*>(pixels) + (inputDepthPitch * i)) : NULL;
- TextureD3D::setImage(unpack, type, layerPixels, mImageArray[level][i]);
+ gl::ImageIndex index = gl::ImageIndex::Make2DArray(level, i);
+ gl::Error error = TextureD3D::setImage(unpack, type, layerPixels, index);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2DArray::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_2DArray::setCompressedImage(GLenum target, GLint level, GLenum format,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D_ARRAY);
@@ -1837,11 +2336,19 @@ void TextureD3D_2DArray::setCompressedImage(GLenum target, GLint level, GLenum f
for (int i = 0; i < depth; i++)
{
const void *layerPixels = pixels ? (reinterpret_cast<const unsigned char*>(pixels) + (inputDepthPitch * i)) : NULL;
- TextureD3D::setCompressedImage(imageSize, layerPixels, mImageArray[level][i]);
+ gl::Error error = TextureD3D::setCompressedImage(unpack, imageSize, layerPixels, mImageArray[level][i]);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2DArray::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels)
+gl::Error TextureD3D_2DArray::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
+ const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D_ARRAY);
@@ -1854,14 +2361,20 @@ void TextureD3D_2DArray::subImage(GLenum target, GLint level, GLint xoffset, GLi
const void *layerPixels = pixels ? (reinterpret_cast<const unsigned char*>(pixels) + (inputDepthPitch * i)) : NULL;
gl::ImageIndex index = gl::ImageIndex::Make2DArray(level, layer);
- if (TextureD3D::subImage(xoffset, yoffset, zoffset, width, height, 1, format, type, unpack, layerPixels, index))
+ gl::Error error = TextureD3D::subImage(xoffset, yoffset, zoffset, width, height, 1, format, type,
+ unpack, layerPixels, index);
+ if (error.isError())
{
- commitRect(level, xoffset, yoffset, layer, width, height);
+ return error;
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2DArray::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
+gl::Error TextureD3D_2DArray::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format,
+ GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels)
{
ASSERT(target == GL_TEXTURE_2D_ARRAY);
@@ -1873,52 +2386,75 @@ void TextureD3D_2DArray::subImageCompressed(GLenum target, GLint level, GLint xo
int layer = zoffset + i;
const void *layerPixels = pixels ? (reinterpret_cast<const unsigned char*>(pixels) + (inputDepthPitch * i)) : NULL;
- if (TextureD3D::subImageCompressed(xoffset, yoffset, zoffset, width, height, 1, format, imageSize, layerPixels, mImageArray[level][layer]))
+ gl::Error error = TextureD3D::subImageCompressed(xoffset, yoffset, zoffset, width, height, 1, format, imageSize, unpack, layerPixels, mImageArray[level][layer]);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ gl::ImageIndex index = gl::ImageIndex::Make2DArray(level, layer);
+ gl::Box region(xoffset, yoffset, 0, width, height, 1);
+ error = commitRegion(index, region);
+ if (error.isError())
{
- commitRect(level, xoffset, yoffset, layer, width, height);
+ return error;
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2DArray::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_2DArray::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
{
UNIMPLEMENTED();
+ return gl::Error(GL_INVALID_OPERATION, "Copying 2D array textures is unimplemented.");
}
-void TextureD3D_2DArray::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error TextureD3D_2DArray::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
{
ASSERT(target == GL_TEXTURE_2D_ARRAY);
- // can only make our texture storage to a render target if level 0 is defined (with a width & height) and
- // the current level we're copying to is defined (with appropriate format, width & height)
- bool canCreateRenderTarget = isLevelComplete(level) && isLevelComplete(0);
+ gl::Rectangle sourceRect(x, y, width, height);
+ gl::ImageIndex index = gl::ImageIndex::Make2DArray(level, zoffset);
- if (!mImageArray[level][0]->isRenderableFormat() || (!mTexStorage && !canCreateRenderTarget))
+ if (canCreateRenderTargetForImage(index))
{
- mImageArray[level][zoffset]->copy(xoffset, yoffset, 0, x, y, width, height, source);
+ gl::Error error = mImageArray[level][zoffset]->copy(xoffset, yoffset, 0, sourceRect, source);
+ if (error.isError())
+ {
+ return error;
+ }
+
mDirtyImages = true;
}
else
{
- ensureRenderTarget();
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
+ {
+ return error;
+ }
if (isValidLevel(level))
{
- updateStorageLevel(level);
-
- gl::Rectangle sourceRect;
- sourceRect.x = x;
- sourceRect.width = width;
- sourceRect.y = y;
- sourceRect.height = height;
+ error = updateStorageLevel(level);
+ if (error.isError())
+ {
+ return error;
+ }
- mRenderer->copyImage2DArray(source, sourceRect, gl::GetInternalFormatInfo(getInternalFormat(0)).format,
- xoffset, yoffset, zoffset, mTexStorage, level);
+ error = mRenderer->copyImage2DArray(source, sourceRect, gl::GetInternalFormatInfo(getInternalFormat(0)).format,
+ xoffset, yoffset, zoffset, mTexStorage, level);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2DArray::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
+gl::Error TextureD3D_2DArray::storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
{
ASSERT(target == GL_TEXTURE_2D_ARRAY);
@@ -1945,11 +2481,20 @@ void TextureD3D_2DArray::storage(GLenum target, GLsizei levels, GLenum internalf
}
}
- mImmutable = true;
-
+ // TODO(geofflang): Verify storage creation had no errors
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storage = mRenderer->createTextureStorage2DArray(internalformat, renderTarget, width, height, depth, levels);
- setCompleteTexStorage(storage);
+
+ gl::Error error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
+ mImmutable = true;
+
+ return gl::Error(GL_NO_ERROR);
}
void TextureD3D_2DArray::bindTexImage(egl::Surface *surface)
@@ -1963,7 +2508,7 @@ void TextureD3D_2DArray::releaseTexImage()
}
-void TextureD3D_2DArray::generateMipmaps()
+void TextureD3D_2DArray::initMipmapsImages()
{
int baseWidth = getBaseLevelWidth();
int baseHeight = getBaseLevelHeight();
@@ -1976,76 +2521,78 @@ void TextureD3D_2DArray::generateMipmaps()
{
redefineImage(level, baseFormat, std::max(baseWidth >> level, 1), std::max(baseHeight >> level, 1), baseDepth);
}
-
- if (mTexStorage && mTexStorage->isRenderTarget())
- {
- mTexStorage->generateMipmaps();
-
- for (int level = 1; level < levelCount; level++)
- {
- for (int layer = 0; layer < mLayerCounts[level]; layer++)
- {
- mImageArray[level][layer]->markClean();
- }
- }
- }
- else
- {
- for (int level = 1; level < levelCount; level++)
- {
- for (int layer = 0; layer < mLayerCounts[level]; layer++)
- {
- mRenderer->generateMipmap(mImageArray[level][layer], mImageArray[level - 1][layer]);
- }
- }
- }
}
unsigned int TextureD3D_2DArray::getRenderTargetSerial(const gl::ImageIndex &index)
{
- return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
+ return (!ensureRenderTarget().isError() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
-RenderTarget *TextureD3D_2DArray::getRenderTarget(const gl::ImageIndex &index)
+gl::Error TextureD3D_2DArray::getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT)
{
// ensure the underlying texture is created
- if (!ensureRenderTarget())
+ gl::Error error = ensureRenderTarget();
+ if (error.isError())
{
- return NULL;
+ return error;
}
- updateStorageLevel(index.mipIndex);
- return mTexStorage->getRenderTarget(index);
+ error = updateStorageLevel(index.mipIndex);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return mTexStorage->getRenderTarget(index, outRT);
}
-void TextureD3D_2DArray::initializeStorage(bool renderTarget)
+gl::Error TextureD3D_2DArray::initializeStorage(bool renderTarget)
{
// Only initialize the first time this texture is used as a render target or shader resource
if (mTexStorage)
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
// do not attempt to create storage for nonexistant data
if (!isLevelComplete(0))
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
bool createRenderTarget = (renderTarget || mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
- setCompleteTexStorage(createCompleteStorage(createRenderTarget));
+ TextureStorage *storage = NULL;
+ gl::Error error = createCompleteStorage(createRenderTarget, &storage);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ error = setCompleteTexStorage(storage);
+ if (error.isError())
+ {
+ SafeDelete(storage);
+ return error;
+ }
+
ASSERT(mTexStorage);
// flush image data to the storage
- updateStorage();
+ error = updateStorage();
+ if (error.isError())
+ {
+ return error;
+ }
+
+ return gl::Error(GL_NO_ERROR);
}
-TextureStorage *TextureD3D_2DArray::createCompleteStorage(bool renderTarget) const
+gl::Error TextureD3D_2DArray::createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const
{
GLsizei width = getBaseLevelWidth();
GLsizei height = getBaseLevelHeight();
- GLsizei depth = getLayers(0);
+ GLsizei depth = getLayerCount(0);
GLenum internalFormat = getBaseLevelInternalFormat();
ASSERT(width > 0 && height > 0 && depth > 0);
@@ -2053,10 +2600,13 @@ TextureStorage *TextureD3D_2DArray::createCompleteStorage(bool renderTarget) con
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(width, height, 1));
- return mRenderer->createTextureStorage2DArray(internalFormat, renderTarget, width, height, depth, levels);
+ // TODO(geofflang): Verify storage creation succeeds
+ *outStorage = mRenderer->createTextureStorage2DArray(internalFormat, renderTarget, width, height, depth, levels);
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2DArray::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
+gl::Error TextureD3D_2DArray::setCompleteTexStorage(TextureStorage *newCompleteTexStorage)
{
SafeDelete(mTexStorage);
mTexStorage = newCompleteTexStorage;
@@ -2064,9 +2614,11 @@ void TextureD3D_2DArray::setCompleteTexStorage(TextureStorage *newCompleteTexSto
// We do not support managed 2D array storage, as managed storage is ES2/D3D9 only
ASSERT(!mTexStorage->isManaged());
+
+ return gl::Error(GL_NO_ERROR);
}
-void TextureD3D_2DArray::updateStorage()
+gl::Error TextureD3D_2DArray::updateStorage()
{
ASSERT(mTexStorage != NULL);
GLint storageLevels = mTexStorage->getLevelCount();
@@ -2074,43 +2626,15 @@ void TextureD3D_2DArray::updateStorage()
{
if (isLevelComplete(level))
{
- updateStorageLevel(level);
- }
- }
-}
-
-bool TextureD3D_2DArray::ensureRenderTarget()
-{
- initializeStorage(true);
-
- if (getBaseLevelWidth() > 0 && getBaseLevelHeight() > 0 && getLayers(0) > 0)
- {
- ASSERT(mTexStorage);
- if (!mTexStorage->isRenderTarget())
- {
- TextureStorage *newRenderTargetStorage = createCompleteStorage(true);
-
- if (!mRenderer->copyToRenderTarget2DArray(newRenderTargetStorage, mTexStorage))
+ gl::Error error = updateStorageLevel(level);
+ if (error.isError())
{
- delete newRenderTargetStorage;
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
-
- setCompleteTexStorage(newRenderTargetStorage);
}
}
- return (mTexStorage && mTexStorage->isRenderTarget());
-}
-
-const ImageD3D *TextureD3D_2DArray::getBaseLevelImage() const
-{
- return (mLayerCounts[0] > 0 ? mImageArray[0][0] : NULL);
-}
-
-TextureStorage *TextureD3D_2DArray::getBaseLevelStorage()
-{
- return mTexStorage;
+ return gl::Error(GL_NO_ERROR);
}
bool TextureD3D_2DArray::isValidLevel(int level) const
@@ -2129,7 +2653,7 @@ bool TextureD3D_2DArray::isLevelComplete(int level) const
GLsizei width = getBaseLevelWidth();
GLsizei height = getBaseLevelHeight();
- GLsizei layers = getLayers(0);
+ GLsizei layers = getLayerCount(0);
if (width <= 0 || height <= 0 || layers <= 0)
{
@@ -2156,7 +2680,7 @@ bool TextureD3D_2DArray::isLevelComplete(int level) const
return false;
}
- if (getLayers(level) != layers)
+ if (getLayerCount(level) != layers)
{
return false;
}
@@ -2164,7 +2688,12 @@ bool TextureD3D_2DArray::isLevelComplete(int level) const
return true;
}
-void TextureD3D_2DArray::updateStorageLevel(int level)
+bool TextureD3D_2DArray::isImageComplete(const gl::ImageIndex &index) const
+{
+ return isLevelComplete(index.mipIndex);
+}
+
+gl::Error TextureD3D_2DArray::updateStorageLevel(int level)
{
ASSERT(level >= 0 && level < (int)ArraySize(mLayerCounts));
ASSERT(isLevelComplete(level));
@@ -2174,9 +2703,17 @@ void TextureD3D_2DArray::updateStorageLevel(int level)
ASSERT(mImageArray[level] != NULL && mImageArray[level][layer] != NULL);
if (mImageArray[level][layer]->isDirty())
{
- commitRect(level, 0, 0, layer, getWidth(level), getHeight(level));
+ gl::ImageIndex index = gl::ImageIndex::Make2DArray(level, layer);
+ gl::Box region(0, 0, 0, getWidth(level), getHeight(level), 1);
+ gl::Error error = commitRegion(index, region);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
void TextureD3D_2DArray::deleteImages()
@@ -2198,7 +2735,7 @@ void TextureD3D_2DArray::redefineImage(GLint level, GLenum internalformat, GLsiz
// If there currently is a corresponding storage texture image, it has these parameters
const int storageWidth = std::max(1, getBaseLevelWidth() >> level);
const int storageHeight = std::max(1, getBaseLevelHeight() >> level);
- const int storageDepth = getLayers(0);
+ const int storageDepth = getLayerCount(0);
const GLenum storageFormat = getBaseLevelInternalFormat();
for (int layer = 0; layer < mLayerCounts[level]; layer++)
@@ -2245,16 +2782,32 @@ void TextureD3D_2DArray::redefineImage(GLint level, GLenum internalformat, GLsiz
}
}
-void TextureD3D_2DArray::commitRect(GLint level, GLint xoffset, GLint yoffset, GLint layerTarget, GLsizei width, GLsizei height)
+gl::ImageIndexIterator TextureD3D_2DArray::imageIterator() const
+{
+ return gl::ImageIndexIterator::Make2DArray(0, mTexStorage->getLevelCount(), mLayerCounts);
+}
+
+gl::ImageIndex TextureD3D_2DArray::getImageIndex(GLint mip, GLint layer) const
+{
+ return gl::ImageIndex::Make2DArray(mip, layer);
+}
+
+bool TextureD3D_2DArray::isValidIndex(const gl::ImageIndex &index) const
{
- if (isValidLevel(level) && layerTarget < getLayers(level))
+ // Check for having a storage and the right type of index
+ if (!mTexStorage || index.type != GL_TEXTURE_2D_ARRAY)
{
- ImageD3D *image = mImageArray[level][layerTarget];
- if (image->copyToStorage2DArray(mTexStorage, level, xoffset, yoffset, layerTarget, width, height))
- {
- image->markClean();
- }
+ return false;
}
+
+ // Check the mip index
+ if (index.mipIndex < 0 || index.mipIndex >= mTexStorage->getLevelCount())
+ {
+ return false;
+ }
+
+ // Check the layer index
+ return (!index.hasLayer() || (index.layerIndex >= 0 && index.layerIndex < mLayerCounts[index.mipIndex]));
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.h
index 41c73180de..083a6335b9 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureD3D.h
@@ -11,7 +11,7 @@
#include "libGLESv2/renderer/TextureImpl.h"
#include "libGLESv2/angletypes.h"
-#include "libGLESv2/constants.h"
+#include "libGLESv2/Constants.h"
namespace gl
{
@@ -23,19 +23,19 @@ namespace rx
class Image;
class ImageD3D;
-class Renderer;
+class RendererD3D;
class RenderTarget;
class TextureStorage;
class TextureD3D : public TextureImpl
{
public:
- TextureD3D(Renderer *renderer);
+ TextureD3D(RendererD3D *renderer);
virtual ~TextureD3D();
static TextureD3D *makeTextureD3D(TextureImpl *texture);
- virtual TextureStorage *getNativeTexture();
+ TextureStorage *getNativeTexture();
virtual void setUsage(GLenum usage) { mUsage = usage; }
bool hasDirtyImages() const { return mDirtyImages; }
@@ -48,45 +48,68 @@ class TextureD3D : public TextureImpl
bool isImmutable() const { return mImmutable; }
- virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index) = 0;
+ virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index) = 0;
+ // Returns an iterator over all "Images" for this particular Texture.
+ virtual gl::ImageIndexIterator imageIterator() const = 0;
+
+ // Returns an ImageIndex for a particular "Image". 3D Textures do not have images for
+ // slices of their depth texures, so 3D textures ignore the layer parameter.
+ virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const = 0;
+ virtual bool isValidIndex(const gl::ImageIndex &index) const = 0;
+
+ virtual gl::Error generateMipmaps();
+ TextureStorage *getStorage();
+ Image *getBaseLevelImage() const;
+
protected:
- void setImage(const gl::PixelUnpackState &unpack, GLenum type, const void *pixels, Image *image);
- bool subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels, const gl::ImageIndex &index);
- void setCompressedImage(GLsizei imageSize, const void *pixels, Image *image);
- bool subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLsizei imageSize, const void *pixels, Image *image);
+ gl::Error setImage(const gl::PixelUnpackState &unpack, GLenum type, const void *pixels, const gl::ImageIndex &index);
+ gl::Error subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels, const gl::ImageIndex &index);
+ gl::Error setCompressedImage(const gl::PixelUnpackState &unpack, GLsizei imageSize, const void *pixels, Image *image);
+ gl::Error subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels, Image *image);
bool isFastUnpackable(const gl::PixelUnpackState &unpack, GLenum sizedInternalFormat);
- bool fastUnpackPixels(const gl::PixelUnpackState &unpack, const void *pixels, const gl::Box &destArea,
- GLenum sizedInternalFormat, GLenum type, RenderTarget *destRenderTarget);
+ gl::Error fastUnpackPixels(const gl::PixelUnpackState &unpack, const void *pixels, const gl::Box &destArea,
+ GLenum sizedInternalFormat, GLenum type, RenderTarget *destRenderTarget);
GLint creationLevels(GLsizei width, GLsizei height, GLsizei depth) const;
int mipLevels() const;
+ virtual void initMipmapsImages() = 0;
+ bool isBaseImageZeroSize() const;
+ virtual bool isImageComplete(const gl::ImageIndex &index) const = 0;
- Renderer *mRenderer;
+ bool canCreateRenderTargetForImage(const gl::ImageIndex &index) const;
+ virtual gl::Error ensureRenderTarget();
+
+ virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const = 0;
+ virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage) = 0;
+ gl::Error commitRegion(const gl::ImageIndex &index, const gl::Box &region);
+
+ RendererD3D *mRenderer;
GLenum mUsage;
bool mDirtyImages;
bool mImmutable;
+ TextureStorage *mTexStorage;
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D);
- virtual void initializeStorage(bool renderTarget) = 0;
+ virtual gl::Error initializeStorage(bool renderTarget) = 0;
- virtual void updateStorage() = 0;
- virtual TextureStorage *getBaseLevelStorage() = 0;
- virtual const ImageD3D *getBaseLevelImage() const = 0;
+ virtual gl::Error updateStorage() = 0;
+
+ bool shouldUseSetData(const Image *image) const;
};
class TextureD3D_2D : public TextureD3D
{
public:
- TextureD3D_2D(Renderer *renderer);
+ TextureD3D_2D(RendererD3D *renderer);
virtual ~TextureD3D_2D();
virtual Image *getImage(int level, int layer) const;
@@ -99,50 +122,49 @@ class TextureD3D_2D : public TextureD3D
GLenum getActualFormat(GLint level) const;
bool isDepth(GLint level) const;
- virtual void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
- virtual void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
- virtual void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+ virtual gl::Error setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage();
- virtual void generateMipmaps();
-
- virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index);
+ virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
+ virtual gl::ImageIndexIterator imageIterator() const;
+ virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
+ virtual bool isValidIndex(const gl::ImageIndex &index) const;
+
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_2D);
- virtual void initializeStorage(bool renderTarget);
- TextureStorage *createCompleteStorage(bool renderTarget) const;
- void setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
+ virtual gl::Error initializeStorage(bool renderTarget);
+ virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const;
+ virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
- virtual void updateStorage();
- bool ensureRenderTarget();
- virtual TextureStorage *getBaseLevelStorage();
- virtual const ImageD3D *getBaseLevelImage() const;
+ virtual gl::Error updateStorage();
+ virtual void initMipmapsImages();
bool isValidLevel(int level) const;
bool isLevelComplete(int level) const;
+ virtual bool isImageComplete(const gl::ImageIndex &index) const;
- void updateStorageLevel(int level);
+ gl::Error updateStorageLevel(int level);
void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height);
- void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
- TextureStorage *mTexStorage;
ImageD3D *mImageArray[gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
};
class TextureD3D_Cube : public TextureD3D
{
public:
- TextureD3D_Cube(Renderer *renderer);
+ TextureD3D_Cube(RendererD3D *renderer);
virtual ~TextureD3D_Cube();
virtual Image *getImage(int level, int layer) const;
@@ -156,51 +178,49 @@ class TextureD3D_Cube : public TextureD3D
GLenum getInternalFormat(GLint level, GLint layer) const;
bool isDepth(GLint level, GLint layer) const;
- virtual void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
- virtual void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
- virtual void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+ virtual gl::Error setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage();
- virtual void generateMipmaps();
-
- virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index);
+ virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
+ virtual gl::ImageIndexIterator imageIterator() const;
+ virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
+ virtual bool isValidIndex(const gl::ImageIndex &index) const;
+
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_Cube);
- virtual void initializeStorage(bool renderTarget);
- TextureStorage *createCompleteStorage(bool renderTarget) const;
- void setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
+ virtual gl::Error initializeStorage(bool renderTarget);
+ virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outTexStorage) const;
+ virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
- virtual void updateStorage();
- bool ensureRenderTarget();
- virtual TextureStorage *getBaseLevelStorage();
- virtual const ImageD3D *getBaseLevelImage() const;
+ virtual gl::Error updateStorage();
+ virtual void initMipmapsImages();
bool isValidFaceLevel(int faceIndex, int level) const;
bool isFaceLevelComplete(int faceIndex, int level) const;
bool isCubeComplete() const;
- void updateStorageFaceLevel(int faceIndex, int level);
+ virtual bool isImageComplete(const gl::ImageIndex &index) const;
+ gl::Error updateStorageFaceLevel(int faceIndex, int level);
void redefineImage(int faceIndex, GLint level, GLenum internalformat, GLsizei width, GLsizei height);
- void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
ImageD3D *mImageArray[6][gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
-
- TextureStorage *mTexStorage;
};
class TextureD3D_3D : public TextureD3D
{
public:
- TextureD3D_3D(Renderer *renderer);
+ TextureD3D_3D(RendererD3D *renderer);
virtual ~TextureD3D_3D();
virtual Image *getImage(int level, int layer) const;
@@ -213,50 +233,48 @@ class TextureD3D_3D : public TextureD3D
GLenum getInternalFormat(GLint level) const;
bool isDepth(GLint level) const;
- virtual void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
- virtual void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
- virtual void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+ virtual gl::Error setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage();
- virtual void generateMipmaps();
-
- virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index);
+ virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
+ virtual gl::ImageIndexIterator imageIterator() const;
+ virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
+ virtual bool isValidIndex(const gl::ImageIndex &index) const;
+
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_3D);
- virtual void initializeStorage(bool renderTarget);
- TextureStorage *createCompleteStorage(bool renderTarget) const;
- void setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
+ virtual gl::Error initializeStorage(bool renderTarget);
+ virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const;
+ virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
- virtual void updateStorage();
- bool ensureRenderTarget();
- virtual TextureStorage *getBaseLevelStorage();
- virtual const ImageD3D *getBaseLevelImage() const;
+ virtual gl::Error updateStorage();
+ virtual void initMipmapsImages();
bool isValidLevel(int level) const;
bool isLevelComplete(int level) const;
- void updateStorageLevel(int level);
+ virtual bool isImageComplete(const gl::ImageIndex &index) const;
+ gl::Error updateStorageLevel(int level);
void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
- void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
ImageD3D *mImageArray[gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
-
- TextureStorage *mTexStorage;
};
class TextureD3D_2DArray : public TextureD3D
{
public:
- TextureD3D_2DArray(Renderer *renderer);
+ TextureD3D_2DArray(RendererD3D *renderer);
virtual ~TextureD3D_2DArray();
virtual Image *getImage(int level, int layer) const;
@@ -265,45 +283,44 @@ class TextureD3D_2DArray : public TextureD3D
GLsizei getWidth(GLint level) const;
GLsizei getHeight(GLint level) const;
- GLsizei getLayers(GLint level) const;
GLenum getInternalFormat(GLint level) const;
bool isDepth(GLint level) const;
- virtual void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
- virtual void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
- virtual void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
- virtual void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
- virtual void storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+ virtual gl::Error setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const gl::PixelUnpackState &unpack, const void *pixels);
+ virtual gl::Error copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
virtual void bindTexImage(egl::Surface *surface);
virtual void releaseTexImage();
- virtual void generateMipmaps();
-
- virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index);
+ virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual unsigned int getRenderTargetSerial(const gl::ImageIndex &index);
+ virtual gl::ImageIndexIterator imageIterator() const;
+ virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const;
+ virtual bool isValidIndex(const gl::ImageIndex &index) const;
+
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D_2DArray);
- virtual void initializeStorage(bool renderTarget);
- TextureStorage *createCompleteStorage(bool renderTarget) const;
- void setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
+ virtual gl::Error initializeStorage(bool renderTarget);
+ virtual gl::Error createCompleteStorage(bool renderTarget, TextureStorage **outStorage) const;
+ virtual gl::Error setCompleteTexStorage(TextureStorage *newCompleteTexStorage);
- virtual void updateStorage();
- bool ensureRenderTarget();
- virtual TextureStorage *getBaseLevelStorage();
- virtual const ImageD3D *getBaseLevelImage() const;
+ virtual gl::Error updateStorage();
+ virtual void initMipmapsImages();
bool isValidLevel(int level) const;
bool isLevelComplete(int level) const;
- void updateStorageLevel(int level);
+ virtual bool isImageComplete(const gl::ImageIndex &index) const;
+ gl::Error updateStorageLevel(int level);
void deleteImages();
void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
- void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint layerTarget, GLsizei width, GLsizei height);
// Storing images as an array of single depth textures since D3D11 treats each array level of a
// Texture2D object as a separate subresource. Each layer would have to be looped over
@@ -311,8 +328,6 @@ class TextureD3D_2DArray : public TextureD3D
// sense for the Image class to not have to worry about layer subresource as well as mip subresources.
GLsizei mLayerCounts[gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
ImageD3D **mImageArray[gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
-
- TextureStorage *mTexStorage;
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.cpp
index dedd266c09..320b74b8ed 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.cpp
@@ -8,6 +8,7 @@
#include "libGLESv2/renderer/d3d/TextureStorage.h"
#include "libGLESv2/renderer/d3d/TextureD3D.h"
+#include "libGLESv2/renderer/RenderTarget.h"
#include "libGLESv2/renderer/Renderer.h"
#include "libGLESv2/Renderbuffer.h"
#include "libGLESv2/Texture.h"
@@ -18,17 +19,14 @@
namespace rx
{
-unsigned int TextureStorage::mCurrentTextureSerial = 1;
-
TextureStorage::TextureStorage()
- : mTextureSerial(issueTextureSerial()),
- mFirstRenderTargetSerial(0),
+ : mFirstRenderTargetSerial(0),
mRenderTargetSerialsLayerStride(0)
{}
void TextureStorage::initializeSerials(unsigned int rtSerialsToReserve, unsigned int rtSerialsLayerStride)
{
- mFirstRenderTargetSerial = gl::RenderbufferStorage::issueSerials(rtSerialsToReserve);
+ mFirstRenderTargetSerial = RenderTarget::issueSerials(rtSerialsToReserve);
mRenderTargetSerialsLayerStride = rtSerialsLayerStride;
}
@@ -38,14 +36,4 @@ unsigned int TextureStorage::getRenderTargetSerial(const gl::ImageIndex &index)
return mFirstRenderTargetSerial + static_cast<unsigned int>(index.mipIndex) + layerOffset;
}
-unsigned int TextureStorage::getTextureSerial() const
-{
- return mTextureSerial;
-}
-
-unsigned int TextureStorage::issueTextureSerial()
-{
- return mCurrentTextureSerial++;
-}
-
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.h
index 9cc2c2977b..da92be3c74 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/TextureStorage.h
@@ -9,20 +9,26 @@
#ifndef LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
#define LIBGLESV2_RENDERER_TEXTURESTORAGE_H_
+#include "libGLESv2/Error.h"
+
#include "common/debug.h"
+#include "libGLESv2/Error.h"
#include <GLES2/gl2.h>
+#include <cstdint>
namespace gl
{
struct ImageIndex;
+struct Box;
+struct PixelUnpackState;
}
namespace rx
{
-class Renderer;
class SwapChain;
class RenderTarget;
+class Image;
class TextureStorage
{
@@ -35,8 +41,12 @@ class TextureStorage
virtual bool isManaged() const = 0;
virtual int getLevelCount() const = 0;
- virtual RenderTarget *getRenderTarget(const gl::ImageIndex &index) = 0;
- virtual void generateMipmaps() = 0;
+ virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
+ virtual gl::Error generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0;
+
+ virtual gl::Error copyToStorage(TextureStorage *destStorage) = 0;
+ virtual gl::Error setData(const gl::ImageIndex &index, Image *image, const gl::Box *destBox, GLenum type,
+ const gl::PixelUnpackState &unpack, const uint8_t *pixelData) = 0;
unsigned int getRenderTargetSerial(const gl::ImageIndex &index) const;
unsigned int getTextureSerial() const;
@@ -47,11 +57,6 @@ class TextureStorage
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage);
- const unsigned int mTextureSerial;
- static unsigned int issueTextureSerial();
-
- static unsigned int mCurrentTextureSerial;
-
unsigned int mFirstRenderTargetSerial;
unsigned int mRenderTargetSerialsLayerStride;
};
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.cpp
index 4f85eb94fa..73f0c79e19 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.cpp
@@ -9,7 +9,7 @@
#include "libGLESv2/renderer/d3d/VertexBuffer.h"
#include "libGLESv2/renderer/d3d/BufferD3D.h"
-#include "libGLESv2/renderer/Renderer.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
#include "libGLESv2/VertexAttribute.h"
#include "common/mathutil.h"
@@ -38,7 +38,7 @@ unsigned int VertexBuffer::getSerial() const
return mSerial;
}
-VertexBufferInterface::VertexBufferInterface(rx::Renderer *renderer, bool dynamic) : mRenderer(renderer)
+VertexBufferInterface::VertexBufferInterface(RendererD3D *renderer, bool dynamic) : mRenderer(renderer)
{
mDynamic = dynamic;
mWritePosition = 0;
@@ -127,7 +127,7 @@ gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute
mWritePosition += spaceRequired;
// Align to 16-byte boundary
- mWritePosition = rx::roundUp(mWritePosition, 16u);
+ mWritePosition = roundUp(mWritePosition, 16u);
return gl::Error(GL_NO_ERROR);
}
@@ -153,7 +153,7 @@ gl::Error VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &a
mReservedSpace += requiredSpace;
// Align to 16-byte boundary
- mReservedSpace = rx::roundUp(mReservedSpace, 16u);
+ mReservedSpace = roundUp(mReservedSpace, 16u);
return gl::Error(GL_NO_ERROR);
}
@@ -197,7 +197,7 @@ bool VertexBufferInterface::directStoragePossible(const gl::VertexAttribute &att
return !requiresConversion && isAligned;
}
-StreamingVertexBufferInterface::StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize) : VertexBufferInterface(renderer, true)
+StreamingVertexBufferInterface::StreamingVertexBufferInterface(RendererD3D *renderer, std::size_t initialSize) : VertexBufferInterface(renderer, true)
{
setBufferSize(initialSize);
}
@@ -231,7 +231,7 @@ gl::Error StreamingVertexBufferInterface::reserveSpace(unsigned int size)
return gl::Error(GL_NO_ERROR);
}
-StaticVertexBufferInterface::StaticVertexBufferInterface(rx::Renderer *renderer) : VertexBufferInterface(renderer, false)
+StaticVertexBufferInterface::StaticVertexBufferInterface(RendererD3D *renderer) : VertexBufferInterface(renderer, false)
{
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.h
index fa747d9cb4..4b40818f8e 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexBuffer.h
@@ -26,7 +26,7 @@ struct VertexAttribCurrentValueData;
namespace rx
{
-class Renderer;
+class RendererD3D;
class VertexBuffer
{
@@ -60,7 +60,7 @@ class VertexBuffer
class VertexBufferInterface
{
public:
- VertexBufferInterface(rx::Renderer *renderer, bool dynamic);
+ VertexBufferInterface(RendererD3D *renderer, bool dynamic);
virtual ~VertexBufferInterface();
gl::Error reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
@@ -90,7 +90,7 @@ class VertexBufferInterface
private:
DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface);
- rx::Renderer *const mRenderer;
+ RendererD3D *const mRenderer;
VertexBuffer* mVertexBuffer;
@@ -102,7 +102,7 @@ class VertexBufferInterface
class StreamingVertexBufferInterface : public VertexBufferInterface
{
public:
- StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize);
+ StreamingVertexBufferInterface(RendererD3D *renderer, std::size_t initialSize);
~StreamingVertexBufferInterface();
protected:
@@ -112,7 +112,7 @@ class StreamingVertexBufferInterface : public VertexBufferInterface
class StaticVertexBufferInterface : public VertexBufferInterface
{
public:
- explicit StaticVertexBufferInterface(rx::Renderer *renderer);
+ explicit StaticVertexBufferInterface(RendererD3D *renderer);
~StaticVertexBufferInterface();
gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
index 7034b78eab..8d3df31c8b 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.cpp
@@ -14,6 +14,7 @@
#include "libGLESv2/Buffer.h"
#include "libGLESv2/ProgramBinary.h"
#include "libGLESv2/VertexAttribute.h"
+#include "libGLESv2/State.h"
namespace
{
@@ -51,7 +52,7 @@ static int StreamingBufferElementCount(const gl::VertexAttribute &attrib, int ve
return vertexDrawCount;
}
-VertexDataManager::VertexDataManager(Renderer *renderer) : mRenderer(renderer)
+VertexDataManager::VertexDataManager(RendererD3D *renderer) : mRenderer(renderer)
{
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
@@ -82,8 +83,8 @@ VertexDataManager::~VertexDataManager()
}
}
-gl::Error VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[],
- gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *translated, GLsizei instances)
+gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint start, GLsizei count,
+ TranslatedAttribute *translated, GLsizei instances)
{
if (!mStreamingBuffer)
{
@@ -93,20 +94,22 @@ gl::Error VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs
// Invalidate static buffers that don't contain matching attributes
for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
{
- translated[attributeIndex].active = (programBinary->getSemanticIndex(attributeIndex) != -1);
+ translated[attributeIndex].active = (state.getCurrentProgramBinary()->getSemanticIndex(attributeIndex) != -1);
+ const gl::VertexAttribute &curAttrib = state.getVertexAttribState(attributeIndex);
- if (translated[attributeIndex].active && attribs[attributeIndex].enabled)
+ if (translated[attributeIndex].active && curAttrib.enabled)
{
- invalidateMatchingStaticData(attribs[attributeIndex], currentValues[attributeIndex]);
+ invalidateMatchingStaticData(curAttrib, state.getVertexAttribCurrentValue(attributeIndex));
}
}
// Reserve the required space in the buffers
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
- if (translated[i].active && attribs[i].enabled)
+ const gl::VertexAttribute &curAttrib = state.getVertexAttribState(i);
+ if (translated[i].active && curAttrib.enabled)
{
- gl::Error error = reserveSpaceForAttrib(attribs[i], currentValues[i], count, instances);
+ gl::Error error = reserveSpaceForAttrib(curAttrib, state.getVertexAttribCurrentValue(i), count, instances);
if (error.isError())
{
return error;
@@ -117,12 +120,14 @@ gl::Error VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs
// Perform the vertex data translations
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
+ const gl::VertexAttribute &curAttrib = state.getVertexAttribState(i);
if (translated[i].active)
{
- if (attribs[i].enabled)
+ if (curAttrib.enabled)
{
- gl::Error error = storeAttribute(attribs[i], currentValues[i], &translated[i],
- start, count, instances);
+ gl::Error error = storeAttribute(curAttrib, state.getVertexAttribCurrentValue(i),
+ &translated[i], start, count, instances);
+
if (error.isError())
{
return error;
@@ -135,7 +140,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs
mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mRenderer, CONSTANT_VERTEX_BUFFER_SIZE);
}
- gl::Error error = storeCurrentValue(attribs[i], currentValues[i], &translated[i],
+ gl::Error error = storeCurrentValue(curAttrib, state.getVertexAttribCurrentValue(i), &translated[i],
&mCurrentValue[i], &mCurrentValueOffsets[i],
mCurrentValueBuffer[i]);
if (error.isError())
@@ -148,14 +153,15 @@ gl::Error VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
- if (translated[i].active && attribs[i].enabled)
+ const gl::VertexAttribute &curAttrib = state.getVertexAttribState(i);
+ if (translated[i].active && curAttrib.enabled)
{
- gl::Buffer *buffer = attribs[i].buffer.get();
+ gl::Buffer *buffer = curAttrib.buffer.get();
if (buffer)
{
BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation());
- bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(attribs[i]));
+ bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(curAttrib));
}
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.h
index 7728722246..64ef653221 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/VertexDataManager.h
@@ -16,8 +16,9 @@
namespace gl
{
-struct VertexAttribute;
class ProgramBinary;
+class State;
+struct VertexAttribute;
struct VertexAttribCurrentValueData;
}
@@ -26,7 +27,7 @@ namespace rx
class BufferD3D;
class StreamingVertexBufferInterface;
class VertexBuffer;
-class Renderer;
+class RendererD3D;
struct TranslatedAttribute
{
@@ -49,11 +50,11 @@ struct TranslatedAttribute
class VertexDataManager
{
public:
- VertexDataManager(rx::Renderer *renderer);
+ VertexDataManager(RendererD3D *renderer);
virtual ~VertexDataManager();
- gl::Error prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[],
- gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *outAttribs, GLsizei instances);
+ gl::Error prepareVertexData(const gl::State &state, GLint start, GLsizei count,
+ TranslatedAttribute *outAttribs, GLsizei instances);
private:
DISALLOW_COPY_AND_ASSIGN(VertexDataManager);
@@ -80,7 +81,7 @@ class VertexDataManager
size_t *cachedOffset,
StreamingVertexBufferInterface *buffer);
- rx::Renderer *const mRenderer;
+ RendererD3D *const mRenderer;
StreamingVertexBufferInterface *mStreamingBuffer;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.cpp
index d43e65ea78..06aea9befe 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.cpp
@@ -172,7 +172,7 @@ static void Write3DVertices(const gl::Box &sourceArea, const gl::Extents &source
*outTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
}
-Blit11::Blit11(rx::Renderer11 *renderer)
+Blit11::Blit11(Renderer11 *renderer)
: mRenderer(renderer), mBlitShaderMap(compareBlitParameters), mSwizzleShaderMap(compareSwizzleParameters),
mVertexBuffer(NULL), mPointSampler(NULL), mLinearSampler(NULL), mScissorEnabledRasterizerState(NULL),
mScissorDisabledRasterizerState(NULL), mDepthStencilState(NULL),
@@ -209,7 +209,7 @@ Blit11::Blit11(rx::Renderer11 *renderer)
pointSamplerDesc.BorderColor[2] = 0.0f;
pointSamplerDesc.BorderColor[3] = 0.0f;
pointSamplerDesc.MinLOD = 0.0f;
- pointSamplerDesc.MaxLOD = mRenderer->isLevel9() ? FLT_MAX : 0.0f;
+ pointSamplerDesc.MaxLOD = mRenderer->isLevel9() ? D3D11_FLOAT32_MAX : 0.0f;
result = device->CreateSamplerState(&pointSamplerDesc, &mPointSampler);
ASSERT(SUCCEEDED(result));
@@ -228,7 +228,7 @@ Blit11::Blit11(rx::Renderer11 *renderer)
linearSamplerDesc.BorderColor[2] = 0.0f;
linearSamplerDesc.BorderColor[3] = 0.0f;
linearSamplerDesc.MinLOD = 0.0f;
- linearSamplerDesc.MaxLOD = mRenderer->isLevel9() ? FLT_MAX : 0.0f;
+ linearSamplerDesc.MaxLOD = mRenderer->isLevel9() ? D3D11_FLOAT32_MAX : 0.0f;
result = device->CreateSamplerState(&linearSamplerDesc, &mLinearSampler);
ASSERT(SUCCEEDED(result));
@@ -468,8 +468,7 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT
deviceContext->GSSetShader(shader.mGeometryShader, NULL, 0);
// Unset the currently bound shader resource to avoid conflicts
- ID3D11ShaderResourceView *const nullSRV = NULL;
- deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL);
// Apply render target
mRenderer->setOneTimeRenderTarget(dest);
@@ -485,7 +484,7 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT
deviceContext->RSSetViewports(1, &viewport);
// Apply textures
- deviceContext->PSSetShaderResources(0, 1, &source);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, source);
// Apply samplers
deviceContext->PSSetSamplers(0, 1, &mPointSampler);
@@ -494,7 +493,7 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT
deviceContext->Draw(drawCount, 0);
// Unbind textures and render targets and vertex buffer
- deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL);
mRenderer->unapplyRenderTargets();
@@ -507,9 +506,9 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT
return gl::Error(GL_NO_ERROR);
}
-bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11RenderTargetView *dest, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor, GLenum destFormat, GLenum filter)
+gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11RenderTargetView *dest, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor, GLenum destFormat, GLenum filter)
{
HRESULT result;
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
@@ -531,7 +530,7 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
if (i == mBlitShaderMap.end())
{
UNREACHABLE();
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Could not find appropriate shader for internal texture blit.");
}
const Shader& shader = i->second;
@@ -541,8 +540,7 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
result = deviceContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
- ERR("Failed to map vertex buffer for texture copy, HRESULT: 0x%X.", result);
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal vertex buffer for texture copy, HRESULT: 0x%X.", result);
}
UINT stride = 0;
@@ -587,8 +585,7 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
deviceContext->GSSetShader(shader.mGeometryShader, NULL, 0);
// Unset the currently bound shader resource to avoid conflicts
- ID3D11ShaderResourceView *const nullSRV = NULL;
- deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL);
// Apply render target
mRenderer->setOneTimeRenderTarget(dest);
@@ -604,7 +601,7 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
deviceContext->RSSetViewports(1, &viewport);
// Apply textures
- deviceContext->PSSetShaderResources(0, 1, &source);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, source);
// Apply samplers
ID3D11SamplerState *sampler = NULL;
@@ -612,7 +609,10 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
{
case GL_NEAREST: sampler = mPointSampler; break;
case GL_LINEAR: sampler = mLinearSampler; break;
- default: UNREACHABLE(); return false;
+
+ default:
+ UNREACHABLE();
+ return gl::Error(GL_OUT_OF_MEMORY, "Internal error, unknown blit filter mode.");
}
deviceContext->PSSetSamplers(0, 1, &sampler);
@@ -620,7 +620,7 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
deviceContext->Draw(drawCount, 0);
// Unbind textures and render targets and vertex buffer
- deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL);
mRenderer->unapplyRenderTargets();
@@ -630,21 +630,21 @@ bool Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &source
mRenderer->markAllStateDirty();
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-bool Blit11::copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor)
+gl::Error Blit11::copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor)
{
return copyDepthStencil(source, sourceSubresource, sourceArea, sourceSize,
dest, destSubresource, destArea, destSize,
scissor, true);
}
-bool Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor)
+gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor)
{
HRESULT result;
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
@@ -654,8 +654,7 @@ bool Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceAr
result = deviceContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
- ERR("Failed to map vertex buffer for texture copy, HRESULT: 0x%X.", result);
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal vertex buffer for texture copy, HRESULT: 0x%X.", result);
}
UINT stride = 0;
@@ -700,8 +699,7 @@ bool Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceAr
deviceContext->GSSetShader(NULL, NULL, 0);
// Unset the currently bound shader resource to avoid conflicts
- ID3D11ShaderResourceView *const nullSRV = NULL;
- deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL);
// Apply render target
deviceContext->OMSetRenderTargets(0, NULL, dest);
@@ -717,7 +715,7 @@ bool Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceAr
deviceContext->RSSetViewports(1, &viewport);
// Apply textures
- deviceContext->PSSetShaderResources(0, 1, &source);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, source);
// Apply samplers
deviceContext->PSSetSamplers(0, 1, &mPointSampler);
@@ -726,7 +724,7 @@ bool Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceAr
deviceContext->Draw(drawCount, 0);
// Unbind textures and render targets and vertex buffer
- deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL);
mRenderer->unapplyRenderTargets();
@@ -736,21 +734,21 @@ bool Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceAr
mRenderer->markAllStateDirty();
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor)
+gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor)
{
return copyDepthStencil(source, sourceSubresource, sourceArea, sourceSize,
dest, destSubresource, destArea, destSize,
scissor, false);
}
-bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor, bool stencilOnly)
+gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor, bool stencilOnly)
{
ID3D11Device *device = mRenderer->getDevice();
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
@@ -764,7 +762,7 @@ bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubreso
{
SafeRelease(sourceStaging);
SafeRelease(destStaging);
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal staging textures for depth stencil blit.");
}
DXGI_FORMAT format = GetTextureFormat(source);
@@ -785,23 +783,23 @@ bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubreso
dxgiFormatInfo.depthBits % 8 == 0);
}
- D3D11_MAPPED_SUBRESOURCE sourceMapping, destMapping;
- deviceContext->Map(sourceStaging, 0, D3D11_MAP_READ, 0, &sourceMapping);
- deviceContext->Map(destStaging, 0, D3D11_MAP_WRITE, 0, &destMapping);
+ D3D11_MAPPED_SUBRESOURCE sourceMapping;
+ HRESULT result = deviceContext->Map(sourceStaging, 0, D3D11_MAP_READ, 0, &sourceMapping);
+ if (FAILED(result))
+ {
+ SafeRelease(sourceStaging);
+ SafeRelease(destStaging);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal source staging texture for depth stencil blit, HRESULT: 0x%X.", result);
+ }
- if (!sourceMapping.pData || !destMapping.pData)
+ D3D11_MAPPED_SUBRESOURCE destMapping;
+ result = deviceContext->Map(destStaging, 0, D3D11_MAP_WRITE, 0, &destMapping);
+ if (FAILED(result))
{
- if (!sourceMapping.pData)
- {
- deviceContext->Unmap(sourceStaging, 0);
- }
- if (!destMapping.pData)
- {
- deviceContext->Unmap(destStaging, 0);
- }
+ deviceContext->Unmap(sourceStaging, 0);
SafeRelease(sourceStaging);
SafeRelease(destStaging);
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal destination staging texture for depth stencil blit, HRESULT: 0x%X.", result);
}
gl::Rectangle clippedDestArea(destArea.x, destArea.y, destArea.width, destArea.height);
@@ -880,7 +878,7 @@ bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubreso
SafeRelease(sourceStaging);
SafeRelease(destStaging);
- return true;
+ return gl::Error(GL_NO_ERROR);
}
bool Blit11::compareBlitParameters(const Blit11::BlitParameters &a, const Blit11::BlitParameters &b)
@@ -1001,12 +999,12 @@ void Blit11::buildShaderMap()
add3DBlitShaderToMap(GL_RGBA_INTEGER, true, d3d11::CompilePS(device, g_PS_PassthroughRGBA3DI, "Blit11 3D I RGBA pixel shader" ));
add3DBlitShaderToMap(GL_BGRA_EXT, false, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D BGRA pixel shader" ));
add3DBlitShaderToMap(GL_RGB, false, d3d11::CompilePS(device, g_PS_PassthroughRGB3D, "Blit11 3D RGB pixel shader" ));
- add3DBlitShaderToMap(GL_RG, false, d3d11::CompilePS(device, g_PS_PassthroughRG3D, "Blit11 3D RG pixel shader" ));
add3DBlitShaderToMap(GL_RGB_INTEGER, false, d3d11::CompilePS(device, g_PS_PassthroughRGB3DUI, "Blit11 3D RGB UI pixel shader" ));
add3DBlitShaderToMap(GL_RGB_INTEGER, true, d3d11::CompilePS(device, g_PS_PassthroughRGB3DI, "Blit11 3D RGB I pixel shader" ));
- add3DBlitShaderToMap(GL_RED, false, d3d11::CompilePS(device, g_PS_PassthroughR3D, "Blit11 3D R pixel shader" ));
+ add3DBlitShaderToMap(GL_RG, false, d3d11::CompilePS(device, g_PS_PassthroughRG3D, "Blit11 3D RG pixel shader" ));
add3DBlitShaderToMap(GL_RG_INTEGER, false, d3d11::CompilePS(device, g_PS_PassthroughRG3DUI, "Blit11 3D RG UI pixel shader" ));
add3DBlitShaderToMap(GL_RG_INTEGER, true, d3d11::CompilePS(device, g_PS_PassthroughRG3DI, "Blit11 3D RG I pixel shader" ));
+ add3DBlitShaderToMap(GL_RED, false, d3d11::CompilePS(device, g_PS_PassthroughR3D, "Blit11 3D R pixel shader" ));
add3DBlitShaderToMap(GL_RED_INTEGER, false, d3d11::CompilePS(device, g_PS_PassthroughR3DUI, "Blit11 3D R UI pixel shader" ));
add3DBlitShaderToMap(GL_RED_INTEGER, true, d3d11::CompilePS(device, g_PS_PassthroughR3DI, "Blit11 3D R I pixel shader" ));
add3DBlitShaderToMap(GL_ALPHA, false, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D alpha pixel shader" ));
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.h
index d6a0b795f4..821fa9d0cc 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Blit11.h
@@ -19,12 +19,6 @@ namespace rx
{
class Renderer11;
-enum Filter
-{
- Point,
- Linear,
-};
-
class Blit11
{
public:
@@ -34,24 +28,24 @@ class Blit11
gl::Error swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderTargetView *dest, const gl::Extents &size,
GLenum swizzleRed, GLenum swizzleGreen, GLenum swizzleBlue, GLenum swizzleAlpha);
- bool copyTexture(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11RenderTargetView *dest, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor, GLenum destFormat, GLenum filter);
-
- bool copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor);
+ gl::Error copyTexture(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11RenderTargetView *dest, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor, GLenum destFormat, GLenum filter);
- bool copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor);
-
- bool copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ gl::Error copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
const gl::Rectangle *scissor);
+ gl::Error copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor);
+
+ gl::Error copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor);
+
private:
- rx::Renderer11 *mRenderer;
+ Renderer11 *mRenderer;
struct BlitParameters
{
@@ -60,9 +54,9 @@ class Blit11
bool m3DBlit;
};
- bool copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
- ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
- const gl::Rectangle *scissor, bool stencilOnly);
+ gl::Error copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+ ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
+ const gl::Rectangle *scissor, bool stencilOnly);
static bool compareBlitParameters(const BlitParameters &a, const BlitParameters &b);
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp
index ecd4d4672b..5aab37938f 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.cpp
@@ -86,7 +86,7 @@ class Buffer11::BufferStorage11
virtual bool copyFromStorage(BufferStorage11 *source, size_t sourceOffset,
size_t size, size_t destOffset) = 0;
- virtual bool resize(size_t size, bool preserveData) = 0;
+ virtual gl::Error resize(size_t size, bool preserveData) = 0;
virtual void *map(size_t offset, size_t length, GLbitfield access) = 0;
virtual void unmap() = 0;
@@ -112,17 +112,17 @@ class Buffer11::NativeBuffer11 : public Buffer11::BufferStorage11
virtual bool copyFromStorage(BufferStorage11 *source, size_t sourceOffset,
size_t size, size_t destOffset);
- virtual bool resize(size_t size, bool preserveData);
+ virtual gl::Error resize(size_t size, bool preserveData);
virtual void *map(size_t offset, size_t length, GLbitfield access);
virtual void unmap();
- bool setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset);
+ gl::Error setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset);
private:
ID3D11Buffer *mNativeBuffer;
- static void fillBufferDesc(D3D11_BUFFER_DESC* bufferDesc, Renderer *renderer, BufferUsage usage, unsigned int bufferSize);
+ static void fillBufferDesc(D3D11_BUFFER_DESC* bufferDesc, Renderer11 *renderer, BufferUsage usage, unsigned int bufferSize);
};
// Pack storage represents internal storage for pack buffers. We implement pack buffers
@@ -135,7 +135,7 @@ class Buffer11::PackStorage11 : public Buffer11::BufferStorage11
virtual bool copyFromStorage(BufferStorage11 *source, size_t sourceOffset,
size_t size, size_t destOffset);
- virtual bool resize(size_t size, bool preserveData);
+ virtual gl::Error resize(size_t size, bool preserveData);
virtual void *map(size_t offset, size_t length, GLbitfield access);
virtual void unmap();
@@ -144,7 +144,7 @@ class Buffer11::PackStorage11 : public Buffer11::BufferStorage11
private:
- void flushQueuedPackCommand();
+ gl::Error flushQueuedPackCommand();
ID3D11Texture2D *mStagingTexture;
DXGI_FORMAT mTextureFormat;
@@ -195,14 +195,14 @@ gl::Error Buffer11::setData(const void *data, size_t size, GLenum usage)
return error;
}
-void *Buffer11::getData()
+gl::Error Buffer11::getData(const uint8_t **outData)
{
NativeBuffer11 *stagingBuffer = getStagingBuffer();
if (!stagingBuffer)
{
// Out-of-memory
- return NULL;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to get internal staging buffer.");
}
if (stagingBuffer->getDataRevision() > mResolvedDataRevision)
@@ -211,7 +211,7 @@ void *Buffer11::getData()
{
if (!mResolvedData.resize(stagingBuffer->getSize()))
{
- return gl::error(GL_OUT_OF_MEMORY, (void*)NULL);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize data resolve buffer.");
}
}
@@ -221,7 +221,7 @@ void *Buffer11::getData()
HRESULT result = context->Map(stagingBuffer->getNativeBuffer(), 0, D3D11_MAP_READ, 0, &mappedResource);
if (FAILED(result))
{
- return gl::error(GL_OUT_OF_MEMORY, (void*)NULL);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer, result: 0x%X.", result);
}
memcpy(mResolvedData.data(), mappedResource.pData, stagingBuffer->getSize());
@@ -238,13 +238,14 @@ void *Buffer11::getData()
{
if (!mResolvedData.resize(mSize))
{
- return gl::error(GL_OUT_OF_MEMORY, (void*)NULL);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize data resolve buffer.");
}
}
ASSERT(mResolvedData.size() >= mSize);
- return mResolvedData.data();
+ *outData = mResolvedData.data();
+ return gl::Error(GL_NO_ERROR);
}
gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
@@ -265,15 +266,17 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
if (stagingBuffer->getSize() < requiredSize)
{
bool preserveData = (offset > 0);
- if (!stagingBuffer->resize(requiredSize, preserveData))
+ gl::Error error = stagingBuffer->resize(requiredSize, preserveData);
+ if (error.isError())
{
- return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize internal staging buffer.");
+ return error;
}
}
- if (!stagingBuffer->setData(D3D11_MAP_WRITE, reinterpret_cast<const uint8_t *>(data), size, offset))
+ gl::Error error = stagingBuffer->setData(D3D11_MAP_WRITE, reinterpret_cast<const uint8_t *>(data), size, offset);
+ if (error.isError())
{
- return gl::Error(GL_OUT_OF_MEMORY, "Failed to set data on internal staging buffer.");
+ return error;
}
stagingBuffer->setDataRevision(stagingBuffer->getDataRevision() + 1);
@@ -411,7 +414,7 @@ void Buffer11::markBufferUsage()
}
}
-Renderer* Buffer11::getRenderer()
+RendererD3D* Buffer11::getRenderer()
{
return mRenderer;
}
@@ -527,7 +530,7 @@ Buffer11::BufferStorage11 *Buffer11::getBufferStorage(BufferUsage usage)
// resize buffer
if (directBuffer->getSize() < mSize)
{
- if (!directBuffer->resize(mSize, true))
+ if (directBuffer->resize(mSize, true).isError())
{
// Out of memory error
return NULL;
@@ -667,6 +670,9 @@ bool Buffer11::NativeBuffer11::copyFromStorage(BufferStorage11 *source, size_t s
// Offset bounds are validated at the API layer
ASSERT(sourceOffset + size <= destOffset + mBufferSize);
memcpy(destPointer, sourcePointer, size);
+
+ context->Unmap(mNativeBuffer, 0);
+ source->unmap();
}
else
{
@@ -689,7 +695,7 @@ bool Buffer11::NativeBuffer11::copyFromStorage(BufferStorage11 *source, size_t s
return createBuffer;
}
-bool Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
+gl::Error Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
{
ID3D11Device *device = mRenderer->getDevice();
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
@@ -702,7 +708,7 @@ bool Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
if (FAILED(result))
{
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer, result: 0x%X.", result);
}
if (mNativeBuffer && preserveData)
@@ -727,10 +733,10 @@ bool Buffer11::NativeBuffer11::resize(size_t size, bool preserveData)
mBufferSize = bufferDesc.ByteWidth;
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-void Buffer11::NativeBuffer11::fillBufferDesc(D3D11_BUFFER_DESC* bufferDesc, Renderer *renderer,
+void Buffer11::NativeBuffer11::fillBufferDesc(D3D11_BUFFER_DESC* bufferDesc, Renderer11 *renderer,
BufferUsage usage, unsigned int bufferSize)
{
bufferDesc->ByteWidth = bufferSize;
@@ -748,7 +754,7 @@ void Buffer11::NativeBuffer11::fillBufferDesc(D3D11_BUFFER_DESC* bufferDesc, Ren
case BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK:
bufferDesc->Usage = D3D11_USAGE_DEFAULT;
bufferDesc->BindFlags = D3D11_BIND_VERTEX_BUFFER;
- if (!static_cast<Renderer11 *>(renderer)->isLevel9())
+ if (!renderer->isLevel9())
bufferDesc->BindFlags |= D3D11_BIND_STREAM_OUTPUT;
bufferDesc->CPUAccessFlags = 0;
break;
@@ -797,7 +803,7 @@ void *Buffer11::NativeBuffer11::map(size_t offset, size_t length, GLbitfield acc
return static_cast<GLubyte*>(mappedResource.pData) + offset;
}
-bool Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset)
+gl::Error Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, size_t size, size_t offset)
{
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
@@ -805,7 +811,7 @@ bool Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, s
HRESULT result = context->Map(mNativeBuffer, 0, mapMode, 0, &mappedResource);
if (FAILED(result))
{
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer, result: 0x%X.", result);
}
uint8_t *offsetBufferPointer = reinterpret_cast<uint8_t *>(mappedResource.pData) + offset;
@@ -813,7 +819,7 @@ bool Buffer11::NativeBuffer11::setData(D3D11_MAP mapMode, const uint8_t *data, s
context->Unmap(mNativeBuffer, 0);
- return true;
+ return gl::Error(GL_NO_ERROR);
}
void Buffer11::NativeBuffer11::unmap()
@@ -847,18 +853,18 @@ bool Buffer11::PackStorage11::copyFromStorage(BufferStorage11 *source, size_t so
return false;
}
-bool Buffer11::PackStorage11::resize(size_t size, bool preserveData)
+gl::Error Buffer11::PackStorage11::resize(size_t size, bool preserveData)
{
if (size != mBufferSize)
{
if (!mMemoryBuffer.resize(size))
{
- return false;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to resize internal buffer storage.");
}
mBufferSize = size;
}
- return true;
+ return gl::Error(GL_NO_ERROR);
}
void *Buffer11::PackStorage11::map(size_t offset, size_t length, GLbitfield access)
@@ -869,7 +875,12 @@ void *Buffer11::PackStorage11::map(size_t offset, size_t length, GLbitfield acce
// and if D3D packs the staging texture memory identically to how we would fill
// the pack buffer according to the current pack state.
- flushQueuedPackCommand();
+ gl::Error error = flushQueuedPackCommand();
+ if (error.isError())
+ {
+ return NULL;
+ }
+
mDataModified = (mDataModified || (access & GL_MAP_WRITE_BIT) != 0);
return mMemoryBuffer.data() + offset;
@@ -882,7 +893,12 @@ void Buffer11::PackStorage11::unmap()
gl::Error Buffer11::PackStorage11::packPixels(ID3D11Texture2D *srcTexure, UINT srcSubresource, const PackPixelsParams &params)
{
- flushQueuedPackCommand();
+ gl::Error error = flushQueuedPackCommand();
+ if (error.isError())
+ {
+ return error;
+ }
+
mQueuedPackCommand = new PackPixelsParams(params);
D3D11_TEXTURE2D_DESC textureDesc;
@@ -947,15 +963,21 @@ gl::Error Buffer11::PackStorage11::packPixels(ID3D11Texture2D *srcTexure, UINT s
return gl::Error(GL_NO_ERROR);
}
-void Buffer11::PackStorage11::flushQueuedPackCommand()
+gl::Error Buffer11::PackStorage11::flushQueuedPackCommand()
{
ASSERT(mMemoryBuffer.size() > 0);
if (mQueuedPackCommand)
{
- mRenderer->packPixels(mStagingTexture, *mQueuedPackCommand, mMemoryBuffer.data());
+ gl::Error error = mRenderer->packPixels(mStagingTexture, *mQueuedPackCommand, mMemoryBuffer.data());
SafeDelete(mQueuedPackCommand);
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ return gl::Error(GL_NO_ERROR);
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h
index 5f24fb4e2d..1c06bbf88a 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Buffer11.h
@@ -47,7 +47,7 @@ typedef size_t DataRevision;
class Buffer11 : public BufferD3D
{
public:
- Buffer11(rx::Renderer11 *renderer);
+ Buffer11(Renderer11 *renderer);
virtual ~Buffer11();
static Buffer11 *makeBuffer11(BufferImpl *buffer);
@@ -60,11 +60,11 @@ class Buffer11 : public BufferD3D
// BufferD3D implementation
virtual size_t getSize() const { return mSize; }
virtual bool supportsDirectBinding() const;
- virtual Renderer* getRenderer();
+ RendererD3D *getRenderer() override;
// BufferImpl implementation
virtual gl::Error setData(const void* data, size_t size, GLenum usage);
- virtual void *getData();
+ gl::Error getData(const uint8_t **outData) override;
virtual gl::Error setSubData(const void* data, size_t size, size_t offset);
virtual gl::Error copySubData(BufferImpl* source, GLintptr sourceOffset, GLintptr destOffset, GLsizeiptr size);
virtual gl::Error map(size_t offset, size_t length, GLbitfield access, GLvoid **mapPtr);
@@ -78,7 +78,7 @@ class Buffer11 : public BufferD3D
class NativeBuffer11;
class PackStorage11;
- rx::Renderer11 *mRenderer;
+ Renderer11 *mRenderer;
size_t mSize;
BufferStorage11 *mMappedStorage;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.cpp
index 765d34fd3f..7185a05506 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.cpp
@@ -104,7 +104,7 @@ Clear11::Clear11(Renderer11 *renderer)
rsDesc.DepthBias = 0;
rsDesc.DepthBiasClamp = 0.0f;
rsDesc.SlopeScaledDepthBias = 0.0f;
- rsDesc.DepthClipEnable = mRenderer->isLevel9();
+ rsDesc.DepthClipEnable = renderer->isLevel9();
rsDesc.ScissorEnable = FALSE;
rsDesc.MultisampleEnable = FALSE;
rsDesc.AntialiasedLineEnable = FALSE;
@@ -119,7 +119,6 @@ Clear11::Clear11(Renderer11 *renderer)
memset(&mIntClearShader, 0, sizeof(ClearShader));
return;
}
-
mUintClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_UINT, g_VS_ClearUint, g_PS_ClearUint );
mIntClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_SINT, g_VS_ClearSint, g_PS_ClearSint );
}
@@ -154,7 +153,7 @@ Clear11::~Clear11()
SafeRelease(mRasterizerState);
}
-gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer)
+gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, const gl::Framebuffer *frameBuffer)
{
// First determine if a scissored clear is needed, this will always require drawing a quad.
//
@@ -217,10 +216,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl::
gl::FramebufferAttachment *attachment = frameBuffer->getColorbuffer(colorAttachment);
if (attachment)
{
- RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(attachment);
- if (!renderTarget)
+ RenderTarget11 *renderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(attachment, &renderTarget);
+ if (error.isError())
{
- return gl::Error(GL_OUT_OF_MEMORY, "Internal render target view pointer unexpectedly null.");
+ return error;
}
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(attachment->getInternalFormat());
@@ -290,10 +290,11 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, gl::
gl::FramebufferAttachment *attachment = frameBuffer->getDepthOrStencilbuffer();
if (attachment)
{
- RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(attachment);
- if (!renderTarget)
+ RenderTarget11 *renderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(attachment, &renderTarget);
+ if (error.isError())
{
- return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil view pointer unexpectedly null.");
+ return error;
}
const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(attachment->getActualFormat());
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.h
index be8e187c40..a7e8fea56a 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Clear11.h
@@ -32,7 +32,7 @@ class Clear11
~Clear11();
// Clears the framebuffer with the supplied clear parameters, assumes that the framebuffer is currently applied.
- gl::Error clearFramebuffer(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer);
+ gl::Error clearFramebuffer(const gl::ClearParameters &clearParams, const gl::Framebuffer *frameBuffer);
private:
Renderer11 *mRenderer;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.cpp
index a841b52862..f44d934056 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.cpp
@@ -4,67 +4,229 @@
// found in the LICENSE file.
//
-// Fence11.cpp: Defines the rx::Fence11 class which implements rx::FenceImpl.
+// Fence11.cpp: Defines the rx::FenceNV11 and rx::FenceSync11 classes which implement rx::FenceNVImpl and rx::FenceSyncImpl.
#include "libGLESv2/renderer/d3d/d3d11/Fence11.h"
#include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
#include "libGLESv2/main.h"
+#include "common/utilities.h"
+
namespace rx
{
-Fence11::Fence11(rx::Renderer11 *renderer)
+//
+// Template helpers for set and test operations.
+//
+
+template<class FenceClass>
+gl::Error FenceSetHelper(FenceClass *fence)
{
- mRenderer = renderer;
- mQuery = NULL;
+ if (!fence->mQuery)
+ {
+ D3D11_QUERY_DESC queryDesc;
+ queryDesc.Query = D3D11_QUERY_EVENT;
+ queryDesc.MiscFlags = 0;
+
+ HRESULT result = fence->mRenderer->getDevice()->CreateQuery(&queryDesc, &fence->mQuery);
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create event query, result: 0x%X.", result);
+ }
+ }
+
+ fence->mRenderer->getDeviceContext()->End(fence->mQuery);
+ return gl::Error(GL_NO_ERROR);
}
-Fence11::~Fence11()
+template <class FenceClass>
+gl::Error FenceTestHelper(FenceClass *fence, bool flushCommandBuffer, GLboolean *outFinished)
+{
+ ASSERT(fence->mQuery);
+
+ UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH);
+ HRESULT result = fence->mRenderer->getDeviceContext()->GetData(fence->mQuery, NULL, 0, getDataFlags);
+
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to get query data, result: 0x%X.", result);
+ }
+ else if (fence->mRenderer->isDeviceLost())
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Device was lost while querying result of an event query.");
+ }
+
+ ASSERT(result == S_OK || result == S_FALSE);
+ *outFinished = ((result == S_OK) ? GL_TRUE : GL_FALSE);
+ return gl::Error(GL_NO_ERROR);
+}
+
+//
+// FenceNV11
+//
+
+FenceNV11::FenceNV11(Renderer11 *renderer)
+ : FenceNVImpl(),
+ mRenderer(renderer),
+ mQuery(NULL)
+{
+}
+
+FenceNV11::~FenceNV11()
{
SafeRelease(mQuery);
}
-bool Fence11::isSet() const
+gl::Error FenceNV11::set()
{
- return mQuery != NULL;
+ return FenceSetHelper(this);
}
-void Fence11::set()
+gl::Error FenceNV11::test(bool flushCommandBuffer, GLboolean *outFinished)
{
- if (!mQuery)
- {
- D3D11_QUERY_DESC queryDesc;
- queryDesc.Query = D3D11_QUERY_EVENT;
- queryDesc.MiscFlags = 0;
+ return FenceTestHelper(this, flushCommandBuffer, outFinished);
+}
+
+gl::Error FenceNV11::finishFence(GLboolean *outFinished)
+{
+ ASSERT(outFinished);
- if (FAILED(mRenderer->getDevice()->CreateQuery(&queryDesc, &mQuery)))
+ while (*outFinished != GL_TRUE)
+ {
+ gl::Error error = test(true, outFinished);
+ if (error.isError())
{
- return gl::error(GL_OUT_OF_MEMORY);
+ return error;
}
+
+ Sleep(0);
}
- mRenderer->getDeviceContext()->End(mQuery);
+ return gl::Error(GL_NO_ERROR);
}
-bool Fence11::test(bool flushCommandBuffer)
+//
+// FenceSync11
+//
+
+// Important note on accurate timers in Windows:
+//
+// QueryPerformanceCounter has a few major issues, including being 10x as expensive to call
+// as timeGetTime on laptops and "jumping" during certain hardware events.
+//
+// See the comments at the top of the Chromium source file "chromium/src/base/time/time_win.cc"
+// https://code.google.com/p/chromium/codesearch#chromium/src/base/time/time_win.cc
+//
+// We still opt to use QPC. In the present and moving forward, most newer systems will not suffer
+// from buggy implementations.
+
+FenceSync11::FenceSync11(Renderer11 *renderer)
+ : FenceSyncImpl(),
+ mRenderer(renderer),
+ mQuery(NULL)
{
- ASSERT(mQuery);
+ LARGE_INTEGER counterFreqency = { 0 };
+ BOOL success = QueryPerformanceFrequency(&counterFreqency);
+ UNUSED_ASSERTION_VARIABLE(success);
+ ASSERT(success);
- UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH);
- HRESULT result = mRenderer->getDeviceContext()->GetData(mQuery, NULL, 0, getDataFlags);
+ mCounterFrequency = counterFreqency.QuadPart;
+}
- if (mRenderer->isDeviceLost())
+FenceSync11::~FenceSync11()
+{
+ SafeRelease(mQuery);
+}
+
+gl::Error FenceSync11::set()
+{
+ return FenceSetHelper(this);
+}
+
+gl::Error FenceSync11::clientWait(GLbitfield flags, GLuint64 timeout, GLenum *outResult)
+{
+ ASSERT(outResult);
+
+ bool flushCommandBuffer = ((flags & GL_SYNC_FLUSH_COMMANDS_BIT) != 0);
+
+ GLboolean result = GL_FALSE;
+ gl::Error error = FenceTestHelper(this, flushCommandBuffer, &result);
+ if (error.isError())
{
- return gl::error(GL_OUT_OF_MEMORY, true);
+ *outResult = GL_WAIT_FAILED;
+ return error;
}
- ASSERT(result == S_OK || result == S_FALSE);
- return (result == S_OK);
+ if (result == GL_TRUE)
+ {
+ *outResult = GL_ALREADY_SIGNALED;
+ return gl::Error(GL_NO_ERROR);
+ }
+
+ if (timeout == 0)
+ {
+ *outResult = GL_TIMEOUT_EXPIRED;
+ return gl::Error(GL_NO_ERROR);
+ }
+
+ LARGE_INTEGER currentCounter = { 0 };
+ BOOL success = QueryPerformanceCounter(&currentCounter);
+ UNUSED_ASSERTION_VARIABLE(success);
+ ASSERT(success);
+
+ LONGLONG timeoutInSeconds = static_cast<LONGLONG>(timeout) * static_cast<LONGLONG>(1000000ll);
+ LONGLONG endCounter = currentCounter.QuadPart + mCounterFrequency * timeoutInSeconds;
+
+ while (currentCounter.QuadPart < endCounter && !result)
+ {
+ Sleep(0);
+ BOOL success = QueryPerformanceCounter(&currentCounter);
+ UNUSED_ASSERTION_VARIABLE(success);
+ ASSERT(success);
+
+ error = FenceTestHelper(this, flushCommandBuffer, &result);
+ if (error.isError())
+ {
+ *outResult = GL_WAIT_FAILED;
+ return error;
+ }
+ }
+
+ if (currentCounter.QuadPart >= endCounter)
+ {
+ *outResult = GL_TIMEOUT_EXPIRED;
+ }
+ else
+ {
+ *outResult = GL_CONDITION_SATISFIED;
+ }
+
+ return gl::Error(GL_NO_ERROR);
}
-bool Fence11::hasError() const
+gl::Error FenceSync11::serverWait(GLbitfield flags, GLuint64 timeout)
{
- return mRenderer->isDeviceLost();
+ // Because our API is currently designed to be called from a single thread, we don't need to do
+ // extra work for a server-side fence. GPU commands issued after the fence is created will always
+ // be processed after the fence is signaled.
+ return gl::Error(GL_NO_ERROR);
}
+gl::Error FenceSync11::getStatus(GLint *outResult)
+{
+ GLboolean result = GL_FALSE;
+ gl::Error error = FenceTestHelper(this, false, &result);
+ if (error.isError())
+ {
+ // The spec does not specify any way to report errors during the status test (e.g. device lost)
+ // so we report the fence is unblocked in case of error or signaled.
+ *outResult = GL_SIGNALED;
+
+ return error;
+ }
+
+ *outResult = (result ? GL_SIGNALED : GL_UNSIGNALED);
+ return gl::Error(GL_NO_ERROR);
}
+
+} // namespace rx
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.h
index 50c7621776..1223a53b90 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Fence11.h
@@ -4,10 +4,10 @@
// found in the LICENSE file.
//
-// Fence11.h: Defines the rx::Fence11 class which implements rx::FenceImpl.
+// Fence11.h: Defines the rx::FenceNV11 and rx::FenceSync11 classes which implement rx::FenceNVImpl and rx::FenceSyncImpl.
-#ifndef LIBGLESV2_RENDERER_Fence11_H_
-#define LIBGLESV2_RENDERER_Fence11_H_
+#ifndef LIBGLESV2_RENDERER_FENCE11_H_
+#define LIBGLESV2_RENDERER_FENCE11_H_
#include "libGLESv2/renderer/FenceImpl.h"
@@ -15,22 +15,46 @@ namespace rx
{
class Renderer11;
-class Fence11 : public FenceImpl
+class FenceNV11 : public FenceNVImpl
{
public:
- explicit Fence11(rx::Renderer11 *renderer);
- virtual ~Fence11();
+ explicit FenceNV11(Renderer11 *renderer);
+ virtual ~FenceNV11();
- bool isSet() const;
- void set();
- bool test(bool flushCommandBuffer);
- bool hasError() const;
+ gl::Error set();
+ gl::Error test(bool flushCommandBuffer, GLboolean *outFinished);
+ gl::Error finishFence(GLboolean *outFinished);
private:
- DISALLOW_COPY_AND_ASSIGN(Fence11);
+ DISALLOW_COPY_AND_ASSIGN(FenceNV11);
- rx::Renderer11 *mRenderer;
+ template<class T> friend gl::Error FenceSetHelper(T *fence);
+ template<class T> friend gl::Error FenceTestHelper(T *fence, bool flushCommandBuffer, GLboolean *outFinished);
+
+ Renderer11 *mRenderer;
+ ID3D11Query *mQuery;
+};
+
+class FenceSync11 : public FenceSyncImpl
+{
+ public:
+ explicit FenceSync11(Renderer11 *renderer);
+ virtual ~FenceSync11();
+
+ gl::Error set();
+ gl::Error clientWait(GLbitfield flags, GLuint64 timeout, GLenum *outResult);
+ gl::Error serverWait(GLbitfield flags, GLuint64 timeout);
+ gl::Error getStatus(GLint *outResult);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FenceSync11);
+
+ template<class T> friend gl::Error FenceSetHelper(T *fence);
+ template<class T> friend gl::Error FenceTestHelper(T *fence, bool flushCommandBuffer, GLboolean *outFinished);
+
+ Renderer11 *mRenderer;
ID3D11Query *mQuery;
+ LONGLONG mCounterFrequency;
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp
index 7536713af4..e6f3e90683 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp
@@ -9,6 +9,7 @@
#include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
#include "libGLESv2/renderer/d3d/d3d11/Image11.h"
+#include "libGLESv2/renderer/d3d/d3d11/RenderTarget11.h"
#include "libGLESv2/renderer/d3d/d3d11/TextureStorage11.h"
#include "libGLESv2/renderer/d3d/d3d11/formatutils11.h"
#include "libGLESv2/renderer/d3d/d3d11/renderer11_utils.h"
@@ -22,15 +23,16 @@ namespace rx
{
Image11::Image11()
+ : mRenderer(NULL),
+ mDXGIFormat(DXGI_FORMAT_UNKNOWN),
+ mStagingTexture(NULL),
+ mStagingSubresource(0),
+ mRecoverFromStorage(false),
+ mAssociatedStorage(NULL),
+ mAssociatedImageIndex(gl::ImageIndex::MakeInvalid()),
+ mRecoveredFromStorageCount(0)
+
{
- mStagingTexture = NULL;
- mRenderer = NULL;
- mDXGIFormat = DXGI_FORMAT_UNKNOWN;
- mRecoverFromStorage = false;
- mAssociatedStorage = NULL;
- mAssociatedStorageLevel = 0;
- mAssociatedStorageLayerTarget = 0;
- mRecoveredFromStorageCount = 0;
}
Image11::~Image11()
@@ -41,11 +43,11 @@ Image11::~Image11()
Image11 *Image11::makeImage11(Image *img)
{
- ASSERT(HAS_DYNAMIC_TYPE(rx::Image11*, img));
- return static_cast<rx::Image11*>(img);
+ ASSERT(HAS_DYNAMIC_TYPE(Image11*, img));
+ return static_cast<Image11*>(img);
}
-void Image11::generateMipmap(Image11 *dest, Image11 *src)
+gl::Error Image11::generateMipmap(Image11 *dest, Image11 *src)
{
ASSERT(src->getDXGIFormat() == dest->getDXGIFormat());
ASSERT(src->getWidth() == 1 || src->getWidth() / 2 == dest->getWidth());
@@ -55,21 +57,18 @@ void Image11::generateMipmap(Image11 *dest, Image11 *src)
ASSERT(dxgiFormatInfo.mipGenerationFunction != NULL);
D3D11_MAPPED_SUBRESOURCE destMapped;
- HRESULT destMapResult = dest->map(D3D11_MAP_WRITE, &destMapped);
- if (FAILED(destMapResult))
+ gl::Error error = dest->map(D3D11_MAP_WRITE, &destMapped);
+ if (error.isError())
{
- ERR("Failed to map destination image for mip map generation. HRESULT:0x%X", destMapResult);
- return;
+ return error;
}
D3D11_MAPPED_SUBRESOURCE srcMapped;
- HRESULT srcMapResult = src->map(D3D11_MAP_READ, &srcMapped);
- if (FAILED(srcMapResult))
+ error = src->map(D3D11_MAP_READ, &srcMapped);
+ if (error.isError())
{
- ERR("Failed to map source image for mip map generation. HRESULT:0x%X", srcMapResult);
-
dest->unmap();
- return;
+ return error;
}
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(srcMapped.pData);
@@ -83,6 +82,8 @@ void Image11::generateMipmap(Image11 *dest, Image11 *src)
src->unmap();
dest->markDirty();
+
+ return gl::Error(GL_NO_ERROR);
}
bool Image11::isDirty() const
@@ -99,32 +100,10 @@ bool Image11::isDirty() const
return mDirty;
}
-bool Image11::copyToStorage2D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
+gl::Error Image11::copyToStorage(TextureStorage *storage, const gl::ImageIndex &index, const gl::Box &region)
{
- TextureStorage11_2D *storage11 = TextureStorage11_2D::makeTextureStorage11_2D(storage);
- return copyToStorageImpl(storage11, level, 0, xoffset, yoffset, width, height);
-}
+ TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(storage);
-bool Image11::copyToStorageCube(TextureStorage *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
-{
- TextureStorage11_Cube *storage11 = TextureStorage11_Cube::makeTextureStorage11_Cube(storage);
- return copyToStorageImpl(storage11, level, face, xoffset, yoffset, width, height);
-}
-
-bool Image11::copyToStorage3D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth)
-{
- TextureStorage11_3D *storage11 = TextureStorage11_3D::makeTextureStorage11_3D(storage);
- return copyToStorageImpl(storage11, level, 0, xoffset, yoffset, width, height);
-}
-
-bool Image11::copyToStorage2DArray(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint arrayLayer, GLsizei width, GLsizei height)
-{
- TextureStorage11_2DArray *storage11 = TextureStorage11_2DArray::makeTextureStorage11_2DArray(storage);
- return copyToStorageImpl(storage11, level, arrayLayer, xoffset, yoffset, width, height);
-}
-
-bool Image11::copyToStorageImpl(TextureStorage11 *storage11, int level, int layerTarget, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height)
-{
// If an app's behavior results in an Image11 copying its data to/from to a TextureStorage multiple times,
// then we should just keep the staging texture around to prevent the copying from impacting perf.
// We allow the Image11 to copy its data to/from TextureStorage once.
@@ -134,23 +113,38 @@ bool Image11::copyToStorageImpl(TextureStorage11 *storage11, int level, int laye
if (attemptToReleaseStagingTexture)
{
// If another image is relying on this Storage for its data, then we must let it recover its data before we overwrite it.
- storage11->releaseAssociatedImage(level, layerTarget, this);
+ gl::Error error = storage11->releaseAssociatedImage(index, this);
+ if (error.isError())
+ {
+ return error;
+ }
+ }
+
+ ID3D11Resource *stagingTexture = NULL;
+ unsigned int stagingSubresourceIndex = 0;
+ gl::Error error = getStagingTexture(&stagingTexture, &stagingSubresourceIndex);
+ if (error.isError())
+ {
+ return error;
}
- bool updateSubresourceSuccess = storage11->updateSubresourceLevel(getStagingTexture(), getStagingSubresource(), level, layerTarget, xoffset, yoffset, 0, width, height, 1);
+ error = storage11->updateSubresourceLevel(stagingTexture, stagingSubresourceIndex, index, region);
+ if (error.isError())
+ {
+ return error;
+ }
// Once the image data has been copied into the Storage, we can release it locally.
- if (attemptToReleaseStagingTexture && updateSubresourceSuccess)
+ if (attemptToReleaseStagingTexture)
{
- storage11->associateImage(this, level, layerTarget);
+ storage11->associateImage(this, index);
releaseStagingTexture();
mRecoverFromStorage = true;
mAssociatedStorage = storage11;
- mAssociatedStorageLevel = level;
- mAssociatedStorageLayerTarget = layerTarget;
+ mAssociatedImageIndex = index;
}
- return updateSubresourceSuccess;
+ return gl::Error(GL_NO_ERROR);
}
bool Image11::isAssociatedStorageValid(TextureStorage11* textureStorage) const
@@ -158,13 +152,17 @@ bool Image11::isAssociatedStorageValid(TextureStorage11* textureStorage) const
return (mAssociatedStorage == textureStorage);
}
-bool Image11::recoverFromAssociatedStorage()
+gl::Error Image11::recoverFromAssociatedStorage()
{
if (mRecoverFromStorage)
{
- createStagingTexture();
+ gl::Error error = createStagingTexture();
+ if (error.isError())
+ {
+ return error;
+ }
- bool textureStorageCorrect = mAssociatedStorage->isAssociatedImageValid(mAssociatedStorageLevel, mAssociatedStorageLayerTarget, this);
+ bool textureStorageCorrect = mAssociatedStorage->isAssociatedImageValid(mAssociatedImageIndex, this);
// This means that the cached TextureStorage has been modified after this Image11 released its copy of its data.
// This should not have happened. The TextureStorage should have told this Image11 to recover its data before it was overwritten.
@@ -173,17 +171,21 @@ bool Image11::recoverFromAssociatedStorage()
if (textureStorageCorrect)
{
// CopySubResource from the Storage to the Staging texture
- mAssociatedStorage->copySubresourceLevel(mStagingTexture, mStagingSubresource, mAssociatedStorageLevel, mAssociatedStorageLayerTarget, 0, 0, 0, mWidth, mHeight, mDepth);
+ gl::Box region(0, 0, 0, mWidth, mHeight, mDepth);
+ error = mAssociatedStorage->copySubresourceLevel(mStagingTexture, mStagingSubresource, mAssociatedImageIndex, region);
+ if (error.isError())
+ {
+ return error;
+ }
+
mRecoveredFromStorageCount += 1;
}
// Reset all the recovery parameters, even if the texture storage association is broken.
disassociateStorage();
-
- return textureStorageCorrect;
}
- return false;
+ return gl::Error(GL_NO_ERROR);
}
void Image11::disassociateStorage()
@@ -191,16 +193,15 @@ void Image11::disassociateStorage()
if (mRecoverFromStorage)
{
// Make the texturestorage release the Image11 too
- mAssociatedStorage->disassociateImage(mAssociatedStorageLevel, mAssociatedStorageLayerTarget, this);
+ mAssociatedStorage->disassociateImage(mAssociatedImageIndex, this);
mRecoverFromStorage = false;
mAssociatedStorage = NULL;
- mAssociatedStorageLevel = 0;
- mAssociatedStorageLayerTarget = 0;
+ mAssociatedImageIndex = gl::ImageIndex::MakeInvalid();
}
}
-bool Image11::redefine(Renderer *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease)
+bool Image11::redefine(RendererD3D *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease)
{
if (mWidth != width ||
mHeight != height ||
@@ -227,7 +228,7 @@ bool Image11::redefine(Renderer *renderer, GLenum target, GLenum internalformat,
mActualFormat = dxgiFormatInfo.internalFormat;
mRenderable = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN);
- SafeRelease(mStagingTexture);
+ releaseStagingTexture();
mDirty = (formatInfo.dataInitializerFunction != NULL);
return true;
@@ -247,8 +248,8 @@ DXGI_FORMAT Image11::getDXGIFormat() const
// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input
// into the target pixel rectangle.
-void Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- GLint unpackAlignment, GLenum type, const void *input)
+gl::Error Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ GLint unpackAlignment, GLenum type, const void *input)
{
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat);
GLsizei inputRowPitch = formatInfo.computeRowPitch(type, width, unpackAlignment);
@@ -261,11 +262,10 @@ void Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei widt
LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(type);
D3D11_MAPPED_SUBRESOURCE mappedImage;
- HRESULT result = map(D3D11_MAP_WRITE, &mappedImage);
- if (FAILED(result))
+ gl::Error error = map(D3D11_MAP_WRITE, &mappedImage);
+ if (error.isError())
{
- ERR("Could not map image for loading.");
- return;
+ return error;
}
uint8_t* offsetMappedData = (reinterpret_cast<uint8_t*>(mappedImage.pData) + (yoffset * mappedImage.RowPitch + xoffset * outputPixelSize + zoffset * mappedImage.DepthPitch));
@@ -274,10 +274,12 @@ void Image11::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei widt
offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch);
unmap();
+
+ return gl::Error(GL_NO_ERROR);
}
-void Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- const void *input)
+gl::Error Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ const void *input)
{
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat);
GLsizei inputRowPitch = formatInfo.computeRowPitch(GL_UNSIGNED_BYTE, width, 1);
@@ -295,11 +297,10 @@ void Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GL
LoadImageFunction loadFunction = d3dFormatInfo.loadFunctions.at(GL_UNSIGNED_BYTE);
D3D11_MAPPED_SUBRESOURCE mappedImage;
- HRESULT result = map(D3D11_MAP_WRITE, &mappedImage);
- if (FAILED(result))
+ gl::Error error = map(D3D11_MAP_WRITE, &mappedImage);
+ if (error.isError())
{
- ERR("Could not map image for loading.");
- return;
+ return error;
}
uint8_t* offsetMappedData = reinterpret_cast<uint8_t*>(mappedImage.pData) + ((yoffset / outputBlockHeight) * mappedImage.RowPitch +
@@ -311,81 +312,130 @@ void Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GL
offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch);
unmap();
+
+ return gl::Error(GL_NO_ERROR);
}
-void Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
+gl::Error Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea, RenderTarget *source)
{
- gl::FramebufferAttachment *colorbuffer = source->getReadColorbuffer();
+ RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(source);
+ ASSERT(sourceRenderTarget->getTexture());
- if (colorbuffer && colorbuffer->getActualFormat() == mActualFormat)
+ UINT subresourceIndex = sourceRenderTarget->getSubresourceIndex();
+ ID3D11Texture2D *sourceTexture2D = d3d11::DynamicCastComObject<ID3D11Texture2D>(sourceRenderTarget->getTexture());
+
+ if (!sourceTexture2D)
{
- // No conversion needed-- use copyback fastpath
- ID3D11Texture2D *colorBufferTexture = NULL;
- unsigned int subresourceIndex = 0;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the ID3D11Texture2D from the source RenderTarget.");
+ }
+
+ gl::Error error = copy(xoffset, yoffset, zoffset, sourceArea, sourceTexture2D, subresourceIndex);
+
+ SafeRelease(sourceTexture2D);
+
+ return error;
+}
+
+gl::Error Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea, const gl::ImageIndex &sourceIndex, TextureStorage *source)
+{
+ TextureStorage11 *sourceStorage11 = TextureStorage11::makeTextureStorage11(source);
+
+ UINT subresourceIndex = sourceStorage11->getSubresourceIndex(sourceIndex);
+ ID3D11Resource *resource = NULL;
+ gl::Error error = sourceStorage11->getResource(&resource);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ ID3D11Texture2D *sourceTexture2D = d3d11::DynamicCastComObject<ID3D11Texture2D>(resource);
+
+ if (!sourceTexture2D)
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the ID3D11Texture2D from the source TextureStorage.");
+ }
+
+ error = copy(xoffset, yoffset, zoffset, sourceArea, sourceTexture2D, subresourceIndex);
+
+ SafeRelease(sourceTexture2D);
+
+ return error;
+}
+
+gl::Error Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea, ID3D11Texture2D *source, UINT sourceSubResource)
+{
+ D3D11_TEXTURE2D_DESC textureDesc;
+ source->GetDesc(&textureDesc);
- if (mRenderer->getRenderTargetResource(colorbuffer, &subresourceIndex, &colorBufferTexture))
+ if (textureDesc.Format == mDXGIFormat)
+ {
+ // No conversion needed-- use copyback fastpath
+ ID3D11Resource *stagingTexture = NULL;
+ unsigned int stagingSubresourceIndex = 0;
+ gl::Error error = getStagingTexture(&stagingTexture, &stagingSubresourceIndex);
+ if (error.isError())
{
- D3D11_TEXTURE2D_DESC textureDesc;
- colorBufferTexture->GetDesc(&textureDesc);
+ return error;
+ }
- ID3D11Device *device = mRenderer->getDevice();
- ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
+ ID3D11Device *device = mRenderer->getDevice();
+ ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
- ID3D11Texture2D* srcTex = NULL;
- if (textureDesc.SampleDesc.Count > 1)
- {
- D3D11_TEXTURE2D_DESC resolveDesc;
- resolveDesc.Width = textureDesc.Width;
- resolveDesc.Height = textureDesc.Height;
- resolveDesc.MipLevels = 1;
- resolveDesc.ArraySize = 1;
- resolveDesc.Format = textureDesc.Format;
- resolveDesc.SampleDesc.Count = 1;
- resolveDesc.SampleDesc.Quality = 0;
- resolveDesc.Usage = D3D11_USAGE_DEFAULT;
- resolveDesc.BindFlags = 0;
- resolveDesc.CPUAccessFlags = 0;
- resolveDesc.MiscFlags = 0;
-
- HRESULT result = device->CreateTexture2D(&resolveDesc, NULL, &srcTex);
- if (FAILED(result))
- {
- ERR("Failed to create resolve texture for Image11::copy, HRESULT: 0x%X.", result);
- return;
- }
-
- deviceContext->ResolveSubresource(srcTex, 0, colorBufferTexture, subresourceIndex, textureDesc.Format);
- subresourceIndex = 0;
- }
- else
+ UINT subresourceAfterResolve = sourceSubResource;
+
+ ID3D11Texture2D* srcTex = NULL;
+ if (textureDesc.SampleDesc.Count > 1)
+ {
+ D3D11_TEXTURE2D_DESC resolveDesc;
+ resolveDesc.Width = textureDesc.Width;
+ resolveDesc.Height = textureDesc.Height;
+ resolveDesc.MipLevels = 1;
+ resolveDesc.ArraySize = 1;
+ resolveDesc.Format = textureDesc.Format;
+ resolveDesc.SampleDesc.Count = 1;
+ resolveDesc.SampleDesc.Quality = 0;
+ resolveDesc.Usage = D3D11_USAGE_DEFAULT;
+ resolveDesc.BindFlags = 0;
+ resolveDesc.CPUAccessFlags = 0;
+ resolveDesc.MiscFlags = 0;
+
+ HRESULT result = device->CreateTexture2D(&resolveDesc, NULL, &srcTex);
+ if (FAILED(result))
{
- srcTex = colorBufferTexture;
- srcTex->AddRef();
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create resolve texture for Image11::copy, HRESULT: 0x%X.", result);
}
- D3D11_BOX srcBox;
- srcBox.left = x;
- srcBox.right = x + width;
- srcBox.top = y;
- srcBox.bottom = y + height;
- srcBox.front = 0;
- srcBox.back = 1;
+ deviceContext->ResolveSubresource(srcTex, 0, source, sourceSubResource, textureDesc.Format);
+ subresourceAfterResolve = 0;
+ }
+ else
+ {
+ srcTex = source;
+ }
- deviceContext->CopySubresourceRegion(mStagingTexture, 0, xoffset, yoffset, zoffset, srcTex, subresourceIndex, &srcBox);
+ D3D11_BOX srcBox;
+ srcBox.left = sourceArea.x;
+ srcBox.right = sourceArea.x + sourceArea.width;
+ srcBox.top = sourceArea.y;
+ srcBox.bottom = sourceArea.y + sourceArea.height;
+ srcBox.front = 0;
+ srcBox.back = 1;
+ deviceContext->CopySubresourceRegion(stagingTexture, stagingSubresourceIndex, xoffset, yoffset, zoffset, srcTex, subresourceAfterResolve, &srcBox);
+
+ if (textureDesc.SampleDesc.Count > 1)
+ {
SafeRelease(srcTex);
- SafeRelease(colorBufferTexture);
}
}
else
{
// This format requires conversion, so we must copy the texture to staging and manually convert via readPixels
D3D11_MAPPED_SUBRESOURCE mappedImage;
- HRESULT result = map(D3D11_MAP_WRITE, &mappedImage);
- if (FAILED(result))
+ gl::Error error = map(D3D11_MAP_WRITE, &mappedImage);
+ if (error.isError())
{
- ERR("Failed to map texture for Image11::copy, HRESULT: 0x%X.", result);
- return;
+ return error;
}
// determine the offset coordinate into the destination buffer
@@ -394,17 +444,32 @@ void Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat);
- mRenderer->readPixels(source, x, y, width, height, formatInfo.format, formatInfo.type, mappedImage.RowPitch, gl::PixelPackState(), dataOffset);
+ error = mRenderer->readTextureData(source, sourceSubResource, sourceArea, formatInfo.format, formatInfo.type, mappedImage.RowPitch, gl::PixelPackState(), dataOffset);
unmap();
+
+ if (error.isError())
+ {
+ return error;
+ }
}
+
+ mDirty = true;
+
+ return gl::Error(GL_NO_ERROR);
}
-ID3D11Resource *Image11::getStagingTexture()
+gl::Error Image11::getStagingTexture(ID3D11Resource **outStagingTexture, unsigned int *outSubresourceIndex)
{
- createStagingTexture();
+ gl::Error error = createStagingTexture();
+ if (error.isError())
+ {
+ return error;
+ }
- return mStagingTexture;
+ *outStagingTexture = mStagingTexture;
+ *outSubresourceIndex = mStagingSubresource;
+ return gl::Error(GL_NO_ERROR);
}
void Image11::releaseStagingTexture()
@@ -412,149 +477,149 @@ void Image11::releaseStagingTexture()
SafeRelease(mStagingTexture);
}
-unsigned int Image11::getStagingSubresource()
-{
- createStagingTexture();
-
- return mStagingSubresource;
-}
-
-void Image11::createStagingTexture()
+gl::Error Image11::createStagingTexture()
{
if (mStagingTexture)
{
- return;
+ return gl::Error(GL_NO_ERROR);
}
+ ASSERT(mWidth > 0 && mHeight > 0 && mDepth > 0);
+
const DXGI_FORMAT dxgiFormat = getDXGIFormat();
- if (mWidth > 0 && mHeight > 0 && mDepth > 0)
- {
- ID3D11Device *device = mRenderer->getDevice();
- HRESULT result;
+ ID3D11Device *device = mRenderer->getDevice();
+ HRESULT result;
- int lodOffset = 1;
- GLsizei width = mWidth;
- GLsizei height = mHeight;
+ int lodOffset = 1;
+ GLsizei width = mWidth;
+ GLsizei height = mHeight;
- // adjust size if needed for compressed textures
- d3d11::MakeValidSize(false, dxgiFormat, &width, &height, &lodOffset);
+ // adjust size if needed for compressed textures
+ d3d11::MakeValidSize(false, dxgiFormat, &width, &height, &lodOffset);
- if (mTarget == GL_TEXTURE_3D)
+ if (mTarget == GL_TEXTURE_3D)
+ {
+ ID3D11Texture3D *newTexture = NULL;
+
+ D3D11_TEXTURE3D_DESC desc;
+ desc.Width = width;
+ desc.Height = height;
+ desc.Depth = mDepth;
+ desc.MipLevels = lodOffset + 1;
+ desc.Format = dxgiFormat;
+ desc.Usage = D3D11_USAGE_STAGING;
+ desc.BindFlags = 0;
+ desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
+ desc.MiscFlags = 0;
+
+ if (d3d11::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL)
{
- ID3D11Texture3D *newTexture = NULL;
-
- D3D11_TEXTURE3D_DESC desc;
- desc.Width = width;
- desc.Height = height;
- desc.Depth = mDepth;
- desc.MipLevels = lodOffset + 1;
- desc.Format = dxgiFormat;
- desc.Usage = D3D11_USAGE_STAGING;
- desc.BindFlags = 0;
- desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
- desc.MiscFlags = 0;
-
- if (d3d11::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL)
- {
- std::vector<D3D11_SUBRESOURCE_DATA> initialData;
- std::vector< std::vector<BYTE> > textureData;
- d3d11::GenerateInitialTextureData(mInternalFormat, width, height, mDepth,
- lodOffset + 1, &initialData, &textureData);
+ std::vector<D3D11_SUBRESOURCE_DATA> initialData;
+ std::vector< std::vector<BYTE> > textureData;
+ d3d11::GenerateInitialTextureData(mInternalFormat, width, height, mDepth,
+ lodOffset + 1, &initialData, &textureData);
- result = device->CreateTexture3D(&desc, initialData.data(), &newTexture);
- }
- else
- {
- result = device->CreateTexture3D(&desc, NULL, &newTexture);
- }
-
- if (FAILED(result))
- {
- ASSERT(result == E_OUTOFMEMORY);
- ERR("Creating image failed.");
- return gl::error(GL_OUT_OF_MEMORY);
- }
-
- mStagingTexture = newTexture;
- mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1);
+ result = device->CreateTexture3D(&desc, initialData.data(), &newTexture);
}
- else if (mTarget == GL_TEXTURE_2D || mTarget == GL_TEXTURE_2D_ARRAY || mTarget == GL_TEXTURE_CUBE_MAP)
+ else
{
- ID3D11Texture2D *newTexture = NULL;
-
- D3D11_TEXTURE2D_DESC desc;
- desc.Width = width;
- desc.Height = height;
- desc.MipLevels = lodOffset + 1;
- desc.ArraySize = 1;
- desc.Format = dxgiFormat;
- desc.SampleDesc.Count = 1;
- desc.SampleDesc.Quality = 0;
- desc.Usage = D3D11_USAGE_STAGING;
- desc.BindFlags = 0;
- desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
- desc.MiscFlags = 0;
-
- if (d3d11::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL)
- {
- std::vector<D3D11_SUBRESOURCE_DATA> initialData;
- std::vector< std::vector<BYTE> > textureData;
- d3d11::GenerateInitialTextureData(mInternalFormat, width, height, 1,
- lodOffset + 1, &initialData, &textureData);
+ result = device->CreateTexture3D(&desc, NULL, &newTexture);
+ }
- result = device->CreateTexture2D(&desc, initialData.data(), &newTexture);
- }
- else
- {
- result = device->CreateTexture2D(&desc, NULL, &newTexture);
- }
+ if (FAILED(result))
+ {
+ ASSERT(result == E_OUTOFMEMORY);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create staging texture, result: 0x%X.", result);
+ }
- if (FAILED(result))
- {
- ASSERT(result == E_OUTOFMEMORY);
- ERR("Creating image failed.");
- return gl::error(GL_OUT_OF_MEMORY);
- }
+ mStagingTexture = newTexture;
+ mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1);
+ }
+ else if (mTarget == GL_TEXTURE_2D || mTarget == GL_TEXTURE_2D_ARRAY || mTarget == GL_TEXTURE_CUBE_MAP)
+ {
+ ID3D11Texture2D *newTexture = NULL;
+
+ D3D11_TEXTURE2D_DESC desc;
+ desc.Width = width;
+ desc.Height = height;
+ desc.MipLevels = lodOffset + 1;
+ desc.ArraySize = 1;
+ desc.Format = dxgiFormat;
+ desc.SampleDesc.Count = 1;
+ desc.SampleDesc.Quality = 0;
+ desc.Usage = D3D11_USAGE_STAGING;
+ desc.BindFlags = 0;
+ desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
+ desc.MiscFlags = 0;
+
+ if (d3d11::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL)
+ {
+ std::vector<D3D11_SUBRESOURCE_DATA> initialData;
+ std::vector< std::vector<BYTE> > textureData;
+ d3d11::GenerateInitialTextureData(mInternalFormat, width, height, 1,
+ lodOffset + 1, &initialData, &textureData);
- mStagingTexture = newTexture;
- mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1);
+ result = device->CreateTexture2D(&desc, initialData.data(), &newTexture);
}
else
{
- UNREACHABLE();
+ result = device->CreateTexture2D(&desc, NULL, &newTexture);
}
+
+ if (FAILED(result))
+ {
+ ASSERT(result == E_OUTOFMEMORY);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create staging texture, result: 0x%X.", result);
+ }
+
+ mStagingTexture = newTexture;
+ mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1);
+ }
+ else
+ {
+ UNREACHABLE();
}
mDirty = false;
+ return gl::Error(GL_NO_ERROR);
}
-HRESULT Image11::map(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map)
+gl::Error Image11::map(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map)
{
- createStagingTexture();
-
// We must recover from the TextureStorage if necessary, even for D3D11_MAP_WRITE.
- recoverFromAssociatedStorage();
-
- HRESULT result = E_FAIL;
+ gl::Error error = recoverFromAssociatedStorage();
+ if (error.isError())
+ {
+ return error;
+ }
- if (mStagingTexture)
+ ID3D11Resource *stagingTexture = NULL;
+ unsigned int subresourceIndex = 0;
+ error = getStagingTexture(&stagingTexture, &subresourceIndex);
+ if (error.isError())
{
- ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
- result = deviceContext->Map(mStagingTexture, mStagingSubresource, mapType, 0, map);
+ return error;
+ }
- // this can fail if the device is removed (from TDR)
- if (d3d11::isDeviceLostError(result))
- {
- mRenderer->notifyDeviceLost();
- }
- else if (SUCCEEDED(result))
- {
- mDirty = true;
- }
+ ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
+
+ ASSERT(mStagingTexture);
+ HRESULT result = deviceContext->Map(stagingTexture, subresourceIndex, mapType, 0, map);
+
+ // this can fail if the device is removed (from TDR)
+ if (d3d11::isDeviceLostError(result))
+ {
+ mRenderer->notifyDeviceLost();
+ }
+ else if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map staging texture, result: 0x%X.", result);
}
- return result;
+ mDirty = true;
+
+ return gl::Error(GL_NO_ERROR);
}
void Image11::unmap()
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.h
index a76a61f036..a936e6d7b2 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Image11.h
@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_IMAGE11_H_
#include "libGLESv2/renderer/d3d/ImageD3D.h"
+#include "libGLESv2/ImageIndex.h"
#include "common/debug.h"
@@ -21,7 +22,6 @@ class Framebuffer;
namespace rx
{
-class Renderer;
class Renderer11;
class TextureStorage11;
@@ -33,42 +33,41 @@ class Image11 : public ImageD3D
static Image11 *makeImage11(Image *img);
- static void generateMipmap(Image11 *dest, Image11 *src);
+ static gl::Error generateMipmap(Image11 *dest, Image11 *src);
virtual bool isDirty() const;
- virtual bool copyToStorage2D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
- virtual bool copyToStorageCube(TextureStorage *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
- virtual bool copyToStorage3D(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
- virtual bool copyToStorage2DArray(TextureStorage *storage, int level, GLint xoffset, GLint yoffset, GLint arrayLayer, GLsizei width, GLsizei height);
+ virtual gl::Error copyToStorage(TextureStorage *storage, const gl::ImageIndex &index, const gl::Box &region);
- virtual bool redefine(Renderer *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease);
+ bool redefine(RendererD3D *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease) override;
DXGI_FORMAT getDXGIFormat() const;
-
- virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- GLint unpackAlignment, GLenum type, const void *input);
- virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
- const void *input);
- virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
+ virtual gl::Error loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ GLint unpackAlignment, GLenum type, const void *input);
+ virtual gl::Error loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
+ const void *input);
- bool recoverFromAssociatedStorage();
+ virtual gl::Error copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea, RenderTarget *source);
+ virtual gl::Error copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea,
+ const gl::ImageIndex &sourceIndex, TextureStorage *source);
+
+ gl::Error recoverFromAssociatedStorage();
bool isAssociatedStorageValid(TextureStorage11* textureStorage) const;
void disassociateStorage();
protected:
- HRESULT map(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map);
+ gl::Error map(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map);
void unmap();
private:
DISALLOW_COPY_AND_ASSIGN(Image11);
- bool copyToStorageImpl(TextureStorage11 *storage11, int level, int layerTarget, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
+ gl::Error copyToStorageImpl(TextureStorage11 *storage11, const gl::ImageIndex &index, const gl::Box &region);
+ gl::Error copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Rectangle &sourceArea, ID3D11Texture2D *source, UINT sourceSubResource);
- ID3D11Resource *getStagingTexture();
- unsigned int getStagingSubresource();
- void createStagingTexture();
+ gl::Error getStagingTexture(ID3D11Resource **outStagingTexture, unsigned int *outSubresourceIndex);
+ gl::Error createStagingTexture();
void releaseStagingTexture();
Renderer11 *mRenderer;
@@ -79,8 +78,7 @@ class Image11 : public ImageD3D
bool mRecoverFromStorage;
TextureStorage11 *mAssociatedStorage;
- int mAssociatedStorageLevel;
- int mAssociatedStorageLayerTarget;
+ gl::ImageIndex mAssociatedImageIndex;
unsigned int mRecoveredFromStorageCount;
};
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/IndexBuffer11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/IndexBuffer11.h
index f7c2b38e7e..3351df5ec1 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/IndexBuffer11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/IndexBuffer11.h
@@ -40,7 +40,7 @@ class IndexBuffer11 : public IndexBuffer
private:
DISALLOW_COPY_AND_ASSIGN(IndexBuffer11);
- rx::Renderer11 *const mRenderer;
+ Renderer11 *const mRenderer;
ID3D11Buffer *mBuffer;
unsigned int mBufferSize;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp
index d835e4fa68..ff90a6a69a 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/InputLayoutCache.cpp
@@ -12,6 +12,7 @@
#include "libGLESv2/renderer/d3d/d3d11/Buffer11.h"
#include "libGLESv2/renderer/d3d/d3d11/ShaderExecutable11.h"
#include "libGLESv2/renderer/d3d/d3d11/formatutils11.h"
+#include "libGLESv2/renderer/d3d/ProgramD3D.h"
#include "libGLESv2/renderer/d3d/VertexDataManager.h"
#include "libGLESv2/ProgramBinary.h"
#include "libGLESv2/VertexAttribute.h"
@@ -137,7 +138,16 @@ gl::Error InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl
{
gl::VertexFormat shaderInputLayout[gl::MAX_VERTEX_ATTRIBS];
GetInputLayout(attributes, shaderInputLayout);
- ShaderExecutable11 *shader = ShaderExecutable11::makeShaderExecutable11(programBinary->getVertexExecutableForInputLayout(shaderInputLayout));
+ ProgramD3D *programD3D = ProgramD3D::makeProgramD3D(programBinary->getImplementation());
+
+ ShaderExecutable *shader = NULL;
+ gl::Error error = programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ ShaderExecutable *shader11 = ShaderExecutable11::makeShaderExecutable11(shader);
D3D11_INPUT_ELEMENT_DESC descs[gl::MAX_VERTEX_ATTRIBS];
for (unsigned int j = 0; j < ilKey.elementCount; ++j)
@@ -145,7 +155,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl
descs[j] = ilKey.elements[j].desc;
}
- HRESULT result = mDevice->CreateInputLayout(descs, ilKey.elementCount, shader->getFunction(), shader->getLength(), &inputLayout);
+ HRESULT result = mDevice->CreateInputLayout(descs, ilKey.elementCount, shader11->getFunction(), shader11->getLength(), &inputLayout);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal input layout, HRESULT: 0x%08x", result);
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.cpp
index a4e84f91c2..6a3d3475ee 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.cpp
@@ -33,12 +33,38 @@ namespace rx
PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
: mRenderer(renderer),
+ mResourcesLoaded(false),
mBufferToTextureVS(NULL),
mBufferToTextureGS(NULL),
mParamsConstantBuffer(NULL),
mCopyRasterizerState(NULL),
mCopyDepthStencilState(NULL)
{
+}
+
+PixelTransfer11::~PixelTransfer11()
+{
+ for (auto shaderMapIt = mBufferToTexturePSMap.begin(); shaderMapIt != mBufferToTexturePSMap.end(); shaderMapIt++)
+ {
+ SafeRelease(shaderMapIt->second);
+ }
+
+ mBufferToTexturePSMap.clear();
+
+ SafeRelease(mBufferToTextureVS);
+ SafeRelease(mBufferToTextureGS);
+ SafeRelease(mParamsConstantBuffer);
+ SafeRelease(mCopyRasterizerState);
+ SafeRelease(mCopyDepthStencilState);
+}
+
+gl::Error PixelTransfer11::loadResources()
+{
+ if (mResourcesLoaded)
+ {
+ return gl::Error(GL_NO_ERROR);
+ }
+
HRESULT result = S_OK;
ID3D11Device *device = mRenderer->getDevice();
@@ -56,6 +82,10 @@ PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
result = device->CreateRasterizerState(&rasterDesc, &mCopyRasterizerState);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal pixel transfer rasterizer state, result: 0x%X.", result);
+ }
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
depthStencilDesc.DepthEnable = true;
@@ -75,9 +105,13 @@ PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
result = device->CreateDepthStencilState(&depthStencilDesc, &mCopyDepthStencilState);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal pixel transfer depth stencil state, result: 0x%X.", result);
+ }
D3D11_BUFFER_DESC constantBufferDesc = { 0 };
- constantBufferDesc.ByteWidth = rx::roundUp<UINT>(sizeof(CopyShaderParams), 32u);
+ constantBufferDesc.ByteWidth = roundUp<UINT>(sizeof(CopyShaderParams), 32u);
constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
@@ -86,34 +120,39 @@ PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
result = device->CreateBuffer(&constantBufferDesc, NULL, &mParamsConstantBuffer);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal pixel transfer constant buffer, result: 0x%X.", result);
+ }
d3d11::SetDebugName(mParamsConstantBuffer, "PixelTransfer11 constant buffer");
- StructZero(&mParamsData);
-
// init shaders
- if (mRenderer->isLevel9())
- return;
-
mBufferToTextureVS = d3d11::CompileVS(device, g_VS_BufferToTexture, "BufferToTexture VS");
- mBufferToTextureGS = d3d11::CompileGS(device, g_GS_BufferToTexture, "BufferToTexture GS");
+ if (!mBufferToTextureVS)
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture vertex shader.");
+ }
- buildShaderMap();
-}
+ if (!mRenderer->isLevel9())
+ {
+ mBufferToTextureGS = d3d11::CompileGS(device, g_GS_BufferToTexture, "BufferToTexture GS");
+ if (!mBufferToTextureGS)
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture geometry shader.");
+ }
+ }
-PixelTransfer11::~PixelTransfer11()
-{
- for (auto shaderMapIt = mBufferToTexturePSMap.begin(); shaderMapIt != mBufferToTexturePSMap.end(); shaderMapIt++)
+ gl::Error error = buildShaderMap();
+ if (error.isError())
{
- SafeRelease(shaderMapIt->second);
+ return error;
}
- mBufferToTexturePSMap.clear();
+ StructZero(&mParamsData);
- SafeRelease(mBufferToTextureVS);
- SafeRelease(mBufferToTextureGS);
- SafeRelease(mParamsConstantBuffer);
- SafeRelease(mCopyRasterizerState);
- SafeRelease(mCopyDepthStencilState);
+ mResourcesLoaded = true;
+
+ return gl::Error(GL_NO_ERROR);
}
void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
@@ -138,18 +177,21 @@ void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, cons
parametersOut->PositionScale[1] = -2.0f / static_cast<float>(destSize.height);
}
-bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
- GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
+gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
+ GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
{
- gl::Extents destSize = destRenderTarget->getExtents();
-
- if (destArea.x < 0 || destArea.x + destArea.width > destSize.width ||
- destArea.y < 0 || destArea.y + destArea.height > destSize.height ||
- destArea.z < 0 || destArea.z + destArea.depth > destSize.depth )
+ gl::Error error = loadResources();
+ if (error.isError())
{
- return false;
+ return error;
}
+ gl::Extents destSize = destRenderTarget->getExtents();
+
+ ASSERT(destArea.x >= 0 && destArea.x + destArea.width <= destSize.width &&
+ destArea.y >= 0 && destArea.y + destArea.height <= destSize.height &&
+ destArea.z >= 0 && destArea.z + destArea.depth <= destSize.depth );
+
const gl::Buffer &sourceBuffer = *unpack.pixelBuffer.get();
ASSERT(mRenderer->supportsFastCopyBufferToTexture(destinationFormat));
@@ -177,7 +219,6 @@ bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, un
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
- ID3D11ShaderResourceView *nullSRV = NULL;
ID3D11Buffer *nullBuffer = NULL;
UINT zero = 0;
@@ -187,7 +228,7 @@ bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, un
deviceContext->VSSetShader(mBufferToTextureVS, NULL, 0);
deviceContext->GSSetShader(geometryShader, NULL, 0);
deviceContext->PSSetShader(pixelShader, NULL, 0);
- deviceContext->PSSetShaderResources(0, 1, &bufferSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, bufferSRV);
deviceContext->IASetInputLayout(NULL);
deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
@@ -220,21 +261,32 @@ bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, un
deviceContext->Draw(numPixels, 0);
// Unbind textures and render targets and vertex buffer
- deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL);
deviceContext->VSSetConstantBuffers(0, 1, &nullBuffer);
mRenderer->markAllStateDirty();
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-void PixelTransfer11::buildShaderMap()
+gl::Error PixelTransfer11::buildShaderMap()
{
ID3D11Device *device = mRenderer->getDevice();
mBufferToTexturePSMap[GL_FLOAT] = d3d11::CompilePS(device, g_PS_BufferToTexture_4F, "BufferToTexture RGBA ps");
mBufferToTexturePSMap[GL_INT] = d3d11::CompilePS(device, g_PS_BufferToTexture_4I, "BufferToTexture RGBA-I ps");
mBufferToTexturePSMap[GL_UNSIGNED_INT] = d3d11::CompilePS(device, g_PS_BufferToTexture_4UI, "BufferToTexture RGBA-UI ps");
+
+ // Check that all the shaders were created successfully
+ for (auto shaderMapIt = mBufferToTexturePSMap.begin(); shaderMapIt != mBufferToTexturePSMap.end(); shaderMapIt++)
+ {
+ if (shaderMapIt->second == NULL)
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture pixel shader.");
+ }
+ }
+
+ return gl::Error(GL_NO_ERROR);
}
ID3D11PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) const
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.h
index ed1a3ae1d0..29552140bb 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/PixelTransfer11.h
@@ -11,6 +11,8 @@
#ifndef LIBGLESV2_PIXELTRANSFER11_H_
#define LIBGLESV2_PIXELTRANSFER11_H_
+#include "libGLESv2/Error.h"
+
#include "common/platform.h"
#include <GLES2/gl2.h>
@@ -38,15 +40,13 @@ class PixelTransfer11
explicit PixelTransfer11(Renderer11 *renderer);
~PixelTransfer11();
- static bool supportsBufferToTextureCopy(GLenum internalFormat);
-
// unpack: the source buffer is stored in the unpack state, and buffer strides
// offset: the start of the data within the unpack buffer
// destRenderTarget: individual slice/layer of a target texture
// destinationFormat/sourcePixelsType: determines shaders + shader parameters
// destArea: the sub-section of destRenderTarget to copy to
- bool copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
- GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
+ gl::Error copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
+ GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
private:
@@ -65,11 +65,13 @@ class PixelTransfer11
static void setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
const gl::PixelUnpackState &unpack, unsigned int offset, CopyShaderParams *parametersOut);
- void buildShaderMap();
+ gl::Error loadResources();
+ gl::Error buildShaderMap();
ID3D11PixelShader *findBufferToTexturePS(GLenum internalFormat) const;
Renderer11 *mRenderer;
+ bool mResourcesLoaded;
std::map<GLenum, ID3D11PixelShader *> mBufferToTexturePSMap;
ID3D11VertexShader *mBufferToTextureVS;
ID3D11GeometryShader *mBufferToTextureGS;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.cpp
index 7109be3e28..17ab1f8ab3 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.cpp
@@ -10,13 +10,14 @@
#include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
#include "libGLESv2/renderer/d3d/d3d11/renderer11_utils.h"
#include "libGLESv2/main.h"
+#include "common/utilities.h"
#include <GLES2/gl2ext.h>
namespace rx
{
-Query11::Query11(rx::Renderer11 *renderer, GLenum type)
+Query11::Query11(Renderer11 *renderer, GLenum type)
: QueryImpl(type),
mResult(0),
mQueryFinished(false),
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.h
index 822f2542ee..f9ff467873 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Query11.h
@@ -18,7 +18,7 @@ class Renderer11;
class Query11 : public QueryImpl
{
public:
- Query11(rx::Renderer11 *renderer, GLenum type);
+ Query11(Renderer11 *renderer, GLenum type);
virtual ~Query11();
virtual gl::Error begin();
@@ -35,7 +35,7 @@ class Query11 : public QueryImpl
bool mQueryFinished;
- rx::Renderer11 *mRenderer;
+ Renderer11 *mRenderer;
ID3D11Query *mQuery;
};
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp
index 71b931f27e..ab4f60bd98 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp
@@ -38,11 +38,14 @@ const unsigned int RenderStateCache::kMaxRasterizerStates = 4096;
const unsigned int RenderStateCache::kMaxDepthStencilStates = 4096;
const unsigned int RenderStateCache::kMaxSamplerStates = 4096;
-RenderStateCache::RenderStateCache() : mDevice(NULL), mCounter(0),
- mBlendStateCache(kMaxBlendStates, hashBlendState, compareBlendStates),
- mRasterizerStateCache(kMaxRasterizerStates, hashRasterizerState, compareRasterizerStates),
- mDepthStencilStateCache(kMaxDepthStencilStates, hashDepthStencilState, compareDepthStencilStates),
- mSamplerStateCache(kMaxSamplerStates, hashSamplerState, compareSamplerStates)
+RenderStateCache::RenderStateCache(Renderer11 *renderer)
+ : mRenderer(renderer),
+ mDevice(NULL),
+ mCounter(0),
+ mBlendStateCache(kMaxBlendStates, hashBlendState, compareBlendStates),
+ mRasterizerStateCache(kMaxRasterizerStates, hashRasterizerState, compareRasterizerStates),
+ mDepthStencilStateCache(kMaxDepthStencilStates, hashDepthStencilState, compareDepthStencilStates),
+ mSamplerStateCache(kMaxSamplerStates, hashSamplerState, compareSamplerStates)
{
}
@@ -89,7 +92,7 @@ gl::Error RenderStateCache::getBlendState(const gl::Framebuffer *framebuffer, co
bool mrt = false;
- const gl::ColorbufferInfo &colorbuffers = framebuffer->getColorbuffersForRender();
+ const gl::ColorbufferInfo &colorbuffers = framebuffer->getColorbuffersForRender(mRenderer->getWorkarounds());
BlendStateKey key = { 0 };
key.blendState = blendState;
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h
index d5471a3061..dfd1d84265 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h
@@ -28,7 +28,7 @@ class Renderer11;
class RenderStateCache
{
public:
- RenderStateCache();
+ RenderStateCache(Renderer11 *renderer);
virtual ~RenderStateCache();
void initialize(ID3D11Device *device);
@@ -42,6 +42,7 @@ class RenderStateCache
private:
DISALLOW_COPY_AND_ASSIGN(RenderStateCache);
+ Renderer11 *mRenderer;
unsigned long long mCounter;
// Blend state cache
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.cpp
index 3041f21faa..aff3453492 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.cpp
@@ -10,6 +10,7 @@
#include "libGLESv2/renderer/d3d/d3d11/RenderTarget11.h"
#include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
#include "libGLESv2/renderer/d3d/d3d11/renderer11_utils.h"
+#include "libGLESv2/renderer/d3d/d3d11/SwapChain11.h"
#include "libGLESv2/renderer/d3d/d3d11/formatutils11.h"
#include "libGLESv2/main.h"
@@ -176,276 +177,228 @@ static unsigned int getDSVSubresourceIndex(ID3D11Resource *resource, ID3D11Depth
return D3D11CalcSubresource(mipSlice, arraySlice, mipLevels);
}
-RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11RenderTargetView *rtv, ID3D11Resource *resource,
- ID3D11ShaderResourceView *srv, GLsizei width, GLsizei height, GLsizei depth)
+RenderTarget11 *RenderTarget11::makeRenderTarget11(RenderTarget *target)
+{
+ ASSERT(HAS_DYNAMIC_TYPE(RenderTarget11*, target));
+ return static_cast<RenderTarget11*>(target);
+}
+
+void RenderTarget11::invalidate(GLint x, GLint y, GLsizei width, GLsizei height)
{
- mRenderer = Renderer11::makeRenderer11(renderer);
+ // Currently a no-op
+}
- mTexture = resource;
+TextureRenderTarget11::TextureRenderTarget11(ID3D11RenderTargetView *rtv, ID3D11Resource *resource, ID3D11ShaderResourceView *srv,
+ GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei samples)
+ : mWidth(width),
+ mHeight(height),
+ mDepth(depth),
+ mInternalFormat(internalFormat),
+ mActualFormat(internalFormat),
+ mSamples(samples),
+ mSubresourceIndex(0),
+ mTexture(resource),
+ mRenderTarget(rtv),
+ mDepthStencil(NULL),
+ mShaderResource(srv)
+{
if (mTexture)
{
mTexture->AddRef();
}
- mRenderTarget = rtv;
if (mRenderTarget)
{
mRenderTarget->AddRef();
}
- mDepthStencil = NULL;
-
- mShaderResource = srv;
if (mShaderResource)
{
mShaderResource->AddRef();
}
- mSubresourceIndex = 0;
-
if (mRenderTarget && mTexture)
{
+ mSubresourceIndex = getRTVSubresourceIndex(mTexture, mRenderTarget);
+
D3D11_RENDER_TARGET_VIEW_DESC desc;
mRenderTarget->GetDesc(&desc);
- unsigned int mipLevels, samples;
- getTextureProperties(mTexture, &mipLevels, &samples);
-
- mSubresourceIndex = getRTVSubresourceIndex(mTexture, mRenderTarget);
- mWidth = width;
- mHeight = height;
- mDepth = depth;
- mSamples = samples;
-
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(desc.Format);
- mInternalFormat = dxgiFormatInfo.internalFormat;
mActualFormat = dxgiFormatInfo.internalFormat;
}
}
-RenderTarget11::RenderTarget11(Renderer *renderer, ID3D11DepthStencilView *dsv, ID3D11Resource *resource,
- ID3D11ShaderResourceView *srv, GLsizei width, GLsizei height, GLsizei depth)
+TextureRenderTarget11::TextureRenderTarget11(ID3D11DepthStencilView *dsv, ID3D11Resource *resource, ID3D11ShaderResourceView *srv,
+ GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei samples)
+ : mWidth(width),
+ mHeight(height),
+ mDepth(depth),
+ mInternalFormat(internalFormat),
+ mActualFormat(internalFormat),
+ mSamples(samples),
+ mSubresourceIndex(0),
+ mTexture(resource),
+ mRenderTarget(NULL),
+ mDepthStencil(dsv),
+ mShaderResource(srv)
{
- mRenderer = Renderer11::makeRenderer11(renderer);
-
- mTexture = resource;
if (mTexture)
{
mTexture->AddRef();
}
- mRenderTarget = NULL;
-
- mDepthStencil = dsv;
if (mDepthStencil)
{
mDepthStencil->AddRef();
}
- mShaderResource = srv;
if (mShaderResource)
{
mShaderResource->AddRef();
}
- mSubresourceIndex = 0;
-
if (mDepthStencil && mTexture)
{
+ mSubresourceIndex = getDSVSubresourceIndex(mTexture, mDepthStencil);
+
D3D11_DEPTH_STENCIL_VIEW_DESC desc;
mDepthStencil->GetDesc(&desc);
- unsigned int mipLevels, samples;
- getTextureProperties(mTexture, &mipLevels, &samples);
-
- mSubresourceIndex = getDSVSubresourceIndex(mTexture, mDepthStencil);
- mWidth = width;
- mHeight = height;
- mDepth = depth;
- mSamples = samples;
-
const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(desc.Format);
- mInternalFormat = dxgiFormatInfo.internalFormat;
mActualFormat = dxgiFormatInfo.internalFormat;
}
}
-RenderTarget11::RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height, GLenum internalFormat, GLsizei samples)
+TextureRenderTarget11::~TextureRenderTarget11()
{
- mRenderer = Renderer11::makeRenderer11(renderer);
- mTexture = NULL;
- mRenderTarget = NULL;
- mDepthStencil = NULL;
- mShaderResource = NULL;
+ SafeRelease(mTexture);
+ SafeRelease(mRenderTarget);
+ SafeRelease(mDepthStencil);
+ SafeRelease(mShaderResource);
+}
- const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(internalFormat);
- const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(formatInfo.texFormat);
+ID3D11Resource *TextureRenderTarget11::getTexture() const
+{
+ return mTexture;
+}
- const gl::TextureCaps &textureCaps = mRenderer->getRendererTextureCaps().get(internalFormat);
- GLuint supportedSamples = textureCaps.getNearestSamples(samples);
+ID3D11RenderTargetView *TextureRenderTarget11::getRenderTargetView() const
+{
+ return mRenderTarget;
+}
- if (width > 0 && height > 0)
- {
- // Create texture resource
- D3D11_TEXTURE2D_DESC desc;
- desc.Width = width;
- desc.Height = height;
- desc.MipLevels = 1;
- desc.ArraySize = 1;
- desc.Format = formatInfo.texFormat;
- desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples;
- desc.SampleDesc.Quality = 0;
- desc.Usage = D3D11_USAGE_DEFAULT;
- desc.CPUAccessFlags = 0;
- desc.MiscFlags = 0;
-
- // If a rendertarget or depthstencil format exists for this texture format,
- // we'll flag it to allow binding that way. Shader resource views are a little
- // more complicated.
- bool bindRTV = false, bindDSV = false, bindSRV = false;
- bindRTV = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN);
- bindDSV = (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN);
- if (formatInfo.srvFormat != DXGI_FORMAT_UNKNOWN)
- {
- // Multisample targets flagged for binding as depth stencil cannot also be
- // flagged for binding as SRV, so make certain not to add the SRV flag for
- // these targets.
- bindSRV = !(formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN && desc.SampleDesc.Count > 1);
- }
-
- desc.BindFlags = (bindRTV ? D3D11_BIND_RENDER_TARGET : 0) |
- (bindDSV ? D3D11_BIND_DEPTH_STENCIL : 0) |
- (bindSRV ? D3D11_BIND_SHADER_RESOURCE : 0);
-
- ID3D11Device *device = mRenderer->getDevice();
- ID3D11Texture2D *texture = NULL;
- HRESULT result = device->CreateTexture2D(&desc, NULL, &texture);
- mTexture = texture;
-
- if (result == E_OUTOFMEMORY)
- {
- gl::error(GL_OUT_OF_MEMORY);
- return;
- }
- ASSERT(SUCCEEDED(result));
-
- if (bindSRV)
- {
- D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
- srvDesc.Format = formatInfo.srvFormat;
- srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS;
- srvDesc.Texture2D.MostDetailedMip = 0;
- srvDesc.Texture2D.MipLevels = 1;
- result = device->CreateShaderResourceView(mTexture, &srvDesc, &mShaderResource);
-
- if (result == E_OUTOFMEMORY)
- {
- SafeRelease(mTexture);
- gl::error(GL_OUT_OF_MEMORY);
- return;
- }
- ASSERT(SUCCEEDED(result));
- }
-
- if (bindDSV)
- {
- D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
- dsvDesc.Format = formatInfo.dsvFormat;
- dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS;
- dsvDesc.Texture2D.MipSlice = 0;
- dsvDesc.Flags = 0;
- result = device->CreateDepthStencilView(mTexture, &dsvDesc, &mDepthStencil);
-
- if (result == E_OUTOFMEMORY)
- {
- SafeRelease(mTexture);
- SafeRelease(mShaderResource);
- gl::error(GL_OUT_OF_MEMORY);
- return;
- }
- ASSERT(SUCCEEDED(result));
- }
-
- if (bindRTV)
- {
- D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
- rtvDesc.Format = formatInfo.rtvFormat;
- rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS;
- rtvDesc.Texture2D.MipSlice = 0;
- result = device->CreateRenderTargetView(mTexture, &rtvDesc, &mRenderTarget);
-
- if (result == E_OUTOFMEMORY)
- {
- SafeRelease(mTexture);
- SafeRelease(mShaderResource);
- SafeRelease(mDepthStencil);
- gl::error(GL_OUT_OF_MEMORY);
- return;
- }
- ASSERT(SUCCEEDED(result));
-
- if (formatInfo.dataInitializerFunction != NULL)
- {
- ID3D11DeviceContext *context = mRenderer->getDeviceContext();
-
- const float clearValues[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
- context->ClearRenderTargetView(mRenderTarget, clearValues);
- }
- }
- }
+ID3D11DepthStencilView *TextureRenderTarget11::getDepthStencilView() const
+{
+ return mDepthStencil;
+}
+ID3D11ShaderResourceView *TextureRenderTarget11::getShaderResourceView() const
+{
+ return mShaderResource;
+}
- mWidth = width;
- mHeight = height;
- mDepth = 1;
- mInternalFormat = internalFormat;
- mSamples = supportedSamples;
- mActualFormat = dxgiFormatInfo.internalFormat;
- mSubresourceIndex = D3D11CalcSubresource(0, 0, 1);
+GLsizei TextureRenderTarget11::getWidth() const
+{
+ return mWidth;
}
-RenderTarget11::~RenderTarget11()
+GLsizei TextureRenderTarget11::getHeight() const
{
- SafeRelease(mTexture);
- SafeRelease(mRenderTarget);
- SafeRelease(mDepthStencil);
- SafeRelease(mShaderResource);
+ return mHeight;
}
-RenderTarget11 *RenderTarget11::makeRenderTarget11(RenderTarget *target)
+GLsizei TextureRenderTarget11::getDepth() const
{
- ASSERT(HAS_DYNAMIC_TYPE(rx::RenderTarget11*, target));
- return static_cast<rx::RenderTarget11*>(target);
+ return mDepth;
}
-void RenderTarget11::invalidate(GLint x, GLint y, GLsizei width, GLsizei height)
+GLenum TextureRenderTarget11::getInternalFormat() const
{
- // Currently a no-op
+ return mInternalFormat;
}
-ID3D11Resource *RenderTarget11::getTexture() const
+GLenum TextureRenderTarget11::getActualFormat() const
{
- return mTexture;
+ return mActualFormat;
}
-ID3D11RenderTargetView *RenderTarget11::getRenderTargetView() const
+GLsizei TextureRenderTarget11::getSamples() const
{
- return mRenderTarget;
+ return mSamples;
}
-ID3D11DepthStencilView *RenderTarget11::getDepthStencilView() const
+unsigned int TextureRenderTarget11::getSubresourceIndex() const
{
- return mDepthStencil;
+ return mSubresourceIndex;
}
-ID3D11ShaderResourceView *RenderTarget11::getShaderResourceView() const
+
+SurfaceRenderTarget11::SurfaceRenderTarget11(SwapChain11 *swapChain, bool depth)
+ : mSwapChain(swapChain),
+ mDepth(depth)
{
- return mShaderResource;
+ ASSERT(mSwapChain);
}
-unsigned int RenderTarget11::getSubresourceIndex() const
+SurfaceRenderTarget11::~SurfaceRenderTarget11()
{
- return mSubresourceIndex;
+}
+
+GLsizei SurfaceRenderTarget11::getWidth() const
+{
+ return mSwapChain->getWidth();
+}
+
+GLsizei SurfaceRenderTarget11::getHeight() const
+{
+ return mSwapChain->getHeight();
+}
+
+GLsizei SurfaceRenderTarget11::getDepth() const
+{
+ return 1;
+}
+
+GLenum SurfaceRenderTarget11::getInternalFormat() const
+{
+ return (mDepth ? mSwapChain->GetDepthBufferInternalFormat() : mSwapChain->GetBackBufferInternalFormat());
+}
+
+GLenum SurfaceRenderTarget11::getActualFormat() const
+{
+ return d3d11::GetDXGIFormatInfo(d3d11::GetTextureFormatInfo(getInternalFormat()).texFormat).internalFormat;
+}
+
+GLsizei SurfaceRenderTarget11::getSamples() const
+{
+ // Our EGL surfaces do not support multisampling.
+ return 0;
+}
+
+ID3D11Resource *SurfaceRenderTarget11::getTexture() const
+{
+ return (mDepth ? mSwapChain->getDepthStencilTexture() : mSwapChain->getOffscreenTexture());
+}
+
+ID3D11RenderTargetView *SurfaceRenderTarget11::getRenderTargetView() const
+{
+ return (mDepth ? NULL : mSwapChain->getRenderTarget());
+}
+
+ID3D11DepthStencilView *SurfaceRenderTarget11::getDepthStencilView() const
+{
+ return (mDepth ? mSwapChain->getDepthStencil() : NULL);
+}
+
+ID3D11ShaderResourceView *SurfaceRenderTarget11::getShaderResourceView() const
+{
+ return (mDepth ? mSwapChain->getDepthStencilShaderResource() : mSwapChain->getRenderTargetShaderResource());
+}
+
+unsigned int SurfaceRenderTarget11::getSubresourceIndex() const
+{
+ return 0;
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.h
index 82182957af..c7babdda3f 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/RenderTarget11.h
@@ -14,39 +14,95 @@
namespace rx
{
-class Renderer;
-class Renderer11;
+class SwapChain11;
class RenderTarget11 : public RenderTarget
{
public:
- // RenderTarget11 takes ownership of any D3D11 resources it is given and will AddRef them
- RenderTarget11(Renderer *renderer, ID3D11RenderTargetView *rtv, ID3D11Resource *resource, ID3D11ShaderResourceView *srv, GLsizei width, GLsizei height, GLsizei depth);
- RenderTarget11(Renderer *renderer, ID3D11DepthStencilView *dsv, ID3D11Resource *resource, ID3D11ShaderResourceView *srv, GLsizei width, GLsizei height, GLsizei depth);
- RenderTarget11(Renderer *renderer, GLsizei width, GLsizei height, GLenum internalFormat, GLsizei samples);
- virtual ~RenderTarget11();
+ RenderTarget11() { }
+ virtual ~RenderTarget11() { }
static RenderTarget11 *makeRenderTarget11(RenderTarget *renderTarget);
- virtual void invalidate(GLint x, GLint y, GLsizei width, GLsizei height);
+ void invalidate(GLint x, GLint y, GLsizei width, GLsizei height) override;
- ID3D11Resource *getTexture() const;
- ID3D11RenderTargetView *getRenderTargetView() const;
- ID3D11DepthStencilView *getDepthStencilView() const;
- ID3D11ShaderResourceView *getShaderResourceView() const;
+ virtual ID3D11Resource *getTexture() const = 0;
+ virtual ID3D11RenderTargetView *getRenderTargetView() const = 0;
+ virtual ID3D11DepthStencilView *getDepthStencilView() const = 0;
+ virtual ID3D11ShaderResourceView *getShaderResourceView() const = 0;
- unsigned int getSubresourceIndex() const;
+ virtual unsigned int getSubresourceIndex() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(RenderTarget11);
+};
+
+class TextureRenderTarget11 : public RenderTarget11
+{
+ public:
+ // TextureRenderTarget11 takes ownership of any D3D11 resources it is given and will AddRef them
+ TextureRenderTarget11(ID3D11RenderTargetView *rtv, ID3D11Resource *resource, ID3D11ShaderResourceView *srv,
+ GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei samples);
+ TextureRenderTarget11(ID3D11DepthStencilView *dsv, ID3D11Resource *resource, ID3D11ShaderResourceView *srv,
+ GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei samples);
+ virtual ~TextureRenderTarget11();
+
+ GLsizei getWidth() const override;
+ GLsizei getHeight() const override;
+ GLsizei getDepth() const override;
+ GLenum getInternalFormat() const override;
+ GLenum getActualFormat() const override;
+ GLsizei getSamples() const override;
+
+ ID3D11Resource *getTexture() const override;
+ ID3D11RenderTargetView *getRenderTargetView() const override;
+ ID3D11DepthStencilView *getDepthStencilView() const override;
+ ID3D11ShaderResourceView *getShaderResourceView() const override;
+
+ unsigned int getSubresourceIndex() const override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TextureRenderTarget11);
+
+ GLsizei mWidth;
+ GLsizei mHeight;
+ GLsizei mDepth;
+ GLenum mInternalFormat;
+ GLenum mActualFormat;
+ GLsizei mSamples;
unsigned int mSubresourceIndex;
ID3D11Resource *mTexture;
ID3D11RenderTargetView *mRenderTarget;
ID3D11DepthStencilView *mDepthStencil;
ID3D11ShaderResourceView *mShaderResource;
+};
+
+class SurfaceRenderTarget11 : public RenderTarget11
+{
+ public:
+ SurfaceRenderTarget11(SwapChain11 *swapChain, bool depth);
+ virtual ~SurfaceRenderTarget11();
+
+ GLsizei getWidth() const override;
+ GLsizei getHeight() const override;
+ GLsizei getDepth() const override;
+ GLenum getInternalFormat() const override;
+ GLenum getActualFormat() const override;
+ GLsizei getSamples() const override;
+
+ ID3D11Resource *getTexture() const override;
+ ID3D11RenderTargetView *getRenderTargetView() const override;
+ ID3D11DepthStencilView *getDepthStencilView() const override;
+ ID3D11ShaderResourceView *getShaderResourceView() const override;
+
+ unsigned int getSubresourceIndex() const override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SurfaceRenderTarget11);
- Renderer11 *mRenderer;
+ SwapChain11 *mSwapChain;
+ bool mDepth;
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
index b29b2ef910..e6d7f3025b 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
@@ -6,12 +6,12 @@
// Renderer11.cpp: Implements a back-end specific class for the D3D11 renderer.
-#include "common/platform.h"
#include "libGLESv2/main.h"
#include "libGLESv2/Buffer.h"
#include "libGLESv2/FramebufferAttachment.h"
#include "libGLESv2/ProgramBinary.h"
#include "libGLESv2/Framebuffer.h"
+#include "libGLESv2/State.h"
#include "libGLESv2/renderer/d3d/ProgramD3D.h"
#include "libGLESv2/renderer/d3d/ShaderD3D.h"
#include "libGLESv2/renderer/d3d/TextureD3D.h"
@@ -36,10 +36,12 @@
#include "libGLESv2/renderer/d3d/d3d11/PixelTransfer11.h"
#include "libGLESv2/renderer/d3d/d3d11/VertexArray11.h"
#include "libGLESv2/renderer/d3d/d3d11/Buffer11.h"
+#include "libGLESv2/renderer/d3d/RenderbufferD3D.h"
#include "libEGL/Display.h"
#include "common/utilities.h"
+#include "common/tls.h"
#include <EGL/eglext.h>
@@ -59,6 +61,9 @@
namespace rx
{
+
+namespace
+{
static const DXGI_FORMAT RenderTargetFormats[] =
{
DXGI_FORMAT_B8G8R8A8_UNORM,
@@ -77,10 +82,22 @@ enum
MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16
};
-Renderer11::Renderer11(egl::Display *display, EGLNativeDisplayType hDc, EGLint requestedDisplay)
- : Renderer(display),
+// Does *not* increment the resource ref count!!
+ID3D11Resource *GetSRVResource(ID3D11ShaderResourceView *srv)
+{
+ ID3D11Resource *resource = NULL;
+ ASSERT(srv);
+ srv->GetResource(&resource);
+ resource->Release();
+ return resource;
+}
+
+}
+
+Renderer11::Renderer11(egl::Display *display, EGLNativeDisplayType hDc, const egl::AttributeMap &attributes)
+ : RendererD3D(display),
mDc(hDc),
- mRequestedDisplay(requestedDisplay)
+ mStateCache(this)
{
mVertexDataManager = NULL;
mIndexDataManager = NULL;
@@ -112,6 +129,50 @@ Renderer11::Renderer11(egl::Display *display, EGLNativeDisplayType hDc, EGLint r
mAppliedGeometryShader = NULL;
mCurPointGeometryShader = NULL;
mAppliedPixelShader = NULL;
+
+ EGLint requestedMajorVersion = attributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, EGL_DONT_CARE);
+ EGLint requestedMinorVersion = attributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, EGL_DONT_CARE);
+
+ if (requestedMajorVersion == EGL_DONT_CARE || requestedMajorVersion >= 11)
+ {
+ if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 0)
+ {
+ mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_11_0);
+ }
+ }
+
+ if (requestedMajorVersion == EGL_DONT_CARE || requestedMajorVersion >= 10)
+ {
+ if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 1)
+ {
+ mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_10_1);
+ }
+ if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 0)
+ {
+ mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_10_0);
+ }
+ }
+
+#if !defined(ANGLE_ENABLE_D3D9)
+ if (requestedMajorVersion == EGL_DONT_CARE || requestedMajorVersion >= 9)
+ {
+ if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 3)
+ {
+ mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_9_3);
+ }
+ if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 2)
+ {
+ mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_9_2);
+ }
+ if (requestedMinorVersion == EGL_DONT_CARE || requestedMinorVersion >= 1)
+ {
+ mAvailableFeatureLevels.push_back(D3D_FEATURE_LEVEL_9_1);
+ }
+ }
+#endif
+
+ mDriverType = (attributes.get(EGL_PLATFORM_ANGLE_USE_WARP_ANGLE, EGL_FALSE) == EGL_TRUE) ? D3D_DRIVER_TYPE_WARP
+ : D3D_DRIVER_TYPE_HARDWARE;
}
Renderer11::~Renderer11()
@@ -121,8 +182,8 @@ Renderer11::~Renderer11()
Renderer11 *Renderer11::makeRenderer11(Renderer *renderer)
{
- ASSERT(HAS_DYNAMIC_TYPE(rx::Renderer11*, renderer));
- return static_cast<rx::Renderer11*>(renderer);
+ ASSERT(HAS_DYNAMIC_TYPE(Renderer11*, renderer));
+ return static_cast<Renderer11*>(renderer);
}
#ifndef __d3d11_1_h__
@@ -136,7 +197,7 @@ EGLint Renderer11::initialize()
return EGL_NOT_INITIALIZED;
}
-#if !defined(ANGLE_PLATFORM_WINRT)
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
mDxgiModule = LoadLibrary(TEXT("dxgi.dll"));
mD3d11Module = LoadLibrary(TEXT("d3d11.dll"));
@@ -157,33 +218,14 @@ EGLint Renderer11::initialize()
}
#endif
- D3D_FEATURE_LEVEL featureLevels[] =
- {
- D3D_FEATURE_LEVEL_11_0,
- D3D_FEATURE_LEVEL_10_1,
- D3D_FEATURE_LEVEL_10_0,
-#if !defined(ANGLE_ENABLE_D3D9)
- D3D_FEATURE_LEVEL_9_3,
- D3D_FEATURE_LEVEL_9_2,
- D3D_FEATURE_LEVEL_9_1,
-#endif
- };
-
- D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_HARDWARE;
- if (mRequestedDisplay == EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE)
- {
- driverType = D3D_DRIVER_TYPE_WARP;
- }
-
HRESULT result = S_OK;
-
#ifdef _DEBUG
result = D3D11CreateDevice(NULL,
- driverType,
+ mDriverType,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
- featureLevels,
- ArraySize(featureLevels),
+ mAvailableFeatureLevels.data(),
+ mAvailableFeatureLevels.size(),
D3D11_SDK_VERSION,
&mDevice,
&mFeatureLevel,
@@ -198,11 +240,11 @@ EGLint Renderer11::initialize()
#endif
{
result = D3D11CreateDevice(NULL,
- driverType,
+ mDriverType,
NULL,
0,
- featureLevels,
- ArraySize(featureLevels),
+ mAvailableFeatureLevels.data(),
+ mAvailableFeatureLevels.size(),
D3D11_SDK_VERSION,
&mDevice,
&mFeatureLevel,
@@ -215,7 +257,18 @@ EGLint Renderer11::initialize()
}
}
-#if !ANGLE_SKIP_DXGI_1_2_CHECK && !defined(ANGLE_PLATFORM_WINRT)
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
+ static wchar_t *qt_d3dcreate_multihreaded_var = _wgetenv(L"QT_D3DCREATE_MULTITHREADED");
+ if (qt_d3dcreate_multihreaded_var && wcsstr(qt_d3dcreate_multihreaded_var, L"1"))
+ {
+ ID3D10Multithread *multithread;
+ result = mDevice->QueryInterface(IID_PPV_ARGS(&multithread));
+ ASSERT(SUCCEEDED(result));
+ result = multithread->SetMultithreadProtected(true);
+ ASSERT(SUCCEEDED(result));
+ multithread->Release();
+ }
+#if !ANGLE_SKIP_DXGI_1_2_CHECK
// In order to create a swap chain for an HWND owned by another process, DXGI 1.2 is required.
// The easiest way to check is to query for a IDXGIDevice2.
bool requireDXGI1_2 = false;
@@ -244,13 +297,10 @@ EGLint Renderer11::initialize()
SafeRelease(dxgiDevice2);
}
#endif
+#endif
-#if !defined(ANGLE_PLATFORM_WINRT)
IDXGIDevice *dxgiDevice = NULL;
-#else
- IDXGIDevice1 *dxgiDevice = NULL;
-#endif
- result = mDevice->QueryInterface(IID_PPV_ARGS(&dxgiDevice));
+ result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
if (FAILED(result))
{
@@ -281,9 +331,9 @@ EGLint Renderer11::initialize()
}
// Disable some spurious D3D11 debug warnings to prevent them from flooding the output log
-#if !defined(__MINGW32__) && defined(ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS) && defined(_DEBUG)
+#if defined(ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS) && defined(_DEBUG)
ID3D11InfoQueue *infoQueue;
- result = mDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void **)&infoQueue);
+ result = mDevice->QueryInterface(IID_ID3D11InfoQueue, (void **)&infoQueue);
if (SUCCEEDED(result))
{
@@ -301,19 +351,6 @@ EGLint Renderer11::initialize()
}
#endif
-#if !defined(ANGLE_PLATFORM_WINRT)
- static wchar_t *qt_d3dcreate_multihreaded_var = _wgetenv(L"QT_D3DCREATE_MULTITHREADED");
- if (qt_d3dcreate_multihreaded_var && wcsstr(qt_d3dcreate_multihreaded_var, L"1"))
- {
- ID3D10Multithread *multithread;
- result = mDevice->QueryInterface(IID_PPV_ARGS(&multithread));
- ASSERT(SUCCEEDED(result));
- result = multithread->SetMultithreadProtected(true);
- ASSERT(SUCCEEDED(result));
- multithread->Release();
- }
-#endif
-
initializeDevice();
return EGL_SUCCESS;
@@ -394,7 +431,7 @@ void Renderer11::deleteConfigs(ConfigDesc *configDescList)
delete [] (configDescList);
}
-void Renderer11::sync(bool block)
+gl::Error Renderer11::sync(bool block)
{
if (block)
{
@@ -408,6 +445,10 @@ void Renderer11::sync(bool block)
result = mDevice->CreateQuery(&queryDesc, &mSyncQuery);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create event query, result: 0x%X.", result);
+ }
}
mDeviceContext->End(mSyncQuery);
@@ -416,13 +457,17 @@ void Renderer11::sync(bool block)
do
{
result = mDeviceContext->GetData(mSyncQuery, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH);
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to get event query data, result: 0x%X.", result);
+ }
// Keep polling, but allow other threads to do something useful first
Sleep(0);
if (testDeviceLost(true))
{
- return;
+ return gl::Error(GL_OUT_OF_MEMORY, "Device was lost while waiting for sync.");
}
}
while (result == S_FALSE);
@@ -431,22 +476,26 @@ void Renderer11::sync(bool block)
{
mDeviceContext->Flush();
}
+
+ return gl::Error(GL_NO_ERROR);
}
-SwapChain *Renderer11::createSwapChain(EGLNativeWindowType window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat)
+SwapChain *Renderer11::createSwapChain(NativeWindow nativeWindow, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat)
{
- return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat);
+ return new SwapChain11(this, nativeWindow, shareHandle, backBufferFormat, depthBufferFormat);
}
gl::Error Renderer11::generateSwizzle(gl::Texture *texture)
{
if (texture)
{
- TextureStorage *texStorage = texture->getNativeTexture();
+ TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation());
+ ASSERT(textureD3D);
+
+ TextureStorage *texStorage = textureD3D->getNativeTexture();
if (texStorage)
{
TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage);
-
gl::Error error = storage11->generateSwizzles(texture->getSamplerState().swizzleRed,
texture->getSamplerState().swizzleGreen,
texture->getSamplerState().swizzleBlue,
@@ -461,16 +510,21 @@ gl::Error Renderer11::generateSwizzle(gl::Texture *texture)
return gl::Error(GL_NO_ERROR);
}
-gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState)
+gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &samplerStateParam)
{
+ // Make sure to add the level offset for our tiny compressed texture workaround
+ TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation());
+ gl::SamplerState samplerStateInternal = samplerStateParam;
+ samplerStateInternal.baseLevel += textureD3D->getNativeTexture()->getTopLevel();
+
if (type == gl::SAMPLER_PIXEL)
{
ASSERT(static_cast<unsigned int>(index) < getRendererCaps().maxTextureImageUnits);
- if (mForceSetPixelSamplerStates[index] || memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0)
+ if (mForceSetPixelSamplerStates[index] || memcmp(&samplerStateInternal, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{
ID3D11SamplerState *dxSamplerState = NULL;
- gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
+ gl::Error error = mStateCache.getSamplerState(samplerStateInternal, &dxSamplerState);
if (error.isError())
{
return error;
@@ -479,7 +533,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl:
ASSERT(dxSamplerState != NULL);
mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState);
- mCurPixelSamplerStates[index] = samplerState;
+ mCurPixelSamplerStates[index] = samplerStateInternal;
}
mForceSetPixelSamplerStates[index] = false;
@@ -488,10 +542,10 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl:
{
ASSERT(static_cast<unsigned int>(index) < getRendererCaps().maxVertexTextureImageUnits);
- if (mForceSetVertexSamplerStates[index] || memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0)
+ if (mForceSetVertexSamplerStates[index] || memcmp(&samplerStateInternal, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{
ID3D11SamplerState *dxSamplerState = NULL;
- gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
+ gl::Error error = mStateCache.getSamplerState(samplerStateInternal, &dxSamplerState);
if (error.isError())
{
return error;
@@ -500,7 +554,7 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl:
ASSERT(dxSamplerState != NULL);
mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState);
- mCurVertexSamplerStates[index] = samplerState;
+ mCurVertexSamplerStates[index] = samplerStateInternal;
}
mForceSetVertexSamplerStates[index] = false;
@@ -513,50 +567,36 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, int index, const gl:
gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture)
{
ID3D11ShaderResourceView *textureSRV = NULL;
- bool forceSetTexture = false;
if (texture)
{
- TextureD3D* textureImpl = TextureD3D::makeTextureD3D(texture->getImplementation());
+ TextureD3D *textureImpl = TextureD3D::makeTextureD3D(texture->getImplementation());
TextureStorage *texStorage = textureImpl->getNativeTexture();
ASSERT(texStorage != NULL);
TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage);
- gl::SamplerState samplerState;
- texture->getSamplerStateWithNativeOffset(&samplerState);
- textureSRV = storage11->getSRV(samplerState);
+
+ // Make sure to add the level offset for our tiny compressed texture workaround
+ gl::SamplerState samplerState = texture->getSamplerState();
+ samplerState.baseLevel += storage11->getTopLevel();
+
+ gl::Error error = storage11->getSRV(samplerState, &textureSRV);
+ if (error.isError())
+ {
+ return error;
+ }
// If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly
// missing the shader resource view
ASSERT(textureSRV != NULL);
- forceSetTexture = textureImpl->hasDirtyImages();
textureImpl->resetDirty();
}
- if (type == gl::SAMPLER_PIXEL)
- {
- ASSERT(static_cast<unsigned int>(index) < getRendererCaps().maxTextureImageUnits);
-
- if (forceSetTexture || mCurPixelSRVs[index] != textureSRV)
- {
- mDeviceContext->PSSetShaderResources(index, 1, &textureSRV);
- }
-
- mCurPixelSRVs[index] = textureSRV;
- }
- else if (type == gl::SAMPLER_VERTEX)
- {
- ASSERT(static_cast<unsigned int>(index) < getRendererCaps().maxVertexTextureImageUnits);
-
- if (forceSetTexture || mCurVertexSRVs[index] != textureSRV)
- {
- mDeviceContext->VSSetShaderResources(index, 1, &textureSRV);
- }
+ ASSERT((type == gl::SAMPLER_PIXEL && static_cast<unsigned int>(index) < getRendererCaps().maxTextureImageUnits) ||
+ (type == gl::SAMPLER_VERTEX && static_cast<unsigned int>(index) < getRendererCaps().maxVertexTextureImageUnits));
- mCurVertexSRVs[index] = textureSRV;
- }
- else UNREACHABLE();
+ setShaderResource(type, index, textureSRV);
return gl::Error(GL_NO_ERROR);
}
@@ -631,7 +671,7 @@ gl::Error Renderer11::setRasterizerState(const gl::RasterizerState &rasterState)
return gl::Error(GL_NO_ERROR);
}
-gl::Error Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
+gl::Error Renderer11::setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
unsigned int sampleMask)
{
if (mForceSetBlendState ||
@@ -831,7 +871,22 @@ bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count)
return count >= minCount;
}
-gl::Error Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
+void Renderer11::unsetSRVsWithResource(gl::SamplerType samplerType, const ID3D11Resource *resource)
+{
+ std::vector<ID3D11ShaderResourceView *> &currentSRVs = (samplerType == gl::SAMPLER_VERTEX ? mCurVertexSRVs : mCurPixelSRVs);
+
+ for (size_t resourceIndex = 0; resourceIndex < currentSRVs.size(); ++resourceIndex)
+ {
+ ID3D11ShaderResourceView *srv = currentSRVs[resourceIndex];
+
+ if (srv && GetSRVResource(srv) == resource)
+ {
+ setShaderResource(samplerType, static_cast<UINT>(resourceIndex), NULL);
+ }
+ }
+}
+
+gl::Error Renderer11::applyRenderTarget(const gl::Framebuffer *framebuffer)
{
// Get the color render buffer and serial
// Also extract the render target dimensions and view
@@ -842,7 +897,7 @@ gl::Error Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
ID3D11RenderTargetView* framebufferRTVs[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS] = {NULL};
bool missingColorRenderTarget = true;
- const gl::ColorbufferInfo &colorbuffers = framebuffer->getColorbuffersForRender();
+ const gl::ColorbufferInfo &colorbuffers = framebuffer->getColorbuffersForRender(getWorkarounds());
for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment)
{
@@ -863,17 +918,16 @@ gl::Error Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
renderTargetSerials[colorAttachment] = GetAttachmentSerial(colorbuffer);
// Extract the render target dimensions and view
- RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
- if (!renderTarget)
+ RenderTarget11 *renderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(colorbuffer, &renderTarget);
+ if (error.isError())
{
- return gl::Error(GL_OUT_OF_MEMORY, "Internal render target pointer unexpectedly null.");
+ return error;
}
+ ASSERT(renderTarget);
framebufferRTVs[colorAttachment] = renderTarget->getRenderTargetView();
- if (!framebufferRTVs[colorAttachment])
- {
- return gl::Error(GL_OUT_OF_MEMORY, "Internal render target view pointer unexpectedly null.");
- }
+ ASSERT(framebufferRTVs[colorAttachment]);
if (missingColorRenderTarget)
{
@@ -883,8 +937,12 @@ gl::Error Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
missingColorRenderTarget = false;
}
- // TODO: Detect if this color buffer is already bound as a texture and unbind it first to prevent
- // D3D11 warnings.
+#if !defined(NDEBUG)
+ // Unbind render target SRVs from the shader here to prevent D3D11 warnings.
+ ID3D11Resource *renderTargetResource = renderTarget->getTexture();
+ unsetSRVsWithResource(gl::SAMPLER_VERTEX, renderTargetResource);
+ unsetSRVsWithResource(gl::SAMPLER_PIXEL, renderTargetResource);
+#endif
}
}
@@ -905,19 +963,17 @@ gl::Error Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
ID3D11DepthStencilView* framebufferDSV = NULL;
if (depthStencil)
{
- RenderTarget11 *depthStencilRenderTarget = d3d11::GetAttachmentRenderTarget(depthStencil);
- if (!depthStencilRenderTarget)
+ RenderTarget11 *depthStencilRenderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(depthStencil, &depthStencilRenderTarget);
+ if (error.isError())
{
SafeRelease(framebufferRTVs);
- return gl::Error(GL_OUT_OF_MEMORY, "Internal render target pointer unexpectedly null.");
+ return error;
}
+ ASSERT(depthStencilRenderTarget);
framebufferDSV = depthStencilRenderTarget->getDepthStencilView();
- if (!framebufferDSV)
- {
- SafeRelease(framebufferRTVs);
- return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil view pointer unexpectedly null.");
- }
+ ASSERT(framebufferDSV);
// If there is no render buffer, the width, height and format values come from
// the depth stencil
@@ -964,17 +1020,16 @@ gl::Error Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
return gl::Error(GL_NO_ERROR);
}
-gl::Error Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances)
+gl::Error Renderer11::applyVertexBuffer(const gl::State &state, GLint first, GLsizei count, GLsizei instances)
{
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
- gl::Error error = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances);
+ gl::Error error = mVertexDataManager->prepareVertexData(state, first, count, attributes, instances);
if (error.isError())
{
return error;
}
- return mInputLayoutCache.applyVertexBuffers(attributes, programBinary);
+ return mInputLayoutCache.applyVertexBuffers(attributes, state.getCurrentProgramBinary());
}
gl::Error Renderer11::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)
@@ -1011,28 +1066,25 @@ gl::Error Renderer11::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elemen
return gl::Error(GL_NO_ERROR);
}
-void Renderer11::applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[])
+void Renderer11::applyTransformFeedbackBuffers(const gl::State& state)
{
- ID3D11Buffer* d3dBuffers[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS];
- UINT d3dOffsets[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS];
+ size_t numXFBBindings = state.getTransformFeedbackBufferIndexRange();
+ ASSERT(numXFBBindings <= gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS);
+
bool requiresUpdate = false;
- for (size_t i = 0; i < gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS; i++)
+ for (size_t i = 0; i < numXFBBindings; i++)
{
- if (transformFeedbackBuffers[i])
+ gl::Buffer *curXFBBuffer = state.getIndexedTransformFeedbackBuffer(i);
+ GLintptr curXFBOffset = state.getIndexedTransformFeedbackBufferOffset(i);
+ ID3D11Buffer *d3dBuffer = NULL;
+ if (curXFBBuffer)
{
- Buffer11 *storage = Buffer11::makeBuffer11(transformFeedbackBuffers[i]->getImplementation());
- ID3D11Buffer *buffer = storage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK);
-
- d3dBuffers[i] = buffer;
- d3dOffsets[i] = (mAppliedTFBuffers[i] != buffer) ? static_cast<UINT>(offsets[i]) : -1;
- }
- else
- {
- d3dBuffers[i] = NULL;
- d3dOffsets[i] = 0;
+ Buffer11 *storage = Buffer11::makeBuffer11(curXFBBuffer->getImplementation());
+ d3dBuffer = storage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK);
}
- if (d3dBuffers[i] != mAppliedTFBuffers[i] || offsets[i] != mAppliedTFOffsets[i])
+ // TODO: mAppliedTFBuffers and friends should also be kept in a vector.
+ if (d3dBuffer != mAppliedTFBuffers[i] || curXFBOffset != mAppliedTFOffsets[i])
{
requiresUpdate = true;
}
@@ -1040,12 +1092,29 @@ void Renderer11::applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuff
if (requiresUpdate)
{
- mDeviceContext->SOSetTargets(ArraySize(d3dBuffers), d3dBuffers, d3dOffsets);
- for (size_t i = 0; i < gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS; i++)
+ for (size_t i = 0; i < numXFBBindings; ++i)
{
- mAppliedTFBuffers[i] = d3dBuffers[i];
- mAppliedTFOffsets[i] = offsets[i];
+ gl::Buffer *curXFBBuffer = state.getIndexedTransformFeedbackBuffer(i);
+ GLintptr curXFBOffset = state.getIndexedTransformFeedbackBufferOffset(i);
+
+ if (curXFBBuffer)
+ {
+ Buffer11 *storage = Buffer11::makeBuffer11(curXFBBuffer->getImplementation());
+ ID3D11Buffer *d3dBuffer = storage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK);
+
+ mCurrentD3DOffsets[i] = (mAppliedTFBuffers[i] != d3dBuffer && mAppliedTFOffsets[i] != curXFBOffset) ?
+ static_cast<UINT>(curXFBOffset) : -1;
+ mAppliedTFBuffers[i] = d3dBuffer;
+ }
+ else
+ {
+ mAppliedTFBuffers[i] = NULL;
+ mCurrentD3DOffsets[i] = 0;
+ }
+ mAppliedTFOffsets[i] = curXFBOffset;
}
+
+ mDeviceContext->SOSetTargets(numXFBBindings, mAppliedTFBuffers, mCurrentD3DOffsets);
}
}
@@ -1129,7 +1198,6 @@ gl::Error Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, cons
return gl::Error(GL_NO_ERROR);
}
}
-
template<typename T>
static void fillLineLoopIndices(GLenum type, GLsizei count, const GLvoid *indices, T *data)
{
@@ -1213,10 +1281,17 @@ gl::Error Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *ind
// Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer)
{
- gl::Buffer *indexBuffer = elementArrayBuffer;
- BufferImpl *storage = indexBuffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(elementArrayBuffer);
intptr_t offset = reinterpret_cast<intptr_t>(indices);
- indices = static_cast<const GLubyte*>(storage->getData()) + offset;
+
+ const uint8_t *bufferData = NULL;
+ gl::Error error = storage->getData(&bufferData);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ indices = bufferData + offset;
}
// TODO: some level 9 hardware supports 32-bit indices; test and store support instead
@@ -1291,10 +1366,17 @@ gl::Error Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *
// Get the raw indices for an indexed draw
if (type != GL_NONE && elementArrayBuffer)
{
- gl::Buffer *indexBuffer = elementArrayBuffer;
- BufferImpl *storage = indexBuffer->getImplementation();
+ BufferD3D *storage = BufferD3D::makeFromBuffer(elementArrayBuffer);
intptr_t offset = reinterpret_cast<intptr_t>(indices);
- indices = static_cast<const GLubyte*>(storage->getData()) + offset;
+
+ const uint8_t *bufferData = NULL;
+ gl::Error error = storage->getData(&bufferData);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ indices = bufferData + offset;
}
const int indexType = isLevel9() ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
@@ -1376,9 +1458,23 @@ gl::Error Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *
gl::Error Renderer11::applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive)
{
- ShaderExecutable *vertexExe = programBinary->getVertexExecutableForInputLayout(inputLayout);
- ShaderExecutable *pixelExe = programBinary->getPixelExecutableForFramebuffer(framebuffer);
- ShaderExecutable *geometryExe = programBinary->getGeometryExecutable();
+ ProgramD3D *programD3D = ProgramD3D::makeProgramD3D(programBinary->getImplementation());
+
+ ShaderExecutable *vertexExe = NULL;
+ gl::Error error = programD3D->getVertexExecutableForInputLayout(inputLayout, &vertexExe);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ ShaderExecutable *pixelExe = NULL;
+ error = programD3D->getPixelExecutableForFramebuffer(framebuffer, &pixelExe);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ ShaderExecutable *geometryExe = programD3D->getGeometryExecutable();
ID3D11VertexShader *vertexShader = (vertexExe ? ShaderExecutable11::makeShaderExecutable11(vertexExe)->getVertexShader() : NULL);
@@ -1433,16 +1529,14 @@ gl::Error Renderer11::applyShaders(gl::ProgramBinary *programBinary, const gl::V
if (dirtyUniforms)
{
- programBinary->dirtyAllUniforms();
+ programD3D->dirtyAllUniforms();
}
return gl::Error(GL_NO_ERROR);
}
-gl::Error Renderer11::applyUniforms(const gl::ProgramBinary &programBinary)
+gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vector<gl::LinkedUniform*> &uniformArray)
{
- const std::vector<gl::LinkedUniform*> &uniformArray = programBinary.getUniforms();
-
unsigned int totalRegisterCountVS = 0;
unsigned int totalRegisterCountPS = 0;
@@ -1466,7 +1560,7 @@ gl::Error Renderer11::applyUniforms(const gl::ProgramBinary &programBinary)
}
}
- const ProgramD3D *programD3D = ProgramD3D::makeProgramD3D(programBinary.getImplementation());
+ const ProgramD3D *programD3D = ProgramD3D::makeProgramD3D(&program);
const UniformStorage11 *vertexUniformStorage = UniformStorage11::makeUniformStorage11(&programD3D->getVertexUniformStorage());
const UniformStorage11 *fragmentUniformStorage = UniformStorage11::makeUniformStorage11(&programD3D->getFragmentUniformStorage());
ASSERT(vertexUniformStorage);
@@ -1598,7 +1692,7 @@ gl::Error Renderer11::applyUniforms(const gl::ProgramBinary &programBinary)
return gl::Error(GL_NO_ERROR);
}
-gl::Error Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer)
+gl::Error Renderer11::clear(const gl::ClearParameters &clearParams, const gl::Framebuffer *frameBuffer)
{
gl::Error error = mClear->clearFramebuffer(clearParams, frameBuffer);
if (error.isError())
@@ -1626,14 +1720,12 @@ void Renderer11::markAllStateDirty()
for (size_t vsamplerId = 0; vsamplerId < mForceSetVertexSamplerStates.size(); ++vsamplerId)
{
mForceSetVertexSamplerStates[vsamplerId] = true;
- mCurVertexSRVs[vsamplerId] = NULL;
}
ASSERT(mForceSetPixelSamplerStates.size() == mCurPixelSRVs.size());
for (size_t fsamplerId = 0; fsamplerId < mForceSetPixelSamplerStates.size(); ++fsamplerId)
{
mForceSetPixelSamplerStates[fsamplerId] = true;
- mCurPixelSRVs[fsamplerId] = NULL;
}
mForceSetBlendState = true;
@@ -1746,32 +1838,20 @@ bool Renderer11::testDeviceResettable()
return false;
}
- D3D_FEATURE_LEVEL featureLevels[] =
- {
- D3D_FEATURE_LEVEL_11_0,
- D3D_FEATURE_LEVEL_10_1,
- D3D_FEATURE_LEVEL_10_0,
-#if !defined(ANGLE_ENABLE_D3D9)
- D3D_FEATURE_LEVEL_9_3,
- D3D_FEATURE_LEVEL_9_2,
- D3D_FEATURE_LEVEL_9_1,
-#endif
- };
-
ID3D11Device* dummyDevice;
D3D_FEATURE_LEVEL dummyFeatureLevel;
ID3D11DeviceContext* dummyContext;
HRESULT result = D3D11CreateDevice(NULL,
- D3D_DRIVER_TYPE_HARDWARE,
+ mDriverType,
NULL,
#if defined(_DEBUG)
D3D11_CREATE_DEVICE_DEBUG,
#else
0,
#endif
- featureLevels,
- ArraySize(featureLevels),
+ mAvailableFeatureLevels.data(),
+ mAvailableFeatureLevels.size(),
D3D11_SDK_VERSION,
&dummyDevice,
&dummyFeatureLevel,
@@ -1939,119 +2019,37 @@ int Renderer11::getMaxSwapInterval() const
return 4;
}
-bool Renderer11::copyToRenderTarget2D(TextureStorage *dest, TextureStorage *source)
-{
- if (source && dest)
- {
- TextureStorage11_2D *source11 = TextureStorage11_2D::makeTextureStorage11_2D(source);
- TextureStorage11_2D *dest11 = TextureStorage11_2D::makeTextureStorage11_2D(dest);
-
- mDeviceContext->CopyResource(dest11->getResource(), source11->getResource());
-
- dest11->invalidateSwizzleCache();
-
- return true;
- }
-
- return false;
-}
-
-bool Renderer11::copyToRenderTargetCube(TextureStorage *dest, TextureStorage *source)
-{
- if (source && dest)
- {
- TextureStorage11_Cube *source11 = TextureStorage11_Cube::makeTextureStorage11_Cube(source);
- TextureStorage11_Cube *dest11 = TextureStorage11_Cube::makeTextureStorage11_Cube(dest);
-
- mDeviceContext->CopyResource(dest11->getResource(), source11->getResource());
-
- dest11->invalidateSwizzleCache();
-
- return true;
- }
-
- return false;
-}
-
-bool Renderer11::copyToRenderTarget3D(TextureStorage *dest, TextureStorage *source)
-{
- if (source && dest)
- {
- TextureStorage11_3D *source11 = TextureStorage11_3D::makeTextureStorage11_3D(source);
- TextureStorage11_3D *dest11 = TextureStorage11_3D::makeTextureStorage11_3D(dest);
-
- mDeviceContext->CopyResource(dest11->getResource(), source11->getResource());
-
- dest11->invalidateSwizzleCache();
-
- return true;
- }
-
- return false;
-}
-
-bool Renderer11::copyToRenderTarget2DArray(TextureStorage *dest, TextureStorage *source)
-{
- if (source && dest)
- {
- TextureStorage11_2DArray *source11 = TextureStorage11_2DArray::makeTextureStorage11_2DArray(source);
- TextureStorage11_2DArray *dest11 = TextureStorage11_2DArray::makeTextureStorage11_2DArray(dest);
-
- mDeviceContext->CopyResource(dest11->getResource(), source11->getResource());
-
- dest11->invalidateSwizzleCache();
-
- return true;
- }
-
- return false;
-}
-
-bool Renderer11::copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level)
+gl::Error Renderer11::copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level)
{
gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer();
- if (!colorbuffer)
- {
- ERR("Failed to retrieve the color buffer from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(colorbuffer);
- RenderTarget11 *sourceRenderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
- if (!sourceRenderTarget)
+ RenderTarget11 *sourceRenderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(colorbuffer, &sourceRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the render target from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(sourceRenderTarget);
ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView();
- if (!source)
- {
- ERR("Failed to retrieve the render target view from the render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(source);
TextureStorage11_2D *storage11 = TextureStorage11_2D::makeTextureStorage11_2D(storage);
- if (!storage11)
- {
- ERR("Failed to retrieve the texture storage from the destination.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(storage11);
gl::ImageIndex index = gl::ImageIndex::Make2D(level);
- RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTarget(index));
- if (!destRenderTarget)
+ RenderTarget *destRenderTarget = NULL;
+ error = storage11->getRenderTarget(index, &destRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the render target from the destination storage.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(destRenderTarget);
- ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView();
- if (!dest)
- {
- ERR("Failed to retrieve the render target view from the destination render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ID3D11RenderTargetView *dest = RenderTarget11::makeRenderTarget11(destRenderTarget)->getRenderTargetView();
+ ASSERT(dest);
gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1);
gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1);
@@ -2061,59 +2059,48 @@ bool Renderer11::copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &
// Use nearest filtering because source and destination are the same size for the direct
// copy
- bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL,
- destFormat, GL_NEAREST);
+ mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, destFormat, GL_NEAREST);
+ if (error.isError())
+ {
+ return error;
+ }
storage11->invalidateSwizzleCacheLevel(level);
- return ret;
+ return gl::Error(GL_NO_ERROR);
}
-bool Renderer11::copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level)
+gl::Error Renderer11::copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level)
{
gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer();
- if (!colorbuffer)
- {
- ERR("Failed to retrieve the color buffer from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(colorbuffer);
- RenderTarget11 *sourceRenderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
- if (!sourceRenderTarget)
+ RenderTarget11 *sourceRenderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(colorbuffer, &sourceRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the render target from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(sourceRenderTarget);
ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView();
- if (!source)
- {
- ERR("Failed to retrieve the render target view from the render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(source);
TextureStorage11_Cube *storage11 = TextureStorage11_Cube::makeTextureStorage11_Cube(storage);
- if (!storage11)
- {
- ERR("Failed to retrieve the texture storage from the destination.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(storage11);
gl::ImageIndex index = gl::ImageIndex::MakeCube(target, level);
- RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTarget(index));
- if (!destRenderTarget)
+ RenderTarget *destRenderTarget = NULL;
+ error = storage11->getRenderTarget(index, &destRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the render target from the destination storage.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(destRenderTarget);
- ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView();
- if (!dest)
- {
- ERR("Failed to retrieve the render target view from the destination render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ID3D11RenderTargetView *dest = RenderTarget11::makeRenderTarget11(destRenderTarget)->getRenderTargetView();
+ ASSERT(dest);
gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1);
gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1);
@@ -2123,59 +2110,48 @@ bool Renderer11::copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle
// Use nearest filtering because source and destination are the same size for the direct
// copy
- bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL,
- destFormat, GL_NEAREST);
+ error = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, destFormat, GL_NEAREST);
+ if (error.isError())
+ {
+ return error;
+ }
storage11->invalidateSwizzleCacheLevel(level);
- return ret;
+ return gl::Error(GL_NO_ERROR);
}
-bool Renderer11::copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level)
+gl::Error Renderer11::copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level)
{
gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer();
- if (!colorbuffer)
- {
- ERR("Failed to retrieve the color buffer from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(colorbuffer);
- RenderTarget11 *sourceRenderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
- if (!sourceRenderTarget)
+ RenderTarget11 *sourceRenderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(colorbuffer, &sourceRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the render target from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(sourceRenderTarget);
ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView();
- if (!source)
- {
- ERR("Failed to retrieve the render target view from the render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(source);
TextureStorage11_3D *storage11 = TextureStorage11_3D::makeTextureStorage11_3D(storage);
- if (!storage11)
- {
- ERR("Failed to retrieve the texture storage from the destination.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(storage11);
gl::ImageIndex index = gl::ImageIndex::Make3D(level, zOffset);
- RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTarget(index));
- if (!destRenderTarget)
+ RenderTarget *destRenderTarget = NULL;
+ error = storage11->getRenderTarget(index, &destRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the render target from the destination storage.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(destRenderTarget);
- ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView();
- if (!dest)
- {
- ERR("Failed to retrieve the render target view from the destination render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ID3D11RenderTargetView *dest = RenderTarget11::makeRenderTarget11(destRenderTarget)->getRenderTargetView();
+ ASSERT(dest);
gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1);
gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1);
@@ -2185,61 +2161,48 @@ bool Renderer11::copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &
// Use nearest filtering because source and destination are the same size for the direct
// copy
- bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL,
- destFormat, GL_NEAREST);
+ error = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, destFormat, GL_NEAREST);
+ if (error.isError())
+ {
+ return error;
+ }
storage11->invalidateSwizzleCacheLevel(level);
- return ret;
+ return gl::Error(GL_NO_ERROR);
}
-bool Renderer11::copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level)
+gl::Error Renderer11::copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level)
{
gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer();
- if (!colorbuffer)
- {
- ERR("Failed to retrieve the color buffer from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(colorbuffer);
- RenderTarget11 *sourceRenderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
- if (!sourceRenderTarget)
+ RenderTarget11 *sourceRenderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(colorbuffer, &sourceRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the render target from the frame buffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(sourceRenderTarget);
ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView();
- if (!source)
- {
- ERR("Failed to retrieve the render target view from the render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(source);
TextureStorage11_2DArray *storage11 = TextureStorage11_2DArray::makeTextureStorage11_2DArray(storage);
- if (!storage11)
- {
- SafeRelease(source);
- ERR("Failed to retrieve the texture storage from the destination.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ASSERT(storage11);
gl::ImageIndex index = gl::ImageIndex::Make2DArray(level, zOffset);
- RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTarget(index));
- if (!destRenderTarget)
+ RenderTarget *destRenderTarget = NULL;
+ error = storage11->getRenderTarget(index, &destRenderTarget);
+ if (error.isError())
{
- SafeRelease(source);
- ERR("Failed to retrieve the render target from the destination storage.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(destRenderTarget);
- ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView();
- if (!dest)
- {
- ERR("Failed to retrieve the render target view from the destination render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
- }
+ ID3D11RenderTargetView *dest = RenderTarget11::makeRenderTarget11(destRenderTarget)->getRenderTargetView();
+ ASSERT(dest);
gl::Box sourceArea(sourceRect.x, sourceRect.y, 0, sourceRect.width, sourceRect.height, 1);
gl::Extents sourceSize(sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), 1);
@@ -2249,12 +2212,15 @@ bool Renderer11::copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectan
// Use nearest filtering because source and destination are the same size for the direct
// copy
- bool ret = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL,
- destFormat, GL_NEAREST);
+ error = mBlit->copyTexture(source, sourceArea, sourceSize, dest, destArea, destSize, NULL, destFormat, GL_NEAREST);
+ if (error.isError())
+ {
+ return error;
+ }
storage11->invalidateSwizzleCacheLevel(level);
- return ret;
+ return gl::Error(GL_NO_ERROR);
}
void Renderer11::unapplyRenderTargets()
@@ -2277,39 +2243,150 @@ void Renderer11::setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView
}
}
-RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth)
+gl::Error Renderer11::createRenderTarget(SwapChain *swapChain, bool depth, RenderTarget **outRT)
{
SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain);
- RenderTarget11 *renderTarget = NULL;
+ *outRT = new SurfaceRenderTarget11(swapChain11, depth);
+ return gl::Error(GL_NO_ERROR);
+}
+
+gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT)
+{
+ const d3d11::TextureFormat &formatInfo = d3d11::GetTextureFormatInfo(format);
- if (depth)
+ const gl::TextureCaps &textureCaps = getRendererTextureCaps().get(format);
+ GLuint supportedSamples = textureCaps.getNearestSamples(samples);
+
+ if (width > 0 && height > 0)
{
- // Note: depth stencil may be NULL for 0 sized surfaces
- renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(),
- swapChain11->getDepthStencilTexture(),
- swapChain11->getDepthStencilShaderResource(),
- swapChain11->getWidth(), swapChain11->getHeight(), 1);
+ // Create texture resource
+ D3D11_TEXTURE2D_DESC desc;
+ desc.Width = width;
+ desc.Height = height;
+ desc.MipLevels = 1;
+ desc.ArraySize = 1;
+ desc.Format = formatInfo.texFormat;
+ desc.SampleDesc.Count = (supportedSamples == 0) ? 1 : supportedSamples;
+ desc.SampleDesc.Quality = 0;
+ desc.Usage = D3D11_USAGE_DEFAULT;
+ desc.CPUAccessFlags = 0;
+ desc.MiscFlags = 0;
+
+ // If a rendertarget or depthstencil format exists for this texture format,
+ // we'll flag it to allow binding that way. Shader resource views are a little
+ // more complicated.
+ bool bindRTV = false, bindDSV = false, bindSRV = false;
+ bindRTV = (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN);
+ bindDSV = (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN);
+ if (formatInfo.srvFormat != DXGI_FORMAT_UNKNOWN)
+ {
+ // Multisample targets flagged for binding as depth stencil cannot also be
+ // flagged for binding as SRV, so make certain not to add the SRV flag for
+ // these targets.
+ bindSRV = !(formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN && desc.SampleDesc.Count > 1);
+ }
+
+ desc.BindFlags = (bindRTV ? D3D11_BIND_RENDER_TARGET : 0) |
+ (bindDSV ? D3D11_BIND_DEPTH_STENCIL : 0) |
+ (bindSRV ? D3D11_BIND_SHADER_RESOURCE : 0);
+
+ // The format must be either an RTV or a DSV
+ ASSERT(bindRTV != bindDSV);
+
+ ID3D11Texture2D *texture = NULL;
+ HRESULT result = mDevice->CreateTexture2D(&desc, NULL, &texture);
+ if (FAILED(result))
+ {
+ ASSERT(result == E_OUTOFMEMORY);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target texture, result: 0x%X.", result);
+ }
+
+ ID3D11ShaderResourceView *srv = NULL;
+ if (bindSRV)
+ {
+ D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
+ srvDesc.Format = formatInfo.srvFormat;
+ srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS;
+ srvDesc.Texture2D.MostDetailedMip = 0;
+ srvDesc.Texture2D.MipLevels = 1;
+
+ result = mDevice->CreateShaderResourceView(texture, &srvDesc, &srv);
+ if (FAILED(result))
+ {
+ ASSERT(result == E_OUTOFMEMORY);
+ SafeRelease(texture);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target shader resource view, result: 0x%X.", result);
+ }
+ }
+
+ if (bindDSV)
+ {
+ D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
+ dsvDesc.Format = formatInfo.dsvFormat;
+ dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS;
+ dsvDesc.Texture2D.MipSlice = 0;
+ dsvDesc.Flags = 0;
+
+ ID3D11DepthStencilView *dsv = NULL;
+ result = mDevice->CreateDepthStencilView(texture, &dsvDesc, &dsv);
+ if (FAILED(result))
+ {
+ ASSERT(result == E_OUTOFMEMORY);
+ SafeRelease(texture);
+ SafeRelease(srv);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target depth stencil view, result: 0x%X.", result);
+ }
+
+ *outRT = new TextureRenderTarget11(dsv, texture, srv, format, width, height, 1, supportedSamples);
+
+ SafeRelease(dsv);
+ }
+ else if (bindRTV)
+ {
+ D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
+ rtvDesc.Format = formatInfo.rtvFormat;
+ rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS;
+ rtvDesc.Texture2D.MipSlice = 0;
+
+ ID3D11RenderTargetView *rtv = NULL;
+ result = mDevice->CreateRenderTargetView(texture, &rtvDesc, &rtv);
+ if (FAILED(result))
+ {
+ ASSERT(result == E_OUTOFMEMORY);
+ SafeRelease(texture);
+ SafeRelease(srv);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target render target view, result: 0x%X.", result);
+ }
+
+ if (formatInfo.dataInitializerFunction != NULL)
+ {
+ const float clearValues[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ mDeviceContext->ClearRenderTargetView(rtv, clearValues);
+ }
+
+ *outRT = new TextureRenderTarget11(rtv, texture, srv, format, width, height, 1, supportedSamples);
+
+ SafeRelease(rtv);
+ }
+ else
+ {
+ UNREACHABLE();
+ }
+
+ SafeRelease(texture);
+ SafeRelease(srv);
}
else
{
- // Note: render target may be NULL for 0 sized surfaces
- renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(),
- swapChain11->getOffscreenTexture(),
- swapChain11->getRenderTargetShaderResource(),
- swapChain11->getWidth(), swapChain11->getHeight(), 1);
+ *outRT = new TextureRenderTarget11(reinterpret_cast<ID3D11RenderTargetView*>(NULL), NULL, NULL, format, width, height, 1, supportedSamples);
}
- return renderTarget;
-}
-RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples)
-{
- RenderTarget11 *renderTarget = new RenderTarget11(this, width, height, format, samples);
- return renderTarget;
+ return gl::Error(GL_NO_ERROR);
}
-ShaderImpl *Renderer11::createShader(GLenum type)
+ShaderImpl *Renderer11::createShader(const gl::Data &data, GLenum type)
{
- return new ShaderD3D(type, this);
+ return new ShaderD3D(data, type, this);
}
ProgramImpl *Renderer11::createProgram()
@@ -2322,22 +2399,23 @@ void Renderer11::releaseShaderCompiler()
ShaderD3D::releaseCompiler();
}
-ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, rx::ShaderType type,
- const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
- bool separatedOutputBuffers)
+gl::Error Renderer11::loadExecutable(const void *function, size_t length, ShaderType type,
+ const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
+ bool separatedOutputBuffers, ShaderExecutable **outExecutable)
{
- ShaderExecutable11 *executable = NULL;
- HRESULT result;
-
switch (type)
{
- case rx::SHADER_VERTEX:
+ case SHADER_VERTEX:
{
ID3D11VertexShader *vertexShader = NULL;
ID3D11GeometryShader *streamOutShader = NULL;
- result = mDevice->CreateVertexShader(function, length, NULL, &vertexShader);
+ HRESULT result = mDevice->CreateVertexShader(function, length, NULL, &vertexShader);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create vertex shader, result: 0x%X.", result);
+ }
if (transformFeedbackVaryings.size() > 0)
{
@@ -2363,99 +2441,116 @@ ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length
result = mDevice->CreateGeometryShaderWithStreamOutput(function, length, soDeclaration.data(), soDeclaration.size(),
NULL, 0, 0, NULL, &streamOutShader);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create steam output shader, result: 0x%X.", result);
+ }
}
- if (vertexShader)
- {
- executable = new ShaderExecutable11(function, length, vertexShader, streamOutShader);
- }
+ *outExecutable = new ShaderExecutable11(function, length, vertexShader, streamOutShader);
}
break;
- case rx::SHADER_PIXEL:
+ case SHADER_PIXEL:
{
ID3D11PixelShader *pixelShader = NULL;
- result = mDevice->CreatePixelShader(function, length, NULL, &pixelShader);
+ HRESULT result = mDevice->CreatePixelShader(function, length, NULL, &pixelShader);
ASSERT(SUCCEEDED(result));
-
- if (pixelShader)
+ if (FAILED(result))
{
- executable = new ShaderExecutable11(function, length, pixelShader);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create pixel shader, result: 0x%X.", result);
}
+
+ *outExecutable = new ShaderExecutable11(function, length, pixelShader);
}
break;
- case rx::SHADER_GEOMETRY:
+ case SHADER_GEOMETRY:
{
ID3D11GeometryShader *geometryShader = NULL;
- result = mDevice->CreateGeometryShader(function, length, NULL, &geometryShader);
+ HRESULT result = mDevice->CreateGeometryShader(function, length, NULL, &geometryShader);
ASSERT(SUCCEEDED(result));
-
- if (geometryShader)
+ if (FAILED(result))
{
- executable = new ShaderExecutable11(function, length, geometryShader);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create geometry shader, result: 0x%X.", result);
}
+
+ *outExecutable = new ShaderExecutable11(function, length, geometryShader);
}
break;
default:
UNREACHABLE();
- break;
+ return gl::Error(GL_INVALID_OPERATION);
}
- return executable;
+ return gl::Error(GL_NO_ERROR);
}
-ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type,
- const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
- bool separatedOutputBuffers, D3DWorkaroundType workaround)
+gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog, const std::string &shaderHLSL, ShaderType type,
+ const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
+ bool separatedOutputBuffers, D3DWorkaroundType workaround,
+ ShaderExecutable **outExectuable)
{
const char *profileType = NULL;
switch (type)
{
- case rx::SHADER_VERTEX:
+ case SHADER_VERTEX:
profileType = "vs";
break;
- case rx::SHADER_PIXEL:
+ case SHADER_PIXEL:
profileType = "ps";
break;
- case rx::SHADER_GEOMETRY:
+ case SHADER_GEOMETRY:
profileType = "gs";
break;
default:
UNREACHABLE();
- return NULL;
+ return gl::Error(GL_INVALID_OPERATION);
}
- const char *profileVersion = NULL;
+ unsigned int profileMajorVersion = 0;
+ unsigned int profileMinorVersion = 0;
+ const char *profileSuffix = NULL;
switch (mFeatureLevel)
{
case D3D_FEATURE_LEVEL_11_0:
- profileVersion = "5_0";
+ profileMajorVersion = 5;
+ profileMinorVersion = 0;
break;
case D3D_FEATURE_LEVEL_10_1:
- profileVersion = "4_1";
+ profileMajorVersion = 4;
+ profileMinorVersion = 1;
break;
case D3D_FEATURE_LEVEL_10_0:
- profileVersion = "4_0";
+ profileMajorVersion = 4;
+ profileMinorVersion = 0;
break;
case D3D_FEATURE_LEVEL_9_3:
- profileVersion = "4_0_level_9_3";
+ profileMajorVersion = 4;
+ profileMinorVersion = 0;
+ profileSuffix = "_level_9_3";
break;
case D3D_FEATURE_LEVEL_9_2:
- profileVersion = "4_0_level_9_2";
+ profileMajorVersion = 4;
+ profileMinorVersion = 0;
+ profileSuffix = "_level_9_2";
break;
case D3D_FEATURE_LEVEL_9_1:
- profileVersion = "4_0_level_9_1";
+ profileMajorVersion = 4;
+ profileMinorVersion = 0;
+ profileSuffix = "_level_9_1";
break;
+ break;
default:
UNREACHABLE();
- return NULL;
+ return gl::Error(GL_INVALID_OPERATION);
}
- char profile[32];
- snprintf(profile, ArraySize(profile), "%s_%s", profileType, profileVersion);
+ std::string profile = FormatString("%s_%u_%u", profileType, profileMajorVersion, profileMinorVersion);
+ if (profileSuffix)
+ profile += profileSuffix;
- UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL0;
+ UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL2;
if (gl::perfActive())
{
@@ -2464,44 +2559,51 @@ ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const ch
#endif
flags |= D3DCOMPILE_DEBUG;
-
- std::string sourcePath = getTempPath();
- std::string sourceText = std::string("#line 2 \"") + sourcePath + std::string("\"\n\n") + std::string(shaderHLSL);
- writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size());
}
// Sometimes D3DCompile will fail with the default compilation flags for complicated shaders when it would otherwise pass with alternative options.
// Try the default flags first and if compilation fails, try some alternatives.
- const UINT extraFlags[] =
- {
- flags,
- flags | D3DCOMPILE_SKIP_VALIDATION,
- flags | D3DCOMPILE_SKIP_OPTIMIZATION
- };
+ std::vector<CompileConfig> configs;
+ configs.push_back(CompileConfig(flags, "default" ));
+ configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_VALIDATION, "skip validation" ));
+ configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_OPTIMIZATION, "skip optimization"));
- const static char *extraFlagNames[] =
- {
- "default",
- "skip validation",
- "skip optimization"
- };
+ D3D_SHADER_MACRO loopMacros[] = { {"ANGLE_ENABLE_LOOP_FLATTEN", "1"}, {0, 0} };
- int attempts = ArraySize(extraFlags);
+ ID3DBlob *binary = NULL;
+ std::string debugInfo;
+ gl::Error error = mCompiler.compileToBinary(infoLog, shaderHLSL, profile, configs, loopMacros, &binary, &debugInfo);
+ if (error.isError())
+ {
+ return error;
+ }
- ID3DBlob *binary = (ID3DBlob*)mCompiler.compileToBinary(infoLog, shaderHLSL, profile, extraFlags, extraFlagNames, attempts);
+ // It's possible that binary is NULL if the compiler failed in all configurations. Set the executable to NULL
+ // and return GL_NO_ERROR to signify that there was a link error but the internal state is still OK.
if (!binary)
{
- return NULL;
+ *outExectuable = NULL;
+ return gl::Error(GL_NO_ERROR);
}
- ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type,
- transformFeedbackVaryings, separatedOutputBuffers);
+ error = loadExecutable(binary->GetBufferPointer(), binary->GetBufferSize(), type,
+ transformFeedbackVaryings, separatedOutputBuffers, outExectuable);
+
SafeRelease(binary);
+ if (error.isError())
+ {
+ return error;
+ }
+
+ if (!debugInfo.empty())
+ {
+ (*outExectuable)->appendDebugInfo(debugInfo);
+ }
- return executable;
+ return gl::Error(GL_NO_ERROR);
}
-rx::UniformStorage *Renderer11::createUniformStorage(size_t storageSize)
+UniformStorage *Renderer11::createUniformStorage(size_t storageSize)
{
return new UniformStorage11(this, storageSize);
}
@@ -2531,9 +2633,14 @@ QueryImpl *Renderer11::createQuery(GLenum type)
return new Query11(this, type);
}
-FenceImpl *Renderer11::createFence()
+FenceNVImpl *Renderer11::createFenceNV()
{
- return new Fence11(this);
+ return new FenceNV11(this);
+}
+
+FenceSyncImpl *Renderer11::createFenceSync()
+{
+ return new FenceSync11(this);
}
TransformFeedbackImpl* Renderer11::createTransformFeedback()
@@ -2576,82 +2683,77 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
return true;
}
-bool Renderer11::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
- GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
+gl::Error Renderer11::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
+ GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
{
ASSERT(supportsFastCopyBufferToTexture(destinationFormat));
return mPixelTransfer->copyBufferToTexture(unpack, offset, destRenderTarget, destinationFormat, sourcePixelsType, destArea);
}
-bool Renderer11::getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndex, ID3D11Texture2D **resource)
+gl::Error Renderer11::getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndexOut, ID3D11Texture2D **texture2DOut)
+
{
- ASSERT(colorbuffer != NULL);
+ ASSERT(colorbuffer);
- RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
- if (renderTarget)
+ RenderTarget11 *renderTarget = NULL;
+ gl::Error error = d3d11::GetAttachmentRenderTarget(colorbuffer, &renderTarget);
+ if (error.isError())
{
- *subresourceIndex = renderTarget->getSubresourceIndex();
+ return error;
+ }
- ID3D11RenderTargetView *colorBufferRTV = renderTarget->getRenderTargetView();
- if (colorBufferRTV)
- {
- ID3D11Resource *textureResource = NULL;
- colorBufferRTV->GetResource(&textureResource);
+ ID3D11Resource *renderTargetResource = renderTarget->getTexture();
+ ASSERT(renderTargetResource);
- if (textureResource)
- {
- HRESULT result = textureResource->QueryInterface(__uuidof(ID3D11Texture2D), (void**)resource);
- SafeRelease(textureResource);
+ *subresourceIndexOut = renderTarget->getSubresourceIndex();
+ *texture2DOut = d3d11::DynamicCastComObject<ID3D11Texture2D>(renderTargetResource);
- if (SUCCEEDED(result))
- {
- return true;
- }
- else
- {
- ERR("Failed to extract the ID3D11Texture2D from the render target resource, "
- "HRESULT: 0x%X.", result);
- }
- }
- }
+ if (!(*texture2DOut))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to query the ID3D11Texture2D from a RenderTarget");
}
- return false;
+ return gl::Error(GL_NO_ERROR);
}
-bool Renderer11::blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
- const gl::Rectangle *scissor, bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter)
+gl::Error Renderer11::blitRect(const gl::Framebuffer *readTarget, const gl::Rectangle &readRect,
+ const gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
+ const gl::Rectangle *scissor, bool blitRenderTarget,
+ bool blitDepth, bool blitStencil, GLenum filter)
{
if (blitRenderTarget)
{
gl::FramebufferAttachment *readBuffer = readTarget->getReadColorbuffer();
+ ASSERT(readBuffer);
- if (!readBuffer)
+ RenderTarget *readRenderTarget = NULL;
+ gl::Error error = GetAttachmentRenderTarget(readBuffer, &readRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the read buffer from the read framebuffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
-
- RenderTarget *readRenderTarget = GetAttachmentRenderTarget(readBuffer);
+ ASSERT(readRenderTarget);
for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
{
if (drawTarget->isEnabledColorAttachment(colorAttachment))
{
gl::FramebufferAttachment *drawBuffer = drawTarget->getColorbuffer(colorAttachment);
+ ASSERT(drawBuffer);
- if (!drawBuffer)
+ RenderTarget *drawRenderTarget = NULL;
+ error = GetAttachmentRenderTarget(drawBuffer, &drawRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the draw buffer from the draw framebuffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(drawRenderTarget);
- RenderTarget *drawRenderTarget = GetAttachmentRenderTarget(drawBuffer);
-
- if (!blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, filter, scissor,
- blitRenderTarget, false, false))
+ error = blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, filter, scissor, blitRenderTarget,
+ false, false);
+ if (error.isError())
{
- return false;
+ return error;
}
}
}
@@ -2660,78 +2762,88 @@ bool Renderer11::blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &read
if (blitDepth || blitStencil)
{
gl::FramebufferAttachment *readBuffer = readTarget->getDepthOrStencilbuffer();
- gl::FramebufferAttachment *drawBuffer = drawTarget->getDepthOrStencilbuffer();
+ ASSERT(readBuffer);
- if (!readBuffer)
+ RenderTarget *readRenderTarget = NULL;
+ gl::Error error = GetAttachmentRenderTarget(readBuffer, &readRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the read depth-stencil buffer from the read framebuffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(readRenderTarget);
- if (!drawBuffer)
+ gl::FramebufferAttachment *drawBuffer = drawTarget->getDepthOrStencilbuffer();
+ ASSERT(drawBuffer);
+
+ RenderTarget *drawRenderTarget = NULL;
+ error = GetAttachmentRenderTarget(drawBuffer, &drawRenderTarget);
+ if (error.isError())
{
- ERR("Failed to retrieve the draw depth-stencil buffer from the draw framebuffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return error;
}
+ ASSERT(drawRenderTarget);
- RenderTarget *readRenderTarget = GetAttachmentRenderTarget(readBuffer);
- RenderTarget *drawRenderTarget = GetAttachmentRenderTarget(drawBuffer);
- ASSERT(readRenderTarget && drawRenderTarget);
-
- if (!blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, filter, scissor,
- false, blitDepth, blitStencil))
+ error = blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, filter, scissor, false,
+ blitDepth, blitStencil);
+ if (error.isError())
{
- return false;
+ return error;
}
}
invalidateFramebufferSwizzles(drawTarget);
- return true;
+ return gl::Error(GL_NO_ERROR);
}
-gl::Error Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
+gl::Error Renderer11::readPixels(const gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels)
{
ID3D11Texture2D *colorBufferTexture = NULL;
unsigned int subresourceIndex = 0;
gl::FramebufferAttachment *colorbuffer = framebuffer->getReadColorbuffer();
+ ASSERT(colorbuffer);
- if (colorbuffer && getRenderTargetResource(colorbuffer, &subresourceIndex, &colorBufferTexture))
+ gl::Error error = getRenderTargetResource(colorbuffer, &subresourceIndex, &colorBufferTexture);
+ if (error.isError())
{
- gl::Rectangle area;
- area.x = x;
- area.y = y;
- area.width = width;
- area.height = height;
+ return error;
+ }
- gl::Buffer *packBuffer = pack.pixelBuffer.get();
- if (packBuffer != NULL)
- {
- rx::Buffer11 *packBufferStorage = Buffer11::makeBuffer11(packBuffer->getImplementation());
- PackPixelsParams packParams(area, format, type, outputPitch, pack, reinterpret_cast<ptrdiff_t>(pixels));
+ gl::Rectangle area;
+ area.x = x;
+ area.y = y;
+ area.width = width;
+ area.height = height;
- gl::Error error = packBufferStorage->packPixels(colorBufferTexture, subresourceIndex, packParams);
- if (error.isError())
- {
- return error;
- }
+ gl::Buffer *packBuffer = pack.pixelBuffer.get();
+ if (packBuffer != NULL)
+ {
+ Buffer11 *packBufferStorage = Buffer11::makeBuffer11(packBuffer->getImplementation());
+ PackPixelsParams packParams(area, format, type, outputPitch, pack, reinterpret_cast<ptrdiff_t>(pixels));
- packBuffer->getIndexRangeCache()->clear();
- }
- else
+ error = packBufferStorage->packPixels(colorBufferTexture, subresourceIndex, packParams);
+ if (error.isError())
{
- gl::Error error = readTextureData(colorBufferTexture, subresourceIndex, area, format, type, outputPitch, pack, pixels);
- if (error.isError())
- {
- return error;
- }
+ SafeRelease(colorBufferTexture);
+ return error;
}
- SafeRelease(colorBufferTexture);
+ packBuffer->getIndexRangeCache()->clear();
+ }
+ else
+ {
+ error = readTextureData(colorBufferTexture, subresourceIndex, area, format, type, outputPitch, pack, pixels);
+ if (error.isError())
+ {
+ SafeRelease(colorBufferTexture);
+ return error;
+ }
}
+ SafeRelease(colorBufferTexture);
+
return gl::Error(GL_NO_ERROR);
}
@@ -2740,11 +2852,11 @@ Image *Renderer11::createImage()
return new Image11();
}
-void Renderer11::generateMipmap(Image *dest, Image *src)
+gl::Error Renderer11::generateMipmap(Image *dest, Image *src)
{
Image11 *dest11 = Image11::makeImage11(dest);
Image11 *src11 = Image11::makeImage11(src);
- Image11::generateMipmap(dest11, src11);
+ return Image11::generateMipmap(dest11, src11);
}
TextureStorage *Renderer11::createTextureStorage2D(SwapChain *swapChain)
@@ -2788,6 +2900,19 @@ TextureImpl *Renderer11::createTexture(GLenum target)
return NULL;
}
+RenderbufferImpl *Renderer11::createRenderbuffer()
+{
+ RenderbufferD3D *renderbuffer = new RenderbufferD3D(this);
+ return renderbuffer;
+}
+
+RenderbufferImpl *Renderer11::createRenderbuffer(SwapChain *swapChain, bool depth)
+{
+ RenderbufferD3D *renderbuffer = new RenderbufferD3D(this);
+ renderbuffer->setStorage(swapChain, depth);
+ return renderbuffer;
+}
+
gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels)
{
@@ -2882,22 +3007,25 @@ gl::Error Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int sub
SafeRelease(srcTex);
PackPixelsParams packParams(safeArea, format, type, outputPitch, pack, 0);
- packPixels(stagingTex, packParams, pixels);
+ gl::Error error = packPixels(stagingTex, packParams, pixels);
SafeRelease(stagingTex);
- return gl::Error(GL_NO_ERROR);
+ return error;
}
-void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut)
+gl::Error Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut)
{
D3D11_TEXTURE2D_DESC textureDesc;
readTexture->GetDesc(&textureDesc);
D3D11_MAPPED_SUBRESOURCE mapping;
HRESULT hr = mDeviceContext->Map(readTexture, 0, D3D11_MAP_READ, 0, &mapping);
- UNUSED_ASSERTION_VARIABLE(hr);
- ASSERT(SUCCEEDED(hr));
+ if (FAILED(hr))
+ {
+ ASSERT(hr == E_OUTOFMEMORY);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal texture for reading, result: 0x%X.", hr);
+ }
uint8_t *source;
int inputPitch;
@@ -2968,24 +3096,23 @@ void Renderer11::packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams
}
mDeviceContext->Unmap(readTexture, 0);
+
+ return gl::Error(GL_NO_ERROR);
}
-bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget,
- RenderTarget *drawRenderTarget, GLenum filter, const gl::Rectangle *scissor,
- bool colorBlit, bool depthBlit, bool stencilBlit)
+gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget,
+ RenderTarget *drawRenderTarget, GLenum filter, const gl::Rectangle *scissor,
+ bool colorBlit, bool depthBlit, bool stencilBlit)
{
// Since blitRenderbufferRect is called for each render buffer that needs to be blitted,
// it should never be the case that both color and depth/stencil need to be blitted at
// at the same time.
ASSERT(colorBlit != (depthBlit || stencilBlit));
- bool result = true;
-
RenderTarget11 *drawRenderTarget11 = RenderTarget11::makeRenderTarget11(drawRenderTarget);
if (!drawRenderTarget)
{
- ERR("Failed to retrieve the draw render target from the draw framebuffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal draw render target from the draw framebuffer.");
}
ID3D11Resource *drawTexture = drawRenderTarget11->getTexture();
@@ -2996,8 +3123,7 @@ bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::R
RenderTarget11 *readRenderTarget11 = RenderTarget11::makeRenderTarget11(readRenderTarget);
if (!readRenderTarget)
{
- ERR("Failed to retrieve the read render target from the read framebuffer.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal read render target from the read framebuffer.");
}
ID3D11Resource *readTexture = NULL;
@@ -3019,7 +3145,7 @@ bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::R
if (FAILED(hresult))
{
SafeRelease(readTexture);
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to create shader resource view to resolve multisampled framebuffer.");
}
}
}
@@ -3036,8 +3162,7 @@ bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::R
{
SafeRelease(readTexture);
SafeRelease(readSRV);
- ERR("Failed to retrieve the read render target view from the read render target.");
- return gl::error(GL_OUT_OF_MEMORY, false);
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal read render target view from the read render target.");
}
gl::Extents readSize(readRenderTarget->getWidth(), readRenderTarget->getHeight(), 1);
@@ -3063,6 +3188,8 @@ bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::R
const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(drawRenderTarget->getActualFormat());
bool partialDSBlit = (actualFormatInfo.depthBits > 0 && depthBlit) != (actualFormatInfo.stencilBits > 0 && stencilBlit);
+ gl::Error result(GL_NO_ERROR);
+
if (readRenderTarget11->getActualFormat() == drawRenderTarget->getActualFormat() &&
!stretchRequired && !outOfBounds && !flipRequired && !partialDSBlit &&
(!(depthBlit || stencilBlit) || wholeBufferCopy))
@@ -3109,7 +3236,7 @@ bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::R
mDeviceContext->CopySubresourceRegion(drawTexture, drawSubresource, dstX, dstY, 0,
readTexture, readSubresource, pSrcBox);
- result = true;
+ result = gl::Error(GL_NO_ERROR);
}
else
{
@@ -3190,7 +3317,8 @@ void Renderer11::invalidateFBOAttachmentSwizzles(gl::FramebufferAttachment *atta
ASSERT(attachment->isTexture());
gl::Texture *texture = attachment->getTexture();
- TextureStorage *texStorage = texture->getNativeTexture();
+ TextureD3D *textureD3D = TextureD3D::makeTextureD3D(texture->getImplementation());
+ TextureStorage *texStorage = textureD3D->getNativeTexture();
if (texStorage)
{
TextureStorage11 *texStorage11 = TextureStorage11::makeTextureStorage11(texStorage);
@@ -3204,7 +3332,7 @@ void Renderer11::invalidateFBOAttachmentSwizzles(gl::FramebufferAttachment *atta
}
}
-void Renderer11::invalidateFramebufferSwizzles(gl::Framebuffer *framebuffer)
+void Renderer11::invalidateFramebufferSwizzles(const gl::Framebuffer *framebuffer)
{
for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
{
@@ -3248,7 +3376,7 @@ bool Renderer11::getLUID(LUID *adapterLuid) const
return true;
}
-rx::VertexConversionType Renderer11::getVertexConversionType(const gl::VertexFormat &vertexFormat) const
+VertexConversionType Renderer11::getVertexConversionType(const gl::VertexFormat &vertexFormat) const
{
return d3d11::GetVertexFormatInfo(vertexFormat).conversionType;
}
@@ -3263,4 +3391,30 @@ void Renderer11::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureC
d3d11_gl::GenerateCaps(mDevice, outCaps, outTextureCaps, outExtensions);
}
+Workarounds Renderer11::generateWorkarounds() const
+{
+ return d3d11::GenerateWorkarounds();
+}
+
+void Renderer11::setShaderResource(gl::SamplerType shaderType, UINT resourceSlot, ID3D11ShaderResourceView *srv)
+{
+ std::vector<ID3D11ShaderResourceView *> &currentSRVs = (shaderType == gl::SAMPLER_VERTEX ? mCurVertexSRVs : mCurPixelSRVs);
+
+ ASSERT(static_cast<size_t>(resourceSlot) < currentSRVs.size());
+
+ if (currentSRVs[resourceSlot] != srv)
+ {
+ if (shaderType == gl::SAMPLER_VERTEX)
+ {
+ mDeviceContext->VSSetShaderResources(resourceSlot, 1, &srv);
+ }
+ else
+ {
+ mDeviceContext->PSSetShaderResources(resourceSlot, 1, &srv);
+ }
+
+ currentSRVs[resourceSlot] = srv;
+ }
+}
+
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
index 2a53fa1672..d44bd2fd30 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
@@ -13,12 +13,14 @@
#include "libGLESv2/angletypes.h"
#include "common/mathutil.h"
-#include "libGLESv2/renderer/Renderer.h"
-#include "libGLESv2/renderer/d3d/HLSLCompiler.h"
#include "libGLESv2/renderer/d3d/d3d11/RenderStateCache.h"
#include "libGLESv2/renderer/d3d/d3d11/InputLayoutCache.h"
+#include "libGLESv2/renderer/d3d/HLSLCompiler.h"
+#include "libGLESv2/renderer/d3d/RendererD3D.h"
#include "libGLESv2/renderer/RenderTarget.h"
+#include "libEGL/AttributeMap.h"
+
namespace gl
{
class FramebufferAttachment;
@@ -33,6 +35,7 @@ class StreamingIndexBufferInterface;
class Blit11;
class Clear11;
class PixelTransfer11;
+class RenderTarget11;
struct PackPixelsParams;
enum
@@ -41,10 +44,10 @@ enum
MAX_FRAGMENT_UNIFORM_VECTORS_D3D11 = 1024
};
-class Renderer11 : public Renderer
+class Renderer11 : public RendererD3D
{
public:
- Renderer11(egl::Display *display, EGLNativeDisplayType hDc, EGLint requestedDisplay);
+ Renderer11(egl::Display *display, EGLNativeDisplayType hDc, const egl::AttributeMap &attributes);
virtual ~Renderer11();
static Renderer11 *makeRenderer11(Renderer *renderer);
@@ -55,19 +58,19 @@ class Renderer11 : public Renderer
virtual int generateConfigs(ConfigDesc **configDescList);
virtual void deleteConfigs(ConfigDesc *configDescList);
- virtual void sync(bool block);
+ virtual gl::Error sync(bool block);
- virtual SwapChain *createSwapChain(EGLNativeWindowType window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat);
+ virtual SwapChain *createSwapChain(NativeWindow nativeWindow, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat);
virtual gl::Error generateSwizzle(gl::Texture *texture);
- virtual gl::Error setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
+ virtual gl::Error setSamplerState(gl::SamplerType type, int index, gl::Texture *texture, const gl::SamplerState &sampler);
virtual gl::Error setTexture(gl::SamplerType type, int index, gl::Texture *texture);
virtual gl::Error setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]);
virtual gl::Error setRasterizerState(const gl::RasterizerState &rasterState);
- virtual gl::Error setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
- unsigned int sampleMask);
+ gl::Error setBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
+ unsigned int sampleMask) override;
virtual gl::Error setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
int stencilBackRef, bool frontFaceCCW);
@@ -76,32 +79,32 @@ class Renderer11 : public Renderer
bool ignoreViewport);
virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
- virtual gl::Error applyRenderTarget(gl::Framebuffer *frameBuffer);
+ gl::Error applyRenderTarget(const gl::Framebuffer *frameBuffer) override;
virtual gl::Error applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive);
- virtual gl::Error applyUniforms(const gl::ProgramBinary &programBinary);
- virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
- GLint first, GLsizei count, GLsizei instances);
+
+ virtual gl::Error applyUniforms(const ProgramImpl &program, const std::vector<gl::LinkedUniform*> &uniformArray);
+ virtual gl::Error applyVertexBuffer(const gl::State &state, GLint first, GLsizei count, GLsizei instances);
virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
- virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]);
+ virtual void applyTransformFeedbackBuffers(const gl::State &state);
virtual gl::Error drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive);
virtual gl::Error drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances);
- virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer);
+ gl::Error clear(const gl::ClearParameters &clearParams, const gl::Framebuffer *frameBuffer) override;
virtual void markAllStateDirty();
// lost device
- void notifyDeviceLost();
- virtual bool isDeviceLost();
- virtual bool testDeviceLost(bool notify);
- virtual bool testDeviceResettable();
+ void notifyDeviceLost() override;
+ bool isDeviceLost() override;
+ bool testDeviceLost(bool notify) override;
+ bool testDeviceResettable() override;
- virtual DWORD getAdapterVendor() const;
- virtual std::string getRendererDescription() const;
- virtual GUID getAdapterIdentifier() const;
+ DWORD getAdapterVendor() const override;
+ std::string getRendererDescription() const override;
+ GUID getAdapterIdentifier() const override;
virtual unsigned int getReservedVertexUniformVectors() const;
virtual unsigned int getReservedFragmentUniformVectors() const;
@@ -115,47 +118,43 @@ class Renderer11 : public Renderer
virtual int getMaxSwapInterval() const;
// Pixel operations
- virtual bool copyToRenderTarget2D(TextureStorage *dest, TextureStorage *source);
- virtual bool copyToRenderTargetCube(TextureStorage *dest, TextureStorage *source);
- virtual bool copyToRenderTarget3D(TextureStorage *dest, TextureStorage *source);
- virtual bool copyToRenderTarget2DArray(TextureStorage *dest, TextureStorage *source);
-
- virtual bool copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level);
- virtual bool copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level);
- virtual bool copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
- GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level);
- virtual bool copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ virtual gl::Error copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level);
+ virtual gl::Error copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level);
+ virtual gl::Error copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level);
+ virtual gl::Error copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
+ GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level);
- virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
- const gl::Rectangle *scissor, bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter);
+ gl::Error blitRect(const gl::Framebuffer *readTarget, const gl::Rectangle &readRect, const gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
+ const gl::Rectangle *scissor, bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter) override;
- virtual gl::Error readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
+ virtual gl::Error readPixels(const gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels);
// RenderTarget creation
- virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth);
- virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples);
+ virtual gl::Error createRenderTarget(SwapChain *swapChain, bool depth, RenderTarget **outRT);
+ virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT);
// Shader creation
- virtual ShaderImpl *createShader(GLenum type);
+ virtual ShaderImpl *createShader(const gl::Data &data, GLenum type);
virtual ProgramImpl *createProgram();
// Shader operations
- virtual void releaseShaderCompiler();
- virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type,
- const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
- bool separatedOutputBuffers);
- virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type,
- const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
- bool separatedOutputBuffers, D3DWorkaroundType workaround);
+ void releaseShaderCompiler() override;
+ virtual gl::Error loadExecutable(const void *function, size_t length, ShaderType type,
+ const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
+ bool separatedOutputBuffers, ShaderExecutable **outExecutable);
+ virtual gl::Error compileToExecutable(gl::InfoLog &infoLog, const std::string &shaderHLSL, ShaderType type,
+ const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
+ bool separatedOutputBuffers, D3DWorkaroundType workaround,
+ ShaderExecutable **outExectuable);
virtual UniformStorage *createUniformStorage(size_t storageSize);
// Image operations
virtual Image *createImage();
- virtual void generateMipmap(Image *dest, Image *source);
+ gl::Error generateMipmap(Image *dest, Image *source) override;
virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain);
virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels);
virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels);
@@ -165,6 +164,10 @@ class Renderer11 : public Renderer
// Texture creation
virtual TextureImpl *createTexture(GLenum target);
+ // Renderbuffer creation
+ virtual RenderbufferImpl *createRenderbuffer();
+ virtual RenderbufferImpl *createRenderbuffer(SwapChain *swapChain, bool depth);
+
// Buffer creation
virtual BufferImpl *createBuffer();
virtual VertexBuffer *createVertexBuffer();
@@ -175,7 +178,8 @@ class Renderer11 : public Renderer
// Query and Fence creation
virtual QueryImpl *createQuery(GLenum type);
- virtual FenceImpl *createFence();
+ virtual FenceNVImpl *createFenceNV();
+ virtual FenceSyncImpl *createFenceSync();
// Transform Feedback creation
virtual TransformFeedbackImpl* createTransformFeedback();
@@ -183,48 +187,54 @@ class Renderer11 : public Renderer
// D3D11-renderer specific methods
ID3D11Device *getDevice() { return mDevice; }
ID3D11DeviceContext *getDeviceContext() { return mDeviceContext; };
- IDXGIFactory *getDxgiFactory() { return mDxgiFactory; };
+ DXGIFactory *getDxgiFactory() { return mDxgiFactory; };
bool isLevel9() { return mFeatureLevel <= D3D_FEATURE_LEVEL_9_3; }
Blit11 *getBlitter() { return mBlit; }
// Buffer-to-texture and Texture-to-buffer copies
virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const;
- virtual bool fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
- GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
+ virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
+ GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
+
+ gl::Error getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndexOut, ID3D11Texture2D **texture2DOut);
- bool getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndex, ID3D11Texture2D **resource);
void unapplyRenderTargets();
void setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView);
- void packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut);
+ gl::Error packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut);
virtual bool getLUID(LUID *adapterLuid) const;
- virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const;
+ virtual VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const;
virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const;
+ gl::Error readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format,
+ GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels);
+
+ void setShaderResource(gl::SamplerType shaderType, UINT resourceSlot, ID3D11ShaderResourceView *srv);
+
private:
DISALLOW_COPY_AND_ASSIGN(Renderer11);
- virtual void generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const;
+ void generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, gl::Extensions *outExtensions) const override;
+ Workarounds generateWorkarounds() const override;
gl::Error drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
gl::Error drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances);
- gl::Error readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format,
- GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels);
-
- bool blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget,
- RenderTarget *drawRenderTarget, GLenum filter, const gl::Rectangle *scissor,
- bool colorBlit, bool depthBlit, bool stencilBlit);
+ gl::Error blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget,
+ RenderTarget *drawRenderTarget, GLenum filter, const gl::Rectangle *scissor,
+ bool colorBlit, bool depthBlit, bool stencilBlit);
ID3D11Texture2D *resolveMultisampledTexture(ID3D11Texture2D *source, unsigned int subresource);
+ void unsetSRVsWithResource(gl::SamplerType shaderType, const ID3D11Resource *resource);
static void invalidateFBOAttachmentSwizzles(gl::FramebufferAttachment *attachment, int mipLevel);
- static void invalidateFramebufferSwizzles(gl::Framebuffer *framebuffer);
+ static void invalidateFramebufferSwizzles(const gl::Framebuffer *framebuffer);
HMODULE mD3d11Module;
HMODULE mDxgiModule;
EGLNativeDisplayType mDc;
- EGLint mRequestedDisplay;
+ std::vector<D3D_FEATURE_LEVEL> mAvailableFeatureLevels;
+ D3D_DRIVER_TYPE mDriverType;
HLSLCompiler mCompiler;
@@ -243,7 +253,7 @@ class Renderer11 : public Renderer
unsigned int mAppliedStencilbufferSerial;
bool mDepthStencilInitialized;
bool mRenderTargetDescInitialized;
- rx::RenderTarget::Desc mRenderTargetDesc;
+ RenderTarget::Desc mRenderTargetDesc;
// Currently applied sampler states
std::vector<bool> mForceSetVertexSamplerStates;
@@ -292,8 +302,14 @@ class Renderer11 : public Renderer
unsigned int mAppliedIBOffset;
// Currently applied transform feedback buffers
- ID3D11Buffer *mAppliedTFBuffers[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS];
- GLintptr mAppliedTFOffsets[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS];
+ ID3D11Buffer *mAppliedTFBuffers[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS]; // Tracks the current D3D buffers
+ // in use for streamout
+ GLintptr mAppliedTFOffsets[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS]; // Tracks the current GL-specified
+ // buffer offsets to transform feedback
+ // buffers
+ UINT mCurrentD3DOffsets[gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS]; // Tracks the D3D buffer offsets,
+ // which may differ from GLs, due
+ // to different append behavior
// Currently applied shaders
ID3D11VertexShader *mAppliedVertexShader;
@@ -339,7 +355,7 @@ class Renderer11 : public Renderer
IDXGIAdapter *mDxgiAdapter;
DXGI_ADAPTER_DESC mAdapterDescription;
char mDescription[128];
- IDXGIFactory *mDxgiFactory;
+ DXGIFactory *mDxgiFactory;
};
}
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/SwapChain11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/SwapChain11.cpp
index 4b29be055d..52c8a81633 100644
--- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/SwapChain11.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/SwapChain11.cpp
@@ -6,7 +6,6 @@
// SwapChain11.cpp: Implements a back-end specific class for the D3D11 swap chain.
-#include "common/platform.h"
#include "libGLESv2/renderer/d3d/d3d11/SwapChain11.h"
#include "libGLESv2/renderer/d3d/d3d11/renderer11_utils.h"
#include "libGLESv2/renderer/d3d/d3d11/formatutils11.h"
@@ -16,12 +15,16 @@
#include "libGLESv2/renderer/d3d/d3d11/shaders/compiled/passthrough2dvs.h"
#include "libGLESv2/renderer/d3d/d3d11/shaders/compiled/passthroughrgba2dps.h"
+#include "common/features.h"
+#include "common/NativeWindow.h"
+
namespace rx
{
-SwapChain11::SwapChain11(Renderer11 *renderer, EGLNativeWindowType window, HANDLE shareHandle,
+SwapChain11::SwapChain11(Renderer11 *renderer, NativeWindow nativeWindow, HANDLE shareHandle,
GLenum backBufferFormat, GLenum depthBufferFormat)
- : mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat)
+ : mRenderer(renderer),
+ SwapChain(nativeWindow, shareHandle, backBufferFormat, depthBufferFormat)
{
mSwapChain = NULL;
mBackBufferTexture = NULL;
@@ -39,8 +42,8 @@ SwapChain11::SwapChain11(Renderer11 *renderer, EGLNativeWindowType window, HANDL
mPassThroughPS = NULL;
mWidth = -1;
mHeight = -1;
- mViewportWidth = -1;
- mViewportHeight = -1;
+ mRotateL = false;
+ mRotateR = false;
mSwapInterval = 0;
mAppCreatedShareHandle = mShareHandle != NULL;
mPassThroughResourcesInit = false;
@@ -91,11 +94,11 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
ASSERT(device != NULL);
// D3D11 does not allow zero size textures
- ASSERT(backbufferWidth >= 1);
- ASSERT(backbufferHeight >= 1);
+ ASSERT(backbufferWidth != 0);
+ ASSERT(backbufferHeight != 0);
// Preserve the render target content
-#if !defined(ANGLE_PLATFORM_WINRT)
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
ID3D11Texture2D *previousOffscreenTexture = mOffscreenTexture;
if (previousOffscreenTexture)
{
@@ -137,8 +140,8 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
mOffscreenTexture->GetDesc(&offscreenTextureDesc);
- if (offscreenTextureDesc.Width != (UINT)backbufferWidth ||
- offscreenTextureDesc.Height != (UINT)backbufferHeight ||
+ if (offscreenTextureDesc.Width != UINT(abs(backbufferWidth)) ||
+ offscreenTextureDesc.Height != UINT(abs(backbufferHeight)) ||
offscreenTextureDesc.Format != backbufferFormatInfo.texFormat ||
offscreenTextureDesc.MipLevels != 1 ||
offscreenTextureDesc.ArraySize != 1)
@@ -150,11 +153,11 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
}
else
{
- const bool useSharedResource = !mWindow && mRenderer->getShareHandleSupport();
+ const bool useSharedResource = !mNativeWindow.getNativeWindow() && mRenderer->getShareHandleSupport();
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
- offscreenTextureDesc.Width = backbufferWidth;
- offscreenTextureDesc.Height = backbufferHeight;
+ offscreenTextureDesc.Width = abs(backbufferWidth);
+ offscreenTextureDesc.Height = abs(backbufferHeight);
offscreenTextureDesc.Format = backbufferFormatInfo.texFormat;
offscreenTextureDesc.MipLevels = 1;
offscreenTextureDesc.ArraySize = 1;
@@ -234,8 +237,8 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
if (mDepthBufferFormat != GL_NONE)
{
D3D11_TEXTURE2D_DESC depthStencilTextureDesc;
- depthStencilTextureDesc.Width = backbufferWidth;
- depthStencilTextureDesc.Height = backbufferHeight;
+ depthStencilTextureDesc.Width = abs(backbufferWidth);
+ depthStencilTextureDesc.Height = abs(backbufferHeight);
depthStencilTextureDesc.Format = depthBufferFormatInfo.texFormat;
depthStencilTextureDesc.MipLevels = 1;
depthStencilTextureDesc.ArraySize = 1;
@@ -286,12 +289,8 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
mWidth = backbufferWidth;
mHeight = backbufferHeight;
-#if !defined(ANGLE_PLATFORM_WINRT) || WINAPI_FAMILY==WINAPI_FAMILY_PC_APP
- mViewportWidth = backbufferWidth;
- mViewportHeight = backbufferHeight;
-#endif
-#if !defined(ANGLE_PLATFORM_WINRT)
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
if (previousOffscreenTexture != NULL)
{
D3D11_BOX sourceBox = {0};
@@ -310,7 +309,7 @@ EGLint SwapChain11::resetOffscreenTexture(int backbufferWidth, int backbufferHei
if (mSwapChain)
{
- swapRect(0, 0, mWidth, mHeight, SWAP_NORMAL);
+ swapRect(0, 0, mWidth, mHeight);
}
}
#endif
@@ -327,8 +326,16 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
return EGL_BAD_ACCESS;
}
+ // Windows Phone works around the rotation limitation by using negative values for the swap chain size
+#if defined(ANGLE_ENABLE_WINDOWS_STORE) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+ mRotateL = backbufferWidth < 0; // Landscape/InvertedLandscape
+ mRotateR = backbufferHeight < 0; // InvertedPortrait/InvertedLandscape
+ backbufferWidth = abs(backbufferWidth);
+ backbufferHeight = abs(backbufferHeight);
+#endif
+
// EGL allows creating a surface with 0x0 dimension, however, DXGI does not like 0x0 swapchains
- if (backbufferWidth < 1 || backbufferHeight < 1)
+ if (backbufferWidth == 0 || backbufferHeight == 0)
{
return EGL_SUCCESS;
}
@@ -336,19 +343,15 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
// Can only call resize if we have already created our swap buffer and resources
ASSERT(mSwapChain && mBackBufferTexture && mBackBufferRTView);
+#if !defined(ANGLE_ENABLE_WINDOWS_STORE) || (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) // The swap chain is not directly resized on Windows Phone
SafeRelease(mBackBufferTexture);
SafeRelease(mBackBufferRTView);
// Resize swap chain
- HRESULT result;
-#if !defined(ANGLE_PLATFORM_WINRT) || WINAPI_FAMILY==WINAPI_FAMILY_PC_APP // Windows phone swap chain is never resized, only the texture is
-#if !defined(ANGLE_PLATFORM_WINRT)
- const int bufferCount = 1;
-#else
- const int bufferCount = 2;
-#endif
+ DXGI_SWAP_CHAIN_DESC desc;
+ mSwapChain->GetDesc(&desc);
const d3d11::TextureFormat &backbufferFormatInfo = d3d11::GetTextureFormatInfo(mBackBufferFormat);
- result = mSwapChain->ResizeBuffers(bufferCount, backbufferWidth, backbufferHeight, backbufferFormatInfo.texFormat, 0);
+ HRESULT result = mSwapChain->ResizeBuffers(desc.BufferCount, backbufferWidth, backbufferHeight, backbufferFormatInfo.texFormat, 0);
if (FAILED(result))
{
@@ -364,7 +367,6 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
return EGL_BAD_ALLOC;
}
}
-#endif
result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture);
ASSERT(SUCCEEDED(result));
@@ -379,6 +381,7 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
{
d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target");
}
+#endif
return resetOffscreenTexture(backbufferWidth, backbufferHeight);
}
@@ -412,62 +415,14 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
return EGL_SUCCESS;
}
- if (mWindow)
+ if (mNativeWindow.getNativeWindow())
{
const d3d11::TextureFormat &backbufferFormatInfo = d3d11::GetTextureFormatInfo(mBackBufferFormat);
- IDXGIFactory *factory = mRenderer->getDxgiFactory();
-
-#if !defined(ANGLE_PLATFORM_WINRT)
- DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};
- swapChainDesc.BufferDesc.Width = backbufferWidth;
- swapChainDesc.BufferDesc.Height = backbufferHeight;
- swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
- swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
- swapChainDesc.BufferDesc.Format = backbufferFormatInfo.texFormat;
- swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
- swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
- swapChainDesc.SampleDesc.Count = 1;
- swapChainDesc.SampleDesc.Quality = 0;
- swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- swapChainDesc.BufferCount = 1;
- swapChainDesc.OutputWindow = mWindow;
- swapChainDesc.Windowed = TRUE;
- swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
- swapChainDesc.Flags = 0;
-
- HRESULT result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain);
-#else
- IDXGIFactory2 *factory2;
- HRESULT result = factory->QueryInterface(IID_PPV_ARGS(&factory2));
- ASSERT(SUCCEEDED(result));
-
- DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
- swapChainDesc.Width = 0;
- swapChainDesc.Height = 0;
- swapChainDesc.Format = backbufferFormatInfo.texFormat;
- swapChainDesc.SampleDesc.Count = 1;
- swapChainDesc.SampleDesc.Quality = 0;
- swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- swapChainDesc.Stereo = FALSE;
- swapChainDesc.Flags = 0;
-#if WINAPI_FAMILY==WINAPI_FAMILY_PC_APP
- swapChainDesc.Scaling = DXGI_SCALING_NONE;
- swapChainDesc.BufferCount = 2;
- swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
-#elif WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP
- swapChainDesc.BufferCount = 1;
- swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
-#endif
+ HRESULT result = mNativeWindow.createSwapChain(device, mRenderer->getDxgiFactory(),
+ backbufferFormatInfo.texFormat,
+ backbufferWidth, backbufferHeight, &mSwapChain);
- IDXGISwapChain1 *swapChain;
- result = factory2->CreateSwapChainForCoreWindow(device, mWindow, &swapChainDesc, NULL, &swapChain);
- mSwapChain = swapChain;
- HRESULT hr = swapChain->GetDesc1(&swapChainDesc);
- ASSERT(SUCCEEDED(hr));
- mViewportWidth = swapChainDesc.Width;
- mViewportHeight = swapChainDesc.Height;
-#endif
if (FAILED(result))
{
ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result);
@@ -537,7 +492,7 @@ void SwapChain11::initPassThroughResources()
samplerDesc.BorderColor[2] = 0.0f;
samplerDesc.BorderColor[3] = 0.0f;
samplerDesc.MinLOD = 0;
- samplerDesc.MaxLOD = FLT_MAX;
+ samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
result = device->CreateSamplerState(&samplerDesc, &mPassThroughSampler);
ASSERT(SUCCEEDED(result));
@@ -563,7 +518,7 @@ void SwapChain11::initPassThroughResources()
}
// parameters should be validated/clamped by caller
-EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height, EGLint flags)
+EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
{
if (!mSwapChain)
{
@@ -573,16 +528,6 @@ EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height, EG
ID3D11Device *device = mRenderer->getDevice();
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
- // Set vertices
- D3D11_MAPPED_SUBRESOURCE mappedResource;
- HRESULT result = deviceContext->Map(mQuadVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
- if (FAILED(result))
- {
- return EGL_BAD_ACCESS;
- }
-
- d3d11::PositionTexCoordVertex *vertices = static_cast<d3d11::PositionTexCoordVertex*>(mappedResource.pData);
-
// Create a quad in homogeneous coordinates
float x1 = (x / float(mWidth)) * 2.0f - 1.0f;
float y1 = (y / float(mHeight)) * 2.0f - 1.0f;
@@ -594,8 +539,18 @@ EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height, EG
float u2 = (x + width) / float(mWidth);
float v2 = (y + height) / float(mHeight);
- const int rotateL = flags & SWAP_ROTATE_90;
- const int rotateR = flags & SWAP_ROTATE_270;
+ const bool rotateL = mRotateL;
+ const bool rotateR = mRotateR;
+
+ // Set vertices
+ D3D11_MAPPED_SUBRESOURCE mappedResource;
+ HRESULT result = deviceContext->Map(mQuadVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+ if (FAILED(result))
+ {
+ return EGL_BAD_ACCESS;
+ }
+
+ d3d11::PositionTexCoordVertex *vertices = static_cast<d3d11::PositionTexCoordVertex*>(mappedResource.pData);
d3d11::SetPositionTexCoordVertex(&vertices[0], x1, y1, rotateL ? u2 : u1, rotateR ? v2 : v1);
d3d11::SetPositionTexCoordVertex(&vertices[1], x1, y2, rotateR ? u2 : u1, rotateL ? v1 : v2);
@@ -628,22 +583,23 @@ EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height, EG
// Set the viewport
D3D11_VIEWPORT viewport;
- viewport.TopLeftX = 0;
- viewport.TopLeftY = 0;
- viewport.Width = mViewportWidth;
- viewport.Height = mViewportHeight;
+ viewport.TopLeftX = 0.0f;
+ viewport.TopLeftY = 0.0f;
+ const bool invertViewport = (mRotateL || mRotateR) && !(mRotateL && mRotateR);
+ viewport.Width = FLOAT(invertViewport ? mHeight : mWidth);
+ viewport.Height = FLOAT(invertViewport ? mWidth : mHeight);
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
deviceContext->RSSetViewports(1, &viewport);
// Apply textures
- deviceContext->PSSetShaderResources(0, 1, &mOffscreenSRView);
+ mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, mOffscreenSRView);
deviceContext->PSSetSamplers(0, 1, &mPassThroughSampler);
// Draw
deviceContext->Draw(4, 0);
-#ifdef ANGLE_FORCE_VSYNC_OFF
+#if ANGLE_VSYNC == ANGLE_DISABLED
result = mSwapChain->Present(0, 0);