Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GFX Descriptor Set #2700

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ cocos_source_files(
cocos/renderer/core/CoreStd.h
cocos/renderer/core/gfx/GFXObject.h
cocos/renderer/core/gfx/GFXObject.cc
cocos/renderer/core/gfx/GFXBindingLayout.cc
cocos/renderer/core/gfx/GFXBindingLayout.h
cocos/renderer/core/gfx/GFXBuffer.cc
cocos/renderer/core/gfx/GFXBuffer.h
cocos/renderer/core/gfx/GFXCommand.h
Expand All @@ -479,6 +477,12 @@ cocos_source_files(
cocos/renderer/core/gfx/GFXFramebuffer.h
cocos/renderer/core/gfx/GFXInputAssembler.cc
cocos/renderer/core/gfx/GFXInputAssembler.h
cocos/renderer/core/gfx/GFXDescriptorSet.cc
cocos/renderer/core/gfx/GFXDescriptorSet.h
cocos/renderer/core/gfx/GFXDescriptorSetLayout.cc
cocos/renderer/core/gfx/GFXDescriptorSetLayout.h
cocos/renderer/core/gfx/GFXPipelineLayout.cc
cocos/renderer/core/gfx/GFXPipelineLayout.h
cocos/renderer/core/gfx/GFXPipelineState.cc
cocos/renderer/core/gfx/GFXPipelineState.h
cocos/renderer/core/gfx/GFXQueue.cc
Expand Down Expand Up @@ -547,8 +551,6 @@ cocos_source_files(
if(CC_USE_GLES2)
cocos_source_files(
cocos/renderer/gfx-gles2/GFXGLES2.h
cocos/renderer/gfx-gles2/GLES2BindingLayout.cc
cocos/renderer/gfx-gles2/GLES2BindingLayout.h
cocos/renderer/gfx-gles2/GLES2Buffer.cc
cocos/renderer/gfx-gles2/GLES2Buffer.h
cocos/renderer/gfx-gles2/GLES2CommandAllocator.cc
Expand All @@ -565,6 +567,12 @@ if(CC_USE_GLES2)
cocos/renderer/gfx-gles2/GLES2GPUObjects.h
cocos/renderer/gfx-gles2/GLES2InputAssembler.cc
cocos/renderer/gfx-gles2/GLES2InputAssembler.h
cocos/renderer/gfx-gles2/GLES2DescriptorSet.cc
cocos/renderer/gfx-gles2/GLES2DescriptorSet.h
cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cc
cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h
cocos/renderer/gfx-gles2/GLES2PipelineLayout.cc
cocos/renderer/gfx-gles2/GLES2PipelineLayout.h
cocos/renderer/gfx-gles2/GLES2PipelineState.cc
cocos/renderer/gfx-gles2/GLES2PipelineState.h
cocos/renderer/gfx-gles2/GLES2Queue.cc
Expand Down Expand Up @@ -602,8 +610,6 @@ endif()
if(CC_USE_GLES3)
cocos_source_files(
cocos/renderer/gfx-gles3/GFXGLES3.h
cocos/renderer/gfx-gles3/GLES3BindingLayout.cc
cocos/renderer/gfx-gles3/GLES3BindingLayout.h
cocos/renderer/gfx-gles3/GLES3Buffer.cc
cocos/renderer/gfx-gles3/GLES3Buffer.h
cocos/renderer/gfx-gles3/GLES3CommandAllocator.cc
Expand All @@ -621,6 +627,12 @@ if(CC_USE_GLES3)
cocos/renderer/gfx-gles3/GLES3GPUObjects.h
cocos/renderer/gfx-gles3/GLES3InputAssembler.cc
cocos/renderer/gfx-gles3/GLES3InputAssembler.h
cocos/renderer/gfx-gles3/GLES3DescriptorSet.cc
cocos/renderer/gfx-gles3/GLES3DescriptorSet.h
cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cc
cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h
cocos/renderer/gfx-gles3/GLES3PipelineLayout.cc
cocos/renderer/gfx-gles3/GLES3PipelineLayout.h
cocos/renderer/gfx-gles3/GLES3PipelineState.cc
cocos/renderer/gfx-gles3/GLES3PipelineState.h
cocos/renderer/gfx-gles3/GLES3Queue.cc
Expand Down Expand Up @@ -659,8 +671,6 @@ endif()
if(CC_USE_METAL)
cocos_source_files(
cocos/renderer/gfx-metal/GFXMTL.h
cocos/renderer/gfx-metal/MTLBindingLayout.cpp
cocos/renderer/gfx-metal/MTLBindingLayout.h
cocos/renderer/gfx-metal/MTLBuffer.h
cocos/renderer/gfx-metal/MTLBuffer.mm
cocos/renderer/gfx-metal/MTLCommandBuffer.h
Expand All @@ -676,8 +686,14 @@ if(CC_USE_METAL)
cocos/renderer/gfx-metal/MTLGPUObjects.h
cocos/renderer/gfx-metal/MTLInputAssembler.h
cocos/renderer/gfx-metal/MTLInputAssembler.mm
cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h
cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm
cocos/renderer/gfx-metal/MTLPipelineLayout.h
cocos/renderer/gfx-metal/MTLPipelineLayout.mm
cocos/renderer/gfx-metal/MTLPipelineState.h
cocos/renderer/gfx-metal/MTLPipelineState.mm
cocos/renderer/gfx-metal/MTLDescriptorSet.h
cocos/renderer/gfx-metal/MTLDescriptorSet.mm
cocos/renderer/gfx-metal/MTLQueue.h
cocos/renderer/gfx-metal/MTLQueue.mm
cocos/renderer/gfx-metal/MTLRenderPass.h
Expand All @@ -703,8 +719,6 @@ if(CC_USE_VULKAN)
cocos_source_files(
cocos/renderer/gfx-vulkan/GFXVulkan.h
cocos/renderer/gfx-vulkan/vk_mem_alloc.h
cocos/renderer/gfx-vulkan/VKBindingLayout.cc
cocos/renderer/gfx-vulkan/VKBindingLayout.h
cocos/renderer/gfx-vulkan/VKBuffer.cc
cocos/renderer/gfx-vulkan/VKBuffer.h
cocos/renderer/gfx-vulkan/VKCommandBuffer.cc
Expand All @@ -720,6 +734,12 @@ if(CC_USE_VULKAN)
cocos/renderer/gfx-vulkan/VKGPUObjects.h
cocos/renderer/gfx-vulkan/VKInputAssembler.cc
cocos/renderer/gfx-vulkan/VKInputAssembler.h
cocos/renderer/gfx-vulkan/VKDescriptorSet.cc
cocos/renderer/gfx-vulkan/VKDescriptorSet.h
cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cc
cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h
cocos/renderer/gfx-vulkan/VKPipelineLayout.cc
cocos/renderer/gfx-vulkan/VKPipelineLayout.h
cocos/renderer/gfx-vulkan/VKPipelineState.cc
cocos/renderer/gfx-vulkan/VKPipelineState.h
cocos/renderer/gfx-vulkan/VKQueue.cc
Expand Down
28 changes: 28 additions & 0 deletions cocos/base/CachedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ class CachedArray : public Object {
CC_INLINE uint size() const { return _size; }
CC_INLINE T pop() { return _array[--_size]; }

void resize(uint size) {
if (size >= _capacity) {
T *temp = _array;
_array = CC_NEW_ARRAY(T, size);
for (uint i = 0; i < _capacity; ++i) {
_array[i] = temp[i];
}
_capacity = size;
CC_DELETE_ARRAY(temp);
}
}

void push(T item) {
if (_size >= _capacity) {
T *temp = _array;
Expand Down Expand Up @@ -95,6 +107,22 @@ class CachedArray : public Object {
}
}

void concat(uint count, T *array) {
if (_size + count >= _capacity) {
T *temp = _array;
uint size = std::max(_capacity * 2, _size + count);
_array = CC_NEW_ARRAY(T, size);
for (uint i = 0; i < _size; ++i) {
_array[i] = temp[i];
}
_capacity = size;
CC_DELETE_ARRAY(temp);
}
for (uint i = 0; i < count; ++i) {
_array[_size++] = array[i];
}
}

void fastRemove(uint idx) {
if (idx >= _size) {
return;
Expand Down
4 changes: 3 additions & 1 deletion cocos/renderer/core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include "gfx/GFXInputAssembler.h"
#include "gfx/GFXRenderPass.h"
#include "gfx/GFXFramebuffer.h"
#include "gfx/GFXBindingLayout.h"
#include "gfx/GFXDescriptorSetLayout.h"
#include "gfx/GFXPipelineLayout.h"
#include "gfx/GFXPipelineState.h"
#include "gfx/GFXDescriptorSet.h"
#include "gfx/GFXCommandBuffer.h"
#include "gfx/GFXFence.h"
#include "gfx/GFXQueue.h"
Expand Down
66 changes: 0 additions & 66 deletions cocos/renderer/core/gfx/GFXBindingLayout.cc

This file was deleted.

35 changes: 0 additions & 35 deletions cocos/renderer/core/gfx/GFXBindingLayout.h

This file was deleted.

12 changes: 8 additions & 4 deletions cocos/renderer/core/gfx/GFXBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CC_DLL Buffer : public GFXObject {

public:
virtual bool initialize(const BufferInfo &info) = 0;
virtual bool initialize(const BufferViewInfo &info) = 0;
virtual void destroy() = 0;
virtual void resize(uint size) = 0;
virtual void update(void *buffer, uint offset = 0, uint size = 0) = 0;
Expand All @@ -24,17 +25,20 @@ class CC_DLL Buffer : public GFXObject {
CC_INLINE uint getCount() const { return _count; }
CC_INLINE uint getSize() const { return _size; }
CC_INLINE BufferFlags getFlags() const { return _flags; }
CC_INLINE uint8_t *getBufferView() const { return _buffer; }
CC_INLINE uint8_t *getBackupBuffer() const { return _buffer; }
CC_INLINE bool isBufferView() const { return _isBufferView; }

protected:
Device *_device = nullptr;
BufferUsage _usage = BufferUsageBit::NONE;
MemoryUsage _memUsage = MemoryUsageBit::NONE;
uint _stride = 0;
uint _count = 0;
uint _size = 0;
uint _stride = 0u;
uint _count = 0u;
uint _size = 0u;
uint _offset = 0u;
BufferFlags _flags = BufferFlagBit::NONE;
uint8_t *_buffer = nullptr;
bool _isBufferView = false;
};

} // namespace gfx
Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/core/gfx/GFXCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum class GFXCmdType : uint8_t {
class GFXCmd : public Object {
public:
GFXCmdType type;
uint ref_count = 0;
uint refCount = 0;

GFXCmd(GFXCmdType _type) : type(_type) {}
virtual ~GFXCmd() {}
Expand Down
27 changes: 21 additions & 6 deletions cocos/renderer/core/gfx/GFXCommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,40 @@ class CC_DLL CommandBuffer : public GFXObject {
public:
virtual bool initialize(const CommandBufferInfo &info) = 0;
virtual void destroy() = 0;
virtual void begin(RenderPass *renderPass = nullptr, uint subpass = 0, Framebuffer *frameBuffer = nullptr) = 0;
virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) = 0;
virtual void end() = 0;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) = 0;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) = 0;
virtual void endRenderPass() = 0;
virtual void bindPipelineState(PipelineState *pso) = 0;
virtual void bindBindingLayout(BindingLayout *layout) = 0;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) = 0;
virtual void bindInputAssembler(InputAssembler *ia) = 0;
virtual void setViewport(const Viewport &vp) = 0;
virtual void setScissor(const Rect &rect) = 0;
virtual void setLineWidth(const float width) = 0;
virtual void setDepthBias(float constant, float clamp, float slope) = 0;
virtual void setBlendConstants(const Color &constants) = 0;
virtual void setDepthBound(float min_bounds, float max_bounds) = 0;
virtual void setDepthBound(float minBounds, float maxBounds) = 0;
virtual void setStencilWriteMask(StencilFace face, uint mask) = 0;
virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) = 0;
virtual void draw(InputAssembler *ia) = 0;
virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset = 0) = 0;
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) = 0;
virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) = 0;
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); }
CC_INLINE void begin(RenderPass *renderPass) { begin(renderPass, 0, nullptr); }
CC_INLINE void begin(RenderPass *renderPass, uint subpass) { begin(renderPass, subpass, nullptr); }
CC_INLINE void execute(const CommandBufferList &cmdBuffs, uint32_t count) { execute(cmdBuffs.data(), count); }
CC_INLINE void bindDescriptorSet(uint set, DescriptorSet *descriptorSet) { bindDescriptorSet(set, descriptorSet, 0, nullptr); }
CC_INLINE void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector<uint> &dynamicOffsets) {
bindDescriptorSet(set, descriptorSet, dynamicOffsets.size(), dynamicOffsets.data());
}
CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &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(), regions.size());
}

CC_INLINE Device *getDevice() const { return _device; }
CC_INLINE Queue *getQueue() const { return _queue; }
Expand Down
6 changes: 3 additions & 3 deletions cocos/renderer/core/gfx/GFXCommandPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ class CommandPool {

T *cmd = _frees[_freeIdx];
_frees[_freeIdx--] = nullptr;
++cmd->ref_count;
++cmd->refCount;
return cmd;
}

void free(T *cmd) {
if (--cmd->ref_count == 0) {
if (--cmd->refCount == 0) {
_freeCmds.push(cmd);
}
}

void freeCmds(CachedArray<T *> &cmds) {
for (uint i = 0; i < cmds.size(); ++i) {
if (--cmds[i]->ref_count == 0) {
if (--cmds[i]->refCount == 0) {
_freeCmds.push(cmds[i]);
}
}
Expand Down
5 changes: 5 additions & 0 deletions cocos/renderer/core/gfx/GFXDef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
namespace cc {
namespace gfx {

const uint DESCRIPTOR_BUFFER_TYPE = (uint)DescriptorType::STORAGE_BUFFER | (uint)DescriptorType::DYNAMIC_STORAGE_BUFFER |
(uint)DescriptorType::UNIFORM_BUFFER | (uint)DescriptorType::DYNAMIC_UNIFORM_BUFFER;
const uint DESCRIPTOR_SAMPLER_TYPE = (uint)DescriptorType::SAMPLER;
const uint DESCRIPTOR_DYNAMIC_TYPE = (uint)DescriptorType::DYNAMIC_STORAGE_BUFFER | (uint)DescriptorType::DYNAMIC_UNIFORM_BUFFER;

const FormatInfo GFX_FORMAT_INFOS[] = {
{"UNKNOWN", 0, 0, FormatType::NONE, false, false, false, false},
{"A8", 1, 1, FormatType::UNORM, true, false, false, false},
Expand Down
Loading