Skip to content

Refactor vk::shader_source to accept raw bytes instead of the filepaths. #87

Description

@mrparmesan01

Context & Goal

Shader loading can be widely dependent on the user whether how they would like to handle fetching the shader byte code. The file I/O aspect is an implementation detail best left the responsible to the user.

This change involves removing internal code that automatically reads compiled SPIR-V binary files from disk:

compile_binary_shader_source(shader_src);

Proposing New API Changes

To provide a better flexibility with reading the bytes of the compiled shader code. It would be best to just past through the raw bytes themselves.

To provide better flexibility and eliminate internal file handling, the new vulkan-cpp wrapper APIs should accept the raw bytecode directly.

Originally Design:

struct shader_source {
    std::string filename;
    shader_stage stage = shader_stage::undefined;
};

New Design:

struct shader_source {
    shader_stage stage = shader_stage::undefined;
    std::span<const uint8_t> bytes_code;
};

Expected for Task Completion

The implementation is quite straightforward. Rather then vk::shader_resource_group automatically loading the .spv file and parsing binary code internally, this responsibility shifts entirely to the user in how they implement that logic.

Expected API Usage Example

// reads and returns the bytes of the shader code compiled.
std::vector<uint8_t> compiled_bytes = read_compiled_spv("shader.vert.spv");

std::array<vk::shader_source, 1> sources = {
    vk::shader_source{
        .stage = vk::shader_stage::vertex,
        .bytes_code = compiled_bytes,
    },
};

vk::shader_resource_group shader_resources(logical_device, sources);

shader_resources.vertex_attributes(...);

Metadata

Metadata

Assignees

No one assigned

    Labels

    💳 Tech DebtTasks that have some kind of user API tech debt📐designTasks that involve the core systems. Highly involve in API design.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions