Igalia / vkrunner

A shader script tester for Vulkan. Moved to https://gitlab.freedesktop.org/mesa/vkrunner
Other
43 stars 14 forks source link

Request for buffer output #17

Closed dneto0 closed 6 years ago

dneto0 commented 6 years ago

I'd like to be able to use vkrunner in an edit/compile cycle when debugging a shader issue. What would be useful there is to be able to the resulting contents of a buffer after the pipeline is executed. It would be similar to -i command line option.

I think I would only need to look at the contents of one buffer. So I suggest the following:

bpeel commented 6 years ago

I had a go at implementing this. I took a slightly different approach. I’m not sure whether it makes sense to have a “save” command in the test script because it seems more like a script debugging utility so it is very different from the other commands. Instead I’ve just added the -b option which saves a buffer to the given file after the test section completes (the same as for the -i option). You can specify a particular buffer using the -B option to tell it the buffer’s binding number.

For the API, instead of adding a save_buffer callback, I’ve added a general inspect callback which is invoked after a test is run. It has a pointer to a structure which is meant to be a place to store all sorts of information. Currently it contains pointers to the color buffer and a struct for each buffer that the script uses. This is also enough to move the image saving code into the application instead of having an option on vr_config. Hopefully this will also make it easier to integrate with CTS if it wants to save the images in the XML file or something.

The API now looks like this:

struct vr_inspect_image {
        /* Dimensions of the buffer */
        int width, height;
        /* The stride in pixels from one row of the image to the next */
        size_t stride;
        /* An opaque pointer describing the format of each pixel in
         * the buffer
         */
        const struct vr_format *format;
        /* The buffer data */
        const void *data;
};

struct vr_inspect_buffer {
        /* The binding number of the buffer */
        int binding;
        /* Size in bytes of the buffer */
        size_t size;
        /* The buffer data */
        const void *data;
};

struct vr_inspect_data {
        /* The color buffer */
        struct vr_inspect_image color_buffer;
        /* An array of buffers used as UBOs or SSBOs */
        size_t n_buffers;
        const struct vr_inspect_buffer *buffers;
};

typedef void
(* vr_config_inspect_cb)(const struct vr_inspect_data *inspect_data,
                         void *user_data);

/* Sets a callback to invoke after the commands in the test section
 * have run. It is not invoked if the test fails before the test
 * section is reached. The application can use the inspect struct to
 * query the buffers used by the test.
 */
void
vr_config_set_inspect_cb(struct vr_config *config,
                         vr_config_inspect_cb inspect_cb);

The implementation is on a branch here. If you have any comments on this approach I’d be happy to hear them.