Skip to content

Commit 2eddba3

Browse files
committed
Squash commits
1 parent 4b5de58 commit 2eddba3

525 files changed

Lines changed: 18446 additions & 82706 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,13 @@ temp/
209209
# ignore downloaded tools
210210
tools/external
211211

212-
# ignore lua-tests res folder which is copy from cpp-tests
213-
tests/lua-tests/res/
214-
215212
extensions/sceneio21
216213
extensions/sceneio20
217214
extensions/sceneio19
218215
extensions/fonteng
219216

220217
tools/bindings-generator/clang/prebuilt/*
221218

222-
templates/lua-template-default/Content/src/axmol
223219
tests/lua-tests/Content/src/axmol
224220
tests/lua-tests/Content/res
225221
tests/cpp-tests/Content
@@ -242,4 +238,4 @@ release_note_draft.txt
242238
1k/.env
243239
1k/llvm.sh
244240

245-
.mimo*
241+
.mimo*

1k/build.profiles

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ emsdk=3.1.73~6.0.1+
9797
oboe=1.10.0
9898
kcp=2.1.1
9999
lz4=v1.10.0
100-
sample-assets=v3.0.0-alpha22
100+
sample-assets=master
101101
live2d-core=5.5
102102
openxr=release-1.1.61
103103
tracy=v0.13.1

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# build engine library and all tests
2929

30-
cmake_minimum_required(VERSION 3.22...4.3)
30+
cmake_minimum_required(VERSION 3.22...4.4)
3131

3232
project(axmol)
3333

axmol/rhi/RenderContext.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,33 @@
2626
#include "axmol/rhi/RenderContext.h"
2727
#include "axmol/rhi/PipelineDesc.h"
2828
#include "axmol/rhi/RenderTarget.h"
29+
#include "axmol/rhi/RHIUtils.h"
30+
#include "axmol/rhi/Texture.h"
2931

3032
#include <limits>
3133

3234
namespace ax::rhi
3335
{
3436

37+
bool RenderContext::validateTextureCopy(const Texture* src, const Texture* dst)
38+
{
39+
if (!src || !dst || src == dst)
40+
return false;
41+
42+
if (src->getTextureType() != TextureType::TEXTURE_2D || dst->getTextureType() != TextureType::TEXTURE_2D ||
43+
src->getArraySize() != 1 || dst->getArraySize() != 1 || src->getMipLevels() != 1 || dst->getMipLevels() != 1 ||
44+
src->getWidth() <= 0 || src->getHeight() <= 0 || src->getWidth() != dst->getWidth() ||
45+
src->getHeight() != dst->getHeight() || src->getPixelFormat() != dst->getPixelFormat())
46+
return false;
47+
48+
const auto format = src->getPixelFormat();
49+
if (format == PixelFormat::NONE || format == PixelFormat::D24S8)
50+
return false;
51+
52+
const auto& formatDesc = RHIUtils::getFormatDesc(format);
53+
return formatDesc.blockWidth == 1 && formatDesc.blockHeight == 1;
54+
}
55+
3556
RenderContext::~RenderContext() {}
3657

3758
void RenderContext::updatePipelineState(const RenderTarget* rt,

axmol/rhi/RenderContext.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,35 @@ class RenderContext : public ax::Object
228228
*/
229229
virtual void readPixels(RenderTarget* rt, std::function<void(const PixelBufferDesc&)> callback) = 0;
230230

231+
/**
232+
* @brief Copies the contents of one texture resource into another texture resource.
233+
*
234+
* This operation performs a GPU-side texture copy without involving the CPU.
235+
* The source and destination textures must be compatible for copying according
236+
* to the underlying graphics backend requirements.
237+
*
238+
* @param src Source texture to copy from.
239+
* @param dst Destination texture to copy into.
240+
*
241+
* @return true if the copy command was successfully issued; otherwise false.
242+
*/
243+
virtual bool copyTexture(Texture* src, Texture* dst) = 0;
244+
245+
/**
246+
* @brief Copies the rendered contents of a render target into a texture resource.
247+
*
248+
* Unlike texture-to-texture copies, this operation copies from the current
249+
* render target output. The underlying implementation may use a framebuffer
250+
* copy, resolve, or other backend-specific operation depending on the graphics
251+
* API.
252+
*
253+
* @param src Source render target.
254+
* @param dst Destination texture to receive the rendered contents.
255+
*
256+
* @return true if the copy command was successfully issued; otherwise false.
257+
*/
258+
virtual bool copyTexture(RenderTarget* src, Texture* dst) = 0;
259+
231260
/**
232261
* This property controls whether or not the drawables'
233262
* metal textures may only be used for framebuffer attachments (YES) or
@@ -254,6 +283,8 @@ class RenderContext : public ax::Object
254283
*/
255284
virtual uint64_t getCompletedFenceValue() const;
256285

286+
static bool validateTextureCopy(const Texture* src, const Texture* dst);
287+
257288
protected:
258289
virtual ~RenderContext();
259290

axmol/rhi/RenderTarget.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,21 @@ void RenderTarget::setDepthStencilTexture(Texture* texture, int level)
8787
}
8888
}
8989

