mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
misc fixes
This commit is contained in:
@@ -21,8 +21,8 @@ bool RenderPassAgent::initialize(const RenderPassInfo &info) {
|
||||
|
||||
_colorAttachments = info.colorAttachments;
|
||||
_depthStencilAttachment = info.depthStencilAttachment;
|
||||
_subPasses = info.subPasses;
|
||||
_hash = computeHash(info);
|
||||
_subpasses = info.subpasses;
|
||||
_hash = computeHash();
|
||||
|
||||
ENQUEUE_MESSAGE_2(
|
||||
((DeviceAgent *)_device)->getMessageQueue(),
|
||||
|
||||
@@ -10,34 +10,6 @@ const DescriptorType DESCRIPTOR_BUFFER_TYPE = DescriptorType::STORAGE_BUFFER | D
|
||||
const DescriptorType DESCRIPTOR_TEXTURE_TYPE = DescriptorType::SAMPLER_TEXTURE | DescriptorType::SAMPLER | DescriptorType::TEXTURE | DescriptorType::STORAGE_IMAGE | DescriptorType::INPUT_ATTACHMENT;
|
||||
const DescriptorType DESCRIPTOR_DYNAMIC_TYPE = DescriptorType::DYNAMIC_STORAGE_BUFFER | DescriptorType::DYNAMIC_UNIFORM_BUFFER;
|
||||
|
||||
const AccessType AccessTypeV::INDIRECT_BUFFER = AccessType::INDIRECT_BUFFER;
|
||||
const AccessType AccessTypeV::INDEX_BUFFER = AccessType::INDEX_BUFFER;
|
||||
const AccessType AccessTypeV::VERTEX_BUFFER = AccessType::VERTEX_BUFFER;
|
||||
const AccessType AccessTypeV::VERTEX_SHADER_READ_UNIFORM_BUFFER = AccessType::VERTEX_SHADER_READ_UNIFORM_BUFFER;
|
||||
const AccessType AccessTypeV::VERTEX_SHADER_READ_TEXTURE = AccessType::VERTEX_SHADER_READ_TEXTURE;
|
||||
const AccessType AccessTypeV::VERTEX_SHADER_READ_OTHER = AccessType::VERTEX_SHADER_READ_OTHER;
|
||||
const AccessType AccessTypeV::FRAGMENT_SHADER_READ_UNIFORM_BUFFER = AccessType::FRAGMENT_SHADER_READ_UNIFORM_BUFFER;
|
||||
const AccessType AccessTypeV::FRAGMENT_SHADER_READ_TEXTURE = AccessType::FRAGMENT_SHADER_READ_TEXTURE;
|
||||
const AccessType AccessTypeV::FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT = AccessType::FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT;
|
||||
const AccessType AccessTypeV::FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT = AccessType::FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT;
|
||||
const AccessType AccessTypeV::FRAGMENT_SHADER_READ_OTHER = AccessType::FRAGMENT_SHADER_READ_OTHER;
|
||||
const AccessType AccessTypeV::COLOR_ATTACHMENT_READ = AccessType::COLOR_ATTACHMENT_READ;
|
||||
const AccessType AccessTypeV::DEPTH_STENCIL_ATTACHMENT_READ = AccessType::DEPTH_STENCIL_ATTACHMENT_READ;
|
||||
const AccessType AccessTypeV::COMPUTE_SHADER_READ_UNIFORM_BUFFER = AccessType::COMPUTE_SHADER_READ_UNIFORM_BUFFER;
|
||||
const AccessType AccessTypeV::COMPUTE_SHADER_READ_TEXTURE = AccessType::COMPUTE_SHADER_READ_TEXTURE;
|
||||
const AccessType AccessTypeV::COMPUTE_SHADER_READ_OTHER = AccessType::COMPUTE_SHADER_READ_OTHER;
|
||||
const AccessType AccessTypeV::TRANSFER_READ = AccessType::TRANSFER_READ;
|
||||
const AccessType AccessTypeV::HOST_READ = AccessType::HOST_READ;
|
||||
const AccessType AccessTypeV::PRESENT = AccessType::PRESENT;
|
||||
const AccessType AccessTypeV::VERTEX_SHADER_WRITE = AccessType::VERTEX_SHADER_WRITE;
|
||||
const AccessType AccessTypeV::FRAGMENT_SHADER_WRITE = AccessType::FRAGMENT_SHADER_WRITE;
|
||||
const AccessType AccessTypeV::COLOR_ATTACHMENT_WRITE = AccessType::COLOR_ATTACHMENT_WRITE;
|
||||
const AccessType AccessTypeV::DEPTH_STENCIL_ATTACHMENT_WRITE = AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE;
|
||||
const AccessType AccessTypeV::COMPUTE_SHADER_WRITE = AccessType::COMPUTE_SHADER_WRITE;
|
||||
const AccessType AccessTypeV::TRANSFER_WRITE = AccessType::TRANSFER_WRITE;
|
||||
const AccessType AccessTypeV::HOST_PREINITIALIZED = AccessType::HOST_PREINITIALIZED;
|
||||
const AccessType AccessTypeV::HOST_WRITE = AccessType::HOST_WRITE;
|
||||
|
||||
const FormatInfo GFX_FORMAT_INFOS[] = {
|
||||
{"UNKNOWN", 0, 0, FormatType::NONE, false, false, false, false},
|
||||
{"A8", 1, 1, FormatType::UNORM, true, false, false, false},
|
||||
|
||||
@@ -26,7 +26,7 @@ class Window;
|
||||
class Context;
|
||||
|
||||
#define GFX_MAX_ATTACHMENTS 4
|
||||
#define GFX_INVALID_BINDING ((uint8_t)-1)
|
||||
#define GFX_INVALID_BINDING ((uint)-1)
|
||||
#define GFX_INVALID_HANDLE ((uint)-1)
|
||||
|
||||
enum class ObjectType {
|
||||
@@ -542,36 +542,6 @@ enum class AccessType {
|
||||
HOST_WRITE, // Written on the host
|
||||
};
|
||||
|
||||
namespace AccessTypeV {
|
||||
extern const AccessType INDIRECT_BUFFER;
|
||||
extern const AccessType INDEX_BUFFER;
|
||||
extern const AccessType VERTEX_BUFFER;
|
||||
extern const AccessType VERTEX_SHADER_READ_UNIFORM_BUFFER;
|
||||
extern const AccessType VERTEX_SHADER_READ_TEXTURE;
|
||||
extern const AccessType VERTEX_SHADER_READ_OTHER;
|
||||
extern const AccessType FRAGMENT_SHADER_READ_UNIFORM_BUFFER;
|
||||
extern const AccessType FRAGMENT_SHADER_READ_TEXTURE;
|
||||
extern const AccessType FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT;
|
||||
extern const AccessType FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT;
|
||||
extern const AccessType FRAGMENT_SHADER_READ_OTHER;
|
||||
extern const AccessType COLOR_ATTACHMENT_READ;
|
||||
extern const AccessType DEPTH_STENCIL_ATTACHMENT_READ;
|
||||
extern const AccessType COMPUTE_SHADER_READ_UNIFORM_BUFFER;
|
||||
extern const AccessType COMPUTE_SHADER_READ_TEXTURE;
|
||||
extern const AccessType COMPUTE_SHADER_READ_OTHER;
|
||||
extern const AccessType TRANSFER_READ;
|
||||
extern const AccessType HOST_READ;
|
||||
extern const AccessType PRESENT;
|
||||
extern const AccessType VERTEX_SHADER_WRITE;
|
||||
extern const AccessType FRAGMENT_SHADER_WRITE;
|
||||
extern const AccessType COLOR_ATTACHMENT_WRITE;
|
||||
extern const AccessType DEPTH_STENCIL_ATTACHMENT_WRITE;
|
||||
extern const AccessType COMPUTE_SHADER_WRITE;
|
||||
extern const AccessType TRANSFER_WRITE;
|
||||
extern const AccessType HOST_PREINITIALIZED;
|
||||
extern const AccessType HOST_WRITE;
|
||||
} // namespace AccessTypeV
|
||||
|
||||
typedef cc::vector<AccessType> AccessTypeList;
|
||||
|
||||
enum class PipelineBindPoint {
|
||||
@@ -959,7 +929,7 @@ struct SamplerInfo {
|
||||
Address addressU = Address::WRAP;
|
||||
Address addressV = Address::WRAP;
|
||||
Address addressW = Address::WRAP;
|
||||
uint maxAnisotropy = 16;
|
||||
uint maxAnisotropy = 0u;
|
||||
ComparisonFunc cmpFunc = ComparisonFunc::NEVER;
|
||||
Color borderColor;
|
||||
uint minLOD = 0;
|
||||
@@ -1082,7 +1052,7 @@ struct ShaderInfo {
|
||||
UniformInputAttachmentList subpassInputs;
|
||||
};
|
||||
|
||||
typedef cc::vector<Buffer *> BufferList;
|
||||
typedef cc::vector<Buffer *> BufferList;
|
||||
typedef cc::vector<TextureBarrier *> TextureBarrierList;
|
||||
|
||||
struct InputAssemblerInfo {
|
||||
@@ -1114,20 +1084,20 @@ struct DepthStencilAttachment {
|
||||
AccessType endAccess = AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE;
|
||||
};
|
||||
|
||||
struct SubPassInfo {
|
||||
cc::vector<uint8_t> inputs;
|
||||
cc::vector<uint8_t> colors;
|
||||
cc::vector<uint8_t> resolves;
|
||||
uint8_t depthStencil = GFX_INVALID_BINDING;
|
||||
cc::vector<uint8_t> preserves;
|
||||
struct SubpassInfo {
|
||||
cc::vector<uint> inputs;
|
||||
cc::vector<uint> colors;
|
||||
cc::vector<uint> resolves;
|
||||
cc::vector<uint> preserves;
|
||||
uint depthStencil = GFX_INVALID_BINDING;
|
||||
};
|
||||
|
||||
typedef cc::vector<SubPassInfo> SubPassInfoList;
|
||||
typedef cc::vector<SubpassInfo> SubpassInfoList;
|
||||
|
||||
struct RenderPassInfo {
|
||||
ColorAttachmentList colorAttachments;
|
||||
DepthStencilAttachment depthStencilAttachment;
|
||||
SubPassInfoList subPasses;
|
||||
SubpassInfoList subpasses;
|
||||
};
|
||||
|
||||
struct GlobalBarrierInfo {
|
||||
@@ -1140,7 +1110,7 @@ struct TextureBarrierInfo {
|
||||
vector<AccessType> prevAccesses;
|
||||
vector<AccessType> nextAccesses;
|
||||
|
||||
bool discardContents = false;
|
||||
bool discardContents = false;
|
||||
|
||||
Queue *srcQueue = nullptr;
|
||||
Queue *dstQueue = nullptr;
|
||||
|
||||
@@ -13,35 +13,35 @@ RenderPass::~RenderPass() {
|
||||
}
|
||||
|
||||
// Based on render pass compatibility
|
||||
uint RenderPass::computeHash(const RenderPassInfo &info) {
|
||||
uint seed = info.colorAttachments.size() * 2 + 2;
|
||||
if (info.subPasses.size()) {
|
||||
for (const SubPassInfo &subPass : info.subPasses) {
|
||||
uint RenderPass::computeHash() {
|
||||
uint seed = _colorAttachments.size() * 2 + 2;
|
||||
if (_subpasses.size()) {
|
||||
for (const SubpassInfo &subPass : _subpasses) {
|
||||
for (const uint8_t iaIndex : subPass.inputs) {
|
||||
if (iaIndex >= info.colorAttachments.size()) break;
|
||||
const ColorAttachment &ia = info.colorAttachments[iaIndex];
|
||||
if (iaIndex >= _colorAttachments.size()) break;
|
||||
const ColorAttachment &ia = _colorAttachments[iaIndex];
|
||||
seed ^= (uint)(ia.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)ia.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
for (const uint8_t caIndex : subPass.colors) {
|
||||
if (caIndex >= info.colorAttachments.size()) break;
|
||||
const ColorAttachment &ca = info.colorAttachments[caIndex];
|
||||
if (caIndex >= _colorAttachments.size()) break;
|
||||
const ColorAttachment &ca = _colorAttachments[caIndex];
|
||||
seed ^= (uint)(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)ca.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
if (subPass.depthStencil < info.colorAttachments.size()) {
|
||||
const ColorAttachment &ds = info.colorAttachments[subPass.depthStencil];
|
||||
if (subPass.depthStencil < _colorAttachments.size()) {
|
||||
const ColorAttachment &ds = _colorAttachments[subPass.depthStencil];
|
||||
seed ^= (uint)(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)ds.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const ColorAttachment &colorAttachment : info.colorAttachments) {
|
||||
for (const ColorAttachment &colorAttachment : _colorAttachments) {
|
||||
seed ^= (uint)(colorAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)colorAttachment.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
seed ^= (uint)(info.depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)info.depthStencilAttachment.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)(_depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)_depthStencilAttachment.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
|
||||
return seed;
|
||||
|
||||
@@ -11,23 +11,22 @@ public:
|
||||
RenderPass(Device *device);
|
||||
virtual ~RenderPass();
|
||||
|
||||
static uint computeHash(const RenderPassInfo &info);
|
||||
|
||||
virtual bool initialize(const RenderPassInfo &info) = 0;
|
||||
virtual void destroy() = 0;
|
||||
|
||||
CC_INLINE Device *getDevice() const { return _device; }
|
||||
CC_INLINE const ColorAttachmentList &getColorAttachments() const { return _colorAttachments; }
|
||||
CC_INLINE const DepthStencilAttachment &getDepthStencilAttachment() const { return _depthStencilAttachment; }
|
||||
CC_INLINE const SubPassInfoList &getSubPasses() const { return _subPasses; }
|
||||
CC_INLINE const SubpassInfoList &getSubpasses() const { return _subpasses; }
|
||||
CC_INLINE uint getHash() const { return _hash; }
|
||||
|
||||
protected:
|
||||
uint computeHash();
|
||||
|
||||
Device *_device = nullptr;
|
||||
ColorAttachmentList _colorAttachments;
|
||||
DepthStencilAttachment _depthStencilAttachment;
|
||||
SubPassInfoList _subPasses;
|
||||
SubpassInfoList _subpasses;
|
||||
uint _hash = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ bool GLES2RenderPass::initialize(const RenderPassInfo &info) {
|
||||
_gpuRenderPass->colorAttachments = _colorAttachments;
|
||||
_gpuRenderPass->depthStencilAttachment = _depthStencilAttachment;
|
||||
|
||||
_hash = computeHash(info);
|
||||
_hash = computeHash();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ bool GLES3RenderPass::initialize(const RenderPassInfo &info) {
|
||||
_gpuRenderPass->colorAttachments = _colorAttachments;
|
||||
_gpuRenderPass->depthStencilAttachment = _depthStencilAttachment;
|
||||
|
||||
_hash = computeHash(info);
|
||||
_hash = computeHash();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ bool CCMTLRenderPass::initialize(const RenderPassInfo &info) {
|
||||
_mtlRenderPassDescriptor.stencilAttachment.loadAction = mu::toMTLLoadAction(_depthStencilAttachment.stencilLoadOp);
|
||||
_mtlRenderPassDescriptor.stencilAttachment.storeAction = mu::toMTLStoreAction(_depthStencilAttachment.stencilStoreOp);
|
||||
|
||||
_hash = computeHash(info);
|
||||
_hash = computeHash();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
|
||||
attachmentDescriptions[colorAttachmentCount].finalLayout = ThsvsAccessMap[dstAccess].imageLayout;
|
||||
}
|
||||
|
||||
size_t subpassCount = gpuRenderPass->subPasses.size();
|
||||
size_t subpassCount = gpuRenderPass->subpasses.size();
|
||||
attachmentReferences.clear();
|
||||
subpassDependencies.clear();
|
||||
|
||||
@@ -280,9 +280,37 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
|
||||
if (hasDepth) subpassDescriptions[0].pDepthStencilAttachment = &attachmentReferences.back();
|
||||
|
||||
// explicitly declare dependencies if needed
|
||||
VkSubpassDependency dependency{0, VK_SUBPASS_EXTERNAL};
|
||||
auto dependencyCheck = [&dependency, colorAttachmentCount, gpuRenderPass](const VkAttachmentReference &ref, VkPipelineStageFlags srcStage, VkAccessFlags srcAccess) {
|
||||
if (attachmentDescriptions[ref.attachment].finalLayout != ref.layout) {
|
||||
VkSubpassDependency beginDependency = {VK_SUBPASS_EXTERNAL, 0, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT};
|
||||
auto beginDependencyCheck = [&beginDependency, colorAttachmentCount, gpuRenderPass](const VkAttachmentReference &ref, VkPipelineStageFlags dstStage, VkAccessFlags dstAccess) {
|
||||
const VkAttachmentDescription &desc = attachmentDescriptions[ref.attachment];
|
||||
if (desc.loadOp != VK_ATTACHMENT_LOAD_OP_DONT_CARE && desc.initialLayout != ref.layout) {
|
||||
AccessType beginAccess = AccessType::NONE;
|
||||
if (ref.attachment < colorAttachmentCount) {
|
||||
beginAccess = gpuRenderPass->colorAttachments[ref.attachment].beginAccess;
|
||||
} else {
|
||||
beginAccess = gpuRenderPass->depthStencilAttachment.beginAccess;
|
||||
}
|
||||
const ThsvsVkAccessInfo &info = ThsvsAccessMap[THSVS_ACCESS_TYPES[(uint)beginAccess]];
|
||||
beginDependency.srcStageMask |= info.stageMask;
|
||||
beginDependency.srcAccessMask |= info.accessMask;
|
||||
beginDependency.dstStageMask |= dstStage;
|
||||
beginDependency.dstAccessMask |= dstAccess;
|
||||
}
|
||||
};
|
||||
for (size_t j = 0u; j < subpassDescriptions[0].colorAttachmentCount; ++j) {
|
||||
beginDependencyCheck(subpassDescriptions[0].pColorAttachments[j], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
|
||||
}
|
||||
if (subpassDescriptions[0].pDepthStencilAttachment) {
|
||||
beginDependencyCheck(*subpassDescriptions[0].pDepthStencilAttachment, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
|
||||
}
|
||||
if (beginDependency.dstAccessMask) {
|
||||
subpassDependencies.push_back(beginDependency);
|
||||
}
|
||||
|
||||
VkSubpassDependency endDependency{0, VK_SUBPASS_EXTERNAL};
|
||||
auto endDependencyCheck = [&endDependency, colorAttachmentCount, gpuRenderPass](const VkAttachmentReference &ref, VkPipelineStageFlags srcStage, VkAccessFlags srcAccess) {
|
||||
const VkAttachmentDescription &desc = attachmentDescriptions[ref.attachment];
|
||||
if (desc.storeOp == VK_ATTACHMENT_STORE_OP_STORE && desc.finalLayout != ref.layout) {
|
||||
AccessType endAccess = AccessType::NONE;
|
||||
if (ref.attachment < colorAttachmentCount) {
|
||||
endAccess = gpuRenderPass->colorAttachments[ref.attachment].endAccess;
|
||||
@@ -291,21 +319,21 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
|
||||
}
|
||||
const ThsvsVkAccessInfo &info = ThsvsAccessMap[THSVS_ACCESS_TYPES[(uint)endAccess]];
|
||||
if (info.accessMask) {
|
||||
dependency.srcStageMask |= srcStage;
|
||||
dependency.srcAccessMask |= srcAccess;
|
||||
dependency.dstAccessMask |= info.accessMask;
|
||||
dependency.dstStageMask |= info.stageMask;
|
||||
endDependency.srcStageMask |= srcStage;
|
||||
endDependency.srcAccessMask |= srcAccess;
|
||||
endDependency.dstStageMask |= info.stageMask;
|
||||
endDependency.dstAccessMask |= info.accessMask;
|
||||
}
|
||||
}
|
||||
};
|
||||
for (size_t j = 0u; j < subpassDescriptions[0].colorAttachmentCount; ++j) {
|
||||
dependencyCheck(subpassDescriptions[0].pColorAttachments[j], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
|
||||
endDependencyCheck(subpassDescriptions[0].pColorAttachments[j], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
|
||||
}
|
||||
if (subpassDescriptions[0].pDepthStencilAttachment) {
|
||||
dependencyCheck(*subpassDescriptions[0].pDepthStencilAttachment, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
|
||||
endDependencyCheck(*subpassDescriptions[0].pDepthStencilAttachment, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
|
||||
}
|
||||
if (dependency.dstAccessMask) {
|
||||
subpassDependencies.push_back(dependency);
|
||||
if (endDependency.dstAccessMask) {
|
||||
subpassDependencies.push_back(endDependency);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,7 +474,11 @@ void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorS
|
||||
createInfo.pDescriptorUpdateEntries = entries.data();
|
||||
createInfo.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET;
|
||||
createInfo.descriptorSetLayout = gpuDescriptorSetLayout->vkDescriptorSetLayout;
|
||||
VK_CHECK(vkCreateDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, &createInfo, nullptr, &gpuDescriptorSetLayout->vkDescriptorUpdateTemplate));
|
||||
if (gpuDevice->minorVersion > 0) {
|
||||
VK_CHECK(vkCreateDescriptorUpdateTemplate(gpuDevice->vkDevice, &createInfo, nullptr, &gpuDescriptorSetLayout->vkDescriptorUpdateTemplate));
|
||||
} else {
|
||||
VK_CHECK(vkCreateDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, &createInfo, nullptr, &gpuDescriptorSetLayout->vkDescriptorUpdateTemplate));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -895,7 +927,11 @@ void CCVKCmdFuncDestroyDescriptorSetLayout(CCVKGPUDevice *gpuDevice, CCVKGPUDesc
|
||||
}
|
||||
|
||||
if (gpuDescriptorSetLayout->vkDescriptorUpdateTemplate != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, gpuDescriptorSetLayout->vkDescriptorUpdateTemplate, nullptr);
|
||||
if (gpuDevice->minorVersion > 0) {
|
||||
vkDestroyDescriptorUpdateTemplate(gpuDevice->vkDevice, gpuDescriptorSetLayout->vkDescriptorUpdateTemplate, nullptr);
|
||||
} else {
|
||||
vkDestroyDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, gpuDescriptorSetLayout->vkDescriptorUpdateTemplate, nullptr);
|
||||
}
|
||||
gpuDescriptorSetLayout->vkDescriptorUpdateTemplate = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,6 @@ bool CCVKContext::initialize(const ContextInfo &info) {
|
||||
};
|
||||
vector<const char *> requestedExtensions{
|
||||
VK_KHR_SURFACE_EXTENSION_NAME,
|
||||
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
|
||||
};
|
||||
|
||||
///////////////////// Instance Creation /////////////////////
|
||||
@@ -123,6 +122,19 @@ bool CCVKContext::initialize(const ContextInfo &info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint apiVersion = VK_API_VERSION_1_0;
|
||||
if (vkEnumerateInstanceVersion) {
|
||||
vkEnumerateInstanceVersion(&apiVersion);
|
||||
if (FORCE_MINOR_VERSION) {
|
||||
apiVersion = VK_MAKE_VERSION(1, FORCE_MINOR_VERSION - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
uint minorVersion = VK_VERSION_MINOR(apiVersion);
|
||||
if (minorVersion < 1) {
|
||||
requestedExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
uint availableLayerCount;
|
||||
VK_CHECK(vkEnumerateInstanceLayerProperties(&availableLayerCount, nullptr));
|
||||
vector<VkLayerProperties> supportedLayers(availableLayerCount);
|
||||
@@ -204,14 +216,6 @@ bool CCVKContext::initialize(const ContextInfo &info) {
|
||||
}
|
||||
}
|
||||
|
||||
uint apiVersion = VK_API_VERSION_1_0;
|
||||
if (vkEnumerateInstanceVersion) {
|
||||
vkEnumerateInstanceVersion(&apiVersion);
|
||||
if (FORCE_MINOR_VERSION) {
|
||||
apiVersion = VK_MAKE_VERSION(1, FORCE_MINOR_VERSION - 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
VkApplicationInfo app{VK_STRUCTURE_TYPE_APPLICATION_INFO};
|
||||
app.pEngineName = "Cocos Creator";
|
||||
app.apiVersion = apiVersion;
|
||||
@@ -364,12 +368,19 @@ bool CCVKContext::initialize(const ContextInfo &info) {
|
||||
_gpuContext->physicalDeviceProperties = physicalDeviceProperties[deviceIndex];
|
||||
vkGetPhysicalDeviceFeatures(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceFeatures);
|
||||
|
||||
if (_minorVersion >= 1 || checkExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
|
||||
vkGetPhysicalDeviceProperties2KHR(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceProperties2);
|
||||
_majorVersion = VK_VERSION_MAJOR(_gpuContext->physicalDeviceProperties.apiVersion);
|
||||
_minorVersion = VK_VERSION_MINOR(_gpuContext->physicalDeviceProperties.apiVersion);
|
||||
|
||||
if (_minorVersion >= 1 || checkExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
|
||||
_gpuContext->physicalDeviceFeatures2.pNext = &_gpuContext->physicalDeviceVulkan11Features;
|
||||
_gpuContext->physicalDeviceVulkan11Features.pNext = &_gpuContext->physicalDeviceVulkan12Features;
|
||||
vkGetPhysicalDeviceFeatures2KHR(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceFeatures2);
|
||||
if (_minorVersion >= 1) {
|
||||
vkGetPhysicalDeviceProperties2(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceProperties2);
|
||||
vkGetPhysicalDeviceFeatures2(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceFeatures2);
|
||||
} else {
|
||||
vkGetPhysicalDeviceProperties2KHR(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceProperties2);
|
||||
vkGetPhysicalDeviceFeatures2KHR(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceFeatures2);
|
||||
}
|
||||
}
|
||||
|
||||
vkGetPhysicalDeviceMemoryProperties(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceMemoryProperties);
|
||||
@@ -383,9 +394,6 @@ bool CCVKContext::initialize(const ContextInfo &info) {
|
||||
_gpuContext->vkSurface, &_gpuContext->queueFamilyPresentables[propertyIndex]);
|
||||
}
|
||||
|
||||
_majorVersion = VK_VERSION_MAJOR(_gpuContext->physicalDeviceProperties.apiVersion);
|
||||
_minorVersion = VK_VERSION_MINOR(_gpuContext->physicalDeviceProperties.apiVersion);
|
||||
|
||||
///////////////////// Swapchain Preperation /////////////////////
|
||||
|
||||
_colorFmt = Format::BGRA8;
|
||||
|
||||
@@ -122,7 +122,7 @@ bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) {
|
||||
vector<VkWriteDescriptorSet> &entries = instance.descriptorUpdateEntries;
|
||||
entries.resize(descriptorCount, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET});
|
||||
|
||||
for (size_t i = 0u, j = 0u; i < descriptorCount; i++) {
|
||||
for (size_t i = 0u, j = 0u; i < bindingCount; i++) {
|
||||
const VkDescriptorSetLayoutBinding &descriptor = gpuDescriptorSetLayout->vkBindings[i];
|
||||
for (size_t k = 0u; k < descriptor.descriptorCount; k++, j++) {
|
||||
entries[j].dstSet = instance.vkDescriptorSet;
|
||||
|
||||
@@ -80,6 +80,11 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
//const VkPhysicalDeviceVulkan11Features &deviceVulkan11Features = gpuContext->physicalDeviceVulkan11Features;
|
||||
//const VkPhysicalDeviceVulkan12Features &deviceVulkan12Features = gpuContext->physicalDeviceVulkan12Features;
|
||||
|
||||
///////////////////// Device Creation /////////////////////
|
||||
|
||||
_gpuDevice = CC_NEW(CCVKGPUDevice);
|
||||
_gpuDevice->minorVersion = context->minorVersion();
|
||||
|
||||
// only enable the absolute essentials for now
|
||||
vector<const char *> requestedValidationLayers{};
|
||||
|
||||
@@ -89,10 +94,13 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
|
||||
vector<const char *> requestedExtensions{
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME,
|
||||
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
|
||||
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
|
||||
};
|
||||
if (_gpuDevice->minorVersion < 1) {
|
||||
requestedExtensions.push_back(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
|
||||
requestedExtensions.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
|
||||
requestedExtensions.push_back(VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
VkPhysicalDeviceFeatures2 requestedFeatures2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
|
||||
VkPhysicalDeviceVulkan11Features requestedVulkan11Features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES};
|
||||
VkPhysicalDeviceVulkan12Features requestedVulkan12Features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
|
||||
@@ -112,10 +120,6 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
requestedExtensions.push_back(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME);
|
||||
#endif
|
||||
|
||||
///////////////////// Device Creation /////////////////////
|
||||
|
||||
_gpuDevice = CC_NEW(CCVKGPUDevice);
|
||||
|
||||
// check extensions
|
||||
uint availableLayerCount;
|
||||
VK_CHECK(vkEnumerateDeviceLayerProperties(gpuContext->physicalDevice, &availableLayerCount, nullptr));
|
||||
@@ -164,12 +168,12 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
deviceCreateInfo.ppEnabledLayerNames = _layers.data();
|
||||
deviceCreateInfo.enabledExtensionCount = toUint(_extensions.size());
|
||||
deviceCreateInfo.ppEnabledExtensionNames = _extensions.data();
|
||||
if (context->minorVersion() < 1 &&
|
||||
if (_gpuDevice->minorVersion < 1 &&
|
||||
!context->checkExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
|
||||
deviceCreateInfo.pEnabledFeatures = &requestedFeatures2.features;
|
||||
} else {
|
||||
deviceCreateInfo.pNext = &requestedFeatures2;
|
||||
if (context->minorVersion() >= 2) {
|
||||
if (_gpuDevice->minorVersion >= 2) {
|
||||
requestedFeatures2.pNext = &requestedVulkan11Features;
|
||||
requestedVulkan11Features.pNext = &requestedVulkan12Features;
|
||||
}
|
||||
@@ -199,7 +203,7 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
_features[(uint)Feature::COMPUTE_SHADER] = true;
|
||||
|
||||
_gpuDevice->useMultiDrawIndirect = deviceFeatures.multiDrawIndirect;
|
||||
_gpuDevice->useDescriptorUpdateTemplate = checkExtension(VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME);
|
||||
_gpuDevice->useDescriptorUpdateTemplate = _gpuDevice->minorVersion > 0 || checkExtension(VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME);
|
||||
|
||||
VkFormatFeatureFlags requiredFeatures = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
|
||||
VkFormatProperties formatProperties;
|
||||
@@ -256,12 +260,15 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
_caps.maxTextureSize = limits.maxImageDimension2D;
|
||||
_caps.maxCubeMapTextureSize = limits.maxImageDimensionCube;
|
||||
_caps.uboOffsetAlignment = (uint)limits.minUniformBufferOffsetAlignment;
|
||||
MapDepthStencilBits(_context->getDepthStencilFormat(), _caps.depthBits, _caps.stencilBits);
|
||||
// compute shaders
|
||||
_caps.maxComputeSharedMemorySize = limits.maxComputeSharedMemorySize;
|
||||
_caps.maxComputeWorkGroupInvocations = limits.maxComputeWorkGroupInvocations;
|
||||
_caps.maxComputeWorkGroupCount = {limits.maxComputeWorkGroupCount[0], limits.maxComputeWorkGroupCount[1], limits.maxComputeWorkGroupCount[2]};
|
||||
_caps.maxComputeWorkGroupSize = {limits.maxComputeWorkGroupSize[0], limits.maxComputeWorkGroupSize[1], limits.maxComputeWorkGroupSize[2]};
|
||||
MapDepthStencilBits(_context->getDepthStencilFormat(), _caps.depthBits, _caps.stencilBits);
|
||||
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
_caps.maxComputeWorkGroupInvocations = 64; // Arm: UNASSIGNED-BestPractices-vkCreateComputePipelines-compute-work-group-size
|
||||
#endif // defined(VK_USE_PLATFORM_ANDROID_KHR)
|
||||
|
||||
///////////////////// Resource Initialization /////////////////////
|
||||
|
||||
@@ -288,8 +295,12 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
allocatorInfo.device = _gpuDevice->vkDevice;
|
||||
allocatorInfo.instance = gpuContext->vkInstance;
|
||||
|
||||
if (checkExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME) &&
|
||||
checkExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME)) {
|
||||
if (_gpuDevice->minorVersion > 0) {
|
||||
allocatorInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
|
||||
vmaVulkanFunc.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2;
|
||||
vmaVulkanFunc.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2;
|
||||
} else if (checkExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME) &&
|
||||
checkExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME)) {
|
||||
allocatorInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
|
||||
vmaVulkanFunc.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2KHR;
|
||||
vmaVulkanFunc.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2KHR;
|
||||
@@ -519,9 +530,9 @@ void CCVKDevice::acquire() {
|
||||
VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, ~0ull,
|
||||
acquireSemaphore, VK_NULL_HANDLE, &_gpuSwapchain->curImageIndex));
|
||||
|
||||
#if CC_PLATFORM != CC_PLATFORM_MAC_IOS && CC_PLATFORM != CC_PLATFORM_MAC_OSX
|
||||
#if defined(VK_USE_PLATFORM_METAL_EXT)
|
||||
assert(_gpuDevice->curBackBufferIndex == _gpuSwapchain->curImageIndex); // MoltenVK seems to be not consistent
|
||||
#endif // CC_PLATFORM != CC_PLATFORM_MAC_IOS && CC_PLATFORM != CC_PLATFORM_MAC_OSX
|
||||
#endif // defined(VK_USE_PLATFORM_METAL_EXT)
|
||||
|
||||
queue->gpuQueue()->nextWaitSemaphore = acquireSemaphore;
|
||||
queue->gpuQueue()->nextSignalSemaphore = _gpuSemaphorePool->alloc();
|
||||
|
||||
@@ -57,7 +57,11 @@ class CCVKGPURenderPass final : public Object {
|
||||
public:
|
||||
ColorAttachmentList colorAttachments;
|
||||
DepthStencilAttachment depthStencilAttachment;
|
||||
SubPassInfoList subPasses;
|
||||
SubpassInfoList subpasses;
|
||||
|
||||
// per attachment
|
||||
vector<vector<ThsvsAccessType>> beginAccesses;
|
||||
vector<vector<ThsvsAccessType>> EndAccesses;
|
||||
|
||||
VkRenderPass vkRenderPass;
|
||||
|
||||
@@ -112,7 +116,7 @@ public:
|
||||
Address addressU = Address::WRAP;
|
||||
Address addressV = Address::WRAP;
|
||||
Address addressW = Address::WRAP;
|
||||
uint maxAnisotropy = 16u;
|
||||
uint maxAnisotropy = 0u;
|
||||
ComparisonFunc cmpFunc = ComparisonFunc::NEVER;
|
||||
Color borderColor;
|
||||
uint minLOD = 0u;
|
||||
@@ -296,7 +300,7 @@ public:
|
||||
VkMemoryBarrier vkBarrier{};
|
||||
|
||||
vector<ThsvsAccessType> accessTypes;
|
||||
ThsvsGlobalBarrier barrier{};
|
||||
ThsvsGlobalBarrier barrier{};
|
||||
};
|
||||
|
||||
class CCVKGPUTextureBarrier final : public Object {
|
||||
@@ -306,7 +310,7 @@ public:
|
||||
VkImageMemoryBarrier vkBarrier{};
|
||||
|
||||
vector<ThsvsAccessType> accessTypes;
|
||||
ThsvsImageBarrier barrier{};
|
||||
ThsvsImageBarrier barrier{};
|
||||
};
|
||||
|
||||
class CCVKGPUCommandBufferPool;
|
||||
@@ -317,6 +321,7 @@ public:
|
||||
vector<VkExtensionProperties> extensions;
|
||||
VmaAllocator memoryAllocator = VK_NULL_HANDLE;
|
||||
VkPipelineCache vkPipelineCache = VK_NULL_HANDLE;
|
||||
uint minorVersion = 0u;
|
||||
|
||||
uint curBackBufferIndex = 0u;
|
||||
uint backBufferCount = 3u;
|
||||
@@ -876,6 +881,11 @@ public:
|
||||
CCVKGPUDescriptorSetHub(CCVKGPUDevice *device)
|
||||
: _device(device) {
|
||||
_setsToBeUpdated.resize(device->backBufferCount);
|
||||
if (device->minorVersion > 0) {
|
||||
_updateFn = vkUpdateDescriptorSetWithTemplate;
|
||||
} else {
|
||||
_updateFn = vkUpdateDescriptorSetWithTemplateKHR;
|
||||
}
|
||||
}
|
||||
|
||||
void record(CCVKGPUDescriptorSet *gpuDescriptorSet) {
|
||||
@@ -909,8 +919,8 @@ private:
|
||||
void update(CCVKGPUDescriptorSet *gpuDescriptorSet) {
|
||||
CCVKGPUDescriptorSet::Instance &instance = gpuDescriptorSet->instances[_device->curBackBufferIndex];
|
||||
if (gpuDescriptorSet->gpuLayout->vkDescriptorUpdateTemplate) {
|
||||
vkUpdateDescriptorSetWithTemplateKHR(_device->vkDevice, instance.vkDescriptorSet,
|
||||
gpuDescriptorSet->gpuLayout->vkDescriptorUpdateTemplate, instance.descriptorInfos.data());
|
||||
_updateFn(_device->vkDevice, instance.vkDescriptorSet,
|
||||
gpuDescriptorSet->gpuLayout->vkDescriptorUpdateTemplate, instance.descriptorInfos.data());
|
||||
} else {
|
||||
vector<VkWriteDescriptorSet> &entries = instance.descriptorUpdateEntries;
|
||||
vkUpdateDescriptorSets(_device->vkDevice, entries.size(), entries.data(), 0, nullptr);
|
||||
@@ -919,6 +929,7 @@ private:
|
||||
|
||||
CCVKGPUDevice * _device = nullptr;
|
||||
vector<unordered_set<CCVKGPUDescriptorSet *>> _setsToBeUpdated;
|
||||
PFN_vkUpdateDescriptorSetWithTemplate _updateFn = nullptr;
|
||||
};
|
||||
|
||||
class CCVKGPUTextureLayoutManager final : public Object {
|
||||
|
||||
@@ -40,15 +40,15 @@ CCVKRenderPass::~CCVKRenderPass() {
|
||||
bool CCVKRenderPass::initialize(const RenderPassInfo &info) {
|
||||
_colorAttachments = info.colorAttachments;
|
||||
_depthStencilAttachment = info.depthStencilAttachment;
|
||||
_subPasses = info.subPasses;
|
||||
_subpasses = info.subpasses;
|
||||
|
||||
_gpuRenderPass = CC_NEW(CCVKGPURenderPass);
|
||||
_gpuRenderPass->colorAttachments = _colorAttachments;
|
||||
_gpuRenderPass->depthStencilAttachment = _depthStencilAttachment;
|
||||
_gpuRenderPass->subPasses = _subPasses;
|
||||
_gpuRenderPass->subpasses = _subpasses;
|
||||
CCVKCmdFuncCreateRenderPass((CCVKDevice *)_device, _gpuRenderPass);
|
||||
|
||||
_hash = computeHash(info);
|
||||
_hash = computeHash();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user