anv: Add a ray-tracing pipeline object
This just adds the core data structure which we'll build on going forward. v2: Add VK_EXT_pipeline_creation_cache_control handling (Lionel) Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8637>
This commit is contained in:

committed by
Marge Bot

parent
dc05daf0e5
commit
8cc5080580
@@ -348,6 +348,18 @@ void anv_DestroyPipeline(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ANV_PIPELINE_RAY_TRACING: {
|
||||||
|
struct anv_ray_tracing_pipeline *rt_pipeline =
|
||||||
|
anv_pipeline_to_ray_tracing(pipeline);
|
||||||
|
|
||||||
|
util_dynarray_foreach(&rt_pipeline->shaders,
|
||||||
|
struct anv_shader_bin *, shader) {
|
||||||
|
anv_shader_bin_unref(device, *shader);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
unreachable("invalid pipeline type");
|
unreachable("invalid pipeline type");
|
||||||
}
|
}
|
||||||
@@ -2392,6 +2404,16 @@ anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline,
|
|||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
anv_ray_tracing_pipeline_init(struct anv_ray_tracing_pipeline *pipeline,
|
||||||
|
struct anv_device *device,
|
||||||
|
struct anv_pipeline_cache *cache,
|
||||||
|
const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
|
||||||
|
const VkAllocationCallbacks *alloc)
|
||||||
|
{
|
||||||
|
return VK_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#define WRITE_STR(field, ...) ({ \
|
#define WRITE_STR(field, ...) ({ \
|
||||||
memset(field, 0, sizeof(field)); \
|
memset(field, 0, sizeof(field)); \
|
||||||
UNUSED int i = snprintf(field, sizeof(field), __VA_ARGS__); \
|
UNUSED int i = snprintf(field, sizeof(field), __VA_ARGS__); \
|
||||||
|
@@ -2928,6 +2928,14 @@ struct anv_cmd_compute_state {
|
|||||||
struct anv_address num_workgroups;
|
struct anv_address num_workgroups;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct anv_cmd_ray_tracing_state {
|
||||||
|
struct anv_cmd_pipeline_state base;
|
||||||
|
|
||||||
|
struct anv_ray_tracing_pipeline *pipeline;
|
||||||
|
|
||||||
|
bool pipeline_dirty;
|
||||||
|
};
|
||||||
|
|
||||||
/** State required while building cmd buffer */
|
/** State required while building cmd buffer */
|
||||||
struct anv_cmd_state {
|
struct anv_cmd_state {
|
||||||
/* PIPELINE_SELECT.PipelineSelection */
|
/* PIPELINE_SELECT.PipelineSelection */
|
||||||
@@ -2937,6 +2945,7 @@ struct anv_cmd_state {
|
|||||||
|
|
||||||
struct anv_cmd_graphics_state gfx;
|
struct anv_cmd_graphics_state gfx;
|
||||||
struct anv_cmd_compute_state compute;
|
struct anv_cmd_compute_state compute;
|
||||||
|
struct anv_cmd_ray_tracing_state rt;
|
||||||
|
|
||||||
enum anv_pipe_bits pending_pipe_bits;
|
enum anv_pipe_bits pending_pipe_bits;
|
||||||
VkShaderStageFlags descriptors_dirty;
|
VkShaderStageFlags descriptors_dirty;
|
||||||
@@ -3441,6 +3450,7 @@ struct anv_pipeline_executable {
|
|||||||
enum anv_pipeline_type {
|
enum anv_pipeline_type {
|
||||||
ANV_PIPELINE_GRAPHICS,
|
ANV_PIPELINE_GRAPHICS,
|
||||||
ANV_PIPELINE_COMPUTE,
|
ANV_PIPELINE_COMPUTE,
|
||||||
|
ANV_PIPELINE_RAY_TRACING,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct anv_pipeline {
|
struct anv_pipeline {
|
||||||
@@ -3550,6 +3560,28 @@ struct anv_compute_pipeline {
|
|||||||
uint32_t interface_descriptor_data[8];
|
uint32_t interface_descriptor_data[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct anv_rt_shader_group {
|
||||||
|
VkRayTracingShaderGroupTypeKHR type;
|
||||||
|
|
||||||
|
struct anv_shader_bin *general;
|
||||||
|
struct anv_shader_bin *closest_hit;
|
||||||
|
struct anv_shader_bin *any_hit;
|
||||||
|
struct anv_shader_bin *intersection;
|
||||||
|
|
||||||
|
/* VK_KHR_ray_tracing requires shaderGroupHandleSize == 32 */
|
||||||
|
uint32_t handle[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct anv_ray_tracing_pipeline {
|
||||||
|
struct anv_pipeline base;
|
||||||
|
|
||||||
|
/* All shaders in the pipeline */
|
||||||
|
struct util_dynarray shaders;
|
||||||
|
|
||||||
|
uint32_t group_count;
|
||||||
|
struct anv_rt_shader_group * groups;
|
||||||
|
};
|
||||||
|
|
||||||
#define ANV_DECL_PIPELINE_DOWNCAST(pipe_type, pipe_enum) \
|
#define ANV_DECL_PIPELINE_DOWNCAST(pipe_type, pipe_enum) \
|
||||||
static inline struct anv_##pipe_type##_pipeline * \
|
static inline struct anv_##pipe_type##_pipeline * \
|
||||||
anv_pipeline_to_##pipe_type(struct anv_pipeline *pipeline) \
|
anv_pipeline_to_##pipe_type(struct anv_pipeline *pipeline) \
|
||||||
@@ -3560,6 +3592,7 @@ struct anv_compute_pipeline {
|
|||||||
|
|
||||||
ANV_DECL_PIPELINE_DOWNCAST(graphics, ANV_PIPELINE_GRAPHICS)
|
ANV_DECL_PIPELINE_DOWNCAST(graphics, ANV_PIPELINE_GRAPHICS)
|
||||||
ANV_DECL_PIPELINE_DOWNCAST(compute, ANV_PIPELINE_COMPUTE)
|
ANV_DECL_PIPELINE_DOWNCAST(compute, ANV_PIPELINE_COMPUTE)
|
||||||
|
ANV_DECL_PIPELINE_DOWNCAST(ray_tracing, ANV_PIPELINE_RAY_TRACING)
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
anv_pipeline_has_stage(const struct anv_graphics_pipeline *pipeline,
|
anv_pipeline_has_stage(const struct anv_graphics_pipeline *pipeline,
|
||||||
@@ -3630,6 +3663,13 @@ anv_pipeline_compile_cs(struct anv_compute_pipeline *pipeline,
|
|||||||
const char *entrypoint,
|
const char *entrypoint,
|
||||||
const VkSpecializationInfo *spec_info);
|
const VkSpecializationInfo *spec_info);
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
anv_ray_tracing_pipeline_init(struct anv_ray_tracing_pipeline *pipeline,
|
||||||
|
struct anv_device *device,
|
||||||
|
struct anv_pipeline_cache *cache,
|
||||||
|
const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
|
||||||
|
const VkAllocationCallbacks *alloc);
|
||||||
|
|
||||||
struct anv_format_plane {
|
struct anv_format_plane {
|
||||||
enum isl_format isl_format:16;
|
enum isl_format isl_format:16;
|
||||||
struct isl_swizzle swizzle;
|
struct isl_swizzle swizzle;
|
||||||
|
@@ -2797,6 +2797,115 @@ VkResult genX(CreateComputePipelines)(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GFX_VERx10 >= 125
|
||||||
|
|
||||||
|
static void
|
||||||
|
assert_rt_stage_index_valid(const VkRayTracingPipelineCreateInfoKHR* pCreateInfo,
|
||||||
|
uint32_t stage_idx,
|
||||||
|
VkShaderStageFlags valid_stages)
|
||||||
|
{
|
||||||
|
if (stage_idx == VK_SHADER_UNUSED_KHR)
|
||||||
|
return;
|
||||||
|
|
||||||
|
assert(stage_idx <= pCreateInfo->stageCount);
|
||||||
|
assert(util_bitcount(pCreateInfo->pStages[stage_idx].stage) == 1);
|
||||||
|
assert(pCreateInfo->pStages[stage_idx].stage & valid_stages);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VkResult
|
||||||
|
ray_tracing_pipeline_create(
|
||||||
|
VkDevice _device,
|
||||||
|
struct anv_pipeline_cache * cache,
|
||||||
|
const VkRayTracingPipelineCreateInfoKHR* pCreateInfo,
|
||||||
|
const VkAllocationCallbacks* pAllocator,
|
||||||
|
VkPipeline* pPipeline)
|
||||||
|
{
|
||||||
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
||||||
|
VkResult result;
|
||||||
|
|
||||||
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR);
|
||||||
|
|
||||||
|
/* Use the default pipeline cache if none is specified */
|
||||||
|
if (cache == NULL && device->physical->instance->pipeline_cache_enabled)
|
||||||
|
cache = &device->default_pipeline_cache;
|
||||||
|
|
||||||
|
VK_MULTIALLOC(ma);
|
||||||
|
VK_MULTIALLOC_DECL(&ma, struct anv_ray_tracing_pipeline, pipeline, 1);
|
||||||
|
VK_MULTIALLOC_DECL(&ma, struct anv_rt_shader_group, groups, pCreateInfo->groupCount);
|
||||||
|
if (!vk_multialloc_alloc2(&ma, &device->vk.alloc, pAllocator,
|
||||||
|
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
|
||||||
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
|
||||||
|
result = anv_pipeline_init(&pipeline->base, device,
|
||||||
|
ANV_PIPELINE_RAY_TRACING, pCreateInfo->flags,
|
||||||
|
pAllocator);
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
vk_free2(&device->vk.alloc, pAllocator, pipeline);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline->group_count = pCreateInfo->groupCount;
|
||||||
|
pipeline->groups = groups;
|
||||||
|
|
||||||
|
const VkShaderStageFlags ray_tracing_stages =
|
||||||
|
VK_SHADER_STAGE_RAYGEN_BIT_KHR |
|
||||||
|
VK_SHADER_STAGE_ANY_HIT_BIT_KHR |
|
||||||
|
VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR |
|
||||||
|
VK_SHADER_STAGE_MISS_BIT_KHR |
|
||||||
|
VK_SHADER_STAGE_INTERSECTION_BIT_KHR |
|
||||||
|
VK_SHADER_STAGE_CALLABLE_BIT_KHR;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < pCreateInfo->stageCount; i++)
|
||||||
|
assert((pCreateInfo->pStages[i].stage & ~ray_tracing_stages) == 0);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < pCreateInfo->groupCount; i++) {
|
||||||
|
const VkRayTracingShaderGroupCreateInfoKHR *ginfo =
|
||||||
|
&pCreateInfo->pGroups[i];
|
||||||
|
assert_rt_stage_index_valid(pCreateInfo, ginfo->generalShader,
|
||||||
|
VK_SHADER_STAGE_RAYGEN_BIT_KHR |
|
||||||
|
VK_SHADER_STAGE_MISS_BIT_KHR |
|
||||||
|
VK_SHADER_STAGE_CALLABLE_BIT_KHR);
|
||||||
|
assert_rt_stage_index_valid(pCreateInfo, ginfo->closestHitShader,
|
||||||
|
VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR);
|
||||||
|
assert_rt_stage_index_valid(pCreateInfo, ginfo->anyHitShader,
|
||||||
|
VK_SHADER_STAGE_ANY_HIT_BIT_KHR);
|
||||||
|
assert_rt_stage_index_valid(pCreateInfo, ginfo->intersectionShader,
|
||||||
|
VK_SHADER_STAGE_INTERSECTION_BIT_KHR);
|
||||||
|
switch (ginfo->type) {
|
||||||
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR:
|
||||||
|
assert(ginfo->generalShader < pCreateInfo->stageCount);
|
||||||
|
assert(ginfo->anyHitShader == VK_SHADER_UNUSED_KHR);
|
||||||
|
assert(ginfo->closestHitShader == VK_SHADER_UNUSED_KHR);
|
||||||
|
assert(ginfo->intersectionShader == VK_SHADER_UNUSED_KHR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR:
|
||||||
|
assert(ginfo->generalShader == VK_SHADER_UNUSED_KHR);
|
||||||
|
assert(ginfo->intersectionShader == VK_SHADER_UNUSED_KHR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR:
|
||||||
|
assert(ginfo->generalShader == VK_SHADER_UNUSED_KHR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
unreachable("Invalid ray-tracing shader group type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = anv_ray_tracing_pipeline_init(pipeline, device, cache,
|
||||||
|
pCreateInfo, pAllocator);
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
anv_pipeline_finish(&pipeline->base, device, pAllocator);
|
||||||
|
vk_free2(&device->vk.alloc, pAllocator, pipeline);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pPipeline = anv_pipeline_to_handle(&pipeline->base);
|
||||||
|
|
||||||
|
return pipeline->base.batch.status;
|
||||||
|
}
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
genX(CreateRayTracingPipelinesKHR)(
|
genX(CreateRayTracingPipelinesKHR)(
|
||||||
VkDevice _device,
|
VkDevice _device,
|
||||||
@@ -2807,6 +2916,32 @@ genX(CreateRayTracingPipelinesKHR)(
|
|||||||
const VkAllocationCallbacks* pAllocator,
|
const VkAllocationCallbacks* pAllocator,
|
||||||
VkPipeline* pPipelines)
|
VkPipeline* pPipelines)
|
||||||
{
|
{
|
||||||
unreachable("Unimplemented");
|
ANV_FROM_HANDLE(anv_pipeline_cache, pipeline_cache, pipelineCache);
|
||||||
return VK_INCOMPLETE;
|
|
||||||
|
VkResult result = VK_SUCCESS;
|
||||||
|
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; i < createInfoCount; i++) {
|
||||||
|
VkResult res = ray_tracing_pipeline_create(_device, pipeline_cache,
|
||||||
|
&pCreateInfos[i],
|
||||||
|
pAllocator, &pPipelines[i]);
|
||||||
|
|
||||||
|
if (res == VK_SUCCESS)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Bail out on the first error as it is not obvious what error should be
|
||||||
|
* report upon 2 different failures. */
|
||||||
|
result = res;
|
||||||
|
if (result != VK_PIPELINE_COMPILE_REQUIRED_EXT)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; i < createInfoCount; i++)
|
||||||
|
pPipelines[i] = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif /* GFX_VERx10 >= 125 */
|
||||||
|
Reference in New Issue
Block a user