Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement VK_KHR_depth_stencil_resolve #1066

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gapis/api/vulkan/api/bitfields.api
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,6 @@ bitfield VkSemaphoreWaitFlagBits {
VK_SEMAPHORE_WAIT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
}
type VkFlags VkSemaphoreWaitFlags

//@extension("VK_KHR_depth_stencil_resolve")
type VkFlags VkResolveModeFlags
11 changes: 11 additions & 0 deletions gapis/api/vulkan/api/enums.api
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ enum VkStructureType: u32 {
VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO = 1000108003,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES = 1000130000,
VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO = 1000130001,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES = 1000199000,
VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE = 1000199001,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES = 1000241000,
VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_STENCIL_LAYOUT = 1000241001,
VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT = 1000241002,
Expand Down Expand Up @@ -1183,3 +1185,12 @@ enum VkTessellationDomainOrigin: u32 {
VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT = 0,
VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT = 1,
}

// Vulkan 1.2 core
enum VkResolveModeFlagBits: u32 {
VK_RESOLVE_MODE_NONE = 0x00000000,
VK_RESOLVE_MODE_SAMPLE_ZERO_BIT = 0x00000001,
VK_RESOLVE_MODE_AVERAGE_BIT = 0x00000002,
VK_RESOLVE_MODE_MIN_BIT = 0x00000004,
VK_RESOLVE_MODE_MAX_BIT = 0x00000008,
}
1 change: 1 addition & 0 deletions gapis/api/vulkan/api/physical_device.api
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

// Vulkan 1.2 core
@unused ref!PhysicalDeviceSamplerFilterMinmaxProperties PhysicalDeviceSamplerFilterMinmaxProperties
@unused ref!PhysicalDeviceDepthStencilResolveProperties PhysicalDeviceDepthStencilResolveProperties

// Extensions
@unused ref!PhysicalDevicePCIBusInfoPropertiesEXT PhysicalDevicePCIBusInfoPropertiesEXT
Expand Down
13 changes: 13 additions & 0 deletions gapis/api/vulkan/api/properties_features_requirements.api
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ sub void GetPhysicalDeviceProperties2(
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES: {
_ = as!VkPhysicalDeviceSamplerFilterMinmaxProperties*(next.Ptr)[0]
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES: {
_ = as!VkPhysicalDeviceDepthStencilResolveProperties*(next.Ptr)[0]
}

}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0].PNext
}
Expand Down Expand Up @@ -877,6 +881,15 @@ sub void GetPhysicalDeviceProperties2(
FilterMinmaxImageComponentMapping: ext.filterMinmaxImageComponentMapping,
)
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES: {
ext := as!VkPhysicalDeviceDepthStencilResolveProperties*(next.Ptr)[0]
phyDev.PhysicalDeviceDepthStencilResolveProperties = new!PhysicalDeviceDepthStencilResolveProperties(
SupportedDepthResolveModes: ext.supportedDepthResolveModes,
SupportedStencilResolveModes: ext.supportedStencilResolveModes,
IndependentResolveNone: ext.independentResolveNone,
IndependentResolve: ext.independentResolve,
)
}
}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0].PNext
}
Expand Down
63 changes: 45 additions & 18 deletions gapis/api/vulkan/api/renderpass_framebuffer.api
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ Thefore there is no need to repeat the KHR structs
}

@internal class AttachmentDescription {
VkAttachmentDescriptionFlags Flags
VkFormat Format
VkSampleCountFlagBits Samples
VkAttachmentLoadOp LoadOp
VkAttachmentStoreOp StoreOp
VkAttachmentLoadOp StencilLoadOp
VkAttachmentStoreOp StencilStoreOp
VkImageLayout InitialLayout
VkImageLayout FinalLayout
ref!AttachmentDescriptionStencilLayout StencilLayout
VkAttachmentDescriptionFlags Flags
VkFormat Format
VkSampleCountFlagBits Samples
VkAttachmentLoadOp LoadOp
VkAttachmentStoreOp StoreOp
VkAttachmentLoadOp StencilLoadOp
VkAttachmentStoreOp StencilStoreOp
VkImageLayout InitialLayout
VkImageLayout FinalLayout
ref!AttachmentDescriptionStencilLayout StencilLayout
}

