nvk: use common pipeline layout code
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
committed by
Marge Bot
parent
04e7c38fd6
commit
f098d26e91
@@ -44,8 +44,6 @@ nvk_files = files(
|
||||
'nvk_physical_device.h',
|
||||
'nvk_pipeline.c',
|
||||
'nvk_pipeline.h',
|
||||
'nvk_pipeline_layout.c',
|
||||
'nvk_pipeline_layout.h',
|
||||
'nvk_private.h',
|
||||
'nvk_queue.c',
|
||||
'nvk_queue.h',
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "nvk_descriptor_set_layout.h"
|
||||
#include "nvk_device.h"
|
||||
#include "nvk_pipeline.h"
|
||||
#include "nvk_pipeline_layout.h"
|
||||
#include "nvk_physical_device.h"
|
||||
|
||||
#include "nouveau_context.h"
|
||||
@@ -282,7 +281,7 @@ nvk_CmdBindDescriptorSets(VkCommandBuffer commandBuffer,
|
||||
const uint32_t *pDynamicOffsets)
|
||||
{
|
||||
VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer);
|
||||
VK_FROM_HANDLE(nvk_pipeline_layout, pipeline_layout, layout);
|
||||
VK_FROM_HANDLE(vk_pipeline_layout, pipeline_layout, layout);
|
||||
struct nvk_descriptor_state *desc =
|
||||
nvk_get_descriptors_state(cmd, pipelineBindPoint);
|
||||
|
||||
@@ -291,7 +290,7 @@ nvk_CmdBindDescriptorSets(VkCommandBuffer commandBuffer,
|
||||
unsigned set_idx = i + firstSet;
|
||||
VK_FROM_HANDLE(nvk_descriptor_set, set, pDescriptorSets[i]);
|
||||
const struct nvk_descriptor_set_layout *set_layout =
|
||||
pipeline_layout->set[set_idx].layout;
|
||||
vk_to_nvk_descriptor_set_layout(pipeline_layout->set_layouts[set_idx]);
|
||||
|
||||
if (desc->sets[set_idx] != set) {
|
||||
if (set->bo)
|
||||
@@ -306,7 +305,7 @@ nvk_CmdBindDescriptorSets(VkCommandBuffer commandBuffer,
|
||||
|
||||
if (set_layout->dynamic_buffer_count > 0) {
|
||||
const uint32_t dynamic_buffer_start =
|
||||
pipeline_layout->set[set_idx].dynamic_buffer_start;
|
||||
nvk_descriptor_set_layout_dynbuf_start(pipeline_layout, set_idx);
|
||||
|
||||
for (uint32_t j = 0; j < set_layout->dynamic_buffer_count; j++) {
|
||||
struct nvk_buffer_address addr = set->dynamic_buffers[j];
|
||||
@@ -353,7 +352,7 @@ nvk_CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
|
||||
const VkWriteDescriptorSet *pDescriptorWrites)
|
||||
{
|
||||
VK_FROM_HANDLE(nvk_cmd_buffer, cmd, commandBuffer);
|
||||
VK_FROM_HANDLE(nvk_pipeline_layout, pipeline_layout, layout);
|
||||
VK_FROM_HANDLE(vk_pipeline_layout, pipeline_layout, layout);
|
||||
struct nvk_descriptor_state *desc =
|
||||
nvk_get_descriptors_state(cmd, pipelineBindPoint);
|
||||
|
||||
@@ -371,8 +370,11 @@ nvk_CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
|
||||
/* Pushing descriptors replaces whatever sets are bound */
|
||||
desc->sets[set] = NULL;
|
||||
|
||||
struct nvk_descriptor_set_layout *set_layout =
|
||||
vk_to_nvk_descriptor_set_layout(pipeline_layout->set_layouts[set]);
|
||||
|
||||
nvk_push_descriptor_set_update(desc->push[set],
|
||||
pipeline_layout->set[set].layout,
|
||||
set_layout,
|
||||
descriptorWriteCount, pDescriptorWrites);
|
||||
desc->push_dirty |= BITFIELD_BIT(set);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "nvk_private.h"
|
||||
#include "nvk_device.h"
|
||||
#include "nvk_pipeline.h"
|
||||
#include "nvk_pipeline_layout.h"
|
||||
#include "nvk_shader.h"
|
||||
|
||||
#include "nouveau_bo.h"
|
||||
@@ -70,7 +69,7 @@ nvk_compute_pipeline_create(struct nvk_device *device,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkPipeline *pPipeline)
|
||||
{
|
||||
VK_FROM_HANDLE(nvk_pipeline_layout, pipeline_layout, pCreateInfo->layout);
|
||||
VK_FROM_HANDLE(vk_pipeline_layout, pipeline_layout, pCreateInfo->layout);
|
||||
struct nvk_physical_device *pdevice = nvk_device_physical(device);
|
||||
struct nvk_compute_pipeline *pipeline;
|
||||
VkResult result;
|
||||
|
||||
@@ -227,3 +227,20 @@ nvk_CreateDescriptorSetLayout(VkDevice _device,
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
nvk_descriptor_set_layout_dynbuf_start(const struct vk_pipeline_layout *pipeline_layout,
|
||||
int set_layout_idx)
|
||||
{
|
||||
uint8_t dynamic_buffer_start = 0;
|
||||
|
||||
assert(set_layout_idx <= pipeline_layout->set_count);
|
||||
|
||||
for (uint32_t i = 0; i < set_layout_idx; i++) {
|
||||
const struct nvk_descriptor_set_layout *set_layout =
|
||||
vk_to_nvk_descriptor_set_layout(pipeline_layout->set_layouts[i]);
|
||||
|
||||
dynamic_buffer_start += set_layout->dynamic_buffer_count;
|
||||
}
|
||||
return dynamic_buffer_start;
|
||||
}
|
||||
|
||||
@@ -60,4 +60,13 @@ void nvk_descriptor_stride_align_for_type(VkDescriptorType type,
|
||||
const VkMutableDescriptorTypeListVALVE *type_list,
|
||||
uint32_t *stride, uint32_t *align);
|
||||
|
||||
static inline struct nvk_descriptor_set_layout *
|
||||
vk_to_nvk_descriptor_set_layout(struct vk_descriptor_set_layout *layout)
|
||||
{
|
||||
return container_of(layout, struct nvk_descriptor_set_layout, vk);
|
||||
}
|
||||
|
||||
uint8_t
|
||||
nvk_descriptor_set_layout_dynbuf_start(const struct vk_pipeline_layout *pipeline_layout,
|
||||
int set_layout_idx);
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "nvk_pipeline.h"
|
||||
|
||||
#include "nvk_device.h"
|
||||
#include "nvk_pipeline_layout.h"
|
||||
#include "nvk_shader.h"
|
||||
#include "nv_push.h"
|
||||
#include "vk_nir.h"
|
||||
@@ -199,7 +198,7 @@ nvk_graphics_pipeline_create(struct nvk_device *device,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkPipeline *pPipeline)
|
||||
{
|
||||
VK_FROM_HANDLE(nvk_pipeline_layout, pipeline_layout, pCreateInfo->layout);
|
||||
VK_FROM_HANDLE(vk_pipeline_layout, pipeline_layout, pCreateInfo->layout);
|
||||
struct nvk_physical_device *pdevice = nvk_device_physical(device);
|
||||
struct nvk_graphics_pipeline *pipeline;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
|
||||
#include "compiler/nir/nir.h"
|
||||
|
||||
struct nvk_pipeline_layout;
|
||||
|
||||
bool nvk_nir_lower_descriptors(nir_shader *nir,
|
||||
const struct nvk_pipeline_layout *layout,
|
||||
const struct vk_pipeline_layout *layout,
|
||||
bool robust_buffer_access);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
#include "nvk_descriptor_set.h"
|
||||
#include "nvk_descriptor_set_layout.h"
|
||||
#include "nvk_nir.h"
|
||||
#include "nvk_pipeline_layout.h"
|
||||
|
||||
#include "nir_builder.h"
|
||||
#include "nir_deref.h"
|
||||
|
||||
struct lower_descriptors_ctx {
|
||||
const struct nvk_pipeline_layout *layout;
|
||||
const struct vk_pipeline_layout *layout;
|
||||
bool clamp_desc_array_bounds;
|
||||
nir_address_format desc_addr_format;
|
||||
nir_address_format ubo_addr_format;
|
||||
@@ -33,8 +32,12 @@ load_descriptor(nir_builder *b, unsigned num_components, unsigned bit_size,
|
||||
const struct lower_descriptors_ctx *ctx)
|
||||
{
|
||||
assert(set < NVK_MAX_SETS);
|
||||
|
||||
const struct vk_pipeline_layout *layout = ctx->layout;
|
||||
const struct nvk_descriptor_set_layout *set_layout =
|
||||
vk_to_nvk_descriptor_set_layout(layout->set_layouts[set]);
|
||||
const struct nvk_descriptor_set_binding_layout *binding_layout =
|
||||
&ctx->layout->set[set].layout->binding[binding];
|
||||
&set_layout->binding[binding];
|
||||
|
||||
if (ctx->clamp_desc_array_bounds)
|
||||
index = nir_umin(b, index, nir_imm_int(b, binding_layout->array_size - 1));
|
||||
@@ -43,8 +46,11 @@ load_descriptor(nir_builder *b, unsigned num_components, unsigned bit_size,
|
||||
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
|
||||
/* Get the index in the root descriptor table dynamic_buffers array. */
|
||||
uint8_t dynamic_buffer_start =
|
||||
nvk_descriptor_set_layout_dynbuf_start(layout, set);
|
||||
|
||||
index = nir_iadd_imm(b, index,
|
||||
ctx->layout->set[set].dynamic_buffer_start +
|
||||
dynamic_buffer_start +
|
||||
binding_layout->dynamic_buffer_index);
|
||||
|
||||
nir_ssa_def *root_desc_offset =
|
||||
@@ -298,7 +304,7 @@ lower_descriptors_instr(nir_builder *b, nir_instr *instr,
|
||||
|
||||
bool
|
||||
nvk_nir_lower_descriptors(nir_shader *nir,
|
||||
const struct nvk_pipeline_layout *layout,
|
||||
const struct vk_pipeline_layout *layout,
|
||||
bool robust_buffer_access)
|
||||
{
|
||||
struct lower_descriptors_ctx ctx = {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "nvk_private.h"
|
||||
#include "nvk_device.h"
|
||||
#include "nvk_pipeline.h"
|
||||
#include "nvk_pipeline_layout.h"
|
||||
|
||||
#include "vk_pipeline_cache.h"
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#include "nvk_pipeline_layout.h"
|
||||
|
||||
#include "nvk_descriptor_set_layout.h"
|
||||
#include "nvk_device.h"
|
||||
|
||||
#include "util/mesa-sha1.h"
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
nvk_CreatePipelineLayout(VkDevice _device,
|
||||
const VkPipelineLayoutCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator,
|
||||
VkPipelineLayout *pPipelineLayout)
|
||||
{
|
||||
VK_FROM_HANDLE(nvk_device, device, _device);
|
||||
struct nvk_pipeline_layout *layout;
|
||||
|
||||
layout = vk_object_alloc(&device->vk, pAllocator, sizeof(*layout),
|
||||
VK_OBJECT_TYPE_PIPELINE_LAYOUT);
|
||||
if (layout == NULL)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
layout->num_sets = pCreateInfo->setLayoutCount;
|
||||
|
||||
uint8_t dynamic_buffer_count = 0;
|
||||
for (uint32_t s = 0; s < pCreateInfo->setLayoutCount; s++) {
|
||||
VK_FROM_HANDLE(nvk_descriptor_set_layout, set_layout,
|
||||
pCreateInfo->pSetLayouts[s]);
|
||||
vk_descriptor_set_layout_ref(&set_layout->vk);
|
||||
layout->set[s].layout = set_layout;
|
||||
layout->set[s].dynamic_buffer_start = dynamic_buffer_count;
|
||||
dynamic_buffer_count += set_layout->dynamic_buffer_count;
|
||||
}
|
||||
|
||||
struct mesa_sha1 sha1_ctx;
|
||||
_mesa_sha1_init(&sha1_ctx);
|
||||
_mesa_sha1_update(&sha1_ctx, &layout->num_sets, sizeof(layout->num_sets));
|
||||
for (uint32_t s = 0; s < pCreateInfo->setLayoutCount; s++) {
|
||||
_mesa_sha1_update(&sha1_ctx, layout->set[s].layout->sha1,
|
||||
sizeof(layout->set[s].layout->sha1));
|
||||
}
|
||||
_mesa_sha1_final(&sha1_ctx, layout->sha1);
|
||||
|
||||
*pPipelineLayout = nvk_pipeline_layout_to_handle(layout);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL
|
||||
nvk_DestroyPipelineLayout(VkDevice _device, VkPipelineLayout pipelineLayout,
|
||||
const VkAllocationCallbacks *pAllocator)
|
||||
{
|
||||
VK_FROM_HANDLE(nvk_device, device, _device);
|
||||
VK_FROM_HANDLE(nvk_pipeline_layout, layout, pipelineLayout);
|
||||
|
||||
if (!layout)
|
||||
return;
|
||||
|
||||
for (uint32_t s = 0; s < layout->num_sets; s++)
|
||||
vk_descriptor_set_layout_unref(&device->vk, &layout->set[s].layout->vk);
|
||||
|
||||
vk_object_free(&device->vk, pAllocator, layout);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef NVK_PIPELINE_LAYOUT
|
||||
#define NVK_PIPELINE_LAYOUT 1
|
||||
|
||||
#include "nvk_private.h"
|
||||
|
||||
#include "vulkan/runtime/vk_object.h"
|
||||
|
||||
struct nvk_descriptor_set_layout;
|
||||
|
||||
struct nvk_pipeline_layout {
|
||||
struct vk_object_base base;
|
||||
|
||||
unsigned char sha1[20];
|
||||
|
||||
uint32_t num_sets;
|
||||
|
||||
struct {
|
||||
struct nvk_descriptor_set_layout *layout;
|
||||
uint8_t dynamic_buffer_start;
|
||||
} set[NVK_MAX_SETS];
|
||||
};
|
||||
|
||||
VK_DEFINE_HANDLE_CASTS(nvk_pipeline_layout, base, VkPipelineLayout,
|
||||
VK_OBJECT_TYPE_PIPELINE_LAYOUT)
|
||||
|
||||
#endif
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "vulkan/runtime/vk_log.h"
|
||||
#include "vulkan/util/vk_alloc.h"
|
||||
#include "vulkan/util/vk_util.h"
|
||||
#include "vulkan/runtime/vk_pipeline_layout.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <xf86drm.h>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "nvk_device.h"
|
||||
#include "nvk_shader.h"
|
||||
#include "nvk_physical_device.h"
|
||||
#include "nvk_pipeline_layout.h"
|
||||
#include "nvk_nir.h"
|
||||
|
||||
#include "nouveau_bo.h"
|
||||
@@ -154,7 +153,7 @@ assign_io_locations(nir_shader *nir)
|
||||
|
||||
void
|
||||
nvk_lower_nir(struct nvk_device *device, nir_shader *nir,
|
||||
const struct nvk_pipeline_layout *layout)
|
||||
const struct vk_pipeline_layout *layout)
|
||||
{
|
||||
NIR_PASS(_, nir, nir_split_struct_vars, nir_var_function_temp);
|
||||
NIR_PASS(_, nir, nir_lower_vars_to_ssa);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
struct vk_shader_module;
|
||||
struct nvk_device;
|
||||
struct nvk_pipeline_layout;
|
||||
struct nvk_physical_device;
|
||||
|
||||
#define GF100_SHADER_HEADER_SIZE (20 * 4)
|
||||
@@ -75,7 +74,7 @@ nvk_physical_device_spirv_options(const struct nvk_physical_device *pdevice);
|
||||
|
||||
void
|
||||
nvk_lower_nir(struct nvk_device *device, nir_shader *nir,
|
||||
const struct nvk_pipeline_layout *layout);
|
||||
const struct vk_pipeline_layout *layout);
|
||||
|
||||
VkResult
|
||||
nvk_compile_nir(struct nvk_physical_device *device, nir_shader *nir,
|
||||
|
||||
Reference in New Issue
Block a user