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.
7 // ShaderExecutable11.cpp: Implements a D3D11-specific class to contain shader
8 // executable implementation details.
10 #include "libGLESv2/renderer/d3d/d3d11/ShaderExecutable11.h"
11 #include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
16 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11PixelShader *executable)
17 : ShaderExecutable(function, length)
19 mPixelExecutable = executable;
20 mVertexExecutable = NULL;
21 mGeometryExecutable = NULL;
22 mStreamOutExecutable = NULL;
25 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable, ID3D11GeometryShader *streamOut)
26 : ShaderExecutable(function, length)
28 mVertexExecutable = executable;
29 mPixelExecutable = NULL;
30 mGeometryExecutable = NULL;
31 mStreamOutExecutable = streamOut;
34 ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11GeometryShader *executable)
35 : ShaderExecutable(function, length)
37 mGeometryExecutable = executable;
38 mVertexExecutable = NULL;
39 mPixelExecutable = NULL;
40 mStreamOutExecutable = NULL;
43 ShaderExecutable11::~ShaderExecutable11()
45 SafeRelease(mVertexExecutable);
46 SafeRelease(mPixelExecutable);
47 SafeRelease(mGeometryExecutable);
48 SafeRelease(mStreamOutExecutable);
51 ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable)
53 ASSERT(HAS_DYNAMIC_TYPE(ShaderExecutable11*, executable));
54 return static_cast<ShaderExecutable11*>(executable);
57 ID3D11VertexShader *ShaderExecutable11::getVertexShader() const
59 return mVertexExecutable;
62 ID3D11PixelShader *ShaderExecutable11::getPixelShader() const
64 return mPixelExecutable;
67 ID3D11GeometryShader *ShaderExecutable11::getGeometryShader() const
69 return mGeometryExecutable;
72 ID3D11GeometryShader *ShaderExecutable11::getStreamOutShader() const
74 return mStreamOutExecutable;
77 UniformStorage11::UniformStorage11(Renderer11 *renderer, size_t initialSize)
78 : UniformStorage(initialSize),
81 ID3D11Device *d3d11Device = renderer->getDevice();
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;
93 HRESULT result = d3d11Device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer);
94 UNUSED_ASSERTION_VARIABLE(result);
95 ASSERT(SUCCEEDED(result));
99 UniformStorage11::~UniformStorage11()
101 SafeRelease(mConstantBuffer);
104 const UniformStorage11 *UniformStorage11::makeUniformStorage11(const UniformStorage *uniformStorage)
106 ASSERT(HAS_DYNAMIC_TYPE(const UniformStorage11*, uniformStorage));
107 return static_cast<const UniformStorage11*>(uniformStorage);