@internal class AttachmentReferenceStencilLayout {
Expand All @@ -188,15 +188,22 @@ Thefore there is no need to repeat the KHR structs
ref!AttachmentReferenceStencilLayout StencilLayout
}

@internal class SubpassDescriptionDepthStencilResolve {
VkResolveModeFlagBits DepthResolveMode
VkResolveModeFlagBits StencilResolveMode
AttachmentReference DepthStencilResolveAttachment
}

@internal class SubpassDescription {
VkSubpassDescriptionFlags Flags
u32 ViewMask
VkPipelineBindPoint PipelineBindPoint
map!(u32, AttachmentReference) InputAttachments
map!(u32, AttachmentReference) ColorAttachments
map!(u32, AttachmentReference) ResolveAttachments
ref!AttachmentReference DepthStencilAttachment
map!(u32, u32) PreserveAttachments
VkSubpassDescriptionFlags Flags
u32 ViewMask
VkPipelineBindPoint PipelineBindPoint
map!(u32, AttachmentReference) InputAttachments
map!(u32, AttachmentReference) ColorAttachments
map!(u32, AttachmentReference) ResolveAttachments
ref!AttachmentReference DepthStencilAttachment
map!(u32, u32) PreserveAttachments
ref!SubpassDescriptionDepthStencilResolve DepthStencilResolve
}

