Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Commit

Permalink
Implement cmd buffer stub further.
Browse files Browse the repository at this point in the history
  • Loading branch information
abergmeier committed Nov 29, 2019
1 parent 3f2bdbe commit 1799d4a
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 120 deletions.
1 change: 1 addition & 0 deletions src/broadcom/vulkan/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_fence, VkFence)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_framebuffer, VkFramebuffer)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_image, VkImage)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_image_view, VkImageView)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_pipeline, VkPipeline)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_pipeline_cache, VkPipelineCache)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_pipeline_layout, VkPipelineLayout)
V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_query_pool, VkQueryPool)
Expand Down
1 change: 0 additions & 1 deletion src/broadcom/vulkan/genv3dvk_cmd_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <vulkan/vulkan.h>
// Needs to be in front to define certain symbols
#include "v3d_cl.h"
#define V3D_VERSION 42
#include "cle/v3dx_pack.h"
#include "common.h"
#include "v3dvk_cmd_buffer.h"
Expand Down
10 changes: 10 additions & 0 deletions src/broadcom/vulkan/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ struct v3dvk_app_info {
uint32_t api_version;
};

enum v3dvk_debug_flags
{
V3DVK_DEBUG_STARTUP = 1 << 0,
V3DVK_DEBUG_NIR = 1 << 1,
V3DVK_DEBUG_IR3 = 1 << 2,
V3DVK_DEBUG_PERF = 1 << 8,
};

