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