mirror of
https://github.com/Yours3lf/rpi-vk-driver.git
synced 2025-01-18 10:52:14 +01:00
now we use vc4 BOs for swapchain, but it still doesn't work
This commit is contained in:
parent
773d06a0d2
commit
891c8a554e
@ -266,13 +266,13 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
|
||||
|
||||
int ret = openIoctl(); assert(!ret);
|
||||
|
||||
(*pInstance)->chipVersion = vc4_get_chip_info(renderFd);
|
||||
(*pInstance)->hasTiling = vc4_test_tiling(renderFd);
|
||||
(*pInstance)->chipVersion = vc4_get_chip_info(controlFd);
|
||||
(*pInstance)->hasTiling = vc4_test_tiling(controlFd);
|
||||
|
||||
(*pInstance)->hasControlFlow = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_BRANCHES);
|
||||
(*pInstance)->hasEtc1 = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_ETC1);
|
||||
(*pInstance)->hasThreadedFs = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_THREADED_FS);
|
||||
(*pInstance)->hasMadvise = vc4_has_feature(renderFd, DRM_VC4_PARAM_SUPPORTS_MADVISE);
|
||||
(*pInstance)->hasControlFlow = vc4_has_feature(controlFd, DRM_VC4_PARAM_SUPPORTS_BRANCHES);
|
||||
(*pInstance)->hasEtc1 = vc4_has_feature(controlFd, DRM_VC4_PARAM_SUPPORTS_ETC1);
|
||||
(*pInstance)->hasThreadedFs = vc4_has_feature(controlFd, DRM_VC4_PARAM_SUPPORTS_THREADED_FS);
|
||||
(*pInstance)->hasMadvise = vc4_has_feature(controlFd, DRM_VC4_PARAM_SUPPORTS_MADVISE);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@ -820,13 +820,18 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
|
||||
s->images[c].samples = 1; //TODO
|
||||
s->images[c].usageBits = pCreateInfo->imageUsage;
|
||||
|
||||
//TODO create this through VC4 instead (create BO)
|
||||
//would still need to point KMS to our BO
|
||||
//but hopefully the GPU could touch the buffer then
|
||||
//TODO determine pixel size from format
|
||||
//we only support RGBA8 with SRGB now
|
||||
uint32_t pixelSizeBytes = 4;
|
||||
s->images[c].size = pCreateInfo->imageExtent.width * pCreateInfo->imageExtent.height * pixelSizeBytes;
|
||||
s->images[c].stride = s->images[c].width * pixelSizeBytes;
|
||||
s->images[c].handle = vc4_bo_alloc(controlFd, s->images[c].size, "swapchain image"); assert(s->images[c].handle);
|
||||
int ret = vc4_bo_set_tiling(controlFd, s->images[c].handle, DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED); assert(ret);
|
||||
int res = modeset_create_fb(controlFd, &s->images[c]); assert(res == 0);
|
||||
}
|
||||
|
||||
int res = modeset_fb_for_dev(controlFd, s->surface, &s->images[s->backbufferIdx]); assert(res == 0);
|
||||
//defer to first swapbuffer (or at least later, getting swapchain != presenting immediately)
|
||||
//int res = modeset_fb_for_dev(controlFd, s->surface, &s->images[s->backbufferIdx]); assert(res == 0);
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@ -1523,7 +1528,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(
|
||||
uint64_t lastEmitSequno = 0; //TODO
|
||||
uint64_t lastFinishedSequno = 0;
|
||||
printf("submit ioctl\n");
|
||||
vc4_cl_submit(renderFd, &cmdbuf->submitCl, &lastEmitSequno, &lastFinishedSequno);
|
||||
vc4_cl_submit(controlFd, &cmdbuf->submitCl, &lastEmitSequno, &lastFinishedSequno);
|
||||
}
|
||||
|
||||
for(int c = 0; c < pSubmits->commandBufferCount; ++c)
|
||||
@ -1696,6 +1701,7 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
|
||||
|
||||
for(int c = 0; c < s->numImages; ++c)
|
||||
{
|
||||
vc4_bo_free(controlFd, s->images[c].handle, 0, s->images->size);
|
||||
modeset_destroy_fb(controlFd, &s->images[c]);
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,10 @@ int vc4_has_feature(int fd, uint32_t feature)
|
||||
int ret = drmIoctl(fd, DRM_IOCTL_VC4_GET_PARAM, &p);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("Couldn't determine if VC4 has feature: %s\n", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return p.value;
|
||||
}
|
||||
@ -158,6 +161,8 @@ int vc4_bo_set_tiling(int fd, uint32_t bo, uint64_t mod)
|
||||
&set_tiling);
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("Couldn't set tiling: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -182,7 +187,7 @@ void* vc4_bo_map_unsynchronized(int fd, uint32_t bo, uint32_t size)
|
||||
ret = drmIoctl(fd, DRM_IOCTL_VC4_MMAP_BO, &map);
|
||||
offset = map.offset;
|
||||
if (ret != 0) {
|
||||
printf("map ioctl failure\n");
|
||||
printf("Couldn't map unsync: %s\n", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -227,7 +232,8 @@ int vc4_bo_wait(int fd, uint32_t bo, uint64_t timeout_ns)
|
||||
int ret = vc4_bo_wait_ioctl(fd, bo, timeout_ns);
|
||||
if (ret) {
|
||||
if (ret != -ETIME) {
|
||||
printf("wait failed: %d\n", ret);
|
||||
printf("BO wait failed: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -269,7 +275,8 @@ int vc4_seqno_wait(int fd, uint64_t* lastFinishedSeqno, uint64_t seqno, uint64_t
|
||||
int ret = vc4_seqno_wait_ioctl(fd, seqno, timeout_ns);
|
||||
if (ret) {
|
||||
if (ret != -ETIME) {
|
||||
printf("wait failed: %d\n", ret);
|
||||
printf("Seqno wait failed: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -321,7 +328,8 @@ uint32_t vc4_bo_alloc_shader(int fd, const void *data, uint32_t* size)
|
||||
&create);
|
||||
|
||||
if (ret != 0) {
|
||||
printf("create shader ioctl failure\n");
|
||||
printf("Couldn't create shader: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -375,6 +383,9 @@ uint32_t vc4_bo_alloc(int fd, uint32_t size, const char *name)
|
||||
uint32_t handle = create.handle;
|
||||
|
||||
if (ret != 0) {
|
||||
printf("Couldn't alloc BO: %s\n",
|
||||
strerror(errno));
|
||||
|
||||
/*if (!list_empty(&screen->bo_cache.time_list) &&
|
||||
!cleared_and_retried) {
|
||||
cleared_and_retried = true;
|
||||
@ -426,7 +437,11 @@ int vc4_bo_unpurgeable(int fd, uint32_t bo, int hasMadvise)
|
||||
return 1;
|
||||
|
||||
if (drmIoctl(fd, DRM_IOCTL_VC4_GEM_MADVISE, &arg))
|
||||
{
|
||||
printf("Unpurgable BO madvise failed: %s\n",
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return arg.retained;
|
||||
}
|
||||
@ -443,7 +458,12 @@ void vc4_bo_purgeable(int fd, uint32_t bo, int hasMadvise)
|
||||
|
||||
if (hasMadvise)
|
||||
{
|
||||
drmIoctl(fd, DRM_IOCTL_VC4_GEM_MADVISE, &arg);
|
||||
int ret = drmIoctl(fd, DRM_IOCTL_VC4_GEM_MADVISE, &arg);
|
||||
if(ret)
|
||||
{
|
||||
printf("Purgable BO madvise failed: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -462,7 +482,12 @@ void vc4_bo_label(int fd, uint32_t bo, const char* name)
|
||||
.len = strlen(str),
|
||||
.name = (uintptr_t)str,
|
||||
};
|
||||
drmIoctl(fd, DRM_IOCTL_VC4_LABEL_BO, &label);
|
||||
int ret = drmIoctl(fd, DRM_IOCTL_VC4_LABEL_BO, &label);
|
||||
if(ret)
|
||||
{
|
||||
printf("BO label failed: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
int vc4_bo_get_dmabuf(int fd, uint32_t bo)
|
||||
@ -474,8 +499,8 @@ int vc4_bo_get_dmabuf(int fd, uint32_t bo)
|
||||
int ret = drmPrimeHandleToFD(fd, bo,
|
||||
O_CLOEXEC, &boFd);
|
||||
if (ret != 0) {
|
||||
printf("Failed to export gem bo %d to dmabuf\n",
|
||||
bo);
|
||||
printf("Failed to export gem bo %d to dmabuf: %s\n",
|
||||
bo, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -493,7 +518,7 @@ void* vc4_bo_map(int fd, uint32_t bo, uint32_t size)
|
||||
//wait infinitely
|
||||
int ok = vc4_bo_wait(fd, bo, WAIT_TIMEOUT_INFINITE);
|
||||
if (!ok) {
|
||||
printf("BO wait for map failed\n");
|
||||
printf("BO wait for map failed: %s\n", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,13 @@ extern "C" {
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
//normal nodes?
|
||||
//modesetting can be done
|
||||
#define DRM_IOCTL_CTRL_DEV_FILE_NAME "/dev/dri/card0"
|
||||
#define DRM_IOCTL_RENDER_DEV_FILE_NAME "/dev/dri/renderD128" //TODO does this need to be dynamic? (eg. iterate through renderDn?)
|
||||
|
||||
//render nodes
|
||||
//no modesetting --> so only for offscreen rendering
|
||||
#define DRM_IOCTL_RENDER_DEV_FILE_NAME "/dev/dri/renderD128"
|
||||
|
||||
#define WAIT_TIMEOUT_INFINITE 0xffffffffffffffffull
|
||||
#define ARM_PAGE_SIZE 4096
|
||||
|
@ -88,11 +88,12 @@ modeset_dev* modeset_create(int fd)
|
||||
struct modeset_dev *dev;
|
||||
int ret;
|
||||
|
||||
uint64_t has_dumb;
|
||||
//we'll use a buffer created by the vc4 kernel module instead
|
||||
/*uint64_t has_dumb;
|
||||
if (drmGetCap(fd, DRM_CAP_DUMB_BUFFER, &has_dumb) < 0 || !has_dumb) {
|
||||
printf("drm device does not support dumb buffers\n");
|
||||
return 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
// retrieve resources
|
||||
res = drmModeGetResources(fd);
|
||||
@ -317,13 +318,14 @@ static int modeset_find_crtc(int fd, drmModeRes *res, drmModeConnector *conn,
|
||||
|
||||
int modeset_create_fb(int fd, _image *buf)
|
||||
{
|
||||
struct drm_mode_create_dumb creq;
|
||||
struct drm_mode_destroy_dumb dreq;
|
||||
struct drm_mode_map_dumb mreq;
|
||||
//struct drm_mode_create_dumb creq;
|
||||
//struct drm_mode_destroy_dumb dreq;
|
||||
//struct drm_mode_map_dumb mreq;
|
||||
int ret;
|
||||
|
||||
//we'll use a buffer created by vc4 instead
|
||||
// create dumb buffer
|
||||
memset(&creq, 0, sizeof(creq));
|
||||
/*memset(&creq, 0, sizeof(creq));
|
||||
creq.width = buf->width;
|
||||
creq.height = buf->height;
|
||||
creq.bpp = 32;
|
||||
@ -335,7 +337,7 @@ int modeset_create_fb(int fd, _image *buf)
|
||||
}
|
||||
buf->stride = creq.pitch;
|
||||
buf->size = creq.size;
|
||||
buf->handle = creq.handle;
|
||||
buf->handle = creq.handle;*/
|
||||
|
||||
// create framebuffer object for the dumb-buffer
|
||||
ret = drmModeAddFB(fd, buf->width, buf->height, 24, 32, buf->stride,
|
||||
@ -345,9 +347,9 @@ int modeset_create_fb(int fd, _image *buf)
|
||||
errno);
|
||||
ret = -errno;
|
||||
|
||||
memset(&dreq, 0, sizeof(dreq));
|
||||
dreq.handle = buf->handle;
|
||||
drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||
//memset(&dreq, 0, sizeof(dreq));
|
||||
//dreq.handle = buf->handle;
|
||||
//drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -399,7 +401,7 @@ int modeset_create_fb(int fd, _image *buf)
|
||||
|
||||
void modeset_destroy_fb(int fd, _image* buf)
|
||||
{
|
||||
struct drm_mode_destroy_dumb dreq;
|
||||
//struct drm_mode_destroy_dumb dreq;
|
||||
|
||||
// unmap buffer
|
||||
//munmap(buf->map, buf->size);
|
||||
@ -408,9 +410,9 @@ void modeset_destroy_fb(int fd, _image* buf)
|
||||
drmModeRmFB(fd, buf->fb);
|
||||
|
||||
// delete dumb buffer
|
||||
memset(&dreq, 0, sizeof(dreq));
|
||||
/*memset(&dreq, 0, sizeof(dreq));
|
||||
dreq.handle = buf->handle;
|
||||
drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
||||
drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);*/
|
||||
}
|
||||
|
||||
/*
|
||||
@ -451,6 +453,11 @@ void modeset_present_buffer(int fd, modeset_dev* dev, _image* buffer)
|
||||
{
|
||||
//TODO use index!!
|
||||
|
||||
if(!dev->saved_crtc)
|
||||
{
|
||||
int res = modeset_fb_for_dev(fd, dev, buffer); assert(res == 0);
|
||||
}
|
||||
|
||||
struct modeset_dev *iter;
|
||||
//struct modeset_buf *buf;
|
||||
int ret;
|
||||
|
@ -16,13 +16,15 @@ extern "C" {
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
#include "CustomAssert.h"
|
||||
|
||||
typedef struct VkImage_T
|
||||
{
|
||||
uint32_t handle;
|
||||
uint32_t fb; //needed for swapchain
|
||||
uint32_t width, height, depth;
|
||||
uint32_t miplevels, layers, samples, size, stride;
|
||||
uint32_t miplevels, layers, samples, size;
|
||||
uint32_t stride; //the number of bytes from one row of pixels in memory to the next row of pixels in memory (aka pitch)
|
||||
uint32_t usageBits;
|
||||
} _image;
|
||||
|
||||
@ -38,6 +40,7 @@ typedef struct modeset_dev {
|
||||
drmModeCrtc *saved_crtc;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t handle;
|
||||
} modeset_dev;
|
||||
|
||||
modeset_dev* modeset_create(int fd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user