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