daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 1 | // |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 2 | // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 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/ShaderExecutable11.h" |
| 11 | |
| 12 | #include "common/debug.h" |
| 13 | |
| 14 | namespace rx |
| 15 | { |
| 16 | |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 17 | ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11PixelShader *executable) |
| 18 | : ShaderExecutable(function, length) |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 19 | { |
| 20 | mPixelExecutable = executable; |
| 21 | mVertexExecutable = NULL; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 22 | mGeometryExecutable = NULL; |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 23 | |
| 24 | mConstantBuffer = NULL; |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 25 | } |
| 26 | |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 27 | ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable) |
| 28 | : ShaderExecutable(function, length) |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 29 | { |
| 30 | mVertexExecutable = executable; |
| 31 | mPixelExecutable = NULL; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 32 | mGeometryExecutable = NULL; |
| 33 | |
| 34 | mConstantBuffer = NULL; |
| 35 | } |
| 36 | |
| 37 | ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11GeometryShader *executable) |
| 38 | : ShaderExecutable(function, length) |
| 39 | { |
| 40 | mGeometryExecutable = executable; |
| 41 | mVertexExecutable = NULL; |
| 42 | mPixelExecutable = NULL; |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 43 | |
| 44 | mConstantBuffer = NULL; |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ShaderExecutable11::~ShaderExecutable11() |
| 48 | { |
| 49 | if (mVertexExecutable) |
| 50 | { |
| 51 | mVertexExecutable->Release(); |
| 52 | } |
| 53 | if (mPixelExecutable) |
| 54 | { |
| 55 | mPixelExecutable->Release(); |
| 56 | } |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 57 | if (mGeometryExecutable) |
| 58 | { |
| 59 | mGeometryExecutable->Release(); |
| 60 | } |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 61 | |
| 62 | if (mConstantBuffer) |
| 63 | { |
| 64 | mConstantBuffer->Release(); |
| 65 | } |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable) |
| 69 | { |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 70 | ASSERT(HAS_DYNAMIC_TYPE(ShaderExecutable11*, executable)); |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 71 | return static_cast<ShaderExecutable11*>(executable); |
| 72 | } |
| 73 | |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 74 | ID3D11VertexShader *ShaderExecutable11::getVertexShader() const |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 75 | { |
| 76 | return mVertexExecutable; |
| 77 | } |
| 78 | |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 79 | ID3D11PixelShader *ShaderExecutable11::getPixelShader() const |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 80 | { |
| 81 | return mPixelExecutable; |
| 82 | } |
| 83 | |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 84 | ID3D11GeometryShader *ShaderExecutable11::getGeometryShader() const |
| 85 | { |
| 86 | return mGeometryExecutable; |
| 87 | } |
| 88 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 89 | ID3D11Buffer *ShaderExecutable11::getConstantBuffer(ID3D11Device *device, unsigned int registerCount) |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 90 | { |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 91 | if (!mConstantBuffer && registerCount > 0) |
| 92 | { |
| 93 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 94 | constantBufferDescription.ByteWidth = registerCount * sizeof(float[4]); |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame^] | 95 | constantBufferDescription.Usage = D3D11_USAGE_DYNAMIC; |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 96 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame^] | 97 | constantBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 98 | constantBufferDescription.MiscFlags = 0; |
| 99 | constantBufferDescription.StructureByteStride = 0; |
| 100 | |
| 101 | HRESULT result = device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer); |
| 102 | ASSERT(SUCCEEDED(result)); |
| 103 | } |
| 104 | |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 105 | return mConstantBuffer; |
| 106 | } |
| 107 | |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 108 | } |