merge latest device

This commit is contained in:
Yun Hsiao Wu
2020-12-23 19:50:32 +08:00
committed by Yun Hsiao Wu
parent 11c51b1067
commit 4eac776f40
38 changed files with 187 additions and 306 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/audio/include/AudioEngine.h"
#include "cocos\audio\include\AudioEngine.h"
extern se::Object* __jsb_cc_AudioProfile_proto;
extern se::Class* __jsb_cc_AudioProfile_class;
+1 -1
View File
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/cocos2d.h"
#include "cocos\cocos2d.h"
extern se::Object* __jsb_cc_FileUtils_proto;
extern se::Class* __jsb_cc_FileUtils_class;
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "extensions/cocos-ext.h"
#include "extensions\cocos-ext.h"
extern se::Object* __jsb_cc_extension_EventAssetsManagerEx_proto;
extern se::Class* __jsb_cc_extension_EventAssetsManagerEx_class;
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/renderer/core/Core.h"
#include "cocos\renderer\core\Core.h"
extern se::Object* __jsb_cc_gfx_Offset_proto;
extern se::Class* __jsb_cc_gfx_Offset_class;
@@ -46,7 +46,6 @@ static bool js_gles2_GLES2Device_getThreadID(se::State& s)
unsigned int result = cobj->getThreadID();
ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "js_gles2_GLES2Device_getThreadID : Error processing arguments");
SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
+1 -1
View File
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/renderer/gfx-gles2/GFXGLES2.h"
#include "cocos\renderer\gfx-gles2\GFXGLES2.h"
extern se::Object* __jsb_cc_gfx_GLES2Device_proto;
extern se::Class* __jsb_cc_gfx_GLES2Device_class;
@@ -46,7 +46,6 @@ static bool js_gles3_GLES3Device_getThreadID(se::State& s)
unsigned int result = cobj->getThreadID();
ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "js_gles3_GLES3Device_getThreadID : Error processing arguments");
SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
+1 -1
View File
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/renderer/gfx-gles3/GFXGLES3.h"
#include "cocos\renderer\gfx-gles3\GFXGLES3.h"
extern se::Object* __jsb_cc_gfx_GLES3Device_proto;
extern se::Class* __jsb_cc_gfx_GLES3Device_class;
@@ -13,6 +13,42 @@
se::Object* __jsb_cc_gfx_CCMTLDevice_proto = nullptr;
se::Class* __jsb_cc_gfx_CCMTLDevice_class = nullptr;
static bool js_mtl_CCMTLDevice_getDSSTexture(se::State& s)
{
cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT<cc::gfx::CCMTLDevice>(s);
SE_PRECONDITION2(cobj, false, "js_mtl_CCMTLDevice_getDSSTexture : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 0) {
void* result = cobj->getDSSTexture();
ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "js_mtl_CCMTLDevice_getDSSTexture : Error processing arguments");
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
return false;
}
SE_BIND_FUNC(js_mtl_CCMTLDevice_getDSSTexture)
static bool js_mtl_CCMTLDevice_getMTLLayer(se::State& s)
{
cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT<cc::gfx::CCMTLDevice>(s);
SE_PRECONDITION2(cobj, false, "js_mtl_CCMTLDevice_getMTLLayer : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 0) {
void* result = cobj->getMTLLayer();
ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "js_mtl_CCMTLDevice_getMTLLayer : Error processing arguments");
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
return false;
}
SE_BIND_FUNC(js_mtl_CCMTLDevice_getMTLLayer)
SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_CCMTLDevice_finalize)
static bool js_mtl_CCMTLDevice_constructor(se::State& s) // constructor.c
@@ -45,6 +81,8 @@ bool js_register_mtl_CCMTLDevice(se::Object* obj)
{
auto cls = se::Class::create("CCMTLDevice", obj, __jsb_cc_gfx_Device_proto, _SE(js_mtl_CCMTLDevice_constructor));
cls->defineFunction("getDSSTexture", _SE(js_mtl_CCMTLDevice_getDSSTexture));
cls->defineFunction("getMTLLayer", _SE(js_mtl_CCMTLDevice_getMTLLayer));
cls->defineFinalizeFunction(_SE(js_cc_gfx_CCMTLDevice_finalize));
cls->install();
JSBClassType::registerClass<cc::gfx::CCMTLDevice>(cls);
+3 -1
View File
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/renderer/gfx-metal/GFXMTL.h"
#include "cocos\renderer\gfx-metal\GFXMTL.h"
extern se::Object* __jsb_cc_gfx_CCMTLDevice_proto;
extern se::Class* __jsb_cc_gfx_CCMTLDevice_class;
@@ -12,5 +12,7 @@ bool js_register_cc_gfx_CCMTLDevice(se::Object* obj);
bool register_all_mtl(se::Object* obj);
JSB_REGISTER_OBJECT_TYPE(cc::gfx::CCMTLDevice);
SE_DECLARE_FUNC(js_mtl_CCMTLDevice_getDSSTexture);
SE_DECLARE_FUNC(js_mtl_CCMTLDevice_getMTLLayer);
SE_DECLARE_FUNC(js_mtl_CCMTLDevice_CCMTLDevice);
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/network/Downloader.h"
#include "cocos\network\Downloader.h"
extern se::Object* __jsb_cc_network_DownloadTask_proto;
extern se::Class* __jsb_cc_network_DownloadTask_class;
+1 -1
View File
@@ -4,7 +4,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/ui/videoplayer/VideoPlayer.h"
#include "cocos\ui\videoplayer\VideoPlayer.h"
extern se::Object* __jsb_cc_VideoPlayer_proto;
extern se::Class* __jsb_cc_VideoPlayer_class;
+1 -1
View File
@@ -3,7 +3,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/renderer/gfx-vulkan/GFXVulkan.h"
#include "cocos\renderer\gfx-vulkan\GFXVulkan.h"
extern se::Object* __jsb_cc_gfx_CCVKDevice_proto;
extern se::Class* __jsb_cc_gfx_CCVKDevice_class;
@@ -4,7 +4,7 @@
#include <type_traits>
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/ui/webview/WebView.h"
#include "cocos\ui\webview\WebView.h"
extern se::Object* __jsb_cc_WebView_proto;
extern se::Class* __jsb_cc_WebView_class;
-20
View File
@@ -5,9 +5,6 @@
#include "base/CachedArray.h"
#include "base/StringUtil.h"
#include "threading/CommandEncoder.h"
#include "threading/ThreadPool.h"
#include "gfx/GFXBuffer.h"
#include "gfx/GFXCommand.h"
#include "gfx/GFXCommandBuffer.h"
@@ -26,20 +23,3 @@
#include "gfx/GFXSampler.h"
#include "gfx/GFXShader.h"
#include "gfx/GFXTexture.h"
#include "gfx-agent/GFXBufferAgent.h"
#include "gfx-agent/GFXCommandBufferAgent.h"
#include "gfx-agent/GFXDescriptorSetAgent.h"
#include "gfx-agent/GFXDeviceAgent.h"
#include "gfx-agent/GFXFramebufferAgent.h"
#include "gfx-agent/GFXInputAssemblerAgent.h"
#include "gfx-agent/GFXPipelineStateAgent.h"
#include "gfx-agent/GFXQueueAgent.h"
#include "gfx-agent/GFXRenderPassAgent.h"
#include "gfx-agent/GFXShaderAgent.h"
#include "gfx-agent/GFXTextureAgent.h"
#define CC_JOB_SYSTEM_TASKFLOW 1
#define CC_JOB_SYSTEM_TBB 2
#define CC_JOB_SYSTEM CC_JOB_SYSTEM_TASKFLOW
@@ -17,7 +17,7 @@ public:
virtual void destroy() = 0;
virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer, int submitIndex) = 0;
virtual void end() = 0;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) = 0;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) = 0;
virtual void endRenderPass() = 0;
virtual void bindPipelineState(PipelineState *pso) = 0;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) = 0;
@@ -35,16 +35,21 @@ public:
virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) = 0;
virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) = 0;
CC_INLINE void begin() { begin(nullptr, 0, nullptr, -1); }
CC_INLINE void begin(int submitIndex) { begin(nullptr, 0, nullptr, submitIndex); }
// secondary command buffer specifics
CC_INLINE void begin(RenderPass *renderPass, uint subpass = 0, Framebuffer *frameBuffer = nullptr) { begin(renderPass, subpass, frameBuffer, -1); }
CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) {
beginRenderPass(renderPass, fbo, renderArea, colors, depth, stencil, nullptr, 0);
CC_INLINE void bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet) {
bindDescriptorSet(set, descriptorSet, 0, nullptr);
}
CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs = nullptr, uint32_t count = 0) {
beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, cmdBuffs, count);
}
CC_INLINE void begin() { begin(nullptr, 0, nullptr, -1); }
CC_INLINE void begin(int submitIndex) { begin(nullptr, 0, nullptr, submitIndex); }
// secondary command buffer specifics
CC_INLINE void begin(RenderPass *renderPass) { begin(renderPass, 0, nullptr, -1); }
CC_INLINE void begin(RenderPass *renderPass, uint subpass) { begin(renderPass, subpass, nullptr, -1); }
CC_INLINE void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { begin(renderPass, subpass, frameBuffer, -1); }
CC_INLINE void updateBuffer(Buffer *buff, const void *data) { updateBuffer(buff, data, buff->getSize()); }
CC_INLINE void execute(const CommandBufferList &cmdBuffs, uint32_t count) { execute(cmdBuffs.data(), count); }
CC_INLINE void updateBuffer(Buffer *buff, const void *data) { updateBuffer(buff, data, buff->getSize()); }
@@ -52,6 +57,12 @@ public:
CC_INLINE void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector<uint> &dynamicOffsets) {
bindDescriptorSet(set, descriptorSet, static_cast<uint>(dynamicOffsets.size()), dynamicOffsets.data());
}
CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) {
beginRenderPass(renderPass, fbo, renderArea, colors, depth, stencil, false);
}
CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil) {
beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil);
}
CC_INLINE void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) {
copyBuffersToTexture(buffers.data(), texture, regions.data(), static_cast<uint>(regions.size()));
}
@@ -105,7 +105,7 @@ void GLES2CommandBuffer::end() {
}
}
void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) {
void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) {
_isInRenderPass = true;
GLES2CmdBeginRenderPass *cmd = _cmdAllocator->beginRenderPassCmdPool.alloc();
@@ -44,7 +44,7 @@ public:
virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer, int submitIndex) override;
virtual void end() override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) override;
virtual void endRenderPass() override;
virtual void bindPipelineState(PipelineState *pso) override;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override;
@@ -1408,6 +1408,10 @@ void GLES2CmdFuncBeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRen
invalidAttachments[numAttachments++] = (gpuFramebuffer->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR_EXT);
break;
}
default:;
}
}
} // for
if (gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN) {
bool hasDepth = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasDepth;
@@ -20,7 +20,7 @@ GLES2PrimaryCommandBuffer::GLES2PrimaryCommandBuffer(Device *device)
GLES2PrimaryCommandBuffer::~GLES2PrimaryCommandBuffer() {
}
void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) {
void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) {
_isInRenderPass = true;
GLES2GPURenderPass *gpuRenderPass = ((GLES2RenderPass *)renderPass)->gpuRenderPass();
GLES2GPUFramebuffer *gpuFramebuffer = ((GLES2Framebuffer *)fbo)->gpuFBO();
@@ -13,7 +13,7 @@ public:
GLES2PrimaryCommandBuffer(Device *device);
~GLES2PrimaryCommandBuffer();
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) override;
virtual void endRenderPass() override;
virtual void draw(InputAssembler *ia) override;
virtual void updateBuffer(Buffer *buff, const void *data, uint size) override;
@@ -105,7 +105,7 @@ void GLES3CommandBuffer::end() {
}
}
void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) {
void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) {
_isInRenderPass = true;
GLES3CmdBeginRenderPass *cmd = _cmdAllocator->beginRenderPassCmdPool.alloc();
@@ -43,7 +43,7 @@ public:
virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer, int submitIndex) override;
virtual void end() override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) override;
virtual void endRenderPass() override;
virtual void bindPipelineState(PipelineState *pso) override;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override;
@@ -1516,6 +1516,10 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen
invalidAttachments[numAttachments++] = (gpuFramebuffer->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR);
break;
}
default:;
}
}
} // for
if (gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN) {
bool hasDepth = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasDepth;
@@ -29,8 +29,6 @@ THE SOFTWARE.
#import <UIKit/UIScreen.h>
#import <UIKit/UIScreen.h>
namespace cc {
namespace gfx {
@@ -20,7 +20,7 @@ GLES3PrimaryCommandBuffer::GLES3PrimaryCommandBuffer(Device *device)
GLES3PrimaryCommandBuffer::~GLES3PrimaryCommandBuffer() {
}
void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) {
void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) {
_isInRenderPass = true;
GLES3GPURenderPass *gpuRenderPass = ((GLES3RenderPass *)renderPass)->gpuRenderPass();
GLES3GPUFramebuffer *gpuFramebuffer = ((GLES3Framebuffer *)fbo)->gpuFBO();
@@ -13,7 +13,7 @@ public:
GLES3PrimaryCommandBuffer(Device *device);
~GLES3PrimaryCommandBuffer();
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) override;
virtual void endRenderPass() override;
virtual void draw(InputAssembler *ia) override;
virtual void updateBuffer(Buffer *buff, const void *data, uint size) override;
@@ -44,6 +44,8 @@ public:
virtual void resize(uint size) override;
virtual void update(void *buffer, uint offset) override;
void encodeBuffer(CCMTLRenderCommandEncoder &encoder, uint offset, uint binding, ShaderStageFlags stages);
CC_INLINE id<MTLBuffer> getMTLBuffer() const { return _mtlBuffer; }
CC_INLINE MTLIndexType getIndexType() const { return _indexType; }
CC_INLINE bool isDrawIndirectByIndex() const { return _isDrawIndirectByIndex; }
+2 -4
View File
@@ -208,10 +208,8 @@ void CCMTLBuffer::resizeBuffer(uint8_t **buffer, uint size, uint oldSize) {
status.bufferSize -= oldSize;
}
void CCMTLBuffer::update(void *buffer, uint size)
{
if (_isBufferView)
{
void CCMTLBuffer::update(void *buffer, uint size) {
if (_isBufferView) {
CC_LOG_WARNING("Cannot update a buffer view.");
return;
}
@@ -51,7 +51,7 @@ public:
virtual void destroy() override;
virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer, int submitIndex) override;
virtual void end() override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) override;
virtual void endRenderPass() override;
virtual void bindPipelineState(PipelineState *pso) override;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override;
@@ -77,30 +77,13 @@ id<CAMetalDrawable> CCMTLCommandBuffer::getCurrentDrawable()
return _currDrawable;
}
bool CCMTLCommandBuffer::isRenderingEntireDrawable(const Rect &rect, const CCMTLRenderPass *renderPass)
{
const int num = renderPass->getColorRenderTargetNums();
if (num == 0)
{
return true;
}
const auto &renderTargetSize = renderPass->getRenderTargetSizes()[0];
return rect.x == 0 && rect.y == 0 && rect.width == renderTargetSize.x && rect.height == renderTargetSize.y;
}
void CCMTLCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer, int submitIndex)
{
if (_commandBufferBegan) return;
cbAutoReleasePool = [[NSAutoreleasePool alloc] init];
_isSubCB = renderPass != nullptr;
if (!_isSubCB)
{
// Sub command buffer for parallel shouldn't request any command buffer
_mtlCommandBuffer = [[_mtlCommandQueue commandBuffer] retain];
[_mtlCommandBuffer enqueue];
}
_mtlCommandBuffer = [_mtlCommandQueue commandBuffer];
[_mtlCommandBuffer retain];
[_mtlCommandBuffer enqueue];
_numTriangles = 0;
_numDrawCalls = 0;
_numInstances = 0;
@@ -118,30 +101,27 @@ void CCMTLCommandBuffer::end()
{
if (!_commandBufferBegan) return;
_commandBufferBegan = false;
// End encoding for sub encoder of a parallel encoder
if (_isSubCB)
{
_commandEncoder.endEncoding();
}
if (_currDrawable)
{
[_currDrawable release];
_currDrawable = nil;
}
[cbAutoReleasePool release];
cbAutoReleasePool = nullptr;
}
void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count)
bool CCMTLCommandBuffer::isRenderingEntireDrawable(const Rect &rect, const CCMTLRenderPass *renderPass)
{
// Sub CommandBuffer should call begin render pass
if (_isSubCB)
const int num = renderPass->getColorRenderTargetNums();
if (num == 0)
{
return;
return true;
}
const auto &renderTargetSize = renderPass->getRenderTargetSizes()[0];
return rect.x == 0 && rect.y == 0 && rect.width == renderTargetSize.x && rect.height == renderTargetSize.y;
}
void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB)
{
auto isOffscreen = static_cast<CCMTLFramebuffer *>(fbo)->isOffscreen();
if (!isOffscreen)
{
@@ -203,17 +183,6 @@ void CCMTLCommandBuffer::endRenderPass()
}
}
void CCMTLCommandBuffer::execute(const CommandBuffer *const *commandBuffs, uint32_t count)
{
for (uint i = 0; i < count; ++i)
{
auto commandBuffer = static_cast<const CCMTLCommandBuffer *>(commandBuffs[i]);
_numDrawCalls += commandBuffer->_numDrawCalls;
_numInstances += commandBuffer->_numInstances;
_numTriangles += commandBuffer->_numTriangles;
}
}
void CCMTLCommandBuffer::bindPipelineState(PipelineState *pso)
{
_gpuPipelineState = static_cast<CCMTLPipelineState *>(pso)->getGPUPipelineState();
@@ -468,6 +437,11 @@ void CCMTLCommandBuffer::draw(InputAssembler *ia)
}
}
}
}
else if (_type == CommandBufferType::SECONDARY)
{
CC_LOG_ERROR("CommandBufferType::SECONDARY not implemented.");
}
else
{
@@ -564,6 +538,17 @@ void CCMTLCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Tex
[encoder endEncoding];
}
void CCMTLCommandBuffer::execute(const CommandBuffer *const *commandBuffs, uint32_t count)
{
for (uint i = 0; i < count; ++i)
{
auto commandBuffer = static_cast<const CCMTLCommandBuffer *>(commandBuffs[i]);
_numDrawCalls += commandBuffer->_numDrawCalls;
_numInstances += commandBuffer->_numInstances;
_numTriangles += commandBuffer->_numTriangles;
}
}
void CCMTLCommandBuffer::bindDescriptorSets()
{
auto &vertexBuffers = _inputAssembler->getVertexBuffers();
@@ -53,22 +53,6 @@ public:
using Device::createPipelineState;
using Device::copyBuffersToTexture;
using Device::createCommandBuffer;
using Device::createFence;
using Device::createQueue;
using Device::createBuffer;
using Device::createTexture;
using Device::createSampler;
using Device::createShader;
using Device::createInputAssembler;
using Device::createRenderPass;
using Device::createFramebuffer;
using Device::createDescriptorSet;
using Device::createDescriptorSetLayout;
using Device::createPipelineLayout;
using Device::createPipelineState;
using Device::copyBuffersToTexture;
virtual bool initialize(const DeviceInfo &info) override;
virtual void destroy() override;
virtual void resize(uint width, uint height) override;
@@ -103,20 +87,6 @@ protected:
virtual PipelineLayout *createPipelineLayout() override;
virtual PipelineState *createPipelineState() override;
virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override;
virtual void blitBuffer(void *srcBuffer, uint offset, uint size, void *dstBuffer);
CC_INLINE CCMTLStateCache *getStateCache() const { return _stateCache; }
CC_INLINE void *getMTLCommandQueue() const { return _mtlCommandQueue; }
CC_INLINE void *getMTLLayer() const { return _mtlLayer; }
CC_INLINE void *getMTLDevice() const { return _mtlDevice; }
CC_INLINE uint getMaximumSamplerUnits() const { return _maxSamplerUnits; }
CC_INLINE uint getMaximumColorRenderTargets() const { return _maxColorRenderTargets; }
CC_INLINE uint getMaximumBufferBindingIndex() const { return _maxBufferBindingIndex; }
CC_INLINE bool isIndirectCommandBufferSupported() const { return _icbSuppored; }
CC_INLINE bool isIndirectDrawSupported() const { return _indirectDrawSupported; }
CC_INLINE CCMTLGPUStagingBufferPool *gpuStagingBufferPool() const { return _gpuStagingBufferPool; }
CC_INLINE bool isSamplerDescriptorCompareFunctionSupported() const { return _isSamplerDescriptorCompareFunctionSupported; }
CC_INLINE void *getDSSTexture() const { return _dssTex; }
private:
void onMemoryWarning();
@@ -126,7 +126,7 @@ void CCVKCommandBuffer::end() {
((CCVKDevice *)_device)->gpuDevice()->getCommandBufferPool(std::this_thread::get_id())->yield(_gpuCommandBuffer);
}
void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) {
void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) {
_curGPUFBO = ((CCVKFramebuffer *)fbo)->gpuFBO();
CCVKGPURenderPass *gpuRenderPass = ((CCVKRenderPass *)renderPass)->gpuRenderPass();
VkFramebuffer framebuffer = _curGPUFBO->vkFramebuffer;
@@ -172,7 +172,7 @@ void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo
passBeginInfo.clearValueCount = clearValues.size();
passBeginInfo.pClearValues = clearValues.data();
passBeginInfo.renderArea = {{(int)renderArea.x, (int)renderArea.y}, {renderArea.width, renderArea.height}};
vkCmdBeginRenderPass(_gpuCommandBuffer->vkCommandBuffer, &passBeginInfo,
vkCmdBeginRenderPass(_gpuCommandBuffer->vkCommandBuffer, &passBeginInfo,
fromSecondaryCB ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE);
if (!fromSecondaryCB) {
@@ -42,7 +42,7 @@ public:
virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer, int submitIndex) override;
virtual void end() override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, const CommandBuffer *const *cmdBuffs, uint32_t count) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, bool fromSecondaryCB) override;
virtual void endRenderPass() override;
virtual void bindPipelineState(PipelineState *pso) override;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override;
@@ -385,6 +385,33 @@ void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorS
VK_CHECK(vkCreateDescriptorSetLayout(gpuDevice->vkDevice, &setCreateInfo, nullptr, &gpuDescriptorSetLayout->vkDescriptorSetLayout));
gpuDescriptorSetLayout->pool.link(gpuDevice, gpuDescriptorSetLayout->maxSetsPerPool, gpuDescriptorSetLayout->vkBindings, gpuDescriptorSetLayout->vkDescriptorSetLayout);
if (gpuDevice->useDescriptorUpdateTemplate) {
const vector<VkDescriptorSetLayoutBinding> &bindings = gpuDescriptorSetLayout->vkBindings;
uint bindingCount = bindings.size();
if (!bindingCount) return;
vector<VkDescriptorUpdateTemplateEntry> entries(bindingCount);
for (size_t j = 0u, k = 0u; j < bindingCount; j++) {
const VkDescriptorSetLayoutBinding &binding = bindings[j];
if (binding.descriptorType != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
entries[j].dstBinding = binding.binding;
entries[j].dstArrayElement = 0;
entries[j].descriptorCount = binding.descriptorCount;
entries[j].descriptorType = binding.descriptorType;
entries[j].offset = sizeof(CCVKDescriptorInfo) * k;
entries[j].stride = sizeof(CCVKDescriptorInfo);
k += binding.descriptorCount;
} // TODO: inline UBOs
}
VkDescriptorUpdateTemplateCreateInfo createInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO};
createInfo.descriptorUpdateEntryCount = bindingCount;
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));
}
}
void CCVKCmdFuncCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout) {
@@ -842,11 +869,6 @@ void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer
}
void CCVKCmdFuncDestroyDescriptorSetLayout(CCVKGPUDevice *gpuDevice, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout) {
if (gpuDescriptorSetLayout->defaultDescriptorSet != VK_NULL_HANDLE) {
gpuDescriptorSetLayout->pool.yield(gpuDescriptorSetLayout->defaultDescriptorSet);
gpuDescriptorSetLayout->defaultDescriptorSet = VK_NULL_HANDLE;
}
if (gpuDescriptorSetLayout->vkDescriptorUpdateTemplate != VK_NULL_HANDLE) {
vkDestroyDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, gpuDescriptorSetLayout->vkDescriptorUpdateTemplate, nullptr);
gpuDescriptorSetLayout->vkDescriptorUpdateTemplate = VK_NULL_HANDLE;
@@ -47,7 +47,6 @@ bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) {
_layout = info.layout->getSetLayouts()[info.setIndex];
CCVKGPUPipelineLayout *gpuPipelineLayout = ((CCVKPipelineLayout *)info.layout)->gpuPipelineLayout();
CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = ((CCVKDescriptorSetLayout *)_layout)->gpuDescriptorSetLayout();
const uint bindingCount = gpuDescriptorSetLayout->bindings.size();
const uint descriptorCount = gpuDescriptorSetLayout->descriptorCount;
@@ -68,13 +67,15 @@ bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) {
CCVKGPUDevice *gpuDevice = ((CCVKDevice *)_device)->gpuDevice();
if (gpuDevice->useDescriptorUpdateTemplate) {
_gpuDescriptorSet->pUpdateTemplate = &gpuPipelineLayout->vkDescriptorUpdateTemplates[info.setIndex];
_gpuDescriptorSet->pUpdateTemplate = &gpuDescriptorSetLayout->vkDescriptorUpdateTemplate;
}
_gpuDescriptorSet->instances.resize(gpuDevice->backBufferCount);
for (size_t t = 0u; t < gpuDevice->backBufferCount; ++t) {
CCVKGPUDescriptorSet::DescriptorSetInstance &instance = _gpuDescriptorSet->instances[t];
instance.vkDescriptorSet = gpuDescriptorSetLayout->pool.request();
if (bindingCount) { // don't create resources if not needed
instance.vkDescriptorSet = gpuDescriptorSetLayout->pool.request();
}
instance.descriptorInfos.resize(descriptorCount, {});
for (size_t i = 0u, k = 0u; i < bindingCount; ++i) {
@@ -155,7 +156,7 @@ void CCVKDescriptorSet::destroy() {
}
}
if (gpuDescriptorSetLayout) {
if (gpuDescriptorSetLayout && instance.vkDescriptorSet) {
gpuDescriptorSetLayout->pool.yield(instance.vkDescriptorSet);
}
}
+30 -12
View File
@@ -302,9 +302,6 @@ public:
uint curBackBufferIndex = 0u;
uint backBufferCount = 3u;
uint curBackBufferIndex = 0u;
uint backBufferCount = 3u;
bool useDescriptorUpdateTemplate = false;
bool useMultiDrawIndirect = false;
@@ -316,10 +313,10 @@ public:
CCVKGPUSwapchain *swapchain = nullptr; // reference
/* */
/* *
using CommandBufferPools = tbb::concurrent_unordered_map<
std::thread::id, CCVKGPUCommandBufferPool *, std::hash<std::thread::id>>;
/* *
/* */
using CommandBufferPools = unordered_map<std::thread::id, CCVKGPUCommandBufferPool *>;
std::mutex mutex;
/* */
@@ -528,6 +525,7 @@ public:
vector<VkDescriptorSetLayoutBinding> vkBindings;
VkDescriptorSetLayout vkDescriptorSetLayout = VK_NULL_HANDLE;
VkDescriptorUpdateTemplate vkDescriptorUpdateTemplate = VK_NULL_HANDLE;
vector<uint> bindingIndices;
vector<uint> descriptorIndices;
@@ -566,13 +564,6 @@ public:
return hash & ((1 << 10) - 1);
}
CC_INLINE uint getHash(uint queueFamilyIndex) {
return (queueFamilyIndex << 10) | _device->curBackBufferIndex;
}
CC_INLINE uint getBackBufferIndex(uint hash) {
return hash & ((1 << 10) - 1);
}
void request(CCVKGPUCommandBuffer *gpuCommandBuffer) {
uint hash = getHash(gpuCommandBuffer->queueFamilyIndex);
@@ -905,6 +896,33 @@ private:
}
}
void erase(CCVKGPUBuffer *gpuBuffer) {
for (uint i = 0u; i < _device->backBufferCount; ++i) {
if (_buffersToBeUpdated[i].count(gpuBuffer)) {
_buffersToBeUpdated[i].erase(gpuBuffer);
}
}
}
void flush() {
unordered_map<CCVKGPUBuffer *, BufferUpdate> &buffers = _buffersToBeUpdated[_device->curBackBufferIndex];
for (unordered_map<CCVKGPUBuffer *, BufferUpdate>::iterator it = buffers.begin(); it != buffers.end(); ++it) {
update(it->first, it->second.src, it->second.size);
}
buffers.clear();
}
private:
struct BufferUpdate {
const void *src = nullptr;
size_t size = 0u;
};
uint8_t *update(CCVKGPUBuffer *gpuBuffer, const void *src, size_t size) {
uint8_t *dst = gpuBuffer->mappedData + _device->curBackBufferIndex * gpuBuffer->instanceSize;
memcpy(dst, src, size);
return dst;
}
CCVKGPUDevice *_device = nullptr;
vector<unordered_set<CCVKGPUDescriptorSet *>> _setsToBeUpdated;
};