5 Commits

Author SHA1 Message Date
db299c6930 Indev (#202) 2026-02-03 12:10:08 +01:00
ebfc00d015 fixing put pixel resize issue (#201) 2026-02-03 12:05:37 +01:00
7639c27df4 fixing put pixel resize issue 2026-02-03 11:58:06 +01:00
2d9f193a72 Bump actions/checkout from 5 to 6 (#200)
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to
6.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/releases">actions/checkout's
releases</a>.</em></p>
<blockquote>
<h2>v6.0.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Update README to include Node.js 24 support details and requirements
by <a href="https://github.com/salmanmkc"><code>@​salmanmkc</code></a>
in <a
href="https://redirect.github.com/actions/checkout/pull/2248">actions/checkout#2248</a></li>
<li>Persist creds to a separate file by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2286">actions/checkout#2286</a></li>
<li>v6-beta by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2298">actions/checkout#2298</a></li>
<li>update readme/changelog for v6 by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2311">actions/checkout#2311</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/checkout/compare/v5.0.0...v6.0.0">https://github.com/actions/checkout/compare/v5.0.0...v6.0.0</a></p>
<h2>v6-beta</h2>
<h2>What's Changed</h2>
<p>Updated persist-credentials to store the credentials under
<code>$RUNNER_TEMP</code> instead of directly in the local git
config.</p>
<p>This requires a minimum Actions Runner version of <a
href="https://github.com/actions/runner/releases/tag/v2.329.0">v2.329.0</a>
to access the persisted credentials for <a
href="https://docs.github.com/en/actions/tutorials/use-containerized-services/create-a-docker-container-action">Docker
container action</a> scenarios.</p>
<h2>v5.0.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Port v6 cleanup to v5 by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2301">actions/checkout#2301</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/checkout/compare/v5...v5.0.1">https://github.com/actions/checkout/compare/v5...v5.0.1</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/blob/main/CHANGELOG.md">actions/checkout's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<h2>v6.0.2</h2>
<ul>
<li>Fix tag handling: preserve annotations and explicit fetch-tags by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2356">actions/checkout#2356</a></li>
</ul>
<h2>v6.0.1</h2>
<ul>
<li>Add worktree support for persist-credentials includeIf by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2327">actions/checkout#2327</a></li>
</ul>
<h2>v6.0.0</h2>
<ul>
<li>Persist creds to a separate file by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2286">actions/checkout#2286</a></li>
<li>Update README to include Node.js 24 support details and requirements
by <a href="https://github.com/salmanmkc"><code>@​salmanmkc</code></a>
in <a
href="https://redirect.github.com/actions/checkout/pull/2248">actions/checkout#2248</a></li>
</ul>
<h2>v5.0.1</h2>
<ul>
<li>Port v6 cleanup to v5 by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2301">actions/checkout#2301</a></li>
</ul>
<h2>v5.0.0</h2>
<ul>
<li>Update actions checkout to use node 24 by <a
href="https://github.com/salmanmkc"><code>@​salmanmkc</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2226">actions/checkout#2226</a></li>
</ul>
<h2>v4.3.1</h2>
<ul>
<li>Port v6 cleanup to v4 by <a
href="https://github.com/ericsciple"><code>@​ericsciple</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2305">actions/checkout#2305</a></li>
</ul>
<h2>v4.3.0</h2>
<ul>
<li>docs: update README.md by <a
href="https://github.com/motss"><code>@​motss</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1971">actions/checkout#1971</a></li>
<li>Add internal repos for checking out multiple repositories by <a
href="https://github.com/mouismail"><code>@​mouismail</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1977">actions/checkout#1977</a></li>
<li>Documentation update - add recommended permissions to Readme by <a
href="https://github.com/benwells"><code>@​benwells</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2043">actions/checkout#2043</a></li>
<li>Adjust positioning of user email note and permissions heading by <a
href="https://github.com/joshmgross"><code>@​joshmgross</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2044">actions/checkout#2044</a></li>
<li>Update README.md by <a
href="https://github.com/nebuk89"><code>@​nebuk89</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2194">actions/checkout#2194</a></li>
<li>Update CODEOWNERS for actions by <a
href="https://github.com/TingluoHuang"><code>@​TingluoHuang</code></a>
in <a
href="https://redirect.github.com/actions/checkout/pull/2224">actions/checkout#2224</a></li>
<li>Update package dependencies by <a
href="https://github.com/salmanmkc"><code>@​salmanmkc</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/2236">actions/checkout#2236</a></li>
</ul>
<h2>v4.2.2</h2>
<ul>
<li><code>url-helper.ts</code> now leverages well-known environment
variables by <a href="https://github.com/jww3"><code>@​jww3</code></a>
in <a
href="https://redirect.github.com/actions/checkout/pull/1941">actions/checkout#1941</a></li>
<li>Expand unit test coverage for <code>isGhes</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1946">actions/checkout#1946</a></li>
</ul>
<h2>v4.2.1</h2>
<ul>
<li>Check out other refs/* by commit if provided, fall back to ref by <a
href="https://github.com/orhantoy"><code>@​orhantoy</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1924">actions/checkout#1924</a></li>
</ul>
<h2>v4.2.0</h2>
<ul>
<li>Add Ref and Commit outputs by <a
href="https://github.com/lucacome"><code>@​lucacome</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1180">actions/checkout#1180</a></li>
<li>Dependency updates by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a>- <a
href="https://redirect.github.com/actions/checkout/pull/1777">actions/checkout#1777</a>,
<a
href="https://redirect.github.com/actions/checkout/pull/1872">actions/checkout#1872</a></li>
</ul>
<h2>v4.1.7</h2>
<ul>
<li>Bump the minor-npm-dependencies group across 1 directory with 4
updates by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1739">actions/checkout#1739</a></li>
<li>Bump actions/checkout from 3 to 4 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1697">actions/checkout#1697</a></li>
<li>Check out other refs/* by commit by <a
href="https://github.com/orhantoy"><code>@​orhantoy</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1774">actions/checkout#1774</a></li>
<li>Pin actions/checkout's own workflows to a known, good, stable
version. by <a href="https://github.com/jww3"><code>@​jww3</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1776">actions/checkout#1776</a></li>
</ul>
<h2>v4.1.6</h2>
<ul>
<li>Check platform to set archive extension appropriately by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1732">actions/checkout#1732</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="8e8c483db8"><code>8e8c483</code></a>
Clarify v6 README (<a
href="https://redirect.github.com/actions/checkout/issues/2328">#2328</a>)</li>
<li><a
href="033fa0dc0b"><code>033fa0d</code></a>
Add worktree support for persist-credentials includeIf (<a
href="https://redirect.github.com/actions/checkout/issues/2327">#2327</a>)</li>
<li><a
href="c2d88d3ecc"><code>c2d88d3</code></a>
Update all references from v5 and v4 to v6 (<a
href="https://redirect.github.com/actions/checkout/issues/2314">#2314</a>)</li>
<li><a
href="1af3b93b68"><code>1af3b93</code></a>
update readme/changelog for v6 (<a
href="https://redirect.github.com/actions/checkout/issues/2311">#2311</a>)</li>
<li><a
href="71cf2267d8"><code>71cf226</code></a>
v6-beta (<a
href="https://redirect.github.com/actions/checkout/issues/2298">#2298</a>)</li>
<li><a
href="069c695914"><code>069c695</code></a>
Persist creds to a separate file (<a
href="https://redirect.github.com/actions/checkout/issues/2286">#2286</a>)</li>
<li><a
href="ff7abcd0c3"><code>ff7abcd</code></a>
Update README to include Node.js 24 support details and requirements (<a
href="https://redirect.github.com/actions/checkout/issues/2248">#2248</a>)</li>
<li>See full diff in <a
href="https://github.com/actions/checkout/compare/v5...v6">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=5&new-version=6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>
2026-02-03 07:08:13 +01:00
dependabot[bot]
6aac4a71de Bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-03 03:49:46 +00:00
7 changed files with 175 additions and 22 deletions

View File

@@ -19,7 +19,7 @@ jobs:
matrix: matrix:
platform: ['x64', 'x86'] platform: ['x64', 'x86']
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
@@ -52,7 +52,7 @@ jobs:
CC: clang-cl CC: clang-cl
CXX: clang-cl CXX: clang-cl
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
@@ -75,7 +75,7 @@ jobs:
matrix: matrix:
platform: ['UCRT64', 'CLANG64'] platform: ['UCRT64', 'CLANG64']
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0

View File

@@ -44,11 +44,16 @@ void update(void* param)
mlx_set_font(mlx->mlx, "default"); mlx_set_font(mlx->mlx, "default");
mlx_string_put(mlx->mlx, mlx->win, 20, 50, (mlx_color){ .rgba = 0xFFFFFFFF }, "that's a text"); mlx_string_put(mlx->mlx, mlx->win, 20, 50, (mlx_color){ .rgba = 0xFFFFFFFF }, "that's a text");
int win_width;
int win_height;
mlx_get_window_size(mlx->mlx, mlx->win, &win_width, &win_height);
uint32_t color = 0; uint32_t color = 0;
for(int j = 0; j < 400; j++) for(int j = 0; j < win_height; j++)
{ {
mlx_pixel_put(mlx->mlx, mlx->win, j, j, (mlx_color){ .rgba = 0x0000FFFF + (color << 24) }); mlx_pixel_put(mlx->mlx, mlx->win, j, j, (mlx_color){ .rgba = 0x0000FFFF + (color << 24) });
mlx_pixel_put(mlx->mlx, mlx->win, 399 - j, j, (mlx_color){ .rgba = 0x0000FFFF }); mlx_pixel_put(mlx->mlx, mlx->win, win_width - j, j, (mlx_color){ .rgba = 0x0000FFFF });
color += (color < 255); color += (color < 255);
} }

View File

@@ -8,7 +8,7 @@ namespace mlx
class PutPixelManager class PutPixelManager
{ {
public: public:
PutPixelManager(NonOwningPtr<class Renderer> renderer) : p_renderer(renderer) {} PutPixelManager(NonOwningPtr<class Renderer> renderer);
// Returns a valid pointer when a new texture has been created // Returns a valid pointer when a new texture has been created
NonOwningPtr<Texture> DrawPixel(int x, int y, std::uint64_t draw_layer, mlx_color color); NonOwningPtr<Texture> DrawPixel(int x, int y, std::uint64_t draw_layer, mlx_color color);
@@ -20,6 +20,7 @@ namespace mlx
private: private:
NonOwningPtr<Texture> GetLayer(std::uint64_t draw_layer, bool& is_newlayer); NonOwningPtr<Texture> GetLayer(std::uint64_t draw_layer, bool& is_newlayer);
std::unique_ptr<Texture> NewTexture();
private: private:
std::unordered_map<std::uint64_t, NonOwningPtr<Texture>> m_placements; std::unordered_map<std::uint64_t, NonOwningPtr<Texture>> m_placements;

View File

@@ -89,7 +89,13 @@ namespace mlx
mlx_color GetPixel(int x, int y) noexcept; mlx_color GetPixel(int x, int y) noexcept;
void GetRegion(int x, int y, int w, int h, mlx_color* dst) noexcept; void GetRegion(int x, int y, int w, int h, mlx_color* dst) noexcept;
void Clear(VkCommandBuffer cmd, Vec4f color) override; void Clear(VkCommandBuffer cmd, Vec4f color) override;
void CopyTo(Texture& other);
void Resize(std::uint32_t width, std::uint32_t height);
void Swap(Texture& texture) noexcept;
// If a valid cmd buffer is passed, this function takes ownership and makes it invalid after
void SyncCPUBuffer(VkCommandBuffer cmd = VK_NULL_HANDLE);
void Update(VkCommandBuffer cmd); void Update(VkCommandBuffer cmd);
~Texture() override { Destroy(); } ~Texture() override { Destroy(); }

View File

@@ -6,6 +6,29 @@
namespace mlx namespace mlx
{ {
PutPixelManager::PutPixelManager(NonOwningPtr<class Renderer> renderer) : p_renderer(renderer)
{
MLX_PROFILE_FUNCTION();
std::function<void(const EventBase&)> functor = [this](const EventBase& event)
{
// Suboptimal for multi-windows applications
if(event.What() == Event::ResizeEventCode)
{
VkExtent2D extent{ .width = 0, .height = 0 };
if(p_renderer->GetWindow())
extent = kvfGetSwapchainImagesSize(p_renderer->GetSwapchain().Get());
else if(p_renderer->GetRenderTarget())
extent = VkExtent2D{ .width = p_renderer->GetRenderTarget()->GetWidth(), .height = p_renderer->GetRenderTarget()->GetHeight() };
else
FatalError("a renderer was created without window nor render target attached (wtf!?)");
for(auto& texture : m_textures)
texture->Resize(extent.width, extent.height);
}
};
EventBus::RegisterListener({ functor, "mlx_put_pixel_manager_" + std::to_string(reinterpret_cast<std::uintptr_t>(this)) });
}
NonOwningPtr<Texture> PutPixelManager::DrawPixel(int x, int y, std::uint64_t draw_layer, mlx_color color) NonOwningPtr<Texture> PutPixelManager::DrawPixel(int x, int y, std::uint64_t draw_layer, mlx_color color)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
@@ -53,21 +76,8 @@ namespace mlx
is_newlayer = true; is_newlayer = true;
if(m_current_texture_index >= m_textures.size()) if(m_current_texture_index >= m_textures.size())
{ m_textures.push_back(NewTexture());
VkExtent2D extent{ .width = 0, .height = 0 };
if(p_renderer->GetWindow())
extent = kvfGetSwapchainImagesSize(p_renderer->GetSwapchain().Get());
else if(p_renderer->GetRenderTarget())
extent = VkExtent2D{ .width = p_renderer->GetRenderTarget()->GetWidth(), .height = p_renderer->GetRenderTarget()->GetHeight() };
else
FatalError("a renderer was created without window nor render target attached (wtf)");
#ifdef DEBUG
m_textures.push_back(std::make_unique<Texture>(CPUBuffer{}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_put_pixel_layer_" + std::to_string(m_current_texture_index)));
#else
m_textures.push_back(std::make_unique<Texture>(CPUBuffer{}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, std::string_view{}));
#endif
}
try try
{ {
m_placements[draw_layer] = m_textures.at(m_current_texture_index).get(); m_placements[draw_layer] = m_textures.at(m_current_texture_index).get();
@@ -83,6 +93,23 @@ namespace mlx
} }
} }
std::unique_ptr<Texture> PutPixelManager::NewTexture()
{
VkExtent2D extent{ .width = 0, .height = 0 };
if(p_renderer->GetWindow())
extent = kvfGetSwapchainImagesSize(p_renderer->GetSwapchain().Get());
else if(p_renderer->GetRenderTarget())
extent = VkExtent2D{ .width = p_renderer->GetRenderTarget()->GetWidth(), .height = p_renderer->GetRenderTarget()->GetHeight() };
else
FatalError("a renderer was created without window nor render target attached (wtf!?)");
#ifdef DEBUG
return std::make_unique<Texture>(CPUBuffer{}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_put_pixel_layer_" + std::to_string(m_current_texture_index));
#else
return std::make_unique<Texture>(CPUBuffer{}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, std::string_view{});
#endif
}
void PutPixelManager::ResetRenderData() void PutPixelManager::ResetRenderData()
{ {
m_placements.clear(); m_placements.clear();

View File

@@ -24,7 +24,7 @@
namespace mlx namespace mlx
{ {
mlx_color ReverseColor(mlx_color color) MLX_FORCEINLINE mlx_color ReverseColor(mlx_color color)
{ {
mlx_color reversed_color; mlx_color reversed_color;
reversed_color.r = color.a; reversed_color.r = color.a;
@@ -362,8 +362,16 @@ namespace mlx
m_staging_buffer->Init(BufferType::Staging, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, {}, {}); m_staging_buffer->Init(BufferType::Staging, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, {}, {});
#endif #endif
SyncCPUBuffer();
}
void Texture::SyncCPUBuffer(VkCommandBuffer cmd)
{
if(!m_staging_buffer.has_value())
return;
VkImageLayout old_layout = m_layout; VkImageLayout old_layout = m_layout;
VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice()); if(cmd == VK_NULL_HANDLE)
cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, cmd); TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, cmd);
kvfCopyImageToBuffer(cmd, m_staging_buffer->Get(), m_image, m_staging_buffer->GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { m_width, m_height, 1 }); kvfCopyImageToBuffer(cmd, m_staging_buffer->Get(), m_image, m_staging_buffer->GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { m_width, m_height, 1 });
@@ -375,6 +383,98 @@ namespace mlx
kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd); kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd);
} }
void Texture::CopyTo(Texture& other)
{
VkImageLayout old_layout = m_layout;
VkImageLayout other_old_layout = other.GetLayout();
VkImageSubresourceLayers subresource{};
subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subresource.mipLevel = 0;
subresource.layerCount = 1;
subresource.baseArrayLayer = 0;
VkExtent3D extent{};
extent.width = m_width;
extent.height = m_height;
extent.depth = 1;
VkOffset3D offset{};
offset.x = 0;
offset.y = 0;
offset.z = 0;
VkImageCopy region{};
region.srcSubresource = subresource;
region.dstSubresource = subresource;
region.extent = extent;
region.srcOffset = offset;
region.dstOffset = offset;
VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, cmd);
other.TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
kvfCopyImageToImage(cmd, m_image, m_layout, other.Get(), other.GetLayout(), 1, &region);
TransitionLayout(old_layout, cmd);
other.TransitionLayout(other_old_layout, cmd);
kvfEndCommandBuffer(cmd);
SyncCPUBuffer(cmd);
}
void Texture::Resize(std::uint32_t width, std::uint32_t height)
{
#ifdef DEBUG
Texture new_texture = Texture(CPUBuffer{}, width, height, m_format, m_is_multisampled, m_debug_name);
#else
Texture new_texture = Texture(CPUBuffer{}, width, height, m_format, m_is_multisampled, std::string_view{});
#endif
if(m_staging_buffer.has_value())
new_texture.OpenCPUBuffer();
// Suboptimal operations, should bake all of them in a single command buffer
new_texture.Clear(VK_NULL_HANDLE, Vec4f{ 0.f });
CopyTo(new_texture);
Swap(new_texture);
}
void Texture::Swap(Texture& texture) noexcept
{
MLX_PROFILE_FUNCTION();
#ifdef DEBUG
std::swap(m_debug_name, texture.m_debug_name);
#endif
std::swap(m_allocation, texture.m_allocation);
std::swap(m_image, texture.m_image);
std::swap(m_image_view, texture.m_image_view);
std::swap(m_sampler, texture.m_sampler);
std::swap(m_format, texture.m_format);
std::swap(m_tiling, texture.m_tiling);
std::swap(m_layout, texture.m_layout);
std::swap(m_type, texture.m_type);
std::swap(m_width, texture.m_width);
std::swap(m_height, texture.m_height);
std::swap(m_is_multisampled, texture.m_is_multisampled);
if(m_staging_buffer.has_value() && texture.m_staging_buffer.has_value())
m_staging_buffer->Swap(*texture.m_staging_buffer);
else if(m_staging_buffer.has_value())
m_staging_buffer.reset();
else if(texture.m_staging_buffer.has_value())
texture.m_staging_buffer.reset();
m_has_been_modified = true;
texture.m_has_been_modified = true;
}
Texture* StbTextureLoad(const std::filesystem::path& file, int* w, int* h) Texture* StbTextureLoad(const std::filesystem::path& file, int* w, int* h)
{ {
using namespace std::literals; using namespace std::literals;

14
third_party/kvf.h vendored
View File

@@ -152,6 +152,8 @@ void kvfDestroySemaphore(VkDevice device, VkSemaphore semaphore);
VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type); VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type);
void kvfCopyImageToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkImage src, size_t buffer_offset, VkImageAspectFlagBits aspect, VkExtent3D extent); void kvfCopyImageToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkImage src, size_t buffer_offset, VkImageAspectFlagBits aspect, VkExtent3D extent);
void kvfCopyImageToImage(VkCommandBuffer cmd, VkImage src, VkImageLayout src_layout, VkImage dst, VkImageLayout dst_layout, uint32_t count, const VkImageCopy* regions);
void kvfDestroyImage(VkDevice device, VkImage image); void kvfDestroyImage(VkDevice device, VkImage image);
VkImageView kvfCreateImageView(VkDevice device, VkImage image, VkFormat format, VkImageViewType type, VkImageAspectFlags aspect, int layer_count); VkImageView kvfCreateImageView(VkDevice device, VkImage image, VkFormat format, VkImageViewType type, VkImageAspectFlags aspect, int layer_count);
void kvfDestroyImageView(VkDevice device, VkImageView image_view); void kvfDestroyImageView(VkDevice device, VkImageView image_view);
@@ -2147,6 +2149,18 @@ void kvfCopyImageToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkImage src, size_t
KVF_GET_DEVICE_FUNCTION(vkCmdCopyImageToBuffer)(cmd, src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst, 1, &region); KVF_GET_DEVICE_FUNCTION(vkCmdCopyImageToBuffer)(cmd, src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst, 1, &region);
} }
void kvfCopyImageToImage(VkCommandBuffer cmd, VkImage src, VkImageLayout src_layout, VkImage dst, VkImageLayout dst_layout, uint32_t count, const VkImageCopy* regions)
{
KVF_ASSERT(cmd != VK_NULL_HANDLE);
KVF_ASSERT(dst != VK_NULL_HANDLE);
KVF_ASSERT(src != VK_NULL_HANDLE);
#ifdef KVF_IMPL_VK_NO_PROTOTYPES
__KvfDevice* kvf_device = __kvfGetKvfDeviceFromVkCommandBuffer(cmd);
KVF_ASSERT(kvf_device != NULL && "could not find VkDevice in registered devices");
#endif
KVF_GET_DEVICE_FUNCTION(vkCmdCopyImage)(cmd, src, src_layout, dst, dst_layout, count, regions);
}
void kvfDestroyImage(VkDevice device, VkImage image) void kvfDestroyImage(VkDevice device, VkImage image)
{ {
if(image == VK_NULL_HANDLE) if(image == VK_NULL_HANDLE)