tu: use common interfaces for shader modules

Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9508>
This commit is contained in:
Mike Blumenkrantz 2021-03-10 17:50:15 -05:00 committed by Marge Bot
parent 07c9dc54dd
commit 71b17149e8
2 changed files with 5 additions and 54 deletions

View File

@ -59,6 +59,7 @@
#include "vk_extensions.h"
#include "vk_instance.h"
#include "vk_physical_device.h"
#include "vk_shader_module.h"
#include "wsi_common.h"
#include "ir3/ir3_compiler.h"
@ -1018,14 +1019,6 @@ struct tu_event
struct tu_bo bo;
};
struct tu_shader_module
{
struct vk_object_base base;
uint32_t code_size;
uint32_t code[];
};
struct tu_push_constant_range
{
uint32_t lo;
@ -1629,7 +1622,6 @@ TU_DEFINE_NONDISP_HANDLE_CASTS(tu_query_pool, VkQueryPool)
TU_DEFINE_NONDISP_HANDLE_CASTS(tu_render_pass, VkRenderPass)
TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler, VkSampler)
TU_DEFINE_NONDISP_HANDLE_CASTS(tu_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
TU_DEFINE_NONDISP_HANDLE_CASTS(tu_shader_module, VkShaderModule)
/* for TU_FROM_HANDLE with both VkFence and VkSemaphore: */
#define tu_syncobj_from_handle(x) ((struct tu_syncobj*) (uintptr_t) (x))

View File

@ -111,11 +111,11 @@ tu_spirv_to_nir(struct tu_device *dev,
num_spec = spec_info->mapEntryCount;
}
struct tu_shader_module *module =
tu_shader_module_from_handle(stage_info->module);
assert(module->code_size % 4 == 0);
struct vk_shader_module *module =
vk_shader_module_from_handle(stage_info->module);
assert(module->size % 4 == 0);
nir_shader *nir =
spirv_to_nir(module->code, module->code_size / 4,
spirv_to_nir((void*)module->data, module->size / 4,
spec, num_spec, stage, stage_info->pName,
&spirv_options, nir_options);
@ -839,44 +839,3 @@ tu_shader_destroy(struct tu_device *dev,
vk_free2(&dev->vk.alloc, alloc, shader);
}
VkResult
tu_CreateShaderModule(VkDevice _device,
const VkShaderModuleCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkShaderModule *pShaderModule)
{
TU_FROM_HANDLE(tu_device, device, _device);
struct tu_shader_module *module;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
assert(pCreateInfo->flags == 0);
assert(pCreateInfo->codeSize % 4 == 0);
module = vk_object_alloc(&device->vk, pAllocator,
sizeof(*module) + pCreateInfo->codeSize,
VK_OBJECT_TYPE_SHADER_MODULE);
if (module == NULL)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
module->code_size = pCreateInfo->codeSize;
memcpy(module->code, pCreateInfo->pCode, pCreateInfo->codeSize);
*pShaderModule = tu_shader_module_to_handle(module);
return VK_SUCCESS;
}
void
tu_DestroyShaderModule(VkDevice _device,
VkShaderModule _module,
const VkAllocationCallbacks *pAllocator)
{
TU_FROM_HANDLE(tu_device, device, _device);
TU_FROM_HANDLE(tu_shader_module, module, _module);
if (!module)
return;
vk_object_free(&device->vk, pAllocator, module);
}