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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/libGLESv2/renderer/Renderer9.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,349 @@
     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 +// Renderer9.h: Defines a back-end specific class for the D3D9 renderer.
    1.11 +
    1.12 +#ifndef LIBGLESV2_RENDERER_RENDERER9_H_
    1.13 +#define LIBGLESV2_RENDERER_RENDERER9_H_
    1.14 +
    1.15 +#include "common/angleutils.h"
    1.16 +#include "libGLESv2/mathutil.h"
    1.17 +#include "libGLESv2/renderer/ShaderCache.h"
    1.18 +#include "libGLESv2/renderer/VertexDeclarationCache.h"
    1.19 +#include "libGLESv2/renderer/Renderer.h"
    1.20 +#include "libGLESv2/renderer/RenderTarget.h"
    1.21 +
    1.22 +namespace gl
    1.23 +{
    1.24 +class Renderbuffer;
    1.25 +}
    1.26 +
    1.27 +namespace rx
    1.28 +{
    1.29 +class VertexDataManager;
    1.30 +class IndexDataManager;
    1.31 +class StreamingIndexBufferInterface;
    1.32 +struct TranslatedAttribute;
    1.33 +
    1.34 +class Renderer9 : public Renderer
    1.35 +{
    1.36 +  public:
    1.37 +    Renderer9(egl::Display *display, HDC hDc, bool softwareDevice);
    1.38 +    virtual ~Renderer9();
    1.39 +
    1.40 +    static Renderer9 *makeRenderer9(Renderer *renderer);
    1.41 +
    1.42 +    virtual EGLint initialize();
    1.43 +    virtual bool resetDevice();
    1.44 +
    1.45 +    virtual int generateConfigs(ConfigDesc **configDescList);
    1.46 +    virtual void deleteConfigs(ConfigDesc *configDescList);
    1.47 +
    1.48 +    void startScene();
    1.49 +    void endScene();
    1.50 +
    1.51 +    virtual void sync(bool block);
    1.52 +
    1.53 +    virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat);
    1.54 +
    1.55 +    IDirect3DQuery9* allocateEventQuery();
    1.56 +    void freeEventQuery(IDirect3DQuery9* query);
    1.57 +
    1.58 +    // resource creation
    1.59 +    IDirect3DVertexShader9 *createVertexShader(const DWORD *function, size_t length);
    1.60 +    IDirect3DPixelShader9 *createPixelShader(const DWORD *function, size_t length);
    1.61 +    HRESULT createVertexBuffer(UINT Length, DWORD Usage, IDirect3DVertexBuffer9 **ppVertexBuffer);
    1.62 +    HRESULT createIndexBuffer(UINT Length, DWORD Usage, D3DFORMAT Format, IDirect3DIndexBuffer9 **ppIndexBuffer);
    1.63 +#if 0
    1.64 +    void *createTexture2D();
    1.65 +    void *createTextureCube();
    1.66 +    void *createQuery();
    1.67 +    void *createIndexBuffer();
    1.68 +    void *createVertexbuffer();
    1.69 +
    1.70 +    // state setup
    1.71 +    void applyShaders();
    1.72 +    void applyConstants();
    1.73 +#endif
    1.74 +    virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler);
    1.75 +    virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture);
    1.76 +
    1.77 +    virtual void setRasterizerState(const gl::RasterizerState &rasterState);
    1.78 +    virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
    1.79 +                               unsigned int sampleMask);
    1.80 +    virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
    1.81 +                                      int stencilBackRef, bool frontFaceCCW);
    1.82 +
    1.83 +    virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
    1.84 +    virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
    1.85 +                             bool ignoreViewport);
    1.86 +
    1.87 +    virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
    1.88 +    virtual void applyShaders(gl::ProgramBinary *programBinary);
    1.89 +    virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray);
    1.90 +    virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
    1.91 +    virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances);
    1.92 +    virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
    1.93 +
    1.94 +    virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances);
    1.95 +    virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances);
    1.96 +
    1.97 +    virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer);
    1.98 +
    1.99 +    virtual void markAllStateDirty();
   1.100 +
   1.101 +    // lost device
   1.102 +    void notifyDeviceLost();
   1.103 +    virtual bool isDeviceLost();
   1.104 +    virtual bool testDeviceLost(bool notify);
   1.105 +    virtual bool testDeviceResettable();
   1.106 +
   1.107 +    // Renderer capabilities
   1.108 +    IDirect3DDevice9 *getDevice() { return mDevice; }
   1.109 +    virtual DWORD getAdapterVendor() const;
   1.110 +    virtual std::string getRendererDescription() const;
   1.111 +    virtual GUID getAdapterIdentifier() const;
   1.112 +
   1.113 +    virtual bool getBGRATextureSupport() const;
   1.114 +    virtual bool getDXT1TextureSupport();
   1.115 +    virtual bool getDXT3TextureSupport();
   1.116 +    virtual bool getDXT5TextureSupport();
   1.117 +    virtual bool getEventQuerySupport();
   1.118 +    virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable);
   1.119 +    virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable);
   1.120 +    virtual bool getLuminanceTextureSupport();
   1.121 +    virtual bool getLuminanceAlphaTextureSupport();
   1.122 +    virtual unsigned int getMaxVertexTextureImageUnits() const;
   1.123 +    virtual unsigned int getMaxCombinedTextureImageUnits() const;
   1.124 +    virtual unsigned int getReservedVertexUniformVectors() const;
   1.125 +    virtual unsigned int getReservedFragmentUniformVectors() const;
   1.126 +    virtual unsigned int getMaxVertexUniformVectors() const;
   1.127 +    virtual unsigned int getMaxFragmentUniformVectors() const;
   1.128 +    virtual unsigned int getMaxVaryingVectors() const;
   1.129 +    virtual bool getNonPower2TextureSupport() const;
   1.130 +    virtual bool getDepthTextureSupport() const;
   1.131 +    virtual bool getOcclusionQuerySupport() const;
   1.132 +    virtual bool getInstancingSupport() const;
   1.133 +    virtual bool getTextureFilterAnisotropySupport() const;
   1.134 +    virtual float getTextureMaxAnisotropy() const;
   1.135 +    virtual bool getShareHandleSupport() const;
   1.136 +    virtual bool getDerivativeInstructionSupport() const;
   1.137 +    virtual bool getPostSubBufferSupport() const;
   1.138 +
   1.139 +    virtual int getMajorShaderModel() const;
   1.140 +    virtual float getMaxPointSize() const;
   1.141 +    virtual int getMaxViewportDimension() const;
   1.142 +    virtual int getMaxTextureWidth() const;
   1.143 +    virtual int getMaxTextureHeight() const;
   1.144 +    virtual bool get32BitIndexSupport() const;
   1.145 +    DWORD getCapsDeclTypes() const;
   1.146 +    virtual int getMinSwapInterval() const;
   1.147 +    virtual int getMaxSwapInterval() const;
   1.148 +
   1.149 +    virtual GLsizei getMaxSupportedSamples() const;
   1.150 +    int getNearestSupportedSamples(D3DFORMAT format, int requested) const;
   1.151 +    
   1.152 +    virtual unsigned int getMaxRenderTargets() const;
   1.153 +
   1.154 +    D3DFORMAT ConvertTextureInternalFormat(GLint internalformat);
   1.155 +
   1.156 +    // Pixel operations
   1.157 +    virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source);
   1.158 +    virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source);
   1.159 +
   1.160 +    virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
   1.161 +                           GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level);
   1.162 +    virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
   1.163 +                           GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level);
   1.164 +
   1.165 +    virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
   1.166 +                          bool blitRenderTarget, bool blitDepthStencil);
   1.167 +    virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
   1.168 +                            GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels);
   1.169 +
   1.170 +    // RenderTarget creation
   1.171 +    virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth);
   1.172 +    virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth);
   1.173 +
   1.174 +    // Shader operations
   1.175 +    virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type);
   1.176 +    virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type);
   1.177 +
   1.178 +    // Image operations
   1.179 +    virtual Image *createImage();
   1.180 +    virtual void generateMipmap(Image *dest, Image *source);
   1.181 +    virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain);
   1.182 +    virtual TextureStorage *createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height);
   1.183 +    virtual TextureStorage *createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size);
   1.184 +
   1.185 +    // Buffer creation
   1.186 +    virtual VertexBuffer *createVertexBuffer();
   1.187 +    virtual IndexBuffer *createIndexBuffer();
   1.188 +    virtual BufferStorage *createBufferStorage();
   1.189 +
   1.190 +    // Query and Fence creation
   1.191 +    virtual QueryImpl *createQuery(GLenum type);
   1.192 +    virtual FenceImpl *createFence();
   1.193 +
   1.194 +    // D3D9-renderer specific methods
   1.195 +    bool boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest);
   1.196 +
   1.197 +    D3DPOOL getTexturePool(DWORD usage) const;
   1.198 +
   1.199 +    virtual bool getLUID(LUID *adapterLuid) const;
   1.200 +
   1.201 +  private:
   1.202 +    DISALLOW_COPY_AND_ASSIGN(Renderer9);
   1.203 +
   1.204 +    void applyUniformnfv(gl::Uniform *targetUniform, const GLfloat *v);
   1.205 +    void applyUniformniv(gl::Uniform *targetUniform, const GLint *v);
   1.206 +    void applyUniformnbv(gl::Uniform *targetUniform, const GLint *v);
   1.207 +
   1.208 +    void drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
   1.209 +    void drawIndexedPoints(GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer);
   1.210 +
   1.211 +    void getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray);
   1.212 +    bool copyToRenderTarget(IDirect3DSurface9 *dest, IDirect3DSurface9 *source, bool fromManaged);
   1.213 +    gl::Renderbuffer *getNullColorbuffer(gl::Renderbuffer *depthbuffer);
   1.214 +
   1.215 +    D3DPOOL getBufferPool(DWORD usage) const;
   1.216 +
   1.217 +    HMODULE mD3d9Module;
   1.218 +    HDC mDc;
   1.219 +
   1.220 +    void initializeDevice();
   1.221 +    D3DPRESENT_PARAMETERS getDefaultPresentParameters();
   1.222 +    void releaseDeviceResources();
   1.223 +
   1.224 +    UINT mAdapter;
   1.225 +    D3DDEVTYPE mDeviceType;
   1.226 +    bool mSoftwareDevice;   // FIXME: Deprecate
   1.227 +    IDirect3D9 *mD3d9;  // Always valid after successful initialization.
   1.228 +    IDirect3D9Ex *mD3d9Ex;  // Might be null if D3D9Ex is not supported.
   1.229 +    IDirect3DDevice9 *mDevice;
   1.230 +    IDirect3DDevice9Ex *mDeviceEx;  // Might be null if D3D9Ex is not supported.
   1.231 +
   1.232 +    Blit *mBlit;
   1.233 +
   1.234 +    HWND mDeviceWindow;
   1.235 +
   1.236 +    bool mDeviceLost;
   1.237 +    D3DCAPS9 mDeviceCaps;
   1.238 +    D3DADAPTER_IDENTIFIER9 mAdapterIdentifier;
   1.239 +
   1.240 +    D3DPRIMITIVETYPE mPrimitiveType;
   1.241 +    int mPrimitiveCount;
   1.242 +    GLsizei mRepeatDraw;
   1.243 +
   1.244 +    bool mSceneStarted;
   1.245 +    bool mSupportsNonPower2Textures;
   1.246 +    bool mSupportsTextureFilterAnisotropy;
   1.247 +    int mMinSwapInterval;
   1.248 +    int mMaxSwapInterval;
   1.249 +
   1.250 +    bool mOcclusionQuerySupport;
   1.251 +    bool mEventQuerySupport;
   1.252 +    bool mVertexTextureSupport;
   1.253 +
   1.254 +    bool mDepthTextureSupport;
   1.255 +
   1.256 +    bool mFloat32TextureSupport;
   1.257 +    bool mFloat32FilterSupport;
   1.258 +    bool mFloat32RenderSupport;
   1.259 +
   1.260 +    bool mFloat16TextureSupport;
   1.261 +    bool mFloat16FilterSupport;
   1.262 +    bool mFloat16RenderSupport;
   1.263 +
   1.264 +    bool mDXT1TextureSupport;
   1.265 +    bool mDXT3TextureSupport;
   1.266 +    bool mDXT5TextureSupport;
   1.267 +
   1.268 +    bool mLuminanceTextureSupport;
   1.269 +    bool mLuminanceAlphaTextureSupport;
   1.270 +
   1.271 +    std::map<D3DFORMAT, bool *> mMultiSampleSupport;
   1.272 +    GLsizei mMaxSupportedSamples;
   1.273 +
   1.274 +    // current render target states
   1.275 +    unsigned int mAppliedRenderTargetSerial;
   1.276 +    unsigned int mAppliedDepthbufferSerial;
   1.277 +    unsigned int mAppliedStencilbufferSerial;
   1.278 +    bool mDepthStencilInitialized;
   1.279 +    bool mRenderTargetDescInitialized;
   1.280 +    rx::RenderTarget::Desc mRenderTargetDesc;
   1.281 +    unsigned int mCurStencilSize;
   1.282 +    unsigned int mCurDepthSize;
   1.283 +
   1.284 +    IDirect3DStateBlock9 *mMaskedClearSavedState;
   1.285 +
   1.286 +    // previously set render states
   1.287 +    bool mForceSetDepthStencilState;
   1.288 +    gl::DepthStencilState mCurDepthStencilState;
   1.289 +    int mCurStencilRef;
   1.290 +    int mCurStencilBackRef;
   1.291 +    bool mCurFrontFaceCCW;
   1.292 +
   1.293 +    bool mForceSetRasterState;
   1.294 +    gl::RasterizerState mCurRasterState;
   1.295 +
   1.296 +    bool mForceSetScissor;
   1.297 +    gl::Rectangle mCurScissor;
   1.298 +    bool mScissorEnabled;
   1.299 +
   1.300 +    bool mForceSetViewport;
   1.301 +    gl::Rectangle mCurViewport;
   1.302 +    float mCurNear;
   1.303 +    float mCurFar;
   1.304 +
   1.305 +    bool mForceSetBlendState;
   1.306 +    gl::BlendState mCurBlendState;
   1.307 +    gl::Color mCurBlendColor;
   1.308 +    GLuint mCurSampleMask;
   1.309 +
   1.310 +    // Currently applied sampler states
   1.311 +    bool mForceSetVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS];
   1.312 +    gl::SamplerState mCurVertexSamplerStates[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS];
   1.313 +
   1.314 +    bool mForceSetPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
   1.315 +    gl::SamplerState mCurPixelSamplerStates[gl::MAX_TEXTURE_IMAGE_UNITS];
   1.316 +
   1.317 +    // Currently applied textures
   1.318 +    unsigned int mCurVertexTextureSerials[gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS];
   1.319 +    unsigned int mCurPixelTextureSerials[gl::MAX_TEXTURE_IMAGE_UNITS];
   1.320 +
   1.321 +    unsigned int mAppliedIBSerial;
   1.322 +    unsigned int mAppliedProgramBinarySerial;
   1.323 +    
   1.324 +    rx::dx_VertexConstants mVertexConstants;
   1.325 +    rx::dx_PixelConstants mPixelConstants;
   1.326 +    bool mDxUniformsDirty;
   1.327 +
   1.328 +    // A pool of event queries that are currently unused.
   1.329 +    std::vector<IDirect3DQuery9*> mEventQueryPool;
   1.330 +    VertexShaderCache mVertexShaderCache;
   1.331 +    PixelShaderCache mPixelShaderCache;
   1.332 +
   1.333 +    VertexDataManager *mVertexDataManager;
   1.334 +    VertexDeclarationCache mVertexDeclarationCache;
   1.335 +
   1.336 +    IndexDataManager *mIndexDataManager;
   1.337 +    StreamingIndexBufferInterface *mLineLoopIB;
   1.338 +
   1.339 +    enum { NUM_NULL_COLORBUFFER_CACHE_ENTRIES = 12 };
   1.340 +    struct NullColorbufferCacheEntry
   1.341 +    {
   1.342 +        UINT lruCount;
   1.343 +        int width;
   1.344 +        int height;
   1.345 +        gl::Renderbuffer *buffer;
   1.346 +    } mNullColorbufferCache[NUM_NULL_COLORBUFFER_CACHE_ENTRIES];
   1.347 +    UINT mMaxNullColorbufferLRU;
   1.348 +
   1.349 +};
   1.350 +
   1.351 +}
   1.352 +#endif // LIBGLESV2_RENDERER_RENDERER9_H_

mercurial