blob: e1eb56033483ffb0902290e59686dd4c0d8b20c2 [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com813bb782012-11-28 21:03:30 +00002//
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +00003// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com813bb782012-11-28 21:03:30 +00004// 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
15namespace rx
16{
17
daniel@transgaming.com7b18d0c2012-11-28 21:04:10 +000018ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11PixelShader *executable)
19 : ShaderExecutable(function, length)
daniel@transgaming.com813bb782012-11-28 21:03:30 +000020{
21 mPixelExecutable = executable;
22 mVertexExecutable = NULL;
shannon.woods@transgaming.com3e773bb2013-01-25 21:55:47 +000023 mGeometryExecutable = NULL;
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000024
25 mConstantBuffer = NULL;
daniel@transgaming.com813bb782012-11-28 21:03:30 +000026}
27
daniel@transgaming.com7b18d0c2012-11-28 21:04:10 +000028ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable)
29 : ShaderExecutable(function, length)
daniel@transgaming.com813bb782012-11-28 21:03:30 +000030{
31 mVertexExecutable = executable;
32 mPixelExecutable = NULL;
shannon.woods@transgaming.com3e773bb2013-01-25 21:55:47 +000033 mGeometryExecutable = NULL;
34
35 mConstantBuffer = NULL;
36}
37
38ShaderExecutable11::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.com358e88d2013-01-25 21:53:11 +000044
45 mConstantBuffer = NULL;
daniel@transgaming.com813bb782012-11-28 21:03:30 +000046}
47
48ShaderExecutable11::~ShaderExecutable11()
49{
50 if (mVertexExecutable)
51 {
52 mVertexExecutable->Release();
53 }
54 if (mPixelExecutable)
55 {
56 mPixelExecutable->Release();
57 }
shannon.woods@transgaming.com3e773bb2013-01-25 21:55:47 +000058 if (mGeometryExecutable)
59 {
60 mGeometryExecutable->Release();
61 }
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000062
63 if (mConstantBuffer)
64 {
65 mConstantBuffer->Release();
66 }
daniel@transgaming.com813bb782012-11-28 21:03:30 +000067}
68
69ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable)
70{
apatrick@chromium.org8b400b12013-01-30 21:53:40 +000071 ASSERT(HAS_DYNAMIC_TYPE(ShaderExecutable11*, executable));
daniel@transgaming.com813bb782012-11-28 21:03:30 +000072 return static_cast<ShaderExecutable11*>(executable);
73}
74
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000075ID3D11VertexShader *ShaderExecutable11::getVertexShader() const
daniel@transgaming.com813bb782012-11-28 21:03:30 +000076{
77 return mVertexExecutable;
78}
79
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000080ID3D11PixelShader *ShaderExecutable11::getPixelShader() const
daniel@transgaming.com813bb782012-11-28 21:03:30 +000081{
82 return mPixelExecutable;
83}
84
shannon.woods@transgaming.com3e773bb2013-01-25 21:55:47 +000085ID3D11GeometryShader *ShaderExecutable11::getGeometryShader() const
86{
87 return mGeometryExecutable;
88}
89
shannon.woods@transgaming.com5929ef22013-01-25 21:53:24 +000090ID3D11Buffer *ShaderExecutable11::getConstantBuffer(ID3D11Device *device, unsigned int registerCount)
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000091{
shannon.woods@transgaming.com5929ef22013-01-25 21:53:24 +000092 if (!mConstantBuffer && registerCount > 0)
93 {
94 D3D11_BUFFER_DESC constantBufferDescription = {0};
95 constantBufferDescription.ByteWidth = registerCount * sizeof(float[4]);
shannon.woods@transgaming.com09bf2a72013-02-28 23:12:54 +000096 constantBufferDescription.Usage = D3D11_USAGE_DYNAMIC;
shannon.woods@transgaming.com5929ef22013-01-25 21:53:24 +000097 constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
shannon.woods@transgaming.com09bf2a72013-02-28 23:12:54 +000098 constantBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
shannon.woods@transgaming.com5929ef22013-01-25 21:53:24 +000099 constantBufferDescription.MiscFlags = 0;
100 constantBufferDescription.StructureByteStride = 0;
101
102 HRESULT result = device->CreateBuffer(&constantBufferDescription, NULL, &mConstantBuffer);
103 ASSERT(SUCCEEDED(result));
104 }
105
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +0000106 return mConstantBuffer;
107}
108
daniel@transgaming.com813bb782012-11-28 21:03:30 +0000109}