* 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 SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
*/
#include "tu_private.h"
-#include "util/debug.h"
-#include "util/disk_cache.h"
-#include "util/strtod.h"
-#include "vk_format.h"
-#include "vk_util.h"
+
#include <fcntl.h>
+#include <libsync.h>
#include <stdbool.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/sysinfo.h>
#include <unistd.h>
#include <xf86drm.h>
-#include <msm_drm.h>
+
+#include "util/debug.h"
+#include "util/disk_cache.h"
+#include "util/strtod.h"
+#include "vk_format.h"
+#include "vk_util.h"
+
+#include "drm/msm_drm.h"
static int
tu_device_get_cache_uuid(uint16_t family, void *uuid)
return -1;
memcpy(uuid, &mesa_timestamp, 4);
- memcpy((char *)uuid + 4, &f, 2);
- snprintf((char *)uuid + 6, VK_UUID_SIZE - 10, "tu");
+ memcpy((char *) uuid + 4, &f, 2);
+ snprintf((char *) uuid + 6, VK_UUID_SIZE - 10, "tu");
return 0;
}
tu_get_driver_uuid(void *uuid)
{
memset(uuid, 0, VK_UUID_SIZE);
+ snprintf(uuid, VK_UUID_SIZE, "freedreno");
}
static void
tu_get_device_uuid(void *uuid)
{
- tu_use_args(uuid);
- tu_stub();
+ memset(uuid, 0, VK_UUID_SIZE);
}
VkResult
if (!gem_handle)
goto fail_new;
- /* Calling DRM_MSM_GEM_INFO forces the kernel to allocate backing pages. We
- * want immediate backing pages because vkAllocateMemory and friends must
- * not lazily fail.
- *
- * TODO(chadv): Must we really call DRM_MSM_GEM_INFO to acquire backing
- * pages? I infer so from reading comments in msm_bo.c:bo_allocate(), but
- * maybe I misunderstand.
- */
-
- /* TODO: Do we need 'offset' if we have 'iova'? */
- uint64_t offset = tu_gem_info_offset(dev, gem_handle);
- if (!offset)
- goto fail_info;
-
uint64_t iova = tu_gem_info_iova(dev, gem_handle);
if (!iova)
goto fail_info;
*bo = (struct tu_bo) {
.gem_handle = gem_handle,
.size = size,
- .offset = offset,
.iova = iova,
};
return VK_SUCCESS;
fail_info:
- tu_gem_close(dev, bo->gem_handle);
+ tu_gem_close(dev, bo->gem_handle);
fail_new:
- return vk_error(dev->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+ return vk_error(dev->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
}
VkResult
if (bo->map)
return VK_SUCCESS;
+ uint64_t offset = tu_gem_info_offset(dev, bo->gem_handle);
+ if (!offset)
+ return vk_error(dev->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+
/* TODO: Should we use the wrapper os_mmap() like Freedreno does? */
void *map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
- dev->physical_device->local_fd, bo->offset);
+ dev->physical_device->local_fd, offset);
if (map == MAP_FAILED)
return vk_error(dev->instance, VK_ERROR_MEMORY_MAP_FAILED);
drmVersionPtr version;
int fd;
int master_fd = -1;
- uint64_t val;
fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) {
result = vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER,
"kernel driver for device %s has version %d.%d, "
"but Vulkan requires version >= %d.%d",
- path,
- version->version_major, version->version_minor,
+ path, version->version_major, version->version_minor,
min_version_major, min_version_minor);
drmFreeVersion(version);
close(fd);
strncpy(device->path, path, ARRAY_SIZE(device->path));
if (instance->enabled_extensions.KHR_display) {
- master_fd = open(drm_device->nodes[DRM_NODE_PRIMARY], O_RDWR | O_CLOEXEC);
+ master_fd =
+ open(drm_device->nodes[DRM_NODE_PRIMARY], O_RDWR | O_CLOEXEC);
if (master_fd >= 0) {
/* TODO: free master_fd is accel is not working? */
}
device->master_fd = master_fd;
device->local_fd = fd;
- device->drm_device = fd_device_new_dup(fd);
- if (!device->drm_device) {
- if (instance->debug_flags & TU_DEBUG_STARTUP)
- tu_logi("Could not create the libdrm device");
- result = vk_errorf(
- instance, VK_ERROR_INITIALIZATION_FAILED, "could not create the libdrm device");
- goto fail;
- }
-
- if (tu_drm_query_param(device, MSM_PARAM_GPU_ID, &val)) {
+ if (tu_drm_get_gpu_id(device, &device->gpu_id)) {
if (instance->debug_flags & TU_DEBUG_STARTUP)
tu_logi("Could not query the GPU ID");
- result = vk_errorf(
- instance, VK_ERROR_INITIALIZATION_FAILED, "could not get GPU ID");
+ result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
+ "could not get GPU ID");
goto fail;
}
- device->gpu_id = val;
- if (tu_drm_query_param(device, MSM_PARAM_GMEM_SIZE, &val)) {
+ if (tu_drm_get_gmem_size(device, &device->gmem_size)) {
if (instance->debug_flags & TU_DEBUG_STARTUP)
tu_logi("Could not query the GMEM size");
- result = vk_errorf(
- instance, VK_ERROR_INITIALIZATION_FAILED, "could not get GMEM size");
+ result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
+ "could not get GMEM size");
goto fail;
}
- device->gmem_size = val;
memset(device->name, 0, sizeof(device->name));
sprintf(device->name, "FD%d", device->gpu_id);
- switch(device->gpu_id) {
+ switch (device->gpu_id) {
case 530:
case 630:
break;
goto fail;
}
if (tu_device_get_cache_uuid(device->gpu_id, device->cache_uuid)) {
- result = vk_errorf(
- instance, VK_ERROR_INITIALIZATION_FAILED, "cannot generate UUID");
+ result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
+ "cannot generate UUID");
goto fail;
}
disk_cache_format_hex_id(buf, device->cache_uuid, VK_UUID_SIZE * 2);
device->disk_cache = disk_cache_create(device->name, buf, 0);
- fprintf(stderr,
- "WARNING: tu is not a conformant vulkan implementation, "
- "testing use only.\n");
+ fprintf(stderr, "WARNING: tu is not a conformant vulkan implementation, "
+ "testing use only.\n");
tu_get_driver_uuid(&device->device_uuid);
tu_get_device_uuid(&device->device_uuid);
return VK_SUCCESS;
fail:
- if (device->drm_device)
- fd_device_del(device->drm_device);
close(fd);
if (master_fd != -1)
close(master_fd);
.pfnFree = default_free_func,
};
-static const struct debug_control tu_debug_options[] = { { "startup",
- TU_DEBUG_STARTUP },
- { NULL, 0 } };
+static const struct debug_control tu_debug_options[] = {
+ { "startup", TU_DEBUG_STARTUP }, { NULL, 0 }
+};
const char *
tu_get_debug_option_name(int id)
tu_EnumerateInstanceVersion(&client_version);
}
- instance = vk_zalloc2(&default_alloc,
- pAllocator,
- sizeof(*instance),
- 8,
+ instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!instance)
return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
instance->physical_device_count = -1;
instance->debug_flags =
- parse_debug_string(getenv("TU_DEBUG"), tu_debug_options);
+ parse_debug_string(getenv("TU_DEBUG"), tu_debug_options);
if (instance->debug_flags & TU_DEBUG_STARTUP)
tu_logi("Created an instance");
if (max_devices < 1)
return vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
- for (unsigned i = 0; i < (unsigned)max_devices; i++) {
+ for (unsigned i = 0; i < (unsigned) max_devices; i++) {
if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
devices[i]->bustype == DRM_BUS_PLATFORM) {
- result = tu_physical_device_init(instance->physical_devices +
- instance->physical_device_count,
- instance,
- devices[i]);
+ result = tu_physical_device_init(
+ instance->physical_devices + instance->physical_device_count,
+ instance, devices[i]);
if (result == VK_SUCCESS)
++instance->physical_device_count;
else if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
}
for (uint32_t i = 0; i < instance->physical_device_count; ++i) {
- vk_outarray_append(&out, p) {
+ vk_outarray_append(&out, p)
+ {
*p = tu_physical_device_to_handle(instance->physical_devices + i);
}
-
}
return vk_outarray_status(&out);
VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties)
{
TU_FROM_HANDLE(tu_instance, instance, _instance);
- VK_OUTARRAY_MAKE(out, pPhysicalDeviceGroupProperties, pPhysicalDeviceGroupCount);
+ VK_OUTARRAY_MAKE(out, pPhysicalDeviceGroupProperties,
+ pPhysicalDeviceGroupCount);
VkResult result;
if (instance->physical_device_count < 0) {
}
for (uint32_t i = 0; i < instance->physical_device_count; ++i) {
- vk_outarray_append(&out, p) {
+ vk_outarray_append(&out, p)
+ {
p->physicalDeviceCount = 1;
p->physicalDevices[0] =
- tu_physical_device_to_handle(instance->physical_devices + i);
+ tu_physical_device_to_handle(instance->physical_devices + i);
p->subsetAllocation = false;
}
}
{
memset(pFeatures, 0, sizeof(*pFeatures));
- *pFeatures = (VkPhysicalDeviceFeatures){
+ *pFeatures = (VkPhysicalDeviceFeatures) {
.robustBufferAccess = false,
.fullDrawIndexUint32 = false,
.imageCubeArray = false,
vk_foreach_struct(ext, pFeatures->pNext)
{
switch (ext->sType) {
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR: {
- VkPhysicalDeviceVariablePointerFeaturesKHR *features = (void *)ext;
- features->variablePointersStorageBuffer = false;
- features->variablePointers = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR: {
- VkPhysicalDeviceMultiviewFeaturesKHR *features =
- (VkPhysicalDeviceMultiviewFeaturesKHR *)ext;
- features->multiview = false;
- features->multiviewGeometryShader = false;
- features->multiviewTessellationShader = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES: {
- VkPhysicalDeviceShaderDrawParameterFeatures *features =
- (VkPhysicalDeviceShaderDrawParameterFeatures *)ext;
- features->shaderDrawParameters = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: {
- VkPhysicalDeviceProtectedMemoryFeatures *features =
- (VkPhysicalDeviceProtectedMemoryFeatures *)ext;
- features->protectedMemory = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
- VkPhysicalDevice16BitStorageFeatures *features =
- (VkPhysicalDevice16BitStorageFeatures *)ext;
- features->storageBuffer16BitAccess = false;
- features->uniformAndStorageBuffer16BitAccess = false;
- features->storagePushConstant16 = false;
- features->storageInputOutput16 = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
- VkPhysicalDeviceSamplerYcbcrConversionFeatures *features =
- (VkPhysicalDeviceSamplerYcbcrConversionFeatures *)ext;
- features->samplerYcbcrConversion = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT: {
- VkPhysicalDeviceDescriptorIndexingFeaturesEXT *features =
- (VkPhysicalDeviceDescriptorIndexingFeaturesEXT *)ext;
- features->shaderInputAttachmentArrayDynamicIndexing = false;
- features->shaderUniformTexelBufferArrayDynamicIndexing = false;
- features->shaderStorageTexelBufferArrayDynamicIndexing = false;
- features->shaderUniformBufferArrayNonUniformIndexing = false;
- features->shaderSampledImageArrayNonUniformIndexing = false;
- features->shaderStorageBufferArrayNonUniformIndexing = false;
- features->shaderStorageImageArrayNonUniformIndexing = false;
- features->shaderInputAttachmentArrayNonUniformIndexing = false;
- features->shaderUniformTexelBufferArrayNonUniformIndexing = false;
- features->shaderStorageTexelBufferArrayNonUniformIndexing = false;
- features->descriptorBindingUniformBufferUpdateAfterBind = false;
- features->descriptorBindingSampledImageUpdateAfterBind = false;
- features->descriptorBindingStorageImageUpdateAfterBind = false;
- features->descriptorBindingStorageBufferUpdateAfterBind = false;
- features->descriptorBindingUniformTexelBufferUpdateAfterBind = false;
- features->descriptorBindingStorageTexelBufferUpdateAfterBind = false;
- features->descriptorBindingUpdateUnusedWhilePending = false;
- features->descriptorBindingPartiallyBound = false;
- features->descriptorBindingVariableDescriptorCount = false;
- features->runtimeDescriptorArray = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT: {
- VkPhysicalDeviceConditionalRenderingFeaturesEXT *features =
- (VkPhysicalDeviceConditionalRenderingFeaturesEXT *)ext;
- features->conditionalRendering = false;
- features->inheritedConditionalRendering = false;
- break;
- }
- default:
- break;
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR: {
+ VkPhysicalDeviceVariablePointerFeaturesKHR *features = (void *) ext;
+ features->variablePointersStorageBuffer = false;
+ features->variablePointers = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR: {
+ VkPhysicalDeviceMultiviewFeaturesKHR *features =
+ (VkPhysicalDeviceMultiviewFeaturesKHR *) ext;
+ features->multiview = false;
+ features->multiviewGeometryShader = false;
+ features->multiviewTessellationShader = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES: {
+ VkPhysicalDeviceShaderDrawParameterFeatures *features =
+ (VkPhysicalDeviceShaderDrawParameterFeatures *) ext;
+ features->shaderDrawParameters = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: {
+ VkPhysicalDeviceProtectedMemoryFeatures *features =
+ (VkPhysicalDeviceProtectedMemoryFeatures *) ext;
+ features->protectedMemory = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
+ VkPhysicalDevice16BitStorageFeatures *features =
+ (VkPhysicalDevice16BitStorageFeatures *) ext;
+ features->storageBuffer16BitAccess = false;
+ features->uniformAndStorageBuffer16BitAccess = false;
+ features->storagePushConstant16 = false;
+ features->storageInputOutput16 = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
+ VkPhysicalDeviceSamplerYcbcrConversionFeatures *features =
+ (VkPhysicalDeviceSamplerYcbcrConversionFeatures *) ext;
+ features->samplerYcbcrConversion = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT: {
+ VkPhysicalDeviceDescriptorIndexingFeaturesEXT *features =
+ (VkPhysicalDeviceDescriptorIndexingFeaturesEXT *) ext;
+ features->shaderInputAttachmentArrayDynamicIndexing = false;
+ features->shaderUniformTexelBufferArrayDynamicIndexing = false;
+ features->shaderStorageTexelBufferArrayDynamicIndexing = false;
+ features->shaderUniformBufferArrayNonUniformIndexing = false;
+ features->shaderSampledImageArrayNonUniformIndexing = false;
+ features->shaderStorageBufferArrayNonUniformIndexing = false;
+ features->shaderStorageImageArrayNonUniformIndexing = false;
+ features->shaderInputAttachmentArrayNonUniformIndexing = false;
+ features->shaderUniformTexelBufferArrayNonUniformIndexing = false;
+ features->shaderStorageTexelBufferArrayNonUniformIndexing = false;
+ features->descriptorBindingUniformBufferUpdateAfterBind = false;
+ features->descriptorBindingSampledImageUpdateAfterBind = false;
+ features->descriptorBindingStorageImageUpdateAfterBind = false;
+ features->descriptorBindingStorageBufferUpdateAfterBind = false;
+ features->descriptorBindingUniformTexelBufferUpdateAfterBind = false;
+ features->descriptorBindingStorageTexelBufferUpdateAfterBind = false;
+ features->descriptorBindingUpdateUnusedWhilePending = false;
+ features->descriptorBindingPartiallyBound = false;
+ features->descriptorBindingVariableDescriptorCount = false;
+ features->runtimeDescriptorArray = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT: {
+ VkPhysicalDeviceConditionalRenderingFeaturesEXT *features =
+ (VkPhysicalDeviceConditionalRenderingFeaturesEXT *) ext;
+ features->conditionalRendering = false;
+ features->inheritedConditionalRendering = false;
+ break;
+ }
+ default:
+ break;
}
}
return tu_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
* there is no set limit, so we just set a pipeline limit. I don't think
* any app is going to hit this soon. */
size_t max_descriptor_set_size =
- ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS) /
- (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
- 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
- 32 /* sampler, largest when combined with image */ +
- 64 /* sampled image */ + 64 /* storage image */);
+ ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS) /
+ (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
+ 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
+ 32 /* sampler, largest when combined with image */ +
+ 64 /* sampled image */ + 64 /* storage image */);
VkPhysicalDeviceLimits limits = {
.maxImageDimension1D = (1 << 14),
.nonCoherentAtomSize = 64,
};
- *pProperties = (VkPhysicalDeviceProperties){
+ *pProperties = (VkPhysicalDeviceProperties) {
.apiVersion = tu_physical_device_api_version(pdevice),
.driverVersion = vk_get_driver_version(),
.vendorID = 0, /* TODO */
vk_foreach_struct(ext, pProperties->pNext)
{
switch (ext->sType) {
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
- VkPhysicalDevicePushDescriptorPropertiesKHR *properties =
- (VkPhysicalDevicePushDescriptorPropertiesKHR *)ext;
- properties->maxPushDescriptors = MAX_PUSH_DESCRIPTORS;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR: {
- VkPhysicalDeviceIDPropertiesKHR *properties =
- (VkPhysicalDeviceIDPropertiesKHR *)ext;
- memcpy(properties->driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
- memcpy(properties->deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
- properties->deviceLUIDValid = false;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR: {
- VkPhysicalDeviceMultiviewPropertiesKHR *properties =
- (VkPhysicalDeviceMultiviewPropertiesKHR *)ext;
- properties->maxMultiviewViewCount = MAX_VIEWS;
- properties->maxMultiviewInstanceIndex = INT_MAX;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR: {
- VkPhysicalDevicePointClippingPropertiesKHR *properties =
- (VkPhysicalDevicePointClippingPropertiesKHR *)ext;
- properties->pointClippingBehavior =
- VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR;
- break;
- }
- case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
- VkPhysicalDeviceMaintenance3Properties *properties =
- (VkPhysicalDeviceMaintenance3Properties *)ext;
- /* Make sure everything is addressable by a signed 32-bit int, and
- * our largest descriptors are 96 bytes. */
- properties->maxPerSetDescriptors = (1ull << 31) / 96;
- /* Our buffer size fields allow only this much */
- properties->maxMemoryAllocationSize = 0xFFFFFFFFull;
- break;
- }
- default:
- break;
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR: {
+ VkPhysicalDevicePushDescriptorPropertiesKHR *properties =
+ (VkPhysicalDevicePushDescriptorPropertiesKHR *) ext;
+ properties->maxPushDescriptors = MAX_PUSH_DESCRIPTORS;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR: {
+ VkPhysicalDeviceIDPropertiesKHR *properties =
+ (VkPhysicalDeviceIDPropertiesKHR *) ext;
+ memcpy(properties->driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
+ memcpy(properties->deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
+ properties->deviceLUIDValid = false;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR: {
+ VkPhysicalDeviceMultiviewPropertiesKHR *properties =
+ (VkPhysicalDeviceMultiviewPropertiesKHR *) ext;
+ properties->maxMultiviewViewCount = MAX_VIEWS;
+ properties->maxMultiviewInstanceIndex = INT_MAX;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR: {
+ VkPhysicalDevicePointClippingPropertiesKHR *properties =
+ (VkPhysicalDevicePointClippingPropertiesKHR *) ext;
+ properties->pointClippingBehavior =
+ VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR;
+ break;
+ }
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
+ VkPhysicalDeviceMaintenance3Properties *properties =
+ (VkPhysicalDeviceMaintenance3Properties *) ext;
+ /* Make sure everything is addressable by a signed 32-bit int, and
+ * our largest descriptors are 96 bytes. */
+ properties->maxPerSetDescriptors = (1ull << 31) / 96;
+ /* Our buffer size fields allow only this much */
+ properties->maxMemoryAllocationSize = 0xFFFFFFFFull;
+ break;
+ }
+ default:
+ break;
}
}
}
-static const VkQueueFamilyProperties
-tu_queue_family_properties = {
- .queueFlags = VK_QUEUE_GRAPHICS_BIT |
- VK_QUEUE_COMPUTE_BIT |
- VK_QUEUE_TRANSFER_BIT,
+static const VkQueueFamilyProperties tu_queue_family_properties = {
+ .queueFlags =
+ VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT,
.queueCount = 1,
.timestampValidBits = 64,
.minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 },
{
VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pQueueFamilyPropertyCount);
- vk_outarray_append(&out, p) {
- *p = tu_queue_family_properties;
- }
+ vk_outarray_append(&out, p) { *p = tu_queue_family_properties; }
}
void
{
VK_OUTARRAY_MAKE(out, pQueueFamilyProperties, pQueueFamilyPropertyCount);
- vk_outarray_append(&out, p) {
+ vk_outarray_append(&out, p)
+ {
p->queueFamilyProperties = tu_queue_family_properties;
}
}
struct sysinfo info;
sysinfo(&info);
- uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;
+ uint64_t total_ram = (uint64_t) info.totalram * (uint64_t) info.mem_unit;
/* We don't want to burn too much ram with the GPU. If the user has 4GiB
* or less, we use at most half. If they have more than 4GiB, we use 3/4.
pMemoryProperties->memoryHeaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
pMemoryProperties->memoryTypeCount = 1;
- pMemoryProperties->memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
- VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
- VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
+ pMemoryProperties->memoryTypes[0].propertyFlags =
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
+ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
pMemoryProperties->memoryTypes[0].heapIndex = 0;
}
VkPhysicalDeviceMemoryProperties2KHR *pMemoryProperties)
{
return tu_GetPhysicalDeviceMemoryProperties(
- physicalDevice, &pMemoryProperties->memoryProperties);
+ physicalDevice, &pMemoryProperties->memoryProperties);
}
-static int
+static VkResult
tu_queue_init(struct tu_device *device,
struct tu_queue *queue,
uint32_t queue_family_index,
queue->queue_idx = idx;
queue->flags = flags;
+ int ret = tu_drm_submitqueue_new(device, 0, &queue->msm_queue_id);
+ if (ret)
+ return VK_ERROR_INITIALIZATION_FAILED;
+
+ queue->submit_fence_fd = -1;
+
return VK_SUCCESS;
}
static void
tu_queue_finish(struct tu_queue *queue)
{
+ if (queue->submit_fence_fd >= 0) {
+ close(queue->submit_fence_fd);
+ }
+ tu_drm_submitqueue_close(queue->device, queue->msm_queue_id);
}
static int
if (pCreateInfo->pEnabledFeatures) {
VkPhysicalDeviceFeatures supported_features;
tu_GetPhysicalDeviceFeatures(physicalDevice, &supported_features);
- VkBool32 *supported_feature = (VkBool32 *)&supported_features;
- VkBool32 *enabled_feature = (VkBool32 *)pCreateInfo->pEnabledFeatures;
+ VkBool32 *supported_feature = (VkBool32 *) &supported_features;
+ VkBool32 *enabled_feature = (VkBool32 *) pCreateInfo->pEnabledFeatures;
unsigned num_features =
- sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
+ sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
for (uint32_t i = 0; i < num_features; i++) {
if (enabled_feature[i] && !supported_feature[i])
return vk_error(physical_device->instance,
}
}
- device = vk_zalloc2(&physical_device->instance->alloc,
- pAllocator,
- sizeof(*device),
- 8,
- VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+ device = vk_zalloc2(&physical_device->instance->alloc, pAllocator,
+ sizeof(*device), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
if (!device)
return vk_error(physical_device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
for (unsigned i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
const VkDeviceQueueCreateInfo *queue_create =
- &pCreateInfo->pQueueCreateInfos[i];
+ &pCreateInfo->pQueueCreateInfos[i];
uint32_t qfi = queue_create->queueFamilyIndex;
- device->queues[qfi] =
- vk_alloc(&device->alloc,
- queue_create->queueCount * sizeof(struct tu_queue),
- 8,
- VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+ device->queues[qfi] = vk_alloc(
+ &device->alloc, queue_create->queueCount * sizeof(struct tu_queue),
+ 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
if (!device->queues[qfi]) {
result = VK_ERROR_OUT_OF_HOST_MEMORY;
goto fail;
}
- memset(device->queues[qfi],
- 0,
+ memset(device->queues[qfi], 0,
queue_create->queueCount * sizeof(struct tu_queue));
device->queue_count[qfi] = queue_create->queueCount;
for (unsigned q = 0; q < queue_create->queueCount; q++) {
- result = tu_queue_init(
- device, &device->queues[qfi][q], qfi, q, queue_create->flags);
+ result = tu_queue_init(device, &device->queues[qfi][q], qfi, q,
+ queue_create->flags);
if (result != VK_SUCCESS)
goto fail;
}
ci.initialDataSize = 0;
VkPipelineCache pc;
result =
- tu_CreatePipelineCache(tu_device_to_handle(device), &ci, NULL, &pc);
+ tu_CreatePipelineCache(tu_device_to_handle(device), &ci, NULL, &pc);
if (result != VK_SUCCESS)
goto fail;
struct tu_queue *queue;
queue =
- &device->queues[pQueueInfo->queueFamilyIndex][pQueueInfo->queueIndex];
+ &device->queues[pQueueInfo->queueFamilyIndex][pQueueInfo->queueIndex];
if (pQueueInfo->flags != queue->flags) {
/* From the Vulkan 1.1.70 spec:
*
VkQueue *pQueue)
{
const VkDeviceQueueInfo2 info =
- (VkDeviceQueueInfo2){.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2,
- .queueFamilyIndex = queueFamilyIndex,
- .queueIndex = queueIndex };
+ (VkDeviceQueueInfo2) { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2,
+ .queueFamilyIndex = queueFamilyIndex,
+ .queueIndex = queueIndex };
tu_GetDeviceQueue2(_device, &info, pQueue);
}
const VkSubmitInfo *pSubmits,
VkFence _fence)
{
+ TU_FROM_HANDLE(tu_queue, queue, _queue);
+
+ for (uint32_t i = 0; i < submitCount; ++i) {
+ const VkSubmitInfo *submit = pSubmits + i;
+ const bool last_submit = (i == submitCount - 1);
+ struct tu_bo_list bo_list;
+ tu_bo_list_init(&bo_list);
+
+ uint32_t entry_count = 0;
+ for (uint32_t j = 0; j < submit->commandBufferCount; ++j) {
+ TU_FROM_HANDLE(tu_cmd_buffer, cmdbuf, submit->pCommandBuffers[j]);
+ entry_count += cmdbuf->cs.entry_count;
+ }
+
+ struct drm_msm_gem_submit_cmd cmds[entry_count];
+ uint32_t entry_idx = 0;
+ for (uint32_t j = 0; j < submit->commandBufferCount; ++j) {
+ TU_FROM_HANDLE(tu_cmd_buffer, cmdbuf, submit->pCommandBuffers[j]);
+ struct tu_cs *cs = &cmdbuf->cs;
+ for (unsigned i = 0; i < cs->entry_count; ++i, ++entry_idx) {
+ cmds[entry_idx].type = MSM_SUBMIT_CMD_BUF;
+ cmds[entry_idx].submit_idx =
+ tu_bo_list_add(&bo_list, cs->entries[i].bo);
+ cmds[entry_idx].submit_offset = cs->entries[i].offset;
+ cmds[entry_idx].size = cs->entries[i].size;
+ cmds[entry_idx].pad = 0;
+ cmds[entry_idx].nr_relocs = 0;
+ cmds[entry_idx].relocs = 0;
+ }
+ }
+
+ struct drm_msm_gem_submit_bo bos[bo_list.count];
+ for (unsigned i = 0; i < bo_list.count; ++i) {
+ bos[i].flags = MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE;
+ bos[i].handle = bo_list.handles[i];
+ bos[i].presumed = 0;
+ }
+
+ uint32_t flags = MSM_PIPE_3D0;
+ if (last_submit) {
+ flags |= MSM_SUBMIT_FENCE_FD_OUT;
+ }
+
+ struct drm_msm_gem_submit req = {
+ .flags = flags,
+ .queueid = queue->msm_queue_id,
+ .bos = (uint64_t)(uintptr_t)bos,
+ .nr_bos = bo_list.count,
+ .cmds = (uint64_t)(uintptr_t)cmds,
+ .nr_cmds = entry_count,
+ };
+
+ int ret = drmCommandWriteRead(queue->device->physical_device->local_fd,
+ DRM_MSM_GEM_SUBMIT,
+ &req, sizeof(req));
+ if (ret) {
+ fprintf(stderr, "submit failed: %s\n", strerror(errno));
+ abort();
+ }
+
+ tu_bo_list_destroy(&bo_list);
+
+ if (last_submit) {
+ /* no need to merge fences as queue execution is serialized */
+ if (queue->submit_fence_fd >= 0) {
+ close(queue->submit_fence_fd);
+ }
+ queue->submit_fence_fd = req.fence_fd;
+ }
+ }
return VK_SUCCESS;
}
VkResult
tu_QueueWaitIdle(VkQueue _queue)
{
+ TU_FROM_HANDLE(tu_queue, queue, _queue);
+
+ if (queue->submit_fence_fd >= 0) {
+ int ret = sync_wait(queue->submit_fence_fd, -1);
+ if (ret)
+ tu_loge("sync_wait on fence fd %d failed", queue->submit_fence_fd);
+
+ close(queue->submit_fence_fd);
+ queue->submit_fence_fd = -1;
+ }
+
return VK_SUCCESS;
}
{
TU_FROM_HANDLE(tu_instance, instance, _instance);
- return tu_lookup_entrypoint_checked(pName,
- instance ? instance->api_version : 0,
- instance ? &instance->enabled_extensions
- : NULL,
- NULL);
+ return tu_lookup_entrypoint_checked(
+ pName, instance ? instance->api_version : 0,
+ instance ? &instance->enabled_extensions : NULL, NULL);
}
/* The loader wants us to expose a second GetInstanceProcAddr function
{
TU_FROM_HANDLE(tu_device, device, _device);
- return tu_lookup_entrypoint_checked(pName,
- device->instance->api_version,
- &device->instance->enabled_extensions,
- &device->enabled_extensions);
+ return tu_lookup_entrypoint_checked(pName, device->instance->api_version,
+ &device->instance->enabled_extensions,
+ &device->enabled_extensions);
}
static VkResult
return VK_SUCCESS;
}
- mem = vk_alloc2(&device->alloc,
- pAllocator,
- sizeof(*mem),
- 8,
+ mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (mem == NULL)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
if (mem->user_ptr) {
*ppData = mem->user_ptr;
- } else if (!mem->map){
+ } else if (!mem->map) {
result = tu_bo_map(device, &mem->bo);
if (result != VK_SUCCESS)
return result;
pMemoryRequirements->memoryTypeBits = 1;
pMemoryRequirements->alignment = 16;
pMemoryRequirements->size =
- align64(buffer->size, pMemoryRequirements->alignment);
+ align64(buffer->size, pMemoryRequirements->alignment);
}
void
const VkBufferMemoryRequirementsInfo2KHR *pInfo,
VkMemoryRequirements2KHR *pMemoryRequirements)
{
- tu_GetBufferMemoryRequirements(
- device, pInfo->buffer, &pMemoryRequirements->memoryRequirements);
+ tu_GetBufferMemoryRequirements(device, pInfo->buffer,
+ &pMemoryRequirements->memoryRequirements);
}
void
const VkImageMemoryRequirementsInfo2KHR *pInfo,
VkMemoryRequirements2KHR *pMemoryRequirements)
{
- tu_GetImageMemoryRequirements(
- device, pInfo->image, &pMemoryRequirements->memoryRequirements);
+ tu_GetImageMemoryRequirements(device, pInfo->image,
+ &pMemoryRequirements->memoryRequirements);
}
void
{
TU_FROM_HANDLE(tu_device, device, _device);
- struct tu_fence *fence = vk_alloc2(&device->alloc,
- pAllocator,
- sizeof(*fence),
- 8,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ struct tu_fence *fence =
+ vk_alloc2(&device->alloc, pAllocator, sizeof(*fence), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!fence)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
{
TU_FROM_HANDLE(tu_device, device, _device);
- struct tu_semaphore *sem = vk_alloc2(&device->alloc,
- pAllocator,
- sizeof(*sem),
- 8,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ struct tu_semaphore *sem =
+ vk_alloc2(&device->alloc, pAllocator, sizeof(*sem), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!sem)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
VkEvent *pEvent)
{
TU_FROM_HANDLE(tu_device, device, _device);
- struct tu_event *event = vk_alloc2(&device->alloc,
- pAllocator,
- sizeof(*event),
- 8,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ struct tu_event *event =
+ vk_alloc2(&device->alloc, pAllocator, sizeof(*event), 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!event)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
- buffer = vk_alloc2(&device->alloc,
- pAllocator,
- sizeof(*buffer),
- 8,
+ buffer = vk_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (buffer == NULL)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
tu_surface_max_layer_count(struct tu_image_view *iview)
{
return iview->type == VK_IMAGE_VIEW_TYPE_3D
- ? iview->extent.depth
- : (iview->base_layer + iview->layer_count);
+ ? iview->extent.depth
+ : (iview->base_layer + iview->layer_count);
}
VkResult
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
- size_t size =
- sizeof(*framebuffer) +
- sizeof(struct tu_attachment_info) * pCreateInfo->attachmentCount;
- framebuffer = vk_alloc2(
- &device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ size_t size = sizeof(*framebuffer) + sizeof(struct tu_attachment_info) *
+ pCreateInfo->attachmentCount;
+ framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (framebuffer == NULL)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
framebuffer->width = MIN2(framebuffer->width, iview->extent.width);
framebuffer->height = MIN2(framebuffer->height, iview->extent.height);
framebuffer->layers =
- MIN2(framebuffer->layers, tu_surface_max_layer_count(iview));
+ MIN2(framebuffer->layers, tu_surface_max_layer_count(iview));
}
*pFramebuffer = tu_framebuffer_to_handle(framebuffer);
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
- sampler = vk_alloc2(&device->alloc,
- pAllocator,
- sizeof(*sampler),
- 8,
+ sampler = vk_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!sampler)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion)
{
/* For the full details on loader interface versioning, see
- * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
- * What follows is a condensed summary, to help you navigate the large and
- * confusing official doc.
- *
- * - Loader interface v0 is incompatible with later versions. We don't
- * support it.
- *
- * - In loader interface v1:
- * - The first ICD entrypoint called by the loader is
- * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
- * entrypoint.
- * - The ICD must statically expose no other Vulkan symbol unless it is
- * linked with -Bsymbolic.
- * - Each dispatchable Vulkan handle created by the ICD must be
- * a pointer to a struct whose first member is VK_LOADER_DATA. The
- * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
- * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
- * vkDestroySurfaceKHR(). The ICD must be capable of working with
- * such loader-managed surfaces.
- *
- * - Loader interface v2 differs from v1 in:
- * - The first ICD entrypoint called by the loader is
- * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
- * statically expose this entrypoint.
- *
- * - Loader interface v3 differs from v2 in:
- * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
- * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
- * because the loader no longer does so.
- */
+ * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
+ * What follows is a condensed summary, to help you navigate the large and
+ * confusing official doc.
+ *
+ * - Loader interface v0 is incompatible with later versions. We don't
+ * support it.
+ *
+ * - In loader interface v1:
+ * - The first ICD entrypoint called by the loader is
+ * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
+ * entrypoint.
+ * - The ICD must statically expose no other Vulkan symbol unless it
+ * is linked with -Bsymbolic.
+ * - Each dispatchable Vulkan handle created by the ICD must be
+ * a pointer to a struct whose first member is VK_LOADER_DATA. The
+ * ICD must initialize VK_LOADER_DATA.loadMagic to
+ * ICD_LOADER_MAGIC.
+ * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
+ * vkDestroySurfaceKHR(). The ICD must be capable of working with
+ * such loader-managed surfaces.
+ *
+ * - Loader interface v2 differs from v1 in:
+ * - The first ICD entrypoint called by the loader is
+ * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
+ * statically expose this entrypoint.
+ *
+ * - Loader interface v3 differs from v2 in:
+ * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
+ * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
+ * because the loader no longer does so.
+ */
*pSupportedVersion = MIN2(*pSupportedVersion, 3u);
return VK_SUCCESS;
}
{
TU_FROM_HANDLE(tu_instance, instance, _instance);
return vk_create_debug_report_callback(&instance->debug_report_callbacks,
- pCreateInfo,
- pAllocator,
- &instance->alloc,
- pCallback);
+ pCreateInfo, pAllocator,
+ &instance->alloc, pCallback);
}
void
{
TU_FROM_HANDLE(tu_instance, instance, _instance);
vk_destroy_debug_report_callback(&instance->debug_report_callbacks,
- _callback,
- pAllocator,
- &instance->alloc);
+ _callback, pAllocator, &instance->alloc);
}
void
const char *pMessage)
{
TU_FROM_HANDLE(tu_instance, instance, _instance);
- vk_debug_report(&instance->debug_report_callbacks,
- flags,
- objectType,
- object,
- location,
- messageCode,
- pLayerPrefix,
- pMessage);
+ vk_debug_report(&instance->debug_report_callbacks, flags, objectType,
+ object, location, messageCode, pLayerPrefix, pMessage);
}
void