Files
cocos4/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp
T
pandamicro 12072ffc62 Merge v3.5.1 zqb branch to v3.6 (#11637)
* support asset property preview (#11017)

(cherry picked from commit 85769cf8f81459b5ad98ccab4138420009572a32)

* show mesh asset thumbnail (#10981)

* V3.5.1 noise particle (#11003)

* add cpu & gpu noise for particle

* add some params & change particle noise shader

* change shader

* add cpu noise particle

* add noise preview

* run generation when preview

* revert shaders

* remove unused statements

* add particle noise module

* change noise preview interface

* add invisible to remap

* remove get deltaTime

* set noiseModule private

* fix eslint

* feat: add noise preview (#11260)

* [Optimize] asset editing undo (#10779)

* edit render-pipeline

* support renderpipeline undo

* optimize material editing undo

* reset last record data

* temporary not support animation-mask undo

* support animation-mask edit undo

* animation mask remove _jointMasks

* Animation clip embedded players (#11320)

* Animation clip subregions

* Log

* Test

* Eval

* Update

* Update

* No longer use animation state to implement clip motion

* Clear subregions

* Fix

* Mark subregion as editor extendable

* Animation clip subregion player path

* fix isnan(0.0) with webgl1.0 (#11262)

* fix isinf(0.0)==true with webgl1.0

* code style

* fix specular params with surface toon (#11265)

* code format and add sliders for parameters (#11266)

* Broadcasting of animation state\'s speed

* Fix

* Rename

* Update

* Fix

* Revert "No longer use animation state to implement clip motion"

This reverts commit 20755f9ec525b27b5b9a515c8dd687349aa4c637.

* Revert some exotic changes

* Update docs

Co-authored-by: jk20012001 <jkregister@163.com>
Co-authored-by: 徐兵 <49358166+xubing0906@users.noreply.github.com>

* fix skinning model split (#11378)

* fix skinning model split

* rename function _resizeMaxJointForDS

Co-authored-by: zhakesi <zhakesi@foxmail.com>

* [ci skip][AUTO]: Automated genbindings update: d823cbba1f7ce8284da28458c26534da2e033961  (#11378) (#11383)

Co-authored-by: cocos-robot <cocos-robot@cocos.com>

* use stop emitting instead (#11381)

* add stop emitting api

* use stop emitting instead

* Update cocos/particle/particle-system.ts

Co-authored-by: Leslie Leigh (李的序) <leslieleigh@outlook.com>

Co-authored-by: Leslie Leigh (李的序) <leslieleigh@outlook.com>

* fix: imageData fault tolerance (#11374)

* fix: imageData fault tolerance

* chore: when data is an empty array,stop the function

* material  undo updating effects list (#11409)

* modify noise module ui (#11433)

* use visible decorator to control the visibility of property (#11438)

* fix joints data with value nan (#11489)

* V3.5.2 CI Android NDK  set version to 21 (#11448) (#11492)

* Minor improvement

* Fix format

* Fix particle culler

* Improve particle culler

* Manually migrate joint data upload with texture in skinning model

* Update shaders for skinning model based on joint texture

* fis native skinning model with realtime-texture mode (#45)

Co-authored-by: zhakesi <zhakesi@foxmail.com>

* fix clangtidy (#46)

* Small tweaks

* modify code struct for skinning model (#47)

* modify code struct for skinning model

* update skinning chunk

Co-authored-by: 黄森斌 <arsen2010@126.com>
Co-authored-by: zxx43 <zxx43@hotmail.com>
Co-authored-by: 袁炜海 <35713518+dogodo-cc@users.noreply.github.com>
Co-authored-by: Leslie Leigh (李的序) <leslieleigh@outlook.com>
Co-authored-by: jk20012001 <jkregister@163.com>
Co-authored-by: 徐兵 <49358166+xubing0906@users.noreply.github.com>
Co-authored-by: zhakesi <liqiao@cocos.com>
Co-authored-by: zhakesi <zhakesi@foxmail.com>
Co-authored-by: Cocos Robot <48829427+cocos-robot@users.noreply.github.com>
Co-authored-by: cocos-robot <cocos-robot@cocos.com>
Co-authored-by: Santy-Wang <wh19930829@qq.com>
Co-authored-by: zhangxin <59186205+chichinohaha@users.noreply.github.com>
Co-authored-by: 江战 <40414978+PatriceJiang@users.noreply.github.com>
2022-06-24 15:10:45 +08:00

221 lines
10 KiB
C++

/****************************************************************************
Copyright (c) 2020-2022 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "GlobalDescriptorSetManager.h"
#include "Define.h"
#include "RenderInstancedQueue.h"
#include "gfx-base/GFXDevice.h"
namespace cc {
namespace pipeline {
void GlobalDSManager::activate(gfx::Device *device) {
_device = device;
_linearSampler = device->getSampler({
gfx::Filter::LINEAR,
gfx::Filter::LINEAR,
gfx::Filter::NONE,
gfx::Address::CLAMP,
gfx::Address::CLAMP,
gfx::Address::CLAMP,
});
_pointSampler = device->getSampler({
gfx::Filter::POINT,
gfx::Filter::POINT,
gfx::Filter::NONE,
gfx::Address::CLAMP,
gfx::Address::CLAMP,
gfx::Address::CLAMP,
});
//tips: for compatibility with old version, when maxVertexUniformVectors is 128, maxJoints = 30
uint maxJoints = (_device->getCapabilities().maxVertexUniformVectors - 38) / 3;
maxJoints = maxJoints < 256 ? maxJoints : 256;
SkinningJointCapacity::jointUniformCapacity = maxJoints;
UBOSkinning::initLayout(maxJoints);
setDescriptorSetLayout();
_descriptorSetLayout = device->createDescriptorSetLayout({globalDescriptorSetLayout.bindings});
_globalDescriptorSet = device->createDescriptorSet({_descriptorSetLayout});
}
void GlobalDSManager::bindBuffer(uint32_t binding, gfx::Buffer *buffer) {
if (_globalDescriptorSet != nullptr) {
_globalDescriptorSet->bindBuffer(binding, buffer);
}
for (const auto &pair : _descriptorSetMap) {
if (pair.second != nullptr) {
pair.second->bindBuffer(binding, buffer);
}
}
}
void GlobalDSManager::bindSampler(uint32_t binding, gfx::Sampler *sampler) {
if (_globalDescriptorSet != nullptr) {
_globalDescriptorSet->bindSampler(binding, sampler);
}
for (const auto &pair : _descriptorSetMap) {
if (pair.second != nullptr) {
pair.second->bindSampler(binding, sampler);
}
}
}
void GlobalDSManager::bindTexture(uint32_t binding, gfx::Texture *texture) {
if (_globalDescriptorSet != nullptr) {
_globalDescriptorSet->bindTexture(binding, texture);
}
for (const auto &pair : _descriptorSetMap) {
if (pair.second != nullptr) {
pair.second->bindTexture(binding, texture);
}
}
}
void GlobalDSManager::update() {
if (_globalDescriptorSet != nullptr) {
_globalDescriptorSet->update();
}
for (const auto &pair : _descriptorSetMap) {
if (pair.second != nullptr) {
pair.second->update();
}
}
}
gfx::DescriptorSet *GlobalDSManager::getOrCreateDescriptorSet(uint32_t idx) {
// The global descriptorSet is managed by the pipeline and binds the buffer
if (_descriptorSetMap.count(idx) <= 0 || (_descriptorSetMap.at(idx) == nullptr)) {
auto *descriptorSet = _device->createDescriptorSet({_descriptorSetLayout});
_descriptorSetMap.emplace(idx, descriptorSet);
const auto begin = static_cast<uint32_t>(PipelineGlobalBindings::UBO_GLOBAL);
const auto end = static_cast<uint32_t>(PipelineGlobalBindings::COUNT);
for (uint32_t i = begin; i < end; ++i) {
auto *const buffer = _globalDescriptorSet->getBuffer(i);
if (buffer != nullptr) {
descriptorSet->bindBuffer(i, buffer);
}
auto *const sampler = _globalDescriptorSet->getSampler(i);
if (sampler != nullptr) {
descriptorSet->bindSampler(i, sampler);
}
auto *const texture = _globalDescriptorSet->getTexture(i);
if (texture != nullptr) {
descriptorSet->bindTexture(i, texture);
}
}
auto *shadowUBO = _device->createBuffer({
gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST,
gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE,
UBOShadow::SIZE,
UBOShadow::SIZE,
gfx::BufferFlagBit::NONE,
});
_shadowUBOs.emplace_back(shadowUBO);
descriptorSet->bindBuffer(UBOShadow::BINDING, shadowUBO);
descriptorSet->update();
}
return _descriptorSetMap.at(idx);
}
void GlobalDSManager::destroy() {
_shadowUBOs.clear();
_descriptorSetMap.clear();
_descriptorSetLayout = nullptr;
_globalDescriptorSet = nullptr;
_linearSampler = nullptr;
_pointSampler = nullptr;
}
void GlobalDSManager::setDescriptorSetLayout() {
globalDescriptorSetLayout.bindings.resize(static_cast<size_t>(PipelineGlobalBindings::COUNT));
globalDescriptorSetLayout.blocks[UBOGlobal::NAME] = UBOGlobal::LAYOUT;
globalDescriptorSetLayout.bindings[UBOGlobal::BINDING] = UBOGlobal::DESCRIPTOR;
globalDescriptorSetLayout.blocks[UBOCamera::NAME] = UBOCamera::LAYOUT;
globalDescriptorSetLayout.bindings[UBOCamera::BINDING] = UBOCamera::DESCRIPTOR;
globalDescriptorSetLayout.blocks[UBOShadow::NAME] = UBOShadow::LAYOUT;
globalDescriptorSetLayout.bindings[UBOShadow::BINDING] = UBOShadow::DESCRIPTOR;
globalDescriptorSetLayout.samplers[SHADOWMAP::NAME] = SHADOWMAP::LAYOUT;
globalDescriptorSetLayout.bindings[SHADOWMAP::BINDING] = SHADOWMAP::DESCRIPTOR;
globalDescriptorSetLayout.samplers[ENVIRONMENT::NAME] = ENVIRONMENT::LAYOUT;
globalDescriptorSetLayout.bindings[ENVIRONMENT::BINDING] = ENVIRONMENT::DESCRIPTOR;
globalDescriptorSetLayout.samplers[SPOTLIGHTINGMAP::NAME] = SPOTLIGHTINGMAP::LAYOUT;
globalDescriptorSetLayout.bindings[SPOTLIGHTINGMAP::BINDING] = SPOTLIGHTINGMAP::DESCRIPTOR;
globalDescriptorSetLayout.samplers[DIFFUSEMAP::NAME] = DIFFUSEMAP::LAYOUT;
globalDescriptorSetLayout.bindings[DIFFUSEMAP::BINDING] = DIFFUSEMAP::DESCRIPTOR;
localDescriptorSetLayout.bindings.resize(static_cast<size_t>(ModelLocalBindings::COUNT));
localDescriptorSetLayout.blocks[UBOLocalBatched::NAME] = UBOLocalBatched::LAYOUT;
localDescriptorSetLayout.bindings[UBOLocalBatched::BINDING] = UBOLocalBatched::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOLocal::NAME] = UBOLocal::LAYOUT;
localDescriptorSetLayout.bindings[UBOLocal::BINDING] = UBOLocal::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOWorldBound::NAME] = UBOWorldBound::LAYOUT;
localDescriptorSetLayout.bindings[UBOWorldBound::BINDING] = UBOWorldBound::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOForwardLight::NAME] = UBOForwardLight::LAYOUT;
localDescriptorSetLayout.bindings[UBOForwardLight::BINDING] = UBOForwardLight::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOSkinningTexture::NAME] = UBOSkinningTexture::LAYOUT;
localDescriptorSetLayout.bindings[UBOSkinningTexture::BINDING] = UBOSkinningTexture::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOSkinningAnimation::NAME] = UBOSkinningAnimation::LAYOUT;
localDescriptorSetLayout.bindings[UBOSkinningAnimation::BINDING] = UBOSkinningAnimation::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOSkinning::NAME] = UBOSkinning::layout;
localDescriptorSetLayout.bindings[UBOSkinning::BINDING] = UBOSkinning::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOMorph::NAME] = UBOMorph::LAYOUT;
localDescriptorSetLayout.bindings[UBOMorph::BINDING] = UBOMorph::DESCRIPTOR;
localDescriptorSetLayout.blocks[UBOUILocal::NAME] = UBOUILocal::LAYOUT;
localDescriptorSetLayout.bindings[UBOUILocal::BINDING] = UBOUILocal::DESCRIPTOR;
localDescriptorSetLayout.samplers[JOINTTEXTURE::NAME] = JOINTTEXTURE::LAYOUT;
localDescriptorSetLayout.bindings[JOINTTEXTURE::BINDING] = JOINTTEXTURE::DESCRIPTOR;
localDescriptorSetLayout.samplers[REALTIMEJOINTTEXTURE::NAME] = REALTIMEJOINTTEXTURE::LAYOUT;
localDescriptorSetLayout.bindings[REALTIMEJOINTTEXTURE::BINDING] = REALTIMEJOINTTEXTURE::DESCRIPTOR;
localDescriptorSetLayout.samplers[POSITIONMORPH::NAME] = POSITIONMORPH::LAYOUT;
localDescriptorSetLayout.bindings[POSITIONMORPH::BINDING] = POSITIONMORPH::DESCRIPTOR;
localDescriptorSetLayout.samplers[NORMALMORPH::NAME] = NORMALMORPH::LAYOUT;
localDescriptorSetLayout.bindings[NORMALMORPH::BINDING] = NORMALMORPH::DESCRIPTOR;
localDescriptorSetLayout.samplers[TANGENTMORPH::NAME] = TANGENTMORPH::LAYOUT;
localDescriptorSetLayout.bindings[TANGENTMORPH::BINDING] = TANGENTMORPH::DESCRIPTOR;
localDescriptorSetLayout.samplers[LIGHTMAPTEXTURE::NAME] = LIGHTMAPTEXTURE::LAYOUT;
localDescriptorSetLayout.bindings[LIGHTMAPTEXTURE::BINDING] = LIGHTMAPTEXTURE::DESCRIPTOR;
localDescriptorSetLayout.samplers[SPRITETEXTURE::NAME] = SPRITETEXTURE::LAYOUT;
localDescriptorSetLayout.bindings[SPRITETEXTURE::BINDING] = SPRITETEXTURE::DESCRIPTOR;
localDescriptorSetLayout.samplers[REFLECTIONTEXTURE::NAME] = REFLECTIONTEXTURE::LAYOUT;
localDescriptorSetLayout.bindings[REFLECTIONTEXTURE::BINDING] = REFLECTIONTEXTURE::DESCRIPTOR;
localDescriptorSetLayout.storeImages[REFLECTIONSTORAGE::NAME] = REFLECTIONSTORAGE::LAYOUT;
localDescriptorSetLayout.bindings[REFLECTIONSTORAGE::BINDING] = REFLECTIONSTORAGE::DESCRIPTOR;
}
} // namespace pipeline
} // namespace cc