Home | History | Annotate | Download | only in d3d11
      1 #include "precompiled.h"
      2 //
      3 // Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved.
      4 // Use of this source code is governed by a BSD-style license that can be
      5 // found in the LICENSE file.
      6 //
      7 
      8 // ShaderExecutable11.cpp: Implements a D3D11-specific class to contain shader
      9 // executable implementation details.
     10 
     11 #include "libGLESv2/renderer/d3d11/ShaderExecutable11.h"
     12 
     13 #include "libGLESv2/renderer/d3d11/Renderer11.h"
     14 
     15 namespace rx
     16 {
     17 
     18 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11PixelShader *executable)
     19     : ShaderExecutable(function, length)
     20 {
     21     mPixelExecutable = executable;
     22     mVertexExecutable = NULL;
     23     mGeometryExecutable = NULL;
     24     mStreamOutExecutable = NULL;
     25 }
     26 
     27 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable, ID3D11GeometryShader *streamOut)
     28     : ShaderExecutable(function, length)
     29 {
     30     mVertexExecutable = executable;
     31     mPixelExecutable = NULL;
     32     mGeometryExecutable = NULL;
     33     mStreamOutExecutable = streamOut;
     34 }
     35 
     36 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11GeometryShader *executable)
     37     : ShaderExecutable(function, length)
     38 {
     39     mGeometryExecutable = executable;
     40     mVertexExecutable = NULL;
     41     mPixelExecutable = NULL;
     42     mStreamOutExecutable = NULL;
     43 }
     44 
     45 ShaderExecutable11::~ShaderExecutable11()
     46 {
     47     SafeRelease(mVertexExecutable);
     48     SafeRelease(mPixelExecutable);
     49     SafeRelease(mGeometryExecutable);
     50     SafeRelease(mStreamOutExecutable);
     51 }
     52 
     53 ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable)
     54 {
     55     ASSERT(HAS_DYNAMIC_TYPE(ShaderExecutable11*, executable));
     56     return static_cast<ShaderExecutable11*>(executable);
     57 }
     58 
     59 ID3D11VertexShader *ShaderExecutable11::getVertexShader() const
     60 {
     61     return mVertexExecutable;
     62 }
     63 
     64 ID3D11PixelShader *ShaderExecutable11::getPixelShader() const
     65 {
     66     return mPixelExecutable;
     67 }
     68 
     69 ID3D11GeometryShader *ShaderExecutable11::getGeometryShader() const
     70 {
     71     return mGeometryExecutable;
     72 }
     73 
     74 ID3D11GeometryShader *ShaderExecutable11::getStreamOutShader() const
     75 {
     76     return mStreamOutExecutable;
     77 }
     78 
     79 UniformStorage11::UniformStorage11(Renderer11 *renderer, size_t initialSize)
     80     : UniformStorage(initialSize),
     81       mConstantBuffer(NULL)
     82 {
     83     ID3D11Device *d3d11Device = renderer->getDevice();
     84 
     85     if (initialSize > 0)
     86     {
     87         D3D11_BUFFER_DESC constantBufferDescription = {0};
     88         constantBufferDescription.ByteWidth = initialSize;
     89         constantBufferDescription.Usage = D3D11_USAGE_DYNAMIC;
     90         constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
     91         constantBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
     92         constantBufferDescription.MiscFlags = 0;
     93         constantBufferDescription.StructureByteStride = 0;
     94 
     95         HRESULT result = d3d11Device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer);
     96         UNUSED_ASSERTION_VARIABLE(result);
     97         ASSERT(SUCCEEDED(result));
     98     }
     99 }
    100 
    101 UniformStorage11::~UniformStorage11()
    102 {
    103     SafeRelease(mConstantBuffer);
    104 }
    105 
    106 const UniformStorage11 *UniformStorage11::makeUniformStorage11(const UniformStorage *uniformStorage)
    107 {
    108     ASSERT(HAS_DYNAMIC_TYPE(const UniformStorage11*, uniformStorage));
    109     return static_cast<const UniformStorage11*>(uniformStorage);
    110 }
    111 
    112 }
    113