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 | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 22 | |
| 23 | mConstantBuffer = NULL; |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 24 | } |
| 25 | |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 26 | ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable) |
| 27 | : ShaderExecutable(function, length) |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 28 | { |
| 29 | mVertexExecutable = executable; |
| 30 | mPixelExecutable = NULL; |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 31 | |
| 32 | mConstantBuffer = NULL; |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | ShaderExecutable11::~ShaderExecutable11() |
| 36 | { |
| 37 | if (mVertexExecutable) |
| 38 | { |
| 39 | mVertexExecutable->Release(); |
| 40 | } |
| 41 | if (mPixelExecutable) |
| 42 | { |
| 43 | mPixelExecutable->Release(); |
| 44 | } |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 45 | |
| 46 | if (mConstantBuffer) |
| 47 | { |
| 48 | mConstantBuffer->Release(); |
| 49 | } |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable) |
| 53 | { |
| 54 | ASSERT(dynamic_cast<ShaderExecutable11*>(executable) != NULL); |
| 55 | return static_cast<ShaderExecutable11*>(executable); |
| 56 | } |
| 57 | |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 58 | ID3D11VertexShader *ShaderExecutable11::getVertexShader() const |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 59 | { |
| 60 | return mVertexExecutable; |
| 61 | } |
| 62 | |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 63 | ID3D11PixelShader *ShaderExecutable11::getPixelShader() const |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 64 | { |
| 65 | return mPixelExecutable; |
| 66 | } |
| 67 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame^] | 68 | ID3D11Buffer *ShaderExecutable11::getConstantBuffer(ID3D11Device *device, unsigned int registerCount) |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 69 | { |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame^] | 70 | if (!mConstantBuffer && registerCount > 0) |
| 71 | { |
| 72 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 73 | constantBufferDescription.ByteWidth = registerCount * sizeof(float[4]); |
| 74 | constantBufferDescription.Usage = D3D11_USAGE_DEFAULT; |
| 75 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 76 | constantBufferDescription.CPUAccessFlags = 0; |
| 77 | constantBufferDescription.MiscFlags = 0; |
| 78 | constantBufferDescription.StructureByteStride = 0; |
| 79 | |
| 80 | HRESULT result = device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer); |
| 81 | ASSERT(SUCCEEDED(result)); |
| 82 | } |
| 83 | |
shannon.woods@transgaming.com | 358e88d | 2013-01-25 21:53:11 +0000 | [diff] [blame] | 84 | return mConstantBuffer; |
| 85 | } |
| 86 | |
daniel@transgaming.com | 813bb78 | 2012-11-28 21:03:30 +0000 | [diff] [blame] | 87 | } |