Skip to content
This repository was archived by the owner on Jul 19, 2018. It is now read-only.
Open
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
153 changes: 152 additions & 1 deletion scripts/mock_icd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
static void DestroyDispObjHandle(void* handle) {
delete reinterpret_cast<VK_LOADER_DATA*>(handle);
}

struct GENERIC_HEADER {
VkStructureType sType;
void *pNext;
};
'''

# Manual code at the top of the cpp source file
Expand Down Expand Up @@ -705,6 +710,55 @@
''',
'vkGetPhysicalDeviceFeatures2KHR': '''
GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
// Handle any extension properties queried down pNext chain
if (pFeatures->pNext) {
auto struct_header = reinterpret_cast<GENERIC_HEADER *>(pFeatures->pNext);
while (struct_header) {
switch (struct_header->sType) {
case VK_STRUCTURE_TYPE_DEVICE_GENERATED_COMMANDS_FEATURES_NVX: {
VkDeviceGeneratedCommandsFeaturesNVX *gc_feat = reinterpret_cast<VkDeviceGeneratedCommandsFeaturesNVX *>(struct_header);
gc_feat->computeBindingPointSupport = VK_TRUE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR: {
VkPhysicalDeviceVariablePointerFeaturesKHR *vp_feat = reinterpret_cast<VkPhysicalDeviceVariablePointerFeaturesKHR *>(struct_header);
vp_feat->variablePointersStorageBuffer = VK_TRUE;
vp_feat->variablePointers = VK_TRUE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX: {
VkPhysicalDeviceMultiviewFeaturesKHX *mv_feat = reinterpret_cast<VkPhysicalDeviceMultiviewFeaturesKHX *>(struct_header);
mv_feat->multiview = VK_TRUE;
mv_feat->multiviewGeometryShader = VK_TRUE;
mv_feat->multiviewTessellationShader = VK_TRUE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR: {
VkPhysicalDevice16BitStorageFeaturesKHR *sbs_feat = reinterpret_cast<VkPhysicalDevice16BitStorageFeaturesKHR *>(struct_header);
sbs_feat->storageBuffer16BitAccess = VK_TRUE;
sbs_feat->uniformAndStorageBuffer16BitAccess = VK_TRUE;
sbs_feat->storagePushConstant16 = VK_TRUE;
sbs_feat->storageInputOutput16 = VK_TRUE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES_KHR: {
VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR *syc_feat = reinterpret_cast<VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR *>(struct_header);
syc_feat->samplerYcbcrConversion = VK_TRUE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT: {
VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *boa_feat = reinterpret_cast<VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT *>(struct_header);
boa_feat->advancedBlendCoherentOperations = VK_TRUE;
break;
}
default:
assert(0);
// Unknown extension feature request needs to be added to mock_icd
break;
}
struct_header = reinterpret_cast<GENERIC_HEADER *>(struct_header->pNext);
}
}
''',
'vkGetPhysicalDeviceFormatProperties': '''
if (VK_FORMAT_UNDEFINED == format) {
Expand Down Expand Up @@ -746,6 +800,101 @@
''',
'vkGetPhysicalDeviceProperties2KHR': '''
GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
// Handle any extension properties queried down pNext chain
if (pProperties->pNext) {
auto struct_header = reinterpret_cast<GENERIC_HEADER *>(pProperties->pNext);
while (struct_header) {
switch (struct_header->sType) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR: {
VkPhysicalDeviceIDPropertiesKHR *id_prop = reinterpret_cast<VkPhysicalDeviceIDPropertiesKHR *>(struct_header);
// This is a dummy ID intended to represent "ICDGOOG" for mock ICD
uint8_t icd_id[] = {1, 0xc, 0xd, 6, 0, 0, 6};
std::copy(icd_id, icd_id + 7, id_prop->deviceUUID);
std::copy(icd_id, icd_id + 7, id_prop->driverUUID);
id_prop->deviceLUID[0] = 0;
id_prop->deviceNodeMask = 1;
id_prop->deviceLUIDValid = VK_FALSE; // This causes the above 2 values to be ignored
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
VkPhysicalDevicePushDescriptorPropertiesKHR *pd_prop = reinterpret_cast<VkPhysicalDevicePushDescriptorPropertiesKHR *>(struct_header);
pd_prop->maxPushDescriptors = 32;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX: {
VkPhysicalDeviceMultiviewPropertiesKHX *mv_prop = reinterpret_cast<VkPhysicalDeviceMultiviewPropertiesKHX *>(struct_header);
mv_prop->maxMultiviewViewCount = 6;
mv_prop->maxMultiviewInstanceIndex = 0x7FFFFFF;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT: {
VkPhysicalDeviceDiscardRectanglePropertiesEXT *rect_prop = reinterpret_cast<VkPhysicalDeviceDiscardRectanglePropertiesEXT *>(struct_header);
rect_prop->maxDiscardRectangles = 4;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT: {
VkPhysicalDeviceSampleLocationsPropertiesEXT *dsl_prop = reinterpret_cast<VkPhysicalDeviceSampleLocationsPropertiesEXT *>(struct_header);
dsl_prop->sampleLocationSampleCounts = VK_SAMPLE_COUNT_4_BIT;
dsl_prop->maxSampleLocationGridSize.width = 1;
dsl_prop->maxSampleLocationGridSize.height = 1;
dsl_prop->sampleLocationCoordinateRange[0] = 0.0;
dsl_prop->sampleLocationCoordinateRange[1] = 0.9375;
dsl_prop->sampleLocationSubPixelBits = 4;
dsl_prop->variableSampleLocations = VK_FALSE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT: {
VkPhysicalDeviceExternalMemoryHostPropertiesEXT *mh_prop = reinterpret_cast<VkPhysicalDeviceExternalMemoryHostPropertiesEXT *>(struct_header);
mh_prop->minImportedHostPointerAlignment = 65536;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_ATTRIBUTES_PROPERTIES_NVX: {
VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX *mpva_prop = reinterpret_cast<VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX *>(struct_header);
mpva_prop->perViewPositionAllComponents = VK_TRUE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR: {
VkPhysicalDevicePointClippingPropertiesKHR *pc_prop = reinterpret_cast<VkPhysicalDevicePointClippingPropertiesKHR *>(struct_header);
pc_prop->pointClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT: {
VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT *boa_prop = reinterpret_cast<VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT *>(struct_header);
boa_prop->advancedBlendMaxColorAttachments = 1;
boa_prop->advancedBlendIndependentBlend = VK_FALSE;
boa_prop->advancedBlendNonPremultipliedSrcColor = VK_FALSE;
boa_prop->advancedBlendNonPremultipliedDstColor = VK_FALSE;
boa_prop->advancedBlendCorrelatedOverlap = VK_FALSE;
boa_prop->advancedBlendAllOperations = VK_FALSE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT: {
VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT *sfm_prop = reinterpret_cast<VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT *>(struct_header);
sfm_prop->filterMinmaxSingleComponentFormats = VK_TRUE;
sfm_prop->filterMinmaxImageComponentMapping = VK_TRUE;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT: {
VkPhysicalDeviceConservativeRasterizationPropertiesEXT *cr_prop = reinterpret_cast<VkPhysicalDeviceConservativeRasterizationPropertiesEXT *>(struct_header);
cr_prop->primitiveOverestimationSize = 0.0;
cr_prop->maxExtraPrimitiveOverestimationSize = 0.0;
cr_prop->extraPrimitiveOverestimationSizeGranularity = 0.0;
cr_prop->primitiveUnderestimation = VK_FALSE;
cr_prop->conservativePointAndLineRasterization = VK_FALSE;
cr_prop->degenerateTrianglesRasterized = VK_FALSE;
cr_prop->degenerateLinesRasterized = VK_FALSE;
cr_prop->fullyCoveredFragmentShaderInputVariable = VK_FALSE;
cr_prop->conservativeRasterizationPostDepthCoverage = VK_FALSE;
break;
}
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VkPhysicalDeviceIDPropertiesKHR is missing from the list but not on the "naughty" list below.

assert(0);
// Unknown extension property request needs to be added to mock_icd
break;
}
struct_header = reinterpret_cast<GENERIC_HEADER *>(struct_header->pNext);
}
}
''',
'vkGetBufferMemoryRequirements': '''
// TODO: Just hard-coding reqs for now
Expand Down Expand Up @@ -967,6 +1116,8 @@ def beginFile(self, genOpts):
write('#include "mock_icd.h"', file=self.outFile)
write('#include <stdlib.h>', file=self.outFile)
write('#include <vector>', file=self.outFile)
write('#include <cassert>', file=self.outFile)
write('#include <algorithm>', file=self.outFile)

write('namespace vkmock {', file=self.outFile)
if self.header:
Expand All @@ -976,7 +1127,7 @@ def beginFile(self, genOpts):
device_exts = []
instance_exts = []
# Ignore extensions that ICDs should not implement or are not safe to report
ignore_exts = ['VK_EXT_validation_cache', 'VK_KHR_push_descriptor']
ignore_exts = ['VK_EXT_validation_cache']
for ext in self.registry.tree.findall("extensions/extension"):
if ext.attrib['supported'] != 'disabled': # Only include enabled extensions
if (ext.attrib['name'] in ignore_exts):
Expand Down