90+
PixelFormat RenderTarget::getColorAttachmentPixelFormat(int index) const
91+
{
92+
if (_defaultRenderTarget && index != 0)
93+
return PixelFormat::NONE;
94+
95+
if (index < 0 || index >= static_cast<int>(_color.size()))
96+
return PixelFormat::NONE;
97+
98+
const auto& color = _color[index];
99+
return color.texture ? color.texture->getPixelFormat() : PixelFormat::NONE;
100+
}
101+
102+
PixelFormat RenderTarget::getDepthStencilAttachmentPixelFormat() const
103+
{
104+
return _depthStencil.texture ? _depthStencil.texture->getPixelFormat() : PixelFormat::NONE;
105+
}
106+
90107
} // namespace ax::rhi

axmol/rhi/RenderTarget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class RenderTarget : public ax::Object
6767
virtual void setColorTexture(Texture* texture, int level = 0, int index = 0);
6868
virtual void setDepthStencilTexture(Texture* texture, int level = 0);
6969

70+
virtual PixelFormat getColorAttachmentPixelFormat(int index = 0) const;
71+
virtual PixelFormat getDepthStencilAttachmentPixelFormat() const;
72+
7073
bool isDirty() const { return !!_dirtyFlags; }
7174

7275
ColorAttachment _color{};

axmol/rhi/Texture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class Texture : public Object
8282

8383
int getWidth() const { return static_cast<int>(_desc.width); }
8484
int getHeight() const { return static_cast<int>(_desc.height); }
85+
int getArraySize() const { return static_cast<int>(_desc.arraySize); }
86+
int getMipLevels() const { return static_cast<int>(_desc.mipLevels); }
8587

8688
/**
8789
* Update a two-dimensional texture image

axmol/rhi/d3d11/RenderContext11.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,4 +851,69 @@ void RenderContextImpl::readPixels(RenderTarget* rt, UINT x, UINT y, UINT width,
851851
SafeRelease(stagingTex);
852852
}
853853

854+
bool RenderContextImpl::copyTexture(Texture* src, Texture* dst)
855+
{
856+
if (!validateTextureCopy(src, dst))
857+
return false;
858+
859+
auto* srcImpl = static_cast<TextureImpl*>(src);
860+
auto* dstImpl = static_cast<TextureImpl*>(dst);
861+
862+
auto* srcResource = srcImpl->internalHandle().resource;
863+
if (!srcResource)
864+
return false;
865+
866+
if (!dstImpl->internalHandle().resource)
867+
dstImpl->updateData(nullptr, dst->getWidth(), dst->getHeight(), 0, 0);
868+
869+
auto* dstResource = dstImpl->internalHandle().resource;
870+
if (!dstResource || srcResource == dstResource)
871+
return false;
872+
873+
D3D11_TEXTURE2D_DESC srcDesc{};
874+
D3D11_TEXTURE2D_DESC dstDesc{};
875+
srcResource->GetDesc(&srcDesc);
876+
dstResource->GetDesc(&dstDesc);
877+
878+
if (srcDesc.Width != dstDesc.Width || srcDesc.Height != dstDesc.Height || srcDesc.Format != dstDesc.Format ||
879+
srcDesc.SampleDesc.Count != 1 || dstDesc.SampleDesc.Count != 1 || srcDesc.ArraySize != 1 ||
880+
dstDesc.ArraySize != 1 || srcDesc.MipLevels != 1 || dstDesc.MipLevels != 1 ||
881+
dstDesc.Usage != D3D11_USAGE_DEFAULT)
882+
return false;
883+
884+
// D3D11 keeps the last render targets bound after endRenderPass(). Temporarily
885+
// unbind them so a just-rendered color attachment can be used as a copy source.
886+
ID3D11RenderTargetView* oldRTVs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]{};
887+
ID3D11DepthStencilView* oldDSV = nullptr;
888+
_d3d11Context->OMGetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, oldRTVs, &oldDSV);
889+
_d3d11Context->OMSetRenderTargets(0, nullptr, nullptr);
890+
891+
_d3d11Context->CopySubresourceRegion(dstResource, 0, 0, 0, 0, srcResource, 0, nullptr);
892+
893+
UINT oldRTVCount = 0;
894+
for (UINT i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
895+
{
896+
if (oldRTVs[i])
897+
oldRTVCount = i + 1;
898+
}
899+
_d3d11Context->OMSetRenderTargets(oldRTVCount, oldRTVs, oldDSV);
900+
for (auto* rtv : oldRTVs)
901+
SafeRelease(rtv);
902+
SafeRelease(oldDSV);
903+
904+
return true;
905+
}
906+
907+
bool RenderContextImpl::copyTexture(RenderTarget* src, Texture* dst)
908+
{
909+
if (!src || !dst || src->_color.empty())
910+
return false;
911+
912+
const auto& color = src->_color[0];
913+
if (color.level != 0 || !color.texture)
914+
return false;
915+
916+
return copyTexture(color.texture, dst);
917+
}
918+
854919
} // namespace ax::rhi::d3d11

axmol/rhi/d3d11/RenderContext11.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class RenderContextImpl : public RenderContext
132132

133133
void readPixels(RenderTarget* rt, std::function<void(const PixelBufferDesc&)> callback) override;
134134

135+
bool copyTexture(RenderTarget* src, Texture* dst) override;
136+
bool copyTexture(Texture* src, Texture* dst) override;
137+
135138
protected:
136139
void readPixels(RenderTarget* rt, UINT x, UINT y, UINT width, UINT height, PixelBufferDesc& pbd);
137140

0 commit comments

Comments
 (0)