struct v3dvk_instance {
VK_LOADER_DATA _loader_data;

Expand All @@ -55,6 +63,8 @@ struct v3dvk_instance {

bool pipeline_cache_enabled;

enum v3dvk_debug_flags debug_flags;

struct vk_debug_report_instance debug_report_callbacks;
};

Expand Down
2 changes: 2 additions & 0 deletions src/broadcom/vulkan/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ libv3dvk_files = files(
'instance.h',
'ioctl.h',
'valgrind.h',
'v3d_cl.c',
'v3dvk_bo.c',
'v3dvk_cmd_buffer.c',
'v3dvk_cmd_pool.c',
Expand All @@ -100,6 +101,7 @@ libv3dvk_files = files(
'v3dvk_formats.c',
'v3dvk_gem.c',
'v3dvk_image.c',
'v3dvk_log.c',
'v3dvk_memory.c',
'v3dvk_physical_device.c',
'v3dvk_pipeline_cache.c',
Expand Down
47 changes: 47 additions & 0 deletions src/broadcom/vulkan/v3d_cl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#include "device.h"
#include "v3d_cl.inl"
#include "common/v3d_macros.h"
#include "cle/v3d_packet_v42_pack.h"
#include "vk_alloc.h"

void
v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t space)
{
if (cl_offset(cl) + space + cl_packet_length(BRANCH) <= cl->size)
return;

struct v3dvk_bo *new_bo = vk_alloc2(&cl->dev->alloc, NULL, sizeof(*new_bo), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);

if (!new_bo)
return; // FIXME: Handle this properly

new_bo->name = "CL";

VkResult result = v3dvk_bo_init_new(cl->dev, new_bo, space);
if (result != VK_SUCCESS) {
// FIXME: Properly handle this
assert(false);
}

assert(space <= new_bo->size);

/* Chain to the new BO from the old one. */
if (cl->bo) {
cl_emit(cl, BRANCH, branch) {
branch.address = cl_address(new_bo, 0);
}
#if 0
v3d_bo_unreference(&cl->bo);
#endif
} else {
/* Root the first RCL/BCL BO in the job. */
v3dvk_cmd_buffer_add_bo(cl->cmd, cl->bo);
}

cl->bo = new_bo;
cl->base = v3dvk_bo_map(cl->bo);
cl->size = cl->bo->size;
cl->next = cl->base;
}
80 changes: 23 additions & 57 deletions src/broadcom/vulkan/v3d_cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
#define VC5_CL_H

#include <stdint.h>
#include "v3dvk_bo.h"

#define V3D_VERSION 42

#include "broadcom/cle/v3d_packet_helpers.h"


struct v3dvk_bo;
struct v3d_job;
struct v3d_cl;
struct v3dvk_device;

/**
* Undefined structure, used for typechecking that you're passing the pointers
Expand All @@ -45,67 +48,47 @@ struct v3d_cl_reloc {
uint32_t offset;
};

static inline struct v3d_cl_reloc
__unpack_address(const uint8_t *cl, uint32_t s, uint32_t e)
{
struct v3d_cl_reloc reloc =
{ NULL, __gen_unpack_uint(cl, s, e) << (31 - (e - s)) };
return reloc;
}

static inline void cl_pack_emit_reloc(struct v3d_cl *cl, const struct v3d_cl_reloc *);

#define __gen_user_data struct v3d_cl
#define __gen_address_type struct v3d_cl_reloc
#define __gen_address_offset(reloc) (((reloc)->bo ? (reloc)->bo->offset : 0) + \
(reloc)->offset)
#define __gen_emit_reloc cl_pack_emit_reloc
#define __gen_unpack_address(cl, s, e) __unpack_address(cl, s, e)

struct v3d_cl {
void *base;
struct v3d_job *job;
struct v3dvk_device *dev;
struct v3dvk_cmd_buffer *cmd;
struct v3d_cl_out *next;
struct v3dvk_bo *bo;
uint32_t size;
};


static inline uint32_t cl_offset(struct v3d_cl *cl)
{
return (char *)cl->next - (char *)cl->base;
}

static inline void
cl_advance(struct v3d_cl_out **cl, uint32_t n)
{
(*cl) = (struct v3d_cl_out *)((char *)(*cl) + n);
}

static inline struct v3d_cl_out *
cl_start(struct v3d_cl *cl)
{
return cl->next;
}

static inline void
cl_end(struct v3d_cl *cl, struct v3d_cl_out *next)
{
cl->next = next;
assert(cl_offset(cl) <= cl->size);
}

/**
* Reference to a BO with its associated offset, used in the pack process.
*/
static inline struct v3d_cl_reloc
cl_address(struct v3dvk_bo *bo, uint32_t offset)
{
struct v3d_cl_reloc reloc = {
.bo = bo,
.offset = offset,
};
return reloc;
}

void v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t size);

#define cl_packet_header(packet) V3DX(packet ## _header)
#define cl_packet_length(packet) V3DX(packet ## _length)
#define cl_packet_pack(packet) V3DX(packet ## _pack)
#define cl_packet_struct(packet) V3DX(packet)

static void
cl_advance(struct v3d_cl_out **cl, uint32_t n);
static struct v3d_cl_out *
cl_start(struct v3d_cl *cl);
static void
cl_end(struct v3d_cl *cl, struct v3d_cl_out *next);


/* Macro for setting up an emit of a CL struct. A temporary unpacked struct
* is created, which you get to set fields in of the form:
*
Expand Down Expand Up @@ -134,21 +117,4 @@ void v3d_cl_ensure_space_with_branch(struct v3d_cl *cl, uint32_t size);
_loop_terminate = NULL; \
}))

void v3d_job_add_bo(struct v3d_job *job, struct v3dvk_bo *bo);

/**
* Helper function called by the XML-generated pack functions for filling in
* an address field in shader records.
*
* Since we have a private address space as of VC5, our BOs can have lifelong
* offsets, and all the kernel needs to know is which BOs need to be paged in
* for this exec.
*/
static inline void
cl_pack_emit_reloc(struct v3d_cl *cl, const struct v3d_cl_reloc *reloc)
{
if (reloc->bo)
v3d_job_add_bo(cl->job, reloc->bo);
}

#endif /* VC5_CL_H */
55 changes: 55 additions & 0 deletions src/broadcom/vulkan/v3d_cl.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

#include "v3d_cl.h"
#include "v3dvk_cmd_buffer.h"

static inline uint32_t cl_offset(struct v3d_cl *cl)
{
return (char *)cl->next - (char *)cl->base;
}

static inline void
cl_advance(struct v3d_cl_out **cl, uint32_t n)
{
(*cl) = (struct v3d_cl_out *)((char *)(*cl) + n);
}

static inline struct v3d_cl_out *
cl_start(struct v3d_cl *cl)
{
return cl->next;
}

static inline void
cl_end(struct v3d_cl *cl, struct v3d_cl_out *next)
{
cl->next = next;
assert(cl_offset(cl) <= cl->size);
}

/**
* Reference to a BO with its associated offset, used in the pack process.
*/
static inline struct v3d_cl_reloc
cl_address(struct v3dvk_bo *bo, uint32_t offset)
{
struct v3d_cl_reloc reloc = {
.bo = bo,
.offset = offset,
};
return reloc;
}

/**
* Helper function called by the XML-generated pack functions for filling in
* an address field in shader records.
*
* Since we have a private address space as of VC5, our BOs can have lifelong
* offsets, and all the kernel needs to know is which BOs need to be paged in
* for this exec.
*/
static inline void
cl_pack_emit_reloc(struct v3d_cl *cl, const struct v3d_cl_reloc *reloc)
{
if (reloc->bo)
v3dvk_cmd_buffer_add_bo(cl->cmd, reloc->bo);
}
Loading

0 comments on commit 1799d4a

Please sign in to comment.