@internal class SubpassDependency {
Expand Down Expand Up @@ -319,6 +326,26 @@ sub SubpassDescription createSubpassDescriptionObjectFrom2(VkSubpassDescription2
PipelineBindPoint: subpassDescription2.pipelineBindPoint,
)

if subpassDescription2.pNext != null {
numPNext := numberOfPNext(subpassDescription2.pNext)
next := MutableVoidPtr(as!void*(subpassDescription2.pNext))
for j in (0 .. numPNext) {
sType := as!const VkStructureType*(next.Ptr)[0]
switch sType {
case VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE: {
ext := as!VkSubpassDescriptionDepthStencilResolve*(next.Ptr)[0]
internalSubpassDescription.DepthStencilResolve = new!SubpassDescriptionDepthStencilResolve(
DepthResolveMode: ext.depthResolveMode,
StencilResolveMode: ext.stencilResolveMode,
)
attachmentReference2 := ext.pDepthStencilResolveAttachment[0]
internalSubpassDescription.DepthStencilResolve.DepthStencilResolveAttachment =
createAttachmentReferenceObjectFrom2(attachmentReference2)
}
}
}
}

inputAttachments := subpassDescription2.pInputAttachments[0:subpassDescription2.inputAttachmentCount]
for j in (0 .. subpassDescription2.inputAttachmentCount) {
attachmentReference2 := inputAttachments[j]
Expand Down
25 changes: 25 additions & 0 deletions gapis/api/vulkan/api/vk12structs.api
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,28 @@ class VkRenderPassAttachmentBeginInfo {
u32 attachmentCount
const VkImageView* pAttachments
}

class VkPhysicalDeviceDepthStencilResolveProperties {
VkStructureType sType
void* pNext
VkResolveModeFlags supportedDepthResolveModes
VkResolveModeFlags supportedStencilResolveModes
VkBool32 independentResolveNone
VkBool32 independentResolve
}

@internal
class PhysicalDeviceDepthStencilResolveProperties {
VkResolveModeFlags SupportedDepthResolveModes
VkResolveModeFlags SupportedStencilResolveModes
VkBool32 IndependentResolveNone
VkBool32 IndependentResolve
}

class VkSubpassDescriptionDepthStencilResolve {
VkStructureType sType
const void* pNext
VkResolveModeFlagBits depthResolveMode
VkResolveModeFlagBits stencilResolveMode
const VkAttachmentReference2* pDepthStencilResolveAttachment
}
45 changes: 45 additions & 0 deletions gapis/api/vulkan/extensions/khr_depth_stencil_resolve.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (C) 2022 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Based off of the original vulkan.h header file which has the following
// license.

// Copyright (c) 2015 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and/or associated documentation files (the
// "Materials"), to deal in the Materials without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Materials, and to
// permit persons to whom the Materials are furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Materials.
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

///////////////
// Constants //
///////////////

@extension("VK_KHR_depth_stencil_resolve") define VK_KHR_DEPTH_STENCIL_RESOLVE_SPEC_VERSION 1
@extension("VK_KHR_depth_stencil_resolve") define VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME "VK_KHR_depth_stencil_resolve"

38 changes: 37 additions & 1 deletion gapis/api/vulkan/state_rebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2441,6 +2441,42 @@ func (sb *stateBuilder) createRenderPass2(rp RenderPassObjectʳ) {
subpassDescriptions := []VkSubpassDescription2{}
for _, k := range rp.SubpassDescriptions().Keys() {
sd := rp.SubpassDescriptions().Get(k)
sdPnext := NewVoidᶜᵖ(memory.Nullptr)

if !sd.DepthStencilResolve().IsNil() {
depthStencilResolve := sd.DepthStencilResolve().Get()
arPnext := NewVoidᶜᵖ(memory.Nullptr)
if !depthStencilResolve.DepthStencilResolveAttachment().StencilLayout().IsNil() {
slPnext := NewVoidᶜᵖ(memory.Nullptr)
arPnext = NewVoidᶜᵖ(sb.MustAllocReadData(
NewVkAttachmentReferenceStencilLayout(
VkStructureType_VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_STENCIL_LAYOUT,
NewVoidᵖ(slPnext),
depthStencilResolve.DepthStencilResolveAttachment().StencilLayout().StencilLayout(),
),
).Ptr())
}

dsrAttachmentRef := NewVkAttachmentReference2ᶜᵖ(sb.MustAllocReadData(
NewVkAttachmentReference2(
VkStructureType_VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2,
arPnext,
depthStencilResolve.DepthStencilResolveAttachment().Attachment(),
depthStencilResolve.DepthStencilResolveAttachment().Layout(),
depthStencilResolve.DepthStencilResolveAttachment().AspectMask(),
),
).Ptr())

sdPnext = NewVoidᶜᵖ(sb.MustAllocReadData(
NewVkSubpassDescriptionDepthStencilResolve(
VkStructureType_VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE,
NewVoidᶜᵖ(memory.Nullptr),
depthStencilResolve.DepthResolveMode(),
depthStencilResolve.StencilResolveMode(),
dsrAttachmentRef,
),
).Ptr())
}

depthStencil := NewVkAttachmentReference2ᶜᵖ(memory.Nullptr)
if !sd.DepthStencilAttachment().IsNil() {
Expand Down Expand Up @@ -2529,7 +2565,7 @@ func (sb *stateBuilder) createRenderPass2(rp RenderPassObjectʳ) {

subpassDescriptions = append(subpassDescriptions, NewVkSubpassDescription2(
VkStructureType_VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2,
NewVoidᶜᵖ(memory.Nullptr),
sdPnext,
sd.Flags(), // flags
sd.PipelineBindPoint(), // pipelineBindPoint
sd.ViewMask(), // viewMask
Expand Down
1 change: 1 addition & 0 deletions gapis/api/vulkan/vulkan.api
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ sub ref!ExtensionSet supportedDeviceExtensions() {
supported.ExtensionNames["VK_QCOM_render_pass_store_ops"] = true
supported.ExtensionNames["VK_EXT_load_store_op_none"] = true
supported.ExtensionNames["VK_KHR_imageless_framebuffer"] = true
supported.ExtensionNames["VK_KHR_depth_stencil_resolve"] = true
return supported
}

Expand Down