1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "RenderAPI/BsGpuProgram.h"
4#include "RenderAPI/BsRenderAPICapabilities.h"
5#include "RenderAPI/BsRenderAPI.h"
6#include "RenderAPI/BsGpuParams.h"
7#include "RenderAPI/BsGpuParamDesc.h"
8#include "Managers/BsGpuProgramManager.h"
9#include "Private/RTTI/BsGpuProgramRTTI.h"
10
11namespace bs
12{
13 GpuProgramBytecode::~GpuProgramBytecode()
14 {
15 if(instructions.data)
16 bs_free(instructions.data);
17 }
18
19 RTTITypeBase* GpuProgramBytecode::getRTTIStatic()
20 {
21 return GpuProgramBytecodeRTTI::instance();
22 }
23
24 RTTITypeBase* GpuProgramBytecode::getRTTI() const
25 {
26 return GpuProgramBytecode::getRTTIStatic();
27 }
28
29 GpuProgram::GpuProgram(const GPU_PROGRAM_DESC& desc)
30 : mNeedsAdjacencyInfo(desc.requiresAdjacency), mLanguage(desc.language), mType(desc.type)
31 , mEntryPoint(desc.entryPoint), mSource(desc.source)
32 {
33
34 }
35
36 bool GpuProgram::isCompiled() const
37 {
38 return getCore()->isCompiled();
39 }
40
41 String GpuProgram::getCompileErrorMessage() const
42 {
43 return getCore()->getCompileErrorMessage();
44 }
45
46 SPtr<GpuParamDesc> GpuProgram::getParamDesc() const
47 {
48 return getCore()->getParamDesc();
49 }
50
51 SPtr<ct::GpuProgram> GpuProgram::getCore() const
52 {
53 return std::static_pointer_cast<ct::GpuProgram>(mCoreSpecific);
54 }
55
56 SPtr<ct::CoreObject> GpuProgram::createCore() const
57 {
58 GPU_PROGRAM_DESC desc;
59 desc.source = mSource;
60 desc.entryPoint = mEntryPoint;
61 desc.language = mLanguage;
62 desc.type = mType;
63 desc.requiresAdjacency = mNeedsAdjacencyInfo;
64 desc.bytecode = mBytecode;
65
66 return ct::GpuProgramManager::instance().createInternal(desc);
67 }
68
69 SPtr<GpuProgram> GpuProgram::create(const GPU_PROGRAM_DESC& desc)
70 {
71 return GpuProgramManager::instance().create(desc);
72 }
73
74 /************************************************************************/
75 /* SERIALIZATION */
76 /************************************************************************/
77 RTTITypeBase* GpuProgram::getRTTIStatic()
78 {
79 return GpuProgramRTTI::instance();
80 }
81
82 RTTITypeBase* GpuProgram::getRTTI() const
83 {
84 return GpuProgram::getRTTIStatic();
85 }
86
87 namespace ct
88 {
89 GpuProgram::GpuProgram(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask)
90 : mNeedsAdjacencyInfo(desc.requiresAdjacency), mType(desc.type), mEntryPoint(desc.entryPoint), mSource(desc.source)
91 , mBytecode(desc.bytecode)
92 {
93 mParametersDesc = bs_shared_ptr_new<GpuParamDesc>();
94 }
95
96 GpuProgram::~GpuProgram()
97 { }
98
99 bool GpuProgram::isSupported() const
100 {
101 return true;
102 }
103
104 SPtr<GpuProgram> GpuProgram::create(const GPU_PROGRAM_DESC& desc, GpuDeviceFlags deviceMask)
105 {
106 return GpuProgramManager::instance().create(desc, deviceMask);
107 }
108
109 SPtr<GpuProgramBytecode> GpuProgram::compileBytecode(const GPU_PROGRAM_DESC& desc)
110 {
111 return GpuProgramManager::instance().compileBytecode(desc);
112 }
113 }
114}