mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 17:42:41 +08:00
gfx: swapchain refactor (#3751)
* gfx: swapchain * acquire/release/surface on swapchain * fix swapchain texture creation * acquire/present back on device * formats are swapchain-specific * swapchain: vk works * enable device agent * format fix * update gfxdef * fix enum decl * pipeline adapt * minor * vk: compress attr locations directly in SPIR-V * gles3 adjust * InputAssembler owns an DrawInfo * gles2 adapt * texture keep track of its hash * device cached states * format * glslang finalize * buffer view adapt * fg: subpass support * minor * 3.4 adapt * profiler adapt * buffer update frequency detection * minor * base commit * swapchain works on metal * spirv * mtltexture issue * remote test code * depthtexture * revert ifdef USE_METAL * ios swapchain header * fix some triple buffer issues * resize accept surface transform Co-authored-by: Zeqiang Li <Zeqiang-li@outlook.com>
This commit is contained in:
@@ -29,11 +29,15 @@
|
||||
#include "VKCommands.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKTexture.h"
|
||||
#include "gfx-base/GFXDef.h"
|
||||
#include "gfx-vulkan/VKSwapchain.h"
|
||||
|
||||
namespace cc {
|
||||
namespace gfx {
|
||||
|
||||
CCVKTexture::CCVKTexture() = default;
|
||||
CCVKTexture::CCVKTexture() {
|
||||
_typedID = generateObjectID<decltype(this)>();
|
||||
}
|
||||
|
||||
CCVKTexture::~CCVKTexture() {
|
||||
destroy();
|
||||
@@ -41,17 +45,17 @@ CCVKTexture::~CCVKTexture() {
|
||||
|
||||
void CCVKTexture::doInit(const TextureInfo & /*info*/) {
|
||||
_gpuTexture = CC_NEW(CCVKGPUTexture);
|
||||
_gpuTexture->type = _type;
|
||||
_gpuTexture->format = _format;
|
||||
_gpuTexture->usage = _usage;
|
||||
_gpuTexture->width = _width;
|
||||
_gpuTexture->height = _height;
|
||||
_gpuTexture->depth = _depth;
|
||||
_gpuTexture->type = _info.type;
|
||||
_gpuTexture->format = _info.format;
|
||||
_gpuTexture->usage = _info.usage;
|
||||
_gpuTexture->width = _info.width;
|
||||
_gpuTexture->height = _info.height;
|
||||
_gpuTexture->depth = _info.depth;
|
||||
_gpuTexture->arrayLayers = _info.layerCount;
|
||||
_gpuTexture->mipLevels = _info.levelCount;
|
||||
_gpuTexture->samples = _info.samples;
|
||||
_gpuTexture->flags = _info.flags;
|
||||
_gpuTexture->size = _size;
|
||||
_gpuTexture->arrayLayers = _layerCount;
|
||||
_gpuTexture->mipLevels = _levelCount;
|
||||
_gpuTexture->samples = _samples;
|
||||
_gpuTexture->flags = _flags;
|
||||
|
||||
cmdFuncCCVKCreateTexture(CCVKDevice::getInstance(), _gpuTexture);
|
||||
|
||||
@@ -72,12 +76,12 @@ void CCVKTexture::doInit(const TextureViewInfo &info) {
|
||||
|
||||
void CCVKTexture::createTextureView() {
|
||||
_gpuTextureView->gpuTexture = _gpuTexture;
|
||||
_gpuTextureView->type = _type;
|
||||
_gpuTextureView->format = _format;
|
||||
_gpuTextureView->baseLevel = _baseLevel;
|
||||
_gpuTextureView->levelCount = _levelCount;
|
||||
_gpuTextureView->baseLayer = _baseLayer;
|
||||
_gpuTextureView->layerCount = _layerCount;
|
||||
_gpuTextureView->type = _viewInfo.type;
|
||||
_gpuTextureView->format = _viewInfo.format;
|
||||
_gpuTextureView->baseLevel = _viewInfo.baseLevel;
|
||||
_gpuTextureView->levelCount = _viewInfo.levelCount;
|
||||
_gpuTextureView->baseLayer = _viewInfo.baseLayer;
|
||||
_gpuTextureView->layerCount = _viewInfo.layerCount;
|
||||
cmdFuncCCVKCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView);
|
||||
}
|
||||
|
||||
@@ -103,6 +107,8 @@ void CCVKTexture::doDestroy() {
|
||||
}
|
||||
|
||||
void CCVKTexture::doResize(uint width, uint height, uint size) {
|
||||
if (!width || !height) return;
|
||||
|
||||
if (!_gpuTexture->memoryless) {
|
||||
CCVKDevice::getInstance()->getMemoryStatus().textureSize -= _size;
|
||||
}
|
||||
@@ -122,5 +128,34 @@ void CCVKTexture::doResize(uint width, uint height, uint size) {
|
||||
cmdFuncCCVKCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView);
|
||||
}
|
||||
|
||||
///////////////////////////// Swapchain Specific /////////////////////////////
|
||||
|
||||
void CCVKTexture::doInit(const SwapchainTextureInfo & /*info*/) {
|
||||
_gpuTexture = CC_NEW(CCVKGPUTexture);
|
||||
_gpuTexture->type = _info.type;
|
||||
_gpuTexture->format = _info.format;
|
||||
_gpuTexture->usage = _info.usage;
|
||||
_gpuTexture->width = _info.width;
|
||||
_gpuTexture->height = _info.height;
|
||||
_gpuTexture->depth = _info.depth;
|
||||
_gpuTexture->arrayLayers = _info.layerCount;
|
||||
_gpuTexture->mipLevels = _info.levelCount;
|
||||
_gpuTexture->flags = _info.flags;
|
||||
_gpuTexture->samples = _info.samples;
|
||||
_gpuTexture->size = _size;
|
||||
|
||||
_gpuTexture->swapchain = static_cast<CCVKSwapchain *>(_swapchain)->gpuSwapchain();
|
||||
_gpuTexture->memoryless = true;
|
||||
|
||||
_gpuTextureView = CC_NEW(CCVKGPUTextureView);
|
||||
_gpuTextureView->gpuTexture = _gpuTexture;
|
||||
_gpuTextureView->type = _viewInfo.type;
|
||||
_gpuTextureView->format = _viewInfo.format;
|
||||
_gpuTextureView->baseLevel = _viewInfo.baseLevel;
|
||||
_gpuTextureView->levelCount = _viewInfo.levelCount;
|
||||
_gpuTextureView->baseLayer = _viewInfo.baseLayer;
|
||||
_gpuTextureView->layerCount = _viewInfo.layerCount;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace cc
|
||||
|
||||
Reference in New Issue
Block a user