Commit f618c9e5 by Jamie Madill Committed by Commit Bot

Vulkan: Add depth/stencil surfaces.

This change lets us create egl::Surfaces from a D24S8 config. This is a bit hacky, because the spec only mandates 24 -or- 32 bit depth support, but not both or either individually. Will need follow-up work for proper EGL config setup. A single depth buffer is allocated for the entire set of swapchain images and is used with each. This also might be a problem if we're rendering to multiple frames at the same time. We'll likely have to revisit this in the future as well. This adds a new RenderTargetVk to the SurfaceVk class which points to the Depth/Stencil image. Since ImageViews must refer to either the depth or stencil, but not both, we'll need to address this when we get to implementing depth/stencil texture reads in shaders. Bug: angleproject:2357 Change-Id: Ibed0eed7e1d0efb272758dbfc79fa2c5aa93997f Reviewed-on: https://chromium-review.googlesource.com/919761Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent b92f92a7
...@@ -40,19 +40,8 @@ SampleApplication::SampleApplication(const std::string &name, ...@@ -40,19 +40,8 @@ SampleApplication::SampleApplication(const std::string &name,
mEGLWindow->setConfigGreenBits(8); mEGLWindow->setConfigGreenBits(8);
mEGLWindow->setConfigBlueBits(8); mEGLWindow->setConfigBlueBits(8);
mEGLWindow->setConfigAlphaBits(8); mEGLWindow->setConfigAlphaBits(8);
// The Vulkan back-end currently does not support depth/stencil.
// TODO(jmadill): Remove this hack once Vulkan supports more configs.
if (requestedRenderer == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
{
mEGLWindow->setConfigDepthBits(0);
mEGLWindow->setConfigStencilBits(0);
}
else
{
mEGLWindow->setConfigDepthBits(24); mEGLWindow->setConfigDepthBits(24);
mEGLWindow->setConfigStencilBits(8); mEGLWindow->setConfigStencilBits(8);
}
// Disable vsync // Disable vsync
mEGLWindow->setSwapInterval(0); mEGLWindow->setSwapInterval(0);
......
...@@ -164,13 +164,14 @@ WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState, ...@@ -164,13 +164,14 @@ WindowSurfaceVk::WindowSurfaceVk(const egl::SurfaceState &surfaceState,
mSurface(VK_NULL_HANDLE), mSurface(VK_NULL_HANDLE),
mInstance(VK_NULL_HANDLE), mInstance(VK_NULL_HANDLE),
mSwapchain(VK_NULL_HANDLE), mSwapchain(VK_NULL_HANDLE),
mRenderTarget(), mColorRenderTarget(),
mDepthStencilRenderTarget(),
mCurrentSwapchainImageIndex(0) mCurrentSwapchainImageIndex(0)
{ {
mRenderTarget.extents.width = static_cast<GLint>(width); mColorRenderTarget.extents.width = static_cast<GLint>(width);
mRenderTarget.extents.height = static_cast<GLint>(height); mColorRenderTarget.extents.height = static_cast<GLint>(height);
mRenderTarget.extents.depth = 1; mColorRenderTarget.extents.depth = 1;
mRenderTarget.resource = this; mColorRenderTarget.resource = this;
} }
WindowSurfaceVk::~WindowSurfaceVk() WindowSurfaceVk::~WindowSurfaceVk()
...@@ -182,14 +183,19 @@ WindowSurfaceVk::~WindowSurfaceVk() ...@@ -182,14 +183,19 @@ WindowSurfaceVk::~WindowSurfaceVk()
void WindowSurfaceVk::destroy(const egl::Display *display) void WindowSurfaceVk::destroy(const egl::Display *display)
{ {
const DisplayVk *displayVk = vk::GetImpl(display); const DisplayVk *displayVk = vk::GetImpl(display);
RendererVk *rendererVk = displayVk->getRenderer(); RendererVk *renderer = displayVk->getRenderer();
VkDevice device = rendererVk->getDevice(); VkDevice device = renderer->getDevice();
VkInstance instance = rendererVk->getInstance(); VkInstance instance = renderer->getInstance();
rendererVk->finish(display->getProxyContext()); // We might not need to flush the pipe here.
renderer->finish(display->getProxyContext());
mAcquireNextImageSemaphore.destroy(device); mAcquireNextImageSemaphore.destroy(device);
renderer->releaseResource(*this, &mDepthStencilImage);
renderer->releaseResource(*this, &mDepthStencilDeviceMemory);
renderer->releaseResource(*this, &mDepthStencilImageView);
for (auto &swapchainImage : mSwapchainImages) for (auto &swapchainImage : mSwapchainImages)
{ {
// Although we don't own the swapchain image handles, we need to keep our shutdown clean. // Although we don't own the swapchain image handles, we need to keep our shutdown clean.
...@@ -227,7 +233,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -227,7 +233,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
uint32_t presentQueue = 0; uint32_t presentQueue = 0;
ANGLE_TRY_RESULT(renderer->selectPresentQueueForSurface(mSurface), presentQueue); ANGLE_TRY_RESULT(renderer->selectPresentQueueForSurface(mSurface), presentQueue);
(void) presentQueue; UNUSED_VARIABLE(presentQueue);
const VkPhysicalDevice &physicalDevice = renderer->getPhysicalDevice(); const VkPhysicalDevice &physicalDevice = renderer->getPhysicalDevice();
...@@ -246,18 +252,18 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -246,18 +252,18 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
{ {
ASSERT(surfaceCaps.currentExtent.height == 0xFFFFFFFFu); ASSERT(surfaceCaps.currentExtent.height == 0xFFFFFFFFu);
if (mRenderTarget.extents.width == 0) if (mColorRenderTarget.extents.width == 0)
{ {
width = windowSize.width; width = windowSize.width;
} }
if (mRenderTarget.extents.height == 0) if (mColorRenderTarget.extents.height == 0)
{ {
height = windowSize.height; height = windowSize.height;
} }
} }
mRenderTarget.extents.width = static_cast<int>(width); mColorRenderTarget.extents.width = static_cast<int>(width);
mRenderTarget.extents.height = static_cast<int>(height); mColorRenderTarget.extents.height = static_cast<int>(height);
uint32_t presentModeCount = 0; uint32_t presentModeCount = 0;
ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface, ANGLE_VK_TRY(vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, mSurface,
...@@ -300,8 +306,8 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -300,8 +306,8 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount,
surfaceFormats.data())); surfaceFormats.data()));
mRenderTarget.format = &renderer->getFormat(mState.config->renderTargetFormat); mColorRenderTarget.format = &renderer->getFormat(mState.config->renderTargetFormat);
VkFormat nativeFormat = mRenderTarget.format->vkTextureFormat; VkFormat nativeFormat = mColorRenderTarget.format->vkTextureFormat;
if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED) if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED)
{ {
...@@ -330,6 +336,11 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -330,6 +336,11 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
ANGLE_VK_CHECK((surfaceCaps.supportedCompositeAlpha & compositeAlpha) != 0, ANGLE_VK_CHECK((surfaceCaps.supportedCompositeAlpha & compositeAlpha) != 0,
VK_ERROR_INITIALIZATION_FAILED); VK_ERROR_INITIALIZATION_FAILED);
// We need transfer src for reading back from the backbuffer.
VkImageUsageFlags imageUsageFlags =
(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT);
VkSwapchainCreateInfoKHR swapchainInfo; VkSwapchainCreateInfoKHR swapchainInfo;
swapchainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; swapchainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swapchainInfo.pNext = nullptr; swapchainInfo.pNext = nullptr;
...@@ -341,8 +352,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -341,8 +352,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
swapchainInfo.imageExtent.width = width; swapchainInfo.imageExtent.width = width;
swapchainInfo.imageExtent.height = height; swapchainInfo.imageExtent.height = height;
swapchainInfo.imageArrayLayers = 1; swapchainInfo.imageArrayLayers = 1;
swapchainInfo.imageUsage = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | swapchainInfo.imageUsage = imageUsageFlags;
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
swapchainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swapchainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
swapchainInfo.queueFamilyIndexCount = 0; swapchainInfo.queueFamilyIndexCount = 0;
swapchainInfo.pQueueFamilyIndices = nullptr; swapchainInfo.pQueueFamilyIndices = nullptr;
...@@ -415,6 +425,85 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -415,6 +425,85 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
// Get the first available swapchain iamge. // Get the first available swapchain iamge.
ANGLE_TRY(nextSwapchainImage(renderer)); ANGLE_TRY(nextSwapchainImage(renderer));
// Initialize depth/stencil if requested.
if (mState.config->depthStencilFormat != GL_NONE)
{
const vk::Format &dsFormat = renderer->getFormat(mState.config->depthStencilFormat);
const VkImageUsageFlags usage =
(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
VkImageCreateInfo imageInfo;
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.pNext = nullptr;
imageInfo.flags = 0;
imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.format = dsFormat.vkTextureFormat;
imageInfo.extent.width = static_cast<uint32_t>(width);
imageInfo.extent.height = static_cast<uint32_t>(height);
imageInfo.extent.depth = 1;
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
imageInfo.usage = usage;
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageInfo.queueFamilyIndexCount = 0;
imageInfo.pQueueFamilyIndices = nullptr;
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
ANGLE_TRY(mDepthStencilImage.init(device, imageInfo));
// TODO(jmadill): Memory sub-allocation. http://anglebug.com/2162
size_t requiredSize;
ANGLE_TRY(vk::AllocateImageMemory(renderer, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&mDepthStencilImage, &mDepthStencilDeviceMemory,
&requiredSize));
const VkImageAspectFlags aspect =
(dsFormat.textureFormat().depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
(dsFormat.textureFormat().stencilBits > 0 ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
VkClearDepthStencilValue depthStencilClearValue = {1.0f, 0};
// Set transfer dest layout, and clear the image.
mDepthStencilImage.changeLayoutWithStages(aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
commandBuffer->clearSingleDepthStencilImage(mDepthStencilImage, aspect,
depthStencilClearValue);
// Depth/Stencil image views.
VkImageViewCreateInfo imageViewInfo;
imageViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
imageViewInfo.pNext = nullptr;
imageViewInfo.flags = 0;
imageViewInfo.image = mDepthStencilImage.getHandle();
imageViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
imageViewInfo.format = dsFormat.vkTextureFormat;
imageViewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
imageViewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
imageViewInfo.subresourceRange.aspectMask = aspect;
imageViewInfo.subresourceRange.baseMipLevel = 0;
imageViewInfo.subresourceRange.levelCount = 1;
imageViewInfo.subresourceRange.baseArrayLayer = 0;
imageViewInfo.subresourceRange.layerCount = 1;
ANGLE_TRY(mDepthStencilImageView.init(device, imageViewInfo));
mDepthStencilRenderTarget.extents.width = static_cast<GLint>(width);
mDepthStencilRenderTarget.extents.height = static_cast<GLint>(height);
mDepthStencilRenderTarget.extents.depth = 1;
mDepthStencilRenderTarget.resource = this;
mDepthStencilRenderTarget.image = &mDepthStencilImage;
mDepthStencilRenderTarget.format = &dsFormat;
// TODO(jmadill): Figure out how to pass depth/stencil image views to the RenderTargetVk.
}
return vk::NoError(); return vk::NoError();
} }
...@@ -472,8 +561,8 @@ vk::Error WindowSurfaceVk::nextSwapchainImage(RendererVk *renderer) ...@@ -472,8 +561,8 @@ vk::Error WindowSurfaceVk::nextSwapchainImage(RendererVk *renderer)
std::swap(image.imageAcquiredSemaphore, mAcquireNextImageSemaphore); std::swap(image.imageAcquiredSemaphore, mAcquireNextImageSemaphore);
// Update RenderTarget pointers. // Update RenderTarget pointers.
mRenderTarget.image = &image.image; mColorRenderTarget.image = &image.image;
mRenderTarget.imageView = &image.imageView; mColorRenderTarget.imageView = &image.imageView;
return vk::NoError(); return vk::NoError();
} }
...@@ -518,12 +607,12 @@ void WindowSurfaceVk::setSwapInterval(EGLint interval) ...@@ -518,12 +607,12 @@ void WindowSurfaceVk::setSwapInterval(EGLint interval)
EGLint WindowSurfaceVk::getWidth() const EGLint WindowSurfaceVk::getWidth() const
{ {
return static_cast<EGLint>(mRenderTarget.extents.width); return static_cast<EGLint>(mColorRenderTarget.extents.width);
} }
EGLint WindowSurfaceVk::getHeight() const EGLint WindowSurfaceVk::getHeight() const
{ {
return static_cast<EGLint>(mRenderTarget.extents.height); return static_cast<EGLint>(mColorRenderTarget.extents.height);
} }
EGLint WindowSurfaceVk::isPostSubBufferSupported() const EGLint WindowSurfaceVk::isPostSubBufferSupported() const
...@@ -539,11 +628,20 @@ EGLint WindowSurfaceVk::getSwapBehavior() const ...@@ -539,11 +628,20 @@ EGLint WindowSurfaceVk::getSwapBehavior() const
} }
gl::Error WindowSurfaceVk::getAttachmentRenderTarget(const gl::Context * /*context*/, gl::Error WindowSurfaceVk::getAttachmentRenderTarget(const gl::Context * /*context*/,
GLenum /*binding*/, GLenum binding,
const gl::ImageIndex & /*target*/, const gl::ImageIndex & /*target*/,
FramebufferAttachmentRenderTarget **rtOut) FramebufferAttachmentRenderTarget **rtOut)
{ {
*rtOut = &mRenderTarget; if (binding == GL_BACK)
{
*rtOut = &mColorRenderTarget;
}
else
{
ASSERT(binding == GL_DEPTH || binding == GL_STENCIL || binding == GL_DEPTH_STENCIL);
*rtOut = &mDepthStencilRenderTarget;
}
return gl::NoError(); return gl::NoError();
} }
...@@ -561,20 +659,21 @@ gl::ErrorOrResult<vk::Framebuffer *> WindowSurfaceVk::getCurrentFramebuffer( ...@@ -561,20 +659,21 @@ gl::ErrorOrResult<vk::Framebuffer *> WindowSurfaceVk::getCurrentFramebuffer(
VkFramebufferCreateInfo framebufferInfo; VkFramebufferCreateInfo framebufferInfo;
// TODO(jmadill): Depth/Stencil attachments. std::array<VkImageView, 2> imageViews = {{VK_NULL_HANDLE, mDepthStencilImageView.getHandle()}};
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
framebufferInfo.pNext = nullptr; framebufferInfo.pNext = nullptr;
framebufferInfo.flags = 0; framebufferInfo.flags = 0;
framebufferInfo.renderPass = compatibleRenderPass.getHandle(); framebufferInfo.renderPass = compatibleRenderPass.getHandle();
framebufferInfo.attachmentCount = 1u; framebufferInfo.attachmentCount = (mDepthStencilImageView.valid() ? 2u : 1u);
framebufferInfo.pAttachments = nullptr; framebufferInfo.pAttachments = imageViews.data();
framebufferInfo.width = static_cast<uint32_t>(mRenderTarget.extents.width); framebufferInfo.width = static_cast<uint32_t>(mColorRenderTarget.extents.width);
framebufferInfo.height = static_cast<uint32_t>(mRenderTarget.extents.height); framebufferInfo.height = static_cast<uint32_t>(mColorRenderTarget.extents.height);
framebufferInfo.layers = 1; framebufferInfo.layers = 1;
for (auto &swapchainImage : mSwapchainImages) for (auto &swapchainImage : mSwapchainImages)
{ {
framebufferInfo.pAttachments = swapchainImage.imageView.ptr(); imageViews[0] = swapchainImage.imageView.getHandle();
ANGLE_TRY(swapchainImage.framebuffer.init(device, framebufferInfo)); ANGLE_TRY(swapchainImage.framebuffer.init(device, framebufferInfo));
} }
......
...@@ -116,7 +116,8 @@ class WindowSurfaceVk : public SurfaceImpl, public ResourceVk ...@@ -116,7 +116,8 @@ class WindowSurfaceVk : public SurfaceImpl, public ResourceVk
VkSwapchainKHR mSwapchain; VkSwapchainKHR mSwapchain;
RenderTargetVk mRenderTarget; RenderTargetVk mColorRenderTarget;
RenderTargetVk mDepthStencilRenderTarget;
uint32_t mCurrentSwapchainImageIndex; uint32_t mCurrentSwapchainImageIndex;
...@@ -141,6 +142,10 @@ class WindowSurfaceVk : public SurfaceImpl, public ResourceVk ...@@ -141,6 +142,10 @@ class WindowSurfaceVk : public SurfaceImpl, public ResourceVk
}; };
std::vector<SwapchainImage> mSwapchainImages; std::vector<SwapchainImage> mSwapchainImages;
vk::Image mDepthStencilImage;
vk::DeviceMemory mDepthStencilDeviceMemory;
vk::ImageView mDepthStencilImageView;
}; };
} // namespace rx } // namespace rx
......
...@@ -37,45 +37,52 @@ SurfaceImpl *DisplayVkAndroid::createWindowSurfaceVk(const egl::SurfaceState &st ...@@ -37,45 +37,52 @@ SurfaceImpl *DisplayVkAndroid::createWindowSurfaceVk(const egl::SurfaceState &st
egl::ConfigSet DisplayVkAndroid::generateConfigs() egl::ConfigSet DisplayVkAndroid::generateConfigs()
{ {
// TODO(jmadill): Multiple configs, pbuffers, and proper checking of config attribs. // TODO(jmadill): Multiple configs, pbuffers, and proper checking of config attribs.
egl::Config singleton; egl::Config rgba;
singleton.renderTargetFormat = GL_RGBA8; rgba.renderTargetFormat = GL_RGBA8;
singleton.depthStencilFormat = GL_NONE; rgba.depthStencilFormat = GL_NONE;
singleton.bufferSize = 32; rgba.bufferSize = 32;
singleton.redSize = 8; rgba.redSize = 8;
singleton.greenSize = 8; rgba.greenSize = 8;
singleton.blueSize = 8; rgba.blueSize = 8;
singleton.alphaSize = 8; rgba.alphaSize = 8;
singleton.alphaMaskSize = 0; rgba.alphaMaskSize = 0;
singleton.bindToTextureRGB = EGL_FALSE; rgba.bindToTextureRGB = EGL_FALSE;
singleton.bindToTextureRGBA = EGL_FALSE; rgba.bindToTextureRGBA = EGL_FALSE;
singleton.colorBufferType = EGL_RGB_BUFFER; rgba.colorBufferType = EGL_RGB_BUFFER;
singleton.configCaveat = EGL_NONE; rgba.configCaveat = EGL_NONE;
singleton.conformant = 0; rgba.conformant = 0;
singleton.depthSize = 0; rgba.depthSize = 0;
singleton.stencilSize = 0; rgba.stencilSize = 0;
singleton.level = 0; rgba.level = 0;
singleton.matchNativePixmap = EGL_NONE; rgba.matchNativePixmap = EGL_NONE;
singleton.maxPBufferWidth = 0; rgba.maxPBufferWidth = 0;
singleton.maxPBufferHeight = 0; rgba.maxPBufferHeight = 0;
singleton.maxPBufferPixels = 0; rgba.maxPBufferPixels = 0;
singleton.maxSwapInterval = 1; rgba.maxSwapInterval = 1;
singleton.minSwapInterval = 1; rgba.minSwapInterval = 1;
singleton.nativeRenderable = EGL_TRUE; rgba.nativeRenderable = EGL_TRUE;
singleton.nativeVisualID = 0; rgba.nativeVisualID = 0;
singleton.nativeVisualType = EGL_NONE; rgba.nativeVisualType = EGL_NONE;
singleton.renderableType = EGL_OPENGL_ES2_BIT; rgba.renderableType = EGL_OPENGL_ES2_BIT;
singleton.sampleBuffers = 0; rgba.sampleBuffers = 0;
singleton.samples = 0; rgba.samples = 0;
singleton.surfaceType = EGL_WINDOW_BIT; rgba.surfaceType = EGL_WINDOW_BIT;
singleton.optimalOrientation = 0; rgba.optimalOrientation = 0;
singleton.transparentType = EGL_NONE; rgba.transparentType = EGL_NONE;
singleton.transparentRedValue = 0; rgba.transparentRedValue = 0;
singleton.transparentGreenValue = 0; rgba.transparentGreenValue = 0;
singleton.transparentBlueValue = 0; rgba.transparentBlueValue = 0;
singleton.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; rgba.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
egl::Config rgbaD24S8;
rgbaD24S8 = rgba;
rgbaD24S8.depthStencilFormat = GL_DEPTH24_STENCIL8;
rgbaD24S8.depthSize = 24;
rgbaD24S8.stencilSize = 8;
egl::ConfigSet configSet; egl::ConfigSet configSet;
configSet.add(singleton); configSet.add(rgba);
configSet.add(rgbaD24S8);
return configSet; return configSet;
} }
......
...@@ -211,7 +211,7 @@ void RenderPassDesc::packColorAttachment(const vk::Format &format, GLsizei sampl ...@@ -211,7 +211,7 @@ void RenderPassDesc::packColorAttachment(const vk::Format &format, GLsizei sampl
void RenderPassDesc::packDepthStencilAttachment(const vk::Format &format, GLsizei samples) void RenderPassDesc::packDepthStencilAttachment(const vk::Format &format, GLsizei samples)
{ {
ASSERT(mDepthStencilAttachmentCount == 0); ASSERT(mDepthStencilAttachmentCount == 0);
packAttachment(mDepthStencilAttachmentCount++, format, samples); packAttachment(mColorAttachmentCount + mDepthStencilAttachmentCount++, format, samples);
} }
RenderPassDesc &RenderPassDesc::operator=(const RenderPassDesc &other) RenderPassDesc &RenderPassDesc::operator=(const RenderPassDesc &other)
......
...@@ -472,6 +472,34 @@ void CommandBuffer::clearSingleColorImage(const vk::Image &image, const VkClearC ...@@ -472,6 +472,34 @@ void CommandBuffer::clearSingleColorImage(const vk::Image &image, const VkClearC
vkCmdClearColorImage(mHandle, image.getHandle(), image.getCurrentLayout(), &color, 1, &range); vkCmdClearColorImage(mHandle, image.getHandle(), image.getCurrentLayout(), &color, 1, &range);
} }
void CommandBuffer::clearSingleDepthStencilImage(const vk::Image &image,
VkImageAspectFlags aspectFlags,
const VkClearDepthStencilValue &depthStencil)
{
VkImageSubresourceRange clearRange = {
/*aspectMask*/ aspectFlags,
/*baseMipLevel*/ 0,
/*levelCount*/ 1,
/*baseArrayLayer*/ 0,
/*layerCount*/ 1,
};
clearDepthStencilImage(image, depthStencil, 1, &clearRange);
}
void CommandBuffer::clearDepthStencilImage(const vk::Image &image,
const VkClearDepthStencilValue &depthStencil,
uint32_t rangeCount,
const VkImageSubresourceRange *ranges)
{
ASSERT(valid());
ASSERT(image.getCurrentLayout() == VK_IMAGE_LAYOUT_GENERAL ||
image.getCurrentLayout() == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
vkCmdClearDepthStencilImage(mHandle, image.getHandle(), image.getCurrentLayout(), &depthStencil,
rangeCount, ranges);
}
void CommandBuffer::copySingleImage(const vk::Image &srcImage, void CommandBuffer::copySingleImage(const vk::Image &srcImage,
const vk::Image &destImage, const vk::Image &destImage,
const gl::Box &copyRegion, const gl::Box &copyRegion,
...@@ -1414,7 +1442,7 @@ void ResourceVk::onWriteResource(vk::CommandBufferNode *writeOperation, Serial s ...@@ -1414,7 +1442,7 @@ void ResourceVk::onWriteResource(vk::CommandBufferNode *writeOperation, Serial s
mCurrentReadOperations.clear(); mCurrentReadOperations.clear();
} }
if (mCurrentWriteOperation) if (mCurrentWriteOperation && mCurrentWriteOperation != writeOperation)
{ {
vk::CommandBufferNode::SetHappensBeforeDependency(mCurrentWriteOperation, writeOperation); vk::CommandBufferNode::SetHappensBeforeDependency(mCurrentWriteOperation, writeOperation);
} }
......
...@@ -331,6 +331,14 @@ class CommandBuffer : public WrappedObject<CommandBuffer, VkCommandBuffer> ...@@ -331,6 +331,14 @@ class CommandBuffer : public WrappedObject<CommandBuffer, VkCommandBuffer>
const VkBufferMemoryBarrier &bufferBarrier); const VkBufferMemoryBarrier &bufferBarrier);
void clearSingleColorImage(const vk::Image &image, const VkClearColorValue &color); void clearSingleColorImage(const vk::Image &image, const VkClearColorValue &color);
void clearSingleDepthStencilImage(const vk::Image &image,
VkImageAspectFlags aspectFlags,
const VkClearDepthStencilValue &depthStencil);
void clearDepthStencilImage(const vk::Image &image,
const VkClearDepthStencilValue &depthStencil,
uint32_t rangeCount,
const VkImageSubresourceRange *ranges);
void copyBuffer(const vk::Buffer &srcBuffer, void copyBuffer(const vk::Buffer &srcBuffer,
const vk::Buffer &destBuffer, const vk::Buffer &destBuffer,
......
...@@ -36,45 +36,52 @@ SurfaceImpl *DisplayVkWin32::createWindowSurfaceVk(const egl::SurfaceState &stat ...@@ -36,45 +36,52 @@ SurfaceImpl *DisplayVkWin32::createWindowSurfaceVk(const egl::SurfaceState &stat
egl::ConfigSet DisplayVkWin32::generateConfigs() egl::ConfigSet DisplayVkWin32::generateConfigs()
{ {
// TODO(jmadill): Multiple configs, pbuffers, and proper checking of config attribs. // TODO(jmadill): Multiple configs, pbuffers, and proper checking of config attribs.
egl::Config singleton; egl::Config bgra;
singleton.renderTargetFormat = GL_BGRA8_EXT; bgra.renderTargetFormat = GL_BGRA8_EXT;
singleton.depthStencilFormat = GL_NONE; bgra.depthStencilFormat = GL_NONE;
singleton.bufferSize = 32; bgra.bufferSize = 32;
singleton.redSize = 8; bgra.redSize = 8;
singleton.greenSize = 8; bgra.greenSize = 8;
singleton.blueSize = 8; bgra.blueSize = 8;
singleton.alphaSize = 8; bgra.alphaSize = 8;
singleton.alphaMaskSize = 0; bgra.alphaMaskSize = 0;
singleton.bindToTextureRGB = EGL_FALSE; bgra.bindToTextureRGB = EGL_FALSE;
singleton.bindToTextureRGBA = EGL_FALSE; bgra.bindToTextureRGBA = EGL_FALSE;
singleton.colorBufferType = EGL_RGB_BUFFER; bgra.colorBufferType = EGL_RGB_BUFFER;
singleton.configCaveat = EGL_NONE; bgra.configCaveat = EGL_NONE;
singleton.conformant = 0; bgra.conformant = 0;
singleton.depthSize = 0; bgra.depthSize = 0;
singleton.stencilSize = 0; bgra.stencilSize = 0;
singleton.level = 0; bgra.level = 0;
singleton.matchNativePixmap = EGL_NONE; bgra.matchNativePixmap = EGL_NONE;
singleton.maxPBufferWidth = 0; bgra.maxPBufferWidth = 0;
singleton.maxPBufferHeight = 0; bgra.maxPBufferHeight = 0;
singleton.maxPBufferPixels = 0; bgra.maxPBufferPixels = 0;
singleton.maxSwapInterval = 1; bgra.maxSwapInterval = 1;
singleton.minSwapInterval = 1; bgra.minSwapInterval = 1;
singleton.nativeRenderable = EGL_TRUE; bgra.nativeRenderable = EGL_TRUE;
singleton.nativeVisualID = 0; bgra.nativeVisualID = 0;
singleton.nativeVisualType = EGL_NONE; bgra.nativeVisualType = EGL_NONE;
singleton.renderableType = EGL_OPENGL_ES2_BIT; bgra.renderableType = EGL_OPENGL_ES2_BIT;
singleton.sampleBuffers = 0; bgra.sampleBuffers = 0;
singleton.samples = 0; bgra.samples = 0;
singleton.surfaceType = EGL_WINDOW_BIT; bgra.surfaceType = EGL_WINDOW_BIT;
singleton.optimalOrientation = 0; bgra.optimalOrientation = 0;
singleton.transparentType = EGL_NONE; bgra.transparentType = EGL_NONE;
singleton.transparentRedValue = 0; bgra.transparentRedValue = 0;
singleton.transparentGreenValue = 0; bgra.transparentGreenValue = 0;
singleton.transparentBlueValue = 0; bgra.transparentBlueValue = 0;
singleton.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; bgra.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
egl::Config bgraD24S8;
bgraD24S8 = bgra;
bgraD24S8.depthStencilFormat = GL_DEPTH24_STENCIL8;
bgraD24S8.depthSize = 24;
bgraD24S8.stencilSize = 8;
egl::ConfigSet configSet; egl::ConfigSet configSet;
configSet.add(singleton); configSet.add(bgra);
configSet.add(bgraD24S8);
return configSet; return configSet;
} }
......
...@@ -64,45 +64,52 @@ SurfaceImpl *DisplayVkXcb::createWindowSurfaceVk(const egl::SurfaceState &state, ...@@ -64,45 +64,52 @@ SurfaceImpl *DisplayVkXcb::createWindowSurfaceVk(const egl::SurfaceState &state,
egl::ConfigSet DisplayVkXcb::generateConfigs() egl::ConfigSet DisplayVkXcb::generateConfigs()
{ {
// TODO(jmadill): Multiple configs, pbuffers, and proper checking of config attribs. // TODO(jmadill): Multiple configs, pbuffers, and proper checking of config attribs.
egl::Config singleton; egl::Config bgra;
singleton.renderTargetFormat = GL_BGRA8_EXT; bgra.renderTargetFormat = GL_BGRA8_EXT;
singleton.depthStencilFormat = GL_NONE; bgra.depthStencilFormat = GL_NONE;
singleton.bufferSize = 32; bgra.bufferSize = 32;
singleton.redSize = 8; bgra.redSize = 8;
singleton.greenSize = 8; bgra.greenSize = 8;
singleton.blueSize = 8; bgra.blueSize = 8;
singleton.alphaSize = 8; bgra.alphaSize = 8;
singleton.alphaMaskSize = 0; bgra.alphaMaskSize = 0;
singleton.bindToTextureRGB = EGL_FALSE; bgra.bindToTextureRGB = EGL_FALSE;
singleton.bindToTextureRGBA = EGL_FALSE; bgra.bindToTextureRGBA = EGL_FALSE;
singleton.colorBufferType = EGL_RGB_BUFFER; bgra.colorBufferType = EGL_RGB_BUFFER;
singleton.configCaveat = EGL_NONE; bgra.configCaveat = EGL_NONE;
singleton.conformant = 0; bgra.conformant = 0;
singleton.depthSize = 0; bgra.depthSize = 0;
singleton.stencilSize = 0; bgra.stencilSize = 0;
singleton.level = 0; bgra.level = 0;
singleton.matchNativePixmap = EGL_NONE; bgra.matchNativePixmap = EGL_NONE;
singleton.maxPBufferWidth = 0; bgra.maxPBufferWidth = 0;
singleton.maxPBufferHeight = 0; bgra.maxPBufferHeight = 0;
singleton.maxPBufferPixels = 0; bgra.maxPBufferPixels = 0;
singleton.maxSwapInterval = 1; bgra.maxSwapInterval = 1;
singleton.minSwapInterval = 1; bgra.minSwapInterval = 1;
singleton.nativeRenderable = EGL_TRUE; bgra.nativeRenderable = EGL_TRUE;
singleton.nativeVisualID = 0; bgra.nativeVisualID = 0;
singleton.nativeVisualType = EGL_NONE; bgra.nativeVisualType = EGL_NONE;
singleton.renderableType = EGL_OPENGL_ES2_BIT; bgra.renderableType = EGL_OPENGL_ES2_BIT;
singleton.sampleBuffers = 0; bgra.sampleBuffers = 0;
singleton.samples = 0; bgra.samples = 0;
singleton.surfaceType = EGL_WINDOW_BIT; bgra.surfaceType = EGL_WINDOW_BIT;
singleton.optimalOrientation = 0; bgra.optimalOrientation = 0;
singleton.transparentType = EGL_NONE; bgra.transparentType = EGL_NONE;
singleton.transparentRedValue = 0; bgra.transparentRedValue = 0;
singleton.transparentGreenValue = 0; bgra.transparentGreenValue = 0;
singleton.transparentBlueValue = 0; bgra.transparentBlueValue = 0;
singleton.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; bgra.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
egl::Config bgraD24S8;
bgraD24S8 = bgra;
bgraD24S8.depthStencilFormat = GL_DEPTH24_STENCIL8;
bgraD24S8.depthSize = 24;
bgraD24S8.stencilSize = 8;
egl::ConfigSet configSet; egl::ConfigSet configSet;
configSet.add(singleton); configSet.add(bgra);
configSet.add(bgraD24S8);
return configSet; return configSet;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "test_utils/ANGLETest.h" #include "test_utils/ANGLETest.h"
#include "random_utils.h" #include "random_utils.h"
#include "test_utils/gl_raii.h"
using namespace angle; using namespace angle;
...@@ -117,8 +118,7 @@ TEST_P(ClearTest, RGBA8Framebuffer) ...@@ -117,8 +118,7 @@ TEST_P(ClearTest, RGBA8Framebuffer)
{ {
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
GLuint texture; GLTexture texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
...@@ -133,6 +133,9 @@ TEST_P(ClearTest, RGBA8Framebuffer) ...@@ -133,6 +133,9 @@ TEST_P(ClearTest, RGBA8Framebuffer)
TEST_P(ClearTest, ClearIssue) TEST_P(ClearTest, ClearIssue)
{ {
// TODO(jmadill): Depth/Stencil clears on Vulkan. http://anglebug.com/2357
ANGLE_SKIP_TEST_IF(IsVulkan());
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
...@@ -144,8 +147,7 @@ TEST_P(ClearTest, ClearIssue) ...@@ -144,8 +147,7 @@ TEST_P(ClearTest, ClearIssue)
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
GLuint rbo; GLRenderbuffer rbo;
glGenRenderbuffers(1, &rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rbo); glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
...@@ -179,8 +181,7 @@ TEST_P(ClearTestES3, MaskedClearBufferBug) ...@@ -179,8 +181,7 @@ TEST_P(ClearTestES3, MaskedClearBufferBug)
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
GLuint textures[2]; GLTexture textures[2];
glGenTextures(2, &textures[0]);
glBindTexture(GL_TEXTURE_2D, textures[0]); glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
...@@ -206,8 +207,6 @@ TEST_P(ClearTestES3, MaskedClearBufferBug) ...@@ -206,8 +207,6 @@ TEST_P(ClearTestES3, MaskedClearBufferBug)
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1); EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1);
glDeleteTextures(2, textures);
} }
TEST_P(ClearTestES3, BadFBOSerialBug) TEST_P(ClearTestES3, BadFBOSerialBug)
...@@ -215,8 +214,7 @@ TEST_P(ClearTestES3, BadFBOSerialBug) ...@@ -215,8 +214,7 @@ TEST_P(ClearTestES3, BadFBOSerialBug)
// First make a simple framebuffer, and clear it to green // First make a simple framebuffer, and clear it to green
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
GLuint textures[2]; GLTexture textures[2];
glGenTextures(2, &textures[0]);
glBindTexture(GL_TEXTURE_2D, textures[0]); glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
...@@ -233,11 +231,9 @@ TEST_P(ClearTestES3, BadFBOSerialBug) ...@@ -233,11 +231,9 @@ TEST_P(ClearTestES3, BadFBOSerialBug)
// Next make a second framebuffer, and draw it to red // Next make a second framebuffer, and draw it to red
// (Triggers bad applied render target serial) // (Triggers bad applied render target serial)
GLuint fbo2; GLFramebuffer fbo2;
glGenFramebuffers(1, &fbo2);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_FRAMEBUFFER, fbo2); glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
ASSERT_GL_NO_ERROR();
glBindTexture(GL_TEXTURE_2D, textures[1]); glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
...@@ -254,9 +250,6 @@ TEST_P(ClearTestES3, BadFBOSerialBug) ...@@ -254,9 +250,6 @@ TEST_P(ClearTestES3, BadFBOSerialBug)
// Check that the first framebuffer is still green. // Check that the first framebuffer is still green.
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
glDeleteTextures(2, textures);
glDeleteFramebuffers(1, &fbo2);
} }
// Test that SRGB framebuffers clear to the linearized clear color // Test that SRGB framebuffers clear to the linearized clear color
...@@ -265,8 +258,7 @@ TEST_P(ClearTestES3, SRGBClear) ...@@ -265,8 +258,7 @@ TEST_P(ClearTestES3, SRGBClear)
// First make a simple framebuffer, and clear it // First make a simple framebuffer, and clear it
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
GLuint texture; GLTexture texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight()); glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
...@@ -284,8 +276,7 @@ TEST_P(ClearTestES3, MixedSRGBClear) ...@@ -284,8 +276,7 @@ TEST_P(ClearTestES3, MixedSRGBClear)
{ {
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
GLuint textures[2]; GLTexture textures[2];
glGenTextures(2, &textures[0]);
glBindTexture(GL_TEXTURE_2D, textures[0]); glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight()); glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
...@@ -481,7 +472,8 @@ ANGLE_INSTANTIATE_TEST(ClearTest, ...@@ -481,7 +472,8 @@ ANGLE_INSTANTIATE_TEST(ClearTest,
ES2_OPENGL(), ES2_OPENGL(),
ES3_OPENGL(), ES3_OPENGL(),
ES2_OPENGLES(), ES2_OPENGLES(),
ES3_OPENGLES()); ES3_OPENGLES(),
ES2_VULKAN());
ANGLE_INSTANTIATE_TEST(ClearTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); ANGLE_INSTANTIATE_TEST(ClearTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
ANGLE_INSTANTIATE_TEST(ScissoredClearTest, ES2_D3D11(), ES2_OPENGL(), ES2_VULKAN()); ANGLE_INSTANTIATE_TEST(ScissoredClearTest, ES2_D3D11(), ES2_OPENGL(), ES2_VULKAN());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment