Skip to content

Commit

Permalink
fix compiling and crash error
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo committed Mar 31, 2022
1 parent a6bf766 commit e849e9c
Show file tree
Hide file tree
Showing 31 changed files with 783 additions and 683 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/native-compile-platforms.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: <Native> Compile

on:
pull_request:
paths:
- 'native/**'
on: [pull_request]

jobs:
compile_windows:
Expand Down
6 changes: 3 additions & 3 deletions native/cocos/application/BaseGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#include "CocosApplication.h"

#include <string>
#include "CocosApplication.h"
#include "renderer/pipeline/GlobalDescriptorSetManager.h"

namespace cc {
class BaseGame : public CocosApplication {
Expand All @@ -47,6 +46,7 @@ class BaseGame : public CocosApplication {

BaseGame() = default;
int init() override {
cc::pipeline::GlobalDSManager::setDescriptorSetLayout();
#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MAC_OSX
// override default value
//_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x;
Expand Down
54 changes: 54 additions & 0 deletions native/cocos/core/assets/SimpleTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "core/assets/SimpleTexture.h"
#include "core/assets/ImageAsset.h"
#include "core/event/EventTypesToJS.h"
#include "core/platform/Debug.h"
#include "core/platform/Macro.h"
#include "renderer/gfx-base/GFXDevice.h"

Expand Down Expand Up @@ -56,6 +57,7 @@ SimpleTexture::~SimpleTexture()= default;


bool SimpleTexture::destroy() {
tryDestroyTextureView();
tryDestroyTexture();
return Super::destroy();
}
Expand Down Expand Up @@ -114,6 +116,7 @@ void SimpleTexture::setMipmapLevel(uint32_t value) {
}

void SimpleTexture::tryReset() {
tryDestroyTextureView();
tryDestroyTexture();
if (_mipmapLevel == 0) {
return;
Expand All @@ -123,6 +126,7 @@ void SimpleTexture::tryReset() {
return;
}
createTexture(device);
createTextureView(device);
}

void SimpleTexture::createTexture(gfx::Device *device) {
Expand Down Expand Up @@ -155,6 +159,25 @@ void SimpleTexture::createTexture(gfx::Device *device) {
notifyTextureUpdated();
}

void SimpleTexture::createTextureView(gfx::Device *device) {
if (!_gfxTexture) {
return;
}
auto textureViewCreateInfo = getGfxTextureViewCreateInfo(
_gfxTexture,
getGFXFormat(),
_baseLevel,
_maxLevel - _baseLevel + 1
);

//TODO(minggo)
// if (!textureViewCreateInfo) {
// return;
// }

_gfxTextureView = device->createTexture(textureViewCreateInfo);
}

void SimpleTexture::tryDestroyTexture() {
if (_gfxTexture != nullptr) {
_gfxTexture->destroy();
Expand All @@ -164,6 +187,37 @@ void SimpleTexture::tryDestroyTexture() {
}
}

void SimpleTexture::tryDestroyTextureView() {
if (_gfxTextureView != nullptr) {
_gfxTextureView->destroy();
_gfxTextureView = nullptr;

//TODO(minggo): should notify JS if the performance is low.
}
}

void SimpleTexture::setMipRange(uint32_t baseLevel, uint32_t maxLevel) {
debug::warnID(baseLevel <= maxLevel, 3124);

setMipRangeInternal(baseLevel, maxLevel);

auto *device = getGFXDevice();
if (!device) {
return;
}
tryDestroyTextureView();
createTextureView(device);
}


void SimpleTexture::setMipRangeInternal(uint32_t baseLevel, uint32_t maxLevel){
_baseLevel = baseLevel;
_baseLevel = _baseLevel < _mipmapLevel ? _baseLevel : _mipmapLevel - 1;

_maxLevel = maxLevel < _baseLevel ? _baseLevel : maxLevel;
_maxLevel = _maxLevel < _mipmapLevel ? _maxLevel : _mipmapLevel - 1;
}

void SimpleTexture::notifyTextureUpdated() {
emit(EventTypesToJS::SIMPLE_TEXTURE_GFX_TEXTURE_UPDATED, _gfxTexture.get());
}
Expand Down
24 changes: 23 additions & 1 deletion native/cocos/core/assets/SimpleTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SimpleTexture : public TextureBase {
* @zh 获取此贴图底层的 GFX 贴图对象。
*/
gfx::Texture *getGFXTexture() const override {
return _gfxTexture.get();
return _gfxTextureView.get();
}

bool destroy() override;
Expand Down Expand Up @@ -108,6 +108,13 @@ class SimpleTexture : public TextureBase {
* @warn As it is invoked by subclass(TextureCube) in TS, so should make it as public.
*/
void setMipmapLevel(uint32_t value);

/**
* Set mipmap level range for this texture.
* @param baseLevel The base mipmap level.
* @param maxLevel The maximum mipmap level.
*/
void setMipRange(uint32_t baseLevel, uint32_t maxLevel);

protected:
SimpleTexture();
Expand All @@ -119,20 +126,35 @@ class SimpleTexture : public TextureBase {
* @param presumed The presumed GFX texture info.
*/
virtual gfx::TextureInfo getGfxTextureCreateInfo(gfx::TextureUsageBit usage, gfx::Format format, uint32_t levelCount, gfx::TextureFlagBit flags) = 0;

/**
* @en This method is overrided by derived classes to provide GFX TextureViewInfo.
* @zh 这个方法被派生类重写以提供 GFX 纹理视图信息。
* @param presumed The presumed GFX TextureViewInfo.
*/
virtual gfx::TextureViewInfo getGfxTextureViewCreateInfo(gfx::Texture *texture, gfx::Format format, uint32_t baseLevel, uint32_t levelCount) = 0;

void tryReset();

void createTexture(gfx::Device *device);
void createTextureView(gfx::Device *device);

void tryDestroyTexture();
void tryDestroyTextureView();
void notifyTextureUpdated();
void setMipRangeInternal(uint32_t baseLevel, uint32_t maxLevel);


IntrusivePtr<gfx::Texture> _gfxTexture;
IntrusivePtr<gfx::Texture> _gfxTextureView;

uint32_t _mipmapLevel{1};
// Cache these data to reduce JSB invoking.
uint32_t _textureWidth{0};
uint32_t _textureHeight{0};

uint32_t _baseLevel{0};
uint32_t _maxLevel{0};

CC_DISALLOW_COPY_MOVE_ASSIGN(SimpleTexture);
};
Expand Down
27 changes: 25 additions & 2 deletions native/cocos/core/assets/Texture2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void Texture2D::setMipmaps(const ccstd::vector<IntrusivePtr<ImageAsset>> &value)
info.height = imageAsset->getHeight();
info.format = imageAsset->getFormat();
info.mipmapLevel = static_cast<uint32_t>(_mipmaps.size());
info.baseLevel = _baseLevel;
info.maxLevel = _maxLevel;
reset(info);

for (size_t i = 0, len = _mipmaps.size(); i < len; ++i) {
Expand All @@ -60,6 +62,8 @@ void Texture2D::setMipmaps(const ccstd::vector<IntrusivePtr<ImageAsset>> &value)
info.width = 0;
info.height = 0;
info.mipmapLevel = static_cast<uint32_t>(_mipmaps.size());
info.baseLevel = _baseLevel;
info.maxLevel = _maxLevel;
reset(info);
}
}
Expand All @@ -76,16 +80,25 @@ void Texture2D::reset(const ITexture2DCreateInfo &info) {
_width = info.width;
_height = info.height;
setGFXFormat(info.format);
setMipmapLevel(info.mipmapLevel.has_value() ? info.mipmapLevel.value() : 1);

uint32_t mipLevels = info.mipmapLevel.has_value() ? info.mipmapLevel.value() : 1;
setMipmapLevel(mipLevels);

uint32_t minLod = info.baseLevel.has_value() ? info.baseLevel.value() : 0;
uint32_t maxLod = info.maxLevel.has_value() ? info.maxLevel.value() : mipLevels - 1;
setMipRange(minLod, maxLod);

tryReset();
}

void Texture2D::create(uint32_t width, uint32_t height, PixelFormat format /* = PixelFormat::RGBA8888*/, uint32_t mipmapLevel /* = 1*/) {
void Texture2D::create(uint32_t width, uint32_t height, PixelFormat format /* = PixelFormat::RGBA8888*/, uint32_t mipmapLevel /* = 1*/, uint32_t baseLevel, uint32_t maxLevel) {
reset({
width,
height,
format,
mipmapLevel,
baseLevel,
maxLevel
});
}

Expand Down Expand Up @@ -186,6 +199,16 @@ gfx::TextureInfo Texture2D::getGfxTextureCreateInfo(gfx::TextureUsageBit usage,
return texInfo;
}

gfx::TextureViewInfo Texture2D::getGfxTextureViewCreateInfo(gfx::Texture *texture, gfx::Format format, uint32_t baseLevel, uint32_t levelCount) {
gfx::TextureViewInfo texViewInfo;
texViewInfo.type = gfx::TextureType::TEX2D;
texViewInfo.texture = texture;
texViewInfo.format = format;
texViewInfo.baseLevel = baseLevel;
texViewInfo.levelCount = levelCount;
return texViewInfo;
}

void Texture2D::initDefault(const cc::optional<ccstd::string> &uuid) {
Super::initDefault(uuid);
auto *imageAsset = new ImageAsset();
Expand Down
21 changes: 20 additions & 1 deletion native/cocos/core/assets/Texture2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ struct ITexture2DCreateInfo {
* @default 1
*/
cc::optional<uint32_t> mipmapLevel;

/**
* @en The selected base mipmap level
* @zh 选择使用的最小 mipmap 层级。
* @default 1
*/
cc::optional<uint32_t> baseLevel;

/**
* @en The selected maximum mipmap level
* @zh 选择使用的最大 mipmap 层级。
* @default 1
*/
cc::optional<uint32_t> maxLevel;

};

/**
Expand Down Expand Up @@ -136,9 +151,12 @@ class Texture2D final : public SimpleTexture {
* @param height Pixel height
* @param format Pixel format
* @param mipmapLevel Mipmap level count
* @param baseLevel Mipmap base level
* @param maxLevel Mipmap maximum level
* @deprecated since v1.0 please use [[reset]] instead
*/
void create(uint32_t width, uint32_t height, PixelFormat format = PixelFormat::RGBA8888, uint32_t mipmapLevel = 1);
void create(uint32_t width, uint32_t height, PixelFormat format = PixelFormat::RGBA8888, uint32_t mipmapLevel = 1, uint32_t baseLevel = 0, uint32_t maxLevel = 0);

ccstd::string toString() const override;

Expand Down Expand Up @@ -186,6 +204,7 @@ class Texture2D final : public SimpleTexture {
void deserialize(const cc::any &serializedData, const cc::any &handle) override;

gfx::TextureInfo getGfxTextureCreateInfo(gfx::TextureUsageBit usage, gfx::Format format, uint32_t levelCount, gfx::TextureFlagBit flags) override;
gfx::TextureViewInfo getGfxTextureViewCreateInfo(gfx::Texture *texture, gfx::Format format, uint32_t baseLevel, uint32_t levelCount) override;

void initDefault(const cc::optional<ccstd::string> &uuid) override;

Expand Down
25 changes: 24 additions & 1 deletion native/cocos/core/assets/TextureCube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ void TextureCube::setMipmaps(const ccstd::vector<ITextureCubeMipmap> &value) {
imageAsset->getHeight(),
imageAsset->getFormat(),
static_cast<uint32_t>(_mipmaps.size()),
_baseLevel,
_maxLevel
});

for (size_t level = 0, len = _mipmaps.size(); level < len; ++level) {
Expand All @@ -99,6 +101,8 @@ void TextureCube::setMipmaps(const ccstd::vector<ITextureCubeMipmap> &value) {
0,
cc::nullopt,
static_cast<uint32_t>(_mipmaps.size()),
_baseLevel,
_maxLevel
});
}
}
Expand All @@ -115,7 +119,14 @@ void TextureCube::reset(const ITextureCubeCreateInfo &info) {
_width = info.width;
_height = info.height;
setGFXFormat(info.format);
setMipmapLevel(info.mipmapLevel.has_value() ? info.mipmapLevel.value() : 1);

uint32_t mipLevels = info.mipmapLevel.has_value() ? info.mipmapLevel.value() : 1;
setMipmapLevel(mipLevels);

uint32_t minLod = info.baseLevel.has_value() ? info.baseLevel.value() : 0;
uint32_t maxLod = info.maxLevel.has_value() ? info.maxLevel.value() : mipLevels - 1;
setMipRange(minLod, maxLod);

tryReset();
}

Expand Down Expand Up @@ -223,6 +234,18 @@ gfx::TextureInfo TextureCube::getGfxTextureCreateInfo(gfx::TextureUsageBit usage
return texInfo;
}

gfx::TextureViewInfo TextureCube::getGfxTextureViewCreateInfo(gfx::Texture *texture, gfx::Format format, uint32_t baseLevel, uint32_t levelCount) {
gfx::TextureViewInfo texViewInfo;
texViewInfo.type = gfx::TextureType::CUBE;
texViewInfo.baseLayer = 0;
texViewInfo.layerCount = 6;
texViewInfo.texture = texture;
texViewInfo.format = format;
texViewInfo.baseLevel = baseLevel;
texViewInfo.levelCount = levelCount;
return texViewInfo;
}

void TextureCube::initDefault(const cc::optional<ccstd::string> &uuid) {
Super::initDefault(uuid);

Expand Down
1 change: 1 addition & 0 deletions native/cocos/core/assets/TextureCube.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class TextureCube final : public SimpleTexture {
void deserialize(const cc::any &serializedData, const cc::any &handle) override;

gfx::TextureInfo getGfxTextureCreateInfo(gfx::TextureUsageBit usage, gfx::Format format, uint32_t levelCount, gfx::TextureFlagBit flags) override;
gfx::TextureViewInfo getGfxTextureViewCreateInfo(gfx::Texture *texture, gfx::Format format, uint32_t baseLevel, uint32_t levelCount) override;

void initDefault(const cc::optional<ccstd::string> &uuid) override;

Expand Down
4 changes: 3 additions & 1 deletion native/cocos/core/builtin/DebugInfos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ ccstd::unordered_map<int, ccstd::string> debugInfos = {
{ 3121, "Can't find a texture format supported by the current platform! Please add a fallback format in the editor." },
{ 3122, "Error Texture in %s." },
{ 3123, "Set same texture %s." },
{ 3124, "Texture: setMipRange failed because base level is larger than max level" },
{ 3300, "Rect width exceeds maximum margin: %s" },
{ 3301, "Rect height exceeds maximum margin: %s" },
{ 3500, "0 priority is forbidden for fixed priority since it's used for scene graph based priority." },
Expand Down Expand Up @@ -191,7 +192,7 @@ ccstd::unordered_map<int, ccstd::string> debugInfos = {
{ 3904, "motion path of target [%s] in prop [%s] frame [%s] is not valid" },
{ 3905, "sprite frames must be an Array." },
{ 3906, "Can't find easing type [%s]" },
{ 3907, "animator not added or already removed" },
{ 3907, "Animation state is not playing or already removed" },
{ 3912, "already-playing" },
{ 3920, "Current context does not allow root motion." },
{ 3921, "You provided a ill-formed track path. The last component of track path should be property key, or the setter should not be empty." },
Expand Down Expand Up @@ -436,6 +437,7 @@ ccstd::unordered_map<int, ccstd::string> debugInfos = {
{ 14100, "Pool.destroy no longer take a function as parameter, Please specify destruct function in the construction of Pool instead" },
{ 14200, "Can not update a static mesh." },
{ 14201, "The primitiveIndex is out of range." },
{ 14300, "Can not keep world transform due to the zero scaling of parent node" },

};
}//namespace cc
Loading

0 comments on commit e849e9c

Please sign in to comment.