blob: 6a5b90c3ab76abcb57fc63c40d26be0e647e156c [file] [log] [blame]
Jamie Madill9e54b5a2016-05-25 12:57:39 -04001//
2// Copyright 2016 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6// ProgramVk.cpp:
7// Implements the class methods for ProgramVk.
8//
9
10#include "libANGLE/renderer/vulkan/ProgramVk.h"
11
12#include "common/debug.h"
Jamie Madillc564c072017-06-01 12:45:42 -040013#include "libANGLE/Context.h"
Jamie Madill8ecf7f92017-01-13 17:29:52 -050014#include "libANGLE/renderer/vulkan/ContextVk.h"
15#include "libANGLE/renderer/vulkan/GlslangWrapper.h"
16#include "libANGLE/renderer/vulkan/RendererVk.h"
Jamie Madill9e54b5a2016-05-25 12:57:39 -040017
18namespace rx
19{
20
21ProgramVk::ProgramVk(const gl::ProgramState &state) : ProgramImpl(state)
22{
23}
24
25ProgramVk::~ProgramVk()
26{
27}
28
Jamie Madillc564c072017-06-01 12:45:42 -040029void ProgramVk::destroy(const gl::Context *contextImpl)
Jamie Madill5deea722017-02-16 10:44:46 -050030{
Jamie Madillc564c072017-06-01 12:45:42 -040031 VkDevice device = GetImplAs<ContextVk>(contextImpl)->getDevice();
Jamie Madill5deea722017-02-16 10:44:46 -050032
33 mLinkedFragmentModule.destroy(device);
34 mLinkedVertexModule.destroy(device);
35 mPipelineLayout.destroy(device);
36}
37
Jamie Madill9cf9e872017-06-05 12:59:25 -040038gl::LinkResult ProgramVk::load(const gl::Context *contextImpl,
39 gl::InfoLog &infoLog,
40 gl::BinaryInputStream *stream)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040041{
42 UNIMPLEMENTED();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -050043 return gl::InternalError();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040044}
45
Jamie Madill83418fb2017-06-05 12:59:24 -040046void ProgramVk::save(gl::BinaryOutputStream *stream)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040047{
48 UNIMPLEMENTED();
Jamie Madill9e54b5a2016-05-25 12:57:39 -040049}
50
51void ProgramVk::setBinaryRetrievableHint(bool retrievable)
52{
53 UNIMPLEMENTED();
54}
55
Yunchao He61afff12017-03-14 15:34:03 +080056void ProgramVk::setSeparable(bool separable)
57{
58 UNIMPLEMENTED();
59}
60
Jamie Madill9cf9e872017-06-05 12:59:25 -040061gl::LinkResult ProgramVk::link(const gl::Context *glContext,
62 const gl::VaryingPacking &packing,
63 gl::InfoLog &infoLog)
Jamie Madill9e54b5a2016-05-25 12:57:39 -040064{
Jamie Madillc564c072017-06-01 12:45:42 -040065 ContextVk *context = GetImplAs<ContextVk>(glContext);
Jamie Madill8ecf7f92017-01-13 17:29:52 -050066 RendererVk *renderer = context->getRenderer();
67 GlslangWrapper *glslangWrapper = renderer->getGlslangWrapper();
68
Jamie Madillbd044ed2017-06-05 12:59:21 -040069 const std::string &vertexSource =
70 mState.getAttachedVertexShader()->getTranslatedSource(glContext);
71 const std::string &fragmentSource =
72 mState.getAttachedFragmentShader()->getTranslatedSource(glContext);
Jamie Madill8ecf7f92017-01-13 17:29:52 -050073
74 std::vector<uint32_t> vertexCode;
75 std::vector<uint32_t> fragmentCode;
76 bool linkSuccess = false;
77 ANGLE_TRY_RESULT(
78 glslangWrapper->linkProgram(vertexSource, fragmentSource, &vertexCode, &fragmentCode),
79 linkSuccess);
80 if (!linkSuccess)
81 {
82 return false;
83 }
84
Jamie Madill5deea722017-02-16 10:44:46 -050085 vk::ShaderModule vertexModule;
86 vk::ShaderModule fragmentModule;
87 VkDevice device = renderer->getDevice();
Jamie Madill8ecf7f92017-01-13 17:29:52 -050088
89 {
90 VkShaderModuleCreateInfo vertexShaderInfo;
91 vertexShaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
92 vertexShaderInfo.pNext = nullptr;
93 vertexShaderInfo.flags = 0;
94 vertexShaderInfo.codeSize = vertexCode.size() * sizeof(uint32_t);
95 vertexShaderInfo.pCode = vertexCode.data();
Jamie Madill5deea722017-02-16 10:44:46 -050096 ANGLE_TRY(vertexModule.init(device, vertexShaderInfo));
Jamie Madill8ecf7f92017-01-13 17:29:52 -050097 }
98
99 {
100 VkShaderModuleCreateInfo fragmentShaderInfo;
101 fragmentShaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
102 fragmentShaderInfo.pNext = nullptr;
103 fragmentShaderInfo.flags = 0;
104 fragmentShaderInfo.codeSize = fragmentCode.size() * sizeof(uint32_t);
105 fragmentShaderInfo.pCode = fragmentCode.data();
106
Jamie Madill5deea722017-02-16 10:44:46 -0500107 ANGLE_TRY(fragmentModule.init(device, fragmentShaderInfo));
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500108 }
109
Jamie Madill5deea722017-02-16 10:44:46 -0500110 mLinkedVertexModule.retain(device, std::move(vertexModule));
111 mLinkedFragmentModule.retain(device, std::move(fragmentModule));
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500112
Jamie Madill72106562017-03-24 14:18:50 -0400113 // TODO(jmadill): Use pipeline cache.
114 context->invalidateCurrentPipeline();
115
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500116 return true;
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400117}
118
119GLboolean ProgramVk::validate(const gl::Caps &caps, gl::InfoLog *infoLog)
120{
121 UNIMPLEMENTED();
122 return GLboolean();
123}
124
125void ProgramVk::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
126{
127 UNIMPLEMENTED();
128}
129
130void ProgramVk::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
131{
132 UNIMPLEMENTED();
133}
134
135void ProgramVk::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
136{
137 UNIMPLEMENTED();
138}
139
140void ProgramVk::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
141{
142 UNIMPLEMENTED();
143}
144
145void ProgramVk::setUniform1iv(GLint location, GLsizei count, const GLint *v)
146{
147 UNIMPLEMENTED();
148}
149
150void ProgramVk::setUniform2iv(GLint location, GLsizei count, const GLint *v)
151{
152 UNIMPLEMENTED();
153}
154
155void ProgramVk::setUniform3iv(GLint location, GLsizei count, const GLint *v)
156{
157 UNIMPLEMENTED();
158}
159
160void ProgramVk::setUniform4iv(GLint location, GLsizei count, const GLint *v)
161{
162 UNIMPLEMENTED();
163}
164
165void ProgramVk::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
166{
167 UNIMPLEMENTED();
168}
169
170void ProgramVk::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
171{
172 UNIMPLEMENTED();
173}
174
175void ProgramVk::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
176{
177 UNIMPLEMENTED();
178}
179
180void ProgramVk::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
181{
182 UNIMPLEMENTED();
183}
184
185void ProgramVk::setUniformMatrix2fv(GLint location,
186 GLsizei count,
187 GLboolean transpose,
188 const GLfloat *value)
189{
190 UNIMPLEMENTED();
191}
192
193void ProgramVk::setUniformMatrix3fv(GLint location,
194 GLsizei count,
195 GLboolean transpose,
196 const GLfloat *value)
197{
198 UNIMPLEMENTED();
199}
200
201void ProgramVk::setUniformMatrix4fv(GLint location,
202 GLsizei count,
203 GLboolean transpose,
204 const GLfloat *value)
205{
206 UNIMPLEMENTED();
207}
208
209void ProgramVk::setUniformMatrix2x3fv(GLint location,
210 GLsizei count,
211 GLboolean transpose,
212 const GLfloat *value)
213{
214 UNIMPLEMENTED();
215}
216
217void ProgramVk::setUniformMatrix3x2fv(GLint location,
218 GLsizei count,
219 GLboolean transpose,
220 const GLfloat *value)
221{
222 UNIMPLEMENTED();
223}
224
225void ProgramVk::setUniformMatrix2x4fv(GLint location,
226 GLsizei count,
227 GLboolean transpose,
228 const GLfloat *value)
229{
230 UNIMPLEMENTED();
231}
232
233void ProgramVk::setUniformMatrix4x2fv(GLint location,
234 GLsizei count,
235 GLboolean transpose,
236 const GLfloat *value)
237{
238 UNIMPLEMENTED();
239}
240
241void ProgramVk::setUniformMatrix3x4fv(GLint location,
242 GLsizei count,
243 GLboolean transpose,
244 const GLfloat *value)
245{
246 UNIMPLEMENTED();
247}
248
249void ProgramVk::setUniformMatrix4x3fv(GLint location,
250 GLsizei count,
251 GLboolean transpose,
252 const GLfloat *value)
253{
254 UNIMPLEMENTED();
255}
256
257void ProgramVk::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding)
258{
259 UNIMPLEMENTED();
260}
261
262bool ProgramVk::getUniformBlockSize(const std::string &blockName, size_t *sizeOut) const
263{
264 UNIMPLEMENTED();
265 return bool();
266}
267
268bool ProgramVk::getUniformBlockMemberInfo(const std::string &memberUniformName,
269 sh::BlockMemberInfo *memberInfoOut) const
270{
271 UNIMPLEMENTED();
272 return bool();
273}
274
Sami Väisänen46eaa942016-06-29 10:26:37 +0300275void ProgramVk::setPathFragmentInputGen(const std::string &inputName,
276 GLenum genMode,
277 GLint components,
278 const GLfloat *coeffs)
279{
280 UNIMPLEMENTED();
281}
282
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500283const vk::ShaderModule &ProgramVk::getLinkedVertexModule() const
284{
285 ASSERT(mLinkedVertexModule.getHandle() != VK_NULL_HANDLE);
286 return mLinkedVertexModule;
287}
288
289const vk::ShaderModule &ProgramVk::getLinkedFragmentModule() const
290{
291 ASSERT(mLinkedFragmentModule.getHandle() != VK_NULL_HANDLE);
292 return mLinkedFragmentModule;
293}
294
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500295gl::ErrorOrResult<vk::PipelineLayout *> ProgramVk::getPipelineLayout(VkDevice device)
296{
Jamie Madill5deea722017-02-16 10:44:46 -0500297 vk::PipelineLayout newLayout;
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500298
299 // TODO(jmadill): Descriptor sets.
300 VkPipelineLayoutCreateInfo createInfo;
301 createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
302 createInfo.pNext = nullptr;
303 createInfo.flags = 0;
304 createInfo.setLayoutCount = 0;
305 createInfo.pSetLayouts = nullptr;
306 createInfo.pushConstantRangeCount = 0;
307 createInfo.pPushConstantRanges = nullptr;
308
Jamie Madill5deea722017-02-16 10:44:46 -0500309 ANGLE_TRY(newLayout.init(device, createInfo));
310 mPipelineLayout.retain(device, std::move(newLayout));
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500311
312 return &mPipelineLayout;
313}
314
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400315} // namespace rx