anv: Add support for vkCmdSetRayTracingPipelineStackSizeKHR

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:
Jason Ekstrand
2020-08-06 22:53:06 -05:00
committed by Marge Bot
parent 02f7964a13
commit f68d64dac0
3 changed files with 72 additions and 0 deletions

View File

@@ -518,6 +518,11 @@ void anv_CmdBindPipeline(
cmd_buffer->state.rt.pipeline = rt_pipeline; cmd_buffer->state.rt.pipeline = rt_pipeline;
cmd_buffer->state.rt.pipeline_dirty = true; cmd_buffer->state.rt.pipeline_dirty = true;
if (rt_pipeline->stack_size > 0) {
anv_CmdSetRayTracingPipelineStackSizeKHR(commandBuffer,
rt_pipeline->stack_size);
}
break; break;
} }
@@ -1591,8 +1596,60 @@ void anv_CmdSetFragmentShadingRateKHR(
cmd_buffer->state.gfx.dirty |= ANV_CMD_DIRTY_DYNAMIC_SHADING_RATE; cmd_buffer->state.gfx.dirty |= ANV_CMD_DIRTY_DYNAMIC_SHADING_RATE;
} }
static inline uint32_t
ilog2_round_up(uint32_t value)
{
assert(value != 0);
return 32 - __builtin_clz(value - 1);
}
void anv_CmdSetRayTracingPipelineStackSizeKHR( void anv_CmdSetRayTracingPipelineStackSizeKHR(
VkCommandBuffer commandBuffer, VkCommandBuffer commandBuffer,
uint32_t pipelineStackSize) uint32_t pipelineStackSize)
{ {
ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
struct anv_cmd_ray_tracing_state *rt = &cmd_buffer->state.rt;
struct anv_device *device = cmd_buffer->device;
if (anv_batch_has_error(&cmd_buffer->batch))
return;
uint32_t stack_ids_per_dss = 2048; /* TODO */
unsigned stack_size_log2 = ilog2_round_up(pipelineStackSize);
if (stack_size_log2 < 10)
stack_size_log2 = 10;
if (rt->scratch.layout.total_size == 1 << stack_size_log2)
return;
brw_rt_compute_scratch_layout(&rt->scratch.layout, &device->info,
stack_ids_per_dss, 1 << stack_size_log2);
unsigned bucket = stack_size_log2 - 10;
assert(bucket < ARRAY_SIZE(device->rt_scratch_bos));
struct anv_bo *bo = p_atomic_read(&device->rt_scratch_bos[bucket]);
if (bo == NULL) {
struct anv_bo *new_bo;
VkResult result = anv_device_alloc_bo(device, "RT scratch",
rt->scratch.layout.total_size,
0, /* alloc_flags */
0, /* explicit_address */
&new_bo);
if (result != VK_SUCCESS) {
rt->scratch.layout.total_size = 0;
anv_batch_set_error(&cmd_buffer->batch, result);
return;
}
bo = p_atomic_cmpxchg(&device->rt_scratch_bos[bucket], NULL, new_bo);
if (bo != NULL) {
anv_device_release_bo(device, bo);
} else {
bo = new_bo;
}
}
rt->scratch.bo = bo;
} }

View File

@@ -3344,6 +3344,9 @@ VkResult anv_CreateDevice(
anv_scratch_pool_init(device, &device->scratch_pool); anv_scratch_pool_init(device, &device->scratch_pool);
/* TODO(RT): Do we want some sort of data structure for this? */
memset(device->rt_scratch_bos, 0, sizeof(device->rt_scratch_bos));
result = anv_genX(&device->info, init_device_state)(device); result = anv_genX(&device->info, init_device_state)(device);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
goto fail_trivial_batch_bo_and_scratch_pool; goto fail_trivial_batch_bo_and_scratch_pool;
@@ -3436,6 +3439,11 @@ void anv_DestroyDevice(
anv_state_pool_free(&device->dynamic_state_pool, device->slice_hash); anv_state_pool_free(&device->dynamic_state_pool, device->slice_hash);
#endif #endif
for (unsigned i = 0; i < ARRAY_SIZE(device->rt_scratch_bos); i++) {
if (device->rt_scratch_bos[i] != NULL)
anv_device_release_bo(device, device->rt_scratch_bos[i]);
}
anv_scratch_pool_finish(device, &device->scratch_pool); anv_scratch_pool_finish(device, &device->scratch_pool);
anv_device_release_bo(device, device->workaround_bo); anv_device_release_bo(device, device->workaround_bo);

View File

@@ -51,6 +51,7 @@
#include "dev/intel_device_info.h" #include "dev/intel_device_info.h"
#include "blorp/blorp.h" #include "blorp/blorp.h"
#include "compiler/brw_compiler.h" #include "compiler/brw_compiler.h"
#include "compiler/brw_rt.h"
#include "util/bitset.h" #include "util/bitset.h"
#include "util/bitscan.h" #include "util/bitscan.h"
#include "util/macros.h" #include "util/macros.h"
@@ -1238,6 +1239,7 @@ struct anv_device {
struct anv_queue * queues; struct anv_queue * queues;
struct anv_scratch_pool scratch_pool; struct anv_scratch_pool scratch_pool;
struct anv_bo *rt_scratch_bos[16];
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t queue_submit; pthread_cond_t queue_submit;
@@ -2937,6 +2939,11 @@ struct anv_cmd_ray_tracing_state {
struct anv_ray_tracing_pipeline *pipeline; struct anv_ray_tracing_pipeline *pipeline;
bool pipeline_dirty; bool pipeline_dirty;
struct {
struct anv_bo *bo;
struct brw_rt_scratch_layout layout;
} scratch;
}; };
/** State required while building cmd buffer */ /** State required while building cmd buffer */