1 #include "precompiled.h"
2 //
3 // Copyright (c) 2012-2013 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/ShaderExecutable11.h"
12
13 #include "common/debug.h"
14
15 namespace rx
16 {
17
ShaderExecutable11(const void * function,size_t length,ID3D11PixelShader * executable)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
25 mConstantBuffer = NULL;
26 }
27
ShaderExecutable11(const void * function,size_t length,ID3D11VertexShader * executable)28 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable)
29 : ShaderExecutable(function, length)
30 {
31 mVertexExecutable = executable;
32 mPixelExecutable = NULL;
33 mGeometryExecutable = NULL;
34
35 mConstantBuffer = NULL;
36 }
37
ShaderExecutable11(const void * function,size_t length,ID3D11GeometryShader * executable)38 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11GeometryShader *executable)
39 : ShaderExecutable(function, length)
40 {
41 mGeometryExecutable = executable;
42 mVertexExecutable = NULL;
43 mPixelExecutable = NULL;
44
45 mConstantBuffer = NULL;
46 }
47
~ShaderExecutable11()48 ShaderExecutable11::~ShaderExecutable11()
49 {
50 if (mVertexExecutable)
51 {
52 mVertexExecutable->Release();
53 }
54 if (mPixelExecutable)
55 {
56 mPixelExecutable->Release();
57 }
58 if (mGeometryExecutable)
59 {
60 mGeometryExecutable->Release();
61 }
62
63 if (mConstantBuffer)
64 {
65 mConstantBuffer->Release();
66 }
67 }
68
makeShaderExecutable11(ShaderExecutable * executable)69 ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable)
70 {
71 ASSERT(HAS_DYNAMIC_TYPE(ShaderExecutable11*, executable));
72 return static_cast<ShaderExecutable11*>(executable);
73 }
74
getVertexShader() const75 ID3D11VertexShader *ShaderExecutable11::getVertexShader() const
76 {
77 return mVertexExecutable;
78 }
79
getPixelShader() const80 ID3D11PixelShader *ShaderExecutable11::getPixelShader() const
81 {
82 return mPixelExecutable;
83 }
84
getGeometryShader() const85 ID3D11GeometryShader *ShaderExecutable11::getGeometryShader() const
86 {
87 return mGeometryExecutable;
88 }
89
getConstantBuffer(ID3D11Device * device,unsigned int registerCount)90 ID3D11Buffer *ShaderExecutable11::getConstantBuffer(ID3D11Device *device, unsigned int registerCount)
91 {
92 if (!mConstantBuffer && registerCount > 0)
93 {
94 D3D11_BUFFER_DESC constantBufferDescription = {0};
95 constantBufferDescription.ByteWidth = registerCount * sizeof(float[4]);
96 constantBufferDescription.Usage = D3D11_USAGE_DYNAMIC;
97 constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
98 constantBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
99 constantBufferDescription.MiscFlags = 0;
100 constantBufferDescription.StructureByteStride = 0;
101
102 HRESULT result = device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer);
103 ASSERT(SUCCEEDED(result));
104 }
105
106 return mConstantBuffer;
107 }
108
109 }