1 //
2 // Copyright 2012 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 "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h"
11
12 #include "libANGLE/Context.h"
13 #include "libANGLE/renderer/d3d/d3d11/Context11.h"
14 #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
15
16 namespace rx
17 {
18
ShaderExecutable11(const void * function,size_t length,d3d11::PixelShader && executable)19 ShaderExecutable11::ShaderExecutable11(const void *function,
20 size_t length,
21 d3d11::PixelShader &&executable)
22 : ShaderExecutableD3D(function, length),
23 mPixelExecutable(std::move(executable)),
24 mVertexExecutable(),
25 mGeometryExecutable(),
26 mStreamOutExecutable(),
27 mComputeExecutable()
28 {}
29
ShaderExecutable11(const void * function,size_t length,d3d11::VertexShader && executable,d3d11::GeometryShader && streamOut)30 ShaderExecutable11::ShaderExecutable11(const void *function,
31 size_t length,
32 d3d11::VertexShader &&executable,
33 d3d11::GeometryShader &&streamOut)
34 : ShaderExecutableD3D(function, length),
35 mPixelExecutable(),
36 mVertexExecutable(std::move(executable)),
37 mGeometryExecutable(),
38 mStreamOutExecutable(std::move(streamOut)),
39 mComputeExecutable()
40 {}
41
ShaderExecutable11(const void * function,size_t length,d3d11::GeometryShader && executable)42 ShaderExecutable11::ShaderExecutable11(const void *function,
43 size_t length,
44 d3d11::GeometryShader &&executable)
45 : ShaderExecutableD3D(function, length),
46 mPixelExecutable(),
47 mVertexExecutable(),
48 mGeometryExecutable(std::move(executable)),
49 mStreamOutExecutable(),
50 mComputeExecutable()
51 {}
52
ShaderExecutable11(const void * function,size_t length,d3d11::ComputeShader && executable)53 ShaderExecutable11::ShaderExecutable11(const void *function,
54 size_t length,
55 d3d11::ComputeShader &&executable)
56 : ShaderExecutableD3D(function, length),
57 mPixelExecutable(),
58 mVertexExecutable(),
59 mGeometryExecutable(),
60 mStreamOutExecutable(),
61 mComputeExecutable(std::move(executable))
62 {}
63
~ShaderExecutable11()64 ShaderExecutable11::~ShaderExecutable11() {}
65
getVertexShader() const66 const d3d11::VertexShader &ShaderExecutable11::getVertexShader() const
67 {
68 return mVertexExecutable;
69 }
70
getPixelShader() const71 const d3d11::PixelShader &ShaderExecutable11::getPixelShader() const
72 {
73 return mPixelExecutable;
74 }
75
getGeometryShader() const76 const d3d11::GeometryShader &ShaderExecutable11::getGeometryShader() const
77 {
78 return mGeometryExecutable;
79 }
80
getStreamOutShader() const81 const d3d11::GeometryShader &ShaderExecutable11::getStreamOutShader() const
82 {
83 return mStreamOutExecutable;
84 }
85
getComputeShader() const86 const d3d11::ComputeShader &ShaderExecutable11::getComputeShader() const
87 {
88 return mComputeExecutable;
89 }
90
UniformStorage11(size_t initialSize)91 UniformStorage11::UniformStorage11(size_t initialSize)
92 : UniformStorageD3D(initialSize), mConstantBuffer()
93 {}
94
~UniformStorage11()95 UniformStorage11::~UniformStorage11() {}
96
getConstantBuffer(const gl::Context * context,Renderer11 * renderer,const d3d11::Buffer ** bufferOut)97 angle::Result UniformStorage11::getConstantBuffer(const gl::Context *context,
98 Renderer11 *renderer,
99 const d3d11::Buffer **bufferOut)
100 {
101 if (size() > 0 && !mConstantBuffer.valid())
102 {
103 D3D11_BUFFER_DESC desc = {};
104 desc.ByteWidth = static_cast<unsigned int>(size());
105 desc.Usage = D3D11_USAGE_DEFAULT;
106 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
107
108 ANGLE_TRY(
109 renderer->allocateResource(GetImplAs<Context11>(context), desc, &mConstantBuffer));
110 }
111
112 *bufferOut = &mConstantBuffer;
113 return angle::Result::Continue;
114 }
115
116 } // namespace rx
117