Add Android Vulkan backend (#2711)

Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
Adrian Cojocaru
2024-09-06 17:40:57 +03:00
committed by GitHub
parent 4b5d06d908
commit ea09bdf2b6
79 changed files with 2580 additions and 1400 deletions

View File

@@ -68,6 +68,7 @@ void main() {
// these transformations used to be applied in the JS and native code bases.
// moved them into the shader for clarity and simplicity.
float u_width = 1.0;
float halfwidth = u_width / 2.0;
float outset = halfwidth + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);

View File

@@ -17,7 +17,7 @@ struct ShaderSource<BuiltIn::BackgroundShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
layout(set = 0, binding = 1) uniform BackgroundDrawableUBO {
mat4 matrix;
@@ -61,7 +61,7 @@ struct ShaderSource<BuiltIn::BackgroundPatternShader, gfx::Backend::Type::Vulkan
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
layout(set = 0, binding = 1) uniform BackgroundPatternDrawableUBO {
mat4 matrix;

View File

@@ -17,7 +17,7 @@ struct ShaderSource<BuiltIn::CircleShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
#if !defined(HAS_UNIFORM_u_color)
layout(location = 1) in vec4 in_color;

View File

@@ -22,7 +22,7 @@ struct ShaderSource<BuiltIn::ClippingMaskProgram, gfx::Backend::Type::Vulkan> {
static constexpr std::array<TextureInfo, 0> textures{};
static constexpr auto vertex = R"(
layout(location = 0) in vec2 position;
layout(location = 0) in ivec2 position;
layout(push_constant) uniform constants {
mat4 matrix;

View File

@@ -17,10 +17,10 @@ struct ShaderSource<BuiltIn::CollisionBoxShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_anchor_position;
layout(location = 2) in vec2 in_extrude;
layout(location = 3) in vec2 in_placed;
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_anchor_position;
layout(location = 2) in ivec2 in_extrude;
layout(location = 3) in uvec2 in_placed;
layout(location = 4) in vec2 in_shift;
layout(set = 0, binding = 1) uniform CollisionBoxUBO {
@@ -98,10 +98,10 @@ struct ShaderSource<BuiltIn::CollisionCircleShader, gfx::Backend::Type::Vulkan>
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_anchor_position;
layout(location = 2) in vec2 in_extrude;
layout(location = 3) in vec2 in_placed;
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_anchor_position;
layout(location = 2) in ivec2 in_extrude;
layout(location = 3) in uvec2 in_placed;
layout(set = 0, binding = 1) uniform CollisionCircleUBO {
mat4 matrix;

View File

@@ -17,7 +17,7 @@ struct ShaderSource<BuiltIn::DebugShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
layout(set = 0, binding = 1) uniform DebugUBO {
mat4 matrix;
@@ -59,18 +59,5 @@ void main() {
)";
};
template <>
struct ShaderSource<BuiltIn::WideVectorShader, gfx::Backend::Type::Vulkan> {
static constexpr const char* name = "WideVectorShader";
static constexpr std::array<UniformBlockInfo, 0> uniforms{};
static constexpr std::array<AttributeInfo, 0> attributes{};
static constexpr std::array<AttributeInfo, 0> instanceAttributes{};
static constexpr std::array<TextureInfo, 0> textures{};
static constexpr auto vertex = R"()";
static constexpr auto fragment = R"()";
};
} // namespace shaders
} // namespace mbgl

View File

@@ -17,7 +17,7 @@ struct ShaderSource<BuiltIn::FillShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
#if !defined(HAS_UNIFORM_u_color)
layout(location = 1) in vec4 in_color;
@@ -110,7 +110,7 @@ struct ShaderSource<BuiltIn::FillOutlineShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
#if !defined(HAS_UNIFORM_u_outline_color)
layout(location = 1) in vec4 in_color;
@@ -216,14 +216,14 @@ struct ShaderSource<BuiltIn::FillPatternShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
#if !defined(HAS_UNIFORM_u_pattern_from)
layout(location = 1) in mediump vec4 in_pattern_from;
layout(location = 1) in mediump uvec4 in_pattern_from;
#endif
#if !defined(HAS_UNIFORM_u_pattern_to)
layout(location = 2) in mediump vec4 in_pattern_to;
layout(location = 2) in mediump uvec4 in_pattern_to;
#endif
#if !defined(HAS_UNIFORM_u_opacity)
@@ -411,14 +411,14 @@ struct ShaderSource<BuiltIn::FillOutlinePatternShader, gfx::Backend::Type::Vulka
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
#if !defined(HAS_UNIFORM_u_pattern_from)
layout(location = 1) in mediump vec4 in_pattern_from;
layout(location = 1) in mediump uvec4 in_pattern_from;
#endif
#if !defined(HAS_UNIFORM_u_pattern_to)
layout(location = 2) in mediump vec4 in_pattern_to;
layout(location = 2) in mediump uvec4 in_pattern_to;
#endif
#if !defined(HAS_UNIFORM_u_opacity)
@@ -615,8 +615,8 @@ struct ShaderSource<BuiltIn::FillOutlineTriangulatedShader, gfx::Backend::Type::
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_pos_normal;
layout(location = 1) in vec4 in_data;
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
layout(set = 0, binding = 1) uniform FillOutlineTriangulatedDrawableUBO {
mat4 matrix;
@@ -641,10 +641,12 @@ void main() {
// We store these in the least significant bit of in_pos_normal
mediump vec2 normal = in_pos_normal - 2.0 * pos;
frag_normal = vec2(normal.x, normal.y * 2.0 - 1.0);
frag_normal.y *= -1.0;
// these transformations used to be applied in the JS and native code bases.
// moved them into the shader for clarity and simplicity.
float halfwidth = drawable.width / 2.0;
float width = 1.0;
float halfwidth = width / 2.0;
float outset = halfwidth + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);
// Scale the extrusion vector down to a normal and then up by the line width
@@ -652,17 +654,15 @@ void main() {
mediump vec2 dist = outset * a_extrude * LINE_NORMAL_SCALE;
vec4 projected_extrude = drawable.matrix * vec4(dist / drawable.ratio, 0.0, 0.0);
gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0) + projected_extrude;
gl_Position = drawable.matrix * vec4(pos, 0.0, 1.0) + projected_extrude;
gl_Position.y *= -1.0;
// calculate how much the perspective view squishes or stretches the extrude
float extrude_length_without_perspective = length(dist);
float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * drawable.units_to_pixels);
frag_width = outset;
frag_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective
gl_Position.y *= -1.0;
float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * global.units_to_pixels);
frag_width2 = outset;
frag_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective;
}
)";
@@ -698,7 +698,7 @@ void main() {
const float blur2 = (1.0 / DEVICE_PIXEL_RATIO) * frag_gamma_scale;
const float alpha = clamp(min(dist + blur2, frag_width2 - dist) / blur2, 0.0, 1.0);
out_color = props.outline_color * (alpha * props.opacit));
out_color = props.outline_color * alpha * props.opacity;
}
)";
};
@@ -714,8 +714,8 @@ struct ShaderSource<BuiltIn::FillExtrusionShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec4 in_normal_ed;
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec4 in_normal_ed;
#if !defined(HAS_UNIFORM_u_color)
layout(location = 2) in vec4 in_color;
@@ -856,8 +856,8 @@ struct ShaderSource<BuiltIn::FillExtrusionPatternShader, gfx::Backend::Type::Vul
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec4 in_normal_ed;
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec4 in_normal_ed;
#if !defined(HAS_UNIFORM_u_base)
layout(location = 2) in vec2 in_base;
@@ -868,11 +868,11 @@ layout(location = 3) in vec2 in_height;
#endif
#if !defined(HAS_UNIFORM_u_pattern_from)
layout(location = 4) in vec4 in_pattern_from;
layout(location = 4) in uvec4 in_pattern_from;
#endif
#if !defined(HAS_UNIFORM_u_pattern_to)
layout(location = 5) in vec4 in_pattern_to;
layout(location = 5) in uvec4 in_pattern_to;
#endif
layout(set = 0, binding = 1) uniform FillExtrusionDrawableUBO {

View File

@@ -25,7 +25,7 @@ const float ZERO = 1.0 / 255.0 / 16.0;
// Gaussian kernel coefficient: 1 / sqrt(2 * PI)
#define GAUSS_COEF 0.3989422804014327
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
#if !defined(HAS_UNIFORM_u_weight)
layout(location = 1) in vec2 in_weight;
@@ -149,7 +149,7 @@ struct ShaderSource<BuiltIn::HeatmapTextureShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 0) in ivec2 in_position;
layout(set = 0, binding = 1) uniform HeatmapTexturePropsUBO {
mat4 matrix;

View File

@@ -17,8 +17,8 @@ struct ShaderSource<BuiltIn::HillshadePrepareShader, gfx::Backend::Type::Vulkan>
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_texture_position;
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_texture_position;
layout(set = 0, binding = 1) uniform HillshadePrepareDrawableUBO {
mat4 matrix;
@@ -135,8 +135,8 @@ struct ShaderSource<BuiltIn::HillshadeShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_texture_position;
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_texture_position;
layout(set = 0, binding = 1) uniform HillshadeDrawableUBO {
mat4 matrix;

View File

@@ -17,8 +17,8 @@ struct ShaderSource<BuiltIn::LineShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_pos_normal;
layout(location = 1) in vec4 in_data;
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
#if !defined(HAS_UNIFORM_u_color)
layout(location = 2) in vec4 in_color;
@@ -248,8 +248,8 @@ struct ShaderSource<BuiltIn::LineGradientShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_pos_normal;
layout(location = 1) in vec4 in_data;
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
#if !defined(HAS_UNIFORM_u_blur)
layout(location = 2) in vec2 in_blur;
@@ -466,8 +466,8 @@ struct ShaderSource<BuiltIn::LinePatternShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_pos_normal;
layout(location = 1) in vec4 in_data;
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
#if !defined(HAS_UNIFORM_u_blur)
layout(location = 2) in vec2 in_blur;
@@ -490,11 +490,11 @@ layout(location = 6) in vec2 in_width;
#endif
#if !defined(HAS_UNIFORM_u_pattern_from)
layout(location = 7) in vec4 in_pattern_from;
layout(location = 7) in uvec4 in_pattern_from;
#endif
#if !defined(HAS_UNIFORM_u_pattern_to)
layout(location = 8) in vec4 in_pattern_to;
layout(location = 8) in uvec4 in_pattern_to;
#endif
layout(set = 0, binding = 1) uniform LineDrawableUBO {
@@ -777,8 +777,8 @@ struct ShaderSource<BuiltIn::LineSDFShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_pos_normal;
layout(location = 1) in vec4 in_data;
layout(location = 0) in ivec2 in_pos_normal;
layout(location = 1) in uvec4 in_data;
#if !defined(HAS_UNIFORM_u_color)
layout(location = 2) in vec4 in_color;

View File

@@ -17,8 +17,8 @@ struct ShaderSource<BuiltIn::RasterShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_texture_position;
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec2 in_texture_position;
layout(set = 0, binding = 1) uniform RasterDrawableUBO {
mat4 matrix;

View File

@@ -17,9 +17,9 @@ struct ShaderSource<BuiltIn::SymbolIconShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec4 in_pos_offset;
layout(location = 1) in vec4 in_data;
layout(location = 2) in vec4 in_pixeloffset;
layout(location = 0) in ivec4 in_pos_offset;
layout(location = 1) in uvec4 in_data;
layout(location = 2) in ivec4 in_pixeloffset;
layout(location = 3) in vec3 in_projected_pos;
layout(location = 4) in float in_fade_opacity;
@@ -196,9 +196,9 @@ struct ShaderSource<BuiltIn::SymbolSDFIconShader, gfx::Backend::Type::Vulkan> {
static constexpr auto vertex = R"(
layout(location = 0) in vec4 in_pos_offset;
layout(location = 1) in vec4 in_data;
layout(location = 2) in vec4 in_pixeloffset;
layout(location = 0) in ivec4 in_pos_offset;
layout(location = 1) in uvec4 in_data;
layout(location = 2) in ivec4 in_pixeloffset;
layout(location = 3) in vec3 in_projected_pos;
layout(location = 4) in float in_fade_opacity;
@@ -496,8 +496,8 @@ struct ShaderSource<BuiltIn::SymbolTextAndIconShader, gfx::Backend::Type::Vulkan
#define SDF 1.0
#define ICON 0.0
layout(location = 0) in vec4 in_pos_offset;
layout(location = 1) in vec4 in_data;
layout(location = 0) in ivec4 in_pos_offset;
layout(location = 1) in uvec4 in_data;
layout(location = 2) in vec3 in_projected_pos;
layout(location = 3) in float in_fade_opacity;

View File

@@ -0,0 +1,173 @@
#pragma once
#include <mbgl/shaders/shader_source.hpp>
#include <mbgl/shaders/vulkan/shader_program.hpp>
namespace mbgl {
namespace shaders {
template <>
struct ShaderSource<BuiltIn::WideVectorShader, gfx::Backend::Type::Vulkan> {
static constexpr const char* name = "WideVectorShader";
static const std::array<UniformBlockInfo, 2> uniforms;
static const std::array<AttributeInfo, 3> attributes;
static const std::array<AttributeInfo, 4> instanceAttributes;
static constexpr std::array<TextureInfo, 0> textures{};
static constexpr auto vertex = R"(
/** Expressions are used to change values like width and opacity over zoom levels. **/
#define WKSExpStops 8
// Line Joins
// These are assumed to match WideVectorLineJoinType
#define WKSVertexLineJoinMiter 0
#define WKSVertexLineJoinBevel 1
#define WKSVertexLineJoinRound 2
#define WKSVertexLineJoinMiterClip 3
#define WKSVertexLineJoinMiterSimple 4
#define WKSVertexLineJoinNone 5
// Line Caps
// These are assumed to match WideVectorLineCapType
#define WKSVertexLineCapRound 0
#define WKSVertexLineCapButt 1
#define WKSVertexLineCapSquare 2
layout(set = 0, binding = 1) uniform WideVectorUniformsUBO {
mat4 mvpMatrix;
mat4 mvpMatrixDiff;
mat4 mvMatrix;
mat4 mvMatrixDiff;
mat4 pMatrix;
mat4 pMatrixDiff;
vec2 frameSize;
} uniforms;
layout(set = 0, binding = 2) uniform WideVectorUniformWideVecUBO {
vec4 color;
float w2;
float offset;
float edge;
float texRepeat;
vec4 texOffset;
float miterLimit;
int join;
int cap;
int hasExp;
float interClipLimit;
} wideVec;
struct IntersectInfo {
bool valid;
vec2 interPt;
float c;
float ta, tb;
};
// wedge product (2D cross product)
// if A ^ B > 0, A is to the right of B
float wedge(vec2 a, vec2 b) {
return a.x * b.y - a.y * b.x;
}
// Intersect two lines
IntersectInfo intersectLines(vec2 a0, vec2 a1, vec2 b0, vec2 b1)
{
const vec2 dA = a0 - a1;
const vec2 dB = b0 - b1;
// Solve the system of equations formed by equating the lines to get their common point.
const float denom = wedge(dA, dB);
if (denom == 0.0) {
// If the denominator comes out zero, the lines are parallel and do not intersect
return { .valid = false };
}
const float tA = wedge(a0, a1);
const float tB = wedge(b0, b1);
const vec2 inter = vec2((tA * dB.x - dA.x * tB), (tA * dB.y - dA.y * tB)) / denom;
return {
.valid = true,
.interPt = inter,
.ta = 0.0,
.tb = 0.0,
};
}
// Intersect two offset lines
IntersectInfo intersectWideLines(vec2 p0,vec2 p1,vec2 p2, vec2 n0,vec2 n1)
{
return intersectLines(p0 + n0, p1 + n0, p1 + n1, p2 + n1);
}
vec3 viewPos(const mat4 &mat, vec3 vec) {
const vec4 p = mat * vec4(vec, 1.0);
return p.xyz; // / p.w; ?
}
float2 screenPos_MVP(const Uniforms &u, float3 viewPos) {
const float4 p4 = float4(viewPos, 1.0);
// Use the MVP matrix
const float4 s = u.mvpMatrix * p4;
return s.xy / s.w;
}
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec4 in_color;
layout(location = 2) in int in_index;
layout(location = 3) in vec3 in_instance_center;
layout(location = 4) in vec4 in_instance_color;
layout(location = 5) in int in_instance_prev;
layout(location = 6) in int in_instance_next;
layout(location = 0) out vec2 frag_screenPos; // un-transformed vertex position
layout(location = 1) out vec2 frag_centerPos; // un-transformed circle center
layout(location = 2) out vec2 frag_midDir; // Turn direction
layout(location = 3) out vec4 frag_color;
layout(location = 4) out vec2 frag_texCoord;
layout(location = 5) out float frag_w2;
layout(location = 6) out float frag_edge;
layout(location = 7) out uvec2 frag_maskIDs;
layout(location = 8) out bool frag_roundJoin;
const float wideVecMinTurnThreshold = 1e-5;
const float wideVecMaxTurnThreshold = 0.99999998476; // sin(89.99 deg)
const int WideVecPolyStartGeom = 0;
const int WideVecPolyBodyGeom = 1;
const int WideVecPolyEndGeom = 2;
const vec4 discardPt = vec4(0,0,-1e6,NAN);
void main() {
}
)";
static constexpr auto fragment = R"(
layout(location = 0) in vec2 frag_uv;
layout(location = 0) out vec4 out_color;
layout(set = 0, binding = 1) uniform DebugUBO {
mat4 matrix;
vec4 color;
float overlay_scale;
float pad1, pad2, pad3;
} debug;
layout(set = 1, binding = 0) uniform sampler2D image_sampler;
void main() {
vec4 overlay_color = texture(image_sampler, frag_uv);
out_color = mix(debug.color, overlay_color, overlay_color.a);
}
)";
};
} // namespace shaders
} // namespace mbgl

View File

@@ -14,26 +14,17 @@ class Context;
struct BufferAllocation {
const VmaAllocator& allocator;
VmaAllocation allocation{};
VkBuffer buffer{};
vk::Buffer buffer{};
void* mappedBuffer{};
BufferAllocation() = delete;
BufferAllocation(BufferAllocation&) = delete;
BufferAllocation& operator=(const BufferAllocation& other) = delete;
BufferAllocation(BufferAllocation&& other) = default;
BufferAllocation(const VmaAllocator& allocator_)
: allocator(allocator_) {}
BufferAllocation(BufferAllocation&& other) noexcept
: allocator(other.allocator),
allocation(other.allocation),
buffer(other.buffer),
mappedBuffer(other.mappedBuffer) {
other.buffer = nullptr;
other.allocation = nullptr;
other.mappedBuffer = nullptr;
}
~BufferAllocation() { destroy(); }
bool create(const VmaAllocationCreateInfo& allocInfo, const vk::BufferCreateInfo& bufferInfo);
@@ -63,7 +54,7 @@ public:
const void* contents() const noexcept { return (raw.empty() ? nullptr : raw.data()); }
Context& getContext() const noexcept { return context; }
const VkBuffer& getVulkanBuffer() const noexcept { return bufferAllocation->buffer; }
const vk::Buffer& getVulkanBuffer() const noexcept { return bufferAllocation->buffer; }
std::size_t getVulkanBufferOffset() const noexcept;
std::size_t getVulkanBufferSize() const noexcept;

View File

@@ -54,6 +54,7 @@ public:
void beginFrame() override;
void endFrame() override;
void submitFrame();
void waitFrame() const;
std::unique_ptr<gfx::CommandEncoder> createCommandEncoder() override;
@@ -145,6 +146,8 @@ public:
void enqueueDeletion(std::function<void(const Context&)>&& function);
void submitOneTimeCommand(const std::function<void(const vk::UniqueCommandBuffer&)>& function);
void requestSurfaceUpdate() { surfaceUpdateRequested = true; }
private:
struct FrameResources {
vk::UniqueCommandBuffer commandBuffer;
@@ -189,6 +192,7 @@ private:
uint8_t frameResourceIndex = 0;
std::vector<FrameResources> frameResources;
bool surfaceUpdateRequested{false};
struct {
gfx::ShaderProgramBasePtr shader;

View File

@@ -82,8 +82,8 @@ public:
void updateVertexInputHash();
std::size_t hash() const;
void setDynamicValues(const vk::UniqueCommandBuffer& buffer) const;
std::vector<vk::DynamicState> getDynamicStates() const;
void setDynamicValues(const RendererBackend& backend, const vk::UniqueCommandBuffer& buffer) const;
std::vector<vk::DynamicState> getDynamicStates(const RendererBackend& backend) const;
protected:
std::size_t vertexInputHash{0};

View File

@@ -16,6 +16,11 @@ protected:
~RenderableResource() override = default;
public:
virtual void swap() {
// Renderable resources that require a swap function to be called
// explicitly can override this method.
}
const vk::Extent2D& getExtent() const { return extent; }
const vk::UniqueRenderPass& getRenderPass() const { return renderPass; }
virtual const vk::UniqueFramebuffer& getFramebuffer() const = 0;
@@ -34,10 +39,12 @@ protected:
~SurfaceRenderableResource() override;
void initColor(uint32_t w, uint32_t h);
void initSwapchain(uint32_t w, uint32_t h);
void initSwapchain(uint32_t w, uint32_t h, vk::PresentModeKHR presentMode = vk::PresentModeKHR::eFifo);
void initDepthStencil();
void swap() override;
public:
virtual void createPlatformSurface() = 0;
virtual std::vector<const char*> getDeviceExtensions() { return {}; }

View File

@@ -47,6 +47,7 @@ public:
uint32_t getMaxFrames() const { return maxFrames; }
const VmaAllocator& getAllocator() const { return allocator; }
const vk::PhysicalDeviceProperties& getDeviceProperties() const { return physicalDeviceProperties; }
const vk::PhysicalDeviceFeatures& getDeviceFeatures() const { return physicalDeviceFeatures; }
int32_t getGraphicsQueueIndex() const { return graphicsQueueIndex; }
int32_t getPresentQueueIndex() const { return presentQueueIndex; }
@@ -97,6 +98,7 @@ protected:
vk::PhysicalDevice physicalDevice;
vk::UniqueDevice device;
vk::PhysicalDeviceProperties physicalDeviceProperties;
vk::PhysicalDeviceFeatures physicalDeviceFeatures;
int32_t graphicsQueueIndex = -1;
int32_t presentQueueIndex = -1;

View File

@@ -15,25 +15,17 @@ class RenderPass;
struct ImageAllocation {
const VmaAllocator& allocator;
VmaAllocation allocation{};
VkImage image{};
vk::Image image{};
vk::UniqueImageView imageView{};
ImageAllocation() = delete;
ImageAllocation(ImageAllocation&) = delete;
ImageAllocation& operator=(const ImageAllocation& other) = delete;
ImageAllocation(ImageAllocation&& other) = default;
ImageAllocation(const VmaAllocator& allocator_)
: allocator(allocator_) {}
ImageAllocation(ImageAllocation&& other) noexcept
: allocator(other.allocator),
allocation(other.allocation),
image(other.image),
imageView(std::move(other.imageView)) {
other.image = nullptr;
other.allocation = nullptr;
}
~ImageAllocation() { destroy(); }
bool create(const VmaAllocationCreateInfo& allocInfo, const vk::ImageCreateInfo& imageInfo);