Skip to content

Commit

Permalink
Implement VK_EXT_index_type_uint8 (#958)
Browse files Browse the repository at this point in the history
Implement VK_EXT_index_type_uint8
  • Loading branch information
yalcinmelihyasin committed Oct 21, 2021
1 parent 7fe113f commit dc9b46f
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 1 deletion.
9 changes: 9 additions & 0 deletions gapis/api/vulkan/api/device.api
Expand Up @@ -87,6 +87,9 @@

// @extension("VK_EXT_blend_operation_advanced")
@unused ref!PhysicalDeviceBlendOperationAdvancedFeaturesEXT PhysicalDeviceBlendOperationAdvancedFeaturesEXT

// @extension("VK_ext_index_type_uint8")
@unused ref!PhysicalDeviceIndexTypeUint8FeaturesEXT PhysicalDeviceIndexTypeUint8FeaturesEXT
}

@indirect("VkDevice")
Expand Down Expand Up @@ -313,6 +316,12 @@ sub ref!DeviceObject createDeviceObject(const VkDeviceCreateInfo* data) {
AdvancedBlendCoherentOperations: ext.advancedBlendCoherentOperations,
)
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT: {
ext := as!VkPhysicalDeviceIndexTypeUint8FeaturesEXT*(next.Ptr)[0]
object.PhysicalDeviceIndexTypeUint8FeaturesEXT = new!PhysicalDeviceIndexTypeUint8FeaturesEXT(
IndexTypeUint8: ext.indexTypeUint8,
)
}
}

next.Ptr = as!VulkanStructHeader*(next.Ptr)[0].PNext
Expand Down
2 changes: 2 additions & 0 deletions gapis/api/vulkan/api/draw_commands.api
Expand Up @@ -210,6 +210,8 @@ sub void readBoundIndexBuffer(u32 indexCount, u32 firstIndex) {
lastDraw := lastDrawInfo()
indexBuffer := lastDraw.BoundIndexBuffer.BoundBuffer.Buffer
indexSize := switch (lastDraw.BoundIndexBuffer.Type) {
case VK_INDEX_TYPE_UINT8_EXT:
as!VkDeviceSize(1)
case VK_INDEX_TYPE_UINT16:
as!VkDeviceSize(2)
case VK_INDEX_TYPE_UINT32:
Expand Down
6 changes: 6 additions & 0 deletions gapis/api/vulkan/api/enums.api
Expand Up @@ -418,6 +418,9 @@ enum VkStructureType: u32 {
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT = 1000259002,
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT = 1000259001,

// @extension("VK_EXT_index_type_uint8")
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT = 1000265000

// @extension("VK_EXT_vertex_attribute_divisor")
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT = 1000190000,
VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT = 1000190001,
Expand Down Expand Up @@ -1072,6 +1075,9 @@ enum VkCommandBufferLevel: u32 {
enum VkIndexType: u32 {
VK_INDEX_TYPE_UINT16 = 0x00000000,
VK_INDEX_TYPE_UINT32 = 0x00000001,

// @extension("VK_EXT_index_type_uint8")
VK_INDEX_TYPE_UINT8_EXT = 1000265000,
}

enum VkSubpassContents: u32 {
Expand Down
6 changes: 6 additions & 0 deletions gapis/api/vulkan/api/properties_features_requirements.api
Expand Up @@ -407,6 +407,9 @@ sub void GetPhysicalDeviceFeatures2(
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT: {
_ = as!VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT*(next.Ptr)[0]
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT: {
_ = as!VkPhysicalDeviceIndexTypeUint8FeaturesEXT*(next.Ptr)[0]
}
}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0].PNext
}
Expand Down Expand Up @@ -483,6 +486,9 @@ sub void GetPhysicalDeviceFeatures2(
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT: {
write(as!VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT*(next.Ptr)[0:1])
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT: {
write(as!VkPhysicalDeviceIndexTypeUint8FeaturesEXT*(next.Ptr)[0:1])
}
}
next.Ptr = as!VulkanStructHeader*(next.Ptr)[0].PNext
}
Expand Down
5 changes: 4 additions & 1 deletion gapis/api/vulkan/draw_call_mesh.go
Expand Up @@ -246,12 +246,15 @@ func getIndicesData(ctx context.Context, s *api.GlobalState, thread uint64, boun
}

switch boundIndexBuffer.Type() {
case VkIndexType_VK_INDEX_TYPE_UINT8_EXT:
return extractIndices(1)
case VkIndexType_VK_INDEX_TYPE_UINT16:
return extractIndices(2)
case VkIndexType_VK_INDEX_TYPE_UINT32:
return extractIndices(4)
default:
return []uint32{}, fmt.Errorf("Missing index buffer type %v", boundIndexBuffer.Type())
}
return []uint32{}, nil
}

func findBinding(lastDrawInfo DrawInfoʳ, attribute VkVertexInputAttributeDescription) (VkVertexInputBindingDescription, bool) {
Expand Down
60 changes: 60 additions & 0 deletions gapis/api/vulkan/extensions/ext_index_type_uint8.api
@@ -0,0 +1,60 @@
// Copyright (C) 2021 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_EXT_index_type_uint8") define VK_EXT_INDEX_TYPE_UINT8_SPEC_VERSION 1
@extension("VK_EXT_index_type_uint8") define VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME "VK_EXT_index_type_uint8"

///////////////
// Structs //
///////////////

@extension("VK_EXT_image_robustness")
class VkPhysicalDeviceIndexTypeUint8FeaturesEXT {
VkStructureType sType
void* pNext
VkBool32 indexTypeUint8
}

@internal
class PhysicalDeviceIndexTypeUint8FeaturesEXT {
VkBool32 IndexTypeUint8
}
9 changes: 9 additions & 0 deletions gapis/api/vulkan/state_rebuilder.go
Expand Up @@ -935,6 +935,15 @@ func (sb *stateBuilder) createDevice(d DeviceObjectʳ) {
),
).Ptr())
}
if !d.PhysicalDeviceIndexTypeUint8FeaturesEXT().IsNil() {
pNext = NewVoidᵖ(sb.MustAllocReadData(
NewVkPhysicalDeviceIndexTypeUint8FeaturesEXT(
VkStructureType_VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT,
pNext,
d.PhysicalDeviceIndexTypeUint8FeaturesEXT().IndexTypeUint8(),
),
).Ptr())
}

sb.write(sb.cb.VkCreateDevice(
d.PhysicalDevice(),
Expand Down
2 changes: 2 additions & 0 deletions gapis/api/vulkan/vulkan.api
Expand Up @@ -123,6 +123,7 @@ import "extensions/ext_image_robustness.api"
import "extensions/ext_provoking_vertex.api"
import "extensions/ext_transform_feedback.api"
import "extensions/ext_blend_operation_advanced.api"
import "extensions/ext_index_type_uint8.api"

import "android/vulkan_android.api"
import "linux/vulkan_linux.api"
Expand Down Expand Up @@ -300,6 +301,7 @@ sub ref!ExtensionSet supportedDeviceExtensions() {
supported.ExtensionNames["VK_EXT_transform_feedback"] = true
supported.ExtensionNames["VK_KHR_shader_terminate_invocation"] = true
supported.ExtensionNames["VK_EXT_blend_operation_advanced"] = true
supported.ExtensionNames["VK_EXT_index_type_uint8"] = true
return supported
}

Expand Down

0 comments on commit dc9b46f

Please sign in to comment.