Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1 | // |
| 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 Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 13 | #include "libANGLE/Context.h" |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 14 | #include "libANGLE/ProgramLinkedResources.h" |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 15 | #include "libANGLE/renderer/renderer_utils.h" |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 16 | #include "libANGLE/renderer/vulkan/BufferVk.h" |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 17 | #include "libANGLE/renderer/vulkan/ContextVk.h" |
| 18 | #include "libANGLE/renderer/vulkan/GlslangWrapper.h" |
| 19 | #include "libANGLE/renderer/vulkan/RendererVk.h" |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 20 | #include "libANGLE/renderer/vulkan/TextureVk.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 21 | |
| 22 | namespace rx |
| 23 | { |
| 24 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 25 | namespace |
| 26 | { |
| 27 | |
Jamie Madill | f361437 | 2018-03-31 14:19:14 -0400 | [diff] [blame] | 28 | constexpr size_t kUniformBlockDynamicBufferMinSize = 256 * 128; |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 29 | |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 30 | void InitDefaultUniformBlock(const std::vector<sh::Uniform> &uniforms, |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 31 | gl::Shader *shader, |
| 32 | sh::BlockLayoutMap *blockLayoutMapOut, |
| 33 | size_t *blockSizeOut) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 34 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 35 | if (uniforms.empty()) |
| 36 | { |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 37 | *blockSizeOut = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 38 | return; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | sh::Std140BlockEncoder blockEncoder; |
Olli Etuaho | 3de2703 | 2017-11-30 12:16:47 +0200 | [diff] [blame] | 42 | sh::GetUniformBlockInfo(uniforms, "", &blockEncoder, blockLayoutMapOut); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 43 | |
Jamie Madill | 4e712be | 2019-01-03 13:53:59 -0500 | [diff] [blame] | 44 | size_t blockSize = blockEncoder.getCurrentOffset(); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 45 | |
| 46 | // TODO(jmadill): I think we still need a valid block for the pipeline even if zero sized. |
| 47 | if (blockSize == 0) |
| 48 | { |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 49 | *blockSizeOut = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 50 | return; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 53 | *blockSizeOut = blockSize; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 54 | return; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | template <typename T> |
| 58 | void UpdateDefaultUniformBlock(GLsizei count, |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 59 | uint32_t arrayIndex, |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 60 | int componentCount, |
| 61 | const T *v, |
| 62 | const sh::BlockMemberInfo &layoutInfo, |
| 63 | angle::MemoryBuffer *uniformData) |
| 64 | { |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 65 | const int elementSize = sizeof(T) * componentCount; |
| 66 | |
| 67 | uint8_t *dst = uniformData->data() + layoutInfo.offset; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 68 | if (layoutInfo.arrayStride == 0 || layoutInfo.arrayStride == elementSize) |
| 69 | { |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 70 | uint32_t arrayOffset = arrayIndex * layoutInfo.arrayStride; |
| 71 | uint8_t *writePtr = dst + arrayOffset; |
Geoff Lang | beb0c94 | 2018-09-27 11:22:23 -0400 | [diff] [blame] | 72 | ASSERT(writePtr + (elementSize * count) <= uniformData->data() + uniformData->size()); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 73 | memcpy(writePtr, v, elementSize * count); |
| 74 | } |
| 75 | else |
| 76 | { |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 77 | // Have to respect the arrayStride between each element of the array. |
| 78 | int maxIndex = arrayIndex + count; |
| 79 | for (int writeIndex = arrayIndex, readIndex = 0; writeIndex < maxIndex; |
| 80 | writeIndex++, readIndex++) |
| 81 | { |
| 82 | const int arrayOffset = writeIndex * layoutInfo.arrayStride; |
| 83 | uint8_t *writePtr = dst + arrayOffset; |
Luc Ferron | e9465a6 | 2018-06-04 10:41:52 -0400 | [diff] [blame] | 84 | const T *readPtr = v + (readIndex * componentCount); |
Geoff Lang | beb0c94 | 2018-09-27 11:22:23 -0400 | [diff] [blame] | 85 | ASSERT(writePtr + elementSize <= uniformData->data() + uniformData->size()); |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 86 | memcpy(writePtr, readPtr, elementSize); |
| 87 | } |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 91 | template <typename T> |
| 92 | void ReadFromDefaultUniformBlock(int componentCount, |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 93 | uint32_t arrayIndex, |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 94 | T *dst, |
| 95 | const sh::BlockMemberInfo &layoutInfo, |
| 96 | const angle::MemoryBuffer *uniformData) |
| 97 | { |
| 98 | ASSERT(layoutInfo.offset != -1); |
| 99 | |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 100 | const int elementSize = sizeof(T) * componentCount; |
| 101 | const uint8_t *source = uniformData->data() + layoutInfo.offset; |
| 102 | |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 103 | if (layoutInfo.arrayStride == 0 || layoutInfo.arrayStride == elementSize) |
| 104 | { |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 105 | const uint8_t *readPtr = source + arrayIndex * layoutInfo.arrayStride; |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 106 | memcpy(dst, readPtr, elementSize); |
| 107 | } |
| 108 | else |
| 109 | { |
Luc Ferron | 2371aca | 2018-03-27 16:03:03 -0400 | [diff] [blame] | 110 | // Have to respect the arrayStride between each element of the array. |
| 111 | const int arrayOffset = arrayIndex * layoutInfo.arrayStride; |
| 112 | const uint8_t *readPtr = source + arrayOffset; |
| 113 | memcpy(dst, readPtr, elementSize); |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 117 | angle::Result SyncDefaultUniformBlock(ContextVk *contextVk, |
| 118 | vk::DynamicBuffer *dynamicBuffer, |
| 119 | const angle::MemoryBuffer &bufferData, |
| 120 | uint32_t *outOffset, |
| 121 | bool *outBufferModified) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 122 | { |
Shahbaz Youssefi | 5829c03 | 2018-11-28 10:39:41 -0500 | [diff] [blame] | 123 | dynamicBuffer->releaseRetainedBuffers(contextVk->getRenderer()); |
| 124 | |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 125 | ASSERT(!bufferData.empty()); |
| 126 | uint8_t *data = nullptr; |
| 127 | VkBuffer *outBuffer = nullptr; |
Jamie Madill | 4c31083 | 2018-08-29 13:43:17 -0400 | [diff] [blame] | 128 | VkDeviceSize offset = 0; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 129 | ANGLE_TRY(dynamicBuffer->allocate(contextVk, bufferData.size(), &data, outBuffer, &offset, |
Jamie Madill | c3755fc | 2018-04-05 08:39:13 -0400 | [diff] [blame] | 130 | outBufferModified)); |
Jamie Madill | 4c31083 | 2018-08-29 13:43:17 -0400 | [diff] [blame] | 131 | *outOffset = static_cast<uint32_t>(offset); |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 132 | memcpy(data, bufferData.data(), bufferData.size()); |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 133 | ANGLE_TRY(dynamicBuffer->flush(contextVk)); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 134 | return angle::Result::Continue; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 135 | } |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 136 | |
| 137 | uint32_t GetUniformBlockArraySize(const std::vector<gl::InterfaceBlock> &uniformBlocks, |
| 138 | uint32_t bufferIndex) |
| 139 | { |
| 140 | const gl::InterfaceBlock &uniformBlock = uniformBlocks[bufferIndex]; |
| 141 | |
| 142 | if (!uniformBlock.isArray) |
| 143 | { |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | ASSERT(uniformBlock.arrayElement == 0); |
| 148 | |
| 149 | // Search consecutively until all array indices of this block are visited. |
| 150 | uint32_t arraySize; |
| 151 | for (arraySize = 1; bufferIndex + arraySize < uniformBlocks.size(); ++arraySize) |
| 152 | { |
| 153 | const gl::InterfaceBlock &nextBlock = uniformBlocks[bufferIndex + arraySize]; |
| 154 | |
| 155 | if (nextBlock.arrayElement != arraySize) |
| 156 | { |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | // It's unexpected for an array to start at a non-zero array size, so we can always rely on |
| 161 | // the sequential `arrayElement`s to belong to the same block. |
| 162 | ASSERT(nextBlock.name == uniformBlock.name); |
| 163 | ASSERT(nextBlock.isArray); |
| 164 | } |
| 165 | |
| 166 | return arraySize; |
| 167 | } |
Shahbaz Youssefi | 9d519ab | 2019-05-09 23:09:46 -0400 | [diff] [blame] | 168 | |
| 169 | class Std140BlockLayoutEncoderFactory : public gl::CustomBlockLayoutEncoderFactory |
| 170 | { |
| 171 | public: |
| 172 | sh::BlockLayoutEncoder *makeEncoder() override { return new sh::Std140BlockEncoder(); } |
| 173 | }; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 174 | } // anonymous namespace |
| 175 | |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 176 | // ProgramVk::ShaderInfo implementation. |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 177 | ProgramVk::ShaderInfo::ShaderInfo() {} |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 178 | |
| 179 | ProgramVk::ShaderInfo::~ShaderInfo() = default; |
| 180 | |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 181 | angle::Result ProgramVk::ShaderInfo::initShaders(ContextVk *contextVk, |
| 182 | const std::string &vertexSource, |
| 183 | const std::string &fragmentSource, |
| 184 | bool enableLineRasterEmulation) |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 185 | { |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 186 | ASSERT(!valid()); |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 187 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 188 | std::vector<uint32_t> vertexCode; |
| 189 | std::vector<uint32_t> fragmentCode; |
| 190 | ANGLE_TRY(GlslangWrapper::GetShaderCode(contextVk, contextVk->getCaps(), |
| 191 | enableLineRasterEmulation, vertexSource, fragmentSource, |
| 192 | &vertexCode, &fragmentCode)); |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 193 | |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 194 | ANGLE_TRY(vk::InitShaderAndSerial(contextVk, &mShaders[gl::ShaderType::Vertex].get(), |
| 195 | vertexCode.data(), vertexCode.size() * sizeof(uint32_t))); |
| 196 | ANGLE_TRY(vk::InitShaderAndSerial(contextVk, &mShaders[gl::ShaderType::Fragment].get(), |
| 197 | fragmentCode.data(), fragmentCode.size() * sizeof(uint32_t))); |
| 198 | |
| 199 | mProgramHelper.setShader(gl::ShaderType::Vertex, &mShaders[gl::ShaderType::Vertex]); |
| 200 | mProgramHelper.setShader(gl::ShaderType::Fragment, &mShaders[gl::ShaderType::Fragment]); |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 201 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 202 | return angle::Result::Continue; |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 203 | } |
| 204 | |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 205 | void ProgramVk::ShaderInfo::release(RendererVk *renderer) |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 206 | { |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 207 | mProgramHelper.release(renderer); |
| 208 | |
| 209 | for (vk::RefCounted<vk::ShaderAndSerial> &shader : mShaders) |
| 210 | { |
| 211 | shader.get().destroy(renderer->getDevice()); |
| 212 | } |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 215 | // ProgramVk implementation. |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 216 | ProgramVk::DefaultUniformBlock::DefaultUniformBlock() |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 217 | : storage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 218 | kUniformBlockDynamicBufferMinSize, |
| 219 | true) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 220 | {} |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 221 | |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 222 | ProgramVk::DefaultUniformBlock::~DefaultUniformBlock() = default; |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 223 | |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame^] | 224 | ProgramVk::ProgramVk(const gl::ProgramState &state) : ProgramImpl(state), mUniformBlocksOffsets{} {} |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 225 | |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 226 | ProgramVk::~ProgramVk() = default; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 227 | |
Jamie Madill | f4a789f | 2018-10-18 16:56:20 -0400 | [diff] [blame] | 228 | void ProgramVk::destroy(const gl::Context *context) |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 229 | { |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 230 | ContextVk *contextVk = vk::GetImpl(context); |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 231 | reset(contextVk->getRenderer()); |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 232 | } |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 233 | |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 234 | void ProgramVk::reset(RendererVk *renderer) |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 235 | { |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 236 | for (auto &descriptorSetLayout : mDescriptorSetLayouts) |
| 237 | { |
| 238 | descriptorSetLayout.reset(); |
| 239 | } |
| 240 | mPipelineLayout.reset(); |
| 241 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 242 | for (auto &uniformBlock : mDefaultUniformBlocks) |
| 243 | { |
Jamie Madill | caaff16 | 2018-06-22 08:55:37 -0400 | [diff] [blame] | 244 | uniformBlock.storage.release(renderer); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 247 | mDefaultShaderInfo.release(renderer); |
| 248 | mLineRasterShaderInfo.release(renderer); |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 249 | |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 250 | mEmptyUniformBlockStorage.release(renderer); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 251 | |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 252 | mDescriptorSets.clear(); |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 253 | mEmptyDescriptorSets.fill(VK_NULL_HANDLE); |
Jamie Madill | b7d924a | 2018-03-10 11:16:54 -0500 | [diff] [blame] | 254 | |
Shahbaz Youssefi | d838178 | 2019-03-04 11:07:47 -0500 | [diff] [blame] | 255 | for (vk::RefCountedDescriptorPoolBinding &binding : mDescriptorPoolBindings) |
Jamie Madill | 78bcd2b | 2018-10-16 15:05:20 -0400 | [diff] [blame] | 256 | { |
| 257 | binding.reset(); |
| 258 | } |
Jamie Madill | 5deea72 | 2017-02-16 10:44:46 -0500 | [diff] [blame] | 259 | } |
| 260 | |
Geoff Lang | e332e62 | 2019-02-14 12:53:04 -0500 | [diff] [blame] | 261 | std::unique_ptr<rx::LinkEvent> ProgramVk::load(const gl::Context *context, |
| 262 | gl::BinaryInputStream *stream, |
| 263 | gl::InfoLog &infoLog) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 264 | { |
| 265 | UNIMPLEMENTED(); |
Geoff Lang | e332e62 | 2019-02-14 12:53:04 -0500 | [diff] [blame] | 266 | return std::make_unique<LinkEventDone>(angle::Result::Stop); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 269 | void ProgramVk::save(const gl::Context *context, gl::BinaryOutputStream *stream) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 270 | { |
| 271 | UNIMPLEMENTED(); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void ProgramVk::setBinaryRetrievableHint(bool retrievable) |
| 275 | { |
| 276 | UNIMPLEMENTED(); |
| 277 | } |
| 278 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 279 | void ProgramVk::setSeparable(bool separable) |
| 280 | { |
| 281 | UNIMPLEMENTED(); |
| 282 | } |
| 283 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 284 | std::unique_ptr<LinkEvent> ProgramVk::link(const gl::Context *context, |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 285 | const gl::ProgramLinkedResources &resources, |
| 286 | gl::InfoLog &infoLog) |
| 287 | { |
| 288 | // TODO(jie.a.chen@intel.com): Parallelize linking. |
| 289 | // http://crbug.com/849576 |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 290 | return std::make_unique<LinkEventDone>(linkImpl(context, resources, infoLog)); |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 291 | } |
| 292 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 293 | angle::Result ProgramVk::linkImpl(const gl::Context *glContext, |
| 294 | const gl::ProgramLinkedResources &resources, |
| 295 | gl::InfoLog &infoLog) |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 296 | { |
Jamie Madill | 06ca634 | 2018-07-12 15:56:53 -0400 | [diff] [blame] | 297 | ContextVk *contextVk = vk::GetImpl(glContext); |
| 298 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 299 | |
Jamie Madill | dc65c5b | 2018-11-21 11:07:26 -0500 | [diff] [blame] | 300 | reset(renderer); |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 301 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 302 | // Link resources before calling GetShaderSource to make sure they are ready for the set/binding |
| 303 | // assignment done in that function. |
| 304 | linkResources(resources); |
| 305 | |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 306 | GlslangWrapper::GetShaderSource(mState, resources, &mVertexSource, &mFragmentSource); |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 307 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 308 | ANGLE_TRY(initDefaultUniformBlocks(glContext)); |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 309 | |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 310 | // Store a reference to the pipeline and descriptor set layouts. This will create them if they |
| 311 | // don't already exist in the cache. |
| 312 | vk::DescriptorSetLayoutDesc uniformsSetDesc; |
| 313 | uniformsSetDesc.update(kVertexUniformsBindingIndex, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, |
| 314 | 1); |
| 315 | uniformsSetDesc.update(kFragmentUniformsBindingIndex, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, |
| 316 | 1); |
| 317 | |
| 318 | ANGLE_TRY(renderer->getDescriptorSetLayout( |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 319 | contextVk, uniformsSetDesc, &mDescriptorSetLayouts[kUniformsDescriptorSetIndex])); |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 320 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 321 | vk::DescriptorSetLayoutDesc uniformBlocksSetDesc; |
| 322 | |
| 323 | const std::vector<gl::InterfaceBlock> &uniformBlocks = mState.getUniformBlocks(); |
| 324 | for (uint32_t bufferIndex = 0; bufferIndex < uniformBlocks.size();) |
| 325 | { |
| 326 | const uint32_t arraySize = GetUniformBlockArraySize(uniformBlocks, bufferIndex); |
| 327 | |
| 328 | uniformBlocksSetDesc.update(bufferIndex, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, arraySize); |
| 329 | |
| 330 | bufferIndex += arraySize; |
| 331 | } |
| 332 | |
| 333 | ANGLE_TRY(renderer->getDescriptorSetLayout( |
| 334 | contextVk, uniformBlocksSetDesc, &mDescriptorSetLayouts[kUniformBlockDescriptorSetIndex])); |
| 335 | |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 336 | vk::DescriptorSetLayoutDesc texturesSetDesc; |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 337 | |
| 338 | for (uint32_t textureIndex = 0; textureIndex < mState.getSamplerBindings().size(); |
| 339 | ++textureIndex) |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 340 | { |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 341 | const gl::SamplerBinding &samplerBinding = mState.getSamplerBindings()[textureIndex]; |
| 342 | |
| 343 | // The front-end always binds array sampler units sequentially. |
| 344 | const uint32_t count = static_cast<uint32_t>(samplerBinding.boundTextureUnits.size()); |
| 345 | texturesSetDesc.update(textureIndex, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, count); |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 348 | ANGLE_TRY(renderer->getDescriptorSetLayout(contextVk, texturesSetDesc, |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 349 | &mDescriptorSetLayouts[kTextureDescriptorSetIndex])); |
| 350 | |
Jamie Madill | b01b480 | 2018-07-10 12:43:57 -0400 | [diff] [blame] | 351 | vk::DescriptorSetLayoutDesc driverUniformsSetDesc; |
| 352 | driverUniformsSetDesc.update(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1); |
| 353 | ANGLE_TRY(renderer->getDescriptorSetLayout( |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 354 | contextVk, driverUniformsSetDesc, |
| 355 | &mDescriptorSetLayouts[kDriverUniformsDescriptorSetIndex])); |
Jamie Madill | b01b480 | 2018-07-10 12:43:57 -0400 | [diff] [blame] | 356 | |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 357 | vk::PipelineLayoutDesc pipelineLayoutDesc; |
| 358 | pipelineLayoutDesc.updateDescriptorSetLayout(kUniformsDescriptorSetIndex, uniformsSetDesc); |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 359 | pipelineLayoutDesc.updateDescriptorSetLayout(kUniformBlockDescriptorSetIndex, |
| 360 | uniformBlocksSetDesc); |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 361 | pipelineLayoutDesc.updateDescriptorSetLayout(kTextureDescriptorSetIndex, texturesSetDesc); |
Jamie Madill | b01b480 | 2018-07-10 12:43:57 -0400 | [diff] [blame] | 362 | pipelineLayoutDesc.updateDescriptorSetLayout(kDriverUniformsDescriptorSetIndex, |
| 363 | driverUniformsSetDesc); |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 364 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 365 | ANGLE_TRY(renderer->getPipelineLayout(contextVk, pipelineLayoutDesc, mDescriptorSetLayouts, |
| 366 | &mPipelineLayout)); |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 367 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 368 | return angle::Result::Continue; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 371 | void ProgramVk::linkResources(const gl::ProgramLinkedResources &resources) |
| 372 | { |
Shahbaz Youssefi | 9d519ab | 2019-05-09 23:09:46 -0400 | [diff] [blame] | 373 | Std140BlockLayoutEncoderFactory std140EncoderFactory; |
| 374 | gl::ProgramLinkedResourcesLinker linker(&std140EncoderFactory); |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 375 | |
| 376 | linker.linkResources(mState, resources); |
| 377 | } |
| 378 | |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 379 | angle::Result ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 380 | { |
Jamie Madill | e1f3ad4 | 2017-10-28 23:00:42 -0400 | [diff] [blame] | 381 | ContextVk *contextVk = vk::GetImpl(glContext); |
Jamie Madill | 57fbfd8 | 2018-02-14 12:45:34 -0500 | [diff] [blame] | 382 | RendererVk *renderer = contextVk->getRenderer(); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 383 | |
| 384 | // Process vertex and fragment uniforms into std140 packing. |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 385 | gl::ShaderMap<sh::BlockLayoutMap> layoutMap; |
| 386 | gl::ShaderMap<size_t> requiredBufferSize; |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 387 | requiredBufferSize.fill(0); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 388 | |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 389 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 390 | { |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 391 | gl::Shader *shader = mState.getAttachedShader(shaderType); |
jchen10 | 3fd614d | 2018-08-13 12:21:58 +0800 | [diff] [blame] | 392 | const std::vector<sh::Uniform> &uniforms = shader->getUniforms(); |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 393 | InitDefaultUniformBlock(uniforms, shader, &layoutMap[shaderType], |
| 394 | &requiredBufferSize[shaderType]); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | // Init the default block layout info. |
Jamie Madill | 77abad8 | 2018-10-25 17:03:48 -0400 | [diff] [blame] | 398 | const auto &uniforms = mState.getUniforms(); |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 399 | for (const gl::VariableLocation &location : mState.getUniformLocations()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 400 | { |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 401 | gl::ShaderMap<sh::BlockMemberInfo> layoutInfo; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 402 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 403 | if (location.used() && !location.ignored) |
| 404 | { |
Jamie Madill | de03e00 | 2017-10-21 14:04:20 -0400 | [diff] [blame] | 405 | const auto &uniform = uniforms[location.index]; |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 406 | if (uniform.isInDefaultBlock() && !uniform.isSampler()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 407 | { |
Geoff Lang | beb0c94 | 2018-09-27 11:22:23 -0400 | [diff] [blame] | 408 | std::string uniformName = uniform.name; |
| 409 | if (uniform.isArray()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 410 | { |
Geoff Lang | beb0c94 | 2018-09-27 11:22:23 -0400 | [diff] [blame] | 411 | // Gets the uniform name without the [0] at the end. |
| 412 | uniformName = gl::ParseResourceName(uniformName, nullptr); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 413 | } |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 414 | |
Geoff Lang | beb0c94 | 2018-09-27 11:22:23 -0400 | [diff] [blame] | 415 | bool found = false; |
| 416 | |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 417 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Geoff Lang | beb0c94 | 2018-09-27 11:22:23 -0400 | [diff] [blame] | 418 | { |
| 419 | auto it = layoutMap[shaderType].find(uniformName); |
| 420 | if (it != layoutMap[shaderType].end()) |
| 421 | { |
| 422 | found = true; |
| 423 | layoutInfo[shaderType] = it->second; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | ASSERT(found); |
| 428 | } |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 429 | } |
| 430 | |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 431 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 432 | { |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 433 | mDefaultUniformBlocks[shaderType].uniformLayout.push_back(layoutInfo[shaderType]); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 437 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 438 | { |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 439 | if (requiredBufferSize[shaderType] > 0) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 440 | { |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 441 | if (!mDefaultUniformBlocks[shaderType].uniformData.resize( |
| 442 | requiredBufferSize[shaderType])) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 443 | { |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 444 | ANGLE_VK_CHECK(contextVk, false, VK_ERROR_OUT_OF_HOST_MEMORY); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 445 | } |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 446 | size_t minAlignment = static_cast<size_t>( |
| 447 | renderer->getPhysicalDeviceProperties().limits.minUniformBufferOffsetAlignment); |
| 448 | |
Luc Ferron | a9ab0f3 | 2018-05-17 17:03:55 -0400 | [diff] [blame] | 449 | mDefaultUniformBlocks[shaderType].storage.init(minAlignment, renderer); |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 450 | |
| 451 | // Initialize uniform buffer memory to zero by default. |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 452 | mDefaultUniformBlocks[shaderType].uniformData.fill(0); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 453 | mDefaultUniformBlocksDirty.set(shaderType); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 457 | if (mDefaultUniformBlocksDirty.any()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 458 | { |
| 459 | // Initialize the "empty" uniform block if necessary. |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 460 | if (!mDefaultUniformBlocksDirty.all()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 461 | { |
Shahbaz Youssefi | 06270c9 | 2018-10-03 17:00:25 -0400 | [diff] [blame] | 462 | VkBufferCreateInfo uniformBufferInfo = {}; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 463 | uniformBufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 464 | uniformBufferInfo.flags = 0; |
| 465 | uniformBufferInfo.size = 1; |
| 466 | uniformBufferInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 467 | uniformBufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 468 | uniformBufferInfo.queueFamilyIndexCount = 0; |
| 469 | uniformBufferInfo.pQueueFamilyIndices = nullptr; |
| 470 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 471 | constexpr VkMemoryPropertyFlags kMemoryType = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 472 | ANGLE_TRY(mEmptyUniformBlockStorage.init(contextVk, uniformBufferInfo, kMemoryType)); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 473 | } |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 474 | } |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 475 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 476 | return angle::Result::Continue; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 477 | } |
| 478 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 479 | GLboolean ProgramVk::validate(const gl::Caps &caps, gl::InfoLog *infoLog) |
| 480 | { |
Luc Ferron | fba1f61 | 2018-06-04 14:37:17 -0400 | [diff] [blame] | 481 | // No-op. The spec is very vague about the behavior of validation. |
| 482 | return GL_TRUE; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 483 | } |
| 484 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 485 | template <typename T> |
| 486 | void ProgramVk::setUniformImpl(GLint location, GLsizei count, const T *v, GLenum entryPointType) |
| 487 | { |
| 488 | const gl::VariableLocation &locationInfo = mState.getUniformLocations()[location]; |
| 489 | const gl::LinkedUniform &linkedUniform = mState.getUniforms()[locationInfo.index]; |
| 490 | |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 491 | if (linkedUniform.isSampler()) |
| 492 | { |
Jamie Madill | 0cb6dc4 | 2018-04-16 10:36:39 -0400 | [diff] [blame] | 493 | // We could potentially cache some indexing here. For now this is a no-op since the mapping |
| 494 | // is handled entirely in ContextVk. |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 495 | return; |
| 496 | } |
| 497 | |
Luc Ferron | 24a3137 | 2018-04-04 11:49:14 -0400 | [diff] [blame] | 498 | if (linkedUniform.typeInfo->type == entryPointType) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 499 | { |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 500 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 501 | { |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 502 | DefaultUniformBlock &uniformBlock = mDefaultUniformBlocks[shaderType]; |
Luc Ferron | 24a3137 | 2018-04-04 11:49:14 -0400 | [diff] [blame] | 503 | const sh::BlockMemberInfo &layoutInfo = uniformBlock.uniformLayout[location]; |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 504 | |
Luc Ferron | 24a3137 | 2018-04-04 11:49:14 -0400 | [diff] [blame] | 505 | // Assume an offset of -1 means the block is unused. |
| 506 | if (layoutInfo.offset == -1) |
| 507 | { |
| 508 | continue; |
| 509 | } |
| 510 | |
| 511 | const GLint componentCount = linkedUniform.typeInfo->componentCount; |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 512 | UpdateDefaultUniformBlock(count, locationInfo.arrayIndex, componentCount, v, layoutInfo, |
| 513 | &uniformBlock.uniformData); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 514 | mDefaultUniformBlocksDirty.set(shaderType); |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 515 | } |
Luc Ferron | 24a3137 | 2018-04-04 11:49:14 -0400 | [diff] [blame] | 516 | } |
| 517 | else |
| 518 | { |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 519 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 520 | { |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 521 | DefaultUniformBlock &uniformBlock = mDefaultUniformBlocks[shaderType]; |
Luc Ferron | 24a3137 | 2018-04-04 11:49:14 -0400 | [diff] [blame] | 522 | const sh::BlockMemberInfo &layoutInfo = uniformBlock.uniformLayout[location]; |
| 523 | |
| 524 | // Assume an offset of -1 means the block is unused. |
| 525 | if (layoutInfo.offset == -1) |
| 526 | { |
| 527 | continue; |
| 528 | } |
| 529 | |
| 530 | const GLint componentCount = linkedUniform.typeInfo->componentCount; |
| 531 | |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 532 | ASSERT(linkedUniform.typeInfo->type == gl::VariableBoolVectorType(entryPointType)); |
| 533 | |
Luc Ferron | d91c379 | 2018-04-06 09:36:36 -0400 | [diff] [blame] | 534 | GLint initialArrayOffset = |
| 535 | locationInfo.arrayIndex * layoutInfo.arrayStride + layoutInfo.offset; |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 536 | for (GLint i = 0; i < count; i++) |
| 537 | { |
| 538 | GLint elementOffset = i * layoutInfo.arrayStride + initialArrayOffset; |
| 539 | GLint *dest = |
| 540 | reinterpret_cast<GLint *>(uniformBlock.uniformData.data() + elementOffset); |
| 541 | const T *source = v + i * componentCount; |
| 542 | |
| 543 | for (int c = 0; c < componentCount; c++) |
| 544 | { |
| 545 | dest[c] = (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE; |
| 546 | } |
| 547 | } |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 548 | |
| 549 | mDefaultUniformBlocksDirty.set(shaderType); |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 550 | } |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 554 | template <typename T> |
| 555 | void ProgramVk::getUniformImpl(GLint location, T *v, GLenum entryPointType) const |
| 556 | { |
| 557 | const gl::VariableLocation &locationInfo = mState.getUniformLocations()[location]; |
| 558 | const gl::LinkedUniform &linkedUniform = mState.getUniforms()[locationInfo.index]; |
| 559 | |
Jamie Madill | 3bb2bbe | 2018-06-15 09:47:03 -0400 | [diff] [blame] | 560 | ASSERT(!linkedUniform.isSampler()); |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 561 | |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 562 | const gl::ShaderType shaderType = linkedUniform.getFirstShaderTypeWhereActive(); |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 563 | ASSERT(shaderType != gl::ShaderType::InvalidEnum); |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 564 | |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 565 | const DefaultUniformBlock &uniformBlock = mDefaultUniformBlocks[shaderType]; |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 566 | const sh::BlockMemberInfo &layoutInfo = uniformBlock.uniformLayout[location]; |
Luc Ferron | 62059a5 | 2018-03-29 07:01:35 -0400 | [diff] [blame] | 567 | |
| 568 | ASSERT(linkedUniform.typeInfo->componentType == entryPointType || |
| 569 | linkedUniform.typeInfo->componentType == gl::VariableBoolVectorType(entryPointType)); |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 570 | |
| 571 | if (gl::IsMatrixType(linkedUniform.type)) |
| 572 | { |
| 573 | const uint8_t *ptrToElement = uniformBlock.uniformData.data() + layoutInfo.offset + |
Luc Ferron | f6fd48f | 2018-06-18 08:11:27 -0400 | [diff] [blame] | 574 | (locationInfo.arrayIndex * layoutInfo.arrayStride); |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 575 | GetMatrixUniform(linkedUniform.type, v, reinterpret_cast<const T *>(ptrToElement), false); |
| 576 | } |
| 577 | else |
| 578 | { |
| 579 | ReadFromDefaultUniformBlock(linkedUniform.typeInfo->componentCount, locationInfo.arrayIndex, |
| 580 | v, layoutInfo, &uniformBlock.uniformData); |
| 581 | } |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 582 | } |
| 583 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 584 | void ProgramVk::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 585 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 586 | setUniformImpl(location, count, v, GL_FLOAT); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | void ProgramVk::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 590 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 591 | setUniformImpl(location, count, v, GL_FLOAT_VEC2); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | void ProgramVk::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 595 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 596 | setUniformImpl(location, count, v, GL_FLOAT_VEC3); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | void ProgramVk::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 600 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 601 | setUniformImpl(location, count, v, GL_FLOAT_VEC4); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void ProgramVk::setUniform1iv(GLint location, GLsizei count, const GLint *v) |
| 605 | { |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 606 | setUniformImpl(location, count, v, GL_INT); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | void ProgramVk::setUniform2iv(GLint location, GLsizei count, const GLint *v) |
| 610 | { |
Luc Ferron | 489243f | 2018-03-28 16:55:28 -0400 | [diff] [blame] | 611 | setUniformImpl(location, count, v, GL_INT_VEC2); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | void ProgramVk::setUniform3iv(GLint location, GLsizei count, const GLint *v) |
| 615 | { |
Luc Ferron | 489243f | 2018-03-28 16:55:28 -0400 | [diff] [blame] | 616 | setUniformImpl(location, count, v, GL_INT_VEC3); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | void ProgramVk::setUniform4iv(GLint location, GLsizei count, const GLint *v) |
| 620 | { |
Luc Ferron | 489243f | 2018-03-28 16:55:28 -0400 | [diff] [blame] | 621 | setUniformImpl(location, count, v, GL_INT_VEC4); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | void ProgramVk::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) |
| 625 | { |
Shahbaz Youssefi | fdbece2 | 2019-05-09 18:06:34 -0400 | [diff] [blame] | 626 | setUniformImpl(location, count, v, GL_UNSIGNED_INT); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | void ProgramVk::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) |
| 630 | { |
Shahbaz Youssefi | fdbece2 | 2019-05-09 18:06:34 -0400 | [diff] [blame] | 631 | setUniformImpl(location, count, v, GL_UNSIGNED_INT_VEC2); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | void ProgramVk::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) |
| 635 | { |
Shahbaz Youssefi | fdbece2 | 2019-05-09 18:06:34 -0400 | [diff] [blame] | 636 | setUniformImpl(location, count, v, GL_UNSIGNED_INT_VEC3); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | void ProgramVk::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) |
| 640 | { |
Shahbaz Youssefi | fdbece2 | 2019-05-09 18:06:34 -0400 | [diff] [blame] | 641 | setUniformImpl(location, count, v, GL_UNSIGNED_INT_VEC4); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 642 | } |
| 643 | |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 644 | template <int cols, int rows> |
| 645 | void ProgramVk::setUniformMatrixfv(GLint location, |
| 646 | GLsizei count, |
| 647 | GLboolean transpose, |
| 648 | const GLfloat *value) |
| 649 | { |
| 650 | const gl::VariableLocation &locationInfo = mState.getUniformLocations()[location]; |
| 651 | const gl::LinkedUniform &linkedUniform = mState.getUniforms()[locationInfo.index]; |
| 652 | |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 653 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 654 | { |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 655 | DefaultUniformBlock &uniformBlock = mDefaultUniformBlocks[shaderType]; |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 656 | const sh::BlockMemberInfo &layoutInfo = uniformBlock.uniformLayout[location]; |
| 657 | |
| 658 | // Assume an offset of -1 means the block is unused. |
| 659 | if (layoutInfo.offset == -1) |
| 660 | { |
| 661 | continue; |
| 662 | } |
| 663 | |
Shahbaz Youssefi | b783fbc | 2019-05-10 23:16:17 -0400 | [diff] [blame] | 664 | bool updated = SetFloatUniformMatrixGLSL<cols, rows>( |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 665 | locationInfo.arrayIndex, linkedUniform.getArraySizeProduct(), count, transpose, value, |
| 666 | uniformBlock.uniformData.data() + layoutInfo.offset); |
Luc Ferron | c8fbff3 | 2018-06-04 10:30:48 -0400 | [diff] [blame] | 667 | |
| 668 | // If the uniformsDirty flag was true, we don't want to flip it to false here if the |
| 669 | // setter did not update any data. We still want the uniform to be included when we'll |
| 670 | // update the descriptor sets. |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 671 | if (updated) |
| 672 | { |
| 673 | mDefaultUniformBlocksDirty.set(shaderType); |
| 674 | } |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 678 | void ProgramVk::setUniformMatrix2fv(GLint location, |
| 679 | GLsizei count, |
| 680 | GLboolean transpose, |
| 681 | const GLfloat *value) |
| 682 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 683 | setUniformMatrixfv<2, 2>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | void ProgramVk::setUniformMatrix3fv(GLint location, |
| 687 | GLsizei count, |
| 688 | GLboolean transpose, |
| 689 | const GLfloat *value) |
| 690 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 691 | setUniformMatrixfv<3, 3>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | void ProgramVk::setUniformMatrix4fv(GLint location, |
| 695 | GLsizei count, |
| 696 | GLboolean transpose, |
| 697 | const GLfloat *value) |
| 698 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 699 | setUniformMatrixfv<4, 4>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void ProgramVk::setUniformMatrix2x3fv(GLint location, |
| 703 | GLsizei count, |
| 704 | GLboolean transpose, |
| 705 | const GLfloat *value) |
| 706 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 707 | setUniformMatrixfv<2, 3>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void ProgramVk::setUniformMatrix3x2fv(GLint location, |
| 711 | GLsizei count, |
| 712 | GLboolean transpose, |
| 713 | const GLfloat *value) |
| 714 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 715 | setUniformMatrixfv<3, 2>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | void ProgramVk::setUniformMatrix2x4fv(GLint location, |
| 719 | GLsizei count, |
| 720 | GLboolean transpose, |
| 721 | const GLfloat *value) |
| 722 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 723 | setUniformMatrixfv<2, 4>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | void ProgramVk::setUniformMatrix4x2fv(GLint location, |
| 727 | GLsizei count, |
| 728 | GLboolean transpose, |
| 729 | const GLfloat *value) |
| 730 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 731 | setUniformMatrixfv<4, 2>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | void ProgramVk::setUniformMatrix3x4fv(GLint location, |
| 735 | GLsizei count, |
| 736 | GLboolean transpose, |
| 737 | const GLfloat *value) |
| 738 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 739 | setUniformMatrixfv<3, 4>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void ProgramVk::setUniformMatrix4x3fv(GLint location, |
| 743 | GLsizei count, |
| 744 | GLboolean transpose, |
| 745 | const GLfloat *value) |
| 746 | { |
Luc Ferron | 48cdc2e | 2018-05-31 09:58:34 -0400 | [diff] [blame] | 747 | setUniformMatrixfv<4, 3>(location, count, transpose, value); |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 748 | } |
| 749 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 750 | void ProgramVk::setPathFragmentInputGen(const std::string &inputName, |
| 751 | GLenum genMode, |
| 752 | GLint components, |
| 753 | const GLfloat *coeffs) |
| 754 | { |
| 755 | UNIMPLEMENTED(); |
| 756 | } |
| 757 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 758 | angle::Result ProgramVk::allocateDescriptorSet(ContextVk *contextVk, uint32_t descriptorSetIndex) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 759 | { |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 760 | // Write out to a new a descriptor set. |
Jamie Madill | edeaa83 | 2018-06-22 09:18:41 -0400 | [diff] [blame] | 761 | vk::DynamicDescriptorPool *dynamicDescriptorPool = |
| 762 | contextVk->getDynamicDescriptorPool(descriptorSetIndex); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 763 | |
Luc Ferron | 6ea1b41 | 2018-03-21 16:13:01 -0400 | [diff] [blame] | 764 | uint32_t potentialNewCount = descriptorSetIndex + 1; |
| 765 | if (potentialNewCount > mDescriptorSets.size()) |
| 766 | { |
| 767 | mDescriptorSets.resize(potentialNewCount, VK_NULL_HANDLE); |
| 768 | } |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 769 | |
Jamie Madill | c7918ce | 2018-06-13 13:25:31 -0400 | [diff] [blame] | 770 | const vk::DescriptorSetLayout &descriptorSetLayout = |
Jamie Madill | 9b168d0 | 2018-06-13 13:25:32 -0400 | [diff] [blame] | 771 | mDescriptorSetLayouts[descriptorSetIndex].get(); |
Jamie Madill | 8a4c49f | 2018-06-21 15:43:06 -0400 | [diff] [blame] | 772 | ANGLE_TRY(dynamicDescriptorPool->allocateSets(contextVk, descriptorSetLayout.ptr(), 1, |
Jamie Madill | 78bcd2b | 2018-10-16 15:05:20 -0400 | [diff] [blame] | 773 | &mDescriptorPoolBindings[descriptorSetIndex], |
Jamie Madill | 8a4c49f | 2018-06-21 15:43:06 -0400 | [diff] [blame] | 774 | &mDescriptorSets[descriptorSetIndex])); |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 775 | mEmptyDescriptorSets[descriptorSetIndex] = VK_NULL_HANDLE; |
| 776 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 777 | return angle::Result::Continue; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 778 | } |
| 779 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 780 | void ProgramVk::getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const |
| 781 | { |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 782 | getUniformImpl(location, params, GL_FLOAT); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | void ProgramVk::getUniformiv(const gl::Context *context, GLint location, GLint *params) const |
| 786 | { |
Luc Ferron | 7cec335 | 2018-03-13 13:29:34 -0400 | [diff] [blame] | 787 | getUniformImpl(location, params, GL_INT); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | void ProgramVk::getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const |
| 791 | { |
Shahbaz Youssefi | fdbece2 | 2019-05-09 18:06:34 -0400 | [diff] [blame] | 792 | getUniformImpl(location, params, GL_UNSIGNED_INT); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 793 | } |
| 794 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 795 | angle::Result ProgramVk::updateUniforms(ContextVk *contextVk) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 796 | { |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 797 | ASSERT(dirtyUniforms()); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 798 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 799 | // Update buffer memory by immediate mapping. This immediate update only works once. |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 800 | bool anyNewBufferAllocated = false; |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 801 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 802 | { |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 803 | DefaultUniformBlock &uniformBlock = mDefaultUniformBlocks[shaderType]; |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 804 | |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 805 | if (mDefaultUniformBlocksDirty[shaderType]) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 806 | { |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 807 | bool bufferModified = false; |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 808 | ANGLE_TRY(SyncDefaultUniformBlock(contextVk, &uniformBlock.storage, |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 809 | uniformBlock.uniformData, |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 810 | &mUniformBlocksOffsets[shaderType], &bufferModified)); |
Jamie Madill | 2b858c2 | 2018-09-03 13:58:14 -0400 | [diff] [blame] | 811 | mDefaultUniformBlocksDirty.reset(shaderType); |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 812 | |
| 813 | if (bufferModified) |
| 814 | { |
| 815 | anyNewBufferAllocated = true; |
| 816 | } |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 820 | if (anyNewBufferAllocated) |
| 821 | { |
| 822 | // We need to reinitialize the descriptor sets if we newly allocated buffers since we can't |
| 823 | // modify the descriptor sets once initialized. |
Jamie Madill | c7918ce | 2018-06-13 13:25:31 -0400 | [diff] [blame] | 824 | ANGLE_TRY(allocateDescriptorSet(contextVk, kUniformsDescriptorSetIndex)); |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 825 | ANGLE_TRY(updateDefaultUniformsDescriptorSet(contextVk)); |
| 826 | } |
| 827 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 828 | return angle::Result::Continue; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 829 | } |
| 830 | |
Jamie Madill | 2106102 | 2018-07-12 23:56:30 -0400 | [diff] [blame] | 831 | angle::Result ProgramVk::updateDefaultUniformsDescriptorSet(ContextVk *contextVk) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 832 | { |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 833 | gl::ShaderMap<VkDescriptorBufferInfo> descriptorBufferInfo; |
| 834 | gl::ShaderMap<VkWriteDescriptorSet> writeDescriptorInfo; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 835 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 836 | // Write default uniforms for each shader type. |
Shahbaz Youssefi | df066e9 | 2018-11-13 15:39:47 -0500 | [diff] [blame] | 837 | for (gl::ShaderType shaderType : gl::AllGLES2ShaderTypes()) |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 838 | { |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 839 | DefaultUniformBlock &uniformBlock = mDefaultUniformBlocks[shaderType]; |
| 840 | VkDescriptorBufferInfo &bufferInfo = descriptorBufferInfo[shaderType]; |
| 841 | VkWriteDescriptorSet &writeInfo = writeDescriptorInfo[shaderType]; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 842 | |
| 843 | if (!uniformBlock.uniformData.empty()) |
| 844 | { |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 845 | const vk::BufferHelper *bufferHelper = uniformBlock.storage.getCurrentBuffer(); |
| 846 | bufferInfo.buffer = bufferHelper->getBuffer().getHandle(); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 847 | } |
| 848 | else |
| 849 | { |
Shahbaz Youssefi | 254b32c | 2018-11-26 11:58:03 -0500 | [diff] [blame] | 850 | bufferInfo.buffer = mEmptyUniformBlockStorage.getBuffer().getHandle(); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | bufferInfo.offset = 0; |
| 854 | bufferInfo.range = VK_WHOLE_SIZE; |
| 855 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 856 | writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 857 | writeInfo.pNext = nullptr; |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 858 | writeInfo.dstSet = mDescriptorSets[kUniformsDescriptorSetIndex]; |
Jamie Madill | 33318de | 2018-05-01 11:22:54 -0400 | [diff] [blame] | 859 | writeInfo.dstBinding = static_cast<uint32_t>(shaderType); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 860 | writeInfo.dstArrayElement = 0; |
| 861 | writeInfo.descriptorCount = 1; |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 862 | writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 863 | writeInfo.pImageInfo = nullptr; |
| 864 | writeInfo.pBufferInfo = &bufferInfo; |
| 865 | writeInfo.pTexelBufferView = nullptr; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | VkDevice device = contextVk->getDevice(); |
| 869 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 870 | constexpr uint32_t kShaderTypeMin = static_cast<uint32_t>(gl::kGLES2ShaderTypeMin); |
| 871 | constexpr uint32_t kShaderTypeMax = static_cast<uint32_t>(gl::kGLES2ShaderTypeMax); |
| 872 | constexpr uint32_t kGLES2ShaderCount = kShaderTypeMax - kShaderTypeMin + 1; |
| 873 | vkUpdateDescriptorSets(device, kGLES2ShaderCount, writeDescriptorInfo.data(), 0, nullptr); |
| 874 | |
| 875 | return angle::Result::Continue; |
| 876 | } |
| 877 | |
| 878 | angle::Result ProgramVk::updateUniformBuffersDescriptorSet(ContextVk *contextVk, |
| 879 | vk::FramebufferHelper *framebuffer) |
| 880 | { |
| 881 | ASSERT(hasUniformBuffers()); |
| 882 | ANGLE_TRY(allocateDescriptorSet(contextVk, kUniformBlockDescriptorSetIndex)); |
| 883 | |
| 884 | VkDescriptorSet descriptorSet = mDescriptorSets[kUniformBlockDescriptorSetIndex]; |
| 885 | |
| 886 | gl::UniformBuffersArray<VkDescriptorBufferInfo> descriptorBufferInfo; |
| 887 | gl::UniformBuffersArray<VkWriteDescriptorSet> writeDescriptorInfo; |
| 888 | uint32_t writeCount = 0; |
| 889 | uint32_t currentBinding = 0; |
| 890 | |
| 891 | // Write uniform buffers. |
| 892 | const gl::State &glState = contextVk->getState(); |
| 893 | const std::vector<gl::InterfaceBlock> &uniformBlocks = mState.getUniformBlocks(); |
| 894 | for (uint32_t bufferIndex = 0; bufferIndex < uniformBlocks.size(); ++bufferIndex) |
| 895 | { |
| 896 | if (glState.getIndexedUniformBuffer(uniformBlocks[bufferIndex].binding).get() == nullptr) |
| 897 | { |
| 898 | continue; |
| 899 | } |
| 900 | |
| 901 | VkWriteDescriptorSet &writeInfo = writeDescriptorInfo[writeCount]; |
| 902 | VkDescriptorBufferInfo &bufferInfo = descriptorBufferInfo[writeCount]; |
| 903 | |
| 904 | const gl::InterfaceBlock &uniformBlock = uniformBlocks[bufferIndex]; |
| 905 | const gl::OffsetBindingPointer<gl::Buffer> &bufferBinding = |
| 906 | glState.getIndexedUniformBuffer(uniformBlock.binding); |
| 907 | gl::Buffer *buffer = bufferBinding.get(); |
| 908 | ASSERT(buffer != nullptr); |
| 909 | |
| 910 | // Make sure there's no possible under/overflow with binding size. |
| 911 | static_assert(sizeof(VkDeviceSize) >= sizeof(bufferBinding.getSize()), |
| 912 | "VkDeviceSize too small"); |
| 913 | ASSERT(bufferBinding.getSize() >= 0); |
| 914 | |
| 915 | BufferVk *bufferVk = vk::GetImpl(buffer); |
| 916 | GLintptr offset = bufferBinding.getOffset(); |
| 917 | VkDeviceSize size = bufferBinding.getSize(); |
| 918 | VkDeviceSize blockSize = uniformBlock.dataSize; |
| 919 | vk::BufferHelper &bufferHelper = bufferVk->getBuffer(); |
| 920 | |
| 921 | ANGLE_TRY(bufferVk->onRead(contextVk, framebuffer, VK_ACCESS_UNIFORM_READ_BIT)); |
| 922 | |
| 923 | // If size is 0, we can't always use VK_WHOLE_SIZE (or bufferHelper.getSize()), as the |
| 924 | // backing buffer may be larger than maxUniformBufferRange. In that case, we use the |
| 925 | // minimum of the backing buffer size (what's left after offset) and the uniform buffer |
| 926 | // size as defined by the shader. |
| 927 | size = std::min(size > 0 ? size : (bufferHelper.getSize() - offset), blockSize); |
| 928 | |
| 929 | bufferInfo.buffer = bufferHelper.getBuffer().getHandle(); |
| 930 | bufferInfo.offset = offset; |
| 931 | bufferInfo.range = size; |
| 932 | |
| 933 | if (!uniformBlock.isArray || uniformBlock.arrayElement == 0) |
| 934 | { |
| 935 | // Array indices of the same buffer binding are placed sequentially in `uniformBlocks`. |
| 936 | // Thus, the uniform block binding is updated only when array index 0 is encountered. |
| 937 | currentBinding = bufferIndex; |
| 938 | } |
| 939 | |
| 940 | writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 941 | writeInfo.pNext = nullptr; |
| 942 | writeInfo.dstSet = descriptorSet; |
| 943 | writeInfo.dstBinding = currentBinding; |
| 944 | writeInfo.dstArrayElement = uniformBlock.isArray ? uniformBlock.arrayElement : 0; |
| 945 | writeInfo.descriptorCount = 1; |
| 946 | writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 947 | writeInfo.pImageInfo = nullptr; |
| 948 | writeInfo.pBufferInfo = &bufferInfo; |
| 949 | writeInfo.pTexelBufferView = nullptr; |
| 950 | ASSERT(writeInfo.pBufferInfo[0].buffer != VK_NULL_HANDLE); |
| 951 | |
| 952 | ++writeCount; |
| 953 | } |
| 954 | |
| 955 | VkDevice device = contextVk->getDevice(); |
| 956 | |
| 957 | vkUpdateDescriptorSets(device, writeCount, writeDescriptorInfo.data(), 0, nullptr); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 958 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 959 | return angle::Result::Continue; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 962 | angle::Result ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk, |
| 963 | vk::FramebufferHelper *framebuffer) |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 964 | { |
Jamie Madill | 88fc6da | 2018-08-30 16:18:36 -0400 | [diff] [blame] | 965 | ASSERT(hasTextures()); |
Jamie Madill | c7918ce | 2018-06-13 13:25:31 -0400 | [diff] [blame] | 966 | ANGLE_TRY(allocateDescriptorSet(contextVk, kTextureDescriptorSetIndex)); |
Luc Ferron | 6ea1b41 | 2018-03-21 16:13:01 -0400 | [diff] [blame] | 967 | |
Jamie Madill | c7918ce | 2018-06-13 13:25:31 -0400 | [diff] [blame] | 968 | VkDescriptorSet descriptorSet = mDescriptorSets[kTextureDescriptorSetIndex]; |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 969 | |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 970 | gl::ActiveTextureArray<VkDescriptorImageInfo> descriptorImageInfo; |
| 971 | gl::ActiveTextureArray<VkWriteDescriptorSet> writeDescriptorInfo; |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 972 | uint32_t writeCount = 0; |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 973 | |
Jamie Madill | 84c662b | 2018-07-12 15:56:55 -0400 | [diff] [blame] | 974 | const gl::ActiveTextureArray<TextureVk *> &activeTextures = contextVk->getActiveTextures(); |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 975 | |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 976 | for (uint32_t textureIndex = 0; textureIndex < mState.getSamplerBindings().size(); |
| 977 | ++textureIndex) |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 978 | { |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 979 | const gl::SamplerBinding &samplerBinding = mState.getSamplerBindings()[textureIndex]; |
| 980 | |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 981 | ASSERT(!samplerBinding.unreferenced); |
| 982 | |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 983 | for (uint32_t arrayElement = 0; arrayElement < samplerBinding.boundTextureUnits.size(); |
| 984 | ++arrayElement) |
Luc Ferron | 9096836 | 2018-05-04 08:47:22 -0400 | [diff] [blame] | 985 | { |
Jamie Madill | dbc605c | 2019-01-04 16:39:14 -0500 | [diff] [blame] | 986 | GLuint textureUnit = samplerBinding.boundTextureUnits[arrayElement]; |
| 987 | TextureVk *textureVk = activeTextures[textureUnit]; |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 988 | |
| 989 | // Ensure any writes to the textures are flushed before we read from them. |
| 990 | ANGLE_TRY(textureVk->ensureImageInitialized(contextVk)); |
| 991 | vk::ImageHelper &image = textureVk->getImage(); |
| 992 | |
| 993 | // Ensure the image is in read-only layout |
Shahbaz Youssefi | 7dafe3e | 2019-01-28 11:39:15 -0500 | [diff] [blame] | 994 | if (image.isLayoutChangeNecessary(vk::ImageLayout::FragmentShaderReadOnly)) |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 995 | { |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 996 | vk::CommandBuffer *srcLayoutChange; |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 997 | ANGLE_TRY(image.recordCommands(contextVk, &srcLayoutChange)); |
| 998 | |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame^] | 999 | VkImageAspectFlags aspectFlags = image.getAspectFlags(); |
| 1000 | ASSERT(aspectFlags != 0); |
| 1001 | image.changeLayout(aspectFlags, vk::ImageLayout::FragmentShaderReadOnly, |
| 1002 | srcLayoutChange); |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | image.addReadDependency(framebuffer); |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 1006 | |
| 1007 | VkDescriptorImageInfo &imageInfo = descriptorImageInfo[writeCount]; |
| 1008 | |
| 1009 | imageInfo.sampler = textureVk->getSampler().getHandle(); |
Shahbaz Youssefi | f83a28a | 2018-12-09 03:48:34 +0100 | [diff] [blame] | 1010 | imageInfo.imageView = textureVk->getReadImageView().getHandle(); |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 1011 | imageInfo.imageLayout = image.getCurrentLayout(); |
| 1012 | |
| 1013 | VkWriteDescriptorSet &writeInfo = writeDescriptorInfo[writeCount]; |
| 1014 | |
| 1015 | writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1016 | writeInfo.pNext = nullptr; |
| 1017 | writeInfo.dstSet = descriptorSet; |
| 1018 | writeInfo.dstBinding = textureIndex; |
| 1019 | writeInfo.dstArrayElement = arrayElement; |
| 1020 | writeInfo.descriptorCount = 1; |
| 1021 | writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 1022 | writeInfo.pImageInfo = &imageInfo; |
| 1023 | writeInfo.pBufferInfo = nullptr; |
| 1024 | writeInfo.pTexelBufferView = nullptr; |
| 1025 | |
| 1026 | writeCount++; |
Luc Ferron | 9096836 | 2018-05-04 08:47:22 -0400 | [diff] [blame] | 1027 | } |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | VkDevice device = contextVk->getDevice(); |
| 1031 | |
Jamie Madill | 4cc753e | 2018-06-13 13:25:33 -0400 | [diff] [blame] | 1032 | ASSERT(writeCount > 0); |
| 1033 | vkUpdateDescriptorSets(device, writeCount, writeDescriptorInfo.data(), 0, nullptr); |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 1034 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1035 | return angle::Result::Continue; |
Jamie Madill | 5547b38 | 2017-10-23 18:16:01 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 1038 | void ProgramVk::setDefaultUniformBlocksMinSizeForTesting(size_t minSize) |
| 1039 | { |
| 1040 | for (DefaultUniformBlock &block : mDefaultUniformBlocks) |
| 1041 | { |
Jamie Madill | 6c7ab7f | 2018-03-31 14:19:15 -0400 | [diff] [blame] | 1042 | block.storage.setMinimumSizeForTesting(minSize); |
Luc Ferron | 7a06ac1 | 2018-03-15 10:17:04 -0400 | [diff] [blame] | 1043 | } |
| 1044 | } |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1045 | |
Shahbaz Youssefi | 2660b50 | 2019-03-21 12:08:40 -0400 | [diff] [blame] | 1046 | angle::Result ProgramVk::updateDescriptorSets(ContextVk *contextVk, |
| 1047 | vk::CommandBuffer *commandBuffer) |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1048 | { |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1049 | // Can probably use better dirty bits here. |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1050 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 1051 | if (mDescriptorSets.empty()) |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1052 | return angle::Result::Continue; |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1053 | |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 1054 | // Find the maximum non-null descriptor set. This is used in conjunction with a driver |
| 1055 | // workaround to bind empty descriptor sets only for gaps in between 0 and max and avoid |
| 1056 | // binding unnecessary empty descriptor sets for the sets beyond max. |
| 1057 | size_t descriptorSetRange = 0; |
| 1058 | for (size_t descriptorSetIndex = 0; descriptorSetIndex < mDescriptorSets.size(); |
| 1059 | ++descriptorSetIndex) |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1060 | { |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 1061 | if (mDescriptorSets[descriptorSetIndex] != VK_NULL_HANDLE) |
| 1062 | { |
| 1063 | descriptorSetRange = descriptorSetIndex + 1; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | for (size_t descriptorSetIndex = 0; descriptorSetIndex < descriptorSetRange; |
| 1068 | ++descriptorSetIndex) |
| 1069 | { |
| 1070 | VkDescriptorSet descSet = mDescriptorSets[descriptorSetIndex]; |
| 1071 | if (descSet == VK_NULL_HANDLE) |
| 1072 | { |
Jonah Ryan-Davis | 776694c | 2019-05-08 10:28:55 -0400 | [diff] [blame] | 1073 | if (!contextVk->getRenderer()->getFeatures().bindEmptyForUnusedDescriptorSets.enabled) |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 1074 | { |
| 1075 | continue; |
| 1076 | } |
| 1077 | |
| 1078 | // Workaround a driver bug where missing (though unused) descriptor sets indices cause |
| 1079 | // later sets to misbehave. |
| 1080 | if (mEmptyDescriptorSets[descriptorSetIndex] == VK_NULL_HANDLE) |
| 1081 | { |
| 1082 | vk::DynamicDescriptorPool *dynamicDescriptorPool = |
| 1083 | contextVk->getDynamicDescriptorPool(descriptorSetIndex); |
| 1084 | const vk::DescriptorSetLayout &descriptorSetLayout = |
| 1085 | mDescriptorSetLayouts[descriptorSetIndex].get(); |
| 1086 | |
| 1087 | ANGLE_TRY(dynamicDescriptorPool->allocateSets( |
| 1088 | contextVk, descriptorSetLayout.ptr(), 1, |
| 1089 | &mDescriptorPoolBindings[descriptorSetIndex], |
| 1090 | &mEmptyDescriptorSets[descriptorSetIndex])); |
| 1091 | } |
| 1092 | descSet = mEmptyDescriptorSets[descriptorSetIndex]; |
| 1093 | } |
| 1094 | |
Courtney Goeltzenleuchter | eaf2d92 | 2019-04-18 16:31:25 -0600 | [diff] [blame^] | 1095 | constexpr uint32_t kShaderTypeMin = static_cast<uint32_t>(gl::kGLES2ShaderTypeMin); |
| 1096 | constexpr uint32_t kShaderTypeMax = static_cast<uint32_t>(gl::kGLES2ShaderTypeMax); |
Shahbaz Youssefi | 216f73d | 2019-04-12 13:32:30 -0400 | [diff] [blame] | 1097 | constexpr uint32_t kShaderTypeCount = kShaderTypeMax - kShaderTypeMin + 1; |
| 1098 | |
| 1099 | // Default uniforms are encompassed in a block per shader stage, and they are assigned |
| 1100 | // through dynamic uniform buffers (requiring dynamic offsets). No other descriptor |
| 1101 | // requires a dynamic offset. |
| 1102 | const uint32_t uniformBlockOffsetCount = |
| 1103 | descriptorSetIndex == kUniformsDescriptorSetIndex ? kShaderTypeCount : 0; |
| 1104 | |
| 1105 | commandBuffer->bindGraphicsDescriptorSets(mPipelineLayout.get(), descriptorSetIndex, 1, |
| 1106 | &descSet, uniformBlockOffsetCount, |
| 1107 | mUniformBlocksOffsets.data() + kShaderTypeMin); |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1110 | return angle::Result::Continue; |
Jamie Madill | 242c4fe | 2018-07-12 15:56:56 -0400 | [diff] [blame] | 1111 | } |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 1112 | } // namespace rx |