Hash :
8ecf7f9b
Author :
Date :
2017-01-13T17:29:52
Vulkan: Implement shader compilation. This hooks up the Vulkan GLSL, decorated with locations, to glslang, and then pipes the SPIRV back to the Program implementation for later use when making pipelines to run draw calls. The program compilation tests work now, but don't really test anything other than not generating Vulkan validation layer errors during compilation and shader object generation. BUG=angleproject:1576 Change-Id: I625e42219f4b4d1433dd3109b94e1a2f666ba4bd Reviewed-on: https://chromium-review.googlesource.com/408519 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// renderervk_utils:
// Helper functions for the Vulkan Renderer.
//
#ifndef LIBANGLE_RENDERER_VULKAN_RENDERERVK_UTILS_H_
#define LIBANGLE_RENDERER_VULKAN_RENDERERVK_UTILS_H_
#include <vulkan/vulkan.h>
#include "common/Optional.h"
#include "libANGLE/Error.h"
namespace gl
{
struct Box;
struct Extents;
struct Rectangle;
}
namespace rx
{
const char *VulkanResultString(VkResult result);
bool HasStandardValidationLayer(const std::vector<VkLayerProperties> &layerProps);
extern const char *g_VkStdValidationLayerName;
enum class TextureDimension
{
TEX_2D,
TEX_CUBE,
TEX_3D,
TEX_2D_ARRAY,
};
namespace vk
{
class DeviceMemory;
class Framebuffer;
class Image;
class RenderPass;
class Error final
{
public:
Error(VkResult result);
Error(VkResult result, const char *file, unsigned int line);
~Error();
Error(const Error &other);
Error &operator=(const Error &other);
gl::Error toGL(GLenum glErrorCode) const;
egl::Error toEGL(EGLint eglErrorCode) const;
operator gl::Error() const;
operator egl::Error() const;
template <typename T>
operator gl::ErrorOrResult<T>() const
{
return static_cast<gl::Error>(*this);
}
bool isError() const;
private:
std::string getExtendedMessage() const;
VkResult mResult;
const char *mFile;
unsigned int mLine;
};
template <typename ResultT>
using ErrorOrResult = angle::ErrorOrResultBase<Error, ResultT, VkResult, VK_SUCCESS>;
// Avoid conflicting with X headers which define "Success".
inline Error NoError()
{
return Error(VK_SUCCESS);
}
template <typename HandleT>
class WrappedObject : angle::NonCopyable
{
public:
WrappedObject() : mDevice(VK_NULL_HANDLE), mHandle(VK_NULL_HANDLE) {}
explicit WrappedObject(VkDevice device) : mDevice(device), mHandle(VK_NULL_HANDLE) {}
WrappedObject(WrappedObject &&other) : mDevice(other.mDevice), mHandle(other.mHandle)
{
other.mDevice = VK_NULL_HANDLE;
other.mHandle = VK_NULL_HANDLE;
}
virtual ~WrappedObject() {}
HandleT getHandle() const { return mHandle; }
bool validDevice() const { return (mDevice != VK_NULL_HANDLE); }
bool valid() const { return (mHandle != VK_NULL_HANDLE) && validDevice(); }
protected:
void assignOpBase(WrappedObject &&other)
{
std::swap(mDevice, other.mDevice);
std::swap(mHandle, other.mHandle);
}
VkDevice mDevice;
HandleT mHandle;
};
// Helper class that wraps a Vulkan command buffer.
class CommandBuffer final : public WrappedObject<VkCommandBuffer>
{
public:
CommandBuffer(VkDevice device, VkCommandPool commandPool);
~CommandBuffer() override;
Error begin();
Error end();
Error reset();
void singleImageBarrier(VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
VkDependencyFlags dependencyFlags,
const VkImageMemoryBarrier &imageMemoryBarrier);
void clearSingleColorImage(const vk::Image &image, const VkClearColorValue &color);
void copySingleImage(const vk::Image &srcImage,
const vk::Image &destImage,
const gl::Box ©Region,
VkImageAspectFlags aspectMask);
void beginRenderPass(const RenderPass &renderPass,
const Framebuffer &framebuffer,
const gl::Rectangle &renderArea,
const std::vector<VkClearValue> &clearValues);
void endRenderPass();
private:
VkCommandPool mCommandPool;
};
class Image final : public WrappedObject<VkImage>
{
public:
// Use this constructor if the lifetime of the image is not controlled by ANGLE. (SwapChain)
Image();
Image(VkDevice device);
explicit Image(VkImage image);
Image(Image &&other);
Image &operator=(Image &&other);
~Image() override;
Error init(const VkImageCreateInfo &createInfo);
void changeLayoutTop(VkImageAspectFlags aspectMask,
VkImageLayout newLayout,
CommandBuffer *commandBuffer);
void changeLayoutWithStages(VkImageAspectFlags aspectMask,
VkImageLayout newLayout,
VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask,
CommandBuffer *commandBuffer);
void getMemoryRequirements(VkMemoryRequirements *requirementsOut) const;
Error bindMemory(const vk::DeviceMemory &deviceMemory);
VkImageLayout getCurrentLayout() const { return mCurrentLayout; }
void updateLayout(VkImageLayout layout) { mCurrentLayout = layout; }
private:
VkImageLayout mCurrentLayout;
};
class ImageView final : public WrappedObject<VkImageView>
{
public:
ImageView();
explicit ImageView(VkDevice device);
ImageView(ImageView &&other);
ImageView &operator=(ImageView &&other);
~ImageView() override;
Error init(const VkImageViewCreateInfo &createInfo);
};
class Semaphore final : public WrappedObject<VkSemaphore>
{
public:
Semaphore();
Semaphore(VkDevice device);
Semaphore(Semaphore &&other);
~Semaphore();
Semaphore &operator=(Semaphore &&other);
Error init();
};
class Framebuffer final : public WrappedObject<VkFramebuffer>
{
public:
Framebuffer();
Framebuffer(VkDevice device);
Framebuffer(Framebuffer &&other);
~Framebuffer();
Framebuffer &operator=(Framebuffer &&other);
Error init(const VkFramebufferCreateInfo &createInfo);
};
class DeviceMemory final : public WrappedObject<VkDeviceMemory>
{
public:
DeviceMemory();
DeviceMemory(VkDevice device);
DeviceMemory(DeviceMemory &&other);
~DeviceMemory();
DeviceMemory &operator=(DeviceMemory &&other);
Error allocate(const VkMemoryAllocateInfo &allocInfo);
Error map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, uint8_t **mapPointer);
void unmap();
};
class RenderPass final : public WrappedObject<VkRenderPass>
{
public:
RenderPass();
RenderPass(VkDevice device);
RenderPass(RenderPass &&other);
~RenderPass();
RenderPass &operator=(RenderPass &&other);
Error init(const VkRenderPassCreateInfo &createInfo);
};
class StagingImage final : angle::NonCopyable
{
public:
StagingImage();
StagingImage(VkDevice device);
StagingImage(StagingImage &&other);
~StagingImage();
StagingImage &operator=(StagingImage &&other);
vk::Error init(uint32_t queueFamilyIndex,
uint32_t hostVisibleMemoryIndex,
TextureDimension dimension,
VkFormat format,
const gl::Extents &extent);
Image &getImage() { return mImage; }
const Image &getImage() const { return mImage; }
DeviceMemory &getDeviceMemory() { return mDeviceMemory; }
const DeviceMemory &getDeviceMemory() const { return mDeviceMemory; }
VkDeviceSize getSize() const { return mSize; }
private:
Image mImage;
DeviceMemory mDeviceMemory;
VkDeviceSize mSize;
};
class Buffer final : public WrappedObject<VkBuffer>
{
public:
Buffer();
Buffer(VkDevice device);
Buffer(Buffer &&other);
~Buffer();
Buffer &operator=(Buffer &&other);
Error init(const VkBufferCreateInfo &createInfo);
Error bindMemory();
DeviceMemory &getMemory() { return mMemory; }
const DeviceMemory &getMemory() const { return mMemory; }
private:
DeviceMemory mMemory;
};
class ShaderModule final : public WrappedObject<VkShaderModule>
{
public:
ShaderModule();
ShaderModule(VkDevice device);
ShaderModule(ShaderModule &&other);
~ShaderModule() override;
ShaderModule &operator=(ShaderModule &&other);
Error init(const VkShaderModuleCreateInfo &createInfo);
};
} // namespace vk
Optional<uint32_t> FindMemoryType(const VkPhysicalDeviceMemoryProperties &memoryProps,
const VkMemoryRequirements &requirements,
uint32_t propertyFlagMask);
} // namespace rx
#define ANGLE_VK_TRY(command) \
{ \
auto ANGLE_LOCAL_VAR = command; \
if (ANGLE_LOCAL_VAR != VK_SUCCESS) \
{ \
return rx::vk::Error(ANGLE_LOCAL_VAR, __FILE__, __LINE__); \
} \
} \
ANGLE_EMPTY_STATEMENT
#define ANGLE_VK_CHECK(test, error) ANGLE_VK_TRY(test ? VK_SUCCESS : error)
#endif // LIBANGLE_RENDERER_VULKAN_RENDERERVK_UTILS_H_