blob: d0903be467a372e736611c0ceaa7b8e79699a4ee [file] [log] [blame]
daniel@transgaming.com813bb782012-11-28 21:03:30 +00001//
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +00002// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com813bb782012-11-28 21:03:30 +00003// 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
14namespace rx
15{
16
daniel@transgaming.com7b18d0c2012-11-28 21:04:10 +000017ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11PixelShader *executable)
18 : ShaderExecutable(function, length)
daniel@transgaming.com813bb782012-11-28 21:03:30 +000019{
20 mPixelExecutable = executable;
21 mVertexExecutable = NULL;
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000022
23 mConstantBuffer = NULL;
daniel@transgaming.com813bb782012-11-28 21:03:30 +000024}
25
daniel@transgaming.com7b18d0c2012-11-28 21:04:10 +000026ShaderExecutable11::ShaderExecutable11(const void *function, size_t length, ID3D11VertexShader *executable)
27 : ShaderExecutable(function, length)
daniel@transgaming.com813bb782012-11-28 21:03:30 +000028{
29 mVertexExecutable = executable;
30 mPixelExecutable = NULL;
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000031
32 mConstantBuffer = NULL;
daniel@transgaming.com813bb782012-11-28 21:03:30 +000033}
34
35ShaderExecutable11::~ShaderExecutable11()
36{
37 if (mVertexExecutable)
38 {
39 mVertexExecutable->Release();
40 }
41 if (mPixelExecutable)
42 {
43 mPixelExecutable->Release();
44 }
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000045
46 if (mConstantBuffer)
47 {
48 mConstantBuffer->Release();
49 }
daniel@transgaming.com813bb782012-11-28 21:03:30 +000050}
51
52ShaderExecutable11 *ShaderExecutable11::makeShaderExecutable11(ShaderExecutable *executable)
53{
54 ASSERT(dynamic_cast<ShaderExecutable11*>(executable) != NULL);
55 return static_cast<ShaderExecutable11*>(executable);
56}
57
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000058ID3D11VertexShader *ShaderExecutable11::getVertexShader() const
daniel@transgaming.com813bb782012-11-28 21:03:30 +000059{
60 return mVertexExecutable;
61}
62
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000063ID3D11PixelShader *ShaderExecutable11::getPixelShader() const
daniel@transgaming.com813bb782012-11-28 21:03:30 +000064{
65 return mPixelExecutable;
66}
67
shannon.woods@transgaming.com5929ef22013-01-25 21:53:24 +000068ID3D11Buffer *ShaderExecutable11::getConstantBuffer(ID3D11Device *device, unsigned int registerCount)
shannon.woods@transgaming.com358e88d2013-01-25 21:53:11 +000069{
shannon.woods@transgaming.com5929ef22013-01-25 21:53:24 +000070 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.com358e88d2013-01-25 21:53:11 +000084 return mConstantBuffer;
85}
86
daniel@transgaming.com813bb782012-11-28 21:03:30 +000087}