gfx/angle/src/libGLESv2/renderer/Renderer11.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/libGLESv2/renderer/Renderer11.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,358 @@
     1.4 +//
     1.5 +// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
     1.6 +// Use of this source code is governed by a BSD-style license that can be
     1.7 +// found in the LICENSE file.
     1.8 +//
     1.9 +
    1.10 +// Renderer11.h: Defines a back-end specific class for the D3D11 renderer.
    1.11 +
    1.12 +#ifndef LIBGLESV2_RENDERER_RENDERER11_H_
    1.13 +#define LIBGLESV2_RENDERER_RENDERER11_H_
    1.14 +
    1.15 +#include "common/angleutils.h"
    1.16 +#include "libGLESv2/angletypes.h"
    1.17 +#include "libGLESv2/mathutil.h"
    1.18 +
    1.19 +#include "libGLESv2/renderer/Renderer.h"
    1.20 +#include "libGLESv2/renderer/RenderStateCache.h"
    1.21 +#include "libGLESv2/renderer/InputLayoutCache.h"
    1.22 +#include "libGLESv2/renderer/RenderTarget.h"
    1.23 +
    1.24 +namespace gl
    1.25 +{
    1.26 +class Renderbuffer;
    1.27 +}
    1.28 +
    1.29 +namespace rx
    1.30 +{
    1.31 +
    1.32 +class VertexDataManager;
    1.33 +class IndexDataManager;
    1.34 +class StreamingIndexBufferInterface;
    1.35 +
    1.36 +enum
    1.37 +{
    1.38 +    MAX_VERTEX_UNIFORM_VECTORS_D3D11 = 1024,
    1.39 +    MAX_FRAGMENT_UNIFORM_VECTORS_D3D11 = 1024
    1.40 +};
    1.41 +
    1.42 +class Renderer11 : public Renderer
    1.43 +{
    1.44 +  public:
    1.45 +    Renderer11(egl::Display *display, HDC hDc);
    1.46 +    virtual ~Renderer11();
    1.47 +
    1.48 +    static Renderer11 *makeRenderer11(Renderer *renderer);
    1.49 +
    1.50 +    virtual EGLint initialize();
    1.51 +    virtual bool resetDevice();
    1.52 +
    1.53 +    virtual int generateConfigs(ConfigDesc **configDescList);
    1.54 +    virtual void deleteConfigs(ConfigDesc *configDescList);
    1.55 +
    1.56 +    virtual void sync(bool block);
    1.57 +
    1.58 +    virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat);
    1.59 +
    1.60 +    virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
    1.61 +    virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture);
    1.62 +
    1.63 +    virtual void setRasterizerState(const gl::RasterizerState &rasterState);
    1.64 +    virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
    1.65 +                               unsigned int sampleMask);
    1.66 +    virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
    1.67 +                                      int stencilBackRef, bool frontFaceCCW);
    1.68 +
    1.69 +    virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
    1.70 +    virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
    1.71 +                             bool ignoreViewport);
    1.72 +
    1.73 +    virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
    1.74 +    virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
    1.75 +    virtual void applyShaders(gl::ProgramBinary *programBinary);
    1.76 +    virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray);
    1.77 +    virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances);
    1.78 +    virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
    1.79 +
    1.80 +    virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances);
    1.81 +    virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances);
    1.82 +
    1.83 +    virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer);
    1.84 +
    1.85 +    virtual void markAllStateDirty();
    1.86 +
    1.87 +    // lost device
    1.88 +    void notifyDeviceLost();
    1.89 +    virtual bool isDeviceLost();
    1.90 +    virtual bool testDeviceLost(bool notify);
    1.91 +    virtual bool testDeviceResettable();
    1.92 +
    1.93 +    // Renderer capabilities
    1.94 +    virtual DWORD getAdapterVendor() const;
    1.95 +    virtual std::string getRendererDescription() const;
    1.96 +    virtual GUID getAdapterIdentifier() const;
    1.97 +
    1.98 +    virtual bool getBGRATextureSupport() const;
    1.99 +    virtual bool getDXT1TextureSupport();
   1.100 +    virtual bool getDXT3TextureSupport();
   1.101 +    virtual bool getDXT5TextureSupport();
   1.102 +    virtual bool getEventQuerySupport();
   1.103 +    virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable);
   1.104 +    virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable);
   1.105 +    virtual bool getLuminanceTextureSupport();
   1.106 +    virtual bool getLuminanceAlphaTextureSupport();
   1.107 +    virtual unsigned int getMaxVertexTextureImageUnits() const;
   1.108 +    virtual unsigned int getMaxCombinedTextureImageUnits() const;
   1.109 +    virtual unsigned int getReservedVertexUniformVectors() const;
   1.110 +    virtual unsigned int getReservedFragmentUniformVectors() const;
   1.111 +    virtual unsigned int getMaxVertexUniformVectors() const;
   1.112 +    virtual unsigned int getMaxFragmentUniformVectors() const;
   1.113 +    virtual unsigned int getMaxVaryingVectors() const;
   1.114 +    virtual bool getNonPower2TextureSupport() const;
   1.115 +    virtual bool getDepthTextureSupport() const;
   1.116 +    virtual bool getOcclusionQuerySupport() const;
   1.117 +    virtual bool getInstancingSupport() const;
   1.118 +    virtual bool getTextureFilterAnisotropySupport() const;
   1.119 +    virtual float getTextureMaxAnisotropy() const;
   1.120 +    virtual bool getShareHandleSupport() const;
   1.121 +    virtual bool getDerivativeInstructionSupport() const;
   1.122 +    virtual bool getPostSubBufferSupport() const;
   1.123 +
   1.124 +    virtual int getMajorShaderModel() const;
   1.125 +    virtual float getMaxPointSize() const;
   1.126 +    virtual int getMaxViewportDimension() const;
   1.127 +    virtual int getMaxTextureWidth() const;
   1.128 +    virtual int getMaxTextureHeight() const;
   1.129 +    virtual bool get32BitIndexSupport() const;
   1.130 +    virtual int getMinSwapInterval() const;
   1.131 +    virtual int getMaxSwapInterval() const;
   1.132 +
   1.133 +    virtual GLsizei getMaxSupportedSamples() const;
   1.134 +    int getNearestSupportedSamples(DXGI_FORMAT format, unsigned int requested) const;
   1.135 +
   1.136 +    virtual unsigned int getMaxRenderTargets() const;
   1.137 +
   1.138 +    // Pixel operations
   1.139 +    virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source);
   1.140 +    virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source);
   1.141 +
   1.142 +    virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
   1.143 +                           GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level);
   1.144 +    virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
   1.145 +                           GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level);
   1.146 +
   1.147 +    bool copyTexture(ID3D11ShaderResourceView *source, const gl::Rectangle &sourceArea, unsigned int sourceWidth, unsigned int sourceHeight,
   1.148 +                     ID3D11RenderTargetView *dest, const gl::Rectangle &destArea, unsigned int destWidth, unsigned int destHeight, GLenum destFormat);
   1.149 +
   1.150 +    virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
   1.151 +                          bool blitRenderTarget, bool blitDepthStencil);
   1.152 +    virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
   1.153 +                            GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels);
   1.154 +
   1.155 +    // RenderTarget creation
   1.156 +    virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth);
   1.157 +    virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth);
   1.158 +
   1.159 +    // Shader operations
   1.160 +    virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type);
   1.161 +    virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type);
   1.162 +
   1.163 +    // Image operations
   1.164 +    virtual Image *createImage();
   1.165 +    virtual void generateMipmap(Image *dest, Image *source);
   1.166 +    virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain);
   1.167 +    virtual TextureStorage *createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height);
   1.168 +    virtual TextureStorage *createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size);
   1.169 +
   1.170 +    // Buffer creation
   1.171 +    virtual VertexBuffer *createVertexBuffer();
   1.172 +    virtual IndexBuffer *createIndexBuffer();
   1.173 +    virtual BufferStorage *createBufferStorage();
   1.174 +
   1.175 +    // Query and Fence creation
   1.176 +    virtual QueryImpl *createQuery(GLenum type);
   1.177 +    virtual FenceImpl *createFence();
   1.178 +
   1.179 +    // D3D11-renderer specific methods
   1.180 +    ID3D11Device *getDevice() { return mDevice; }
   1.181 +    ID3D11DeviceContext *getDeviceContext() { return mDeviceContext; };
   1.182 +    IDXGIFactory *getDxgiFactory() { return mDxgiFactory; };
   1.183 +
   1.184 +    bool getRenderTargetResource(gl::Renderbuffer *colorbuffer, unsigned int *subresourceIndex, ID3D11Texture2D **resource);
   1.185 +    void unapplyRenderTargets();
   1.186 +    void setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView);
   1.187 +
   1.188 +    virtual bool getLUID(LUID *adapterLuid) const;
   1.189 +
   1.190 +  private:
   1.191 +    DISALLOW_COPY_AND_ASSIGN(Renderer11);
   1.192 +
   1.193 +    void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
   1.194 +    void drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances);
   1.195 +
   1.196 +    void readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area,
   1.197 +                         GLenum format, GLenum type, GLsizei outputPitch, bool packReverseRowOrder,
   1.198 +                         GLint packAlignment, void *pixels);
   1.199 +
   1.200 +    void maskedClear(const gl::ClearParameters &clearParams, bool usingExtendedDrawBuffers);
   1.201 +    rx::Range getViewportBounds() const;
   1.202 +
   1.203 +    bool blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget, 
   1.204 +                              RenderTarget *drawRenderTarget, bool wholeBufferCopy);
   1.205 +    ID3D11Texture2D *resolveMultisampledTexture(ID3D11Texture2D *source, unsigned int subresource);
   1.206 +
   1.207 +    HMODULE mD3d11Module;
   1.208 +    HMODULE mDxgiModule;
   1.209 +    HDC mDc;
   1.210 +
   1.211 +    bool mDeviceLost;
   1.212 +
   1.213 +    void initializeDevice();
   1.214 +    void releaseDeviceResources();
   1.215 +    int getMinorShaderModel() const;
   1.216 +    void release();
   1.217 +
   1.218 +    RenderStateCache mStateCache;
   1.219 +
   1.220 +    // Support flags
   1.221 +    bool mFloat16TextureSupport;
   1.222 +    bool mFloat16FilterSupport;
   1.223 +    bool mFloat16RenderSupport;
   1.224 +
   1.225 +    bool mFloat32TextureSupport;
   1.226 +    bool mFloat32FilterSupport;
   1.227 +    bool mFloat32RenderSupport;
   1.228 +
   1.229 +    bool mDXT1TextureSupport;
   1.230 +    bool mDXT3TextureSupport;
   1.231 +    bool mDXT5TextureSupport;
   1.232 +
   1.233 +    bool mDepthTextureSupport;
   1.234 +
   1.235 +    // Multisample format support
   1.236 +    struct MultisampleSupportInfo
   1.237 +    {
   1.238 +        unsigned int qualityLevels[D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT];
   1.239 +    };
   1.240 +
   1.241 +    typedef std::unordered_map<DXGI_FORMAT, MultisampleSupportInfo, std::hash<int> > MultisampleSupportMap;
   1.242 +    MultisampleSupportMap mMultisampleSupportMap;
   1.243 +
   1.244 +    unsigned int mMaxSupportedSamples;
   1.245 +
   1.246 +    // current render target states
   1.247 +    unsigned int mAppliedRenderTargetSerials[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS];
   1.248 +    unsigned int mAppliedDepthbufferSerial;
   1.249 +    unsigned int mAppliedStencilbufferSerial;
   1.250 +    bool mDepthStencilInitialized;
   1.251 +    bool mRenderTargetDescInitialized;
   1.252 +    rx::RenderTarget::Desc mRenderTargetDesc;
   1.253 +    unsigned int mCurDepthSize;
   1.254 +    unsigned int mCurStencilSize;
   1.255 +
   1.256 +    // Currently applied sampler states
   1.257 +    bool mForceSetVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS];
   1.258 +    gl::SamplerState mCurVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS];
   1.259 +
   1.260 +    bool mForceSetPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
   1.261 +    gl::SamplerState mCurPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
   1.262 +
   1.263 +    // Currently applied textures
   1.264 +    unsigned int mCurVertexTextureSerials[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS];
   1.265 +    unsigned int mCurPixelTextureSerials[gl::MAX_TEXTURE_IMAGE_UNITS];
   1.266 +
   1.267 +    // Currently applied blend state
   1.268 +    bool mForceSetBlendState;
   1.269 +    gl::BlendState mCurBlendState;
   1.270 +    gl::Color mCurBlendColor;
   1.271 +    unsigned int mCurSampleMask;
   1.272 +
   1.273 +    // Currently applied rasterizer state
   1.274 +    bool mForceSetRasterState;
   1.275 +    gl::RasterizerState mCurRasterState;
   1.276 +
   1.277 +    // Currently applied depth stencil state
   1.278 +    bool mForceSetDepthStencilState;
   1.279 +    gl::DepthStencilState mCurDepthStencilState;
   1.280 +    int mCurStencilRef;
   1.281 +    int mCurStencilBackRef;
   1.282 +
   1.283 +    // Currently applied scissor rectangle
   1.284 +    bool mForceSetScissor;
   1.285 +    bool mScissorEnabled;
   1.286 +    gl::Rectangle mCurScissor;
   1.287 +
   1.288 +    // Currently applied viewport
   1.289 +    bool mForceSetViewport;
   1.290 +    gl::Rectangle mCurViewport;
   1.291 +    float mCurNear;
   1.292 +    float mCurFar;
   1.293 +
   1.294 +    // Currently applied primitive topology
   1.295 +    D3D11_PRIMITIVE_TOPOLOGY mCurrentPrimitiveTopology;
   1.296 +
   1.297 +    unsigned int mAppliedIBSerial;
   1.298 +    unsigned int mAppliedStorageIBSerial;
   1.299 +    unsigned int mAppliedIBOffset;
   1.300 +
   1.301 +    unsigned int mAppliedProgramBinarySerial;
   1.302 +    bool mIsGeometryShaderActive;
   1.303 +
   1.304 +    dx_VertexConstants mVertexConstants;
   1.305 +    dx_VertexConstants mAppliedVertexConstants;
   1.306 +    ID3D11Buffer *mDriverConstantBufferVS;
   1.307 +    ID3D11Buffer *mCurrentVertexConstantBuffer;
   1.308 +
   1.309 +    dx_PixelConstants mPixelConstants;
   1.310 +    dx_PixelConstants mAppliedPixelConstants;
   1.311 +    ID3D11Buffer *mDriverConstantBufferPS;
   1.312 +    ID3D11Buffer *mCurrentPixelConstantBuffer;
   1.313 +
   1.314 +    ID3D11Buffer *mCurrentGeometryConstantBuffer;
   1.315 +
   1.316 +    // Vertex, index and input layouts
   1.317 +    VertexDataManager *mVertexDataManager;
   1.318 +    IndexDataManager *mIndexDataManager;
   1.319 +    InputLayoutCache mInputLayoutCache;
   1.320 +
   1.321 +    StreamingIndexBufferInterface *mLineLoopIB;
   1.322 +    StreamingIndexBufferInterface *mTriangleFanIB;
   1.323 +
   1.324 +    // Texture copy resources
   1.325 +    bool mCopyResourcesInitialized;
   1.326 +    ID3D11Buffer *mCopyVB;
   1.327 +    ID3D11SamplerState *mCopySampler;
   1.328 +    ID3D11InputLayout *mCopyIL;
   1.329 +    ID3D11VertexShader *mCopyVS;
   1.330 +    ID3D11PixelShader *mCopyRGBAPS;
   1.331 +    ID3D11PixelShader *mCopyRGBPS;
   1.332 +    ID3D11PixelShader *mCopyLumPS;
   1.333 +    ID3D11PixelShader *mCopyLumAlphaPS;
   1.334 +
   1.335 +    // Masked clear resources
   1.336 +    bool mClearResourcesInitialized;
   1.337 +    ID3D11Buffer *mClearVB;
   1.338 +    ID3D11InputLayout *mClearIL;
   1.339 +    ID3D11VertexShader *mClearVS;
   1.340 +    ID3D11PixelShader *mClearSinglePS;
   1.341 +    ID3D11PixelShader *mClearMultiplePS;
   1.342 +    ID3D11RasterizerState *mClearScissorRS;
   1.343 +    ID3D11RasterizerState *mClearNoScissorRS;
   1.344 +
   1.345 +    // Sync query
   1.346 +    ID3D11Query *mSyncQuery;
   1.347 +
   1.348 +    ID3D11Device *mDevice;
   1.349 +    D3D_FEATURE_LEVEL mFeatureLevel;
   1.350 +    ID3D11DeviceContext *mDeviceContext;
   1.351 +    IDXGIAdapter *mDxgiAdapter;
   1.352 +    DXGI_ADAPTER_DESC mAdapterDescription;
   1.353 +    char mDescription[128];
   1.354 +    IDXGIFactory *mDxgiFactory;
   1.355 +
   1.356 +    // Cached device caps
   1.357 +    bool mBGRATextureSupport;
   1.358 +};
   1.359 +
   1.360 +}
   1.361 +#endif // LIBGLESV2_RENDERER_RENDERER11_H_

mercurial