Skip to content

Commit 766e972

Browse files
committed
Implement d3d11 renderer backend (#2631)
* Improve render backend macro detection * Implement d3d11 backend (WIP) * [d3d11] Fix depth stencil state not apply Also resolved self-addressed issue: text rendering "Te", the 'e' left will edge pixel will lost, actually override by "T" due to draw order mistake * [d3d] Fix buffer creation * [d3d] Make ImGui works * [d3d11] Resize SwapChain support Also fix texture reference leaks * Improve VertexLayout * Update axslcc to 1.10.0 to resolve d3d instance draw issue Reason: the older axslcc split mat4 vertex input four vec4 when translate to HLSL will allocate non-standard semantic name, looks like `TEXCOORD1_[1~N]`, benefit SPIRV-cross support flag: flatten_matrix_vertex_input_semantics=true, SPIRV-corss will translate mat4 to TEXCOORD{N,N+1,N+2,...} rather than TEXCOORDN_{0,1,2,3} * [d3d11] Fix RGB8 texture upload The d3d not support RGB8, need convert at renderer frontend * Resolve lint warnings * Update luabindings generator * [d3d11] Make live2d works * [d3d11] Translate texture descriptor properly * Fix compile errors * [d3d11] Try fix depth-stencil texture creation * [d3d11] Fix offscreen render target depth-stencil texture creation * [d3d11] Fix OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 is still bound on input * [d3d11] bind dummy lightmap texture for terrain when lightmap not set by user * [d3d11] Add mip levels support temporary * [d3d11] Fix skybox textureCube data upload * [d3d11] Don't add bind flags render target for non RENDER_TARGET texture Fix MotionStreak vertex format * [d3d11] Fix blend state translation * Fix lua bindings * Adapte metal backend * Fix metal backend
1 parent 1512ed7 commit 766e972

File tree

228 files changed

+6166
-2821
lines changed

Some content is hidden

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

228 files changed

+6166
-2821
lines changed

1k/1kiss.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ function download_and_expand($url, $out, $dest) {
772772
$1k.mkdirs($dest)
773773
if ($out.EndsWith('.zip')) {
774774
if ($IsWin) {
775-
Expand-Archive -Path $out -DestinationPath $dest
775+
Expand-Archive -Path $out -DestinationPath $dest -Force
776776
}
777777
else {
778778
unzip -d $dest $out | Out-Null
@@ -1211,7 +1211,7 @@ function setup_unzip() {
12111211
$unzip_cmd_info = Get-Command 'unzip' -ErrorAction SilentlyContinue
12121212
if (!$unzip_cmd_info) {
12131213
if ($IsLinux) {
1214-
if ($(which dpkg)) {
1214+
if ($(which dpkg)) {
12151215
sudo apt install unzip
12161216
}
12171217
elseif($(which pacman)) {
@@ -1323,7 +1323,7 @@ function setup_android_sdk() {
13231323
return $null
13241324
}
13251325
$1k.println("Looking require $ndk_ver$IsGraterThan in $sdk_dir")
1326-
1326+
13271327
$ndk_major = ($ndk_ver -replace '[^0-9]', '')
13281328
$ndk_minor_off = "$ndk_major".Length + 1
13291329
$ndk_minor = if ($ndk_minor_off -lt $ndk_ver.Length) { "$([int][char]$ndk_ver.Substring($ndk_minor_off) - $ndk_minor_base)" } else { '0' }
@@ -1367,7 +1367,7 @@ function setup_android_sdk() {
13671367
}
13681368

13691369
$ndk_root = &$find_ndk_in $selected_sdk_root
1370-
1370+
13711371
$sdk_comps = @()
13721372

13731373
### cmdline-tools ###

1k/build.profiles

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# --- region platfom:common
77

88
# The axmol shader compiler, legacy name is 'glslcc' before axmol-2.3.0
9-
axslcc=1.9.6+
9+
axslcc=1.10.0+
1010

1111
# The cmake, @gradle @axmol-cmdline
1212
# as latest as possible

CMakeOptions.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@
3737
- AX_ENABLE_EXT_JSONDEFAULT: the UserDefault based on json, default: `FALSE`
3838
- AX_ENABLE_EXT_LUA: the lua extension, default: `TRUE`
3939
- AX_WITH_XXX: usually user don't need care it
40-
- AX_USE_COMPAT_GL: whether use compat gl as renderer backend, default: win32: `TRUE`, others: `FALSE`
41-
- win32: whether use ANGLE GLES backend
42-
- osx: whether use OpenGL instead Metal backend
43-
- ios/tvos: whether use GLES instead Metal backend
40+
- AX_RENDER_API: specify render api: gl, mtl, d3d, default: `auto`
41+
- AX_USE_ANGLE: whether use angle as win32 gl backend, default: `TRUE`
4442
- AX_CORE_PROFILE: whether strip all deprecated features, default `FALSE`, it's useful to pre-upgrade your game project to adapte future axmol versions
4543
- AX_ISA_LEVEL: specifiy SIMD Instructions Acceleration Level: 0~4, 0: disabled, 1: SSE2, 2: SSE4.1/NEON, 3: SSE4.2, 4: AVX2, default: 2
4644
- AX_GLES_PROFILE: specify GLES profile version for GLES backend, valid value `200`, `300`

cmake/Modules/AXConfigDefine.cmake

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -164,35 +164,10 @@ function(use_ax_compile_define target)
164164
# !important axmol not use double precision
165165
# target_compile_definitions(${target} PUBLIC CP_USE_CGTYPES=0)
166166
# target_compile_definitions(${target} PUBLIC CP_USE_DOUBLES=0)
167-
if(APPLE)
168-
target_compile_definitions(${target} PUBLIC __APPLE__)
169-
170-
if(AX_USE_GL)
171-
target_compile_definitions(${target}
172-
PUBLIC AX_USE_GL=1
173-
PUBLIC GL_SILENCE_DEPRECATION=1
174-
)
175-
176-
if(NOT _AX_USE_PREBUILT)
177-
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
178-
endif()
179-
endif()
180-
elseif(LINUX)
167+
if(LINUX)
181168
ax_config_pred(${target} AX_ENABLE_VLC_MEDIA)
182169
target_compile_definitions(${target} PUBLIC _GNU_SOURCE)
183-
elseif(ANDROID)
184-
if(NOT _AX_USE_PREBUILT)
185-
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
186-
endif()
187-
188-
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
189-
elseif(EMSCRIPTEN)
190-
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
191170
elseif(WINDOWS)
192-
if(NOT _AX_USE_PREBUILT)
193-
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
194-
endif()
195-
196171
ax_config_pred(${target} AX_ENABLE_VLC_MEDIA)
197172
target_compile_definitions(${target}
198173
PUBLIC WIN32
@@ -202,14 +177,26 @@ function(use_ax_compile_define target)
202177
PUBLIC _UNICODE
203178
PUBLIC _CRT_SECURE_NO_WARNINGS
204179
PUBLIC _SCL_SECURE_NO_WARNINGS
205-
206180
# PUBLIC GLAD_GLAPI_EXPORT
207181
)
208182

209183
if(BUILD_SHARED_LIBS)
210184
target_compile_definitions(${target} PRIVATE AX_DLLEXPORT INTERFACE AX_DLLIMPORT)
211185
endif()
212186
endif()
187+
188+
# render api
189+
if(AX_RENDER_API STREQUAL "gl")
190+
target_compile_definitions(${target} PUBLIC AX_RENDER_API=1)
191+
if(APPLE)
192+
target_compile_definitions(${target} PUBLIC GL_SILENCE_DEPRECATION=1)
193+
endif()
194+
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
195+
elseif(AX_RENDER_API STREQUAL "mtl")
196+
target_compile_definitions(${target} PUBLIC AX_RENDER_API=2)
197+
elseif(AX_RENDER_API STREQUAL "d3d")
198+
target_compile_definitions(${target} PUBLIC AX_RENDER_API=3)
199+
endif()
213200
endfunction()
214201

215202
# Set compiler options for engine lib: axmol

cmake/Modules/AXConfigDepend.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ macro(ax_depend)
7474
${COREAUDIO_LIBRARY}
7575
${SYSTEMCONFIGURATION_LIBRARY}
7676
)
77-
if(AX_USE_COMPAT_GL)
77+
if(AX_RENDER_API STREQUAL "gl")
7878
find_library(OPENGL_LIBRARY OpenGL)
7979
list(APPEND PLATFORM_SPECIFIC_LIBS ${OPENGL_LIBRARY})
8080
endif()
@@ -101,7 +101,7 @@ macro(ax_depend)
101101
${_AX_APPLE_LIBS}
102102
)
103103

104-
if(AX_USE_COMPAT_GL)
104+
if(AX_RENDER_API STREQUAL "gl")
105105
find_library(OPENGLES_LIBRARY OpenGLES)
106106
list(APPEND PLATFORM_SPECIFIC_LIBS ${OPENGLES_LIBRARY})
107107
endif()

cmake/Modules/AXSLCC.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,19 @@ function(ax_target_compile_shaders target_name)
118118
endif()
119119

120120
list(APPEND SC_FLAGS "--lang=gles" "--profile=${SC_PROFILE}")
121-
elseif(AX_USE_GL)
121+
elseif(AX_RENDER_API STREQUAL "gl")
122122
# version 330
123123
set(OUT_LANG "GLSL")
124124
set(SC_PROFILE "330")
125125
list(APPEND SC_FLAGS "--lang=glsl" "--profile=${SC_PROFILE}")
126-
elseif(AX_USE_METAL)
126+
elseif(AX_RENDER_API STREQUAL "mtl")
127127
set(OUT_LANG "MSL")
128128
list(APPEND SC_FLAGS "--lang=msl")
129129
set(SC_DEFINES "METAL")
130+
elseif(AX_RENDER_API STREQUAL "d3d")
131+
set(OUT_LANG "HLSL")
132+
list(APPEND SC_FLAGS "--lang=hlsl")
133+
set(SC_DEFINES "HLSL")
130134
endif()
131135

132136
# automap, no-suffix since 1.18.1 released by axmolengine
@@ -157,8 +161,8 @@ function(ax_target_compile_shaders target_name)
157161
list(APPEND SC_FLAGS "--cvar=shader_rt_${FILE_NAME}")
158162
endif()
159163

160-
# sgs, because Apple Metal lack of shader uniform reflect so use --sgs --refelect
161-
if(AX_USE_METAL)
164+
# sgs, because Apple Metal lack of shader uniform reflect and d3d reflect only support semantic name, so use --sgs --refelect
165+
if(AX_RENDER_API STREQUAL "mtl" OR AX_RENDER_API STREQUAL "d3d")
162166
list(APPEND SC_FLAGS "--sgs" "--reflect")
163167
endif()
164168

core/2d/CameraBackgroundBrush.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/****************************************************************************
22
Copyright (c) 2015-2016 Chukong Technologies Inc.
33
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4+
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
45
56
https://axmol.dev/
67
@@ -32,7 +33,7 @@
3233
#include "renderer/QuadCommand.h"
3334
#include "renderer/CustomCommand.h"
3435
#include "renderer/GroupCommand.h"
35-
#include "renderer/backend/Types.h"
36+
3637
#include <vector>
3738

3839
namespace ax

core/2d/FastTMXLayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void FastTMXLayer::updateVertexBuffer()
274274
unsigned int vertexBufferSize = (unsigned int)(sizeof(V3F_T2F_C4B) * _totalQuads.size() * 4);
275275
if (!_vertexBuffer)
276276
{
277-
_vertexBuffer = backend::DriverBase::getInstance()->newBuffer(vertexBufferSize, backend::BufferType::VERTEX, backend::BufferUsage::STATIC);
277+
_vertexBuffer = backend::DriverBase::getInstance()->createBuffer(vertexBufferSize, backend::BufferType::VERTEX, backend::BufferUsage::STATIC);
278278
}
279279
_vertexBuffer->updateData(&_totalQuads[0], vertexBufferSize);
280280
}
@@ -284,7 +284,7 @@ void FastTMXLayer::updateIndexBuffer()
284284
auto indexBufferSize = (sizeof(decltype(_indices)::value_type) * _indices.size());
285285
if (!_indexBuffer)
286286
{
287-
_indexBuffer = backend::DriverBase::getInstance()->newBuffer(indexBufferSize, backend::BufferType::INDEX, backend::BufferUsage::DYNAMIC);
287+
_indexBuffer = backend::DriverBase::getInstance()->createBuffer(indexBufferSize, backend::BufferType::INDEX, backend::BufferUsage::DYNAMIC);
288288
}
289289
_indexBuffer->updateData(&_indices[0], indexBufferSize);
290290
}

core/2d/Grid.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool GridBase::initWithSize(const Vec2& gridSize, Texture2D* texture, bool flipp
8888
AX_SAFE_RETAIN(_texture);
8989
_isTextureFlipped = flipped;
9090

91-
#ifdef AX_USE_METAL
91+
#if AX_RENDER_API == AX_RENDER_API_MTL
9292
_isTextureFlipped = !flipped;
9393
#endif
9494

@@ -116,18 +116,18 @@ bool GridBase::initWithSize(const Vec2& gridSize, Texture2D* texture, bool flipp
116116
#define VERTEX_TEXCOORD_SIZE 2
117117
uint32_t texcoordOffset = (VERTEX_POSITION_SIZE) * sizeof(float);
118118
uint32_t totalSize = (VERTEX_POSITION_SIZE + VERTEX_TEXCOORD_SIZE) * sizeof(float);
119-
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
120-
auto iter = attributeInfo.find("a_position");
119+
const auto& vertexInputs = _programState->getProgram()->getActiveVertexInputs();
120+
auto iter = vertexInputs.find("a_position");
121121

122122
auto layout = _programState->getMutableVertexLayout();
123-
if (iter != attributeInfo.end())
123+
if (iter != vertexInputs.end())
124124
{
125-
layout->setAttrib("a_position", iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
125+
layout->setAttrib("a_position", &iter->second, backend::VertexFormat::FLOAT3, 0, false);
126126
}
127-
iter = attributeInfo.find("a_texCoord");
128-
if (iter != attributeInfo.end())
127+
iter = vertexInputs.find("a_texCoord");
128+
if (iter != vertexInputs.end())
129129
{
130-
layout->setAttrib("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, texcoordOffset,
130+
layout->setAttrib("a_texCoord", &iter->second, backend::VertexFormat::FLOAT2, texcoordOffset,
131131
false);
132132
}
133133
layout->setStride(totalSize);
@@ -220,7 +220,7 @@ void GridBase::beforeDraw()
220220
_oldRenderTarget = renderer->getRenderTarget();
221221
AX_SAFE_RELEASE(_renderTarget);
222222
_renderTarget =
223-
backend::DriverBase::getInstance()->newRenderTarget(_texture->getBackendTexture());
223+
backend::DriverBase::getInstance()->createRenderTarget(_texture->getBackendTexture());
224224
renderer->setRenderTarget(_renderTarget);
225225
};
226226
renderer->addCallbackCommand(beforeDrawCommandFunc);

core/2d/MotionStreak.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void MotionStreak::setTexture(Texture2D* texture)
217217
AX_SAFE_RELEASE(_texture);
218218
_texture = texture;
219219

220-
setProgramStateWithRegistry(backend::ProgramType::POSITION_TEXTURE_COLOR, _texture);
220+
setProgramStateWithRegistry(backend::ProgramType::TRAIL_2D, _texture);
221221
}
222222
}
223223

@@ -231,27 +231,29 @@ bool MotionStreak::setProgramState(backend::ProgramState* programState, bool own
231231

232232
_mvpMatrixLocaiton = _programState->getUniformLocation("u_MVPMatrix");
233233

234+
#if 0
234235
// setup custom vertex layout for V2F_T2F_C4B
235-
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
236-
auto iter = attributeInfo.find("a_position");
236+
const auto& vertexInputs = _programState->getProgram()->getActiveVertexInputs();
237+
auto iter = vertexInputs.find("a_position");
237238
auto layout = _programState->getMutableVertexLayout();
238-
if (iter != attributeInfo.end())
239+
if (iter != vertexInputs.end())
239240
{
240-
layout->setAttrib("a_position", iter->second.location, backend::VertexFormat::FLOAT2, 0, false);
241+
layout->setAttrib("a_position", &iter->second, backend::VertexFormat::FLOAT2, 0, false);
241242
}
242-
iter = attributeInfo.find("a_texCoord");
243-
if (iter != attributeInfo.end())
243+
iter = vertexInputs.find("a_texCoord");
244+
if (iter != vertexInputs.end())
244245
{
245-
layout->setAttrib("a_texCoord", iter->second.location, backend::VertexFormat::FLOAT2, sizeof(Vec2), false);
246+
layout->setAttrib("a_texCoord", &iter->second, backend::VertexFormat::FLOAT2, sizeof(Vec2), false);
246247
}
247-
iter = attributeInfo.find("a_color");
248-
if (iter != attributeInfo.end())
248+
iter = vertexInputs.find("a_color");
249+
if (iter != vertexInputs.end())
249250
{
250-
layout->setAttrib("a_color", iter->second.location, backend::VertexFormat::UBYTE4, sizeof(Vec2) * 2, true);
251+
layout->setAttrib("a_color", &iter->second, backend::VertexFormat::UBYTE4, sizeof(Vec2) * 2, true);
251252
}
252253

253254
constexpr size_t vertexSize = sizeof(_vertices[0]);
254255
layout->setStride(vertexSize);
256+
#endif
255257

256258
updateProgramStateTexture(_texture);
257259
return true;

0 commit comments

Comments
 (0)