diff --git a/CMakeLists.txt b/CMakeLists.txt index 710b64dde6a..1859eb9c9b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/cocos/base/CachedArray.h b/cocos/base/CachedArray.h index 4769e565b05..5dc3002b69d 100755 --- a/cocos/base/CachedArray.h +++ b/cocos/base/CachedArray.h @@ -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; @@ -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; diff --git a/cocos/renderer/core/Core.h b/cocos/renderer/core/Core.h index 06663d08107..1c4e58a11ed 100644 --- a/cocos/renderer/core/Core.h +++ b/cocos/renderer/core/Core.h @@ -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" diff --git a/cocos/renderer/core/gfx/GFXBindingLayout.cc b/cocos/renderer/core/gfx/GFXBindingLayout.cc deleted file mode 100755 index df9cd9f9da9..00000000000 --- a/cocos/renderer/core/gfx/GFXBindingLayout.cc +++ /dev/null @@ -1,66 +0,0 @@ -#include "CoreStd.h" -#include "GFXBindingLayout.h" - -namespace cc { -namespace gfx { - -BindingLayout::BindingLayout(Device *device) -: GFXObject(ObjectType::BINDING_LAYOUT), _device(device) { -} - -BindingLayout::~BindingLayout() { -} - -void BindingLayout::bindBuffer(uint binding, Buffer *buffer) { - for (size_t i = 0; i < _bindingUnits.size(); ++i) { - BindingUnit &bindingUnit = _bindingUnits[i]; - if (bindingUnit.binding == binding) { - if (bindingUnit.type == BindingType::UNIFORM_BUFFER) { - if (bindingUnit.buffer != buffer) { - bindingUnit.buffer = buffer; - _isDirty = true; - } - } else { - CCASSERT(false, "Setting binding is not BindingType.UNIFORM_BUFFER."); - } - return; - } - } -} - -void BindingLayout::bindTexture(uint binding, Texture *texture) { - for (size_t i = 0; i < _bindingUnits.size(); ++i) { - BindingUnit &bindingUnit = _bindingUnits[i]; - if (bindingUnit.binding == binding) { - if (bindingUnit.type == BindingType::SAMPLER) { - if (bindingUnit.texture != texture) { - bindingUnit.texture = texture; - _isDirty = true; - } - } else { - CCASSERT(false, "Setting binding is not BindingType.SAMPLER."); - } - return; - } - } -} - -void BindingLayout::bindSampler(uint binding, Sampler *sampler) { - for (size_t i = 0; i < _bindingUnits.size(); ++i) { - BindingUnit &bindingUnit = _bindingUnits[i]; - if (bindingUnit.binding == binding) { - if (bindingUnit.type == BindingType::SAMPLER) { - if (bindingUnit.sampler != sampler) { - bindingUnit.sampler = sampler; - _isDirty = true; - } - } else { - CCASSERT(false, "Setting binding is not BindingType.SAMPLER."); - } - return; - } - } -} - -} // namespace gfx -} // namespace cc diff --git a/cocos/renderer/core/gfx/GFXBindingLayout.h b/cocos/renderer/core/gfx/GFXBindingLayout.h deleted file mode 100755 index 518c338626f..00000000000 --- a/cocos/renderer/core/gfx/GFXBindingLayout.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CC_CORE_GFX_BINDING_LAYOUT_H_ -#define CC_CORE_GFX_BINDING_LAYOUT_H_ - -#include "GFXDef.h" - -namespace cc { -namespace gfx { - -class CC_DLL BindingLayout : public GFXObject { -public: - BindingLayout(Device *device); - virtual ~BindingLayout(); - -public: - virtual bool initialize(const BindingLayoutInfo &info) = 0; - virtual void destroy() = 0; - virtual void update() = 0; - - void bindBuffer(uint binding, Buffer *buffer); - void bindTexture(uint binding, Texture *texView); - void bindSampler(uint binding, Sampler *sampler); - - CC_INLINE Device *getDevice() const { return _device; } - CC_INLINE const BindingUnitList &getBindingUnits() const { return _bindingUnits; } - -protected: - Device *_device = nullptr; - BindingUnitList _bindingUnits; - bool _isDirty = false; -}; - -} // namespace gfx -} // namespace cc - -#endif // CC_CORE_GFX_BINDING_LAYOUT_H_ diff --git a/cocos/renderer/core/gfx/GFXBuffer.h b/cocos/renderer/core/gfx/GFXBuffer.h index b670bfeefce..bcd943f5a8c 100755 --- a/cocos/renderer/core/gfx/GFXBuffer.h +++ b/cocos/renderer/core/gfx/GFXBuffer.h @@ -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; @@ -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 diff --git a/cocos/renderer/core/gfx/GFXCommand.h b/cocos/renderer/core/gfx/GFXCommand.h index 89873de7c25..b2fc052b992 100644 --- a/cocos/renderer/core/gfx/GFXCommand.h +++ b/cocos/renderer/core/gfx/GFXCommand.h @@ -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() {} diff --git a/cocos/renderer/core/gfx/GFXCommandBuffer.h b/cocos/renderer/core/gfx/GFXCommandBuffer.h index 41908be6ede..bedd67f96b7 100755 --- a/cocos/renderer/core/gfx/GFXCommandBuffer.h +++ b/cocos/renderer/core/gfx/GFXCommandBuffer.h @@ -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 &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 ®ions) = 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 &dynamicOffsets) { + bindDescriptorSet(set, descriptorSet, dynamicOffsets.size(), dynamicOffsets.data()); + } + CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector &colors, float depth, int stencil) { + beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil); + } + CC_INLINE void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { + copyBuffersToTexture(buffers.data(), texture, regions.data(), regions.size()); + } CC_INLINE Device *getDevice() const { return _device; } CC_INLINE Queue *getQueue() const { return _queue; } diff --git a/cocos/renderer/core/gfx/GFXCommandPool.h b/cocos/renderer/core/gfx/GFXCommandPool.h index de1b3e79d0d..4d79e9aa4f2 100644 --- a/cocos/renderer/core/gfx/GFXCommandPool.h +++ b/cocos/renderer/core/gfx/GFXCommandPool.h @@ -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 &cmds) { for (uint i = 0; i < cmds.size(); ++i) { - if (--cmds[i]->ref_count == 0) { + if (--cmds[i]->refCount == 0) { _freeCmds.push(cmds[i]); } } diff --git a/cocos/renderer/core/gfx/GFXDef.cc b/cocos/renderer/core/gfx/GFXDef.cc index 3843cc9a570..ea380217f63 100755 --- a/cocos/renderer/core/gfx/GFXDef.cc +++ b/cocos/renderer/core/gfx/GFXDef.cc @@ -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}, diff --git a/cocos/renderer/core/gfx/GFXDef.h b/cocos/renderer/core/gfx/GFXDef.h index 5f1220f033f..9d0f6e1c590 100755 --- a/cocos/renderer/core/gfx/GFXDef.h +++ b/cocos/renderer/core/gfx/GFXDef.h @@ -12,8 +12,10 @@ class Shader; class InputAssembler; class RenderPass; class Framebuffer; -class BindingLayout; +class DescriptorSetLayout; +class PipelineLayout; class PipelineState; +class DescriptorSet; class CommandAllocator; class CommandBuffer; class Fence; @@ -32,13 +34,14 @@ enum class ObjectType : uint8_t { UNKNOWN, BUFFER, TEXTURE, - TEXTURE_VIEW, RENDER_PASS, FRAMEBUFFER, SAMPLER, SHADER, + DESCRIPTOR_SET_LAYOUT, + PIPELINE_LAYOUT, PIPELINE_STATE, - BINDING_LAYOUT, + DESCRIPTOR_SET, INPUT_ASSEMBLER, COMMAND_BUFFER, FENCE, @@ -415,7 +418,7 @@ enum class ColorMask : uint8_t { }; CC_ENUM_OPERATORS(ColorMask); -enum class ShaderType : uint8_t { +enum class ShaderStageFlagBit : uint8_t { NONE = 0x0, VERTEX = 0x1, CONTROL = 0x2, @@ -425,7 +428,8 @@ enum class ShaderType : uint8_t { COMPUTE = 0x20, ALL = 0x3f, }; -CC_ENUM_OPERATORS(ShaderType); +typedef ShaderStageFlagBit ShaderStageFlags; +CC_ENUM_OPERATORS(ShaderStageFlagBit); enum class LoadOp : uint8_t { LOAD, // Load the contents from the fbo from previous @@ -513,11 +517,13 @@ enum class StencilFace : uint8_t { ALL, }; -enum class BindingType : uint8_t { - UNKNOWN, - UNIFORM_BUFFER, - SAMPLER, - STORAGE_BUFFER, +enum class DescriptorType : uint8_t { + UNKNOWN = 0, + UNIFORM_BUFFER = 0x1, + DYNAMIC_UNIFORM_BUFFER = 0x2, + STORAGE_BUFFER = 0x4, + DYNAMIC_STORAGE_BUFFER = 0x8, + SAMPLER = 0x10, }; enum class QueueType : uint8_t { @@ -647,6 +653,22 @@ struct Color { #pragma pack(pop) typedef vector ColorList; +/** + * For non-vulkan backends, to maintain compatibility and maximize + * descriptor cache-locality, descriptor-set-based binding numbers need + * to be mapped to backend-specific bindings based on maximum limit + * of available descriptor slots in each set. + * + * Because the binding numbers are guaranteed to be consecutive for each + * descriptor type inside each set, the mapping procedure can be reduced + * to a simple shifting operation. This data structure specifies the + * exact offsets for each descriptor type in each set. + */ +struct BindingMappingInfo { + vector bufferOffsets; + vector samplerOffsets; +}; + struct DeviceInfo { uintptr_t windowHandle = 0; uint width = 0; @@ -654,6 +676,7 @@ struct DeviceInfo { uint nativeWidth = 0; uint nativeHeight = 0; Context *sharedCtx = nullptr; + BindingMappingInfo bindingMappingInfo; }; struct WindowInfo { @@ -685,6 +708,12 @@ struct BufferInfo { BufferFlags flags = BufferFlagBit::NONE; }; +struct BufferViewInfo { + Buffer *buffer = nullptr; + uint offset = 0u; + uint range = 0u; +}; + #pragma pack(push, 1) struct DrawInfo { uint vertexCount = 0; @@ -758,16 +787,17 @@ struct Uniform { typedef vector UniformList; struct UniformBlock { - ShaderType shaderStages = ShaderType::NONE; + uint set = 0; uint binding = 0; String name; - UniformList uniforms; + UniformList members; + uint count = 0; }; typedef vector UniformBlockList; struct UniformSampler { - ShaderType shaderStages = ShaderType::NONE; + uint set = 0; uint binding = 0; String name; Type type = Type::UNKNOWN; @@ -777,9 +807,8 @@ struct UniformSampler { typedef vector UniformSamplerList; struct ShaderStage { - ShaderType type; + ShaderStageFlagBit stage; String source; - ShaderMacroList macros; }; typedef vector ShaderStageList; @@ -857,32 +886,41 @@ struct RenderPassInfo { SubPassList subPasses; }; +typedef vector BufferList; typedef vector TextureList; +typedef vector SamplerList; struct FramebufferInfo { RenderPass *renderPass = nullptr; TextureList colorTextures; - vector colorMipmapLevels; + vector colorMipmapLevels; Texture *depthStencilTexture = nullptr; - int depthStencilMipmapLevel = 0; + uint depthStencilMipmapLevel = 0; }; -struct BindingLayoutInfo { - Shader *shader = nullptr; +struct DescriptorSetLayoutBinding { + DescriptorType descriptorType; + uint count; + ShaderStageFlagBit stageFlags; + SamplerList immutableSamplers; }; +typedef vector DescriptorSetLayoutBindingList; -struct BindingUnit { - ShaderType shaderStages = ShaderType::NONE; - uint binding = 0; - BindingType type = BindingType::UNKNOWN; - String name; - uint count = 0; - Buffer *buffer = nullptr; - Texture *texture = nullptr; - Sampler *sampler = nullptr; +struct DescriptorSetLayoutInfo { + // array index is used as the binding numbers, + // i.e. they should be strictly consecutive and start from 0 + DescriptorSetLayoutBindingList bindings; }; -typedef vector BindingUnitList; +struct DescriptorSetInfo { + DescriptorSetLayout *layout = nullptr; +}; + +typedef vector DescriptorSetLayoutList; + +struct PipelineLayoutInfo { + DescriptorSetLayoutList setLayouts; +}; struct InputState { AttributeList attributes; @@ -958,6 +996,7 @@ struct PipelineStateInfo { BlendState blendState; DynamicStateFlags dynamicStates = DynamicStateFlagBit::NONE; RenderPass *renderPass = nullptr; + PipelineLayout *pipelineLayout = nullptr; }; struct CommandBufferInfo { @@ -984,6 +1023,10 @@ struct FormatInfo { bool isCompressed = false; }; +extern CC_DLL const uint DESCRIPTOR_BUFFER_TYPE; +extern CC_DLL const uint DESCRIPTOR_SAMPLER_TYPE; +extern CC_DLL const uint DESCRIPTOR_DYNAMIC_TYPE; + extern CC_DLL const FormatInfo GFX_FORMAT_INFOS[]; extern CC_DLL const uint GFX_TYPE_SIZES[]; diff --git a/cocos/renderer/core/gfx/GFXDescriptorSet.cc b/cocos/renderer/core/gfx/GFXDescriptorSet.cc new file mode 100644 index 00000000000..d65018f81bf --- /dev/null +++ b/cocos/renderer/core/gfx/GFXDescriptorSet.cc @@ -0,0 +1,52 @@ +#include "CoreStd.h" +#include "GFXDescriptorSet.h" +#include "GFXDescriptorSetLayout.h" + +namespace cc { +namespace gfx { + +DescriptorSet::DescriptorSet(Device *device) +: GFXObject(ObjectType::DESCRIPTOR_SET), _device(device) { +} + +DescriptorSet::~DescriptorSet() { +} + +void DescriptorSet::bindBuffer(uint binding, Buffer *buffer) { + const DescriptorSetLayoutBinding &descriptor = _layout->getBindings()[binding]; + if ((uint)descriptor.descriptorType & DESCRIPTOR_BUFFER_TYPE) { + if (_buffers[binding] != buffer) { + _buffers[binding] = buffer; + _isDirty = true; + } + } else { + CCASSERT(false, "Setting binding is not BindingType.UNIFORM_BUFFER."); + } +} + +void DescriptorSet::bindTexture(uint binding, Texture *texture) { + const DescriptorSetLayoutBinding &descriptor = _layout->getBindings()[binding]; + if ((uint)descriptor.descriptorType & DESCRIPTOR_SAMPLER_TYPE) { + if (_textures[binding] != texture) { + _textures[binding] = texture; + _isDirty = true; + } + } else { + CCASSERT(false, "Setting binding is not BindingType.UNIFORM_BUFFER."); + } +} + +void DescriptorSet::bindSampler(uint binding, Sampler *sampler) { + const DescriptorSetLayoutBinding &descriptor = _layout->getBindings()[binding]; + if ((uint)descriptor.descriptorType & DESCRIPTOR_SAMPLER_TYPE) { + if (_samplers[binding] != sampler) { + _samplers[binding] = sampler; + _isDirty = true; + } + } else { + CCASSERT(false, "Setting binding is not BindingType.UNIFORM_BUFFER."); + } +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/core/gfx/GFXDescriptorSet.h b/cocos/renderer/core/gfx/GFXDescriptorSet.h new file mode 100644 index 00000000000..e36baa44053 --- /dev/null +++ b/cocos/renderer/core/gfx/GFXDescriptorSet.h @@ -0,0 +1,42 @@ +#ifndef CC_CORE_GFX_DESCRIPTOR_SET_H_ +#define CC_CORE_GFX_DESCRIPTOR_SET_H_ + +#include "GFXDef.h" + +namespace cc { +namespace gfx { + +class CC_DLL DescriptorSet : public GFXObject { +public: + DescriptorSet(Device *device); + virtual ~DescriptorSet(); + +public: + virtual bool initialize(const DescriptorSetInfo &info) = 0; + virtual void destroy() = 0; + virtual void update() = 0; + + void bindBuffer(uint binding, Buffer *buffer); + void bindTexture(uint binding, Texture *texView); + void bindSampler(uint binding, Sampler *sampler); + + CC_INLINE Device *getDevice() const { return _device; } + CC_INLINE const Buffer *getBuffer(uint binding) const { return _buffers[binding]; } + CC_INLINE const Texture *getTexture(uint binding) const { return _textures[binding]; } + CC_INLINE const Sampler *getSampler(uint binding) const { return _samplers[binding]; } + +protected: + Device *_device = nullptr; + + DescriptorSetLayout *_layout; + BufferList _buffers; + TextureList _textures; + SamplerList _samplers; + + bool _isDirty = false; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_CORE_GFX_DESCRIPTOR_SET_H_ diff --git a/cocos/renderer/core/gfx/GFXDescriptorSetLayout.cc b/cocos/renderer/core/gfx/GFXDescriptorSetLayout.cc new file mode 100644 index 00000000000..47a8bf45921 --- /dev/null +++ b/cocos/renderer/core/gfx/GFXDescriptorSetLayout.cc @@ -0,0 +1,15 @@ +#include "CoreStd.h" +#include "GFXDescriptorSetLayout.h" + +namespace cc { +namespace gfx { + +DescriptorSetLayout::DescriptorSetLayout(Device *device) +: GFXObject(ObjectType::DESCRIPTOR_SET_LAYOUT), _device(device) { +} + +DescriptorSetLayout::~DescriptorSetLayout() { +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/core/gfx/GFXDescriptorSetLayout.h b/cocos/renderer/core/gfx/GFXDescriptorSetLayout.h new file mode 100644 index 00000000000..17abdb5126b --- /dev/null +++ b/cocos/renderer/core/gfx/GFXDescriptorSetLayout.h @@ -0,0 +1,29 @@ +#ifndef CC_CORE_GFX_DESCRIPTOR_SET_LAYOUT_H_ +#define CC_CORE_GFX_DESCRIPTOR_SET_LAYOUT_H_ + +#include "GFXDef.h" + +namespace cc { +namespace gfx { + +class CC_DLL DescriptorSetLayout : public GFXObject { +public: + DescriptorSetLayout(Device *device); + virtual ~DescriptorSetLayout(); + +public: + virtual bool initialize(const DescriptorSetLayoutInfo &info) = 0; + virtual void destroy() = 0; + + CC_INLINE Device *getDevice() const { return _device; } + CC_INLINE const DescriptorSetLayoutBindingList &getBindings() const { return _bindings; } + +protected: + Device *_device = nullptr; + DescriptorSetLayoutBindingList _bindings; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_CORE_GFX_DESCRIPTOR_SET_LAYOUT_H_ diff --git a/cocos/renderer/core/gfx/GFXDevice.h b/cocos/renderer/core/gfx/GFXDevice.h index c4a6f7b2f11..ecac8665033 100755 --- a/cocos/renderer/core/gfx/GFXDevice.h +++ b/cocos/renderer/core/gfx/GFXDevice.h @@ -23,6 +23,7 @@ class CC_DLL Device : public Object { virtual Fence *createFence(const FenceInfo &info) = 0; virtual Queue *createQueue(const QueueInfo &info) = 0; virtual Buffer *createBuffer(const BufferInfo &info) = 0; + virtual Buffer *createBuffer(const BufferViewInfo &info) = 0; virtual Texture *createTexture(const TextureInfo &info) = 0; virtual Texture *createTexture(const TextureViewInfo &info) = 0; virtual Sampler *createSampler(const SamplerInfo &info) = 0; @@ -30,9 +31,15 @@ class CC_DLL Device : public Object { virtual InputAssembler *createInputAssembler(const InputAssemblerInfo &info) = 0; virtual RenderPass *createRenderPass(const RenderPassInfo &info) = 0; virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) = 0; - virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) = 0; + virtual DescriptorSet *createDescriptorSet(const DescriptorSetInfo &info) = 0; + virtual DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) = 0; + virtual PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) = 0; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) = 0; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) = 0; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) = 0; + + CC_INLINE void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { + copyBuffersToTexture(buffers.data(), dst, regions.data(), regions.size()); + } CC_INLINE API getGfxAPI() const { return _API; } CC_INLINE const String &getDeviceName() const { return _deviceName; } @@ -57,6 +64,7 @@ class CC_DLL Device : public Object { CC_INLINE int getMaxUniformBlockSize() const { return _maxUniformBlockSize; } CC_INLINE int getMaxTextureSize() const { return _maxTextureSize; } CC_INLINE int getMaxCubeMapTextureSize() const { return _maxCubeMapTextureSize; } + CC_INLINE int getUboOffsetAlignment() const { return _uboOffsetAlignment; } CC_INLINE int getDepthBits() const { return _depthBits; } CC_INLINE int getStencilBits() const { return _stencilBits; } CC_INLINE uint getShaderIdGen() { return _shaderIdGen++; } @@ -83,21 +91,22 @@ class CC_DLL Device : public Object { uintptr_t _windowHandle = 0; Context *_context = nullptr; Queue *_queue = nullptr; - uint _numDrawCalls = 0; - uint _numInstances = 0; - uint _numTriangles = 0; - uint _maxVertexAttributes = 0; - uint _maxVertexUniformVectors = 0; - uint _maxFragmentUniformVectors = 0; - uint _maxTextureUnits = 0; - uint _maxVertexTextureUnits = 0; + uint _numDrawCalls = 0u; + uint _numInstances = 0u; + uint _numTriangles = 0u; + uint _maxVertexAttributes = 0u; + uint _maxVertexUniformVectors = 0u; + uint _maxFragmentUniformVectors = 0u; + uint _maxTextureUnits = 0u; + uint _maxVertexTextureUnits = 0u; uint _maxUniformBufferBindings = GFX_MAX_BUFFER_BINDINGS; - uint _maxUniformBlockSize = 0; - uint _maxTextureSize = 0; - uint _maxCubeMapTextureSize = 0; - uint _depthBits = 0; - uint _stencilBits = 0; - uint _shaderIdGen = 0; + uint _maxUniformBlockSize = 0u; + uint _maxTextureSize = 0u; + uint _maxCubeMapTextureSize = 0u; + uint _uboOffsetAlignment = 0u; + uint _depthBits = 0u; + uint _stencilBits = 0u; + uint _shaderIdGen = 0u; unordered_map _macros; float _clipSpaceMinZ = -1.0f; float _screenSpaceSignY = 1.0f; diff --git a/cocos/renderer/core/gfx/GFXPipelineLayout.cc b/cocos/renderer/core/gfx/GFXPipelineLayout.cc new file mode 100644 index 00000000000..4b45efd2cca --- /dev/null +++ b/cocos/renderer/core/gfx/GFXPipelineLayout.cc @@ -0,0 +1,15 @@ +#include "CoreStd.h" +#include "GFXPipelineLayout.h" + +namespace cc { +namespace gfx { + +PipelineLayout::PipelineLayout(Device *device) +: GFXObject(ObjectType::PIPELINE_LAYOUT), _device(device) { +} + +PipelineLayout::~PipelineLayout() { +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/core/gfx/GFXPipelineLayout.h b/cocos/renderer/core/gfx/GFXPipelineLayout.h new file mode 100644 index 00000000000..ecfbff2f5fe --- /dev/null +++ b/cocos/renderer/core/gfx/GFXPipelineLayout.h @@ -0,0 +1,29 @@ +#ifndef CC_CORE_GFX_PIPELINE_LAYOUT_H_ +#define CC_CORE_GFX_PIPELINE_LAYOUT_H_ + +#include "GFXDef.h" + +namespace cc { +namespace gfx { + +class CC_DLL PipelineLayout : public GFXObject { +public: + PipelineLayout(Device *device); + virtual ~PipelineLayout(); + +public: + virtual bool initialize(const PipelineLayoutInfo &info) = 0; + virtual void destroy() = 0; + + CC_INLINE Device *getDevice() const { return _device; } + CC_INLINE const DescriptorSetLayoutList &getSetLayouts() const { return _setLayouts; } + +protected: + Device *_device = nullptr; + DescriptorSetLayoutList _setLayouts; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_CORE_GFX_PIPELINE_LAYOUT_H_ diff --git a/cocos/renderer/core/gfx/GFXPipelineState.h b/cocos/renderer/core/gfx/GFXPipelineState.h index 08d7c28498f..3e0aa7fa566 100755 --- a/cocos/renderer/core/gfx/GFXPipelineState.h +++ b/cocos/renderer/core/gfx/GFXPipelineState.h @@ -24,6 +24,7 @@ class CC_DLL PipelineState : public GFXObject { CC_INLINE const DepthStencilState &getDepthStencilState() const { return _depthStencilState; } CC_INLINE const BlendState &getBlendState() const { return _blendState; } CC_INLINE const RenderPass *getRenderPass() const { return _renderPass; } + CC_INLINE const PipelineLayout *getPipelineLayout() const { return _pipelineLayout; } protected: Device *_device = nullptr; @@ -35,6 +36,7 @@ class CC_DLL PipelineState : public GFXObject { DepthStencilState _depthStencilState; BlendState _blendState; RenderPass *_renderPass = nullptr; + PipelineLayout *_pipelineLayout = nullptr; }; } // namespace gfx diff --git a/cocos/renderer/core/gfx/GFXTexture.h b/cocos/renderer/core/gfx/GFXTexture.h index 31fa9fc72ad..eec972cbbe4 100755 --- a/cocos/renderer/core/gfx/GFXTexture.h +++ b/cocos/renderer/core/gfx/GFXTexture.h @@ -29,6 +29,7 @@ class CC_DLL Texture : public GFXObject { CC_INLINE SampleCount getSamples() const { return _samples; } CC_INLINE TextureFlags getFlags() const { return _flags; } CC_INLINE uint8_t *getBuffer() const { return _buffer; } + CC_INLINE bool isTextureView() const { return _isTextureView; } protected: Device *_device = nullptr; @@ -46,6 +47,7 @@ class CC_DLL Texture : public GFXObject { SampleCount _samples = SampleCount::X1; TextureFlags _flags = TextureFlagBit::NONE; uint8_t *_buffer = nullptr; + bool _isTextureView = false; }; } // namespace gfx diff --git a/cocos/renderer/gfx-gles2/CMakeLists.txt b/cocos/renderer/gfx-gles2/CMakeLists.txt index be1af23001b..c825e9e46ee 100644 --- a/cocos/renderer/gfx-gles2/CMakeLists.txt +++ b/cocos/renderer/gfx-gles2/CMakeLists.txt @@ -64,7 +64,7 @@ endif() if(COCOS_PLATFORM_OSX) list(REMOVE_ITEM ALL_FILES "${COCOS_SRC_PATH}/renderer/gfx-gles2/GLES2Context.mm") endif() - + add_definitions("-DCC_GLES2_EXPORTS") if(WIN32) add_definitions("-DGLEW_BUILD") @@ -87,4 +87,4 @@ set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME_DEBUG CCGFXGLES2_d) use_precompiled_header("${CMAKE_CURRENT_SOURCE_DIR}/GLES2Std.h" "${CMAKE_CURRENT_SOURCE_DIR}/GLES2Std.cpp" SOURCE_CPP_FILES) -message(STATUS "${TARGET_NAME} configuration completed.") +message(STATUS "${TARGET_NAME} configuration completed.") diff --git a/cocos/renderer/gfx-gles2/GLES2BindingLayout.cc b/cocos/renderer/gfx-gles2/GLES2BindingLayout.cc deleted file mode 100644 index 1644c78ae22..00000000000 --- a/cocos/renderer/gfx-gles2/GLES2BindingLayout.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include "GLES2Std.h" -#include "GLES2BindingLayout.h" -#include "GLES2Commands.h" -#include "GLES2Buffer.h" -#include "GLES2Sampler.h" -#include "GLES2Texture.h" - -namespace cc { -namespace gfx { - -GLES2BindingLayout::GLES2BindingLayout(Device *device) -: BindingLayout(device) { -} - -GLES2BindingLayout::~GLES2BindingLayout() { -} - -bool GLES2BindingLayout::initialize(const BindingLayoutInfo &info) { - - const UniformBlockList &blocks = info.shader->getBlocks(); - const UniformSamplerList &samplers = info.shader->getSamplers(); - const uint bindingCount = blocks.size() + samplers.size(); - - if (bindingCount) { - _bindingUnits.resize(bindingCount); - for (size_t i = 0u; i < blocks.size(); ++i) { - const UniformBlock &binding = blocks[i]; - BindingUnit &bindingUnit = _bindingUnits[i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::UNIFORM_BUFFER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = 1; - } - for (size_t i = 0u; i < samplers.size(); ++i) { - const UniformSampler &binding = samplers[i]; - BindingUnit &bindingUnit = _bindingUnits[blocks.size() + i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::SAMPLER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = binding.count; - } - } - - _gpuBindingLayout = CC_NEW(GLES2GPUBindingLayout); - _gpuBindingLayout->gpuBindings.resize(_bindingUnits.size()); - for (size_t i = 0; i < _gpuBindingLayout->gpuBindings.size(); ++i) { - GLES2GPUBinding &gpuBinding = _gpuBindingLayout->gpuBindings[i]; - const BindingUnit &bindingUnit = _bindingUnits[i]; - gpuBinding.binding = bindingUnit.binding; - gpuBinding.type = bindingUnit.type; - gpuBinding.name = bindingUnit.name; - } - - _status = Status::SUCCESS; - - return true; -} - -void GLES2BindingLayout::destroy() { - if (_gpuBindingLayout) { - CC_DELETE(_gpuBindingLayout); - _gpuBindingLayout = nullptr; - } - _status = Status::UNREADY; -} - -void GLES2BindingLayout::update() { - if (_isDirty && _gpuBindingLayout) { - for (size_t i = 0; i < _bindingUnits.size(); ++i) { - BindingUnit &bindingUnit = _bindingUnits[i]; - switch (bindingUnit.type) { - case BindingType::UNIFORM_BUFFER: { - if (bindingUnit.buffer) { - _gpuBindingLayout->gpuBindings[i].gpuBuffer = ((GLES2Buffer *)bindingUnit.buffer)->gpuBuffer(); - } - break; - } - case BindingType::SAMPLER: { - if (bindingUnit.texture) { - _gpuBindingLayout->gpuBindings[i].gpuTexture = ((GLES2Texture *)bindingUnit.texture)->gpuTexture(); - } - if (bindingUnit.sampler) { - _gpuBindingLayout->gpuBindings[i].gpuSampler = ((GLES2Sampler *)bindingUnit.sampler)->gpuSampler(); - } - break; - } - default:; - } - } - _isDirty = false; - } -} - -} // namespace gfx -} // namespace cc diff --git a/cocos/renderer/gfx-gles2/GLES2BindingLayout.h b/cocos/renderer/gfx-gles2/GLES2BindingLayout.h deleted file mode 100644 index 5e7f6e2fce5..00000000000 --- a/cocos/renderer/gfx-gles2/GLES2BindingLayout.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CC_GFXGLES2_GLES2_BINDING_LAYOUT_H_ -#define CC_GFXGLES2_GLES2_BINDING_LAYOUT_H_ - -namespace cc { -namespace gfx { - -class GLES2GPUBindingLayout; - -class CC_GLES2_API GLES2BindingLayout : public BindingLayout { -public: - GLES2BindingLayout(Device *device); - ~GLES2BindingLayout(); - -public: - virtual bool initialize(const BindingLayoutInfo &info) override; - virtual void destroy() override; - virtual void update() override; - - CC_INLINE GLES2GPUBindingLayout *gpuBindingLayout() const { return _gpuBindingLayout; } - -private: - GLES2GPUBindingLayout *_gpuBindingLayout = nullptr; -}; - -} // namespace gfx -} // namespace cc - -#endif diff --git a/cocos/renderer/gfx-gles2/GLES2Buffer.cc b/cocos/renderer/gfx-gles2/GLES2Buffer.cc index 7675d2fe7be..52ff4d8f71e 100644 --- a/cocos/renderer/gfx-gles2/GLES2Buffer.cc +++ b/cocos/renderer/gfx-gles2/GLES2Buffer.cc @@ -1,4 +1,5 @@ #include "GLES2Std.h" + #include "GLES2Buffer.h" #include "GLES2Commands.h" @@ -17,7 +18,7 @@ bool GLES2Buffer::initialize(const BufferInfo &info) { _usage = info.usage; _memUsage = info.memUsage; _size = info.size; - _stride = std::max(info.stride, 1U); + _stride = std::max(info.stride, 1u); _count = _size / _stride; _flags = info.flags; @@ -57,6 +58,26 @@ bool GLES2Buffer::initialize(const BufferInfo &info) { return true; } +bool GLES2Buffer::initialize(const BufferViewInfo &info) { + + _isBufferView = true; + + GLES2Buffer *buffer = (GLES2Buffer *)info.buffer; + + _usage = buffer->_usage; + _memUsage = buffer->_memUsage; + _size = _stride = info.range; + _count = 1u; + _flags = buffer->_flags; + + _gpuBufferView = CC_NEW(GLES2GPUBufferView); + _gpuBufferView->gpuBuffer = buffer->gpuBuffer(); + _gpuBufferView->range = _size; + _gpuBufferView->offset = info.offset; + + return true; +} + void GLES2Buffer::destroy() { if (_gpuBuffer) { GLES2CmdFuncDestroyBuffer((GLES2Device *)_device, _gpuBuffer); @@ -65,6 +86,8 @@ void GLES2Buffer::destroy() { _gpuBuffer = nullptr; } + CC_SAFE_DELETE(_gpuBufferView); + if (_buffer) { CC_FREE(_buffer); _device->getMemoryStatus().bufferSize -= _size; @@ -75,6 +98,8 @@ void GLES2Buffer::destroy() { } void GLES2Buffer::resize(uint size) { + CCASSERT(!_isBufferView, "Cannot resize buffer views"); + if (_size != size) { const uint oldSize = _size; _size = size; @@ -106,8 +131,10 @@ void GLES2Buffer::resize(uint size) { } void GLES2Buffer::update(void *buffer, uint offset, uint size) { + CCASSERT(!_isBufferView, "Cannot update through buffer views"); CCASSERT(size != 0, "Should not update buffer with 0 bytes of data"); CCASSERT(buffer, "Buffer should not be nullptr"); + if (_buffer) { memcpy(_buffer + offset, buffer, size); } diff --git a/cocos/renderer/gfx-gles2/GLES2Buffer.h b/cocos/renderer/gfx-gles2/GLES2Buffer.h index dcc4caf9c00..05e0cc53aa7 100644 --- a/cocos/renderer/gfx-gles2/GLES2Buffer.h +++ b/cocos/renderer/gfx-gles2/GLES2Buffer.h @@ -5,6 +5,7 @@ namespace cc { namespace gfx { class GLES2GPUBuffer; +class GLES2GPUBufferView; class CC_GLES2_API GLES2Buffer : public Buffer { public: @@ -13,14 +14,17 @@ class CC_GLES2_API GLES2Buffer : public Buffer { public: virtual bool initialize(const BufferInfo &info) override; + virtual bool initialize(const BufferViewInfo &info) override; virtual void destroy() override; virtual void resize(uint size) override; virtual void update(void *buffer, uint offset, uint size) override; CC_INLINE GLES2GPUBuffer *gpuBuffer() const { return _gpuBuffer; } + CC_INLINE GLES2GPUBufferView *gpuBufferView() const { return _gpuBufferView; } private: GLES2GPUBuffer *_gpuBuffer = nullptr; + GLES2GPUBufferView *_gpuBufferView = nullptr; }; } // namespace gfx diff --git a/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc b/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc index 714509fb817..8201d5f2071 100644 --- a/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc +++ b/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc @@ -1,9 +1,9 @@ #include "GLES2Std.h" -#include "GLES2BindingLayout.h" #include "GLES2Buffer.h" #include "GLES2CommandAllocator.h" #include "GLES2CommandBuffer.h" +#include "GLES2DescriptorSet.h" #include "GLES2Device.h" #include "GLES2Framebuffer.h" #include "GLES2InputAssembler.h" @@ -27,6 +27,10 @@ bool GLES2CommandBuffer::initialize(const CommandBufferInfo &info) { _gles2Allocator = ((GLES2Device *)_device)->cmdAllocator(); + uint setCount = ((GLES2Device *)_device)->bindingMappingInfo().bufferOffsets.size(); + _curGPUDescriptorSets.resize(setCount); + _curDynamicOffsets.resize(setCount); + _cmdPackage = CC_NEW(GLES2CmdPackage); _status = Status::SUCCESS; @@ -46,8 +50,10 @@ void GLES2CommandBuffer::destroy() { void GLES2CommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { _gles2Allocator->clearCmds(_cmdPackage); _curGPUPipelineState = nullptr; - _curGPUBlendLayout = nullptr; _curGPUInputAssember = nullptr; + _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); + for (vector &offsets : _curDynamicOffsets) offsets.clear(); + _numDrawCalls = 0; _numInstances = 0; _numTriangles = 0; @@ -60,15 +66,15 @@ void GLES2CommandBuffer::end() { _isInRenderPass = false; } -void GLES2CommandBuffer::beginRenderPass(RenderPass* renderPass, Framebuffer *fbo, const Rect &renderArea, const vector &colors, float depth, int stencil) { +void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) { _isInRenderPass = true; GLES2CmdBeginRenderPass *cmd = _gles2Allocator->beginRenderPassCmdPool.alloc(); cmd->gpuRenderPass = ((GLES2RenderPass *)renderPass)->gpuRenderPass(); cmd->gpuFBO = ((GLES2Framebuffer *)fbo)->gpuFBO(); cmd->renderArea = renderArea; - cmd->numClearColors = (uint32_t)colors.size(); - for (uint i = 0; i < colors.size(); ++i) { + cmd->numClearColors = cmd->gpuRenderPass->colorAttachments.size(); + for (uint i = 0; i < cmd->numClearColors; ++i) { cmd->clearColors[i] = colors[i]; } cmd->clearDepth = depth; @@ -83,13 +89,25 @@ void GLES2CommandBuffer::endRenderPass() { } void GLES2CommandBuffer::bindPipelineState(PipelineState *pso) { - _curGPUPipelineState = ((GLES2PipelineState *)pso)->gpuPipelineState(); - _isStateInvalid = true; + GLES2GPUPipelineState *gpuPipelineState = ((GLES2PipelineState *)pso)->gpuPipelineState(); + if (_curGPUPipelineState != gpuPipelineState) { + _curGPUPipelineState = gpuPipelineState; + _isStateInvalid = true; + } } -void GLES2CommandBuffer::bindBindingLayout(BindingLayout *layout) { - _curGPUBlendLayout = ((GLES2BindingLayout *)layout)->gpuBindingLayout(); - _isStateInvalid = true; +void GLES2CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { + CCASSERT(_curGPUDescriptorSets.size() > set, "Invalid set index"); + + GLES2GPUDescriptorSet *gpuDescriptorSet = ((GLES2DescriptorSet *)descriptorSet)->gpuDescriptorSet(); + if (_curGPUDescriptorSets[set] != gpuDescriptorSet) { + _curGPUDescriptorSets[set] = gpuDescriptorSet; + _isStateInvalid = true; + } + if (dynamicOffsetCount) { + _curDynamicOffsets[set].assign(dynamicOffsets, dynamicOffsets + dynamicOffsetCount); + _isStateInvalid = true; + } } void GLES2CommandBuffer::bindInputAssembler(InputAssembler *ia) { @@ -151,20 +169,20 @@ void GLES2CommandBuffer::setBlendConstants(const Color &constants) { } } -void GLES2CommandBuffer::setDepthBound(float min_bounds, float max_bounds) { - if (math::IsNotEqualF(_curDepthBounds.minBounds, min_bounds) || - math::IsNotEqualF(_curDepthBounds.maxBounds, max_bounds)) { - _curDepthBounds.minBounds = min_bounds; - _curDepthBounds.maxBounds = max_bounds; +void GLES2CommandBuffer::setDepthBound(float minBounds, float maxBounds) { + if (math::IsNotEqualF(_curDepthBounds.minBounds, minBounds) || + math::IsNotEqualF(_curDepthBounds.maxBounds, maxBounds)) { + _curDepthBounds.minBounds = minBounds; + _curDepthBounds.maxBounds = maxBounds; _isStateInvalid = true; } } void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { if ((_curStencilWriteMask.face != face) || - (_curStencilWriteMask.write_mask != mask)) { + (_curStencilWriteMask.writeMask != mask)) { _curStencilWriteMask.face = face; - _curStencilWriteMask.write_mask = mask; + _curStencilWriteMask.writeMask = mask; _isStateInvalid = true; } } @@ -237,19 +255,16 @@ void GLES2CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint } } -void GLES2CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { +void GLES2CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) || (_type == CommandBufferType::SECONDARY)) { GLES2GPUTexture *gpuTexture = ((GLES2Texture *)texture)->gpuTexture(); if (gpuTexture) { GLES2CmdCopyBufferToTexture *cmd = _gles2Allocator->copyBufferToTextureCmdPool.alloc(); cmd->gpuTexture = gpuTexture; - cmd->buffers.resize(buffers.size()); - cmd->regions.resize(regions.size()); - for (uint i = 0; i < static_cast(regions.size()); ++i) { - cmd->buffers[i] = buffers[i]; - cmd->regions[i] = regions[i]; - } + cmd->buffers = buffers; + cmd->regions = regions; + cmd->count = count; _cmdPackage->copyBufferToTextureCmds.push(cmd); _cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE); @@ -259,48 +274,51 @@ void GLES2CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Tex } } -void GLES2CommandBuffer::execute(const CommandBufferList &cmd_buffs, uint32_t count) { +void GLES2CommandBuffer::execute(const CommandBuffer *const *cmdBuffs, uint32_t count) { for (uint i = 0; i < count; ++i) { - GLES2CommandBuffer *cmd_buff = (GLES2CommandBuffer *)cmd_buffs[i]; + GLES2CommandBuffer *cmdBuff = (GLES2CommandBuffer *)cmdBuffs[i]; - for (uint j = 0; j < cmd_buff->_cmdPackage->beginRenderPassCmds.size(); ++j) { - GLES2CmdBeginRenderPass *cmd = cmd_buff->_cmdPackage->beginRenderPassCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->beginRenderPassCmds.size(); ++j) { + GLES2CmdBeginRenderPass *cmd = cmdBuff->_cmdPackage->beginRenderPassCmds[j]; + ++cmd->refCount; _cmdPackage->beginRenderPassCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->bindStatesCmds.size(); ++j) { - GLES2CmdBindStates *cmd = cmd_buff->_cmdPackage->bindStatesCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->bindStatesCmds.size(); ++j) { + GLES2CmdBindStates *cmd = cmdBuff->_cmdPackage->bindStatesCmds[j]; + ++cmd->refCount; _cmdPackage->bindStatesCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->drawCmds.size(); ++j) { - GLES2CmdDraw *cmd = cmd_buff->_cmdPackage->drawCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->drawCmds.size(); ++j) { + GLES2CmdDraw *cmd = cmdBuff->_cmdPackage->drawCmds[j]; + ++cmd->refCount; _cmdPackage->drawCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->updateBufferCmds.size(); ++j) { - GLES2CmdUpdateBuffer *cmd = cmd_buff->_cmdPackage->updateBufferCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->updateBufferCmds.size(); ++j) { + GLES2CmdUpdateBuffer *cmd = cmdBuff->_cmdPackage->updateBufferCmds[j]; + ++cmd->refCount; _cmdPackage->updateBufferCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->copyBufferToTextureCmds.size(); ++j) { - GLES2CmdCopyBufferToTexture *cmd = cmd_buff->_cmdPackage->copyBufferToTextureCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->copyBufferToTextureCmds.size(); ++j) { + GLES2CmdCopyBufferToTexture *cmd = cmdBuff->_cmdPackage->copyBufferToTextureCmds[j]; + ++cmd->refCount; _cmdPackage->copyBufferToTextureCmds.push(cmd); } - _cmdPackage->cmds.concat(cmd_buff->_cmdPackage->cmds); + _cmdPackage->cmds.concat(cmdBuff->_cmdPackage->cmds); - _numDrawCalls += cmd_buff->getNumDrawCalls(); - _numInstances += cmd_buff->getNumInstances(); - _numTriangles += cmd_buff->getNumTris(); + _numDrawCalls += cmdBuff->getNumDrawCalls(); + _numInstances += cmdBuff->getNumInstances(); + _numTriangles += cmdBuff->getNumTris(); } } void GLES2CommandBuffer::BindStates() { GLES2CmdBindStates *cmd = _gles2Allocator->bindStatesCmdPool.alloc(); cmd->gpuPipelineState = _curGPUPipelineState; - cmd->gpuBindingLayout = _curGPUBlendLayout; cmd->gpuInputAssembler = _curGPUInputAssember; + cmd->gpuDescriptorSets = _curGPUDescriptorSets; + for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { + cmd->dynamicOffsets.insert(cmd->dynamicOffsets.end(), _curDynamicOffsets[i].begin(), _curDynamicOffsets[i].end()); + } cmd->viewport = _curViewport; cmd->scissor = _curScissor; cmd->lineWidth = _curLineWidth; diff --git a/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h b/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h index e17ca29ab64..4540435d811 100644 --- a/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h +++ b/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h @@ -21,23 +21,23 @@ class CC_GLES2_API GLES2CommandBuffer : public CommandBuffer { virtual void begin(RenderPass *renderPass = nullptr, uint subpass = 0, Framebuffer *frameBuffer = nullptr) override; virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector &colors, float depth, int stencil) override; + virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) override; virtual void endRenderPass() override; virtual void bindPipelineState(PipelineState *pso) override; - virtual void bindBindingLayout(BindingLayout *layout) override; + virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; virtual void bindInputAssembler(InputAssembler *ia) override; virtual void setViewport(const Viewport &vp) override; virtual void setScissor(const Rect &rect) override; virtual void setLineWidth(const float width) override; virtual void setDepthBias(float constant, float clamp, float slope) override; virtual void setBlendConstants(const Color &constants) override; - virtual void setDepthBound(float min_bounds, float max_bounds) override; + virtual void setDepthBound(float minBounds, float maxBounds) override; virtual void setStencilWriteMask(StencilFace face, uint mask) override; virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; virtual void draw(InputAssembler *ia) override; virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset) override; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override; - virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; + virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) override; private: void BindStates(); @@ -47,7 +47,8 @@ class CC_GLES2_API GLES2CommandBuffer : public CommandBuffer { GLES2CommandAllocator *_gles2Allocator = nullptr; bool _isInRenderPass = false; GLES2GPUPipelineState *_curGPUPipelineState = nullptr; - GLES2GPUBindingLayout *_curGPUBlendLayout = nullptr; + vector _curGPUDescriptorSets; + vector> _curDynamicOffsets; GLES2GPUInputAssembler *_curGPUInputAssember = nullptr; Viewport _curViewport; Rect _curScissor; diff --git a/cocos/renderer/gfx-gles2/GLES2Commands.cc b/cocos/renderer/gfx-gles2/GLES2Commands.cc index 410fdb036a2..5b6a16d9a4f 100644 --- a/cocos/renderer/gfx-gles2/GLES2Commands.cc +++ b/cocos/renderer/gfx-gles2/GLES2Commands.cc @@ -374,7 +374,7 @@ uint GLComponentCount(GLenum glType) { } } -const GLenum GLES3_WRAPS[] = { +const GLenum GLES2_WRAPS[] = { GL_REPEAT, GL_MIRRORED_REPEAT, GL_CLAMP_TO_EDGE, @@ -636,8 +636,8 @@ void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -669,8 +669,8 @@ void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) uint w = gpuTexture->width; uint h = gpuTexture->height; for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -732,8 +732,8 @@ void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -764,8 +764,8 @@ void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) uint w = gpuTexture->width; uint h = gpuTexture->height; for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -805,59 +805,59 @@ void GLES2CmdFuncCreateSampler(GLES2Device *device, GLES2GPUSampler *gpuSampler) gpuSampler->glMagFilter = GL_NEAREST; } - gpuSampler->glWrapS = GLES3_WRAPS[(int)gpuSampler->addressU]; - gpuSampler->glWrapT = GLES3_WRAPS[(int)gpuSampler->addressV]; - gpuSampler->glWrapR = GLES3_WRAPS[(int)gpuSampler->addressW]; + gpuSampler->glWrapS = GLES2_WRAPS[(int)gpuSampler->addressU]; + gpuSampler->glWrapT = GLES2_WRAPS[(int)gpuSampler->addressV]; + gpuSampler->glWrapR = GLES2_WRAPS[(int)gpuSampler->addressW]; } void GLES2CmdFuncDestroySampler(GLES2Device *device, GLES2GPUSampler *gpuSampler) { } void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { - GLenum gl_shader_type = 0; - String shader_type_str; + GLenum glShaderType = 0; + String shaderTypeStr; GLint status; for (size_t i = 0; i < gpuShader->gpuStages.size(); ++i) { - GLES2GPUShaderStage &gpu_stage = gpuShader->gpuStages[i]; + GLES2GPUShaderStage &gpuStage = gpuShader->gpuStages[i]; - switch (gpu_stage.type) { - case ShaderType::VERTEX: { - gl_shader_type = GL_VERTEX_SHADER; - shader_type_str = "Vertex Shader"; + switch (gpuStage.type) { + case ShaderStageFlagBit::VERTEX: { + glShaderType = GL_VERTEX_SHADER; + shaderTypeStr = "Vertex Shader"; break; } - case ShaderType::FRAGMENT: { - gl_shader_type = GL_FRAGMENT_SHADER; - shader_type_str = "Fragment Shader"; + case ShaderStageFlagBit::FRAGMENT: { + glShaderType = GL_FRAGMENT_SHADER; + shaderTypeStr = "Fragment Shader"; break; } default: { - CCASSERT(false, "Unsupported ShaderType"); + CCASSERT(false, "Unsupported ShaderStageFlagBit"); return; } } - gpu_stage.glShader = glCreateShader(gl_shader_type); - const char *shader_src = gpu_stage.source.c_str(); - glShaderSource(gpu_stage.glShader, 1, (const GLchar **)&shader_src, nullptr); - glCompileShader(gpu_stage.glShader); + gpuStage.glShader = glCreateShader(glShaderType); + const char *shaderSrc = gpuStage.source.c_str(); + glShaderSource(gpuStage.glShader, 1, (const GLchar **)&shaderSrc, nullptr); + glCompileShader(gpuStage.glShader); - glGetShaderiv(gpu_stage.glShader, GL_COMPILE_STATUS, &status); + glGetShaderiv(gpuStage.glShader, GL_COMPILE_STATUS, &status); if (status != 1) { - GLint log_size = 0; - glGetShaderiv(gpu_stage.glShader, GL_INFO_LOG_LENGTH, &log_size); + GLint logSize = 0; + glGetShaderiv(gpuStage.glShader, GL_INFO_LOG_LENGTH, &logSize); - ++log_size; - GLchar *logs = (GLchar *)CC_MALLOC(log_size); - glGetShaderInfoLog(gpu_stage.glShader, log_size, nullptr, logs); + ++logSize; + GLchar *logs = (GLchar *)CC_MALLOC(logSize); + glGetShaderInfoLog(gpuStage.glShader, logSize, nullptr, logs); - CC_LOG_ERROR("%s in %s compilation failed.", shader_type_str.c_str(), gpuShader->name.c_str()); - CC_LOG_ERROR("Shader source:%s", gpu_stage.source.c_str()); + CC_LOG_ERROR("%s in %s compilation failed.", shaderTypeStr.c_str(), gpuShader->name.c_str()); + CC_LOG_ERROR("Shader source:%s", gpuStage.source.c_str()); CC_LOG_ERROR(logs); CC_FREE(logs); - glDeleteShader(gpu_stage.glShader); - gpu_stage.glShader = 0; + glDeleteShader(gpuStage.glShader); + gpuStage.glShader = 0; return; } } @@ -866,31 +866,31 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { // link program for (size_t i = 0; i < gpuShader->gpuStages.size(); ++i) { - GLES2GPUShaderStage &gpu_stage = gpuShader->gpuStages[i]; - glAttachShader(gpuShader->glProgram, gpu_stage.glShader); + GLES2GPUShaderStage &gpuStage = gpuShader->gpuStages[i]; + glAttachShader(gpuShader->glProgram, gpuStage.glShader); } glLinkProgram(gpuShader->glProgram); // detach & delete immediately for (size_t i = 0; i < gpuShader->gpuStages.size(); ++i) { - GLES2GPUShaderStage &gpu_stage = gpuShader->gpuStages[i]; - if (gpu_stage.glShader) { - glDetachShader(gpuShader->glProgram, gpu_stage.glShader); - glDeleteShader(gpu_stage.glShader); - gpu_stage.glShader = 0; + GLES2GPUShaderStage &gpuStage = gpuShader->gpuStages[i]; + if (gpuStage.glShader) { + glDetachShader(gpuShader->glProgram, gpuStage.glShader); + glDeleteShader(gpuStage.glShader); + gpuStage.glShader = 0; } } glGetProgramiv(gpuShader->glProgram, GL_LINK_STATUS, &status); if (status != 1) { CC_LOG_ERROR("Failed to link Shader [%s].", gpuShader->name.c_str()); - GLint log_size = 0; - glGetProgramiv(gpuShader->glProgram, GL_INFO_LOG_LENGTH, &log_size); - if (log_size) { - ++log_size; - GLchar *logs = (GLchar *)CC_MALLOC(log_size); - glGetProgramInfoLog(gpuShader->glProgram, log_size, nullptr, logs); + GLint logSize = 0; + glGetProgramiv(gpuShader->glProgram, GL_INFO_LOG_LENGTH, &logSize); + if (logSize) { + ++logSize; + GLchar *logs = (GLchar *)CC_MALLOC(logSize); + glGetProgramInfoLog(gpuShader->glProgram, logSize, nullptr, logs); CC_LOG_ERROR("Failed to link shader '%s'.", gpuShader->name.c_str()); CC_LOG_ERROR(logs); @@ -901,33 +901,33 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { CC_LOG_INFO("Shader '%s' compilation succeeded.", gpuShader->name.c_str()); - GLint attr_max_length = 0; - GLint attr_count = 0; - glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attr_max_length); - glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTES, &attr_count); + GLint attrMaxLength = 0; + GLint attrCount = 0; + glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attrMaxLength); + glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTES, &attrCount); - GLchar gl_name[256]; - GLsizei gl_length; - GLsizei gl_size; + GLchar glName[256]; + GLsizei glLength; + GLsizei glSize; GLenum glType; - gpuShader->glInputs.resize(attr_count); - for (GLint i = 0; i < attr_count; ++i) { + gpuShader->glInputs.resize(attrCount); + for (GLint i = 0; i < attrCount; ++i) { GLES2GPUInput &gpuInput = gpuShader->glInputs[i]; - memset(gl_name, 0, sizeof(gl_name)); - glGetActiveAttrib(gpuShader->glProgram, i, attr_max_length, &gl_length, &gl_size, &glType, gl_name); - char *offset = strchr(gl_name, '['); + memset(glName, 0, sizeof(glName)); + glGetActiveAttrib(gpuShader->glProgram, i, attrMaxLength, &glLength, &glSize, &glType, glName); + char *offset = strchr(glName, '['); if (offset) { - gl_name[offset - gl_name] = '\0'; + glName[offset - glName] = '\0'; } - gpuInput.glLoc = glGetAttribLocation(gpuShader->glProgram, gl_name); + gpuInput.glLoc = glGetAttribLocation(gpuShader->glProgram, glName); gpuInput.binding = gpuInput.glLoc; - gpuInput.name = gl_name; + gpuInput.name = glName; gpuInput.type = MapType(glType); gpuInput.stride = GLTypeSize(glType); - gpuInput.count = gl_size; + gpuInput.count = glSize; gpuInput.size = gpuInput.stride * gpuInput.count; gpuInput.glType = glType; } @@ -942,12 +942,13 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { UniformBlock &block = gpuShader->blocks[i]; gpuBlock.name = block.name; + gpuBlock.set = block.set; gpuBlock.binding = block.binding; - gpuBlock.glUniforms.resize(block.uniforms.size()); + gpuBlock.glUniforms.resize(block.members.size()); for (size_t j = 0; j < gpuBlock.glUniforms.size(); ++j) { GLES2GPUUniform &gpuUniform = gpuBlock.glUniforms[j]; - Uniform &uniform = block.uniforms[j]; + Uniform &uniform = block.members[j]; gpuUniform.binding = GFX_INVALID_BINDING; gpuUniform.name = uniform.name; @@ -972,6 +973,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { for (size_t i = 0; i < gpuShader->glSamplers.size(); ++i) { UniformSampler &sampler = gpuShader->samplers[i]; GLES2GPUUniformSampler &gpuSampler = gpuShader->glSamplers[i]; + gpuSampler.set = sampler.set; gpuSampler.binding = sampler.binding; gpuSampler.name = sampler.name; gpuSampler.type = sampler.type; @@ -984,39 +986,39 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { GLint glActiveUniforms; glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORMS, &glActiveUniforms); - GLint unit_idx = 0; + GLint unitIdx = 0; - GLES2GPUUniformSamplerList active_gpu_samplers; + GLES2GPUUniformSamplerList activeGPUSamplers; for (GLint i = 0; i < glActiveUniforms; ++i) { - memset(gl_name, 0, sizeof(gl_name)); - glGetActiveUniform(gpuShader->glProgram, i, 255, &gl_length, &gl_size, &glType, gl_name); - char *u_offset = strchr(gl_name, '['); - if (u_offset) { - gl_name[u_offset - gl_name] = '\0'; + memset(glName, 0, sizeof(glName)); + glGetActiveUniform(gpuShader->glProgram, i, 255, &glLength, &glSize, &glType, glName); + char *offset = strchr(glName, '['); + if (offset) { + glName[offset - glName] = '\0'; } - String u_name = gl_name; - - bool is_sampler = (glType == GL_SAMPLER_2D) || - (glType == GL_SAMPLER_3D_OES) || - (glType == GL_SAMPLER_CUBE) || - (glType == GL_SAMPLER_CUBE_MAP_ARRAY_OES) || - (glType == GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_OES) || - (glType == GL_INT_SAMPLER_CUBE_MAP_ARRAY_OES) || - (glType == GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_OES); - if (is_sampler) { + String name = glName; + + bool isSampler = (glType == GL_SAMPLER_2D) || + (glType == GL_SAMPLER_3D_OES) || + (glType == GL_SAMPLER_CUBE) || + (glType == GL_SAMPLER_CUBE_MAP_ARRAY_OES) || + (glType == GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_OES) || + (glType == GL_INT_SAMPLER_CUBE_MAP_ARRAY_OES) || + (glType == GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_OES); + if (isSampler) { for (size_t s = 0; s < gpuShader->glSamplers.size(); ++s) { GLES2GPUUniformSampler &gpuSampler = gpuShader->glSamplers[s]; - if (gpuSampler.name == u_name) { - gpuSampler.units.resize(gl_size); - for (GLsizei u = 0; u < gl_size; ++u) { - gpuSampler.units[u] = unit_idx + u; + if (gpuSampler.name == name) { + gpuSampler.units.resize(glSize); + for (GLsizei u = 0; u < glSize; ++u) { + gpuSampler.units[u] = unitIdx + u; } - gpuSampler.glLoc = glGetUniformLocation(gpuShader->glProgram, gl_name); - unit_idx += gl_size; + gpuSampler.glLoc = glGetUniformLocation(gpuShader->glProgram, glName); + unitIdx += glSize; - active_gpu_samplers.push_back(gpuSampler); + activeGPUSamplers.push_back(gpuSampler); break; } } @@ -1024,9 +1026,9 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { for (size_t b = 0; b < gpuShader->glBlocks.size(); ++b) { GLES2GPUUniformBlock &gpuBlock = gpuShader->glBlocks[b]; for (size_t u = 0; u < gpuBlock.glUniforms.size(); ++u) { - if (gpuBlock.glUniforms[u].name == u_name) { + if (gpuBlock.glUniforms[u].name == name) { GLES2GPUUniform &gpuUniform = gpuBlock.glUniforms[u]; - gpuUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, gl_name); + gpuUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, glName); gpuUniform.buff = (uint8_t *)CC_MALLOC(gpuUniform.size); gpuBlock.glActiveUniforms.emplace_back(gpuUniform); @@ -1037,17 +1039,35 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } // for - if (active_gpu_samplers.size()) { + if (activeGPUSamplers.size()) { if (device->stateCache->glProgram != gpuShader->glProgram) { glUseProgram(gpuShader->glProgram); device->stateCache->glProgram = gpuShader->glProgram; } - for (size_t i = 0; i < active_gpu_samplers.size(); ++i) { - GLES2GPUUniformSampler &gpuSampler = active_gpu_samplers[i]; + for (size_t i = 0; i < activeGPUSamplers.size(); ++i) { + GLES2GPUUniformSampler &gpuSampler = activeGPUSamplers[i]; glUniform1iv(gpuSampler.glLoc, (GLsizei)gpuSampler.units.size(), gpuSampler.units.data()); } } + + // strip out the inactive ones + for (uint i = 0u; i < gpuShader->glBlocks.size();) { + if (gpuShader->glBlocks[i].glActiveUniforms.size()) { + i++; + } else { + gpuShader->glBlocks[i] = gpuShader->glBlocks.back(); + gpuShader->glBlocks.pop_back(); + } + } + for (uint i = 0u; i < gpuShader->glSamplers.size();) { + if (gpuShader->glSamplers[i].units.size()) { + i++; + } else { + gpuShader->glSamplers[i] = gpuShader->glSamplers.back(); + gpuShader->glSamplers.pop_back(); + } + } } void GLES2CmdFuncDestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader) { @@ -1074,14 +1094,14 @@ void GLES2CmdFuncCreateInputAssembler(GLES2Device *device, GLES2GPUInputAssemble } } - uint stream_offsets[GFX_MAX_VERTEX_ATTRIBUTES] = {0}; + uint streamOffsets[GFX_MAX_VERTEX_ATTRIBUTES] = {0}; gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size()); for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) { GLES2GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[i]; const Attribute &attrib = gpuInputAssembler->attributes[i]; - GLES2GPUBuffer *gpu_vb = (GLES2GPUBuffer *)gpuInputAssembler->gpuVertexBuffers[attrib.stream]; + GLES2GPUBuffer *gpuVB = (GLES2GPUBuffer *)gpuInputAssembler->gpuVertexBuffers[attrib.stream]; gpuAttribute.name = attrib.name; gpuAttribute.glType = FormatToGLType(attrib.format); @@ -1090,13 +1110,13 @@ void GLES2CmdFuncCreateInputAssembler(GLES2Device *device, GLES2GPUInputAssemble gpuAttribute.componentCount = GLComponentCount(gpuAttribute.glType); gpuAttribute.isNormalized = attrib.isNormalized; gpuAttribute.isInstanced = attrib.isInstanced; - gpuAttribute.offset = stream_offsets[attrib.stream]; + gpuAttribute.offset = streamOffsets[attrib.stream]; - if (gpu_vb) { - gpuAttribute.glBuffer = gpu_vb->glBuffer; - gpuAttribute.stride = gpu_vb->stride; + if (gpuVB) { + gpuAttribute.glBuffer = gpuVB->glBuffer; + gpuAttribute.stride = gpuVB->stride; } - stream_offsets[attrib.stream] += gpuAttribute.size; + streamOffsets[attrib.stream] += gpuAttribute.size; } } @@ -1133,7 +1153,7 @@ void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpu } GLenum attachments[GFX_MAX_ATTACHMENTS] = {0}; - uint attachment_count = 0; + uint attachmentCount = 0; for (size_t i = 0; i < gpuFBO->gpuColorTextures.size(); ++i) { GLES2GPUTexture *gpuColorTexture = gpuFBO->gpuColorTextures[i]; @@ -1141,7 +1161,7 @@ void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpu // Mipmap level in GLES2 should be 0. glFramebufferTexture2D(GL_FRAMEBUFFER, (GLenum)(GL_COLOR_ATTACHMENT0 + i), gpuColorTexture->glTarget, gpuColorTexture->glTexture, 0); - attachments[attachment_count++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + attachments[attachmentCount++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); } } @@ -1255,7 +1275,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } GLbitfield glClears = 0; - uint num_attachments = 0; + uint numAttachments = 0; gpuRenderPass = cmd->gpuRenderPass; for (uint j = 0; j < cmd->numClearColors; ++j) { @@ -1275,7 +1295,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR_EXT); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR_EXT); break; } default:; @@ -1297,14 +1317,14 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH_EXT); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH_EXT); break; } default:; } } // if (hasDepth) - bool has_stencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; - if (has_stencils) { + bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: { @@ -1320,16 +1340,16 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); break; } default:; } - } // if (has_stencils) + } // if (hasStencils) } // if - if (num_attachments && device->useDiscardFramebuffer()) { - glDiscardFramebufferEXT(GL_FRAMEBUFFER, num_attachments, glAttachments); + if (numAttachments && device->useDiscardFramebuffer()) { + glDiscardFramebufferEXT(GL_FRAMEBUFFER, numAttachments, glAttachments); } if (glClears) { @@ -1338,12 +1358,12 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { // restore states if (glClears & GL_COLOR_BUFFER_BIT) { - ColorMask color_mask = cache->bs.targets[0].blendColorMask; - if (color_mask != ColorMask::ALL) { - glColorMask((GLboolean)(color_mask & ColorMask::R), - (GLboolean)(color_mask & ColorMask::G), - (GLboolean)(color_mask & ColorMask::B), - (GLboolean)(color_mask & ColorMask::A)); + ColorMask colorMask = cache->bs.targets[0].blendColorMask; + if (colorMask != ColorMask::ALL) { + glColorMask((GLboolean)(colorMask & ColorMask::R), + (GLboolean)(colorMask & ColorMask::G), + (GLboolean)(colorMask & ColorMask::B), + (GLboolean)(colorMask & ColorMask::A)); } } @@ -1364,7 +1384,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } case GFXCmdType::END_RENDER_PASS: { GLES2CmdBeginRenderPass *cmd = cmdBeginRenderPass; - uint num_attachments = 0; + uint numAttachments = 0; for (uint j = 0; j < cmd->numClearColors; ++j) { const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[j]; if (colorAttachment.format != Format::UNKNOWN) { @@ -1373,7 +1393,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { case LoadOp::CLEAR: break; case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR_EXT); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR_EXT); break; } default:; @@ -1389,29 +1409,29 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { case LoadOp::CLEAR: break; case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH_EXT); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH_EXT); break; } default:; } } // if (hasDepth) - bool has_stencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; - if (has_stencils) { + bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: break; case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); break; } default:; } - } // if (has_stencils) + } // if (hasStencils) } // if - if (num_attachments && device->useDiscardFramebuffer()) { - glDiscardFramebufferEXT(GL_FRAMEBUFFER, num_attachments, glAttachments); + if (numAttachments && device->useDiscardFramebuffer()) { + glDiscardFramebufferEXT(GL_FRAMEBUFFER, numAttachments, glAttachments); } break; } @@ -1459,366 +1479,380 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } cache->rs.cullMode = gpuPipelineState->rs.cullMode; } - } - bool isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW; - if (reverseCW) isFrontFaceCCW = !isFrontFaceCCW; - if (cache->rs.isFrontFaceCCW != isFrontFaceCCW) { - glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW); - cache->rs.isFrontFaceCCW = isFrontFaceCCW; - } - if ((cache->rs.depthBias != gpuPipelineState->rs.depthBias) || - (cache->rs.depthBiasSlop != gpuPipelineState->rs.depthBiasSlop)) { - glPolygonOffset(cache->rs.depthBias, cache->rs.depthBiasSlop); - cache->rs.depthBiasSlop = gpuPipelineState->rs.depthBiasSlop; - } - if (cache->rs.lineWidth != gpuPipelineState->rs.lineWidth) { - glLineWidth(gpuPipelineState->rs.lineWidth); - cache->rs.lineWidth = gpuPipelineState->rs.lineWidth; - } + bool isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW; + if (reverseCW) isFrontFaceCCW = !isFrontFaceCCW; + if (cache->rs.isFrontFaceCCW != isFrontFaceCCW) { + glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW); + cache->rs.isFrontFaceCCW = isFrontFaceCCW; + } + if ((cache->rs.depthBias != gpuPipelineState->rs.depthBias) || + (cache->rs.depthBiasSlop != gpuPipelineState->rs.depthBiasSlop)) { + glPolygonOffset(cache->rs.depthBias, cache->rs.depthBiasSlop); + cache->rs.depthBiasSlop = gpuPipelineState->rs.depthBiasSlop; + } + if (cache->rs.lineWidth != gpuPipelineState->rs.lineWidth) { + glLineWidth(gpuPipelineState->rs.lineWidth); + cache->rs.lineWidth = gpuPipelineState->rs.lineWidth; + } - // bind depth-stencil state - if (cache->dss.depthTest != gpuPipelineState->dss.depthTest) { - if (gpuPipelineState->dss.depthTest) { - glEnable(GL_DEPTH_TEST); - } else { - glDisable(GL_DEPTH_TEST); + // bind depth-stencil state + if (cache->dss.depthTest != gpuPipelineState->dss.depthTest) { + if (gpuPipelineState->dss.depthTest) { + glEnable(GL_DEPTH_TEST); + } else { + glDisable(GL_DEPTH_TEST); + } + cache->dss.depthTest = gpuPipelineState->dss.depthTest; + } + if (cache->dss.depthWrite != gpuPipelineState->dss.depthWrite) { + glDepthMask(gpuPipelineState->dss.depthWrite); + cache->dss.depthWrite = gpuPipelineState->dss.depthWrite; + } + if (cache->dss.depthFunc != gpuPipelineState->dss.depthFunc) { + glDepthFunc(GLES2_CMP_FUNCS[(int)gpuPipelineState->dss.depthFunc]); + cache->dss.depthFunc = gpuPipelineState->dss.depthFunc; } - cache->dss.depthTest = gpuPipelineState->dss.depthTest; - } - if (cache->dss.depthWrite != gpuPipelineState->dss.depthWrite) { - glDepthMask(gpuPipelineState->dss.depthWrite); - cache->dss.depthWrite = gpuPipelineState->dss.depthWrite; - } - if (cache->dss.depthFunc != gpuPipelineState->dss.depthFunc) { - glDepthFunc(GLES2_CMP_FUNCS[(int)gpuPipelineState->dss.depthFunc]); - cache->dss.depthFunc = gpuPipelineState->dss.depthFunc; - } - // bind depth-stencil state - front - if (gpuPipelineState->dss.stencilTestFront || gpuPipelineState->dss.stencilTestBack) { - if (!cache->isStencilTestEnabled) { - glEnable(GL_STENCIL_TEST); - cache->isStencilTestEnabled = true; + // bind depth-stencil state - front + if (gpuPipelineState->dss.stencilTestFront || gpuPipelineState->dss.stencilTestBack) { + if (!cache->isStencilTestEnabled) { + glEnable(GL_STENCIL_TEST); + cache->isStencilTestEnabled = true; + } + } else { + if (cache->isStencilTestEnabled) { + glDisable(GL_STENCIL_TEST); + cache->isStencilTestEnabled = false; + } } - } else { - if (cache->isStencilTestEnabled) { - glDisable(GL_STENCIL_TEST); - cache->isStencilTestEnabled = false; + if (cache->dss.stencilFuncFront != gpuPipelineState->dss.stencilFuncFront || + cache->dss.stencilRefFront != gpuPipelineState->dss.stencilRefFront || + cache->dss.stencilReadMaskFront != gpuPipelineState->dss.stencilReadMaskFront) { + glStencilFuncSeparate(GL_FRONT, + GLES2_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncFront], + gpuPipelineState->dss.stencilRefFront, + gpuPipelineState->dss.stencilReadMaskFront); + cache->dss.stencilFuncFront = gpuPipelineState->dss.stencilFuncFront; + cache->dss.stencilRefFront = gpuPipelineState->dss.stencilRefFront; + cache->dss.stencilReadMaskFront = gpuPipelineState->dss.stencilReadMaskFront; + } + if (cache->dss.stencilFailOpFront != gpuPipelineState->dss.stencilFailOpFront || + cache->dss.stencilZFailOpFront != gpuPipelineState->dss.stencilZFailOpFront || + cache->dss.stencilPassOpFront != gpuPipelineState->dss.stencilPassOpFront) { + glStencilOpSeparate(GL_FRONT, + GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpFront], + GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpFront], + GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpFront]); + cache->dss.stencilFailOpFront = gpuPipelineState->dss.stencilFailOpFront; + cache->dss.stencilZFailOpFront = gpuPipelineState->dss.stencilZFailOpFront; + cache->dss.stencilPassOpFront = gpuPipelineState->dss.stencilPassOpFront; + } + if (cache->dss.stencilWriteMaskFront != gpuPipelineState->dss.stencilWriteMaskFront) { + glStencilMaskSeparate(GL_FRONT, gpuPipelineState->dss.stencilWriteMaskFront); + cache->dss.stencilWriteMaskFront = gpuPipelineState->dss.stencilWriteMaskFront; } - } - if (cache->dss.stencilFuncFront != gpuPipelineState->dss.stencilFuncFront || - cache->dss.stencilRefFront != gpuPipelineState->dss.stencilRefFront || - cache->dss.stencilReadMaskFront != gpuPipelineState->dss.stencilReadMaskFront) { - glStencilFuncSeparate(GL_FRONT, - GLES2_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncFront], - gpuPipelineState->dss.stencilRefFront, - gpuPipelineState->dss.stencilReadMaskFront); - cache->dss.stencilFuncFront = gpuPipelineState->dss.stencilFuncFront; - cache->dss.stencilRefFront = gpuPipelineState->dss.stencilRefFront; - cache->dss.stencilReadMaskFront = gpuPipelineState->dss.stencilReadMaskFront; - } - if (cache->dss.stencilFailOpFront != gpuPipelineState->dss.stencilFailOpFront || - cache->dss.stencilZFailOpFront != gpuPipelineState->dss.stencilZFailOpFront || - cache->dss.stencilPassOpFront != gpuPipelineState->dss.stencilPassOpFront) { - glStencilOpSeparate(GL_FRONT, - GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpFront], - GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpFront], - GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpFront]); - cache->dss.stencilFailOpFront = gpuPipelineState->dss.stencilFailOpFront; - cache->dss.stencilZFailOpFront = gpuPipelineState->dss.stencilZFailOpFront; - cache->dss.stencilPassOpFront = gpuPipelineState->dss.stencilPassOpFront; - } - if (cache->dss.stencilWriteMaskFront != gpuPipelineState->dss.stencilWriteMaskFront) { - glStencilMaskSeparate(GL_FRONT, gpuPipelineState->dss.stencilWriteMaskFront); - cache->dss.stencilWriteMaskFront = gpuPipelineState->dss.stencilWriteMaskFront; - } - // bind depth-stencil state - back - if (cache->dss.stencilFuncBack != gpuPipelineState->dss.stencilFuncBack || - cache->dss.stencilRefBack != gpuPipelineState->dss.stencilRefBack || - cache->dss.stencilReadMaskBack != gpuPipelineState->dss.stencilReadMaskBack) { - glStencilFuncSeparate(GL_BACK, - GLES2_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncBack], - gpuPipelineState->dss.stencilRefBack, - gpuPipelineState->dss.stencilReadMaskBack); - cache->dss.stencilFuncBack = gpuPipelineState->dss.stencilFuncBack; - cache->dss.stencilRefBack = gpuPipelineState->dss.stencilRefBack; - cache->dss.stencilReadMaskBack = gpuPipelineState->dss.stencilReadMaskBack; - } - if (cache->dss.stencilFailOpBack != gpuPipelineState->dss.stencilFailOpBack || - cache->dss.stencilZFailOpBack != gpuPipelineState->dss.stencilZFailOpBack || - cache->dss.stencilPassOpBack != gpuPipelineState->dss.stencilPassOpBack) { - glStencilOpSeparate(GL_BACK, - GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpBack], - GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpBack], - GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpBack]); - cache->dss.stencilFailOpBack = gpuPipelineState->dss.stencilFailOpBack; - cache->dss.stencilZFailOpBack = gpuPipelineState->dss.stencilZFailOpBack; - cache->dss.stencilPassOpBack = gpuPipelineState->dss.stencilPassOpBack; - } - if (cache->dss.stencilWriteMaskBack != gpuPipelineState->dss.stencilWriteMaskBack) { - glStencilMaskSeparate(GL_BACK, gpuPipelineState->dss.stencilWriteMaskBack); - cache->dss.stencilWriteMaskBack = gpuPipelineState->dss.stencilWriteMaskBack; - } + // bind depth-stencil state - back + if (cache->dss.stencilFuncBack != gpuPipelineState->dss.stencilFuncBack || + cache->dss.stencilRefBack != gpuPipelineState->dss.stencilRefBack || + cache->dss.stencilReadMaskBack != gpuPipelineState->dss.stencilReadMaskBack) { + glStencilFuncSeparate(GL_BACK, + GLES2_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncBack], + gpuPipelineState->dss.stencilRefBack, + gpuPipelineState->dss.stencilReadMaskBack); + cache->dss.stencilFuncBack = gpuPipelineState->dss.stencilFuncBack; + cache->dss.stencilRefBack = gpuPipelineState->dss.stencilRefBack; + cache->dss.stencilReadMaskBack = gpuPipelineState->dss.stencilReadMaskBack; + } + if (cache->dss.stencilFailOpBack != gpuPipelineState->dss.stencilFailOpBack || + cache->dss.stencilZFailOpBack != gpuPipelineState->dss.stencilZFailOpBack || + cache->dss.stencilPassOpBack != gpuPipelineState->dss.stencilPassOpBack) { + glStencilOpSeparate(GL_BACK, + GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpBack], + GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpBack], + GLES2_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpBack]); + cache->dss.stencilFailOpBack = gpuPipelineState->dss.stencilFailOpBack; + cache->dss.stencilZFailOpBack = gpuPipelineState->dss.stencilZFailOpBack; + cache->dss.stencilPassOpBack = gpuPipelineState->dss.stencilPassOpBack; + } + if (cache->dss.stencilWriteMaskBack != gpuPipelineState->dss.stencilWriteMaskBack) { + glStencilMaskSeparate(GL_BACK, gpuPipelineState->dss.stencilWriteMaskBack); + cache->dss.stencilWriteMaskBack = gpuPipelineState->dss.stencilWriteMaskBack; + } - // bind blend state - if (cache->bs.isA2C != gpuPipelineState->bs.isA2C) { - if (cache->bs.isA2C) { - glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); - } else { - glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + // bind blend state + if (cache->bs.isA2C != gpuPipelineState->bs.isA2C) { + if (cache->bs.isA2C) { + glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } else { + glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } + cache->bs.isA2C = gpuPipelineState->bs.isA2C; + } + if (cache->bs.blendColor.r != gpuPipelineState->bs.blendColor.r || + cache->bs.blendColor.g != gpuPipelineState->bs.blendColor.g || + cache->bs.blendColor.b != gpuPipelineState->bs.blendColor.b || + cache->bs.blendColor.a != gpuPipelineState->bs.blendColor.a) { + + glBlendColor(gpuPipelineState->bs.blendColor.r, + gpuPipelineState->bs.blendColor.g, + gpuPipelineState->bs.blendColor.b, + gpuPipelineState->bs.blendColor.a); + cache->bs.blendColor = gpuPipelineState->bs.blendColor; } - cache->bs.isA2C = gpuPipelineState->bs.isA2C; - } - if (cache->bs.blendColor.r != gpuPipelineState->bs.blendColor.r || - cache->bs.blendColor.g != gpuPipelineState->bs.blendColor.g || - cache->bs.blendColor.b != gpuPipelineState->bs.blendColor.b || - cache->bs.blendColor.a != gpuPipelineState->bs.blendColor.a) { - - glBlendColor(gpuPipelineState->bs.blendColor.r, - gpuPipelineState->bs.blendColor.g, - gpuPipelineState->bs.blendColor.b, - gpuPipelineState->bs.blendColor.a); - cache->bs.blendColor = gpuPipelineState->bs.blendColor; - } - BlendTarget &cache_target = cache->bs.targets[0]; - const BlendTarget &target = gpuPipelineState->bs.targets[0]; - if (cache_target.blend != target.blend) { - if (!cache_target.blend) { - glEnable(GL_BLEND); - } else { - glDisable(GL_BLEND); + BlendTarget &cacheTarget = cache->bs.targets[0]; + const BlendTarget &target = gpuPipelineState->bs.targets[0]; + if (cacheTarget.blend != target.blend) { + if (!cacheTarget.blend) { + glEnable(GL_BLEND); + } else { + glDisable(GL_BLEND); + } + cacheTarget.blend = target.blend; } - cache_target.blend = target.blend; - } - if (cache_target.blendEq != target.blendEq || - cache_target.blendAlphaEq != target.blendAlphaEq) { - glBlendEquationSeparate(GLES2_BLEND_OPS[(int)target.blendEq], - GLES2_BLEND_OPS[(int)target.blendAlphaEq]); - cache_target.blendEq = target.blendEq; - cache_target.blendAlphaEq = target.blendAlphaEq; - } - if (cache_target.blendSrc != target.blendSrc || - cache_target.blendDst != target.blendDst || - cache_target.blendSrcAlpha != target.blendSrcAlpha || - cache_target.blendDstAlpha != target.blendDstAlpha) { - glBlendFuncSeparate(GLES2_BLEND_FACTORS[(int)target.blendSrc], - GLES2_BLEND_FACTORS[(int)target.blendDst], - GLES2_BLEND_FACTORS[(int)target.blendSrcAlpha], - GLES2_BLEND_FACTORS[(int)target.blendDstAlpha]); - cache_target.blendSrc = target.blendSrc; - cache_target.blendDst = target.blendDst; - cache_target.blendSrcAlpha = target.blendSrcAlpha; - cache_target.blendDstAlpha = target.blendDstAlpha; - } - if (cache_target.blendColorMask != target.blendColorMask) { - glColorMask((GLboolean)(target.blendColorMask & ColorMask::R), - (GLboolean)(target.blendColorMask & ColorMask::G), - (GLboolean)(target.blendColorMask & ColorMask::B), - (GLboolean)(target.blendColorMask & ColorMask::A)); - cache_target.blendColorMask = target.blendColorMask; - } + if (cacheTarget.blendEq != target.blendEq || + cacheTarget.blendAlphaEq != target.blendAlphaEq) { + glBlendEquationSeparate(GLES2_BLEND_OPS[(int)target.blendEq], + GLES2_BLEND_OPS[(int)target.blendAlphaEq]); + cacheTarget.blendEq = target.blendEq; + cacheTarget.blendAlphaEq = target.blendAlphaEq; + } + if (cacheTarget.blendSrc != target.blendSrc || + cacheTarget.blendDst != target.blendDst || + cacheTarget.blendSrcAlpha != target.blendSrcAlpha || + cacheTarget.blendDstAlpha != target.blendDstAlpha) { + glBlendFuncSeparate(GLES2_BLEND_FACTORS[(int)target.blendSrc], + GLES2_BLEND_FACTORS[(int)target.blendDst], + GLES2_BLEND_FACTORS[(int)target.blendSrcAlpha], + GLES2_BLEND_FACTORS[(int)target.blendDstAlpha]); + cacheTarget.blendSrc = target.blendSrc; + cacheTarget.blendDst = target.blendDst; + cacheTarget.blendSrcAlpha = target.blendSrcAlpha; + cacheTarget.blendDstAlpha = target.blendDstAlpha; + } + if (cacheTarget.blendColorMask != target.blendColorMask) { + glColorMask((GLboolean)(target.blendColorMask & ColorMask::R), + (GLboolean)(target.blendColorMask & ColorMask::G), + (GLboolean)(target.blendColorMask & ColorMask::B), + (GLboolean)(target.blendColorMask & ColorMask::A)); + cacheTarget.blendColorMask = target.blendColorMask; + } + } // if - // bind shader resources - if (cmd->gpuBindingLayout && gpuPipelineState->gpuShader) { - uint8_t *uniform_buff; - - for (size_t j = 0; j < cmd->gpuBindingLayout->gpuBindings.size(); ++j) { - const GLES2GPUBinding &gpuBinding = cmd->gpuBindingLayout->gpuBindings[j]; - switch (gpuBinding.type) { - case BindingType::UNIFORM_BUFFER: { - if (gpuBinding.gpuBuffer) { - for (size_t k = 0; k < gpuPipelineState->gpuShader->glBlocks.size(); ++k) { - const GLES2GPUUniformBlock &gpuBlock = gpuPipelineState->gpuShader->glBlocks[k]; - - if (gpuBinding.binding == gpuBlock.binding && - gpuBinding.gpuBuffer && - gpuBinding.gpuBuffer->buffer) { - for (size_t u = 0; u < gpuBlock.glActiveUniforms.size(); ++u) { - const GLES2GPUUniform &gpuUniform = gpuBlock.glActiveUniforms[u]; - uniform_buff = (gpuBinding.gpuBuffer->buffer + gpuUniform.offset); - switch (gpuUniform.glType) { - case GL_BOOL: - case GL_INT: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform1iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_BOOL_VEC2: - case GL_INT_VEC2: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform2iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_BOOL_VEC3: - case GL_INT_VEC3: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform3iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_BOOL_VEC4: - case GL_INT_VEC4: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform4iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_FLOAT: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform1fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_FLOAT_VEC2: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform2fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_FLOAT_VEC3: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform3fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_FLOAT_VEC4: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniform4fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_FLOAT_MAT2: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniformMatrix2fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, (const GLfloat *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_FLOAT_MAT3: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniformMatrix3fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, (const GLfloat *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - case GL_FLOAT_MAT4: { - if (memcmp(gpuUniform.buff, uniform_buff, gpuUniform.size) != 0) { - glUniformMatrix4fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, (const GLfloat *)uniform_buff); - memcpy(gpuUniform.buff, uniform_buff, gpuUniform.size); - } - break; - } - default: - break; - } - } // for - break; - } + // bind descriptor sets + if (cmd->gpuPipelineState && gpuPipelineState->gpuShader && gpuPipelineState->gpuPipelineLayout) { + + size_t blockLen = gpuPipelineState->gpuShader->glBlocks.size(); + const vector> &dynamicOffsetIndices = cmd->gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices; + uint8_t *uniformBuffBase, *uniformBuff; + + for (size_t j = 0; j < blockLen; j++) { + const GLES2GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j]; + + CCASSERT(cmd->gpuDescriptorSets.size() > glBlock.set, "Invalid set index"); + const GLES2GPUDescriptorSet *gpuDescriptorSet = cmd->gpuDescriptorSets[glBlock.set]; + const GLES2GPUDescriptor &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[glBlock.binding]; + + if (!gpuDescriptor.gpuBuffer && !gpuDescriptor.gpuBufferView) { + CC_LOG_ERROR("Buffer binding '%s' at set %d binding %d is not bounded", + glBlock.name.c_str(), glBlock.set, glBlock.binding); + continue; + } + + uint offset = 0u; + const vector &dynamicOffsetIndexSet = dynamicOffsetIndices[glBlock.set]; + if (dynamicOffsetIndexSet.size() > glBlock.binding) { + int dynamicOffsetIndex = dynamicOffsetIndexSet[glBlock.binding]; + if (dynamicOffsetIndex >= 0) offset = cmd->dynamicOffsets[dynamicOffsetIndex]; + } + + if (gpuDescriptor.gpuBufferView) { + uniformBuffBase = gpuDescriptor.gpuBufferView->gpuBuffer->buffer + + gpuDescriptor.gpuBufferView->offset + offset; + } else if (gpuDescriptor.gpuBuffer) { + uniformBuffBase = gpuDescriptor.gpuBuffer->buffer + offset; + } else { + continue; + } + + for (size_t u = 0; u < glBlock.glActiveUniforms.size(); ++u) { + const GLES2GPUUniform &gpuUniform = glBlock.glActiveUniforms[u]; + uniformBuff = uniformBuffBase + gpuUniform.offset; + switch (gpuUniform.glType) { + case GL_BOOL: + case GL_INT: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform1iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_BOOL_VEC2: + case GL_INT_VEC2: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform2iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); } + break; } - break; - } - case BindingType::SAMPLER: { - if (gpuBinding.gpuSampler) { - for (size_t k = 0; k < gpuPipelineState->gpuShader->glSamplers.size(); ++k) { - const GLES2GPUUniformSampler &gpuSampler = gpuPipelineState->gpuShader->glSamplers[k]; - if (gpuSampler.binding == gpuBinding.binding) { - for (size_t u = 0; u < gpuSampler.units.size(); ++u) { - uint unit = (uint)gpuSampler.units[u]; - if (gpuBinding.gpuTexture && (gpuBinding.gpuTexture->size > 0)) { - GLES2GPUTexture *gpuTexture = gpuBinding.gpuTexture; - GLuint glTexture = gpuTexture->glTexture; - if (cache->glTextures[unit] != glTexture) { - if (cache->texUint != unit) { - glActiveTexture(GL_TEXTURE0 + unit); - cache->texUint = unit; - } - glBindTexture(gpuTexture->glTarget, glTexture); - cache->glTextures[unit] = glTexture; - } - - if (gpuBinding.gpuTexture->isPowerOf2) { - glWrapS = gpuBinding.gpuSampler->glWrapS; - glWrapT = gpuBinding.gpuSampler->glWrapT; - - if (gpuBinding.gpuTexture->mipLevel <= 1 && - !(gpuBinding.gpuTexture->flags & TextureFlagBit::GEN_MIPMAP) && - (gpuBinding.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_NEAREST || - gpuBinding.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_LINEAR)) { - glMinFilter = GL_LINEAR; - } else { - glMinFilter = gpuBinding.gpuSampler->glMinFilter; - } - } else { - glWrapS = GL_CLAMP_TO_EDGE; - glWrapT = GL_CLAMP_TO_EDGE; - - if (gpuBinding.gpuSampler->glMinFilter == GL_LINEAR || - gpuBinding.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_NEAREST || - gpuBinding.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_LINEAR) { - glMinFilter = GL_LINEAR; - } else { - glMinFilter = GL_NEAREST; - } - } - - if (gpuTexture->glWrapS != glWrapS) { - if (cache->texUint != unit) { - glActiveTexture(GL_TEXTURE0 + unit); - cache->texUint = unit; - } - glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_WRAP_S, glWrapS); - gpuTexture->glWrapS = glWrapS; - } - - if (gpuTexture->glWrapT != glWrapT) { - if (cache->texUint != unit) { - glActiveTexture(GL_TEXTURE0 + unit); - cache->texUint = unit; - } - glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_WRAP_T, glWrapT); - gpuTexture->glWrapT = glWrapT; - } - - if (gpuTexture->glMinFilter != glMinFilter) { - if (cache->texUint != unit) { - glActiveTexture(GL_TEXTURE0 + unit); - cache->texUint = unit; - } - glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_MIN_FILTER, glMinFilter); - gpuTexture->glMinFilter = glMinFilter; - } - - if (gpuTexture->glMagFilter != gpuBinding.gpuSampler->glMagFilter) { - if (cache->texUint != unit) { - glActiveTexture(GL_TEXTURE0 + unit); - cache->texUint = unit; - } - glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_MAG_FILTER, gpuBinding.gpuSampler->glMagFilter); - gpuTexture->glMagFilter = gpuBinding.gpuSampler->glMagFilter; - } - } - } - break; - } + case GL_BOOL_VEC3: + case GL_INT_VEC3: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform3iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); } + break; } - break; + case GL_BOOL_VEC4: + case GL_INT_VEC4: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform4iv(gpuUniform.glLoc, gpuUniform.count, (const GLint *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_FLOAT: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform1fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_FLOAT_VEC2: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform2fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_FLOAT_VEC3: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform3fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_FLOAT_VEC4: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniform4fv(gpuUniform.glLoc, gpuUniform.count, (const GLfloat *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_FLOAT_MAT2: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniformMatrix2fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, (const GLfloat *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_FLOAT_MAT3: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniformMatrix3fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, (const GLfloat *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + case GL_FLOAT_MAT4: { + if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + glUniformMatrix4fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, (const GLfloat *)uniformBuff); + memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + } + break; + } + default: + break; + } + } + } + + size_t samplerLen = gpuPipelineState->gpuShader->glSamplers.size(); + for (size_t j = 0; j < samplerLen; j++) { + const GLES2GPUUniformSampler &glSampler = gpuPipelineState->gpuShader->glSamplers[j]; + + CCASSERT(cmd->gpuDescriptorSets.size() > glSampler.set, "Invalid set index"); + const GLES2GPUDescriptorSet *gpuDescriptorSet = cmd->gpuDescriptorSets[glSampler.set]; + const GLES2GPUDescriptor &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[glSampler.binding]; + + if (!gpuDescriptor.gpuTexture || !gpuDescriptor.gpuSampler) { + CC_LOG_ERROR("Sampler binding '%s' at set %d binding %d is not bounded", + glSampler.name.c_str(), glSampler.set, glSampler.binding); + } + + for (size_t u = 0; u < glSampler.units.size(); ++u) { + uint unit = (uint)glSampler.units[u]; + GLES2GPUTexture *gpuTexture = gpuDescriptor.gpuTexture; + GLuint glTexture = gpuTexture->glTexture; + if (cache->glTextures[unit] != glTexture) { + if (cache->texUint != unit) { + glActiveTexture(GL_TEXTURE0 + unit); + cache->texUint = unit; + } + glBindTexture(gpuTexture->glTarget, glTexture); + cache->glTextures[unit] = glTexture; + } + + if (gpuDescriptor.gpuTexture->isPowerOf2) { + glWrapS = gpuDescriptor.gpuSampler->glWrapS; + glWrapT = gpuDescriptor.gpuSampler->glWrapT; + + if (gpuDescriptor.gpuTexture->mipLevel <= 1 && + !(gpuDescriptor.gpuTexture->flags & TextureFlagBit::GEN_MIPMAP) && + (gpuDescriptor.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_NEAREST || + gpuDescriptor.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_LINEAR)) { + glMinFilter = GL_LINEAR; + } else { + glMinFilter = gpuDescriptor.gpuSampler->glMinFilter; + } + } else { + glWrapS = GL_CLAMP_TO_EDGE; + glWrapT = GL_CLAMP_TO_EDGE; + + if (gpuDescriptor.gpuSampler->glMinFilter == GL_LINEAR || + gpuDescriptor.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_NEAREST || + gpuDescriptor.gpuSampler->glMinFilter == GL_LINEAR_MIPMAP_LINEAR) { + glMinFilter = GL_LINEAR; + } else { + glMinFilter = GL_NEAREST; + } + } + + if (gpuTexture->glWrapS != glWrapS) { + if (cache->texUint != unit) { + glActiveTexture(GL_TEXTURE0 + unit); + cache->texUint = unit; + } + glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_WRAP_S, glWrapS); + gpuTexture->glWrapS = glWrapS; + } + + if (gpuTexture->glWrapT != glWrapT) { + if (cache->texUint != unit) { + glActiveTexture(GL_TEXTURE0 + unit); + cache->texUint = unit; + } + glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_WRAP_T, glWrapT); + gpuTexture->glWrapT = glWrapT; + } + + if (gpuTexture->glMinFilter != glMinFilter) { + if (cache->texUint != unit) { + glActiveTexture(GL_TEXTURE0 + unit); + cache->texUint = unit; + } + glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_MIN_FILTER, glMinFilter); + gpuTexture->glMinFilter = glMinFilter; + } + + if (gpuTexture->glMagFilter != gpuDescriptor.gpuSampler->glMagFilter) { + if (cache->texUint != unit) { + glActiveTexture(GL_TEXTURE0 + unit); + cache->texUint = unit; + } + glTexParameteri(gpuTexture->glTarget, GL_TEXTURE_MAG_FILTER, gpuDescriptor.gpuSampler->glMagFilter); + gpuTexture->glMagFilter = gpuDescriptor.gpuSampler->glMagFilter; } - default: - break; } } } // if @@ -1845,11 +1879,11 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { for (uint c = 0; c < gpuAttribute.componentCount; ++c) { GLint glLoc = gpuInput.glLoc + c; - uint attrib_offset = gpuAttribute.offset + gpuAttribute.size * c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; glEnableVertexAttribArray(glLoc); cache->glEnabledAttribLocs[glLoc] = true; - glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attrib_offset)); + glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset)); if (device->useInstancedArrays()) { glVertexAttribDivisorEXT(glLoc, gpuAttribute.isInstanced ? 1 : 0); @@ -1893,11 +1927,11 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { for (uint c = 0; c < gpuAttribute.componentCount; ++c) { GLint glLoc = gpuInput.glLoc + c; - uint attrib_offset = gpuAttribute.offset + gpuAttribute.size * c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; glEnableVertexAttribArray(glLoc); cache->glEnabledAttribLocs[glLoc] = true; cache->glCurrentAttribLocs[glLoc] = true; - glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attrib_offset)); + glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset)); if (device->useInstancedArrays()) { glVertexAttribDivisorEXT(glLoc, gpuAttribute.isInstanced ? 1 : 0); @@ -1976,23 +2010,23 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { case DynamicStateFlagBit::STENCIL_WRITE_MASK: switch (cmd->stencilWriteMask.face) { case StencilFace::FRONT: - if (cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.write_mask) { - glStencilMaskSeparate(GL_FRONT, cmd->stencilWriteMask.write_mask); - cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.write_mask; + if (cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.writeMask) { + glStencilMaskSeparate(GL_FRONT, cmd->stencilWriteMask.writeMask); + cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.writeMask; } break; case StencilFace::BACK: - if (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.write_mask) { - glStencilMaskSeparate(GL_BACK, cmd->stencilWriteMask.write_mask); - cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.write_mask; + if (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.writeMask) { + glStencilMaskSeparate(GL_BACK, cmd->stencilWriteMask.writeMask); + cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.writeMask; } break; case StencilFace::ALL: - if ((cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.write_mask) || - (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.write_mask)) { - glStencilMask(cmd->stencilWriteMask.write_mask); - cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.write_mask; - cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.write_mask; + if ((cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.writeMask) || + (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.writeMask)) { + glStencilMask(cmd->stencilWriteMask.writeMask); + cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.writeMask; + cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.writeMask; } break; } @@ -2046,10 +2080,10 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { CC_LOG_ERROR("Invalid dynamic states."); break; } // switch - } // for - } // if + } // for + } // if break; - } // case BIND_STATES + } // namespace gfx case GFXCmdType::DRAW: { GLES2CmdDraw *cmd = cmdPackage->drawCmds[cmdIdx]; if (gpuInputAssembler && gpuPipelineState) { @@ -2108,17 +2142,17 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } case GFXCmdType::COPY_BUFFER_TO_TEXTURE: { GLES2CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; - GLES2CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions); + GLES2CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); break; } default: break; - } + } // namespace cc cmdIdx++; } } -void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { +void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { GLuint &glTexture = device->stateCache->glTextures[device->stateCache->texUint]; if (glTexture != gpuTexture->glTexture) { glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture); @@ -2132,7 +2166,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList case GL_TEXTURE_2D: { uint w; uint h; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; h = region.texExtent.height; @@ -2163,7 +2197,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList case GL_TEXTURE_2D_ARRAY: { uint w; uint h; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; uint d = region.texSubres.layerCount; uint layerCount = d + region.texSubres.baseArrayLayer; @@ -2201,7 +2235,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList uint w; uint h; uint d; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; h = region.texExtent.height; @@ -2236,10 +2270,10 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList uint w; uint h; uint f; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; - uint face_count = region.texSubres.baseArrayLayer + region.texSubres.layerCount; - for (f = region.texSubres.baseArrayLayer; f < face_count; ++f) { + uint faceCount = region.texSubres.baseArrayLayer + region.texSubres.layerCount; + for (f = region.texSubres.baseArrayLayer; f < faceCount; ++f) { w = region.texExtent.width; h = region.texExtent.height; const uint8_t *buff = buffers[n++]; diff --git a/cocos/renderer/gfx-gles2/GLES2Commands.h b/cocos/renderer/gfx-gles2/GLES2Commands.h index 687ce517e58..91138084b8e 100644 --- a/cocos/renderer/gfx-gles2/GLES2Commands.h +++ b/cocos/renderer/gfx-gles2/GLES2Commands.h @@ -21,7 +21,7 @@ struct GLES2DepthBounds { struct GLES2StencilWriteMask { StencilFace face = StencilFace::FRONT; - uint write_mask = 0; + uint writeMask = 0; }; struct GLES2StencilCompareMask { @@ -79,8 +79,9 @@ enum class GLES2State : uint8_t { class GLES2CmdBindStates : public GFXCmd { public: GLES2GPUPipelineState *gpuPipelineState = nullptr; - GLES2GPUBindingLayout *gpuBindingLayout = nullptr; GLES2GPUInputAssembler *gpuInputAssembler = nullptr; + vector gpuDescriptorSets; + vector dynamicOffsets; uint8_t stateFlags[(int)GLES2State::COUNT] = {0}; Viewport viewport; Rect scissor; @@ -96,8 +97,9 @@ class GLES2CmdBindStates : public GFXCmd { virtual void clear() override { gpuPipelineState = nullptr; - gpuBindingLayout = nullptr; gpuInputAssembler = nullptr; + gpuDescriptorSets.clear(); + dynamicOffsets.clear(); memset(stateFlags, 0, sizeof(stateFlags)); } }; @@ -128,15 +130,17 @@ class GLES2CmdUpdateBuffer : public GFXCmd { class GLES2CmdCopyBufferToTexture : public GFXCmd { public: GLES2GPUTexture *gpuTexture = nullptr; - BufferDataList buffers; - BufferTextureCopyList regions; + const uint8_t *const *buffers = nullptr; + const BufferTextureCopy *regions = nullptr; + uint count = 0u; GLES2CmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {} virtual void clear() override { gpuTexture = nullptr; - buffers.clear(); - regions.clear(); + buffers = nullptr; + regions = nullptr; + count = 0u; } }; @@ -166,7 +170,7 @@ CC_GLES2_API void GLES2CmdFuncDestroyInputAssembler(GLES2Device *device, GLES2GP CC_GLES2_API void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); CC_GLES2_API void GLES2CmdFuncDestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); CC_GLES2_API void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmd_package); -CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions); +CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count); } // namespace gfx } // namespace cc diff --git a/cocos/renderer/gfx-gles2/GLES2Context.cc b/cocos/renderer/gfx-gles2/GLES2Context.cc index cd7cc6b7020..0530c09eace 100644 --- a/cocos/renderer/gfx-gles2/GLES2Context.cc +++ b/cocos/renderer/gfx-gles2/GLES2Context.cc @@ -21,39 +21,39 @@ void APIENTRY GLES2EGLDebugProc(GLenum source, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { - String source_desc; + String sourceDesc; switch (source) { - case GL_DEBUG_SOURCE_API_KHR: source_desc = "API"; break; - case GL_DEBUG_SOURCE_SHADER_COMPILER_KHR: source_desc = "SHADER_COMPILER"; break; - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR: source_desc = "WINDOW_SYSTEM"; break; - case GL_DEBUG_SOURCE_THIRD_PARTY_KHR: source_desc = "THIRD_PARTY"; break; - case GL_DEBUG_SOURCE_APPLICATION_KHR: source_desc = "APPLICATION"; break; - default: source_desc = "OTHER"; break; + case GL_DEBUG_SOURCE_API_KHR: sourceDesc = "API"; break; + case GL_DEBUG_SOURCE_SHADER_COMPILER_KHR: sourceDesc = "SHADER_COMPILER"; break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR: sourceDesc = "WINDOW_SYSTEM"; break; + case GL_DEBUG_SOURCE_THIRD_PARTY_KHR: sourceDesc = "THIRD_PARTY"; break; + case GL_DEBUG_SOURCE_APPLICATION_KHR: sourceDesc = "APPLICATION"; break; + default: sourceDesc = "OTHER"; break; } - String type_desc; + String typeDesc; switch (severity) { - case GL_DEBUG_TYPE_ERROR_KHR: type_desc = "ERROR"; break; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR: type_desc = "PEPRECATED_BEHAVIOR"; break; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR: type_desc = "UNDEFINED_BEHAVIOR"; break; - case GL_DEBUG_TYPE_PERFORMANCE_KHR: type_desc = "PERFORMANCE"; break; - case GL_DEBUG_TYPE_PORTABILITY_KHR: type_desc = "PORTABILITY"; break; - case GL_DEBUG_TYPE_MARKER_KHR: type_desc = "MARKER"; break; - case GL_DEBUG_TYPE_PUSH_GROUP_KHR: type_desc = "PUSH_GROUP"; break; - case GL_DEBUG_TYPE_POP_GROUP_KHR: type_desc = "POP_GROUP"; break; - default: type_desc = "OTHER"; break; + case GL_DEBUG_TYPE_ERROR_KHR: typeDesc = "ERROR"; break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR: typeDesc = "PEPRECATED_BEHAVIOR"; break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR: typeDesc = "UNDEFINED_BEHAVIOR"; break; + case GL_DEBUG_TYPE_PERFORMANCE_KHR: typeDesc = "PERFORMANCE"; break; + case GL_DEBUG_TYPE_PORTABILITY_KHR: typeDesc = "PORTABILITY"; break; + case GL_DEBUG_TYPE_MARKER_KHR: typeDesc = "MARKER"; break; + case GL_DEBUG_TYPE_PUSH_GROUP_KHR: typeDesc = "PUSH_GROUP"; break; + case GL_DEBUG_TYPE_POP_GROUP_KHR: typeDesc = "POP_GROUP"; break; + default: typeDesc = "OTHER"; break; } - String severity_desc; + String severityDesc; switch (severity) { - case GL_DEBUG_SEVERITY_HIGH_KHR: severity_desc = "HIGH"; break; - case GL_DEBUG_SEVERITY_MEDIUM_KHR: severity_desc = "MEDIUM"; break; - case GL_DEBUG_SEVERITY_LOW_KHR: severity_desc = "LOW"; break; - default: severity_desc = "NOTIFICATION"; break; + case GL_DEBUG_SEVERITY_HIGH_KHR: severityDesc = "HIGH"; break; + case GL_DEBUG_SEVERITY_MEDIUM_KHR: severityDesc = "MEDIUM"; break; + case GL_DEBUG_SEVERITY_LOW_KHR: severityDesc = "LOW"; break; + default: severityDesc = "NOTIFICATION"; break; } String msg = StringUtil::Format("source: %s, type: %s, severity: %s, message: %s", - source_desc.c_str(), type_desc.c_str(), severity_desc.c_str(), + sourceDesc.c_str(), typeDesc.c_str(), severityDesc.c_str(), message); if (severity == GL_DEBUG_SEVERITY_HIGH_KHR) { @@ -148,9 +148,9 @@ bool GLES2Context::initialize(const ContextInfo &info) { // advanced applications choose to do. For this application however, taking the first EGLConfig that the function returns suits // its needs perfectly, so we limit it to returning a single EGLConfig. - EGLint num_configs; - if (eglChooseConfig(_eglDisplay, attribs, &_eglConfig, 1, &num_configs) == EGL_FALSE || - num_configs <= 0) { + EGLint numConfigs; + if (eglChooseConfig(_eglDisplay, attribs, &_eglConfig, 1, &numConfigs) == EGL_FALSE || + numConfigs <= 0) { CC_LOG_ERROR("Choosing configuration failed."); return false; } @@ -188,15 +188,15 @@ bool GLES2Context::initialize(const ContextInfo &info) { */ #if (CC_PLATFORM == CC_PLATFORM_ANDROID) - EGLint n_fmt; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &n_fmt) == EGL_FALSE) { + EGLint nFmt; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { CC_LOG_ERROR("Getting configuration attributes failed."); return false; } uint width = _device->getWidth(); uint height = _device->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, n_fmt); + ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); #endif _eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL); @@ -205,35 +205,35 @@ bool GLES2Context::initialize(const ContextInfo &info) { return false; } - //String egl_vendor = eglQueryString(_eglDisplay, EGL_VENDOR); - //String egl_version = eglQueryString(_eglDisplay, EGL_VERSION); + //String eglVendor = eglQueryString(_eglDisplay, EGL_VENDOR); + //String eglVersion = eglQueryString(_eglDisplay, EGL_VERSION); _extensions = StringUtil::Split((const char *)eglQueryString(_eglDisplay, EGL_EXTENSIONS), " "); _majorVersion = 2; _minorVersion = 0; - EGLint ctx_attribs[32]; + EGLint ctxAttribs[32]; uint n = 0; - bool has_khr_create_ctx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); - if (has_khr_create_ctx) { - ctx_attribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; - ctx_attribs[n++] = _majorVersion; - ctx_attribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; - ctx_attribs[n++] = _minorVersion; + bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); + if (hasKHRCreateCtx) { + ctxAttribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; + ctxAttribs[n++] = _majorVersion; + ctxAttribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; + ctxAttribs[n++] = _minorVersion; #ifdef CC_GFX_DEBUG - ctx_attribs[n++] = EGL_CONTEXT_FLAGS_KHR; - ctx_attribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; + ctxAttribs[n++] = EGL_CONTEXT_FLAGS_KHR; + ctxAttribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; #endif - ctx_attribs[n] = EGL_NONE; + ctxAttribs[n] = EGL_NONE; } else { - ctx_attribs[n++] = EGL_CONTEXT_CLIENT_VERSION; - ctx_attribs[n++] = _majorVersion; - ctx_attribs[n] = EGL_NONE; + ctxAttribs[n++] = EGL_CONTEXT_CLIENT_VERSION; + ctxAttribs[n++] = _majorVersion; + ctxAttribs[n] = EGL_NONE; } - _eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctx_attribs); + _eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctxAttribs); if (!_eglContext) { CC_LOG_ERROR("Create EGL context failed."); return false; @@ -252,7 +252,7 @@ bool GLES2Context::initialize(const ContextInfo &info) { _colorFmt = sharedCtx->getColorFormat(); _depthStencilFmt = sharedCtx->getDepthStencilFormat(); - EGLint pbuff_attribs[] = { + EGLint pbuffAttribs[] = { EGL_WIDTH, 2, EGL_HEIGHT, 2, EGL_LARGEST_PBUFFER, EGL_TRUE, @@ -260,40 +260,40 @@ bool GLES2Context::initialize(const ContextInfo &info) { EGL_TEXTURE_TARGET, EGL_NO_TEXTURE, EGL_NONE}; - _eglSurface = eglCreatePbufferSurface(_eglDisplay, _eglConfig, pbuff_attribs); + _eglSurface = eglCreatePbufferSurface(_eglDisplay, _eglConfig, pbuffAttribs); if (_eglSurface == EGL_NO_SURFACE) { CC_LOG_ERROR("eglCreatePbufferSurface - FAILED"); return false; } - bool has_khr_create_ctx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); - if (!has_khr_create_ctx) { + bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); + if (!hasKHRCreateCtx) { CC_LOG_INFO( "EGL context creation: EGL_KHR_create_context not supported. Minor version will be discarded, and debug disabled."); _minorVersion = 0; } - EGLint ctx_attribs[32]; + EGLint ctxAttribs[32]; uint n = 0; - if (has_khr_create_ctx) { - ctx_attribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; - ctx_attribs[n++] = _majorVersion; - ctx_attribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; - ctx_attribs[n++] = _minorVersion; + if (hasKHRCreateCtx) { + ctxAttribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; + ctxAttribs[n++] = _majorVersion; + ctxAttribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; + ctxAttribs[n++] = _minorVersion; #ifdef CC_GFX_DEBUG - ctx_attribs[n++] = EGL_CONTEXT_FLAGS_KHR; - ctx_attribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; + ctxAttribs[n++] = EGL_CONTEXT_FLAGS_KHR; + ctxAttribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; #endif } else { - ctx_attribs[n++] = EGL_CONTEXT_CLIENT_VERSION; - ctx_attribs[n++] = _majorVersion; + ctxAttribs[n++] = EGL_CONTEXT_CLIENT_VERSION; + ctxAttribs[n++] = _majorVersion; } - ctx_attribs[n] = EGL_NONE; + ctxAttribs[n] = EGL_NONE; - _eglContext = eglCreateContext(_eglDisplay, _eglConfig, _eglSharedContext, ctx_attribs); + _eglContext = eglCreateContext(_eglDisplay, _eglConfig, _eglSharedContext, ctxAttribs); if (!_eglContext) { CC_LOG_ERROR("Create EGL context with share context [0x%p] failed.", _eglSharedContext); return false; @@ -315,14 +315,14 @@ bool GLES2Context::initialize(const ContextInfo &info) { EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [=](const CustomEvent &event) -> void { _windowHandle = (uintptr_t)event.args->ptrVal; - EGLint n_fmt; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &n_fmt) == EGL_FALSE) { + EGLint nFmt; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { CC_LOG_ERROR("Getting configuration attributes failed."); return; } uint width = _device->getWidth(); uint height = _device->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, n_fmt); + ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); _eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL); if (_eglSurface == EGL_NO_SURFACE) { diff --git a/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cc b/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cc new file mode 100644 index 00000000000..d5eba117620 --- /dev/null +++ b/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cc @@ -0,0 +1,83 @@ +#include "GLES2Std.h" + +#include "GLES2Buffer.h" +#include "GLES2Commands.h" +#include "GLES2DescriptorSet.h" +#include "GLES2Sampler.h" +#include "GLES2Texture.h" + +namespace cc { +namespace gfx { + +GLES2DescriptorSet::GLES2DescriptorSet(Device *device) +: DescriptorSet(device) { +} + +GLES2DescriptorSet::~GLES2DescriptorSet() { +} + +bool GLES2DescriptorSet::initialize(const DescriptorSetInfo &info) { + + _layout = info.layout; + + const DescriptorSetLayoutBindingList &bindings = _layout->getBindings(); + const size_t descriptorCount = bindings.size(); + + _buffers.resize(descriptorCount); + _textures.resize(descriptorCount); + _samplers.resize(descriptorCount); + + _gpuDescriptorSet = CC_NEW(GLES2GPUDescriptorSet); + _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); + for (size_t i = 0u; i < descriptorCount; i++) { + _gpuDescriptorSet->gpuDescriptors[i].type = bindings[i].descriptorType; + } + + _status = Status::SUCCESS; + + return true; +} + +void GLES2DescriptorSet::destroy() { + _layout = nullptr; + + if (_gpuDescriptorSet) { + CC_DELETE(_gpuDescriptorSet); + _gpuDescriptorSet = nullptr; + } + + _status = Status::UNREADY; +} + +void GLES2DescriptorSet::update() { + if (_isDirty && _gpuDescriptorSet) { + uint bindingCount = _gpuDescriptorSet->gpuDescriptors.size(); + + for (size_t i = 0; i < bindingCount; i++) { + GLES2GPUDescriptor &binding = _gpuDescriptorSet->gpuDescriptors[i]; + + if ((uint)binding.type & DESCRIPTOR_BUFFER_TYPE) { + GLES2Buffer *buffer = (GLES2Buffer *)_buffers[i]; + if (buffer) { + if (buffer->gpuBuffer()) { + binding.gpuBuffer = buffer->gpuBuffer(); + } else if (buffer->gpuBufferView()) { + binding.gpuBufferView = buffer->gpuBufferView(); + } + } + } + else if ((uint)binding.type & DESCRIPTOR_SAMPLER_TYPE) { + if (_textures[i]) { + binding.gpuTexture = ((GLES2Texture *)_textures[i])->gpuTexture(); + } + if (_samplers[i]) { + binding.gpuSampler = ((GLES2Sampler *)_samplers[i])->gpuSampler(); + } + } + } + _isDirty = false; + } +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-gles2/GLES2DescriptorSet.h b/cocos/renderer/gfx-gles2/GLES2DescriptorSet.h new file mode 100644 index 00000000000..42b5d5adec1 --- /dev/null +++ b/cocos/renderer/gfx-gles2/GLES2DescriptorSet.h @@ -0,0 +1,28 @@ +#ifndef CC_GFXGLES2_GLES2_DESCRIPTOR_SET_H_ +#define CC_GFXGLES2_GLES2_DESCRIPTOR_SET_H_ + +namespace cc { +namespace gfx { + +class GLES2GPUDescriptorSet; + +class CC_GLES2_API GLES2DescriptorSet : public DescriptorSet { +public: + GLES2DescriptorSet(Device *device); + ~GLES2DescriptorSet(); + +public: + virtual bool initialize(const DescriptorSetInfo &info) override; + virtual void destroy() override; + virtual void update() override; + + CC_INLINE GLES2GPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } + +private: + GLES2GPUDescriptorSet *_gpuDescriptorSet = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXGLES2_GLES2_DESCRIPTOR_SET_H_ diff --git a/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cc b/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cc new file mode 100644 index 00000000000..64bc51cc900 --- /dev/null +++ b/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cc @@ -0,0 +1,47 @@ +#include "GLES2Std.h" + +#include "GLES2Commands.h" +#include "GLES2DescriptorSetLayout.h" + +namespace cc { +namespace gfx { + +GLES2DescriptorSetLayout::GLES2DescriptorSetLayout(Device *device) +: DescriptorSetLayout(device) { +} + +GLES2DescriptorSetLayout::~GLES2DescriptorSetLayout() { +} + +bool GLES2DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { + + _bindings = info.bindings; + + _gpuDescriptorSetLayout = CC_NEW(GLES2GPUDescriptorSetLayout); + + for (uint i = 0u; i < _bindings.size(); i++) { + const DescriptorSetLayoutBinding &binding = _bindings[i]; + if ((uint)binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { + for (uint j = 0u; j < binding.count; j++) { + _gpuDescriptorSetLayout->dynamicBindings.push_back(i); + } + } + _gpuDescriptorSetLayout->bindings.push_back(binding); + } + + _status = Status::SUCCESS; + + return true; +} + +void GLES2DescriptorSetLayout::destroy() { + if (_gpuDescriptorSetLayout) { + CC_DELETE(_gpuDescriptorSetLayout); + _gpuDescriptorSetLayout = nullptr; + } + + _status = Status::UNREADY; +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h b/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h new file mode 100644 index 00000000000..11056b39841 --- /dev/null +++ b/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h @@ -0,0 +1,27 @@ +#ifndef CC_GFXGLES2_GLES2_DESCRIPTOR_SET_LAYOUT_H_ +#define CC_GFXGLES2_GLES2_DESCRIPTOR_SET_LAYOUT_H_ + +namespace cc { +namespace gfx { + +class GLES2GPUDescriptorSetLayout; + +class CC_GLES2_API GLES2DescriptorSetLayout : public DescriptorSetLayout { +public: + GLES2DescriptorSetLayout(Device *device); + ~GLES2DescriptorSetLayout(); + +public: + virtual bool initialize(const DescriptorSetLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE GLES2GPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } + +private: + GLES2GPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXGLES2_GLES2_DESCRIPTOR_SET_LAYOUT_H_ diff --git a/cocos/renderer/gfx-gles2/GLES2Device.cc b/cocos/renderer/gfx-gles2/GLES2Device.cc index 9259c96ac45..16709c45054 100644 --- a/cocos/renderer/gfx-gles2/GLES2Device.cc +++ b/cocos/renderer/gfx-gles2/GLES2Device.cc @@ -1,14 +1,16 @@ #include "GLES2Std.h" -#include "GLES2BindingLayout.h" #include "GLES2Buffer.h" #include "GLES2CommandAllocator.h" #include "GLES2CommandBuffer.h" #include "GLES2Context.h" +#include "GLES2DescriptorSet.h" +#include "GLES2DescriptorSetLayout.h" #include "GLES2Device.h" #include "GLES2Fence.h" #include "GLES2Framebuffer.h" #include "GLES2InputAssembler.h" +#include "GLES2PipelineLayout.h" #include "GLES2PipelineState.h" #include "GLES2Queue.h" #include "GLES2RenderPass.h" @@ -35,6 +37,14 @@ bool GLES2Device::initialize(const DeviceInfo &info) { _nativeHeight = info.nativeHeight; _windowHandle = info.windowHandle; + _bindingMappingInfo = info.bindingMappingInfo; + if (!_bindingMappingInfo.bufferOffsets.size()) { + _bindingMappingInfo.bufferOffsets.push_back(0); + } + if (!_bindingMappingInfo.samplerOffsets.size()) { + _bindingMappingInfo.samplerOffsets.push_back(0); + } + _cmdAllocator = CC_NEW(GLES2CommandAllocator); stateCache = CC_NEW(GLES2StateCache); @@ -131,6 +141,7 @@ bool GLES2Device::initialize(const DeviceInfo &info) { glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint *)&_maxCubeMapTextureSize); glGetIntegerv(GL_DEPTH_BITS, (GLint *)&_depthBits); glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_stencilBits); + _uboOffsetAlignment = 1u; return true; } @@ -201,6 +212,15 @@ Buffer *GLES2Device::createBuffer(const BufferInfo &info) { return nullptr; } +Buffer *GLES2Device::createBuffer(const BufferViewInfo &info) { + Buffer *buffer = CC_NEW(GLES2Buffer(this)); + if (buffer->initialize(info)) + return buffer; + + CC_SAFE_DESTROY(buffer); + return nullptr; +} + Texture *GLES2Device::createTexture(const TextureInfo &info) { Texture *texture = CC_NEW(GLES2Texture(this)); if (texture->initialize(info)) @@ -264,12 +284,30 @@ Framebuffer *GLES2Device::createFramebuffer(const FramebufferInfo &info) { return nullptr; } -BindingLayout *GLES2Device::createBindingLayout(const BindingLayoutInfo &info) { - BindingLayout *bindingLayout = CC_NEW(GLES2BindingLayout(this)); - if (bindingLayout->initialize(info)) - return bindingLayout; +DescriptorSet *GLES2Device::createDescriptorSet(const DescriptorSetInfo &info) { + DescriptorSet *descriptorSet = CC_NEW(GLES2DescriptorSet(this)); + if (descriptorSet->initialize(info)) + return descriptorSet; + + CC_SAFE_DESTROY(descriptorSet); + return nullptr; +} + +DescriptorSetLayout *GLES2Device::createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) { + DescriptorSetLayout *descriptorSetLayout = CC_NEW(GLES2DescriptorSetLayout(this)); + if (descriptorSetLayout->initialize(info)) + return descriptorSetLayout; + + CC_SAFE_DESTROY(descriptorSetLayout); + return nullptr; +} + +PipelineLayout *GLES2Device::createPipelineLayout(const PipelineLayoutInfo &info) { + PipelineLayout *pipelineLayout = CC_NEW(GLES2PipelineLayout(this)); + if (pipelineLayout->initialize(info)) + return pipelineLayout; - CC_SAFE_DESTROY(bindingLayout); + CC_SAFE_DESTROY(pipelineLayout); return nullptr; } @@ -282,8 +320,8 @@ PipelineState *GLES2Device::createPipelineState(const PipelineStateInfo &info) { return nullptr; } -void GLES2Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - GLES2CmdFuncCopyBuffersToTexture(this, buffers, ((GLES2Texture *)dst)->gpuTexture(), regions); +void GLES2Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { + GLES2CmdFuncCopyBuffersToTexture(this, buffers, ((GLES2Texture *)dst)->gpuTexture(), regions, count); } } // namespace gfx diff --git a/cocos/renderer/gfx-gles2/GLES2Device.h b/cocos/renderer/gfx-gles2/GLES2Device.h index f37e7e96ad3..f89648aa5a9 100644 --- a/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/cocos/renderer/gfx-gles2/GLES2Device.h @@ -24,6 +24,7 @@ class CC_GLES2_API GLES2Device : public Device { virtual Fence *createFence(const FenceInfo &info) override; virtual Queue *createQueue(const QueueInfo &info) override; virtual Buffer *createBuffer(const BufferInfo &info) override; + virtual Buffer *createBuffer(const BufferViewInfo &info) override; virtual Texture *createTexture(const TextureInfo &info) override; virtual Texture *createTexture(const TextureViewInfo &info) override; virtual Sampler *createSampler(const SamplerInfo &info) override; @@ -31,15 +32,18 @@ class CC_GLES2_API GLES2Device : public Device { virtual InputAssembler *createInputAssembler(const InputAssemblerInfo &info) override; virtual RenderPass *createRenderPass(const RenderPassInfo &info) override; virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; - virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; + virtual DescriptorSet *createDescriptorSet(const DescriptorSetInfo &info) override; + virtual DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) override; + virtual PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; CC_INLINE bool useVAO() const { return _useVAO; } CC_INLINE bool useDrawInstanced() const { return _useDrawInstanced; } CC_INLINE bool useInstancedArrays() const { return _useInstancedArrays; } CC_INLINE bool useDiscardFramebuffer() const { return _useDiscardFramebuffer; } CC_INLINE GLES2CommandAllocator *cmdAllocator() const { return _cmdAllocator; } + CC_INLINE const BindingMappingInfo &bindingMappingInfo() const { return _bindingMappingInfo; } CC_INLINE bool checkExtension(const String &extension) const { for (size_t i = 0; i < _extensions.size(); ++i) { @@ -51,9 +55,10 @@ class CC_GLES2_API GLES2Device : public Device { } private: + BindingMappingInfo _bindingMappingInfo; GLES2CommandAllocator *_cmdAllocator = nullptr; - StringArray _extensions; + bool _useVAO = false; bool _useDrawInstanced = false; bool _useInstancedArrays = false; diff --git a/cocos/renderer/gfx-gles2/GLES2GPUObjects.h b/cocos/renderer/gfx-gles2/GLES2GPUObjects.h index 6ee2df71204..66d9ddd424e 100644 --- a/cocos/renderer/gfx-gles2/GLES2GPUObjects.h +++ b/cocos/renderer/gfx-gles2/GLES2GPUObjects.h @@ -20,6 +20,13 @@ class GLES2GPUBuffer : public Object { }; typedef vector GLES2GPUBufferList; +class GLES2GPUBufferView : public Object { +public: + GLES2GPUBuffer *gpuBuffer = nullptr; + uint offset = 0u; + uint range = 0u; +}; + class GLES2GPUTexture : public Object { public: TextureType type = TextureType::TEX2D; @@ -122,6 +129,7 @@ struct GLES2GPUUniform { typedef vector GLES2GPUUniformList; struct GLES2GPUUniformBlock { + uint set = 0; uint binding = 0; uint idx = 0; String name; @@ -132,6 +140,7 @@ struct GLES2GPUUniformBlock { typedef vector GLES2GPUUniformBlockList; struct GLES2GPUUniformSampler { + uint set = 0; uint binding = 0; String name; Type type = Type::UNKNOWN; @@ -142,11 +151,10 @@ struct GLES2GPUUniformSampler { typedef vector GLES2GPUUniformSamplerList; struct GLES2GPUShaderStage { - GLES2GPUShaderStage(ShaderType t, String s, ShaderMacroList m, GLuint shader = 0) - : type(t), source(s), macros(m), glShader(shader) {} - ShaderType type; + GLES2GPUShaderStage(ShaderStageFlagBit t, String s, GLuint shader = 0) + : type(t), source(s), glShader(shader) {} + ShaderStageFlagBit type; String source; - ShaderMacroList macros; GLuint glShader = 0; }; typedef vector GLES2GPUShaderStageList; @@ -203,8 +211,19 @@ class GLES2GPUFramebuffer : public Object { bool isOffscreen = false; }; +class GLES2GPUDescriptorSetLayout : public Object { +public: + DescriptorSetLayoutBindingList bindings; + vector dynamicBindings; +}; +typedef vector GLES2GPUDescriptorSetLayoutList; + class GLES2GPUPipelineLayout : public Object { public: + GLES2GPUDescriptorSetLayoutList setLayouts; + vector> dynamicOffsetIndices; + vector dynamicOffsetOffsets; + uint dynamicOffsetCount; }; class GLES2GPUPipelineState : public Object { @@ -217,21 +236,21 @@ class GLES2GPUPipelineState : public Object { DynamicStateList dynamicStates; GLES2GPUPipelineLayout *gpuLayout = nullptr; GLES2GPURenderPass *gpuRenderPass = nullptr; + GLES2GPUPipelineLayout *gpuPipelineLayout = nullptr; }; -struct GLES2GPUBinding { - uint binding = GFX_INVALID_BINDING; - BindingType type = BindingType::UNKNOWN; - String name; +struct GLES2GPUDescriptor { + DescriptorType type = DescriptorType::UNKNOWN; GLES2GPUBuffer *gpuBuffer = nullptr; + GLES2GPUBufferView *gpuBufferView = nullptr; GLES2GPUTexture *gpuTexture = nullptr; GLES2GPUSampler *gpuSampler = nullptr; }; -typedef vector GLES2GPUBindingList; +typedef vector GLES2GPUDescriptorList; -class GLES2GPUBindingLayout : public Object { +class GLES2GPUDescriptorSet : public Object { public: - GLES2GPUBindingList gpuBindings; + GLES2GPUDescriptorList gpuDescriptors; }; class GLES2GPUFence : public Object { diff --git a/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cc b/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cc new file mode 100644 index 00000000000..92cdf1ff738 --- /dev/null +++ b/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cc @@ -0,0 +1,61 @@ +#include "GLES2Std.h" + +#include "GLES2Commands.h" +#include "GLES2DescriptorSetLayout.h" +#include "GLES2PipelineLayout.h" + +namespace cc { +namespace gfx { + +GLES2PipelineLayout::GLES2PipelineLayout(Device *device) +: PipelineLayout(device) { +} + +GLES2PipelineLayout::~GLES2PipelineLayout() { +} + +bool GLES2PipelineLayout::initialize(const PipelineLayoutInfo &info) { + + _setLayouts = info.setLayouts; + + _gpuPipelineLayout = CC_NEW(GLES2GPUPipelineLayout); + + int offset = 0u; + _gpuPipelineLayout->dynamicOffsetIndices.resize(_setLayouts.size()); + for (uint i = 0u; i < _setLayouts.size(); i++) { + DescriptorSetLayout *setLayout = _setLayouts[i]; + GLES2GPUDescriptorSetLayout *gpuSetLayout = ((GLES2DescriptorSetLayout *)setLayout)->gpuDescriptorSetLayout(); + size_t bindingCount = gpuSetLayout->bindings.size(); + size_t dynamicCount = gpuSetLayout->dynamicBindings.size(); + + vector &indices = _gpuPipelineLayout->dynamicOffsetIndices[i]; + indices.assign(bindingCount, -1); + + for (uint j = 0u; j < dynamicCount; j++) { + uint binding = gpuSetLayout->dynamicBindings[j]; + if (indices[binding] < 0) indices[binding] = offset + j; + } + _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); + _gpuPipelineLayout->setLayouts.push_back(gpuSetLayout); + offset += dynamicCount; + } + _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); + _gpuPipelineLayout->dynamicOffsetCount = offset; + + _status = Status::SUCCESS; + + return true; +} + +void GLES2PipelineLayout::destroy() { + + if (_gpuPipelineLayout) { + CC_DELETE(_gpuPipelineLayout); + _gpuPipelineLayout = nullptr; + } + + _status = Status::UNREADY; +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-gles2/GLES2PipelineLayout.h b/cocos/renderer/gfx-gles2/GLES2PipelineLayout.h new file mode 100644 index 00000000000..c452d8efee8 --- /dev/null +++ b/cocos/renderer/gfx-gles2/GLES2PipelineLayout.h @@ -0,0 +1,27 @@ +#ifndef CC_GFXGLES2_GLES2_PIPELINE_LAYOUT_H_ +#define CC_GFXGLES2_GLES2_PIPELINE_LAYOUT_H_ + +namespace cc { +namespace gfx { + +class GLES2GPUPipelineLayout; + +class CC_GLES2_API GLES2PipelineLayout : public PipelineLayout { +public: + GLES2PipelineLayout(Device *device); + ~GLES2PipelineLayout(); + +public: + virtual bool initialize(const PipelineLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE GLES2GPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } + +private: + GLES2GPUPipelineLayout *_gpuPipelineLayout = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXGLES2_GLES2_PIPELINE_LAYOUT_H_ diff --git a/cocos/renderer/gfx-gles2/GLES2PipelineState.cc b/cocos/renderer/gfx-gles2/GLES2PipelineState.cc index 2c69e1bb45d..ff4772a6978 100644 --- a/cocos/renderer/gfx-gles2/GLES2PipelineState.cc +++ b/cocos/renderer/gfx-gles2/GLES2PipelineState.cc @@ -1,8 +1,10 @@ #include "GLES2Std.h" -#include "GLES2PipelineState.h" + #include "GLES2Commands.h" -#include "GLES2Shader.h" +#include "GLES2PipelineLayout.h" +#include "GLES2PipelineState.h" #include "GLES2RenderPass.h" +#include "GLES2Shader.h" namespace cc { namespace gfx { @@ -41,6 +43,7 @@ bool GLES2PipelineState::initialize(const PipelineStateInfo &info) { _blendState = info.blendState; _dynamicStates = info.dynamicStates; _renderPass = info.renderPass; + _pipelineLayout = info.pipelineLayout; _gpuPipelineState = CC_NEW(GLES2GPUPipelineState); _gpuPipelineState->glPrimitive = GLES2Primitives[(int)_primitive]; @@ -49,6 +52,7 @@ bool GLES2PipelineState::initialize(const PipelineStateInfo &info) { _gpuPipelineState->dss = _depthStencilState; _gpuPipelineState->bs = _blendState; _gpuPipelineState->gpuRenderPass = ((GLES2RenderPass *)_renderPass)->gpuRenderPass(); + _gpuPipelineState->gpuPipelineLayout = ((GLES2PipelineLayout *)_pipelineLayout)->gpuPipelineLayout(); for (uint i = 0; i < 31; i++) { if ((uint)_dynamicStates & (1 << i)) { diff --git a/cocos/renderer/gfx-gles2/GLES2Shader.cc b/cocos/renderer/gfx-gles2/GLES2Shader.cc index 0b2bd68b972..70ad0ec1b98 100644 --- a/cocos/renderer/gfx-gles2/GLES2Shader.cc +++ b/cocos/renderer/gfx-gles2/GLES2Shader.cc @@ -24,7 +24,7 @@ bool GLES2Shader::initialize(const ShaderInfo &info) { _gpuShader->blocks = _blocks; _gpuShader->samplers = _samplers; for (const auto &stage : _stages) { - GLES2GPUShaderStage gpuShaderStage = {stage.type, stage.source, stage.macros, 0}; + GLES2GPUShaderStage gpuShaderStage = {stage.stage, stage.source}; _gpuShader->gpuStages.emplace_back(std::move(gpuShaderStage)); } diff --git a/cocos/renderer/gfx-gles2/GLES2Texture.cc b/cocos/renderer/gfx-gles2/GLES2Texture.cc index 6f06da40b01..84520ba37d8 100644 --- a/cocos/renderer/gfx-gles2/GLES2Texture.cc +++ b/cocos/renderer/gfx-gles2/GLES2Texture.cc @@ -96,7 +96,7 @@ bool GLES2Texture::initialize(const TextureInfo &info) { } bool GLES2Texture::initialize(const TextureViewInfo &info) { - _Type = ObjectType::TEXTURE_VIEW; + _isTextureView = true; CC_LOG_ERROR("GLES2 doesn't support texture view"); _status = Status::FAILED; diff --git a/cocos/renderer/gfx-gles3/GLES3BindingLayout.cc b/cocos/renderer/gfx-gles3/GLES3BindingLayout.cc deleted file mode 100644 index 86979af1135..00000000000 --- a/cocos/renderer/gfx-gles3/GLES3BindingLayout.cc +++ /dev/null @@ -1,98 +0,0 @@ -#include "GLES3Std.h" -#include "GLES3BindingLayout.h" -#include "GLES3Commands.h" -#include "GLES3Buffer.h" -#include "GLES3Sampler.h" -#include "GLES3Texture.h" - -namespace cc { -namespace gfx { - -GLES3BindingLayout::GLES3BindingLayout(Device *device) -: BindingLayout(device) { -} - -GLES3BindingLayout::~GLES3BindingLayout() { -} - -bool GLES3BindingLayout::initialize(const BindingLayoutInfo &info) { - - const UniformBlockList &blocks = info.shader->getBlocks(); - const UniformSamplerList &samplers = info.shader->getSamplers(); - const uint bindingCount = blocks.size() + samplers.size(); - - if (bindingCount) { - _bindingUnits.resize(bindingCount); - for (size_t i = 0u; i < blocks.size(); ++i) { - const UniformBlock &binding = blocks[i]; - BindingUnit &bindingUnit = _bindingUnits[i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::UNIFORM_BUFFER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = 1; - } - for (size_t i = 0u; i < samplers.size(); ++i) { - const UniformSampler &binding = samplers[i]; - BindingUnit &bindingUnit = _bindingUnits[blocks.size() + i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::SAMPLER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = binding.count; - } - } - - _gpuBindingLayout = CC_NEW(GLES3GPUBindingLayout); - _gpuBindingLayout->gpuBindings.resize(_bindingUnits.size()); - for (size_t i = 0; i < _gpuBindingLayout->gpuBindings.size(); ++i) { - GLES3GPUBinding &gpuBinding = _gpuBindingLayout->gpuBindings[i]; - const BindingUnit &bindingUnit = _bindingUnits[i]; - gpuBinding.binding = bindingUnit.binding; - gpuBinding.type = bindingUnit.type; - gpuBinding.name = bindingUnit.name; - } - - _status = Status::SUCCESS; - - return true; -} - -void GLES3BindingLayout::destroy() { - if (_gpuBindingLayout) { - CC_DELETE(_gpuBindingLayout); - _gpuBindingLayout = nullptr; - } - - _status = Status::UNREADY; -} - -void GLES3BindingLayout::update() { - if (_isDirty && _gpuBindingLayout) { - for (size_t i = 0; i < _bindingUnits.size(); ++i) { - BindingUnit &bindingUnit = _bindingUnits[i]; - switch (bindingUnit.type) { - case BindingType::UNIFORM_BUFFER: { - if (bindingUnit.buffer) { - _gpuBindingLayout->gpuBindings[i].gpuBuffer = ((GLES3Buffer *)bindingUnit.buffer)->gpuBuffer(); - } - break; - } - case BindingType::SAMPLER: { - if (bindingUnit.texture) { - _gpuBindingLayout->gpuBindings[i].gpuTexture = ((GLES3Texture *)bindingUnit.texture)->gpuTexture(); - } - if (bindingUnit.sampler) { - _gpuBindingLayout->gpuBindings[i].gpuSampler = ((GLES3Sampler *)bindingUnit.sampler)->gpuSampler(); - } - break; - } - default:; - } - } - _isDirty = false; - } -} - -} // namespace gfx -} // namespace cc diff --git a/cocos/renderer/gfx-gles3/GLES3BindingLayout.h b/cocos/renderer/gfx-gles3/GLES3BindingLayout.h deleted file mode 100644 index a5f56c23511..00000000000 --- a/cocos/renderer/gfx-gles3/GLES3BindingLayout.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CC_GFXGLES3_GLES3_BINDING_LAYOUT_H_ -#define CC_GFXGLES3_GLES3_BINDING_LAYOUT_H_ - -namespace cc { -namespace gfx { - -class GLES3GPUBindingLayout; - -class CC_GLES3_API GLES3BindingLayout : public BindingLayout { -public: - GLES3BindingLayout(Device *device); - ~GLES3BindingLayout(); - -public: - virtual bool initialize(const BindingLayoutInfo &info) override; - virtual void destroy() override; - virtual void update() override; - - CC_INLINE GLES3GPUBindingLayout *gpuBindingLayout() const { return _gpuBindingLayout; } - -private: - GLES3GPUBindingLayout *_gpuBindingLayout = nullptr; -}; - -} // namespace gfx -} // namespace cc - -#endif diff --git a/cocos/renderer/gfx-gles3/GLES3Buffer.cc b/cocos/renderer/gfx-gles3/GLES3Buffer.cc index cd9ee7e618b..d2871641bbc 100644 --- a/cocos/renderer/gfx-gles3/GLES3Buffer.cc +++ b/cocos/renderer/gfx-gles3/GLES3Buffer.cc @@ -1,4 +1,5 @@ #include "GLES3Std.h" + #include "GLES3Buffer.h" #include "GLES3Commands.h" @@ -54,10 +55,39 @@ bool GLES3Buffer::initialize(const BufferInfo &info) { return true; } +bool GLES3Buffer::initialize(const BufferViewInfo &info) { + + _isBufferView = true; + + GLES3Buffer *buffer = (GLES3Buffer *)info.buffer; + + _usage = buffer->_usage; + _memUsage = buffer->_memUsage; + _size = _stride = info.range; + _count = 1u; + _flags = buffer->_flags; + + _gpuBuffer = CC_NEW(GLES3GPUBuffer); + _gpuBuffer->usage = _usage; + _gpuBuffer->memUsage = _memUsage; + _gpuBuffer->size = _size; + _gpuBuffer->stride = _stride; + _gpuBuffer->count = _count; + _gpuBuffer->glTarget = buffer->_gpuBuffer->glTarget; + _gpuBuffer->glBuffer = buffer->_gpuBuffer->glBuffer; + _gpuBuffer->glOffset = info.offset; + _gpuBuffer->buffer = buffer->_gpuBuffer->buffer; + _gpuBuffer->indirects = buffer->_gpuBuffer->indirects; + + return true; +} + void GLES3Buffer::destroy() { if (_gpuBuffer) { - GLES3CmdFuncDestroyBuffer((GLES3Device *)_device, _gpuBuffer); - _device->getMemoryStatus().bufferSize -= _size; + if (!_isBufferView) { + GLES3CmdFuncDestroyBuffer((GLES3Device *)_device, _gpuBuffer); + _device->getMemoryStatus().bufferSize -= _size; + } CC_DELETE(_gpuBuffer); _gpuBuffer = nullptr; } @@ -71,6 +101,8 @@ void GLES3Buffer::destroy() { } void GLES3Buffer::resize(uint size) { + CCASSERT(!_isBufferView, "Cannot resize buffer views"); + if (_size != size) { const uint oldSize = _size; _size = size; @@ -102,6 +134,8 @@ void GLES3Buffer::resize(uint size) { } void GLES3Buffer::update(void *buffer, uint offset, uint size) { + CCASSERT(!_isBufferView, "Cannot update through buffer views"); + if (_buffer) { memcpy(_buffer + offset, buffer, size); } diff --git a/cocos/renderer/gfx-gles3/GLES3Buffer.h b/cocos/renderer/gfx-gles3/GLES3Buffer.h index 53adb9f9798..6d474dff4d4 100644 --- a/cocos/renderer/gfx-gles3/GLES3Buffer.h +++ b/cocos/renderer/gfx-gles3/GLES3Buffer.h @@ -13,6 +13,7 @@ class CC_GLES3_API GLES3Buffer : public Buffer { public: virtual bool initialize(const BufferInfo &info) override; + virtual bool initialize(const BufferViewInfo &info) override; virtual void destroy() override; virtual void resize(uint size) override; virtual void update(void *buffer, uint offset, uint size) override; diff --git a/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc b/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc index 2f8b3e45a66..fdcc22af6ef 100644 --- a/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc +++ b/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc @@ -1,9 +1,9 @@ #include "GLES3Std.h" -#include "GLES3BindingLayout.h" #include "GLES3Buffer.h" #include "GLES3CommandAllocator.h" #include "GLES3CommandBuffer.h" +#include "GLES3DescriptorSet.h" #include "GLES3Device.h" #include "GLES3Framebuffer.h" #include "GLES3InputAssembler.h" @@ -27,6 +27,10 @@ bool GLES3CommandBuffer::initialize(const CommandBufferInfo &info) { _gles3Allocator = ((GLES3Device *)_device)->cmdAllocator(); + uint setCount = ((GLES3Device *)_device)->bindingMappingInfo().bufferOffsets.size(); + _curGPUDescriptorSets.resize(setCount); + _curDynamicOffsets.resize(setCount); + _cmdPackage = CC_NEW(GLES3CmdPackage); _status = Status::SUCCESS; @@ -46,8 +50,10 @@ void GLES3CommandBuffer::destroy() { void GLES3CommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { _gles3Allocator->clearCmds(_cmdPackage); _curGPUPipelineState = nullptr; - _curGPUBlendLayout = nullptr; _curGPUInputAssember = nullptr; + _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); + for (vector &offsets : _curDynamicOffsets) offsets.clear(); + _numDrawCalls = 0; _numInstances = 0; _numTriangles = 0; @@ -60,15 +66,15 @@ void GLES3CommandBuffer::end() { _isInRenderPass = false; } -void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector &colors, float depth, int stencil) { +void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) { _isInRenderPass = true; GLES3CmdBeginRenderPass *cmd = _gles3Allocator->beginRenderPassCmdPool.alloc(); cmd->gpuRenderPass = ((GLES3RenderPass *)renderPass)->gpuRenderPass(); cmd->gpuFBO = ((GLES3Framebuffer *)fbo)->gpuFBO(); cmd->renderArea = renderArea; - cmd->numClearColors = (uint32_t)colors.size(); - for (uint i = 0; i < colors.size(); ++i) { + cmd->numClearColors = cmd->gpuRenderPass->colorAttachments.size(); + for (uint i = 0; i < cmd->numClearColors; ++i) { cmd->clearColors[i] = colors[i]; } cmd->clearDepth = depth; @@ -83,13 +89,25 @@ void GLES3CommandBuffer::endRenderPass() { } void GLES3CommandBuffer::bindPipelineState(PipelineState *pso) { - _curGPUPipelineState = ((GLES3PipelineState *)pso)->gpuPipelineState(); - _isStateInvalid = true; + GLES3GPUPipelineState *gpuPipelineState = ((GLES3PipelineState *)pso)->gpuPipelineState(); + if (_curGPUPipelineState != gpuPipelineState) { + _curGPUPipelineState = gpuPipelineState; + _isStateInvalid = true; + } } -void GLES3CommandBuffer::bindBindingLayout(BindingLayout *layout) { - _curGPUBlendLayout = ((GLES3BindingLayout *)layout)->gpuBindingLayout(); - _isStateInvalid = true; +void GLES3CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { + CCASSERT(_curGPUDescriptorSets.size() > set, "Invalid set index"); + + GLES3GPUDescriptorSet *gpuDescriptorSet = ((GLES3DescriptorSet *)descriptorSet)->gpuDescriptorSet(); + if (_curGPUDescriptorSets[set] != gpuDescriptorSet) { + _curGPUDescriptorSets[set] = gpuDescriptorSet; + _isStateInvalid = true; + } + if (dynamicOffsetCount) { + _curDynamicOffsets[set].assign(dynamicOffsets, dynamicOffsets + dynamicOffsetCount); + _isStateInvalid = true; + } } void GLES3CommandBuffer::bindInputAssembler(InputAssembler *ia) { @@ -155,22 +173,22 @@ void GLES3CommandBuffer::setBlendConstants(const Color &constants) { } } -void GLES3CommandBuffer::setDepthBound(float min_bounds, float max_bounds) { - if (math::IsNotEqualF(_curDepthBounds.minBounds, min_bounds) || - math::IsNotEqualF(_curDepthBounds.maxBounds, max_bounds)) { +void GLES3CommandBuffer::setDepthBound(float minBounds, float maxBounds) { + if (math::IsNotEqualF(_curDepthBounds.minBounds, minBounds) || + math::IsNotEqualF(_curDepthBounds.maxBounds, maxBounds)) { - _curDepthBounds.minBounds = min_bounds; - _curDepthBounds.maxBounds = max_bounds; + _curDepthBounds.minBounds = minBounds; + _curDepthBounds.maxBounds = maxBounds; _isStateInvalid = true; } } void GLES3CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { if ((_curStencilWriteMask.face != face) || - (_curStencilWriteMask.write_mask != mask)) { + (_curStencilWriteMask.writeMask != mask)) { _curStencilWriteMask.face = face; - _curStencilWriteMask.write_mask = mask; + _curStencilWriteMask.writeMask = mask; _isStateInvalid = true; } } @@ -242,7 +260,7 @@ void GLES3CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint } } -void GLES3CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { +void GLES3CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) || (_type == CommandBufferType::SECONDARY)) { @@ -250,12 +268,10 @@ void GLES3CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Tex if (gpuTexture) { GLES3CmdCopyBufferToTexture *cmd = _gles3Allocator->copyBufferToTextureCmdPool.alloc(); cmd->gpuTexture = gpuTexture; - cmd->buffers.resize(buffers.size()); - cmd->regions.resize(regions.size()); - for (uint i = 0; i < static_cast(regions.size()); ++i) { - cmd->buffers[i] = buffers[i]; - cmd->regions[i] = regions[i]; - } + cmd->gpuTexture = gpuTexture; + cmd->buffers = buffers; + cmd->regions = regions; + cmd->count = count; _cmdPackage->copyBufferToTextureCmds.push(cmd); _cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE); @@ -265,48 +281,51 @@ void GLES3CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Tex } } -void GLES3CommandBuffer::execute(const CommandBufferList &cmd_buffs, uint32_t count) { +void GLES3CommandBuffer::execute(const CommandBuffer *const *cmdBuffs, uint32_t count) { for (uint i = 0; i < count; ++i) { - GLES3CommandBuffer *cmd_buff = (GLES3CommandBuffer *)cmd_buffs[i]; + GLES3CommandBuffer *cmdBuff = (GLES3CommandBuffer *)cmdBuffs[i]; - for (uint j = 0; j < cmd_buff->_cmdPackage->beginRenderPassCmds.size(); ++j) { - GLES3CmdBeginRenderPass *cmd = cmd_buff->_cmdPackage->beginRenderPassCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->beginRenderPassCmds.size(); ++j) { + GLES3CmdBeginRenderPass *cmd = cmdBuff->_cmdPackage->beginRenderPassCmds[j]; + ++cmd->refCount; _cmdPackage->beginRenderPassCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->bindStatesCmds.size(); ++j) { - GLES3CmdBindStates *cmd = cmd_buff->_cmdPackage->bindStatesCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->bindStatesCmds.size(); ++j) { + GLES3CmdBindStates *cmd = cmdBuff->_cmdPackage->bindStatesCmds[j]; + ++cmd->refCount; _cmdPackage->bindStatesCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->drawCmds.size(); ++j) { - GLES3CmdDraw *cmd = cmd_buff->_cmdPackage->drawCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->drawCmds.size(); ++j) { + GLES3CmdDraw *cmd = cmdBuff->_cmdPackage->drawCmds[j]; + ++cmd->refCount; _cmdPackage->drawCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->updateBufferCmds.size(); ++j) { - GLES3CmdUpdateBuffer *cmd = cmd_buff->_cmdPackage->updateBufferCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->updateBufferCmds.size(); ++j) { + GLES3CmdUpdateBuffer *cmd = cmdBuff->_cmdPackage->updateBufferCmds[j]; + ++cmd->refCount; _cmdPackage->updateBufferCmds.push(cmd); } - for (uint j = 0; j < cmd_buff->_cmdPackage->copyBufferToTextureCmds.size(); ++j) { - GLES3CmdCopyBufferToTexture *cmd = cmd_buff->_cmdPackage->copyBufferToTextureCmds[j]; - ++cmd->ref_count; + for (uint j = 0; j < cmdBuff->_cmdPackage->copyBufferToTextureCmds.size(); ++j) { + GLES3CmdCopyBufferToTexture *cmd = cmdBuff->_cmdPackage->copyBufferToTextureCmds[j]; + ++cmd->refCount; _cmdPackage->copyBufferToTextureCmds.push(cmd); } - _cmdPackage->cmds.concat(cmd_buff->_cmdPackage->cmds); + _cmdPackage->cmds.concat(cmdBuff->_cmdPackage->cmds); - _numDrawCalls += cmd_buff->getNumDrawCalls(); - _numInstances += cmd_buff->getNumInstances(); - _numTriangles += cmd_buff->getNumTris(); + _numDrawCalls += cmdBuff->getNumDrawCalls(); + _numInstances += cmdBuff->getNumInstances(); + _numTriangles += cmdBuff->getNumTris(); } } void GLES3CommandBuffer::BindStates() { GLES3CmdBindStates *cmd = _gles3Allocator->bindStatesCmdPool.alloc(); cmd->gpuPipelineState = _curGPUPipelineState; - cmd->gpuBindingLayout = _curGPUBlendLayout; cmd->gpuInputAssembler = _curGPUInputAssember; + cmd->gpuDescriptorSets = _curGPUDescriptorSets; + for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { + cmd->dynamicOffsets.insert(cmd->dynamicOffsets.end(), _curDynamicOffsets[i].begin(), _curDynamicOffsets[i].end()); + } cmd->viewport = _curViewport; cmd->scissor = _curScissor; cmd->lineWidth = _curLineWidth; diff --git a/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h b/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h index 94f0f3c1dfe..8386c76020a 100644 --- a/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h +++ b/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h @@ -19,25 +19,25 @@ class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer { virtual bool initialize(const CommandBufferInfo &info) override; virtual void destroy() override; - virtual void begin(RenderPass *renderPass = nullptr, uint subpass = 0, Framebuffer *frameBuffer = nullptr) override; + virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector &colors, float depth, int stencil) override; + virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) override; virtual void endRenderPass() override; virtual void bindPipelineState(PipelineState *pso) override; - virtual void bindBindingLayout(BindingLayout *layout) override; + virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; virtual void bindInputAssembler(InputAssembler *ia) override; virtual void setViewport(const Viewport &vp) override; virtual void setScissor(const Rect &rect) override; virtual void setLineWidth(const float width) override; virtual void setDepthBias(float constant, float clamp, float slope) override; virtual void setBlendConstants(const Color &constants) override; - virtual void setDepthBound(float min_bounds, float max_bounds) override; + virtual void setDepthBound(float minBounds, float maxBounds) override; virtual void setStencilWriteMask(StencilFace face, uint mask) override; virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; virtual void draw(InputAssembler *ia) override; virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset) override; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override; - virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; + virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) override; private: void BindStates(); @@ -47,8 +47,9 @@ class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer { GLES3CommandAllocator *_gles3Allocator = nullptr; bool _isInRenderPass = false; GLES3GPUPipelineState *_curGPUPipelineState = nullptr; - GLES3GPUBindingLayout *_curGPUBlendLayout = nullptr; GLES3GPUInputAssembler *_curGPUInputAssember = nullptr; + vector _curGPUDescriptorSets; + vector> _curDynamicOffsets; Viewport _curViewport; Rect _curScissor; float _curLineWidth = 1.0f; diff --git a/cocos/renderer/gfx-gles3/GLES3Commands.cc b/cocos/renderer/gfx-gles3/GLES3Commands.cc index 2ac12828f02..ab73029c553 100644 --- a/cocos/renderer/gfx-gles3/GLES3Commands.cc +++ b/cocos/renderer/gfx-gles3/GLES3Commands.cc @@ -712,8 +712,8 @@ void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -745,8 +745,8 @@ void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) uint w = gpuTexture->width; uint h = gpuTexture->height; for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -808,8 +808,8 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -840,8 +840,8 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) uint w = gpuTexture->width; uint h = gpuTexture->height; for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint img_size = FormatSize(gpuTexture->format, w, h, 1); - glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, img_size, nullptr); + uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } @@ -857,7 +857,7 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } void GLES3CmdFuncCreateSampler(GLES3Device *device, GLES3GPUSampler *gpuSampler) { - glGenSamplers(1, &gpuSampler->gl_sampler); + glGenSamplers(1, &gpuSampler->glSampler); if (gpuSampler->minFilter == Filter::LINEAR || gpuSampler->minFilter == Filter::ANISOTROPIC) { if (gpuSampler->mipFilter == Filter::LINEAR || gpuSampler->mipFilter == Filter::ANISOTROPIC) { gpuSampler->glMinFilter = GL_LINEAR_MIPMAP_LINEAR; @@ -885,74 +885,74 @@ void GLES3CmdFuncCreateSampler(GLES3Device *device, GLES3GPUSampler *gpuSampler) gpuSampler->glWrapS = GLES3_WRAPS[(int)gpuSampler->addressU]; gpuSampler->glWrapT = GLES3_WRAPS[(int)gpuSampler->addressV]; gpuSampler->glWrapR = GLES3_WRAPS[(int)gpuSampler->addressW]; - glSamplerParameteri(gpuSampler->gl_sampler, GL_TEXTURE_MIN_FILTER, gpuSampler->glMinFilter); - glSamplerParameteri(gpuSampler->gl_sampler, GL_TEXTURE_MAG_FILTER, gpuSampler->glMagFilter); - glSamplerParameteri(gpuSampler->gl_sampler, GL_TEXTURE_WRAP_S, gpuSampler->glWrapS); - glSamplerParameteri(gpuSampler->gl_sampler, GL_TEXTURE_WRAP_T, gpuSampler->glWrapT); - glSamplerParameteri(gpuSampler->gl_sampler, GL_TEXTURE_WRAP_R, gpuSampler->glWrapR); - glSamplerParameteri(gpuSampler->gl_sampler, GL_TEXTURE_MIN_LOD, gpuSampler->minLOD); - glSamplerParameteri(gpuSampler->gl_sampler, GL_TEXTURE_MAX_LOD, gpuSampler->maxLOD); + glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_MIN_FILTER, gpuSampler->glMinFilter); + glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_MAG_FILTER, gpuSampler->glMagFilter); + glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_WRAP_S, gpuSampler->glWrapS); + glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_WRAP_T, gpuSampler->glWrapT); + glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_WRAP_R, gpuSampler->glWrapR); + glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_MIN_LOD, gpuSampler->minLOD); + glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_MAX_LOD, gpuSampler->maxLOD); } void GLES3CmdFuncDestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler) { - if (gpuSampler->gl_sampler) { + if (gpuSampler->glSampler) { uint unit = device->stateCache->texUint; GLuint &glSampler = device->stateCache->glSamplers[unit]; - if (glSampler == gpuSampler->gl_sampler) { + if (glSampler == gpuSampler->glSampler) { glBindSampler(unit, 0); glSampler = 0; } - glDeleteSamplers(1, &gpuSampler->gl_sampler); - gpuSampler->gl_sampler = 0; + glDeleteSamplers(1, &gpuSampler->glSampler); + gpuSampler->glSampler = 0; } } void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { - GLenum gl_shader_type = 0; - String shader_type_str; + GLenum glShaderStage = 0; + String shaderStageStr; GLint status; for (size_t i = 0; i < gpuShader->gpuStages.size(); ++i) { - GLES3GPUShaderStage &gpu_stage = gpuShader->gpuStages[i]; + GLES3GPUShaderStage &gpuStage = gpuShader->gpuStages[i]; - switch (gpu_stage.type) { - case ShaderType::VERTEX: { - gl_shader_type = GL_VERTEX_SHADER; - shader_type_str = "Vertex Shader"; + switch (gpuStage.type) { + case ShaderStageFlagBit::VERTEX: { + glShaderStage = GL_VERTEX_SHADER; + shaderStageStr = "Vertex Shader"; break; } - case ShaderType::FRAGMENT: { - gl_shader_type = GL_FRAGMENT_SHADER; - shader_type_str = "Fragment Shader"; + case ShaderStageFlagBit::FRAGMENT: { + glShaderStage = GL_FRAGMENT_SHADER; + shaderStageStr = "Fragment Shader"; break; } default: { - CCASSERT(false, "Unsupported ShaderType"); + CCASSERT(false, "Unsupported ShaderStageFlagBit"); return; } } - gpu_stage.glShader = glCreateShader(gl_shader_type); - String shaderSource = "#version 300 es\n" + gpu_stage.source; + gpuStage.glShader = glCreateShader(glShaderStage); + String shaderSource = "#version 300 es\n" + gpuStage.source; const char *source = shaderSource.c_str(); - glShaderSource(gpu_stage.glShader, 1, (const GLchar **)&source, nullptr); - glCompileShader(gpu_stage.glShader); + glShaderSource(gpuStage.glShader, 1, (const GLchar **)&source, nullptr); + glCompileShader(gpuStage.glShader); - glGetShaderiv(gpu_stage.glShader, GL_COMPILE_STATUS, &status); + glGetShaderiv(gpuStage.glShader, GL_COMPILE_STATUS, &status); if (status != 1) { - GLint log_size = 0; - glGetShaderiv(gpu_stage.glShader, GL_INFO_LOG_LENGTH, &log_size); + GLint logSize = 0; + glGetShaderiv(gpuStage.glShader, GL_INFO_LOG_LENGTH, &logSize); - ++log_size; - GLchar *logs = (GLchar *)CC_MALLOC(log_size); - glGetShaderInfoLog(gpu_stage.glShader, log_size, nullptr, logs); + ++logSize; + GLchar *logs = (GLchar *)CC_MALLOC(logSize); + glGetShaderInfoLog(gpuStage.glShader, logSize, nullptr, logs); - CC_LOG_ERROR("%s in %s compilation failed.", shader_type_str.c_str(), gpuShader->name.c_str()); - CC_LOG_ERROR("Shader source: %s", gpu_stage.source.c_str()); + CC_LOG_ERROR("%s in %s compilation failed.", shaderStageStr.c_str(), gpuShader->name.c_str()); + CC_LOG_ERROR("Shader source: %s", gpuStage.source.c_str()); CC_LOG_ERROR(logs); CC_FREE(logs); - glDeleteShader(gpu_stage.glShader); - gpu_stage.glShader = 0; + glDeleteShader(gpuStage.glShader); + gpuStage.glShader = 0; return; } } @@ -961,31 +961,31 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { // link program for (size_t i = 0; i < gpuShader->gpuStages.size(); ++i) { - GLES3GPUShaderStage &gpu_stage = gpuShader->gpuStages[i]; - glAttachShader(gpuShader->glProgram, gpu_stage.glShader); + GLES3GPUShaderStage &gpuStage = gpuShader->gpuStages[i]; + glAttachShader(gpuShader->glProgram, gpuStage.glShader); } glLinkProgram(gpuShader->glProgram); // detach & delete immediately for (size_t i = 0; i < gpuShader->gpuStages.size(); ++i) { - GLES3GPUShaderStage &gpu_stage = gpuShader->gpuStages[i]; - if (gpu_stage.glShader) { - glDetachShader(gpuShader->glProgram, gpu_stage.glShader); - glDeleteShader(gpu_stage.glShader); - gpu_stage.glShader = 0; + GLES3GPUShaderStage &gpuStage = gpuShader->gpuStages[i]; + if (gpuStage.glShader) { + glDetachShader(gpuShader->glProgram, gpuStage.glShader); + glDeleteShader(gpuStage.glShader); + gpuStage.glShader = 0; } } glGetProgramiv(gpuShader->glProgram, GL_LINK_STATUS, &status); if (status != 1) { CC_LOG_ERROR("Failed to link Shader [%s].", gpuShader->name.c_str()); - GLint log_size = 0; - glGetProgramiv(gpuShader->glProgram, GL_INFO_LOG_LENGTH, &log_size); - if (log_size) { - ++log_size; - GLchar *logs = (GLchar *)CC_MALLOC(log_size); - glGetProgramInfoLog(gpuShader->glProgram, log_size, nullptr, logs); + GLint logSize = 0; + glGetProgramiv(gpuShader->glProgram, GL_INFO_LOG_LENGTH, &logSize); + if (logSize) { + ++logSize; + GLchar *logs = (GLchar *)CC_MALLOC(logSize); + glGetProgramInfoLog(gpuShader->glProgram, logSize, nullptr, logs); CC_LOG_ERROR("Failed to link shader '%s'.", gpuShader->name.c_str()); CC_LOG_ERROR(logs); @@ -996,103 +996,105 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { CC_LOG_INFO("Shader '%s' compilation succeeded.", gpuShader->name.c_str()); - GLint attr_max_length = 0; - GLint attr_count = 0; - glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attr_max_length); - glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTES, &attr_count); + GLint attrMaxLength = 0; + GLint attrCount = 0; + glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attrMaxLength); + glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_ATTRIBUTES, &attrCount); - GLchar gl_name[256]; - GLsizei gl_length; - GLsizei gl_size; + GLchar glName[256]; + GLsizei glLength; + GLsizei glSize; GLenum glType; - gpuShader->glInputs.resize(attr_count); - for (GLint i = 0; i < attr_count; ++i) { + gpuShader->glInputs.resize(attrCount); + for (GLint i = 0; i < attrCount; ++i) { GLES3GPUInput &gpuInput = gpuShader->glInputs[i]; - memset(gl_name, 0, sizeof(gl_name)); - glGetActiveAttrib(gpuShader->glProgram, i, attr_max_length, &gl_length, &gl_size, &glType, gl_name); - char *offset = strchr(gl_name, '['); + memset(glName, 0, sizeof(glName)); + glGetActiveAttrib(gpuShader->glProgram, i, attrMaxLength, &glLength, &glSize, &glType, glName); + char *offset = strchr(glName, '['); if (offset) { - gl_name[offset - gl_name] = '\0'; + glName[offset - glName] = '\0'; } - gpuInput.glLoc = glGetAttribLocation(gpuShader->glProgram, gl_name); + gpuInput.glLoc = glGetAttribLocation(gpuShader->glProgram, glName); gpuInput.binding = gpuInput.glLoc; - gpuInput.name = gl_name; + gpuInput.name = glName; gpuInput.type = MapType(glType); gpuInput.stride = GLTypeSize(glType); - gpuInput.count = gl_size; + gpuInput.count = glSize; gpuInput.size = gpuInput.stride * gpuInput.count; gpuInput.glType = glType; } // create uniform blocks - GLint block_count; - glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORM_BLOCKS, &block_count); - if (block_count) { - GLint gl_block_size = 0; - GLint gl_block_uniforms = 0; - uint32_t block_idx = 0; - - gpuShader->glBlocks.resize(block_count); - for (GLint i = 0; i < block_count; ++i) { + GLint blockCount; + glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORM_BLOCKS, &blockCount); + if (blockCount) { + GLint glBlockSize = 0; + GLint glBlockUniforms = 0; + uint32_t blockIdx = 0; + + gpuShader->glBlocks.resize(blockCount); + for (GLint i = 0; i < blockCount; ++i) { GLES3GPUUniformBlock &gpuBlock = gpuShader->glBlocks[i]; - memset(gl_name, 0, sizeof(gl_name)); - glGetActiveUniformBlockName(gpuShader->glProgram, i, 255, &gl_length, gl_name); + memset(glName, 0, sizeof(glName)); + glGetActiveUniformBlockName(gpuShader->glProgram, i, 255, &glLength, glName); - char *offset = strchr(gl_name, '['); + char *offset = strchr(glName, '['); if (offset) { - gl_name[offset - gl_name] = '\0'; + glName[offset - glName] = '\0'; } - gpuBlock.name = gl_name; + gpuBlock.name = glName; gpuBlock.binding = GFX_INVALID_BINDING; for (size_t b = 0; b < gpuShader->blocks.size(); ++b) { UniformBlock &block = gpuShader->blocks[b]; if (block.name == gpuBlock.name) { + gpuBlock.set = block.set; gpuBlock.binding = block.binding; + gpuBlock.glBinding = block.binding + device->bindingMappingInfo().bufferOffsets[block.set]; break; } } if (gpuBlock.binding != GFX_INVALID_BINDING) { - block_idx = i; + blockIdx = i; - glUniformBlockBinding(gpuShader->glProgram, block_idx, gpuBlock.binding); + glUniformBlockBinding(gpuShader->glProgram, blockIdx, gpuBlock.glBinding); - glGetActiveUniformBlockiv(gpuShader->glProgram, i, GL_UNIFORM_BLOCK_DATA_SIZE, &gl_block_size); - glGetActiveUniformBlockiv(gpuShader->glProgram, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &gl_block_uniforms); - glUniformBlockBinding(gpuShader->glProgram, block_idx, gpuBlock.binding); + glGetActiveUniformBlockiv(gpuShader->glProgram, i, GL_UNIFORM_BLOCK_DATA_SIZE, &glBlockSize); + glGetActiveUniformBlockiv(gpuShader->glProgram, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &glBlockUniforms); + glUniformBlockBinding(gpuShader->glProgram, blockIdx, gpuBlock.glBinding); - gpuBlock.size = gl_block_size; - gpuBlock.glUniforms.resize(gl_block_uniforms); + gpuBlock.size = glBlockSize; + gpuBlock.glUniforms.resize(glBlockUniforms); - vector u_indices(gl_block_uniforms); - glGetActiveUniformBlockiv(gpuShader->glProgram, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &u_indices[0]); - // vector u_sizes(gl_block_uniforms); - // glGetActiveUniformsiv(gpuShader->glProgram, gl_block_uniforms, (const GLuint*)u_indices.data(), GL_UNIFORM_SIZE, &u_sizes[0]); - vector u_offsets(gl_block_uniforms); - glGetActiveUniformsiv(gpuShader->glProgram, gl_block_uniforms, (const GLuint *)u_indices.data(), GL_UNIFORM_OFFSET, &u_offsets[0]); + vector indices(glBlockUniforms); + glGetActiveUniformBlockiv(gpuShader->glProgram, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &indices[0]); + // vector sizes(glBlockUniforms); + // glGetActiveUniformsiv(gpuShader->glProgram, glBlockUniforms, (const GLuint*)indices.data(), GL_UNIFORM_SIZE, &sizes[0]); + vector offsets(glBlockUniforms); + glGetActiveUniformsiv(gpuShader->glProgram, glBlockUniforms, (const GLuint *)indices.data(), GL_UNIFORM_OFFSET, &offsets[0]); - for (GLint u = 0; u < gl_block_uniforms; ++u) { + for (GLint u = 0; u < glBlockUniforms; ++u) { GLES3GPUUniform &uniform = gpuBlock.glUniforms[u]; - GLint idx = u_indices[u]; - memset(gl_name, 0, sizeof(gl_name)); - glGetActiveUniform(gpuShader->glProgram, idx, 255, &gl_length, &gl_size, &glType, gl_name); - offset = strchr(gl_name, '['); + GLint idx = indices[u]; + memset(glName, 0, sizeof(glName)); + glGetActiveUniform(gpuShader->glProgram, idx, 255, &glLength, &glSize, &glType, glName); + offset = strchr(glName, '['); if (offset) { - gl_name[offset - gl_name] = '\0'; + glName[offset - glName] = '\0'; } uniform.binding = GFX_INVALID_BINDING; - uniform.name = gl_name; + uniform.name = glName; uniform.type = MapType(glType); uniform.stride = GFX_TYPE_SIZES[(int)uniform.type]; - uniform.count = gl_size; + uniform.count = glSize; uniform.size = uniform.stride * uniform.count; - uniform.offset = u_offsets[u]; + uniform.offset = offsets[u]; uniform.glType = glType; uniform.glLoc = -1; } @@ -1107,6 +1109,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { for (size_t i = 0; i < gpuShader->glSamplers.size(); ++i) { UniformSampler &sampler = gpuShader->samplers[i]; GLES3GPUUniformSampler &gpuSampler = gpuShader->glSamplers[i]; + gpuSampler.set = sampler.set; gpuSampler.binding = sampler.binding; gpuSampler.name = sampler.name; gpuSampler.type = sampler.type; @@ -1119,55 +1122,65 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { GLint glActiveUniforms; glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORMS, &glActiveUniforms); - GLint unit_idx = 0; + GLint unitIdx = 0; - GLES3GPUUniformSamplerList active_gpu_samplers; + GLES3GPUUniformSamplerList activeGPUSamplers; for (GLint i = 0; i < glActiveUniforms; ++i) { - memset(gl_name, 0, sizeof(gl_name)); - glGetActiveUniform(gpuShader->glProgram, i, 255, &gl_length, &gl_size, &glType, gl_name); - char *u_offset = strchr(gl_name, '['); - if (u_offset) { - gl_name[u_offset - gl_name] = '\0'; + memset(glName, 0, sizeof(glName)); + glGetActiveUniform(gpuShader->glProgram, i, 255, &glLength, &glSize, &glType, glName); + char *offset = strchr(glName, '['); + if (offset) { + glName[offset - glName] = '\0'; } - bool is_sampler = (glType == GL_SAMPLER_2D) || - (glType == GL_SAMPLER_3D) || - (glType == GL_SAMPLER_CUBE) || - (glType == GL_SAMPLER_CUBE_SHADOW) || - (glType == GL_SAMPLER_2D_ARRAY) || - (glType == GL_SAMPLER_2D_ARRAY_SHADOW); - if (is_sampler) { - String u_name = gl_name; + bool isSampler = (glType == GL_SAMPLER_2D) || + (glType == GL_SAMPLER_3D) || + (glType == GL_SAMPLER_CUBE) || + (glType == GL_SAMPLER_CUBE_SHADOW) || + (glType == GL_SAMPLER_2D_ARRAY) || + (glType == GL_SAMPLER_2D_ARRAY_SHADOW); + if (isSampler) { + String name = glName; for (size_t s = 0; s < gpuShader->glSamplers.size(); ++s) { GLES3GPUUniformSampler &gpuSampler = gpuShader->glSamplers[s]; - if (gpuSampler.name == u_name) { - gpuSampler.units.resize(gl_size); - for (GLsizei u = 0; u < gl_size; ++u) { - gpuSampler.units[u] = unit_idx + u; + if (gpuSampler.name == name) { + gpuSampler.units.resize(glSize); + for (GLsizei u = 0; u < glSize; ++u) { + gpuSampler.units[u] = unitIdx + u; } - gpuSampler.glLoc = glGetUniformLocation(gpuShader->glProgram, gl_name); - unit_idx += gl_size; + gpuSampler.glLoc = glGetUniformLocation(gpuShader->glProgram, glName); + unitIdx += glSize; - active_gpu_samplers.push_back(gpuSampler); + activeGPUSamplers.push_back(gpuSampler); break; } } } // if - } // for + } - if (active_gpu_samplers.size()) { + if (activeGPUSamplers.size()) { if (device->stateCache->glProgram != gpuShader->glProgram) { glUseProgram(gpuShader->glProgram); device->stateCache->glProgram = gpuShader->glProgram; } - for (size_t i = 0; i < active_gpu_samplers.size(); ++i) { - GLES3GPUUniformSampler &gpuSampler = active_gpu_samplers[i]; + for (size_t i = 0; i < activeGPUSamplers.size(); ++i) { + GLES3GPUUniformSampler &gpuSampler = activeGPUSamplers[i]; glUniform1iv(gpuSampler.glLoc, (GLsizei)gpuSampler.units.size(), gpuSampler.units.data()); } } + + // strip out the inactive ones + for (uint i = 0u; i < gpuShader->glSamplers.size();) { + if (gpuShader->glSamplers[i].units.size()) { + i++; + } else { + gpuShader->glSamplers[i] = gpuShader->glSamplers.back(); + gpuShader->glSamplers.pop_back(); + } + } } void GLES3CmdFuncDestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader) { @@ -1194,14 +1207,13 @@ void GLES3CmdFuncCreateInputAssembler(GLES3Device *device, GLES3GPUInputAssemble } } - uint stream_offsets[GFX_MAX_VERTEX_ATTRIBUTES] = {0}; + uint streamOffsets[GFX_MAX_VERTEX_ATTRIBUTES] = {0}; gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size()); for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) { GLES3GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[i]; const Attribute &attrib = gpuInputAssembler->attributes[i]; - - GLES3GPUBuffer *gpu_vb = (GLES3GPUBuffer *)gpuInputAssembler->gpuVertexBuffers[attrib.stream]; + GLES3GPUBuffer *gpuVB = (GLES3GPUBuffer *)gpuInputAssembler->gpuVertexBuffers[attrib.stream]; gpuAttribute.name = attrib.name; gpuAttribute.glType = FormatToGLType(attrib.format); @@ -1210,13 +1222,13 @@ void GLES3CmdFuncCreateInputAssembler(GLES3Device *device, GLES3GPUInputAssemble gpuAttribute.componentCount = GLComponentCount(gpuAttribute.glType); gpuAttribute.isNormalized = attrib.isNormalized; gpuAttribute.isInstanced = attrib.isInstanced; - gpuAttribute.offset = stream_offsets[attrib.stream]; + gpuAttribute.offset = streamOffsets[attrib.stream]; - if (gpu_vb) { - gpuAttribute.glBuffer = gpu_vb->glBuffer; - gpuAttribute.stride = gpu_vb->stride; + if (gpuVB) { + gpuAttribute.glBuffer = gpuVB->glBuffer; + gpuAttribute.stride = gpuVB->stride; } - stream_offsets[attrib.stream] += gpuAttribute.size; + streamOffsets[attrib.stream] += gpuAttribute.size; } } @@ -1253,7 +1265,7 @@ void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpu } GLenum attachments[GFX_MAX_ATTACHMENTS] = {0}; - uint attachment_count = 0; + uint attachmentCount = 0; size_t colorMipmapLevelCount = gpuFBO->colorMipmapLevels.size(); for (size_t i = 0; i < gpuFBO->gpuColorTextures.size(); ++i) { @@ -1265,17 +1277,17 @@ void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpu } glFramebufferTexture2D(GL_FRAMEBUFFER, (GLenum)(GL_COLOR_ATTACHMENT0 + i), gpuColorTexture->glTarget, gpuColorTexture->glTexture, mipmapLevel); - attachments[attachment_count++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + attachments[attachmentCount++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); } } if (gpuFBO->gpuDepthStencilTexture) { GLES3GPUTexture *gpuDepthStencilTexture = gpuFBO->gpuDepthStencilTexture; - const GLenum gl_attachment = GFX_FORMAT_INFOS[(int)gpuDepthStencilTexture->format].hasStencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT; - glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attachment, gpuDepthStencilTexture->glTarget, gpuDepthStencilTexture->glTexture, gpuFBO->depthStencilMipmapLevel); + const GLenum glAttachment = GFX_FORMAT_INFOS[(int)gpuDepthStencilTexture->format].hasStencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT; + glFramebufferTexture2D(GL_FRAMEBUFFER, glAttachment, gpuDepthStencilTexture->glTarget, gpuDepthStencilTexture->glTexture, gpuFBO->depthStencilMipmapLevel); } - glDrawBuffers(attachment_count, attachments); + glDrawBuffers(attachmentCount, attachments); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { @@ -1372,8 +1384,8 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { cache->scissor.height = cmd->renderArea.height; } - GLbitfield gl_clears = 0; - uint num_attachments = 0; + GLbitfield glClears = 0; + uint numAttachments = 0; gpuRenderPass = cmd->gpuRenderPass; for (uint j = 0; j < cmd->numClearColors; ++j) { @@ -1387,22 +1399,22 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } if (cmd->gpuFBO->isOffscreen) { - static float f_colors[4]; - f_colors[0] = cmd->clearColors[j].r; - f_colors[1] = cmd->clearColors[j].g; - f_colors[2] = cmd->clearColors[j].b; - f_colors[3] = cmd->clearColors[j].a; - glClearBufferfv(GL_COLOR, j, f_colors); + static float fColors[4]; + fColors[0] = cmd->clearColors[j].r; + fColors[1] = cmd->clearColors[j].g; + fColors[2] = cmd->clearColors[j].b; + fColors[3] = cmd->clearColors[j].a; + glClearBufferfv(GL_COLOR, j, fColors); } else { const Color &color = cmd->clearColors[j]; glClearColor(color.r, color.g, color.b, color.a); - gl_clears |= GL_COLOR_BUFFER_BIT; + glClears |= GL_COLOR_BUFFER_BIT; } break; } case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR); break; } default:; @@ -1419,19 +1431,19 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { glDepthMask(true); cache->dss.depthWrite = true; glClearDepthf(cmd->clearDepth); - gl_clears |= GL_DEPTH_BUFFER_BIT; + glClears |= GL_DEPTH_BUFFER_BIT; break; } case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH); break; } default:; } } // if (hasDepth) - bool has_stencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; - if (has_stencils) { + bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: { @@ -1442,43 +1454,43 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { glStencilMaskSeparate(GL_BACK, 0xffffffff); } glClearStencil(cmd->clearStencil); - gl_clears |= GL_STENCIL_BUFFER_BIT; + glClears |= GL_STENCIL_BUFFER_BIT; break; } case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL); break; } default:; } - } // if (has_stencils) - } // if + } // if (hasStencils) + } - if (num_attachments) { - glInvalidateFramebuffer(GL_FRAMEBUFFER, num_attachments, glAttachments); + if (numAttachments) { + glInvalidateFramebuffer(GL_FRAMEBUFFER, numAttachments, glAttachments); } - if (gl_clears) { - glClear(gl_clears); + if (glClears) { + glClear(glClears); } // restore states - if (gl_clears & GL_COLOR_BUFFER_BIT) { - ColorMask color_mask = cache->bs.targets[0].blendColorMask; - if (color_mask != ColorMask::ALL) { - glColorMask((GLboolean)(color_mask & ColorMask::R), - (GLboolean)(color_mask & ColorMask::G), - (GLboolean)(color_mask & ColorMask::B), - (GLboolean)(color_mask & ColorMask::A)); + if (glClears & GL_COLOR_BUFFER_BIT) { + ColorMask colorMask = cache->bs.targets[0].blendColorMask; + if (colorMask != ColorMask::ALL) { + glColorMask((GLboolean)(colorMask & ColorMask::R), + (GLboolean)(colorMask & ColorMask::G), + (GLboolean)(colorMask & ColorMask::B), + (GLboolean)(colorMask & ColorMask::A)); } } - if ((gl_clears & GL_COLOR_BUFFER_BIT) && !cache->dss.depthWrite) { + if ((glClears & GL_COLOR_BUFFER_BIT) && !cache->dss.depthWrite) { glDepthMask(false); } - if (gl_clears & GL_STENCIL_BUFFER_BIT) { + if (glClears & GL_STENCIL_BUFFER_BIT) { if (!cache->dss.stencilWriteMaskFront) { glStencilMaskSeparate(GL_FRONT, 0); } @@ -1491,7 +1503,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } case GFXCmdType::END_RENDER_PASS: { GLES3CmdBeginRenderPass *cmd = cmdBeginRenderPass; - uint num_attachments = 0; + uint numAttachments = 0; for (uint j = 0; j < cmd->numClearColors; ++j) { const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[j]; if (colorAttachment.format != Format::UNKNOWN) { @@ -1500,7 +1512,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { case LoadOp::CLEAR: break; case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_COLOR_ATTACHMENT0 + j : GL_COLOR); break; } default:; @@ -1516,29 +1528,29 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { case LoadOp::CLEAR: break; case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH); break; } default:; } } // if (hasDepth) - bool has_stencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; - if (has_stencils) { + bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: break; case LoadOp::DISCARD: { // invalidate fbo - glAttachments[num_attachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL); + glAttachments[numAttachments++] = (cmd->gpuFBO->isOffscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL); break; } default:; } - } // if (has_stencils) - } // if + } // if (hasStencils) + } - if (num_attachments) { - glInvalidateFramebuffer(GL_FRAMEBUFFER, num_attachments, glAttachments); + if (numAttachments) { + glInvalidateFramebuffer(GL_FRAMEBUFFER, numAttachments, glAttachments); } break; } @@ -1586,218 +1598,235 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } cache->rs.cullMode = gpuPipelineState->rs.cullMode; } - } - bool isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW; - if (reverseCW) isFrontFaceCCW = !isFrontFaceCCW; - if (cache->rs.isFrontFaceCCW != isFrontFaceCCW) { - glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW); - cache->rs.isFrontFaceCCW = isFrontFaceCCW; - } - if ((cache->rs.depthBias != gpuPipelineState->rs.depthBias) || - (cache->rs.depthBiasSlop != gpuPipelineState->rs.depthBiasSlop)) { - glPolygonOffset(cache->rs.depthBias, cache->rs.depthBiasSlop); - cache->rs.depthBiasSlop = gpuPipelineState->rs.depthBiasSlop; - } - if (cache->rs.lineWidth != gpuPipelineState->rs.lineWidth) { - glLineWidth(gpuPipelineState->rs.lineWidth); - cache->rs.lineWidth = gpuPipelineState->rs.lineWidth; - } + bool isFrontFaceCCW = gpuPipelineState->rs.isFrontFaceCCW; + if (reverseCW) isFrontFaceCCW = !isFrontFaceCCW; + if (cache->rs.isFrontFaceCCW != isFrontFaceCCW) { + glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW); + cache->rs.isFrontFaceCCW = isFrontFaceCCW; + } + if ((cache->rs.depthBias != gpuPipelineState->rs.depthBias) || + (cache->rs.depthBiasSlop != gpuPipelineState->rs.depthBiasSlop)) { + glPolygonOffset(cache->rs.depthBias, cache->rs.depthBiasSlop); + cache->rs.depthBiasSlop = gpuPipelineState->rs.depthBiasSlop; + } + if (cache->rs.lineWidth != gpuPipelineState->rs.lineWidth) { + glLineWidth(gpuPipelineState->rs.lineWidth); + cache->rs.lineWidth = gpuPipelineState->rs.lineWidth; + } - // bind depth-stencil state - if (cache->dss.depthTest != gpuPipelineState->dss.depthTest) { - if (gpuPipelineState->dss.depthTest) { - glEnable(GL_DEPTH_TEST); + // bind depth-stencil state + if (cache->dss.depthTest != gpuPipelineState->dss.depthTest) { + if (gpuPipelineState->dss.depthTest) { + glEnable(GL_DEPTH_TEST); + } else { + glDisable(GL_DEPTH_TEST); + } + cache->dss.depthTest = gpuPipelineState->dss.depthTest; + } + if (cache->dss.depthWrite != gpuPipelineState->dss.depthWrite) { + glDepthMask(gpuPipelineState->dss.depthWrite); + cache->dss.depthWrite = gpuPipelineState->dss.depthWrite; + } + if (cache->dss.depthFunc != gpuPipelineState->dss.depthFunc) { + glDepthFunc(GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.depthFunc]); + cache->dss.depthFunc = gpuPipelineState->dss.depthFunc; + } + + // bind depth-stencil state - front + if (gpuPipelineState->dss.stencilTestFront || gpuPipelineState->dss.stencilTestBack) { + if (!cache->isStencilTestEnabled) { + glEnable(GL_STENCIL_TEST); + cache->isStencilTestEnabled = true; + } } else { - glDisable(GL_DEPTH_TEST); + if (cache->isStencilTestEnabled) { + glDisable(GL_STENCIL_TEST); + cache->isStencilTestEnabled = false; + } + } + if (cache->dss.stencilFuncFront != gpuPipelineState->dss.stencilFuncFront || + cache->dss.stencilRefFront != gpuPipelineState->dss.stencilRefFront || + cache->dss.stencilReadMaskFront != gpuPipelineState->dss.stencilReadMaskFront) { + glStencilFuncSeparate(GL_FRONT, + GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncFront], + gpuPipelineState->dss.stencilRefFront, + gpuPipelineState->dss.stencilReadMaskFront); + cache->dss.stencilFuncFront = gpuPipelineState->dss.stencilFuncFront; + cache->dss.stencilRefFront = gpuPipelineState->dss.stencilRefFront; + cache->dss.stencilReadMaskFront = gpuPipelineState->dss.stencilReadMaskFront; + } + if (cache->dss.stencilFailOpFront != gpuPipelineState->dss.stencilFailOpFront || + cache->dss.stencilZFailOpFront != gpuPipelineState->dss.stencilZFailOpFront || + cache->dss.stencilPassOpFront != gpuPipelineState->dss.stencilPassOpFront) { + glStencilOpSeparate(GL_FRONT, + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpFront], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpFront], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpFront]); + cache->dss.stencilFailOpFront = gpuPipelineState->dss.stencilFailOpFront; + cache->dss.stencilZFailOpFront = gpuPipelineState->dss.stencilZFailOpFront; + cache->dss.stencilPassOpFront = gpuPipelineState->dss.stencilPassOpFront; + } + if (cache->dss.stencilWriteMaskFront != gpuPipelineState->dss.stencilWriteMaskFront) { + glStencilMaskSeparate(GL_FRONT, gpuPipelineState->dss.stencilWriteMaskFront); + cache->dss.stencilWriteMaskFront = gpuPipelineState->dss.stencilWriteMaskFront; } - cache->dss.depthTest = gpuPipelineState->dss.depthTest; - } - if (cache->dss.depthWrite != gpuPipelineState->dss.depthWrite) { - glDepthMask(gpuPipelineState->dss.depthWrite); - cache->dss.depthWrite = gpuPipelineState->dss.depthWrite; - } - if (cache->dss.depthFunc != gpuPipelineState->dss.depthFunc) { - glDepthFunc(GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.depthFunc]); - cache->dss.depthFunc = gpuPipelineState->dss.depthFunc; - } - // bind depth-stencil state - front - if (gpuPipelineState->dss.stencilTestFront || gpuPipelineState->dss.stencilTestBack) { - if (!cache->isStencilTestEnabled) { - glEnable(GL_STENCIL_TEST); - cache->isStencilTestEnabled = true; + // bind depth-stencil state - back + if (cache->dss.stencilFuncBack != gpuPipelineState->dss.stencilFuncBack || + cache->dss.stencilRefBack != gpuPipelineState->dss.stencilRefBack || + cache->dss.stencilReadMaskBack != gpuPipelineState->dss.stencilReadMaskBack) { + glStencilFuncSeparate(GL_BACK, + GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncBack], + gpuPipelineState->dss.stencilRefBack, + gpuPipelineState->dss.stencilReadMaskBack); + cache->dss.stencilFuncBack = gpuPipelineState->dss.stencilFuncBack; + cache->dss.stencilRefBack = gpuPipelineState->dss.stencilRefBack; + cache->dss.stencilReadMaskBack = gpuPipelineState->dss.stencilReadMaskBack; } - } else { - if (cache->isStencilTestEnabled) { - glDisable(GL_STENCIL_TEST); - cache->isStencilTestEnabled = false; + if (cache->dss.stencilFailOpBack != gpuPipelineState->dss.stencilFailOpBack || + cache->dss.stencilZFailOpBack != gpuPipelineState->dss.stencilZFailOpBack || + cache->dss.stencilPassOpBack != gpuPipelineState->dss.stencilPassOpBack) { + glStencilOpSeparate(GL_BACK, + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpBack], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpBack], + GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpBack]); + cache->dss.stencilFailOpBack = gpuPipelineState->dss.stencilFailOpBack; + cache->dss.stencilZFailOpBack = gpuPipelineState->dss.stencilZFailOpBack; + cache->dss.stencilPassOpBack = gpuPipelineState->dss.stencilPassOpBack; + } + if (cache->dss.stencilWriteMaskBack != gpuPipelineState->dss.stencilWriteMaskBack) { + glStencilMaskSeparate(GL_BACK, gpuPipelineState->dss.stencilWriteMaskBack); + cache->dss.stencilWriteMaskBack = gpuPipelineState->dss.stencilWriteMaskBack; } - } - if (cache->dss.stencilFuncFront != gpuPipelineState->dss.stencilFuncFront || - cache->dss.stencilRefFront != gpuPipelineState->dss.stencilRefFront || - cache->dss.stencilReadMaskFront != gpuPipelineState->dss.stencilReadMaskFront) { - glStencilFuncSeparate(GL_FRONT, - GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncFront], - gpuPipelineState->dss.stencilRefFront, - gpuPipelineState->dss.stencilReadMaskFront); - cache->dss.stencilFuncFront = gpuPipelineState->dss.stencilFuncFront; - cache->dss.stencilRefFront = gpuPipelineState->dss.stencilRefFront; - cache->dss.stencilReadMaskFront = gpuPipelineState->dss.stencilReadMaskFront; - } - if (cache->dss.stencilFailOpFront != gpuPipelineState->dss.stencilFailOpFront || - cache->dss.stencilZFailOpFront != gpuPipelineState->dss.stencilZFailOpFront || - cache->dss.stencilPassOpFront != gpuPipelineState->dss.stencilPassOpFront) { - glStencilOpSeparate(GL_FRONT, - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpFront], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpFront], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpFront]); - cache->dss.stencilFailOpFront = gpuPipelineState->dss.stencilFailOpFront; - cache->dss.stencilZFailOpFront = gpuPipelineState->dss.stencilZFailOpFront; - cache->dss.stencilPassOpFront = gpuPipelineState->dss.stencilPassOpFront; - } - if (cache->dss.stencilWriteMaskFront != gpuPipelineState->dss.stencilWriteMaskFront) { - glStencilMaskSeparate(GL_FRONT, gpuPipelineState->dss.stencilWriteMaskFront); - cache->dss.stencilWriteMaskFront = gpuPipelineState->dss.stencilWriteMaskFront; - } - // bind depth-stencil state - back - if (cache->dss.stencilFuncBack != gpuPipelineState->dss.stencilFuncBack || - cache->dss.stencilRefBack != gpuPipelineState->dss.stencilRefBack || - cache->dss.stencilReadMaskBack != gpuPipelineState->dss.stencilReadMaskBack) { - glStencilFuncSeparate(GL_BACK, - GLES3_CMP_FUNCS[(int)gpuPipelineState->dss.stencilFuncBack], - gpuPipelineState->dss.stencilRefBack, - gpuPipelineState->dss.stencilReadMaskBack); - cache->dss.stencilFuncBack = gpuPipelineState->dss.stencilFuncBack; - cache->dss.stencilRefBack = gpuPipelineState->dss.stencilRefBack; - cache->dss.stencilReadMaskBack = gpuPipelineState->dss.stencilReadMaskBack; - } - if (cache->dss.stencilFailOpBack != gpuPipelineState->dss.stencilFailOpBack || - cache->dss.stencilZFailOpBack != gpuPipelineState->dss.stencilZFailOpBack || - cache->dss.stencilPassOpBack != gpuPipelineState->dss.stencilPassOpBack) { - glStencilOpSeparate(GL_BACK, - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilFailOpBack], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilZFailOpBack], - GLES3_STENCIL_OPS[(int)gpuPipelineState->dss.stencilPassOpBack]); - cache->dss.stencilFailOpBack = gpuPipelineState->dss.stencilFailOpBack; - cache->dss.stencilZFailOpBack = gpuPipelineState->dss.stencilZFailOpBack; - cache->dss.stencilPassOpBack = gpuPipelineState->dss.stencilPassOpBack; - } - if (cache->dss.stencilWriteMaskBack != gpuPipelineState->dss.stencilWriteMaskBack) { - glStencilMaskSeparate(GL_BACK, gpuPipelineState->dss.stencilWriteMaskBack); - cache->dss.stencilWriteMaskBack = gpuPipelineState->dss.stencilWriteMaskBack; - } + // bind blend state + if (cache->bs.isA2C != gpuPipelineState->bs.isA2C) { + if (cache->bs.isA2C) { + glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } else { + glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } + cache->bs.isA2C = gpuPipelineState->bs.isA2C; + } + if (cache->bs.blendColor.r != gpuPipelineState->bs.blendColor.r || + cache->bs.blendColor.g != gpuPipelineState->bs.blendColor.g || + cache->bs.blendColor.b != gpuPipelineState->bs.blendColor.b || + cache->bs.blendColor.a != gpuPipelineState->bs.blendColor.a) { + + glBlendColor(gpuPipelineState->bs.blendColor.r, + gpuPipelineState->bs.blendColor.g, + gpuPipelineState->bs.blendColor.b, + gpuPipelineState->bs.blendColor.a); + cache->bs.blendColor = gpuPipelineState->bs.blendColor; + } - // bind blend state - if (cache->bs.isA2C != gpuPipelineState->bs.isA2C) { - if (cache->bs.isA2C) { - glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); - } else { - glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); + BlendTarget &cacheTarget = cache->bs.targets[0]; + const BlendTarget &target = gpuPipelineState->bs.targets[0]; + if (cacheTarget.blend != target.blend) { + if (!cacheTarget.blend) { + glEnable(GL_BLEND); + } else { + glDisable(GL_BLEND); + } + cacheTarget.blend = target.blend; } - cache->bs.isA2C = gpuPipelineState->bs.isA2C; - } - if (cache->bs.blendColor.r != gpuPipelineState->bs.blendColor.r || - cache->bs.blendColor.g != gpuPipelineState->bs.blendColor.g || - cache->bs.blendColor.b != gpuPipelineState->bs.blendColor.b || - cache->bs.blendColor.a != gpuPipelineState->bs.blendColor.a) { - - glBlendColor(gpuPipelineState->bs.blendColor.r, - gpuPipelineState->bs.blendColor.g, - gpuPipelineState->bs.blendColor.b, - gpuPipelineState->bs.blendColor.a); - cache->bs.blendColor = gpuPipelineState->bs.blendColor; - } + if (cacheTarget.blendEq != target.blendEq || + cacheTarget.blendAlphaEq != target.blendAlphaEq) { + glBlendEquationSeparate(GLES3_BLEND_OPS[(int)target.blendEq], + GLES3_BLEND_OPS[(int)target.blendAlphaEq]); + cacheTarget.blendEq = target.blendEq; + cacheTarget.blendAlphaEq = target.blendAlphaEq; + } + if (cacheTarget.blendSrc != target.blendSrc || + cacheTarget.blendDst != target.blendDst || + cacheTarget.blendSrcAlpha != target.blendSrcAlpha || + cacheTarget.blendDstAlpha != target.blendDstAlpha) { + glBlendFuncSeparate(GLES3_BLEND_FACTORS[(int)target.blendSrc], + GLES3_BLEND_FACTORS[(int)target.blendDst], + GLES3_BLEND_FACTORS[(int)target.blendSrcAlpha], + GLES3_BLEND_FACTORS[(int)target.blendDstAlpha]); + cacheTarget.blendSrc = target.blendSrc; + cacheTarget.blendDst = target.blendDst; + cacheTarget.blendSrcAlpha = target.blendSrcAlpha; + cacheTarget.blendDstAlpha = target.blendDstAlpha; + } + if (cacheTarget.blendColorMask != target.blendColorMask) { + glColorMask((GLboolean)(target.blendColorMask & ColorMask::R), + (GLboolean)(target.blendColorMask & ColorMask::G), + (GLboolean)(target.blendColorMask & ColorMask::B), + (GLboolean)(target.blendColorMask & ColorMask::A)); + cacheTarget.blendColorMask = target.blendColorMask; + } + } // if - BlendTarget &cache_target = cache->bs.targets[0]; - const BlendTarget &target = gpuPipelineState->bs.targets[0]; - if (cache_target.blend != target.blend) { - if (!cache_target.blend) { - glEnable(GL_BLEND); - } else { - glDisable(GL_BLEND); + // bind descriptor sets + if (cmd->gpuPipelineState && gpuPipelineState->gpuShader && gpuPipelineState->gpuPipelineLayout) { + + size_t blockLen = gpuPipelineState->gpuShader->glBlocks.size(); + const vector> &dynamicOffsetIndices = cmd->gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices; + + for (size_t j = 0; j < blockLen; j++) { + const GLES3GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j]; + + CCASSERT(cmd->gpuDescriptorSets.size() > glBlock.set, "Invalid set index"); + const GLES3GPUDescriptorSet *gpuDescriptorSet = cmd->gpuDescriptorSets[glBlock.set]; + const GLES3GPUDescriptor &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[glBlock.binding]; + + if (!gpuDescriptor.gpuBuffer) { + CC_LOG_ERROR("Buffer binding '%s' at set %d binding %d is not bounded", + glBlock.name.c_str(), glBlock.set, glBlock.binding); + continue; + } + + int dynamicOffsetIndex = -1; + const vector &dynamicOffsetIndexSet = dynamicOffsetIndices[glBlock.set]; + dynamicOffsetIndex = dynamicOffsetIndexSet[glBlock.binding]; + + if (dynamicOffsetIndex >= 0) { // dynamically bound + glBindBufferRange(GL_UNIFORM_BUFFER, glBlock.glBinding, gpuDescriptor.gpuBuffer->glBuffer, + gpuDescriptor.gpuBuffer->glOffset + cmd->dynamicOffsets[dynamicOffsetIndex], + gpuDescriptor.gpuBuffer->size); + cache->glUniformBuffer = cache->glBindUBOs[glBlock.glBinding] = gpuDescriptor.gpuBuffer->glBuffer; + } else { // statically bound + if (cache->glBindUBOs[glBlock.glBinding] != gpuDescriptor.gpuBuffer->glBuffer) { + glBindBufferBase(GL_UNIFORM_BUFFER, glBlock.glBinding, gpuDescriptor.gpuBuffer->glBuffer); + cache->glUniformBuffer = cache->glBindUBOs[glBlock.glBinding] = gpuDescriptor.gpuBuffer->glBuffer; + } + } } - cache_target.blend = target.blend; - } - if (cache_target.blendEq != target.blendEq || - cache_target.blendAlphaEq != target.blendAlphaEq) { - glBlendEquationSeparate(GLES3_BLEND_OPS[(int)target.blendEq], - GLES3_BLEND_OPS[(int)target.blendAlphaEq]); - cache_target.blendEq = target.blendEq; - cache_target.blendAlphaEq = target.blendAlphaEq; - } - if (cache_target.blendSrc != target.blendSrc || - cache_target.blendDst != target.blendDst || - cache_target.blendSrcAlpha != target.blendSrcAlpha || - cache_target.blendDstAlpha != target.blendDstAlpha) { - glBlendFuncSeparate(GLES3_BLEND_FACTORS[(int)target.blendSrc], - GLES3_BLEND_FACTORS[(int)target.blendDst], - GLES3_BLEND_FACTORS[(int)target.blendSrcAlpha], - GLES3_BLEND_FACTORS[(int)target.blendDstAlpha]); - cache_target.blendSrc = target.blendSrc; - cache_target.blendDst = target.blendDst; - cache_target.blendSrcAlpha = target.blendSrcAlpha; - cache_target.blendDstAlpha = target.blendDstAlpha; - } - if (cache_target.blendColorMask != target.blendColorMask) { - glColorMask((GLboolean)(target.blendColorMask & ColorMask::R), - (GLboolean)(target.blendColorMask & ColorMask::G), - (GLboolean)(target.blendColorMask & ColorMask::B), - (GLboolean)(target.blendColorMask & ColorMask::A)); - cache_target.blendColorMask = target.blendColorMask; - } - // bind shader resources - if (cmd->gpuBindingLayout && gpuPipelineState->gpuShader) { - for (size_t j = 0; j < cmd->gpuBindingLayout->gpuBindings.size(); ++j) { - const GLES3GPUBinding &gpuBinding = cmd->gpuBindingLayout->gpuBindings[j]; - switch (gpuBinding.type) { - case BindingType::UNIFORM_BUFFER: { - if (gpuBinding.gpuBuffer) { - for (size_t k = 0; k < gpuPipelineState->gpuShader->glBlocks.size(); ++k) { - const GLES3GPUUniformBlock &gpuBlock = gpuPipelineState->gpuShader->glBlocks[k]; - if ((gpuBlock.binding == gpuBinding.binding) && cache->glBindUBOs[gpuBlock.binding] != gpuBinding.gpuBuffer->glBuffer) { - glBindBufferBase(GL_UNIFORM_BUFFER, gpuBlock.binding, gpuBinding.gpuBuffer->glBuffer); - cache->glBindUBOs[gpuBlock.binding] = gpuBinding.gpuBuffer->glBuffer; - cache->glUniformBuffer = gpuBinding.gpuBuffer->glBuffer; - } + size_t samplerLen = gpuPipelineState->gpuShader->glSamplers.size(); + for (size_t j = 0; j < samplerLen; j++) { + const GLES3GPUUniformSampler &glSampler = gpuPipelineState->gpuShader->glSamplers[j]; + + CCASSERT(cmd->gpuDescriptorSets.size() > glSampler.set, "Invalid set index"); + const GLES3GPUDescriptorSet *gpuDescriptorSet = cmd->gpuDescriptorSets[glSampler.set]; + const GLES3GPUDescriptor &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[glSampler.binding]; + + if (!gpuDescriptor.gpuTexture || !gpuDescriptor.gpuSampler) { + CC_LOG_ERROR("Sampler binding '%s' at set %d binding %d is not bounded", + glSampler.name.c_str(), glSampler.set, glSampler.binding); + } + + for (size_t u = 0; u < glSampler.units.size(); ++u) { + uint unit = (uint)glSampler.units[u]; + + if (gpuDescriptor.gpuTexture->size > 0) { + GLuint glTexture = gpuDescriptor.gpuTexture->glTexture; + if (cache->glTextures[unit] != glTexture) { + if (cache->texUint != unit) { + glActiveTexture(GL_TEXTURE0 + unit); + cache->texUint = unit; } + glBindTexture(gpuDescriptor.gpuTexture->glTarget, glTexture); + cache->glTextures[unit] = glTexture; } - break; - } - case BindingType::SAMPLER: { - if (gpuBinding.gpuSampler) { - for (size_t k = 0; k < gpuPipelineState->gpuShader->glSamplers.size(); ++k) { - const GLES3GPUUniformSampler &gpuSampler = gpuPipelineState->gpuShader->glSamplers[k]; - if (gpuSampler.binding == gpuBinding.binding) { - for (size_t u = 0; u < gpuSampler.units.size(); ++u) { - uint unit = (uint)gpuSampler.units[u]; - - if (gpuBinding.gpuTexture && (gpuBinding.gpuTexture->size > 0)) { - GLuint glTexture = gpuBinding.gpuTexture->glTexture; - if (cache->glTextures[unit] != glTexture) { - if (cache->texUint != unit) { - glActiveTexture(GL_TEXTURE0 + unit); - cache->texUint = unit; - } - glBindTexture(gpuBinding.gpuTexture->glTarget, glTexture); - cache->glTextures[unit] = glTexture; - } - - if (cache->glSamplers[unit] != gpuBinding.gpuSampler->gl_sampler) { - glBindSampler(unit, gpuBinding.gpuSampler->gl_sampler); - cache->glSamplers[unit] = gpuBinding.gpuSampler->gl_sampler; - } - } - } - break; - } - } + + if (cache->glSamplers[unit] != gpuDescriptor.gpuSampler->glSampler) { + glBindSampler(unit, gpuDescriptor.gpuSampler->glSampler); + cache->glSamplers[unit] = gpuDescriptor.gpuSampler->glSampler; } - break; } - default: - break; } } } // if @@ -1824,17 +1853,17 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { for (uint c = 0; c < gpuAttribute.componentCount; ++c) { GLint glLoc = gpuInput.glLoc + c; - uint attrib_offset = gpuAttribute.offset + gpuAttribute.size * c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; glEnableVertexAttribArray(glLoc); cache->glEnabledAttribLocs[glLoc] = true; - glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attrib_offset)); + glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset)); glVertexAttribDivisor(glLoc, gpuAttribute.isInstanced ? 1 : 0); } break; } - } // for - } // for + } + } if (gpuInputAssembler->gpuIndexBuffer) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gpuInputAssembler->gpuIndexBuffer->glBuffer); @@ -1869,17 +1898,17 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { for (uint c = 0; c < gpuAttribute.componentCount; ++c) { GLint glLoc = gpuInput.glLoc + c; - uint attrib_offset = gpuAttribute.offset + gpuAttribute.size * c; + uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; glEnableVertexAttribArray(glLoc); cache->glCurrentAttribLocs[glLoc] = true; cache->glEnabledAttribLocs[glLoc] = true; - glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attrib_offset)); + glVertexAttribPointer(glLoc, gpuAttribute.count, gpuAttribute.glType, gpuAttribute.isNormalized, gpuAttribute.stride, BUFFER_OFFSET(attribOffset)); glVertexAttribDivisor(glLoc, gpuAttribute.isInstanced ? 1 : 0); } break; } - } // for - } // for + } + } if (gpuInputAssembler->gpuIndexBuffer) { if (cache->glElementArrayBuffer != gpuInputAssembler->gpuIndexBuffer->glBuffer) { @@ -1894,8 +1923,8 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { cache->glEnabledAttribLocs[a] = false; } } - } // if - } + } + } // if if (gpuPipelineState) { for (DynamicStateFlagBit dynamicState : gpuPipelineState->dynamicStates) { @@ -1949,23 +1978,23 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { case DynamicStateFlagBit::STENCIL_WRITE_MASK: switch (cmd->stencilWriteMask.face) { case StencilFace::FRONT: - if (cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.write_mask) { - glStencilMaskSeparate(GL_FRONT, cmd->stencilWriteMask.write_mask); - cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.write_mask; + if (cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.writeMask) { + glStencilMaskSeparate(GL_FRONT, cmd->stencilWriteMask.writeMask); + cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.writeMask; } break; case StencilFace::BACK: - if (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.write_mask) { - glStencilMaskSeparate(GL_BACK, cmd->stencilWriteMask.write_mask); - cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.write_mask; + if (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.writeMask) { + glStencilMaskSeparate(GL_BACK, cmd->stencilWriteMask.writeMask); + cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.writeMask; } break; case StencilFace::ALL: - if ((cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.write_mask) || - (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.write_mask)) { - glStencilMask(cmd->stencilWriteMask.write_mask); - cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.write_mask; - cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.write_mask; + if ((cache->dss.stencilWriteMaskFront != cmd->stencilWriteMask.writeMask) || + (cache->dss.stencilWriteMaskBack != cmd->stencilWriteMask.writeMask)) { + glStencilMask(cmd->stencilWriteMask.writeMask); + cache->dss.stencilWriteMaskFront = cmd->stencilWriteMask.writeMask; + cache->dss.stencilWriteMaskBack = cmd->stencilWriteMask.writeMask; } break; } @@ -2019,8 +2048,8 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { CC_LOG_ERROR("Invalid dynamic states."); break; } // switch - } // for - } // if + } + } break; } // case BIND_STATES case GFXCmdType::DRAW: { @@ -2072,7 +2101,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } case GFXCmdType::COPY_BUFFER_TO_TEXTURE: { GLES3CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; - GLES3CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions); + GLES3CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); break; } default: @@ -2082,7 +2111,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } } -void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList &buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { +void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { GLuint &glTexture = device->stateCache->glTextures[device->stateCache->texUint]; if (glTexture != gpuTexture->glTexture) { glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture); @@ -2096,7 +2125,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList case GL_TEXTURE_2D: { uint w; uint h; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; h = region.texExtent.height; @@ -2127,7 +2156,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList case GL_TEXTURE_2D_ARRAY: { uint w; uint h; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; uint d = region.texSubres.layerCount; uint layerCount = d + region.texSubres.baseArrayLayer; @@ -2166,7 +2195,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList uint w; uint h; uint d; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; h = region.texExtent.height; @@ -2201,10 +2230,10 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList uint w; uint h; uint f; - for (size_t i = 0; i < regions.size(); ++i) { + for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; - uint face_count = region.texSubres.baseArrayLayer + region.texSubres.layerCount; - for (f = region.texSubres.baseArrayLayer; f < face_count; ++f) { + uint faceCount = region.texSubres.baseArrayLayer + region.texSubres.layerCount; + for (f = region.texSubres.baseArrayLayer; f < faceCount; ++f) { w = region.texExtent.width; h = region.texExtent.height; const uint8_t *buff = buffers[n++]; diff --git a/cocos/renderer/gfx-gles3/GLES3Commands.h b/cocos/renderer/gfx-gles3/GLES3Commands.h index f6998f06f5d..8736e129f2b 100644 --- a/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -21,7 +21,7 @@ struct GLES3DepthBounds { struct GLES3StencilWriteMask { StencilFace face = StencilFace::FRONT; - uint write_mask = 0; + uint writeMask = 0; }; struct GLES3StencilCompareMask { @@ -79,8 +79,9 @@ enum class GLES3State : uint8_t { class GLES3CmdBindStates : public GFXCmd { public: GLES3GPUPipelineState *gpuPipelineState = nullptr; - GLES3GPUBindingLayout *gpuBindingLayout = nullptr; GLES3GPUInputAssembler *gpuInputAssembler = nullptr; + vector gpuDescriptorSets; + vector dynamicOffsets; uint8_t stateFlags[(int)GLES3State::COUNT] = {0}; Viewport viewport; Rect scissor; @@ -96,8 +97,9 @@ class GLES3CmdBindStates : public GFXCmd { virtual void clear() override { gpuPipelineState = nullptr; - gpuBindingLayout = nullptr; gpuInputAssembler = nullptr; + gpuDescriptorSets.clear(); + dynamicOffsets.clear(); memset(stateFlags, 0, sizeof(stateFlags)); } }; @@ -128,15 +130,17 @@ class GLES3CmdUpdateBuffer : public GFXCmd { class GLES3CmdCopyBufferToTexture : public GFXCmd { public: GLES3GPUTexture *gpuTexture = nullptr; - BufferDataList buffers; - BufferTextureCopyList regions; + const uint8_t *const *buffers = nullptr; + const BufferTextureCopy *regions = nullptr; + uint count = 0u; GLES3CmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {} virtual void clear() override { gpuTexture = nullptr; - buffers.clear(); - regions.clear(); + buffers = nullptr; + regions = nullptr; + count = 0u; } }; @@ -166,7 +170,7 @@ CC_GLES3_API void GLES3CmdFuncDestroyInputAssembler(GLES3Device *device, GLES3GP CC_GLES3_API void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); CC_GLES3_API void GLES3CmdFuncDestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); CC_GLES3_API void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmd_package); -CC_GLES3_API void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList &buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions); +CC_GLES3_API void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count); } // namespace gfx } // namespace cc diff --git a/cocos/renderer/gfx-gles3/GLES3Context.cc b/cocos/renderer/gfx-gles3/GLES3Context.cc index 24804e3480e..c5da9298ab4 100644 --- a/cocos/renderer/gfx-gles3/GLES3Context.cc +++ b/cocos/renderer/gfx-gles3/GLES3Context.cc @@ -17,39 +17,39 @@ namespace gfx { #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) void APIENTRY GLES3EGLDebugProc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { - String source_desc; + String sourceDesc; switch (source) { - case GL_DEBUG_SOURCE_API_KHR: source_desc = "API"; break; - case GL_DEBUG_SOURCE_SHADER_COMPILER_KHR: source_desc = "SHADER_COMPILER"; break; - case GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR: source_desc = "WINDOW_SYSTEM"; break; - case GL_DEBUG_SOURCE_THIRD_PARTY_KHR: source_desc = "THIRD_PARTY"; break; - case GL_DEBUG_SOURCE_APPLICATION_KHR: source_desc = "APPLICATION"; break; - default: source_desc = "OTHER"; + case GL_DEBUG_SOURCE_API_KHR: sourceDesc = "API"; break; + case GL_DEBUG_SOURCE_SHADER_COMPILER_KHR: sourceDesc = "SHADER_COMPILER"; break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR: sourceDesc = "WINDOW_SYSTEM"; break; + case GL_DEBUG_SOURCE_THIRD_PARTY_KHR: sourceDesc = "THIRD_PARTY"; break; + case GL_DEBUG_SOURCE_APPLICATION_KHR: sourceDesc = "APPLICATION"; break; + default: sourceDesc = "OTHER"; } - String type_desc; + String typeDesc; switch (severity) { - case GL_DEBUG_TYPE_ERROR_KHR: type_desc = "ERROR"; break; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR: type_desc = "PEPRECATED_BEHAVIOR"; break; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR: type_desc = "UNDEFINED_BEHAVIOR"; break; - case GL_DEBUG_TYPE_PERFORMANCE_KHR: type_desc = "PERFORMANCE"; break; - case GL_DEBUG_TYPE_PORTABILITY_KHR: type_desc = "PORTABILITY"; break; - case GL_DEBUG_TYPE_MARKER_KHR: type_desc = "MARKER"; break; - case GL_DEBUG_TYPE_PUSH_GROUP_KHR: type_desc = "PUSH_GROUP"; break; - case GL_DEBUG_TYPE_POP_GROUP_KHR: type_desc = "POP_GROUP"; break; - default: type_desc = "OTHER"; + case GL_DEBUG_TYPE_ERROR_KHR: typeDesc = "ERROR"; break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR: typeDesc = "PEPRECATED_BEHAVIOR"; break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR: typeDesc = "UNDEFINED_BEHAVIOR"; break; + case GL_DEBUG_TYPE_PERFORMANCE_KHR: typeDesc = "PERFORMANCE"; break; + case GL_DEBUG_TYPE_PORTABILITY_KHR: typeDesc = "PORTABILITY"; break; + case GL_DEBUG_TYPE_MARKER_KHR: typeDesc = "MARKER"; break; + case GL_DEBUG_TYPE_PUSH_GROUP_KHR: typeDesc = "PUSH_GROUP"; break; + case GL_DEBUG_TYPE_POP_GROUP_KHR: typeDesc = "POP_GROUP"; break; + default: typeDesc = "OTHER"; } - String severity_desc; + String severityDesc; switch (severity) { - case GL_DEBUG_SEVERITY_HIGH_KHR: severity_desc = "HIGH"; break; - case GL_DEBUG_SEVERITY_MEDIUM_KHR: severity_desc = "MEDIUM"; break; - case GL_DEBUG_SEVERITY_LOW_KHR: severity_desc = "LOW"; break; - default: severity_desc = "NOTIFICATION"; + case GL_DEBUG_SEVERITY_HIGH_KHR: severityDesc = "HIGH"; break; + case GL_DEBUG_SEVERITY_MEDIUM_KHR: severityDesc = "MEDIUM"; break; + case GL_DEBUG_SEVERITY_LOW_KHR: severityDesc = "LOW"; break; + default: severityDesc = "NOTIFICATION"; } String msg = StringUtil::Format("source: %s, type: %s, severity: %s, message: %s", - source_desc.c_str(), type_desc.c_str(), severity_desc.c_str(), message); + sourceDesc.c_str(), typeDesc.c_str(), severityDesc.c_str(), message); if (severity == GL_DEBUG_SEVERITY_HIGH_KHR) { #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) @@ -143,8 +143,8 @@ bool GLES3Context::initialize(const ContextInfo &info) { // advanced applications choose to do. For this application however, taking the first EGLConfig that the function returns suits // its needs perfectly, so we limit it to returning a single EGLConfig. - EGLint num_configs; - if (eglChooseConfig(_eglDisplay, attribs, &_eglConfig, 1, &num_configs) == EGL_FALSE || num_configs <= 0) { + EGLint numConfigs; + if (eglChooseConfig(_eglDisplay, attribs, &_eglConfig, 1, &numConfigs) == EGL_FALSE || numConfigs <= 0) { CC_LOG_ERROR("Choosing configuration failed."); return false; } @@ -180,15 +180,15 @@ bool GLES3Context::initialize(const ContextInfo &info) { * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ #if (CC_PLATFORM == CC_PLATFORM_ANDROID) - EGLint n_fmt; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &n_fmt) == EGL_FALSE) { + EGLint nFmt; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { CC_LOG_ERROR("Getting configuration attributes failed."); return false; } uint width = _device->getWidth(); uint height = _device->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, n_fmt); + ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); #endif _eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL); @@ -197,42 +197,42 @@ bool GLES3Context::initialize(const ContextInfo &info) { return false; } - //String egl_vendor = eglQueryString(_eglDisplay, EGL_VENDOR); - //String egl_version = eglQueryString(_eglDisplay, EGL_VERSION); + //String eglVendor = eglQueryString(_eglDisplay, EGL_VENDOR); + //String eglVersion = eglQueryString(_eglDisplay, EGL_VERSION); _extensions = StringUtil::Split((const char *)eglQueryString(_eglDisplay, EGL_EXTENSIONS), " "); _majorVersion = 3; _minorVersion = 0; - EGLint ctx_attribs[32]; + EGLint ctxAttribs[32]; uint n = 0; - bool has_khr_create_ctx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); - if (has_khr_create_ctx) { + bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); + if (hasKHRCreateCtx) { for (int m = 2; m >= 0; --m) { n = 0; - ctx_attribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; - ctx_attribs[n++] = _majorVersion; - ctx_attribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; - ctx_attribs[n++] = m; + ctxAttribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; + ctxAttribs[n++] = _majorVersion; + ctxAttribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; + ctxAttribs[n++] = m; #ifdef CC_GFX_DEBUG - ctx_attribs[n++] = EGL_CONTEXT_FLAGS_KHR; - ctx_attribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; + ctxAttribs[n++] = EGL_CONTEXT_FLAGS_KHR; + ctxAttribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; #endif - ctx_attribs[n] = EGL_NONE; + ctxAttribs[n] = EGL_NONE; - _eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctx_attribs); + _eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctxAttribs); if (_eglContext) { _minorVersion = m; break; } } } else { - ctx_attribs[n++] = EGL_CONTEXT_CLIENT_VERSION; - ctx_attribs[n++] = _majorVersion; - ctx_attribs[n] = EGL_NONE; - _eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctx_attribs); + ctxAttribs[n++] = EGL_CONTEXT_CLIENT_VERSION; + ctxAttribs[n++] = _majorVersion; + ctxAttribs[n] = EGL_NONE; + _eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctxAttribs); } if (!_eglContext) { @@ -253,7 +253,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { _colorFmt = sharedCtx->getColorFormat(); _depthStencilFmt = sharedCtx->getDepthStencilFormat(); - EGLint pbuff_attribs[] = + EGLint pbuffAttribs[] = { EGL_WIDTH, 2, EGL_HEIGHT, 2, @@ -262,7 +262,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { EGL_TEXTURE_TARGET, EGL_NO_TEXTURE, EGL_NONE}; - _eglSurface = eglCreatePbufferSurface(_eglDisplay, _eglConfig, pbuff_attribs); + _eglSurface = eglCreatePbufferSurface(_eglDisplay, _eglConfig, pbuffAttribs); if (_eglSurface == EGL_NO_SURFACE) { CC_LOG_ERROR("eglCreatePbufferSurface - FAILED"); return false; @@ -271,33 +271,33 @@ bool GLES3Context::initialize(const ContextInfo &info) { _majorVersion = 3; _minorVersion = sharedCtx->minor_ver(); - bool has_khr_create_ctx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); - if (!has_khr_create_ctx) { + bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); + if (!hasKHRCreateCtx) { CC_LOG_INFO("EGL context creation: EGL_KHR_create_context not supported. Minor version will be discarded, and debug disabled."); _minorVersion = 0; } - EGLint ctx_attribs[32]; + EGLint ctxAttribs[32]; uint n = 0; - if (has_khr_create_ctx) { - ctx_attribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; - ctx_attribs[n++] = _majorVersion; - ctx_attribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; - ctx_attribs[n++] = _minorVersion; + if (hasKHRCreateCtx) { + ctxAttribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; + ctxAttribs[n++] = _majorVersion; + ctxAttribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; + ctxAttribs[n++] = _minorVersion; #ifdef CC_GFX_DEBUG - ctx_attribs[n++] = EGL_CONTEXT_FLAGS_KHR; - ctx_attribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; + ctxAttribs[n++] = EGL_CONTEXT_FLAGS_KHR; + ctxAttribs[n++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; #endif } else { - ctx_attribs[n++] = EGL_CONTEXT_CLIENT_VERSION; - ctx_attribs[n++] = _majorVersion; + ctxAttribs[n++] = EGL_CONTEXT_CLIENT_VERSION; + ctxAttribs[n++] = _majorVersion; } - ctx_attribs[n] = EGL_NONE; + ctxAttribs[n] = EGL_NONE; - _eglContext = eglCreateContext(_eglDisplay, _eglConfig, _eglSharedContext, ctx_attribs); + _eglContext = eglCreateContext(_eglDisplay, _eglConfig, _eglSharedContext, ctxAttribs); if (!_eglContext) { CC_LOG_ERROR("Create EGL context with share context [0x%p] failed.", _eglSharedContext); return false; @@ -319,14 +319,14 @@ bool GLES3Context::initialize(const ContextInfo &info) { EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [=](const CustomEvent &event) -> void { _windowHandle = (uintptr_t)event.args->ptrVal; - EGLint n_fmt; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &n_fmt) == EGL_FALSE) { + EGLint nFmt; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { CC_LOG_ERROR("Getting configuration attributes failed."); return; } uint width = _device->getWidth(); uint height = _device->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, n_fmt); + ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); _eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL); if (_eglSurface == EGL_NO_SURFACE) { diff --git a/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cc b/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cc new file mode 100644 index 00000000000..dea7ef4cc5b --- /dev/null +++ b/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cc @@ -0,0 +1,74 @@ +#include "GLES3Std.h" + +#include "GLES3Buffer.h" +#include "GLES3Commands.h" +#include "GLES3DescriptorSet.h" +#include "GLES3Sampler.h" +#include "GLES3Texture.h" + +namespace cc { +namespace gfx { + +GLES3DescriptorSet::GLES3DescriptorSet(Device *device) +: DescriptorSet(device) { +} + +GLES3DescriptorSet::~GLES3DescriptorSet() { +} + +bool GLES3DescriptorSet::initialize(const DescriptorSetInfo &info) { + + _layout = info.layout; + + const DescriptorSetLayoutBindingList &bindings = _layout->getBindings(); + const size_t descriptorCount = bindings.size(); + + _buffers.resize(descriptorCount); + _textures.resize(descriptorCount); + _samplers.resize(descriptorCount); + + _gpuDescriptorSet = CC_NEW(GLES3GPUDescriptorSet); + _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); + for (size_t i = 0u; i < descriptorCount; i++) { + _gpuDescriptorSet->gpuDescriptors[i].type = bindings[i].descriptorType; + } + + _status = Status::SUCCESS; + + return true; +} + +void GLES3DescriptorSet::destroy() { + _layout = nullptr; + + if (_gpuDescriptorSet) { + CC_DELETE(_gpuDescriptorSet); + _gpuDescriptorSet = nullptr; + } + + _status = Status::UNREADY; +} + +void GLES3DescriptorSet::update() { + if (_isDirty && _gpuDescriptorSet) { + const DescriptorSetLayoutBindingList &bindings = _layout->getBindings(); + for (size_t i = 0; i < bindings.size(); i++) { + if ((uint)bindings[i].descriptorType & DESCRIPTOR_BUFFER_TYPE) { + if (_buffers[i]) { + _gpuDescriptorSet->gpuDescriptors[i].gpuBuffer = ((GLES3Buffer *)_buffers[i])->gpuBuffer(); + } + } else if ((uint)bindings[i].descriptorType & DESCRIPTOR_SAMPLER_TYPE) { + if (_textures[i]) { + _gpuDescriptorSet->gpuDescriptors[i].gpuTexture = ((GLES3Texture *)_textures[i])->gpuTexture(); + } + if (_samplers[i]) { + _gpuDescriptorSet->gpuDescriptors[i].gpuSampler = ((GLES3Sampler *)_samplers[i])->gpuSampler(); + } + } + } + _isDirty = false; + } +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-gles3/GLES3DescriptorSet.h b/cocos/renderer/gfx-gles3/GLES3DescriptorSet.h new file mode 100644 index 00000000000..9740a392383 --- /dev/null +++ b/cocos/renderer/gfx-gles3/GLES3DescriptorSet.h @@ -0,0 +1,28 @@ +#ifndef CC_GFXGLES3_GLES3_DESCRIPTOR_SET_H_ +#define CC_GFXGLES3_GLES3_DESCRIPTOR_SET_H_ + +namespace cc { +namespace gfx { + +class GLES3GPUDescriptorSet; + +class CC_GLES3_API GLES3DescriptorSet : public DescriptorSet { +public: + GLES3DescriptorSet(Device *device); + ~GLES3DescriptorSet(); + +public: + virtual bool initialize(const DescriptorSetInfo &info) override; + virtual void destroy() override; + virtual void update() override; + + CC_INLINE GLES3GPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } + +private: + GLES3GPUDescriptorSet *_gpuDescriptorSet = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXGLES3_GLES3_DESCRIPTOR_SET_H_ diff --git a/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cc b/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cc new file mode 100644 index 00000000000..3f511978026 --- /dev/null +++ b/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cc @@ -0,0 +1,47 @@ +#include "GLES3Std.h" + +#include "GLES3Commands.h" +#include "GLES3DescriptorSetLayout.h" + +namespace cc { +namespace gfx { + +GLES3DescriptorSetLayout::GLES3DescriptorSetLayout(Device *device) +: DescriptorSetLayout(device) { +} + +GLES3DescriptorSetLayout::~GLES3DescriptorSetLayout() { +} + +bool GLES3DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { + + _bindings = info.bindings; + + _gpuDescriptorSetLayout = CC_NEW(GLES3GPUDescriptorSetLayout); + + for (uint i = 0u; i < _bindings.size(); i++) { + const DescriptorSetLayoutBinding &binding = _bindings[i]; + if ((uint)binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { + for (uint j = 0u; j < binding.count; j++) { + _gpuDescriptorSetLayout->dynamicBindings.push_back(i); + } + } + _gpuDescriptorSetLayout->bindings.push_back(binding); + } + + _status = Status::SUCCESS; + + return true; +} + +void GLES3DescriptorSetLayout::destroy() { + if (_gpuDescriptorSetLayout) { + CC_DELETE(_gpuDescriptorSetLayout); + _gpuDescriptorSetLayout = nullptr; + } + + _status = Status::UNREADY; +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h b/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h new file mode 100644 index 00000000000..fd5f47a5ce4 --- /dev/null +++ b/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h @@ -0,0 +1,27 @@ +#ifndef CC_GFXGLES3_GLES3_DESCRIPTOR_SET_LAYOUT_H_ +#define CC_GFXGLES3_GLES3_DESCRIPTOR_SET_LAYOUT_H_ + +namespace cc { +namespace gfx { + +class GLES3GPUDescriptorSetLayout; + +class CC_GLES3_API GLES3DescriptorSetLayout : public DescriptorSetLayout { +public: + GLES3DescriptorSetLayout(Device *device); + ~GLES3DescriptorSetLayout(); + +public: + virtual bool initialize(const DescriptorSetLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE GLES3GPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } + +private: + GLES3GPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXGLES3_GLES3_DESCRIPTOR_SET_LAYOUT_H_ diff --git a/cocos/renderer/gfx-gles3/GLES3Device.cc b/cocos/renderer/gfx-gles3/GLES3Device.cc index cf8974d9d31..d3f4b3faa41 100644 --- a/cocos/renderer/gfx-gles3/GLES3Device.cc +++ b/cocos/renderer/gfx-gles3/GLES3Device.cc @@ -1,14 +1,16 @@ #include "GLES3Std.h" -#include "GLES3BindingLayout.h" #include "GLES3Buffer.h" #include "GLES3CommandAllocator.h" #include "GLES3CommandBuffer.h" #include "GLES3Context.h" +#include "GLES3DescriptorSet.h" +#include "GLES3DescriptorSetLayout.h" #include "GLES3Device.h" #include "GLES3Fence.h" #include "GLES3Framebuffer.h" #include "GLES3InputAssembler.h" +#include "GLES3PipelineLayout.h" #include "GLES3PipelineState.h" #include "GLES3Queue.h" #include "GLES3RenderPass.h" @@ -35,6 +37,14 @@ bool GLES3Device::initialize(const DeviceInfo &info) { _nativeHeight = info.nativeHeight; _windowHandle = info.windowHandle; + _bindingMappingInfo = info.bindingMappingInfo; + if (!_bindingMappingInfo.bufferOffsets.size()) { + _bindingMappingInfo.bufferOffsets.push_back(0); + } + if (!_bindingMappingInfo.samplerOffsets.size()) { + _bindingMappingInfo.samplerOffsets.push_back(0); + } + _cmdAllocator = CC_NEW(GLES3CommandAllocator); stateCache = CC_NEW(GLES3StateCache); @@ -125,6 +135,7 @@ bool GLES3Device::initialize(const DeviceInfo &info) { glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, (GLint *)&_maxVertexTextureUnits); glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&_maxTextureSize); glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint *)&_maxCubeMapTextureSize); + glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, (GLint *)&_uboOffsetAlignment); glGetIntegerv(GL_DEPTH_BITS, (GLint *)&_depthBits); glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_stencilBits); @@ -197,6 +208,15 @@ Buffer *GLES3Device::createBuffer(const BufferInfo &info) { return nullptr; } +Buffer *GLES3Device::createBuffer(const BufferViewInfo &info) { + Buffer *buffer = CC_NEW(GLES3Buffer(this)); + if (buffer->initialize(info)) + return buffer; + + CC_SAFE_DESTROY(buffer); + return nullptr; +} + Texture *GLES3Device::createTexture(const TextureInfo &info) { Texture *texture = CC_NEW(GLES3Texture(this)); if (texture->initialize(info)) @@ -260,12 +280,30 @@ Framebuffer *GLES3Device::createFramebuffer(const FramebufferInfo &info) { return nullptr; } -BindingLayout *GLES3Device::createBindingLayout(const BindingLayoutInfo &info) { - BindingLayout *bindingLayout = CC_NEW(GLES3BindingLayout(this)); - if (bindingLayout->initialize(info)) - return bindingLayout; +DescriptorSet *GLES3Device::createDescriptorSet(const DescriptorSetInfo &info) { + DescriptorSet *descriptorSet = CC_NEW(GLES3DescriptorSet(this)); + if (descriptorSet->initialize(info)) + return descriptorSet; + + CC_SAFE_DESTROY(descriptorSet); + return nullptr; +} + +DescriptorSetLayout *GLES3Device::createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) { + DescriptorSetLayout *descriptorSetLayout = CC_NEW(GLES3DescriptorSetLayout(this)); + if (descriptorSetLayout->initialize(info)) + return descriptorSetLayout; + + CC_SAFE_DESTROY(descriptorSetLayout); + return nullptr; +} + +PipelineLayout *GLES3Device::createPipelineLayout(const PipelineLayoutInfo &info) { + PipelineLayout *pipelineLayout = CC_NEW(GLES3PipelineLayout(this)); + if (pipelineLayout->initialize(info)) + return pipelineLayout; - CC_SAFE_DESTROY(bindingLayout); + CC_SAFE_DESTROY(pipelineLayout); return nullptr; } @@ -278,8 +316,8 @@ PipelineState *GLES3Device::createPipelineState(const PipelineStateInfo &info) { return nullptr; } -void GLES3Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - GLES3CmdFuncCopyBuffersToTexture(this, buffers, ((GLES3Texture *)dst)->gpuTexture(), regions); +void GLES3Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { + GLES3CmdFuncCopyBuffersToTexture(this, buffers, ((GLES3Texture *)dst)->gpuTexture(), regions, count); } } // namespace gfx diff --git a/cocos/renderer/gfx-gles3/GLES3Device.h b/cocos/renderer/gfx-gles3/GLES3Device.h index d5f000fb4b9..fd23a2d3dc9 100644 --- a/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/cocos/renderer/gfx-gles3/GLES3Device.h @@ -24,6 +24,7 @@ class CC_GLES3_API GLES3Device : public Device { virtual Fence *createFence(const FenceInfo &info) override; virtual Queue *createQueue(const QueueInfo &info) override; virtual Buffer *createBuffer(const BufferInfo &info) override; + virtual Buffer *createBuffer(const BufferViewInfo &info) override; virtual Texture *createTexture(const TextureInfo &info) override; virtual Texture *createTexture(const TextureViewInfo &info) override; virtual Sampler *createSampler(const SamplerInfo &info) override; @@ -31,11 +32,14 @@ class CC_GLES3_API GLES3Device : public Device { virtual InputAssembler *createInputAssembler(const InputAssemblerInfo &info) override; virtual RenderPass *createRenderPass(const RenderPassInfo &info) override; virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; - virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; + virtual DescriptorSet *createDescriptorSet(const DescriptorSetInfo &info) override; + virtual DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) override; + virtual PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; CC_INLINE GLES3CommandAllocator *cmdAllocator() const { return _cmdAllocator; } + CC_INLINE const BindingMappingInfo &bindingMappingInfo() const { return _bindingMappingInfo; } CC_INLINE bool checkExtension(const String &extension) const { for (size_t i = 0; i < _extensions.size(); ++i) { @@ -47,6 +51,7 @@ class CC_GLES3_API GLES3Device : public Device { } private: + BindingMappingInfo _bindingMappingInfo; GLES3CommandAllocator *_cmdAllocator = nullptr; StringArray _extensions; }; diff --git a/cocos/renderer/gfx-gles3/GLES3Framebuffer.cc b/cocos/renderer/gfx-gles3/GLES3Framebuffer.cc index aed78b066e1..0eef2fde799 100644 --- a/cocos/renderer/gfx-gles3/GLES3Framebuffer.cc +++ b/cocos/renderer/gfx-gles3/GLES3Framebuffer.cc @@ -23,7 +23,9 @@ bool GLES3Framebuffer::initialize(const FramebufferInfo &info) { _gpuFBO = CC_NEW(GLES3GPUFramebuffer); _gpuFBO->gpuRenderPass = ((GLES3RenderPass *)_renderPass)->gpuRenderPass(); _gpuFBO->depthStencilMipmapLevel = info.depthStencilMipmapLevel; - _gpuFBO->colorMipmapLevels = info.colorMipmapLevels; + for (uint mipLevel : info.colorMipmapLevels) { + _gpuFBO->colorMipmapLevels.push_back(mipLevel); + } _gpuFBO->gpuColorTextures.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { diff --git a/cocos/renderer/gfx-gles3/GLES3GPUObjects.h b/cocos/renderer/gfx-gles3/GLES3GPUObjects.h index 7439f394651..028f83f790c 100644 --- a/cocos/renderer/gfx-gles3/GLES3GPUObjects.h +++ b/cocos/renderer/gfx-gles3/GLES3GPUObjects.h @@ -15,6 +15,7 @@ class GLES3GPUBuffer : public Object { uint count = 0; GLenum glTarget = 0; GLuint glBuffer = 0; + GLuint glOffset = 0; uint8_t *buffer = nullptr; DrawInfoList indirects; }; @@ -58,7 +59,7 @@ class GLES3GPUSampler : public Object { Address addressW = Address::CLAMP; uint minLOD = 0; uint maxLOD = 1000; - GLuint gl_sampler = 0; + GLuint glSampler = 0; GLenum glMinFilter = 0; GLenum glMagFilter = 0; GLenum glWrapS = 0; @@ -92,16 +93,19 @@ struct GLES3GPUUniform { typedef vector GLES3GPUUniformList; struct GLES3GPUUniformBlock { - uint binding = 0; + uint set = GFX_INVALID_BINDING; + uint binding = GFX_INVALID_BINDING; uint idx = 0; String name; uint size = 0; + uint glBinding = GFX_INVALID_BINDING; GLES3GPUUniformList glUniforms; GLES3GPUUniformList glActiveUniforms; }; typedef vector GLES3GPUUniformBlockList; struct GLES3GPUUniformSampler { + uint set = 0; uint binding = 0; String name; Type type = Type::UNKNOWN; @@ -112,11 +116,10 @@ struct GLES3GPUUniformSampler { typedef vector GLES3GPUUniformSamplerList; struct GLES3GPUShaderStage { - GLES3GPUShaderStage(ShaderType t, String s, ShaderMacroList m, GLuint shader = 0) - : type(t), source(s), macros(m), glShader(shader) {} - ShaderType type; + GLES3GPUShaderStage(ShaderStageFlagBit t, String s, GLuint shader = 0) + : type(t), source(s), glShader(shader) {} + ShaderStageFlagBit type; String source; - ShaderMacroList macros; GLuint glShader = 0; }; typedef vector GLES3GPUShaderStageList; @@ -175,8 +178,19 @@ class GLES3GPUFramebuffer : public Object { bool isOffscreen = false; }; +class GLES3GPUDescriptorSetLayout : public Object { +public: + DescriptorSetLayoutBindingList bindings; + vector dynamicBindings; +}; +typedef vector GLES3GPUDescriptorSetLayoutList; + class GLES3GPUPipelineLayout : public Object { public: + GLES3GPUDescriptorSetLayoutList setLayouts; + vector> dynamicOffsetIndices; + vector dynamicOffsetOffsets; + uint dynamicOffsetCount; }; class GLES3GPUPipelineState : public Object { @@ -189,21 +203,20 @@ class GLES3GPUPipelineState : public Object { DynamicStateList dynamicStates; GLES3GPUPipelineLayout *gpuLayout = nullptr; GLES3GPURenderPass *gpuRenderPass = nullptr; + GLES3GPUPipelineLayout *gpuPipelineLayout = nullptr; }; -struct GLES3GPUBinding { - uint binding = GFX_INVALID_BINDING; - BindingType type = BindingType::UNKNOWN; - String name; +struct GLES3GPUDescriptor { + DescriptorType type = DescriptorType::UNKNOWN; GLES3GPUBuffer *gpuBuffer = nullptr; GLES3GPUTexture *gpuTexture = nullptr; GLES3GPUSampler *gpuSampler = nullptr; }; -typedef vector GLES3GPUBindingList; +typedef vector GLES3GPUDescriptorList; -class GLES3GPUBindingLayout : public Object { +class GLES3GPUDescriptorSet : public Object { public: - GLES3GPUBindingList gpuBindings; + GLES3GPUDescriptorList gpuDescriptors; }; class GLES3GPUFence : public Object { diff --git a/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cc b/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cc new file mode 100644 index 00000000000..515b9e8190f --- /dev/null +++ b/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cc @@ -0,0 +1,61 @@ +#include "GLES3Std.h" + +#include "GLES3Commands.h" +#include "GLES3DescriptorSetLayout.h" +#include "GLES3PipelineLayout.h" + +namespace cc { +namespace gfx { + +GLES3PipelineLayout::GLES3PipelineLayout(Device *device) +: PipelineLayout(device) { +} + +GLES3PipelineLayout::~GLES3PipelineLayout() { +} + +bool GLES3PipelineLayout::initialize(const PipelineLayoutInfo &info) { + + _setLayouts = info.setLayouts; + + _gpuPipelineLayout = CC_NEW(GLES3GPUPipelineLayout); + + int offset = 0u; + _gpuPipelineLayout->dynamicOffsetIndices.resize(_setLayouts.size()); + for (uint i = 0u; i < _setLayouts.size(); i++) { + DescriptorSetLayout *setLayout = _setLayouts[i]; + GLES3GPUDescriptorSetLayout *gpuSetLayout = ((GLES3DescriptorSetLayout *)setLayout)->gpuDescriptorSetLayout(); + size_t bindingCount = gpuSetLayout->bindings.size(); + size_t dynamicCount = gpuSetLayout->dynamicBindings.size(); + + vector &indices = _gpuPipelineLayout->dynamicOffsetIndices[i]; + indices.assign(bindingCount, -1); + + for (uint j = 0u; j < dynamicCount; j++) { + uint binding = gpuSetLayout->dynamicBindings[j]; + if (indices[binding] < 0) indices[binding] = offset + j; + } + _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); + _gpuPipelineLayout->setLayouts.push_back(gpuSetLayout); + offset += dynamicCount; + } + _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); + _gpuPipelineLayout->dynamicOffsetCount = offset; + + _status = Status::SUCCESS; + + return true; +} + +void GLES3PipelineLayout::destroy() { + + if (_gpuPipelineLayout) { + CC_DELETE(_gpuPipelineLayout); + _gpuPipelineLayout = nullptr; + } + + _status = Status::UNREADY; +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-gles3/GLES3PipelineLayout.h b/cocos/renderer/gfx-gles3/GLES3PipelineLayout.h new file mode 100644 index 00000000000..906cf720dc4 --- /dev/null +++ b/cocos/renderer/gfx-gles3/GLES3PipelineLayout.h @@ -0,0 +1,27 @@ +#ifndef CC_GFXGLES3_GLES3_PIPELINE_LAYOUT_H_ +#define CC_GFXGLES3_GLES3_PIPELINE_LAYOUT_H_ + +namespace cc { +namespace gfx { + +class GLES3GPUPipelineLayout; + +class CC_GLES3_API GLES3PipelineLayout : public PipelineLayout { +public: + GLES3PipelineLayout(Device *device); + ~GLES3PipelineLayout(); + +public: + virtual bool initialize(const PipelineLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE GLES3GPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } + +private: + GLES3GPUPipelineLayout *_gpuPipelineLayout = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXGLES3_GLES3_PIPELINE_LAYOUT_H_ diff --git a/cocos/renderer/gfx-gles3/GLES3PipelineState.cc b/cocos/renderer/gfx-gles3/GLES3PipelineState.cc index 8989b29725e..5be9ff8015d 100644 --- a/cocos/renderer/gfx-gles3/GLES3PipelineState.cc +++ b/cocos/renderer/gfx-gles3/GLES3PipelineState.cc @@ -1,8 +1,10 @@ #include "GLES3Std.h" -#include "GLES3PipelineState.h" + #include "GLES3Commands.h" -#include "GLES3Shader.h" +#include "GLES3PipelineState.h" +#include "GLES3PipelineLayout.h" #include "GLES3RenderPass.h" +#include "GLES3Shader.h" namespace cc { namespace gfx { @@ -41,6 +43,7 @@ bool GLES3PipelineState::initialize(const PipelineStateInfo &info) { _blendState = info.blendState; _dynamicStates = info.dynamicStates; _renderPass = info.renderPass; + _pipelineLayout = info.pipelineLayout; _gpuPipelineState = CC_NEW(GLES3GPUPipelineState); _gpuPipelineState->glPrimitive = GLES3Primitives[(int)_primitive]; @@ -49,6 +52,7 @@ bool GLES3PipelineState::initialize(const PipelineStateInfo &info) { _gpuPipelineState->dss = _depthStencilState; _gpuPipelineState->bs = _blendState; _gpuPipelineState->gpuRenderPass = ((GLES3RenderPass *)_renderPass)->gpuRenderPass(); + _gpuPipelineState->gpuPipelineLayout = ((GLES3PipelineLayout *)_pipelineLayout)->gpuPipelineLayout(); for (uint i = 0; i < 31; i++) { if ((uint)_dynamicStates & (1 << i)) { diff --git a/cocos/renderer/gfx-gles3/GLES3Shader.cc b/cocos/renderer/gfx-gles3/GLES3Shader.cc index 43d4f4ab58f..3bf60f92971 100644 --- a/cocos/renderer/gfx-gles3/GLES3Shader.cc +++ b/cocos/renderer/gfx-gles3/GLES3Shader.cc @@ -24,7 +24,7 @@ bool GLES3Shader::initialize(const ShaderInfo &info) { _gpuShader->blocks = _blocks; _gpuShader->samplers = _samplers; for (const auto &stage : _stages) { - GLES3GPUShaderStage gpuShaderStage = {stage.type, stage.source, stage.macros, 0}; + GLES3GPUShaderStage gpuShaderStage = {stage.stage, stage.source}; _gpuShader->gpuStages.emplace_back(std::move(gpuShaderStage)); } diff --git a/cocos/renderer/gfx-gles3/GLES3Texture.cc b/cocos/renderer/gfx-gles3/GLES3Texture.cc index 7d261205080..898a3a122e1 100644 --- a/cocos/renderer/gfx-gles3/GLES3Texture.cc +++ b/cocos/renderer/gfx-gles3/GLES3Texture.cc @@ -97,7 +97,8 @@ bool GLES3Texture::initialize(const TextureInfo &info) { } bool GLES3Texture::initialize(const TextureViewInfo &info) { - _Type = ObjectType::TEXTURE_VIEW; + _isTextureView = true; + CC_LOG_ERROR("GLES3 doesn't support texture view."); _status = Status::FAILED; return false; diff --git a/cocos/renderer/gfx-metal/CMakeLists.txt b/cocos/renderer/gfx-metal/CMakeLists.txt index 00a41e694ba..ba458819d56 100644 --- a/cocos/renderer/gfx-metal/CMakeLists.txt +++ b/cocos/renderer/gfx-metal/CMakeLists.txt @@ -33,7 +33,7 @@ endif() target_compile_definitions(${TARGET_NAME} PRIVATE USE_METAL) find_library(METAL_LIBRARY Metal) find_library(METALKIT_LIBRARY MetalKit) -set(glslang_libs_name glslang OGLCompiler OSDependent SPIRV) +set(glslang_libs_name glslang OGLCompiler OSDependent SPIRV glslang-default-resource-limits) set(spirv-cross_libs_name spirv-cross-core spirv-cross-glsl spirv-cross-msl) target_link_libraries(${TARGET_NAME} Core ${METAL_LIBRARY} ${METALKIT_LIBRARY} ${glslang_libs_name} ${spirv-cross_libs_name}) target_include_directories(${TARGET_NAME} PUBLIC ${COCOS_EXTERNAL_PATH}/mac/include) diff --git a/cocos/renderer/gfx-metal/MTLBindingLayout.cpp b/cocos/renderer/gfx-metal/MTLBindingLayout.cpp deleted file mode 100644 index ed2c22c64d9..00000000000 --- a/cocos/renderer/gfx-metal/MTLBindingLayout.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "MTLStd.h" -#include "MTLBindingLayout.h" - -namespace cc { -namespace gfx { - -CCMTLBindingLayout::CCMTLBindingLayout(Device *device) : BindingLayout(device) {} -CCMTLBindingLayout::~CCMTLBindingLayout() { destroy(); } - -bool CCMTLBindingLayout::initialize(const BindingLayoutInfo &info) { - - const UniformBlockList &blocks = info.shader->getBlocks(); - const UniformSamplerList &samplers = info.shader->getSamplers(); - const uint bindingCount = blocks.size() + samplers.size(); - - if (bindingCount) { - _bindingUnits.resize(bindingCount); - for (size_t i = 0u; i < blocks.size(); ++i) { - const UniformBlock &binding = blocks[i]; - BindingUnit &bindingUnit = _bindingUnits[i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::UNIFORM_BUFFER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = 1; - } - for (size_t i = 0u; i < samplers.size(); ++i) { - const UniformSampler &binding = samplers[i]; - BindingUnit &bindingUnit = _bindingUnits[blocks.size() + i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::SAMPLER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = binding.count; - } - } - - _status = Status::SUCCESS; - return true; -} - -void CCMTLBindingLayout::destroy() { - _status = Status::UNREADY; -} - -void CCMTLBindingLayout::update() { -} - -} // namespace gfx -} // namespace cc diff --git a/cocos/renderer/gfx-metal/MTLBindingLayout.h b/cocos/renderer/gfx-metal/MTLBindingLayout.h deleted file mode 100644 index 27d2fa671c4..00000000000 --- a/cocos/renderer/gfx-metal/MTLBindingLayout.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -namespace cc { -namespace gfx { - -class CCMTLBindingLayout : public BindingLayout { -public: - CCMTLBindingLayout(Device *device); - virtual ~CCMTLBindingLayout(); - - virtual bool initialize(const BindingLayoutInfo &info) override; - virtual void destroy() override; - virtual void update() override; -}; - -} // namespace gfx -} // namespace cc diff --git a/cocos/renderer/gfx-metal/MTLBuffer.h b/cocos/renderer/gfx-metal/MTLBuffer.h index d2f2046b886..a52225adeb7 100644 --- a/cocos/renderer/gfx-metal/MTLBuffer.h +++ b/cocos/renderer/gfx-metal/MTLBuffer.h @@ -13,6 +13,7 @@ class CCMTLBuffer : public Buffer { ~CCMTLBuffer(); virtual bool initialize(const BufferInfo &info) override; + virtual bool initialize(const BufferViewInfo &info) override; virtual void destroy() override; virtual void resize(uint size) override; virtual void update(void *buffer, uint offset, uint size) override; @@ -21,7 +22,7 @@ class CCMTLBuffer : public Buffer { CC_INLINE uint8_t *getTransferBuffer() const { return _transferBuffer; } CC_INLINE MTLIndexType getIndexType() const { return _indexType; } CC_INLINE bool isDrawIndirectByIndex() const { return _isDrawIndirectByIndex; } - void encodeBuffer(id encoder, uint offset, uint binding, ShaderType stages); + void encodeBuffer(id encoder, uint offset, uint binding, ShaderStageFlags stages); private: void resizeBuffer(uint8_t **, uint, uint); diff --git a/cocos/renderer/gfx-metal/MTLBuffer.mm b/cocos/renderer/gfx-metal/MTLBuffer.mm index 43b6f658ef3..11a1d72d7c3 100644 --- a/cocos/renderer/gfx-metal/MTLBuffer.mm +++ b/cocos/renderer/gfx-metal/MTLBuffer.mm @@ -78,6 +78,11 @@ return true; } +bool CCMTLBuffer::initialize(const BufferViewInfo &info) { + *this = *static_cast(info.buffer); + return true; +} + bool CCMTLBuffer::createMTLBuffer(uint size, MemoryUsage usage) { if (_mtlBuffer) [_mtlBuffer release]; @@ -94,6 +99,11 @@ } void CCMTLBuffer::destroy() { + if(_isBufferView) { + _status = Status::UNREADY; + return; + } + if (_mtlBuffer) { [_mtlBuffer release]; _mtlBuffer = nil; @@ -120,6 +130,11 @@ } void CCMTLBuffer::resize(uint size) { + if(_isBufferView) { + CC_LOG_WARNING("Cannot resize a buffer view."); + return; + } + if (_size == size) return; @@ -173,6 +188,10 @@ } void CCMTLBuffer::update(void *buffer, uint offset, uint size) { + if(_isBufferView) { + CC_LOG_WARNING("Cannot update a buffer view."); + return; + } if (_buffer) memcpy(_buffer + offset, buffer, size); @@ -229,13 +248,13 @@ } } -void CCMTLBuffer::encodeBuffer(id encoder, uint offset, uint binding, ShaderType stages) { +void CCMTLBuffer::encodeBuffer(id encoder, uint offset, uint binding, ShaderStageFlags stages) { if (encoder == nil) { CC_LOG_ERROR("CCMTLBuffer::encodeBuffer: MTLRenderCommandEncoder should not be nil."); return; } - if (stages & ShaderType::VERTEX) { + if (stages & ShaderStageFlagBit::VERTEX) { if (_useOptimizedBufferEncoder) { [encoder setVertexBytes:_bufferBytes length:_size @@ -247,7 +266,7 @@ } } - if (stages & ShaderType::FRAGMENT) { + if (stages & ShaderStageFlagBit::FRAGMENT) { if (_useOptimizedBufferEncoder) { [encoder setFragmentBytes:_bufferBytes length:_size diff --git a/cocos/renderer/gfx-metal/MTLCommandBuffer.h b/cocos/renderer/gfx-metal/MTLCommandBuffer.h index 4082af9970c..ea981f34fbb 100644 --- a/cocos/renderer/gfx-metal/MTLCommandBuffer.h +++ b/cocos/renderer/gfx-metal/MTLCommandBuffer.h @@ -24,23 +24,23 @@ class CCMTLCommandBuffer : public CommandBuffer { virtual void destroy() override; virtual void begin(RenderPass *renderPass = nullptr, uint subpass = 0, Framebuffer *frameBuffer = nullptr) override; virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector &colors, float depth, int stencil) override; + virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) override; virtual void endRenderPass() override; virtual void bindPipelineState(PipelineState *pso) override; - virtual void bindBindingLayout(BindingLayout *layout) override; + virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; virtual void bindInputAssembler(InputAssembler *ia) override; virtual void setViewport(const Viewport &vp) override; virtual void setScissor(const Rect &rect) override; virtual void setLineWidth(const float width) override; virtual void setDepthBias(float constant, float clamp, float slope) override; virtual void setBlendConstants(const Color &constants) override; - virtual void setDepthBound(float min_bounds, float max_bounds) override; + virtual void setDepthBound(float minBounds, float maxBounds) override; virtual void setStencilWriteMask(StencilFace face, uint mask) override; virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; virtual void draw(InputAssembler *ia) override; virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset = 0) override; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override; - virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; + virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) override; private: void bindStates(); @@ -53,6 +53,9 @@ class CCMTLCommandBuffer : public CommandBuffer { CCMTLDepthBias _depthBias; CCMTLDepthBounds _depthBounds; Color _blendConstants; + + vector _GPUDescriptorSets; + vector> _dynamicOffsets; MTKView *_mtkView = nil; id _mtlCommandBuffer = nil; diff --git a/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index e6ee071e650..aaaa7322da6 100644 --- a/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -1,6 +1,5 @@ #include "MTLStd.h" -#include "MTLBindingLayout.h" #include "MTLBuffer.h" #include "MTLCommandBuffer.h" #include "MTLCommands.h" @@ -13,6 +12,7 @@ #include "MTLShader.h" #include "MTLTexture.h" #include "MTLUtils.h" +#include "MTLDescriptorSet.h" namespace cc { namespace gfx { @@ -48,6 +48,11 @@ _numDrawCalls = 0; _gpuIndexBuffer = {0, 0, 0}; _gpuIndirectBuffer = {0, 0, 0}; + + _GPUDescriptorSets.assign(_GPUDescriptorSets.size(),nullptr); + for(auto & dynamicOffset : _dynamicOffsets) { + dynamicOffset.clear(); + } } void CCMTLCommandBuffer::end() { @@ -97,41 +102,70 @@ backReferenceValue:_gpuPipelineState->stencilRefBack]; [_mtlEncoder setDepthStencilState:_gpuPipelineState->mtlDepthStencilState]; } + + _GPUDescriptorSets.resize(_gpuPipelineState->gpuPipelineLayout->setLayouts.size()); } -void CCMTLCommandBuffer::bindBindingLayout(BindingLayout *layout) { - const auto *bindingLayout = static_cast(layout); - - for (const auto &binding : bindingLayout->getBindingUnits()) { - if (binding.buffer) - static_cast(binding.buffer)->encodeBuffer(_mtlEncoder, 0, binding.binding, binding.shaderStages); - - if (binding.shaderStages & ShaderType::VERTEX) { - if (binding.texture) - [_mtlEncoder setVertexTexture:static_cast(binding.texture)->getMTLTexture() - atIndex:binding.binding]; - - if (binding.sampler) - [_mtlEncoder setVertexSamplerState:static_cast(binding.sampler)->getMTLSamplerState() - atIndex:_gpuPipelineState->vertexSamplerBinding.at(binding.binding)]; - } - - if (binding.shaderStages & ShaderType::FRAGMENT) { - if (binding.sampler && binding.texture) { -#if COCOS2D_DEBUG > 0 - if (_gpuPipelineState->fragmentSamplerBinding.find(binding.binding) == _gpuPipelineState->fragmentSamplerBinding.end()) { - CC_LOG_WARNING("%s(binding = %d) not used in shader.", binding.name.c_str(), binding.binding); - continue; - } -#endif - [_mtlEncoder setFragmentTexture:static_cast(binding.texture)->getMTLTexture() - atIndex:binding.binding]; - - [_mtlEncoder setFragmentSamplerState:static_cast(binding.sampler)->getMTLSamplerState() - atIndex:_gpuPipelineState->fragmentSamplerBinding.at(binding.binding)]; +void CCMTLCommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { + _GPUDescriptorSets[set] = static_cast(descriptorSet)->gpuDescriptorSet(); +// const auto *bindingLayout = static_cast(layout); + const auto &blocks = _gpuPipelineState->gpuShader->getBlocks(); + auto blockCount = blocks.size(); + const auto &dynamicOffsetIndices = _gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices; + for (size_t i = 0; i < blockCount; i++) { + const auto &block = blocks[i]; + CCASSERT(_GPUDescriptorSets.size() > block.set, "Invalid block set value"); + + const auto gpuDescriptorSet = _GPUDescriptorSets[block.set]; + CCASSERT(gpuDescriptorSet && gpuDescriptorSet->gpuDescriptors.size() > block.binding, "Invalid block binding value"); + + const auto &gpuDescriptor = gpuDescriptorSet->gpuDescriptors[block.binding]; + CCASSERT(gpuDescriptor.buffer, "Buffer not bounded."); + + int dynamicOffsetIndex = -1; + if(dynamicOffsetIndices.size() > block.set) { + const auto &dynamicOffsetIndexSet = dynamicOffsetIndices[block.set]; + if(dynamicOffsetIndices.size() > block.binding) { + dynamicOffsetIndex = dynamicOffsetIndexSet[block.binding]; } } + + if(dynamicOffsetIndex >= 0) { //dynamiclly bound + + } else { +// gpuDescriptor.buffer->encodeBuffer(_mtlEncoder, 0, block.binding, <#ShaderStageFlags stages#>); + } } +// for (const auto &binding : bindingLayout->getBindingUnits()) { +// if (binding.buffer) +// static_cast(binding.buffer)->encodeBuffer(_mtlEncoder, 0, binding.binding, binding.shaderStages); +// +// if (binding.shaderStages & ShaderStageFlagBit::VERTEX) { +// if (binding.texture) +// [_mtlEncoder setVertexTexture:static_cast(binding.texture)->getMTLTexture() +// atIndex:binding.binding]; +// +// if (binding.sampler) +// [_mtlEncoder setVertexSamplerState:static_cast(binding.sampler)->getMTLSamplerState() +// atIndex:_gpuPipelineState->vertexSamplerBinding.at(binding.binding)]; +// } +// +// if (binding.shaderStages & ShaderStageFlagBit::FRAGMENT) { +// if (binding.sampler && binding.texture) { +//#if COCOS2D_DEBUG > 0 +// if (_gpuPipelineState->fragmentSamplerBinding.find(binding.binding) == _gpuPipelineState->fragmentSamplerBinding.end()) { +// CC_LOG_WARNING("%s(binding = %d) not used in shader.", binding.name.c_str(), binding.binding); +// continue; +// } +//#endif +// [_mtlEncoder setFragmentTexture:static_cast(binding.texture)->getMTLTexture() +// atIndex:binding.binding]; +// +// [_mtlEncoder setFragmentSamplerState:static_cast(binding.sampler)->getMTLSamplerState() +// atIndex:_gpuPipelineState->fragmentSamplerBinding.at(binding.binding)]; +// } +// } +// } } void CCMTLCommandBuffer::bindInputAssembler(InputAssembler *ia) { @@ -151,7 +185,7 @@ for (const auto &bindingInfo : _gpuPipelineState->vertexBufferBindingInfo) { auto index = std::get<0>(bindingInfo); auto stream = std::get<1>(bindingInfo); - static_cast(vertexBuffers[stream])->encodeBuffer(_mtlEncoder, 0, index, ShaderType::VERTEX); + static_cast(vertexBuffers[stream])->encodeBuffer(_mtlEncoder, 0, index, ShaderStageFlagBit::VERTEX); } } } @@ -218,6 +252,8 @@ } void CCMTLCommandBuffer::draw(InputAssembler *ia) { + // + if (_type == CommandBufferType::PRIMARY) { if (_gpuIndirectBuffer.count) { for (size_t j = 0; j < _gpuIndirectBuffer.count; j++) { @@ -288,11 +324,11 @@ } } -void CCMTLCommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { +void CCMTLCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { if ((_type == CommandBufferType::PRIMARY) || (_type == CommandBufferType::SECONDARY)) { if (texture) { - static_cast(texture)->update(buffers.data(), regions); + static_cast(texture)->update(buffers, regions, count); } else { CC_LOG_ERROR("CCMTLCommandBuffer::copyBufferToTexture: texture is nullptr"); } @@ -301,7 +337,7 @@ } } -void CCMTLCommandBuffer::execute(const CommandBufferList &commandBuffs, uint32_t count) { +void CCMTLCommandBuffer::execute(const CommandBuffer *const *commandBuffs, uint32_t count) { for (uint i = 0; i < count; ++i) { auto commandBuffer = static_cast(commandBuffs[i]); _numDrawCalls += commandBuffer->_numDrawCalls; diff --git a/cocos/renderer/gfx-metal/MTLDescriptorSet.h b/cocos/renderer/gfx-metal/MTLDescriptorSet.h new file mode 100644 index 00000000000..e65c5f241fb --- /dev/null +++ b/cocos/renderer/gfx-metal/MTLDescriptorSet.h @@ -0,0 +1,21 @@ +#pragma once +namespace cc { +namespace gfx { +class CCMTLGPUDescriptorSet; + +class CCMTLDescriptorSet : public DescriptorSet { +public: + CCMTLDescriptorSet(Device *device); + ~CCMTLDescriptorSet(); + + virtual bool initialize(const DescriptorSetInfo &info) override; + virtual void destroy() override; + virtual void update() override; + + CC_INLINE CCMTLGPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } +private: + + CCMTLGPUDescriptorSet *_gpuDescriptorSet = nullptr; +}; +} +} diff --git a/cocos/renderer/gfx-metal/MTLDescriptorSet.mm b/cocos/renderer/gfx-metal/MTLDescriptorSet.mm new file mode 100644 index 00000000000..a43d3522795 --- /dev/null +++ b/cocos/renderer/gfx-metal/MTLDescriptorSet.mm @@ -0,0 +1,64 @@ +#include "MTLStd.h" + +#include "MTLDescriptorSet.h" +#include "MTLGPUObjects.h" +#include "MTLTexture.h" +#include "MTLSampler.h" +#include "MTLBuffer.h" + +namespace cc { +namespace gfx { +CCMTLDescriptorSet::CCMTLDescriptorSet(Device *device) : DescriptorSet(device){ + +} +CCMTLDescriptorSet::~CCMTLDescriptorSet() { + destroy(); +} + +bool CCMTLDescriptorSet::initialize(const DescriptorSetInfo &info) { + _layout = info.layout; + + const auto &bindings = _layout->getBindings(); + const auto descriptorCount = bindings.size(); + + _buffers.resize(descriptorCount); + _textures.resize(descriptorCount); + _samplers.resize(descriptorCount); + + _gpuDescriptorSet = CC_NEW(CCMTLGPUDescriptorSet); + _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); + for (size_t i = 0; i < descriptorCount; i++) { + _gpuDescriptorSet->gpuDescriptors[i].type = bindings[i].descriptorType; + } + + _status = Status::SUCCESS; + return true; +} +void CCMTLDescriptorSet::destroy() { + _layout = nullptr; + CC_SAFE_DELETE(_gpuDescriptorSet); + _status = Status::UNREADY; +} + +void CCMTLDescriptorSet::update() { + if (_isDirty && _gpuDescriptorSet) { + const auto &bindings = _layout->getBindings(); + for (size_t i = 0; i < bindings.size(); i++) { + if (static_cast(bindings[i].descriptorType) & DESCRIPTOR_BUFFER_TYPE) { + if (_buffers[i]) { + _gpuDescriptorSet->gpuDescriptors[i].buffer = static_cast(_buffers[i]); + } + } else if (static_cast(bindings[i].descriptorType) & DESCRIPTOR_SAMPLER_TYPE) { + if (_textures[i]) { + _gpuDescriptorSet->gpuDescriptors[i].texture = static_cast(_textures[i]); + } + if (_samplers[i]) { + _gpuDescriptorSet->gpuDescriptors[i].sampler = static_cast(_samplers[i]); + } + } + } + _isDirty = false; + } +} +} +} diff --git a/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h b/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h new file mode 100644 index 00000000000..974e87cd294 --- /dev/null +++ b/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h @@ -0,0 +1,19 @@ +#pragma once +namespace cc { +namespace gfx { +class CCMTLGPUDescriptorSetLayout; +class CCMTLDescriptorSetLayout : public DescriptorSetLayout { +public: + CCMTLDescriptorSetLayout(Device *device); + virtual ~CCMTLDescriptorSetLayout(); + + virtual bool initialize(const DescriptorSetLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE CCMTLGPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } +private: + CCMTLGPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; +}; + +} +} diff --git a/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm b/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm new file mode 100644 index 00000000000..c5852746e5d --- /dev/null +++ b/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm @@ -0,0 +1,39 @@ +#include "MTLStd.h" + +#include "MTLDescriptorSetLayout.h" +#include "MTLGPUObjects.h" + +namespace cc { +namespace gfx { + +CCMTLDescriptorSetLayout::CCMTLDescriptorSetLayout(Device *device) : DescriptorSetLayout(device) { + +} +CCMTLDescriptorSetLayout::~CCMTLDescriptorSetLayout() { + destroy(); +} + +bool CCMTLDescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { + _bindings = info.bindings; + + _gpuDescriptorSetLayout = CC_NEW(CCMTLGPUDescriptorSetLayout); + + for (size_t i = 0; i < _bindings.size(); i++) { + const auto binding = _bindings[i]; + if (static_cast(binding.descriptorType) & DESCRIPTOR_DYNAMIC_TYPE) { + for (uint j = 0; j < binding.count; j++) { + _gpuDescriptorSetLayout->dynamicBindings.push_back(i); + } + } + } + + _gpuDescriptorSetLayout->bindings = _bindings; + _status = Status::SUCCESS; + return true; +} +void CCMTLDescriptorSetLayout::destroy() { + CC_SAFE_DELETE(_gpuDescriptorSetLayout); + _status = Status::UNREADY; +} +} +} diff --git a/cocos/renderer/gfx-metal/MTLDevice.h b/cocos/renderer/gfx-metal/MTLDevice.h index 0b8cb1a0d84..053e98b34f6 100644 --- a/cocos/renderer/gfx-metal/MTLDevice.h +++ b/cocos/renderer/gfx-metal/MTLDevice.h @@ -20,6 +20,7 @@ class CCMTLDevice : public Device { virtual Fence *createFence(const FenceInfo &info) override; virtual Queue *createQueue(const QueueInfo &info) override; virtual Buffer *createBuffer(const BufferInfo &info) override; + virtual Buffer *createBuffer(const BufferViewInfo &info) override; virtual Texture *createTexture(const TextureInfo &info) override; virtual Texture *createTexture(const TextureViewInfo &info) override; virtual Sampler *createSampler(const SamplerInfo &info) override; @@ -27,9 +28,11 @@ class CCMTLDevice : public Device { virtual InputAssembler *createInputAssembler(const InputAssemblerInfo &info) override; virtual RenderPass *createRenderPass(const RenderPassInfo &info) override; virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; - virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; + virtual DescriptorSet *createDescriptorSet(const DescriptorSetInfo &info) override; + virtual DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) override; + virtual PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) 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; } diff --git a/cocos/renderer/gfx-metal/MTLDevice.mm b/cocos/renderer/gfx-metal/MTLDevice.mm index 5cc046809d1..c1a165f4bf1 100644 --- a/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/cocos/renderer/gfx-metal/MTLDevice.mm @@ -1,6 +1,5 @@ #include "MTLStd.h" -#include "MTLBindingLayout.h" #include "MTLBuffer.h" #include "MTLCommandBuffer.h" #include "MTLContext.h" @@ -16,6 +15,9 @@ #include "MTLStateCache.h" #include "MTLTexture.h" #include "MTLUtils.h" +#include "MTLDescriptorSet.h" +#include "MTLDescriptorSetLayout.h" +#include "MTLPipelineLayout.h" #include #import @@ -176,6 +178,15 @@ return nullptr; } +Buffer *CCMTLDevice::createBuffer(const BufferViewInfo &info) { + auto buffer = CC_NEW(CCMTLBuffer(this)); + if (buffer && buffer->initialize(info)) + return buffer; + + CC_SAFE_DESTROY(buffer); + return nullptr; +} + Texture *CCMTLDevice::createTexture(const TextureInfo &info) { auto texture = CC_NEW(CCMTLTexture(this)); if (texture && texture->initialize(info)) @@ -239,12 +250,30 @@ return nullptr; } -BindingLayout *CCMTLDevice::createBindingLayout(const BindingLayoutInfo &info) { - auto bl = CC_NEW(CCMTLBindingLayout(this)); - if (bl && bl->initialize(info)) - return bl; +DescriptorSet *CCMTLDevice::createDescriptorSet(const DescriptorSetInfo &info) { + auto descriptorSet = CC_NEW(CCMTLDescriptorSet(this)); + if (descriptorSet && descriptorSet->initialize(info)) + return descriptorSet; + + CC_SAFE_DESTROY(descriptorSet); + return nullptr; +} + +DescriptorSetLayout *CCMTLDevice::createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) { + auto descriptorSetLayout = CC_NEW(CCMTLDescriptorSetLayout(this)); + if (descriptorSetLayout && descriptorSetLayout->initialize(info)) + return descriptorSetLayout; + + CC_SAFE_DESTROY(descriptorSetLayout); + return nullptr; +} + +PipelineLayout *CCMTLDevice::createPipelineLayout(const PipelineLayoutInfo &info) { + auto pipelineLayout = CC_NEW(CCMTLPipelineLayout(this)); + if (pipelineLayout && pipelineLayout->initialize(info)) + return pipelineLayout; - CC_SAFE_DESTROY(bl); + CC_SAFE_DESTROY(pipelineLayout); return nullptr; } @@ -257,8 +286,8 @@ return nullptr; } -void CCMTLDevice::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { - static_cast(texture)->update(buffers.data(), regions); +void CCMTLDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { + static_cast(texture)->update(buffers, regions, count); } void CCMTLDevice::blitBuffer(void *srcData, uint offset, uint size, void *dstBuffer) { diff --git a/cocos/renderer/gfx-metal/MTLFrameBuffer.h b/cocos/renderer/gfx-metal/MTLFramebuffer.h similarity index 100% rename from cocos/renderer/gfx-metal/MTLFrameBuffer.h rename to cocos/renderer/gfx-metal/MTLFramebuffer.h diff --git a/cocos/renderer/gfx-metal/MTLFramebuffer.mm b/cocos/renderer/gfx-metal/MTLFramebuffer.mm index e30d82f0465..326bbaa7b4c 100644 --- a/cocos/renderer/gfx-metal/MTLFramebuffer.mm +++ b/cocos/renderer/gfx-metal/MTLFramebuffer.mm @@ -18,7 +18,7 @@ auto *mtlRenderPass = static_cast(_renderPass); size_t slot = 0; size_t levelCount = info.colorMipmapLevels.size(); - int i = 0; + size_t i = 0; size_t attachmentIndices = 0; for (const auto &colorTexture : info.colorTextures) { int level = 0; diff --git a/cocos/renderer/gfx-metal/MTLGPUObjects.h b/cocos/renderer/gfx-metal/MTLGPUObjects.h index 25edb1d958c..1f94c6d2fab 100644 --- a/cocos/renderer/gfx-metal/MTLGPUObjects.h +++ b/cocos/renderer/gfx-metal/MTLGPUObjects.h @@ -9,6 +9,10 @@ namespace cc { namespace gfx { +class CCMTLBuffer; +class CCMTLTexture; +class CCMTLSampler; +class CCMTLShader; #define MAX_INFLIGHT_BUFFER 1 @@ -42,6 +46,19 @@ struct CCMTLGPUSamplerState { }; typedef vector CCMTLGPUSamplerStateList; +class CCMTLGPUDescriptorSetLayout : public Object { +public: + DescriptorSetLayoutBindingList bindings; + vector dynamicBindings; +}; +typedef vector MTLGPUDescriptorSetLayoutList; + +class CCMTLGPUPipelineLayout : public Object { +public: + MTLGPUDescriptorSetLayoutList setLayouts; + vector> dynamicOffsetIndices; +}; + struct CCMTLGPUPipelineState { MTLCullMode cullMode; MTLWinding winding; @@ -55,6 +72,8 @@ struct CCMTLGPUPipelineState { vector> vertexBufferBindingInfo; unordered_map vertexSamplerBinding; unordered_map fragmentSamplerBinding; + CCMTLGPUPipelineLayout *gpuPipelineLayout = nullptr; + CCMTLShader *gpuShader = nullptr; }; struct CCMTLGPUBuffer { @@ -70,5 +89,19 @@ class CCMTLGPUInputAssembler : public Object { vector> mtlVertexBufers; }; +struct CCMTLGPUDescriptor { + DescriptorType type = DescriptorType::UNKNOWN; + + CCMTLBuffer *buffer = nullptr; + CCMTLTexture *texture = nullptr; + CCMTLSampler *sampler = nullptr; +}; +typedef vector MTLGPUDescriptorList; + +class CCMTLGPUDescriptorSet : public Object { +public: + MTLGPUDescriptorList gpuDescriptors; +}; + } // namespace gfx } // namespace cc diff --git a/cocos/renderer/gfx-metal/MTLPipelineLayout.h b/cocos/renderer/gfx-metal/MTLPipelineLayout.h new file mode 100644 index 00000000000..619cd4922ac --- /dev/null +++ b/cocos/renderer/gfx-metal/MTLPipelineLayout.h @@ -0,0 +1,20 @@ +#pragma once +namespace cc{ +namespace gfx { +class CCMTLGPUPipelineLayout; + +class CCMTLPipelineLayout : public PipelineLayout { +public: + CCMTLPipelineLayout(Device *device); + virtual ~CCMTLPipelineLayout(); + + virtual bool initialize(const PipelineLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE CCMTLGPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } + +private: + CCMTLGPUPipelineLayout *_gpuPipelineLayout = nullptr; +}; +} +} diff --git a/cocos/renderer/gfx-metal/MTLPipelineLayout.mm b/cocos/renderer/gfx-metal/MTLPipelineLayout.mm new file mode 100644 index 00000000000..efa54546852 --- /dev/null +++ b/cocos/renderer/gfx-metal/MTLPipelineLayout.mm @@ -0,0 +1,48 @@ +#include "MTLStd.h" + +#include "MTLPipelineLayout.h" +#include "MTLGPUObjects.h" +#include "MTLDescriptorSetLayout.h" +namespace cc { +namespace gfx { + +CCMTLPipelineLayout::CCMTLPipelineLayout(Device *device) : PipelineLayout(device) { + +} +CCMTLPipelineLayout::~CCMTLPipelineLayout() { + destroy(); +} + +bool CCMTLPipelineLayout::initialize(const PipelineLayoutInfo &info) { + _setLayouts = info.setLayouts; + + _gpuPipelineLayout = CC_NEW(CCMTLGPUPipelineLayout); + + int offset = 0u; + uint set = 0; + _gpuPipelineLayout->dynamicOffsetIndices.resize(_setLayouts.size()); + for (auto setLayout : _setLayouts) { + auto gpuDescriptorSetLayout = static_cast(setLayout)->gpuDescriptorSetLayout(); + auto bindingCount = gpuDescriptorSetLayout->bindings.size(); + auto dynamicCount = gpuDescriptorSetLayout->dynamicBindings.size(); + + vector &indices = _gpuPipelineLayout->dynamicOffsetIndices[set]; + indices.assign(bindingCount, -1); + + for (uint j = 0u; j < dynamicCount; j++) { + uint binding = gpuDescriptorSetLayout->dynamicBindings[j]; + if (indices[binding] < 0) indices[binding] = offset + j; //TODO? + } + _gpuPipelineLayout->setLayouts.emplace_back(gpuDescriptorSetLayout); + offset += dynamicCount; + } + + _status = Status::SUCCESS; + return true; +} + +void CCMTLPipelineLayout::destroy() { + +} +} +} diff --git a/cocos/renderer/gfx-metal/MTLPipelineState.mm b/cocos/renderer/gfx-metal/MTLPipelineState.mm index 7e00b965d01..34de0b6d47a 100644 --- a/cocos/renderer/gfx-metal/MTLPipelineState.mm +++ b/cocos/renderer/gfx-metal/MTLPipelineState.mm @@ -1,6 +1,5 @@ #include "MTLStd.h" -#include "MTLBindingLayout.h" #include "MTLBuffer.h" #include "MTLDevice.h" #include "MTLGPUObjects.h" @@ -9,6 +8,7 @@ #include "MTLShader.h" #include "MTLTexture.h" #include "MTLUtils.h" +#include "MTLPipelineLayout.h" #import #import @@ -28,6 +28,7 @@ _blendState = info.blendState; _dynamicStates = info.dynamicStates; _renderPass = info.renderPass; + _pipelineLayout = info.pipelineLayout; if (!createGPUPipelineState()) { _status = Status::FAILED; @@ -75,7 +76,7 @@ _GPUPipelieState->primitiveType = mu::toMTLPrimitiveType(_primitive); _GPUPipelieState->vertexSamplerBinding = static_cast(_shader)->getVertexSamplerBindings(); _GPUPipelieState->fragmentSamplerBinding = static_cast(_shader)->getFragmentSamplerBindings(); - + _GPUPipelieState->gpuPipelineLayout = static_cast(_pipelineLayout)->gpuPipelineLayout(); return true; } @@ -155,7 +156,7 @@ if (inputAttrib.name == activeAttribute.name) { descriptor.vertexDescriptor.attributes[activeAttribute.location].format = mu::toMTLVertexFormat(inputAttrib.format, inputAttrib.isNormalized); descriptor.vertexDescriptor.attributes[activeAttribute.location].offset = streamOffsets[inputAttrib.stream]; - auto bufferIndex = static_cast(_shader)->getAvailableBufferBindingIndex(ShaderType::VERTEX, inputAttrib.stream); + auto bufferIndex = static_cast(_shader)->getAvailableBufferBindingIndex(ShaderStageFlagBit::VERTEX, inputAttrib.stream); descriptor.vertexDescriptor.attributes[activeAttribute.location].bufferIndex = bufferIndex; streamOffsets[inputAttrib.stream] += GFX_FORMAT_INFOS[(int)inputAttrib.format].size; @@ -170,7 +171,7 @@ if (!attributeFound) { //handle absent attribute descriptor.vertexDescriptor.attributes[activeAttribute.location].format = MTLVertexFormatFloat; descriptor.vertexDescriptor.attributes[activeAttribute.location].offset = 0; - descriptor.vertexDescriptor.attributes[activeAttribute.location].bufferIndex = static_cast(_shader)->getAvailableBufferBindingIndex(ShaderType::VERTEX, activeAttribute.stream); + descriptor.vertexDescriptor.attributes[activeAttribute.location].bufferIndex = static_cast(_shader)->getAvailableBufferBindingIndex(ShaderStageFlagBit::VERTEX, activeAttribute.stream); CC_LOG_WARNING("Attribute %s is missing, add a dummy data for it.", activeAttribute.name.c_str()); } } diff --git a/cocos/renderer/gfx-metal/MTLShader.h b/cocos/renderer/gfx-metal/MTLShader.h index 54ed15441ef..6867cc13689 100644 --- a/cocos/renderer/gfx-metal/MTLShader.h +++ b/cocos/renderer/gfx-metal/MTLShader.h @@ -19,7 +19,7 @@ class CCMTLShader : public Shader { CC_INLINE const unordered_map &getVertexSamplerBindings() const { return _mtlVertexSamplerBindings; } CC_INLINE const unordered_map &getFragmentSamplerBindings() const { return _mtlFragmentSamplerBindings; } - uint getAvailableBufferBindingIndex(ShaderType stage, uint stream); + uint getAvailableBufferBindingIndex(ShaderStageFlagBit stage, uint stream); #ifdef DEBUG_SHADER CC_INLINE const String &getVertGlslShader() const { return _vertGlslShader; } diff --git a/cocos/renderer/gfx-metal/MTLShader.mm b/cocos/renderer/gfx-metal/MTLShader.mm index 9cc64f476ab..ee504c4c7f1 100644 --- a/cocos/renderer/gfx-metal/MTLShader.mm +++ b/cocos/renderer/gfx-metal/MTLShader.mm @@ -47,10 +47,10 @@ } bool CCMTLShader::createMTLFunction(const ShaderStage &stage) { - bool isVertexShader = stage.type == ShaderType::VERTEX; + bool isVertexShader = stage.stage == ShaderStageFlagBit::VERTEX; id mtlDevice = id(((CCMTLDevice *)_device)->getMTLDevice()); auto mtlShader = mu::compileGLSLShader2Msl(stage.source, - stage.type, + stage.stage, _device, isVertexShader ? _mtlVertexSamplerBindings : _mtlFragmentSamplerBindings); NSString *shader = [NSString stringWithUTF8String:mtlShader.c_str()]; @@ -65,7 +65,7 @@ return false; } - if (stage.type == ShaderType::VERTEX) { + if (stage.stage == ShaderStageFlagBit::VERTEX) { _vertexMTLFunction = [library newFunctionWithName:@"main0"]; if (!_vertexMTLFunction) { [library release]; @@ -95,12 +95,12 @@ return true; } -uint CCMTLShader::getAvailableBufferBindingIndex(ShaderType stage, uint stream) { - if (stage & ShaderType::VERTEX) { +uint CCMTLShader::getAvailableBufferBindingIndex(ShaderStageFlagBit stage, uint stream) { + if (stage & ShaderStageFlagBit::VERTEX) { return _availableVertexBufferBindingIndex.at(stream); } - if (stage & ShaderType::FRAGMENT) { + if (stage & ShaderStageFlagBit::FRAGMENT) { return _availableFragmentBufferBindingIndex.at(stream); } @@ -109,21 +109,23 @@ } void CCMTLShader::setAvailableBufferBindingIndex() { + CC_ASSERT(0); uint usedVertexBufferBindingIndexes = 0; uint usedFragmentBufferBindingIndexes = 0; size_t vertexBindingCount = 0; size_t fragmentBindingCount = 0; - for (const auto &block : _blocks) { - if (block.shaderStages & ShaderType::VERTEX) { - usedVertexBufferBindingIndexes |= 1 << block.binding; - vertexBindingCount++; - } - - if (block.shaderStages & ShaderType::FRAGMENT) { - usedFragmentBufferBindingIndexes |= 1 << block.binding; - fragmentBindingCount++; - } - } + //TODO coulsonwang +// for (const auto &block : _blocks) { +// if (block.shaderStages & ShaderStageFlagBit::VERTEX) { +// usedVertexBufferBindingIndexes |= 1 << block.binding; +// vertexBindingCount++; +// } +// +// if (block.shaderStages & ShaderStageFlagBit::FRAGMENT) { +// usedFragmentBufferBindingIndexes |= 1 << block.binding; +// fragmentBindingCount++; +// } +// } auto maxBufferBindinIndex = static_cast(_device)->getMaximumBufferBindingIndex(); _availableVertexBufferBindingIndex.resize(maxBufferBindinIndex - vertexBindingCount); _availableFragmentBufferBindingIndex.resize(maxBufferBindinIndex - fragmentBindingCount); diff --git a/cocos/renderer/gfx-metal/MTLTexture.h b/cocos/renderer/gfx-metal/MTLTexture.h index a3229e5cb74..667c0bfbbb2 100644 --- a/cocos/renderer/gfx-metal/MTLTexture.h +++ b/cocos/renderer/gfx-metal/MTLTexture.h @@ -22,7 +22,7 @@ class CCMTLTexture : public Texture { CC_INLINE Format getConvertedFormat() const { return _convertedFormat; } private: - void update(const uint8_t *const *datas, const BufferTextureCopyList ®ions); + void update(const uint8_t *const *datas, const BufferTextureCopy *regions, uint count); bool createMTLTexture(); void generateMipmaps(); diff --git a/cocos/renderer/gfx-metal/MTLTexture.mm b/cocos/renderer/gfx-metal/MTLTexture.mm index 6f01cbdcf70..952255b88c1 100644 --- a/cocos/renderer/gfx-metal/MTLTexture.mm +++ b/cocos/renderer/gfx-metal/MTLTexture.mm @@ -90,7 +90,7 @@ } bool CCMTLTexture::initialize(const TextureViewInfo &info) { - _Type = ObjectType::TEXTURE_VIEW; + _isTextureView = true; if (!info.texture) { _status = Status::FAILED; @@ -239,7 +239,7 @@ _status = Status::SUCCESS; } -void CCMTLTexture::update(const uint8_t *const *datas, const BufferTextureCopyList ®ions) { +void CCMTLTexture::update(const uint8_t *const *datas, const BufferTextureCopy *regions, uint count) { if (!_mtlTexture) return; @@ -249,7 +249,7 @@ auto mtlTextureType = mu::toMTLTextureType(_type); switch (mtlTextureType) { case MTLTextureType2D: - for (size_t i = 0; i < regions.size(); i++) { + for (size_t i = 0; i < count; i++) { const auto ®ion = regions[i]; w = region.texExtent.width; h = region.texExtent.height; @@ -269,7 +269,7 @@ break; case MTLTextureType2DArray: case MTLTextureTypeCube: - for (size_t i = 0; i < regions.size(); i++) { + for (size_t i = 0; i < count; i++) { const auto ®ion = regions[i]; auto layer = region.texSubres.baseArrayLayer; auto layerCount = layer + region.texSubres.layerCount; diff --git a/cocos/renderer/gfx-metal/MTLUtils.h b/cocos/renderer/gfx-metal/MTLUtils.h index c4ae54f996d..e4a0a769cae 100644 --- a/cocos/renderer/gfx-metal/MTLUtils.h +++ b/cocos/renderer/gfx-metal/MTLUtils.h @@ -39,7 +39,7 @@ MTLSamplerAddressMode toMTLSamplerAddressMode(Address); MTLSamplerBorderColor toMTLSamplerBorderColor(const Color &); MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(Filter); MTLSamplerMipFilter toMTLSamplerMipFilter(Filter); -String compileGLSLShader2Msl(const String &src, ShaderType shaderType, Device* device, unordered_map &samplerBindings); +String compileGLSLShader2Msl(const String &src, ShaderStageFlagBit shaderType, Device *device, unordered_map &samplerBindings); const uint8_t *convertRGB8ToRGBA8(const uint8_t *source, uint length); const uint8_t *convertRGB32FToRGBA32F(const uint8_t *source, uint length); NSUInteger highestSupportedFeatureSet(id device); diff --git a/cocos/renderer/gfx-metal/MTLUtils.mm b/cocos/renderer/gfx-metal/MTLUtils.mm index 78688bd149a..e037b2927a1 100644 --- a/cocos/renderer/gfx-metal/MTLUtils.mm +++ b/cocos/renderer/gfx-metal/MTLUtils.mm @@ -11,16 +11,16 @@ namespace gfx { namespace { -EShLanguage getShaderStage(ShaderType type) { +EShLanguage getShaderStage(ShaderStageFlagBit type) { switch (type) { - case ShaderType::VERTEX: return EShLangVertex; - case ShaderType::CONTROL: return EShLangTessControl; - case ShaderType::EVALUATION: return EShLangTessEvaluation; - case ShaderType::GEOMETRY: return EShLangGeometry; - case ShaderType::FRAGMENT: return EShLangFragment; - case ShaderType::COMPUTE: return EShLangCompute; + case ShaderStageFlagBit::VERTEX: return EShLangVertex; + case ShaderStageFlagBit::CONTROL: return EShLangTessControl; + case ShaderStageFlagBit::EVALUATION: return EShLangTessEvaluation; + case ShaderStageFlagBit::GEOMETRY: return EShLangGeometry; + case ShaderStageFlagBit::FRAGMENT: return EShLangFragment; + case ShaderStageFlagBit::COMPUTE: return EShLangCompute; default: { - CCASSERT(false, "Unsupported ShaderType, convert to EShLanguage failed."); + CCASSERT(false, "Unsupported ShaderStageFlagBit, convert to EShLanguage failed."); return EShLangVertex; } } @@ -50,7 +50,7 @@ EShLanguage getShaderStage(ShaderType type) { } } -const vector GLSL2SPIRV(ShaderType type, const String &source, int vulkanMinorVersion = 2) { +const vector GLSL2SPIRV(ShaderStageFlagBit type, const String &source, int vulkanMinorVersion = 2) { static bool glslangInitialized = false; if (!glslangInitialized) { glslang::InitializeProcess(); @@ -512,7 +512,7 @@ MTLSamplerMipFilter toMTLSamplerMipFilter(Filter filter) { } String compileGLSLShader2Msl(const String &src, - ShaderType shaderType, + ShaderStageFlagBit shaderType, Device *device, unordered_map &samplerBindings) { #if USE_METAL diff --git a/cocos/renderer/gfx-vulkan/CMakeLists.txt b/cocos/renderer/gfx-vulkan/CMakeLists.txt index 4f4ffdb7a81..d916209a365 100644 --- a/cocos/renderer/gfx-vulkan/CMakeLists.txt +++ b/cocos/renderer/gfx-vulkan/CMakeLists.txt @@ -44,12 +44,6 @@ if(COCOS_PLATFORM_IOS OR COCOS_PLATFORM_OSX) set(ALL_FILES ${ALL_FILES} ${SOURCE_MM_FILES}) endif() -if(COCOS_PLATFORM_IOS OR COCOS_PLATFORM_OSX) - list(REMOVE_ITEM ALL_FILES "${COCOS_SRC_PATH}/renderer/gfx-vulkan/gles3w.c") -else() - list(REMOVE_ITEM ALL_FILES "${COCOS_SRC_PATH}/renderer/gfx-vulkan/gles3w.mm") -endif() - add_definitions("-DCC_VK_EXPORTS") if(WIN32) add_definitions("-DGLEW_BUILD") diff --git a/cocos/renderer/gfx-vulkan/VKBindingLayout.cc b/cocos/renderer/gfx-vulkan/VKBindingLayout.cc deleted file mode 100644 index 8cd41ec826f..00000000000 --- a/cocos/renderer/gfx-vulkan/VKBindingLayout.cc +++ /dev/null @@ -1,198 +0,0 @@ -#include "VKStd.h" - -#include "VKBindingLayout.h" -#include "VKBuffer.h" -#include "VKCommands.h" -#include "VKDevice.h" -#include "VKSampler.h" -#include "VKShader.h" -#include "VKTexture.h" - -namespace cc { -namespace gfx { - -CCVKBindingLayout::CCVKBindingLayout(Device *device) -: BindingLayout(device) { -} - -CCVKBindingLayout::~CCVKBindingLayout() { -} - -bool CCVKBindingLayout::initialize(const BindingLayoutInfo &info) { - - const CCVKGPUShader *gpuShader = ((CCVKShader *)info.shader)->gpuShader(); - const UniformBlockList &blocks = gpuShader->blocks; - const UniformSamplerList &samplers = gpuShader->samplers; - const uint bindingCount = blocks.size() + samplers.size(); - const uint descriptorCount = gpuShader->pipelineLayout->descriptorCounts[0]; - - if (bindingCount) { - _bindingUnits.resize(bindingCount); - for (size_t i = 0u; i < blocks.size(); ++i) { - const UniformBlock &binding = blocks[i]; - BindingUnit &bindingUnit = _bindingUnits[i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::UNIFORM_BUFFER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = 1; - } - for (size_t i = 0u; i < samplers.size(); ++i) { - const UniformSampler &binding = samplers[i]; - BindingUnit &bindingUnit = _bindingUnits[blocks.size() + i]; - bindingUnit.shaderStages = binding.shaderStages; - bindingUnit.type = BindingType::SAMPLER; - bindingUnit.binding = binding.binding; - bindingUnit.name = binding.name; - bindingUnit.count = binding.count; - } - } - - _gpuBindingLayout = CC_NEW(CCVKGPUBindingLayout); - _gpuBindingLayout->gpuBindings.resize(1); - _gpuBindingLayout->descriptorSets.resize(1); - _gpuBindingLayout->gpuBindings[0].resize(bindingCount); - _gpuBindingLayout->descriptorInfos.resize(descriptorCount); - _gpuBindingLayout->descriptorIndices = &gpuShader->pipelineLayout->descriptorIndices; - - for (size_t i = blocks.size(); i < descriptorCount; ++i) { - _gpuBindingLayout->descriptorInfos[i].image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - } - - if (!((CCVKDevice *)_device)->gpuDevice()->useDescriptorUpdateTemplate) { - vector &entries = _gpuBindingLayout->descriptorUpdateEntries; - entries.resize(descriptorCount, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}); - - for (size_t i = 0u, j = 0u; i < bindingCount; i++) { - BindingUnit &bindingUnit = _bindingUnits[i]; - // better not to assume that our descriptor layout will be contiguous - for (size_t k = 0u; k < bindingUnit.count; k++, j++) { - entries[j].dstBinding = bindingUnit.binding; - entries[j].dstArrayElement = k; - entries[j].descriptorCount = 1; - entries[j].descriptorType = MapVkDescriptorType(bindingUnit.type); - switch (entries[j].descriptorType) { - case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: - case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: - case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: - case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: - entries[j].pBufferInfo = &_gpuBindingLayout->descriptorInfos[j].buffer; - break; - case VK_DESCRIPTOR_TYPE_SAMPLER: - case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: - case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: - case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: - case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: - entries[j].pImageInfo = &_gpuBindingLayout->descriptorInfos[j].image; - break; - case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: - case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: - entries[j].pTexelBufferView = &_gpuBindingLayout->descriptorInfos[j].texelBufferView; - break; - default: break; - } - } - } - } - - _status = Status::SUCCESS; - - return true; -} - -void CCVKBindingLayout::destroy() { - if (_gpuBindingLayout) { - for (vector &bindings : _gpuBindingLayout->gpuBindings) { - for (uint i = 0u; i < bindings.size(); i++) { - CCVKGPUBinding &binding = bindings[i]; - const uint descriptorIndex = _gpuBindingLayout->descriptorIndices->at(0)[i]; - CCVKGPUDescriptorInfo &descriptorInfo = _gpuBindingLayout->descriptorInfos[descriptorIndex]; - CCVKGPUDescriptorHub *descriptorHub = ((CCVKDevice *)_device)->gpuDescriptorHub(); - if (binding.buffer) { - descriptorHub->disengage(binding.buffer, &descriptorInfo.buffer); - } - if (binding.texView) { - descriptorHub->disengage(binding.texView, &descriptorInfo.image); - } - if (binding.sampler) { - descriptorHub->disengage(binding.sampler, &descriptorInfo.image); - } - } - bindings.clear(); - } - _gpuBindingLayout->gpuBindings.clear(); - _gpuBindingLayout->descriptorInfos.clear(); - _gpuBindingLayout->descriptorSets.clear(); - _gpuBindingLayout->descriptorIndices = nullptr; - CC_DELETE(_gpuBindingLayout); - _gpuBindingLayout = nullptr; - } - - _status = Status::UNREADY; -} - -void CCVKBindingLayout::update() { - if (_isDirty && _gpuBindingLayout) { - CCVKGPUDescriptorHub *descriptorHub = ((CCVKDevice *)_device)->gpuDescriptorHub(); - for (size_t i = 0u; i < _bindingUnits.size(); ++i) { - BindingUnit &bindingUnit = _bindingUnits[i]; - CCVKGPUBinding &binding = _gpuBindingLayout->gpuBindings[0][i]; - const uint descriptorIndex = _gpuBindingLayout->descriptorIndices->at(0)[i]; - CCVKGPUDescriptorInfo &descriptorInfo = _gpuBindingLayout->descriptorInfos[descriptorIndex]; - switch (bindingUnit.type) { - case BindingType::UNIFORM_BUFFER: { - if (bindingUnit.buffer) { - CCVKGPUBuffer *buffer = ((CCVKBuffer *)bindingUnit.buffer)->gpuBuffer(); - if (binding.buffer != buffer) { - if (binding.buffer) { - descriptorHub->disengage(binding.buffer, &descriptorInfo.buffer); - } - if (buffer) { - descriptorHub->connect(buffer, &descriptorInfo.buffer); - descriptorHub->update(buffer, &descriptorInfo.buffer); - } - binding.buffer = buffer; - } - } - break; - } - case BindingType::SAMPLER: { - // TODO: handle texture arrays(need public interface changes) - if (bindingUnit.texture) { - CCVKGPUTextureView *texView = ((CCVKTexture *)bindingUnit.texture)->gpuTextureView(); - if (binding.texView != texView) { - if (binding.texView) { - descriptorHub->disengage(binding.texView, &descriptorInfo.image); - } - if (texView) { - descriptorHub->connect(texView, &descriptorInfo.image); - descriptorHub->update(texView, &descriptorInfo.image); - } - binding.texView = texView; - } - } - if (bindingUnit.sampler) { - CCVKGPUSampler *sampler = ((CCVKSampler *)bindingUnit.sampler)->gpuSampler(); - if (binding.sampler != sampler) { - if (binding.sampler) { - descriptorHub->disengage(binding.sampler, &descriptorInfo.image); - } - if (sampler) { - descriptorHub->connect(sampler, &descriptorInfo.image); - descriptorHub->update(sampler, &descriptorInfo.image); - } - binding.sampler = sampler; - } - } - break; - } - default: break; - } - } - - _isDirty = false; - } -} - -} // namespace gfx -} // namespace cc diff --git a/cocos/renderer/gfx-vulkan/VKBindingLayout.h b/cocos/renderer/gfx-vulkan/VKBindingLayout.h deleted file mode 100644 index b028b7121f7..00000000000 --- a/cocos/renderer/gfx-vulkan/VKBindingLayout.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CC_GFXVULKAN_CCVK_BINDING_LAYOUT_H_ -#define CC_GFXVULKAN_CCVK_BINDING_LAYOUT_H_ - -namespace cc { -namespace gfx { - -class CCVKGPUBindingLayout; - -class CC_VULKAN_API CCVKBindingLayout : public BindingLayout { -public: - CCVKBindingLayout(Device *device); - ~CCVKBindingLayout(); - -public: - bool initialize(const BindingLayoutInfo &info); - void destroy(); - void update(); - - CC_INLINE CCVKGPUBindingLayout *gpuBindingLayout() const { return _gpuBindingLayout; } - -private: - CCVKGPUBindingLayout *_gpuBindingLayout = nullptr; -}; - -} // namespace gfx -} // namespace cc - -#endif diff --git a/cocos/renderer/gfx-vulkan/VKBuffer.cc b/cocos/renderer/gfx-vulkan/VKBuffer.cc index 8db03e9000f..0aad9a8c0e3 100644 --- a/cocos/renderer/gfx-vulkan/VKBuffer.cc +++ b/cocos/renderer/gfx-vulkan/VKBuffer.cc @@ -1,8 +1,8 @@ #include "VKStd.h" #include "VKBuffer.h" -#include "VKDevice.h" #include "VKCommands.h" +#include "VKDevice.h" namespace cc { namespace gfx { @@ -44,18 +44,54 @@ bool CCVKBuffer::initialize(const BufferInfo &info) { CCVKCmdFuncCreateBuffer((CCVKDevice *)_device, _gpuBuffer); _device->getMemoryStatus().bufferSize += _size; + + _gpuBufferView = CC_NEW(CCVKGPUBufferView); + createBufferView(); + _status = Status::SUCCESS; return true; } +bool CCVKBuffer::initialize(const BufferViewInfo &info) { + _isBufferView = true; + + CCVKBuffer *buffer = (CCVKBuffer *)info.buffer; + + _usage = buffer->_usage; + _memUsage = buffer->_memUsage; + _size = _stride = info.range; + _count = 1u; + _flags = buffer->_flags; + _offset = info.offset; + + _gpuBuffer = ((CCVKBuffer*)info.buffer)->gpuBuffer(); + _gpuBufferView = CC_NEW(CCVKGPUBufferView); + createBufferView(); + + return true; +} + +void CCVKBuffer::createBufferView() { + _gpuBufferView->gpuBuffer = _gpuBuffer; + _gpuBufferView->offset = _offset; + _gpuBufferView->range = _size; + ((CCVKDevice *)_device)->gpuDescriptorHub()->update(_gpuBufferView); +} + void CCVKBuffer::destroy() { - if (_gpuBuffer) { - ((CCVKDevice *)_device)->gpuDescriptorHub()->disengage(_gpuBuffer); - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); + if (_gpuBufferView) { + ((CCVKDevice *)_device)->gpuDescriptorHub()->disengage(_gpuBufferView); + CC_DELETE(_gpuBufferView); + _gpuBufferView = nullptr; + } - _device->getMemoryStatus().bufferSize -= _size; - CC_DELETE(_gpuBuffer); + if (_gpuBuffer) { + if (!_isBufferView) { + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); + _device->getMemoryStatus().bufferSize -= _size; + CC_DELETE(_gpuBuffer); + } _gpuBuffer = nullptr; } @@ -69,16 +105,22 @@ void CCVKBuffer::destroy() { } void CCVKBuffer::resize(uint size) { + CCASSERT(!_isBufferView, "Cannot resize buffer views"); + if (_size != size) { const uint oldSize = _size; _size = size; _count = _size / _stride; - MemoryStatus &status = _device->getMemoryStatus(); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); + _gpuBuffer->size = _size; _gpuBuffer->count = _count; - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); CCVKCmdFuncCreateBuffer((CCVKDevice *)_device, _gpuBuffer); + + createBufferView(); + + MemoryStatus &status = _device->getMemoryStatus(); status.bufferSize -= oldSize; status.bufferSize += _size; @@ -102,6 +144,8 @@ void CCVKBuffer::resize(uint size) { } void CCVKBuffer::update(void *buffer, uint offset, uint size) { + CCASSERT(!_isBufferView, "Cannot update through buffer views"); + #if COCOS2D_DEBUG > 0 if (_usage & BufferUsageBit::INDIRECT) { DrawInfo *drawInfo = static_cast(buffer); @@ -115,6 +159,7 @@ void CCVKBuffer::update(void *buffer, uint offset, uint size) { } } #endif + if (_buffer) { memcpy(_buffer + offset, buffer, size); } diff --git a/cocos/renderer/gfx-vulkan/VKBuffer.h b/cocos/renderer/gfx-vulkan/VKBuffer.h index f02e9bb0f36..7a81556456c 100644 --- a/cocos/renderer/gfx-vulkan/VKBuffer.h +++ b/cocos/renderer/gfx-vulkan/VKBuffer.h @@ -5,6 +5,7 @@ namespace cc { namespace gfx { class CCVKGPUBuffer; +class CCVKGPUBufferView; class CC_VULKAN_API CCVKBuffer : public Buffer { public: @@ -13,14 +14,19 @@ class CC_VULKAN_API CCVKBuffer : public Buffer { public: bool initialize(const BufferInfo &info); + bool initialize(const BufferViewInfo &info); void destroy(); void resize(uint size); void update(void *buffer, uint offset, uint size); CC_INLINE CCVKGPUBuffer *gpuBuffer() const { return _gpuBuffer; } + CC_INLINE CCVKGPUBufferView *gpuBufferView() const { return _gpuBufferView; } private: + void createBufferView(); + CCVKGPUBuffer *_gpuBuffer = nullptr; + CCVKGPUBufferView *_gpuBufferView = nullptr; }; } // namespace gfx diff --git a/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc b/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc index f543e0eb50f..92e266a9df8 100644 --- a/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc +++ b/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc @@ -1,9 +1,9 @@ #include "VKStd.h" -#include "VKBindingLayout.h" #include "VKBuffer.h" #include "VKCommandBuffer.h" #include "VKCommands.h" +#include "VKDescriptorSet.h" #include "VKDevice.h" #include "VKFramebuffer.h" #include "VKInputAssembler.h" @@ -31,6 +31,10 @@ bool CCVKCommandBuffer::initialize(const CommandBufferInfo &info) { _gpuCommandBuffer->queueFamilyIndex = ((CCVKQueue *)_queue)->gpuQueue()->queueFamilyIndex; ((CCVKDevice *)_device)->gpuCommandBufferPool()->request(_gpuCommandBuffer); + uint setCount = ((CCVKDevice *)_device)->bindingMappingInfo().bufferOffsets.size(); + _curGPUDescriptorSets.resize(setCount); + _curDynamicOffsets.resize(setCount); + _status = Status::SUCCESS; return true; } @@ -47,8 +51,13 @@ void CCVKCommandBuffer::destroy() { void CCVKCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { _curGPUPipelineState = nullptr; - _curGPUBindingLayout = nullptr; _curGPUInputAssember = nullptr; + _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); + for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { + _curDynamicOffsets[i].clear(); + } + _firstDirtyDescriptorSet = UINT_MAX; + _numDrawCalls = 0; _numInstances = 0; _numTriangles = 0; @@ -76,7 +85,7 @@ void CCVKCommandBuffer::end() { } void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, - const vector &colors, float depth, int stencil) { + const Color *colors, float depth, int stencil) { _curGPUFBO = ((CCVKFramebuffer *)fbo)->gpuFBO(); CCVKGPURenderPass *gpuRenderPass = ((CCVKRenderPass *)renderPass)->gpuRenderPass(); VkFramebuffer framebuffer = _curGPUFBO->vkFramebuffer; @@ -127,51 +136,18 @@ void CCVKCommandBuffer::bindPipelineState(PipelineState *pso) { } } -void CCVKCommandBuffer::bindBindingLayout(BindingLayout *layout) { - if (!_curGPUPipelineState) { - CC_LOG_ERROR("Command 'bindBindingLayout' must be recorded after 'bindPipelineState'."); - return; - } - - CCVKGPUBindingLayout *gpuBindingLayout = ((CCVKBindingLayout *)layout)->gpuBindingLayout(); - - if (_curGPUBindingLayout != gpuBindingLayout) { - - CCVKDevice *device = (CCVKDevice *)_device; - CCVKGPUDevice *gpuDevice = device->gpuDevice(); - VkCommandBuffer cmdBuff = _gpuCommandBuffer->vkCommandBuffer; - CCVKGPUPipelineLayout *pipelineLayout = _curGPUPipelineState->gpuShader->pipelineLayout; - vector &descriptorInfos = gpuBindingLayout->descriptorInfos; - - if (gpuDevice->usePushDescriptorSet) { - vector &templates = pipelineLayout->vkDescriptorUpdateTemplates; - - for (uint i = 0u; i < templates.size(); i++) { - vkCmdPushDescriptorSetWithTemplateKHR(cmdBuff, templates[i], pipelineLayout->vkPipelineLayout, i, descriptorInfos.data()); - } - } else { - vector &layouts = pipelineLayout->vkDescriptorSetLayouts; - vector &sets = gpuBindingLayout->descriptorSets; - - device->gpuDescriptorSetPool()->alloc(layouts.data(), sets.data(), layouts.size()); +void CCVKCommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { + CCASSERT(_curGPUDescriptorSets.size() > set, "Invalid set index"); - if (gpuDevice->useDescriptorUpdateTemplate) { - vector &templates = pipelineLayout->vkDescriptorUpdateTemplates; + CCVKGPUDescriptorSet *gpuDescriptorSet = ((CCVKDescriptorSet *)descriptorSet)->gpuDescriptorSet(); - for (uint i = 0u; i < templates.size(); i++) { - vkUpdateDescriptorSetWithTemplateKHR(device->gpuDevice()->vkDevice, sets[i], templates[i], descriptorInfos.data()); - } - } else { - vector &entries = gpuBindingLayout->descriptorUpdateEntries; - - for (uint j = 0u; j < entries.size(); j++) { - entries[j].dstSet = sets[0]; - } - vkUpdateDescriptorSets(device->gpuDevice()->vkDevice, entries.size(), entries.data(), 0, nullptr); - } - vkCmdBindDescriptorSets(cmdBuff, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout->vkPipelineLayout, 0, layouts.size(), sets.data(), 0, nullptr); - } - _curGPUBindingLayout = gpuBindingLayout; + if (_curGPUDescriptorSets[set] != gpuDescriptorSet) { + _curGPUDescriptorSets[set] = gpuDescriptorSet; + if (set < _firstDirtyDescriptorSet) _firstDirtyDescriptorSet = set; + } + if (dynamicOffsetCount) { + _curDynamicOffsets[set].assign(dynamicOffsets, dynamicOffsets + dynamicOffsetCount); + if (set < _firstDirtyDescriptorSet) _firstDirtyDescriptorSet = set; } } @@ -283,82 +259,81 @@ void CCVKCommandBuffer::setStencilCompareMask(StencilFace face, int reference, u } void CCVKCommandBuffer::draw(InputAssembler *ia) { - if ((_type == CommandBufferType::PRIMARY && _curGPUFBO) || - (_type == CommandBufferType::SECONDARY)) { - CCVKGPUInputAssembler *gpuInputAssembler = ((CCVKInputAssembler *)ia)->gpuInputAssembler(); - DrawInfo drawInfo; - - if (gpuInputAssembler->gpuIndirectBuffer) { - uint drawInfoCount = gpuInputAssembler->gpuIndirectBuffer->count; - if (static_cast(_device)->gpuDevice()->useMultiDrawIndirect) { - if (gpuInputAssembler->gpuIndirectBuffer->isDrawIndirectByIndex) { + if (_firstDirtyDescriptorSet < _curGPUDescriptorSets.size()) { + doBindDescriptorSet(); + } + + CCVKGPUInputAssembler *gpuInputAssembler = ((CCVKInputAssembler *)ia)->gpuInputAssembler(); + DrawInfo drawInfo; + + if (gpuInputAssembler->gpuIndirectBuffer) { + uint drawInfoCount = gpuInputAssembler->gpuIndirectBuffer->count; + if (static_cast(_device)->gpuDevice()->useMultiDrawIndirect) { + if (gpuInputAssembler->gpuIndirectBuffer->isDrawIndirectByIndex) { + vkCmdDrawIndexedIndirect(_gpuCommandBuffer->vkCommandBuffer, + gpuInputAssembler->gpuIndirectBuffer->vkBuffer, + 0, + drawInfoCount, + sizeof(VkDrawIndexedIndirectCommand)); + } else { + vkCmdDrawIndirect(_gpuCommandBuffer->vkCommandBuffer, + gpuInputAssembler->gpuIndirectBuffer->vkBuffer, + 0, + drawInfoCount, + sizeof(VkDrawIndirectCommand)); + } + } else { + // If multi draw is not available, we must issue separate draw commands + if (gpuInputAssembler->gpuIndirectBuffer->isDrawIndirectByIndex) { + for (uint j = 0u; j < drawInfoCount; j++) { vkCmdDrawIndexedIndirect(_gpuCommandBuffer->vkCommandBuffer, gpuInputAssembler->gpuIndirectBuffer->vkBuffer, - 0, - drawInfoCount, + j * sizeof(VkDrawIndexedIndirectCommand), + 1, sizeof(VkDrawIndexedIndirectCommand)); - } else { + } + } else { + for (uint j = 0u; j < drawInfoCount; j++) { vkCmdDrawIndirect(_gpuCommandBuffer->vkCommandBuffer, gpuInputAssembler->gpuIndirectBuffer->vkBuffer, - 0, - drawInfoCount, + j * sizeof(VkDrawIndirectCommand), + 1, sizeof(VkDrawIndirectCommand)); } - } else { - // If multi draw is not available, we must issue separate draw commands - if (gpuInputAssembler->gpuIndirectBuffer->isDrawIndirectByIndex) { - for (uint j = 0u; j < drawInfoCount; j++) { - vkCmdDrawIndexedIndirect(_gpuCommandBuffer->vkCommandBuffer, - gpuInputAssembler->gpuIndirectBuffer->vkBuffer, - j * sizeof(VkDrawIndexedIndirectCommand), - 1, - sizeof(VkDrawIndexedIndirectCommand)); - } - } else { - for (uint j = 0u; j < drawInfoCount; j++) { - vkCmdDrawIndirect(_gpuCommandBuffer->vkCommandBuffer, - gpuInputAssembler->gpuIndirectBuffer->vkBuffer, - j * sizeof(VkDrawIndirectCommand), - 1, - sizeof(VkDrawIndirectCommand)); - } - } } - } else { - ((CCVKInputAssembler *)ia)->extractDrawInfo(drawInfo); - uint instanceCount = std::max(drawInfo.instanceCount, 1u); - bool hasIndexBuffer = gpuInputAssembler->gpuIndexBuffer && drawInfo.indexCount >= 0; + } + } else { + ((CCVKInputAssembler *)ia)->extractDrawInfo(drawInfo); + uint instanceCount = std::max(drawInfo.instanceCount, 1u); + bool hasIndexBuffer = gpuInputAssembler->gpuIndexBuffer && drawInfo.indexCount >= 0; - if (hasIndexBuffer) { - vkCmdDrawIndexed(_gpuCommandBuffer->vkCommandBuffer, drawInfo.indexCount, instanceCount, - drawInfo.firstIndex, drawInfo.vertexOffset, drawInfo.firstInstance); - } else { - vkCmdDraw(_gpuCommandBuffer->vkCommandBuffer, drawInfo.vertexCount, instanceCount, - drawInfo.firstVertex, drawInfo.firstInstance); - } + if (hasIndexBuffer) { + vkCmdDrawIndexed(_gpuCommandBuffer->vkCommandBuffer, drawInfo.indexCount, instanceCount, + drawInfo.firstIndex, drawInfo.vertexOffset, drawInfo.firstInstance); + } else { + vkCmdDraw(_gpuCommandBuffer->vkCommandBuffer, drawInfo.vertexCount, instanceCount, + drawInfo.firstVertex, drawInfo.firstInstance); + } - ++_numDrawCalls; - _numInstances += drawInfo.instanceCount; - if (_curGPUPipelineState) { - uint indexCount = hasIndexBuffer ? drawInfo.indexCount : drawInfo.vertexCount; - switch (_curGPUPipelineState->primitive) { - case PrimitiveMode::TRIANGLE_LIST: - _numTriangles += indexCount / 3 * instanceCount; - break; - case PrimitiveMode::TRIANGLE_STRIP: - case PrimitiveMode::TRIANGLE_FAN: - _numTriangles += (indexCount - 2) * instanceCount; - break; - default: break; - } + ++_numDrawCalls; + _numInstances += drawInfo.instanceCount; + if (_curGPUPipelineState) { + uint indexCount = hasIndexBuffer ? drawInfo.indexCount : drawInfo.vertexCount; + switch (_curGPUPipelineState->primitive) { + case PrimitiveMode::TRIANGLE_LIST: + _numTriangles += indexCount / 3 * instanceCount; + break; + case PrimitiveMode::TRIANGLE_STRIP: + case PrimitiveMode::TRIANGLE_FAN: + _numTriangles += (indexCount - 2) * instanceCount; + break; + default: break; } } - } else { - CC_LOG_ERROR("Command 'draw' must be recorded inside a render pass."); } } -void CCVKCommandBuffer::execute(const CommandBufferList &cmdBuffs, uint count) { +void CCVKCommandBuffer::execute(const CommandBuffer *const *cmdBuffs, uint count) { if (!count) { return; } @@ -378,24 +353,63 @@ void CCVKCommandBuffer::execute(const CommandBufferList &cmdBuffs, uint count) { } void CCVKCommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint offset) { - if ((_type == CommandBufferType::PRIMARY && !_curGPUFBO) || - (_type == CommandBufferType::SECONDARY)) { - CCVKCmdFuncUpdateBuffer((CCVKDevice *)_device, ((CCVKBuffer *)buff)->gpuBuffer(), data, offset, size); - } else { - CC_LOG_ERROR("Command 'updateBuffer' must be recorded outside a render pass."); - } + CCVKCmdFuncUpdateBuffer((CCVKDevice *)_device, ((CCVKBuffer *)buff)->gpuBuffer(), data, offset, size); } -void CCVKCommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { - if ((_type == CommandBufferType::PRIMARY && !_curGPUFBO) || - (_type == CommandBufferType::SECONDARY)) { - //const CCVKGPUBuffer* gpuBuffer = ((CCVKBuffer*)src)->gpuBuffer(); - //const CCVKGPUTexture* gpuTexture = ((CCVKTexture*)dst)->gpuTexture(); - //vkCmdCopyBufferToImage(_gpuCommandBuffer->vkCommandBuffer, gpuBuffer->vkBuffer, gpuTexture->vkImage, MapVkImageLayout(layout), - // regions.size(), regions.data()); - } else { - CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass."); +void CCVKCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { + //const CCVKGPUBuffer* gpuBuffer = ((CCVKBuffer*)src)->gpuBuffer(); + //const CCVKGPUTexture* gpuTexture = ((CCVKTexture*)dst)->gpuTexture(); + //vkCmdCopyBufferToImage(_gpuCommandBuffer->vkCommandBuffer, gpuBuffer->vkBuffer, gpuTexture->vkImage, MapVkImageLayout(layout), + // regions.size(), regions.data()); +} + +void CCVKCommandBuffer::doBindDescriptorSet() { + + CCVKDevice *device = (CCVKDevice *)_device; + CCVKGPUDevice *gpuDevice = device->gpuDevice(); + VkCommandBuffer cmdBuff = _gpuCommandBuffer->vkCommandBuffer; + CCVKGPUPipelineLayout *pipelineLayout = _curGPUPipelineState->gpuPipelineLayout; + uint dirtyDescriptorSetCount = _curGPUDescriptorSets.size() - _firstDirtyDescriptorSet; + uint dynamicOffsetStartIndex = pipelineLayout->dynamicOffsetOffsets[_firstDirtyDescriptorSet]; + uint dynamicOffsetCount = pipelineLayout->dynamicOffsetCount - dynamicOffsetStartIndex; + uint *dynamicOffsets = pipelineLayout->dynamicOffsets.data() + dynamicOffsetStartIndex; + + const vector &layouts = _curGPUPipelineState->gpuPipelineLayout->descriptorSetLayouts; + vector &sets = _curGPUPipelineState->gpuPipelineLayout->descriptorSets; + device->gpuDescriptorSetPool()->alloc(layouts.data() + _firstDirtyDescriptorSet, + sets.data() + _firstDirtyDescriptorSet, + dirtyDescriptorSetCount); + + for (uint i = 0u, offsetAcc = 0u; i < dirtyDescriptorSetCount; i++) { + uint set = _firstDirtyDescriptorSet + i; + CCVKGPUDescriptorSet *gpuDescriptorSet = _curGPUDescriptorSets[set]; + if (!gpuDescriptorSet || !gpuDescriptorSet->gpuDescriptors.size()) continue; + + if (gpuDevice->useDescriptorUpdateTemplate) { + const vector &descriptorInfos = gpuDescriptorSet->descriptorInfos; + const vector &templates = pipelineLayout->vkDescriptorUpdateTemplates; + vkUpdateDescriptorSetWithTemplateKHR(device->gpuDevice()->vkDevice, sets[set], templates[set], descriptorInfos.data()); + } else { + vector &entries = gpuDescriptorSet->descriptorUpdateEntries; + + for (uint j = 0u; j < entries.size(); j++) { + entries[j].dstSet = sets[set]; + } + vkUpdateDescriptorSets(device->gpuDevice()->vkDevice, entries.size(), entries.data(), 0, nullptr); + } + + uint offsetCount = pipelineLayout->dynamicOffsetOffsets[set + 1] - dynamicOffsetStartIndex; + if (_curDynamicOffsets[set].size() && offsetCount > 0) { + memcpy(dynamicOffsets + offsetAcc, _curDynamicOffsets[set].data(), offsetCount * sizeof(uint)); + offsetAcc += offsetCount; + } } + + vkCmdBindDescriptorSets(cmdBuff, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout->vkPipelineLayout, + _firstDirtyDescriptorSet, dirtyDescriptorSetCount, sets.data() + _firstDirtyDescriptorSet, + dynamicOffsetCount, dynamicOffsets); + + _firstDirtyDescriptorSet = UINT_MAX; } } // namespace gfx diff --git a/cocos/renderer/gfx-vulkan/VKCommandBuffer.h b/cocos/renderer/gfx-vulkan/VKCommandBuffer.h index 47463e0218c..a61f48c3e6e 100644 --- a/cocos/renderer/gfx-vulkan/VKCommandBuffer.h +++ b/cocos/renderer/gfx-vulkan/VKCommandBuffer.h @@ -14,36 +14,41 @@ class CC_VULKAN_API CCVKCommandBuffer : public CommandBuffer { friend class CCVKQueue; public: - bool initialize(const CommandBufferInfo &info); - void destroy(); - - void begin(RenderPass *renderPass = nullptr, uint subpass = 0, Framebuffer *frameBuffer = nullptr); - void end(); - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector &colors, float depth, int stencil); - void endRenderPass(); - void bindPipelineState(PipelineState *pso); - void bindBindingLayout(BindingLayout *layout); - void bindInputAssembler(InputAssembler *ia); - void setViewport(const Viewport &vp); - void setScissor(const Rect &rect); - void setLineWidth(const float width); - void setDepthBias(float constant, float clamp, float slope); - void setBlendConstants(const Color &constants); - void setDepthBound(float min_bounds, float max_bounds); - void setStencilWriteMask(StencilFace face, uint mask); - void setStencilCompareMask(StencilFace face, int reference, uint mask); - void draw(InputAssembler *ia); - void updateBuffer(Buffer *buff, void *data, uint size, uint offset); - void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions); - void execute(const CommandBufferList &cmd_buffs, uint count); + virtual bool initialize(const CommandBufferInfo &info) override; + virtual void destroy() override; + + virtual void begin(RenderPass *renderPass = nullptr, uint subpass = 0, Framebuffer *frameBuffer = nullptr) override; + virtual void end() override; + virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) override; + virtual void endRenderPass() override; + virtual void bindPipelineState(PipelineState *pso) override; + virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + virtual void bindInputAssembler(InputAssembler *ia) override; + virtual void setViewport(const Viewport &vp) override; + virtual void setScissor(const Rect &rect) override; + virtual void setLineWidth(const float width) override; + virtual void setDepthBias(float constant, float clamp, float slope) override; + virtual void setBlendConstants(const Color &constants) override; + virtual void setDepthBound(float minBounds, float maxBounds) override; + virtual void setStencilWriteMask(StencilFace face, uint mask) override; + virtual void setStencilCompareMask(StencilFace face, int reference, uint mask) override; + virtual void draw(InputAssembler *ia) override; + virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset) override; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; + virtual void execute(const CommandBuffer *const *cmdBuffs, uint count) override; CCVKGPUCommandBuffer *gpuCommandBuffer() const { return _gpuCommandBuffer; } private: + void doBindDescriptorSet(); + CCVKGPUCommandBuffer *_gpuCommandBuffer = nullptr; CCVKGPUPipelineState *_curGPUPipelineState = nullptr; - CCVKGPUBindingLayout *_curGPUBindingLayout = nullptr; + vector _curGPUDescriptorSets; + vector> _curDynamicOffsets; + uint _firstDirtyDescriptorSet = UINT_MAX; + CCVKGPUInputAssembler *_curGPUInputAssember = nullptr; CCVKGPUFramebuffer *_curGPUFBO = nullptr; diff --git a/cocos/renderer/gfx-vulkan/VKCommands.cc b/cocos/renderer/gfx-vulkan/VKCommands.cc index eb1b4771d23..990f4014fc6 100644 --- a/cocos/renderer/gfx-vulkan/VKCommands.cc +++ b/cocos/renderer/gfx-vulkan/VKCommands.cc @@ -175,8 +175,6 @@ void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { gpuBuffer->mappedData = (uint8_t *)res.pMappedData; gpuBuffer->startOffset = 0; // we are creating one VkBuffer each for now - - device->gpuDescriptorHub()->update(gpuBuffer); } void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) { @@ -316,117 +314,90 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra } } -void CCVKGPUPipelineLayoutPool::request(CCVKGPUShader *gpuShader) { - const UniformBlockList &blocks = gpuShader->blocks; - const UniformSamplerList &samplers = gpuShader->samplers; - const uint bindingCount = blocks.size() + samplers.size(); - - uint seed = bindingCount; - for (size_t i = 0u; i < blocks.size(); i++) { - const UniformBlock &block = blocks[i]; - uint hash = block.binding | ((uint)block.shaderStages << 16); - seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); - } - for (size_t i = 0u; i < samplers.size(); i++) { - const UniformSampler sampler = samplers[i]; - uint hash = sampler.binding | ((uint)sampler.shaderStages << 16) | (sampler.count << 22); - seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); +void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { + for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { + vector spirv = GLSL2SPIRV(stage.type, "#version 450\n" + stage.source, ((CCVKContext *)device->getContext())->minorVersion()); + VkShaderModuleCreateInfo createInfo{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; + createInfo.codeSize = spirv.size() * sizeof(unsigned int); + createInfo.pCode = spirv.data(); + VK_CHECK(vkCreateShaderModule(device->gpuDevice()->vkDevice, &createInfo, nullptr, &stage.vkShader)); } + CC_LOG_INFO("Shader '%s' compilation succeeded.", gpuShader->name.c_str()); +} - if (_pool.count(seed)) { - gpuShader->pipelineLayout = &_pool[seed]; - return; - } +void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout) { + CCVKGPUDevice *gpuDevice = device->gpuDevice(); + size_t bindingCount = gpuDescriptorSetLayout->bindings.size(); - _pool.emplace(std::piecewise_construct, std::forward_as_tuple(seed), std::forward_as_tuple()); - - CCVKGPUPipelineLayout &pipelineLayout = _pool[seed]; - - pipelineLayout.vkDescriptorSetLayouts.resize(1); - pipelineLayout.descriptorCounts.resize(1); - pipelineLayout.descriptorIndices.resize(1); - pipelineLayout.descriptorIndices[0].resize(bindingCount); - - vector setBindings(bindingCount); - for (size_t i = 0u; i < blocks.size(); i++) { - const UniformBlock &binding = blocks[i]; - VkDescriptorSetLayoutBinding &setBinding = setBindings[i]; - setBinding.stageFlags = MapVkShaderStageFlags(binding.shaderStages); - setBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - setBinding.binding = binding.binding; - setBinding.descriptorCount = 1; // the effect compiler guarantees this to be non-array - pipelineLayout.descriptorIndices[0][i] = i; - } - uint descriptorCount = blocks.size(); - for (size_t i = 0u; i < samplers.size(); i++) { - const UniformSampler &binding = samplers[i]; - VkDescriptorSetLayoutBinding &setBinding = setBindings[blocks.size() + i]; - setBinding.stageFlags = MapVkShaderStageFlags(binding.shaderStages); - setBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - setBinding.binding = binding.binding; - setBinding.descriptorCount = binding.count; - pipelineLayout.descriptorIndices[0][blocks.size() + i] = descriptorCount; + uint descriptorCount = 0u; + gpuDescriptorSetLayout->vkBindings.resize(bindingCount); + gpuDescriptorSetLayout->descriptorIndices.resize(bindingCount); + for (size_t i = 0u; i < bindingCount; i++) { + const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; + VkDescriptorSetLayoutBinding &vkBinding = gpuDescriptorSetLayout->vkBindings[i]; + vkBinding.stageFlags = MapVkShaderStageFlags(binding.stageFlags); + vkBinding.descriptorType = MapVkDescriptorType(binding.descriptorType); + vkBinding.binding = i; + vkBinding.descriptorCount = binding.count; + gpuDescriptorSetLayout->descriptorIndices[i] = descriptorCount; descriptorCount += binding.count; } - pipelineLayout.descriptorCounts[0] = descriptorCount; + gpuDescriptorSetLayout->descriptorCount = descriptorCount; VkDescriptorSetLayoutCreateInfo setCreateInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; - if (_device->usePushDescriptorSet) setCreateInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR; setCreateInfo.bindingCount = bindingCount; - setCreateInfo.pBindings = setBindings.data(); - VK_CHECK(vkCreateDescriptorSetLayout(_device->vkDevice, &setCreateInfo, nullptr, &pipelineLayout.vkDescriptorSetLayouts[0])); + setCreateInfo.pBindings = gpuDescriptorSetLayout->vkBindings.data(); + VK_CHECK(vkCreateDescriptorSetLayout(gpuDevice->vkDevice, &setCreateInfo, nullptr, &gpuDescriptorSetLayout->vkDescriptorSetLayout)); +} - VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; - pipelineLayoutCreateInfo.setLayoutCount = pipelineLayout.vkDescriptorSetLayouts.size(); - pipelineLayoutCreateInfo.pSetLayouts = pipelineLayout.vkDescriptorSetLayouts.data(); - VK_CHECK(vkCreatePipelineLayout(_device->vkDevice, &pipelineLayoutCreateInfo, nullptr, &pipelineLayout.vkPipelineLayout)); - - if (_device->useDescriptorUpdateTemplate) { - pipelineLayout.vkDescriptorUpdateTemplates.resize(1); - - vector entries(bindingCount); - for (size_t i = 0u, j = 0u; i < bindingCount; i++) { - VkDescriptorSetLayoutBinding &binding = setBindings[i]; - if (binding.descriptorType != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { - entries[i].dstBinding = binding.binding; - entries[i].dstArrayElement = 0; - entries[i].descriptorCount = binding.descriptorCount; - entries[i].descriptorType = binding.descriptorType; - entries[i].offset = sizeof(CCVKGPUDescriptorInfo) * j; - entries[i].stride = sizeof(CCVKGPUDescriptorInfo); - j += binding.descriptorCount; - } // TODO: inline UBOs - } +void CCVKCmdFuncCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout) { + CCVKGPUDevice *gpuDevice = device->gpuDevice(); + size_t layoutCount = gpuPipelineLayout->setLayouts.size(); - VkDescriptorUpdateTemplateCreateInfo createInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO}; - createInfo.descriptorUpdateEntryCount = bindingCount; - createInfo.pDescriptorUpdateEntries = entries.data(); - if (_device->usePushDescriptorSet) { - createInfo.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR; - createInfo.descriptorSetLayout = VK_NULL_HANDLE; - } else { - createInfo.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET; - createInfo.descriptorSetLayout = pipelineLayout.vkDescriptorSetLayouts[0]; - } - createInfo.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; - createInfo.pipelineLayout = pipelineLayout.vkPipelineLayout; - VK_CHECK(vkCreateDescriptorUpdateTemplateKHR(_device->vkDevice, &createInfo, nullptr, &pipelineLayout.vkDescriptorUpdateTemplates[0])); + gpuPipelineLayout->descriptorSets.resize(layoutCount); + gpuPipelineLayout->descriptorSetLayouts.resize(layoutCount); + for (uint i = 0; i < layoutCount; i++) { + gpuPipelineLayout->descriptorSetLayouts[i] = gpuPipelineLayout->setLayouts[i]->vkDescriptorSetLayout; } - gpuShader->pipelineLayout = &pipelineLayout; -} -void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { - for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { - vector spirv = GLSL2SPIRV(stage.type, "#version 450\n" + stage.source, ((CCVKContext *)device->getContext())->minorVersion()); - VkShaderModuleCreateInfo createInfo{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; - createInfo.codeSize = spirv.size() * sizeof(unsigned int); - createInfo.pCode = spirv.data(); - VK_CHECK(vkCreateShaderModule(device->gpuDevice()->vkDevice, &createInfo, nullptr, &stage.vkShader)); - } - CC_LOG_INFO("Shader '%s' compilation succeeded.", gpuShader->name.c_str()); + VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; + pipelineLayoutCreateInfo.setLayoutCount = layoutCount; + pipelineLayoutCreateInfo.pSetLayouts = gpuPipelineLayout->descriptorSetLayouts.data(); + VK_CHECK(vkCreatePipelineLayout(gpuDevice->vkDevice, &pipelineLayoutCreateInfo, nullptr, &gpuPipelineLayout->vkPipelineLayout)); + + if (gpuDevice->useDescriptorUpdateTemplate) { + gpuPipelineLayout->vkDescriptorUpdateTemplates.resize(layoutCount); + + for (uint i = 0; i < layoutCount; i++) { + const vector &bindings = gpuPipelineLayout->setLayouts[i]->vkBindings; + uint bindingCount = bindings.size(); + if (!bindingCount) continue; + + vector 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 + } - device->gpuPipelineLayoutPool()->request(gpuShader); + 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 = gpuPipelineLayout->setLayouts[i]->vkDescriptorSetLayout; + createInfo.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + createInfo.pipelineLayout = gpuPipelineLayout->vkPipelineLayout; + VK_CHECK(vkCreateDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, &createInfo, nullptr, &gpuPipelineLayout->vkDescriptorUpdateTemplates[i])); + } + } } void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) { @@ -488,7 +459,7 @@ void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gp break; } } - if (!attributeFound) { //handle absent attribute + if (!attributeFound) { // handle absent attribute attributeDescriptions[i].location = shaderAttrs[i].location; attributeDescriptions[i].format = MapVkFormat(shaderAttrs[i].format); attributeDescriptions[i].offset = 0; // reuse the first attribute as dummy data @@ -613,7 +584,7 @@ void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gp ///////////////////// References ///////////////////// - createInfo.layout = gpuPipelineState->gpuShader->pipelineLayout->vkPipelineLayout; + createInfo.layout = gpuPipelineState->gpuPipelineLayout->vkPipelineLayout; createInfo.renderPass = gpuPipelineState->gpuRenderPass->vkRenderPass; ///////////////////// Creation ///////////////////// @@ -682,7 +653,7 @@ void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void } } -void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const BufferDataList &buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { +void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { device->gpuTransportHub()->checkIn([&](VkCommandBuffer cmdBuff) { //bool isCompressed = GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed; @@ -701,9 +672,9 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const BufferDataList &b vkCmdPipelineBarrier(cmdBuff, gpuTexture->targetStage, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, barriers); - uint regionCount = regions.size(), totalSize = 0u; - vector regionSizes(regionCount); - for (size_t i = 0u; i < regionCount; ++i) { + uint totalSize = 0u; + vector regionSizes(count); + for (size_t i = 0u; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; uint w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; uint h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; @@ -715,9 +686,9 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const BufferDataList &b uint texelSize = GFX_FORMAT_INFOS[(uint)gpuTexture->format].size; device->gpuStagingBufferPool()->alloc(&stagingBuffer, texelSize); - vector stagingRegions(regionCount); + vector stagingRegions(count); VkDeviceSize offset = 0; - for (size_t i = 0u; i < regionCount; ++i) { + for (size_t i = 0u; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; VkBufferImageCopy &stagingRegion = stagingRegions[i]; stagingRegion.bufferOffset = stagingBuffer.startOffset + offset; @@ -831,7 +802,6 @@ void CCVKCmdFuncDestroyShader(CCVKGPUDevice *gpuDevice, CCVKGPUShader *gpuShader vkDestroyShaderModule(gpuDevice->vkDevice, stage.vkShader, nullptr); stage.vkShader = VK_NULL_HANDLE; } - gpuShader->pipelineLayout = nullptr; } void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer *gpuFramebuffer) { @@ -853,6 +823,27 @@ void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer } } +void CCVKCmdFuncDestroyDescriptorSetLayout(CCVKGPUDevice *gpuDevice, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout) { + if (gpuDescriptorSetLayout->vkDescriptorSetLayout != VK_NULL_HANDLE) { + vkDestroyDescriptorSetLayout(gpuDevice->vkDevice, gpuDescriptorSetLayout->vkDescriptorSetLayout, nullptr); + gpuDescriptorSetLayout->vkDescriptorSetLayout = VK_NULL_HANDLE; + } +} + +void CCVKCmdFuncDestroyPipelineLayout(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineLayout *gpuPipelineLayout) { + for (VkDescriptorUpdateTemplate updateTemplate : gpuPipelineLayout->vkDescriptorUpdateTemplates) { + if (updateTemplate != VK_NULL_HANDLE) { + vkDestroyDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, updateTemplate, nullptr); + } + } + gpuPipelineLayout->vkDescriptorUpdateTemplates.clear(); + + if (gpuPipelineLayout->vkPipelineLayout != VK_NULL_HANDLE) { + vkDestroyPipelineLayout(gpuDevice->vkDevice, gpuPipelineLayout->vkPipelineLayout, nullptr); + gpuPipelineLayout->vkPipelineLayout = VK_NULL_HANDLE; + } +} + void CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineState *gpuPipelineState) { if (gpuPipelineState->vkPipeline != VK_NULL_HANDLE) { vkDestroyPipeline(gpuDevice->vkDevice, gpuPipelineState->vkPipeline, nullptr); @@ -871,62 +862,76 @@ void CCVKGPURecycleBin::clear() { for (uint i = 0u; i < _count; i++) { Resource &res = _resources[i]; switch (res.type) { - case ObjectType::BUFFER: + case RecycledType::BUFFER: if (res.buffer.vkBuffer) { vmaDestroyBuffer(_device->memoryAllocator, res.buffer.vkBuffer, res.buffer.vmaAllocation); res.buffer.vkBuffer = VK_NULL_HANDLE; res.buffer.vmaAllocation = VK_NULL_HANDLE; } break; - case ObjectType::TEXTURE: + case RecycledType::TEXTURE: if (res.image.vkImage) { vmaDestroyImage(_device->memoryAllocator, res.image.vkImage, res.image.vmaAllocation); res.image.vkImage = VK_NULL_HANDLE; res.image.vmaAllocation = VK_NULL_HANDLE; } break; - case ObjectType::TEXTURE_VIEW: + case RecycledType::TEXTURE_VIEW: if (res.vkImageView) { vkDestroyImageView(_device->vkDevice, res.vkImageView, nullptr); res.vkImageView = VK_NULL_HANDLE; } break; - case ObjectType::RENDER_PASS: + case RecycledType::RENDER_PASS: if (res.gpuRenderPass) { CCVKCmdFuncDestroyRenderPass(_device, res.gpuRenderPass); CC_DELETE(res.gpuRenderPass); res.gpuRenderPass = nullptr; } break; - case ObjectType::FRAMEBUFFER: + case RecycledType::FRAMEBUFFER: if (res.gpuFramebuffer) { CCVKCmdFuncDestroyFramebuffer(_device, res.gpuFramebuffer); CC_DELETE(res.gpuFramebuffer); res.gpuFramebuffer = nullptr; } break; - case ObjectType::SAMPLER: + case RecycledType::SAMPLER: if (res.gpuSampler) { CCVKCmdFuncDestroySampler(_device, res.gpuSampler); CC_DELETE(res.gpuSampler); res.gpuSampler = nullptr; } break; - case ObjectType::SHADER: + case RecycledType::SHADER: if (res.gpuShader) { CCVKCmdFuncDestroyShader(_device, res.gpuShader); CC_DELETE(res.gpuShader); res.gpuShader = nullptr; } break; - case ObjectType::PIPELINE_STATE: + case RecycledType::DESCRIPTOR_SET_LAYOUT: + if (res.gpuDescriptorSetLayout) { + CCVKCmdFuncDestroyDescriptorSetLayout(_device, res.gpuDescriptorSetLayout); + CC_DELETE(res.gpuDescriptorSetLayout); + res.gpuDescriptorSetLayout = nullptr; + } + break; + case RecycledType::PIPELINE_LAYOUT: + if (res.gpuPipelineLayout) { + CCVKCmdFuncDestroyPipelineLayout(_device, res.gpuPipelineLayout); + CC_DELETE(res.gpuPipelineLayout); + res.gpuPipelineLayout = nullptr; + } + break; + case RecycledType::PIPELINE_STATE: if (res.gpuPipelineState) { CCVKCmdFuncDestroyPipelineState(_device, res.gpuPipelineState); CC_DELETE(res.gpuPipelineState); res.gpuPipelineState = nullptr; } break; - case ObjectType::FENCE: + case RecycledType::FENCE: if (res.gpuFence) { CCVKCmdFuncDestroyFence(_device, res.gpuFence); CC_DELETE(res.gpuFence); @@ -935,7 +940,7 @@ void CCVKGPURecycleBin::clear() { break; default: break; } - res.type = ObjectType::UNKNOWN; + res.type = RecycledType::UNKNOWN; } _count = 0; } diff --git a/cocos/renderer/gfx-vulkan/VKCommands.h b/cocos/renderer/gfx-vulkan/VKCommands.h index 62e6ba0a04a..1a9c89adb1a 100644 --- a/cocos/renderer/gfx-vulkan/VKCommands.h +++ b/cocos/renderer/gfx-vulkan/VKCommands.h @@ -39,16 +39,20 @@ CC_VULKAN_API void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gp CC_VULKAN_API void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass); CC_VULKAN_API void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); CC_VULKAN_API void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader); +CC_VULKAN_API void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout); +CC_VULKAN_API void CCVKCmdFuncCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout); CC_VULKAN_API void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); CC_VULKAN_API void CCVKCmdFuncCreateFence(CCVKDevice *device, CCVKGPUFence *gpuFence); CC_VULKAN_API void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size); -CC_VULKAN_API void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const BufferDataList &buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions); +CC_VULKAN_API void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count); CC_VULKAN_API void CCVKCmdFuncDestroyRenderPass(CCVKGPUDevice *device, CCVKGPURenderPass *gpuRenderPass); CC_VULKAN_API void CCVKCmdFuncDestroySampler(CCVKGPUDevice *device, CCVKGPUSampler *gpuSampler); CC_VULKAN_API void CCVKCmdFuncDestroyShader(CCVKGPUDevice *device, CCVKGPUShader *gpuShader); CC_VULKAN_API void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); +CC_VULKAN_API void CCVKCmdFuncDestroyDescriptorSetLayout(CCVKGPUDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout); +CC_VULKAN_API void CCVKCmdFuncDestroyPipelineLayout(CCVKGPUDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout); CC_VULKAN_API void CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *device, CCVKGPUPipelineState *gpuPipelineState); CC_VULKAN_API void CCVKCmdFuncDestroyFence(CCVKGPUDevice *device, CCVKGPUFence *gpuFence); diff --git a/cocos/renderer/gfx-vulkan/VKContext.cc b/cocos/renderer/gfx-vulkan/VKContext.cc index 82527cacf06..b3e18e13695 100644 --- a/cocos/renderer/gfx-vulkan/VKContext.cc +++ b/cocos/renderer/gfx-vulkan/VKContext.cc @@ -300,7 +300,6 @@ bool CCVKContext::initialize(const ContextInfo &info) { vkGetPhysicalDeviceFeatures(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceFeatures); if (_minorVersion >= 1 || checkExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) { - _gpuContext->physicalDeviceProperties2.pNext = &_gpuContext->physicalDevicePushDescriptorProperties; vkGetPhysicalDeviceProperties2KHR(_gpuContext->physicalDevice, &_gpuContext->physicalDeviceProperties2); _gpuContext->physicalDeviceFeatures2.pNext = &_gpuContext->physicalDeviceVulkan11Features; diff --git a/cocos/renderer/gfx-vulkan/VKDescriptorSet.cc b/cocos/renderer/gfx-vulkan/VKDescriptorSet.cc new file mode 100644 index 00000000000..e26b5a452bf --- /dev/null +++ b/cocos/renderer/gfx-vulkan/VKDescriptorSet.cc @@ -0,0 +1,177 @@ +#include "VKStd.h" + +#include "VKBuffer.h" +#include "VKCommands.h" +#include "VKDescriptorSet.h" +#include "VKDescriptorSetLayout.h" +#include "VKDevice.h" +#include "VKSampler.h" +#include "VKShader.h" +#include "VKTexture.h" + +namespace cc { +namespace gfx { + +CCVKDescriptorSet::CCVKDescriptorSet(Device *device) +: DescriptorSet(device) { +} + +CCVKDescriptorSet::~CCVKDescriptorSet() { +} + +bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) { + + _layout = info.layout; + + const CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = ((CCVKDescriptorSetLayout *)_layout)->gpuDescriptorSetLayout(); + const uint bindingCount = gpuDescriptorSetLayout->bindings.size(); + const uint descriptorCount = gpuDescriptorSetLayout->descriptorCount; + + _buffers.resize(bindingCount); + _textures.resize(bindingCount); + _samplers.resize(bindingCount); + + CCVKGPUDevice *gpuDevice = ((CCVKDevice *)_device)->gpuDevice(); + _gpuDescriptorSet = CC_NEW(CCVKGPUDescriptorSet); + _gpuDescriptorSet->gpuDescriptors.resize(bindingCount); + _gpuDescriptorSet->descriptorInfos.resize(bindingCount); + for (size_t i = 0u; i < bindingCount; i++) { + const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; + _gpuDescriptorSet->gpuDescriptors[i].type = binding.descriptorType; + if ((uint)binding.descriptorType & DESCRIPTOR_BUFFER_TYPE) { + _gpuDescriptorSet->descriptorInfos[i].buffer.buffer = gpuDevice->defaultBuffer.vkBuffer; + _gpuDescriptorSet->descriptorInfos[i].buffer.offset = gpuDevice->defaultBuffer.startOffset; + _gpuDescriptorSet->descriptorInfos[i].buffer.range = gpuDevice->defaultBuffer.size; + } else if ((uint)binding.descriptorType & DESCRIPTOR_SAMPLER_TYPE) { + _gpuDescriptorSet->descriptorInfos[i].image.sampler = gpuDevice->defaultSampler.vkSampler; + _gpuDescriptorSet->descriptorInfos[i].image.imageView = gpuDevice->defaultTextureView.vkImageView; + _gpuDescriptorSet->descriptorInfos[i].image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + } + } + + if (!gpuDevice->useDescriptorUpdateTemplate) { + vector &entries = _gpuDescriptorSet->descriptorUpdateEntries; + entries.resize(descriptorCount, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}); + + 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].dstBinding = descriptor.binding; + entries[j].dstArrayElement = k; + entries[j].descriptorCount = 1; + entries[j].descriptorType = descriptor.descriptorType; + switch (entries[j].descriptorType) { + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: + entries[j].pBufferInfo = &_gpuDescriptorSet->descriptorInfos[j].buffer; + break; + case VK_DESCRIPTOR_TYPE_SAMPLER: + case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: + case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: + case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: + case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: + entries[j].pImageInfo = &_gpuDescriptorSet->descriptorInfos[j].image; + break; + case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: + entries[j].pTexelBufferView = &_gpuDescriptorSet->descriptorInfos[j].texelBufferView; + break; + default: break; + } + } + } + } + + _status = Status::SUCCESS; + + return true; +} + +void CCVKDescriptorSet::destroy() { + if (_gpuDescriptorSet) { + CCVKGPUDescriptorHub *descriptorHub = ((CCVKDevice *)_device)->gpuDescriptorHub(); + const vector &indicies = ((CCVKDescriptorSetLayout *)_layout)->gpuDescriptorSetLayout()->descriptorIndices; + + for (uint i = 0u; i < _gpuDescriptorSet->gpuDescriptors.size(); i++) { + CCVKGPUDescriptor &binding = _gpuDescriptorSet->gpuDescriptors[i]; + const uint descriptorIndex = indicies[i]; + CCVKDescriptorInfo &descriptorInfo = _gpuDescriptorSet->descriptorInfos[descriptorIndex]; + if (binding.gpuBufferView) { + descriptorHub->disengage(binding.gpuBufferView, &descriptorInfo.buffer); + } + if (binding.gpuTextureView) { + descriptorHub->disengage(binding.gpuTextureView, &descriptorInfo.image); + } + if (binding.gpuSampler) { + descriptorHub->disengage(binding.gpuSampler, &descriptorInfo.image); + } + } + CC_DELETE(_gpuDescriptorSet); + _gpuDescriptorSet = nullptr; + } + + _status = Status::UNREADY; +} + +void CCVKDescriptorSet::update() { + if (_isDirty && _gpuDescriptorSet) { + CCVKGPUDescriptorHub *descriptorHub = ((CCVKDevice *)_device)->gpuDescriptorHub(); + const vector &indicies = ((CCVKDescriptorSetLayout *)_layout)->gpuDescriptorSetLayout()->descriptorIndices; + uint bindingCount = _gpuDescriptorSet->gpuDescriptors.size(); + + for (size_t i = 0u; i < bindingCount; i++) { + CCVKDescriptorInfo &descriptorInfo = _gpuDescriptorSet->descriptorInfos[indicies[i]]; + CCVKGPUDescriptor &binding = _gpuDescriptorSet->gpuDescriptors[i]; + + if ((uint)binding.type & DESCRIPTOR_BUFFER_TYPE) { + if (_buffers[i]) { + CCVKGPUBufferView *bufferView = ((CCVKBuffer *)_buffers[i])->gpuBufferView(); + if (binding.gpuBufferView != bufferView) { + if (binding.gpuBufferView) { + descriptorHub->disengage(binding.gpuBufferView, &descriptorInfo.buffer); + } + if (bufferView) { + descriptorHub->connect(bufferView, &descriptorInfo.buffer); + descriptorHub->update(bufferView, &descriptorInfo.buffer); + } + binding.gpuBufferView = bufferView; + } + } + } else if ((uint)binding.type & DESCRIPTOR_SAMPLER_TYPE) { + // TODO: handle texture arrays (need public interface changes) + if (_textures[i]) { + CCVKGPUTextureView *textureView = ((CCVKTexture *)_textures[i])->gpuTextureView(); + if (binding.gpuTextureView != textureView) { + if (binding.gpuTextureView) { + descriptorHub->disengage(binding.gpuTextureView, &descriptorInfo.image); + } + if (textureView) { + descriptorHub->connect(textureView, &descriptorInfo.image); + descriptorHub->update(textureView, &descriptorInfo.image); + } + binding.gpuTextureView = textureView; + } + } + if (_samplers[i]) { + CCVKGPUSampler *sampler = ((CCVKSampler *)_samplers[i])->gpuSampler(); + if (binding.gpuSampler != sampler) { + if (binding.gpuSampler) { + descriptorHub->disengage(binding.gpuSampler, &descriptorInfo.image); + } + if (sampler) { + descriptorHub->connect(sampler, &descriptorInfo.image); + descriptorHub->update(sampler, &descriptorInfo.image); + } + binding.gpuSampler = sampler; + } + } + } + } + _isDirty = false; + } +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-vulkan/VKDescriptorSet.h b/cocos/renderer/gfx-vulkan/VKDescriptorSet.h new file mode 100644 index 00000000000..0cef32e6625 --- /dev/null +++ b/cocos/renderer/gfx-vulkan/VKDescriptorSet.h @@ -0,0 +1,28 @@ +#ifndef CC_GFXVULKAN_CCVK_BINDING_LAYOUT_H_ +#define CC_GFXVULKAN_CCVK_BINDING_LAYOUT_H_ + +namespace cc { +namespace gfx { + +class CCVKGPUDescriptorSet; + +class CC_VULKAN_API CCVKDescriptorSet : public DescriptorSet { +public: + CCVKDescriptorSet(Device *device); + ~CCVKDescriptorSet(); + +public: + virtual bool initialize(const DescriptorSetInfo &info) override; + virtual void destroy() override; + virtual void update() override; + + CC_INLINE CCVKGPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } + +private: + CCVKGPUDescriptorSet *_gpuDescriptorSet = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif diff --git a/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cc b/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cc new file mode 100644 index 00000000000..3aec94162b4 --- /dev/null +++ b/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cc @@ -0,0 +1,50 @@ +#include "VKStd.h" + +#include "VKCommands.h" +#include "VKDescriptorSetLayout.h" +#include "VKDevice.h" + +namespace cc { +namespace gfx { + +CCVKDescriptorSetLayout::CCVKDescriptorSetLayout(Device *device) +: DescriptorSetLayout(device) { +} + +CCVKDescriptorSetLayout::~CCVKDescriptorSetLayout() { +} + +bool CCVKDescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { + + _bindings = info.bindings; + + _gpuDescriptorSetLayout = CC_NEW(CCVKGPUDescriptorSetLayout); + + for (uint i = 0u; i < _bindings.size(); i++) { + const DescriptorSetLayoutBinding &binding = _bindings[i]; + if ((uint)binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { + for (uint j = 0u; j < binding.count; j++) { + _gpuDescriptorSetLayout->dynamicBindings.push_back(i); + } + } + _gpuDescriptorSetLayout->bindings.push_back(binding); + } + + CCVKCmdFuncCreateDescriptorSetLayout((CCVKDevice *)_device, _gpuDescriptorSetLayout); + + _status = Status::SUCCESS; + + return true; +} + +void CCVKDescriptorSetLayout::destroy() { + if (_gpuDescriptorSetLayout) { + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuDescriptorSetLayout); + _gpuDescriptorSetLayout = nullptr; + } + + _status = Status::UNREADY; +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h b/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h new file mode 100644 index 00000000000..96d009db421 --- /dev/null +++ b/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h @@ -0,0 +1,27 @@ +#ifndef CC_GFXVULKAN_CCVK_DESCRIPTOR_SET_LAYOUT_H_ +#define CC_GFXVULKAN_CCVK_DESCRIPTOR_SET_LAYOUT_H_ + +namespace cc { +namespace gfx { + +class CCVKGPUDescriptorSetLayout; + +class CC_VULKAN_API CCVKDescriptorSetLayout : public DescriptorSetLayout { +public: + CCVKDescriptorSetLayout(Device *device); + ~CCVKDescriptorSetLayout(); + +public: + virtual bool initialize(const DescriptorSetLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } + +private: + CCVKGPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXVULKAN_CCVK_DESCRIPTOR_SET_LAYOUT_H_ diff --git a/cocos/renderer/gfx-vulkan/VKDevice.cc b/cocos/renderer/gfx-vulkan/VKDevice.cc index a8cd0b743ea..1b3174ce3d3 100644 --- a/cocos/renderer/gfx-vulkan/VKDevice.cc +++ b/cocos/renderer/gfx-vulkan/VKDevice.cc @@ -1,13 +1,15 @@ #include "VKStd.h" -#include "VKBindingLayout.h" #include "VKBuffer.h" #include "VKCommandBuffer.h" #include "VKContext.h" +#include "VKDescriptorSet.h" +#include "VKDescriptorSetLayout.h" #include "VKDevice.h" #include "VKFence.h" #include "VKFramebuffer.h" #include "VKInputAssembler.h" +#include "VKPipelineLayout.h" #include "VKPipelineState.h" #include "VKQueue.h" #include "VKRenderPass.h" @@ -46,6 +48,14 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { _nativeHeight = info.nativeHeight; _windowHandle = info.windowHandle; + _bindingMappingInfo = info.bindingMappingInfo; + if (!_bindingMappingInfo.bufferOffsets.size()) { + _bindingMappingInfo.bufferOffsets.push_back(0); + } + if (!_bindingMappingInfo.samplerOffsets.size()) { + _bindingMappingInfo.samplerOffsets.push_back(0); + } + ContextInfo contextCreateInfo; contextCreateInfo.windowHandle = _windowHandle; contextCreateInfo.sharedCtx = info.sharedCtx; @@ -70,7 +80,6 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { vector requestedExtensions{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, - VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, }; @@ -168,7 +177,6 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { _features[(uint)Feature::STENCIL_WRITE_MASK] = true; _gpuDevice->useMultiDrawIndirect = deviceFeatures.multiDrawIndirect; - _gpuDevice->usePushDescriptorSet = checkExtension(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); _gpuDevice->useDescriptorUpdateTemplate = checkExtension(VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME); VkFormatFeatureFlags requiredFeatures = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT; @@ -223,6 +231,7 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { _maxVertexTextureUnits = limits.maxPerStageDescriptorSampledImages; _maxTextureSize = limits.maxImageDimension2D; _maxCubeMapTextureSize = limits.maxImageDimensionCube; + _uboOffsetAlignment = (uint)limits.minUniformBufferOffsetAlignment; MapDepthStencilBits(_context->getDepthStencilFormat(), _depthBits, _stencilBits); ///////////////////// Resource Initialization ///////////////////// @@ -274,10 +283,27 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { _gpuDescriptorSetPool = CC_NEW(CCVKGPUDescriptorSetPool(_gpuDevice)); _gpuCommandBufferPool = CC_NEW(CCVKGPUCommandBufferPool(_gpuDevice)); _gpuStagingBufferPool = CC_NEW(CCVKGPUStagingBufferPool(_gpuDevice)); - _gpuPipelineLayoutPool = CC_NEW(CCVKGPUPipelineLayoutPool(_gpuDevice)); _gpuTransportHub->link(((CCVKQueue *)_queue)->gpuQueue(), _gpuFencePool, _gpuCommandBufferPool, _gpuStagingBufferPool); + CCVKCmdFuncCreateSampler(this, &_gpuDevice->defaultSampler); + + _gpuDevice->defaultTexture.format = Format::RGBA8; + _gpuDevice->defaultTexture.usage = TextureUsageBit::SAMPLED; + _gpuDevice->defaultTexture.width = _gpuDevice->defaultTexture.height = 1u; + _gpuDevice->defaultTexture.size = FormatSize(Format::RGBA8, 1u, 1u, 1u); + CCVKCmdFuncCreateTexture(this, &_gpuDevice->defaultTexture); + + _gpuDevice->defaultTextureView.gpuTexture = &_gpuDevice->defaultTexture; + _gpuDevice->defaultTextureView.format = Format::RGBA8; + CCVKCmdFuncCreateTextureView(this, &_gpuDevice->defaultTextureView); + + _gpuDevice->defaultBuffer.usage = BufferUsage::UNIFORM; + _gpuDevice->defaultBuffer.memUsage = MemoryUsage::HOST | MemoryUsage::DEVICE; + _gpuDevice->defaultBuffer.size = _gpuDevice->defaultBuffer.stride = 16u; + _gpuDevice->defaultBuffer.count = 1u; + CCVKCmdFuncCreateBuffer(this, &_gpuDevice->defaultBuffer); + for (uint i = 0u; i < gpuContext->swapchainCreateInfo.minImageCount; i++) { TextureInfo depthStencilTexInfo; depthStencilTexInfo.type = TextureType::TEX2D; @@ -366,7 +392,6 @@ void CCVKDevice::destroy() { CC_SAFE_DESTROY(_queue); CC_SAFE_DELETE(_gpuSwapchain); - CC_SAFE_DELETE(_gpuPipelineLayoutPool); CC_SAFE_DELETE(_gpuStagingBufferPool); CC_SAFE_DELETE(_gpuCommandBufferPool); CC_SAFE_DELETE(_gpuDescriptorSetPool); @@ -377,6 +402,22 @@ void CCVKDevice::destroy() { CC_SAFE_DELETE(_gpuFencePool); if (_gpuDevice) { + if (_gpuDevice->defaultBuffer.vkBuffer) { + vmaDestroyBuffer(_gpuDevice->memoryAllocator, _gpuDevice->defaultBuffer.vkBuffer, _gpuDevice->defaultBuffer.vmaAllocation); + _gpuDevice->defaultBuffer.vkBuffer = VK_NULL_HANDLE; + _gpuDevice->defaultBuffer.vmaAllocation = VK_NULL_HANDLE; + } + if (_gpuDevice->defaultTextureView.vkImageView) { + vkDestroyImageView(_gpuDevice->vkDevice, _gpuDevice->defaultTextureView.vkImageView, nullptr); + _gpuDevice->defaultTextureView.vkImageView = VK_NULL_HANDLE; + } + if (_gpuDevice->defaultTexture.vkImage) { + vmaDestroyImage(_gpuDevice->memoryAllocator, _gpuDevice->defaultTexture.vkImage, _gpuDevice->defaultTexture.vmaAllocation); + _gpuDevice->defaultTexture.vkImage = VK_NULL_HANDLE; + _gpuDevice->defaultTexture.vmaAllocation = VK_NULL_HANDLE; + } + CCVKCmdFuncDestroySampler(_gpuDevice, &_gpuDevice->defaultSampler); + if (_gpuDevice->memoryAllocator != VK_NULL_HANDLE) { VmaStats stats; vmaCalculateStats(_gpuDevice->memoryAllocator, &stats); @@ -572,6 +613,15 @@ Buffer *CCVKDevice::createBuffer(const BufferInfo &info) { return nullptr; } +Buffer *CCVKDevice::createBuffer(const BufferViewInfo &info) { + Buffer *buffer = CC_NEW(CCVKBuffer(this)); + if (buffer->initialize(info)) + return buffer; + + CC_SAFE_DESTROY(buffer); + return nullptr; +} + Texture *CCVKDevice::createTexture(const TextureInfo &info) { Texture *texture = CC_NEW(CCVKTexture(this)); if (texture->initialize(info)) @@ -635,12 +685,30 @@ Framebuffer *CCVKDevice::createFramebuffer(const FramebufferInfo &info) { return nullptr; } -BindingLayout *CCVKDevice::createBindingLayout(const BindingLayoutInfo &info) { - BindingLayout *bindingLayout = CC_NEW(CCVKBindingLayout(this)); - if (bindingLayout->initialize(info)) - return bindingLayout; +DescriptorSet *CCVKDevice::createDescriptorSet(const DescriptorSetInfo &info) { + DescriptorSet *descriptorSet = CC_NEW(CCVKDescriptorSet(this)); + if (descriptorSet->initialize(info)) + return descriptorSet; + + CC_SAFE_DESTROY(descriptorSet); + return nullptr; +} + +DescriptorSetLayout *CCVKDevice::createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) { + DescriptorSetLayout *descriptorSetLayout = CC_NEW(CCVKDescriptorSetLayout(this)); + if (descriptorSetLayout->initialize(info)) + return descriptorSetLayout; + + CC_SAFE_DESTROY(descriptorSetLayout); + return nullptr; +} + +PipelineLayout *CCVKDevice::createPipelineLayout(const PipelineLayoutInfo &info) { + PipelineLayout *pipelineLayout = CC_NEW(CCVKPipelineLayout(this)); + if (pipelineLayout->initialize(info)) + return pipelineLayout; - CC_SAFE_DESTROY(bindingLayout); + CC_SAFE_DESTROY(pipelineLayout); return nullptr; } @@ -653,8 +721,8 @@ PipelineState *CCVKDevice::createPipelineState(const PipelineStateInfo &info) { return nullptr; } -void CCVKDevice::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - CCVKCmdFuncCopyBuffersToTexture(this, buffers, ((CCVKTexture *)dst)->gpuTexture(), regions); +void CCVKDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { + CCVKCmdFuncCopyBuffersToTexture(this, buffers, ((CCVKTexture *)dst)->gpuTexture(), regions, count); } } // namespace gfx diff --git a/cocos/renderer/gfx-vulkan/VKDevice.h b/cocos/renderer/gfx-vulkan/VKDevice.h index fa56a72f5a8..81fa46f96e6 100644 --- a/cocos/renderer/gfx-vulkan/VKDevice.h +++ b/cocos/renderer/gfx-vulkan/VKDevice.h @@ -20,7 +20,6 @@ class CCVKGPUSemaphorePool; class CCVKGPUDescriptorSetPool; class CCVKGPUCommandBufferPool; class CCVKGPUStagingBufferPool; -class CCVKGPUPipelineLayoutPool; class CC_VULKAN_API CCVKDevice : public Device { public: @@ -37,6 +36,7 @@ class CC_VULKAN_API CCVKDevice : public Device { virtual Fence *createFence(const FenceInfo &info) override; virtual Queue *createQueue(const QueueInfo &info) override; virtual Buffer *createBuffer(const BufferInfo &info) override; + virtual Buffer *createBuffer(const BufferViewInfo &info) override; virtual Texture *createTexture(const TextureInfo &info) override; virtual Texture *createTexture(const TextureViewInfo &info) override; virtual Sampler *createSampler(const SamplerInfo &info) override; @@ -44,9 +44,11 @@ class CC_VULKAN_API CCVKDevice : public Device { virtual InputAssembler *createInputAssembler(const InputAssemblerInfo &info) override; virtual RenderPass *createRenderPass(const RenderPassInfo &info) override; virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; - virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; + virtual DescriptorSet *createDescriptorSet(const DescriptorSetInfo &info) override; + virtual DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) override; + virtual PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; CC_INLINE bool checkExtension(const String &extension) const { return std::find_if(_extensions.begin(), _extensions.end(), @@ -54,6 +56,7 @@ class CC_VULKAN_API CCVKDevice : public Device { return std::strcmp(device_extension, extension.c_str()) == 0; }) != _extensions.end(); } + CC_INLINE const BindingMappingInfo &bindingMappingInfo() const { return _bindingMappingInfo; } CCVKGPUContext *gpuContext() const; CC_INLINE CCVKGPUDevice *gpuDevice() const { return _gpuDevice; } @@ -67,7 +70,6 @@ class CC_VULKAN_API CCVKDevice : public Device { CC_INLINE CCVKGPUDescriptorSetPool *gpuDescriptorSetPool() { return _gpuDescriptorSetPool; } CC_INLINE CCVKGPUCommandBufferPool *gpuCommandBufferPool() { return _gpuCommandBufferPool; } CC_INLINE CCVKGPUStagingBufferPool *gpuStagingBufferPool() { return _gpuStagingBufferPool; } - CC_INLINE CCVKGPUPipelineLayoutPool *gpuPipelineLayoutPool() { return _gpuPipelineLayoutPool; } private: void buildSwapchain(); @@ -84,8 +86,8 @@ class CC_VULKAN_API CCVKDevice : public Device { CCVKGPUDescriptorSetPool *_gpuDescriptorSetPool = nullptr; CCVKGPUCommandBufferPool *_gpuCommandBufferPool = nullptr; CCVKGPUStagingBufferPool *_gpuStagingBufferPool = nullptr; - CCVKGPUPipelineLayoutPool *_gpuPipelineLayoutPool = nullptr; + BindingMappingInfo _bindingMappingInfo; vector _layers; vector _extensions; diff --git a/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/cocos/renderer/gfx-vulkan/VKGPUObjects.h index e105804b32c..197224cc44a 100644 --- a/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -19,7 +19,6 @@ class CCVKGPUContext : public Object { VkPhysicalDeviceVulkan12Features physicalDeviceVulkan12Features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; VkPhysicalDeviceProperties physicalDeviceProperties{}; VkPhysicalDeviceProperties2 physicalDeviceProperties2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2}; - VkPhysicalDevicePushDescriptorPropertiesKHR physicalDevicePushDescriptorProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR}; VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties{}; vector queueFamilyProperties; vector queueFamilyPresentables; @@ -28,19 +27,6 @@ class CCVKGPUContext : public Object { VkSwapchainCreateInfoKHR swapchainCreateInfo{VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR}; }; - -class CCVKGPUDevice : public Object { -public: - VkDevice vkDevice = VK_NULL_HANDLE; - vector layers; - vector extensions; - VmaAllocator memoryAllocator = VK_NULL_HANDLE; - - bool useDescriptorUpdateTemplate = false; - bool usePushDescriptorSet = false; - bool useMultiDrawIndirect = false; -}; - class CCVKGPURenderPass : public Object { public: ColorAttachmentList colorAttachments; @@ -130,6 +116,13 @@ class CCVKGPUBuffer : public Object { }; typedef vector CCVKGPUBufferList; +class CCVKGPUBufferView : public Object { +public: + CCVKGPUBuffer *gpuBuffer = nullptr; + uint offset = 0u; + uint range = 0u; +}; + class CCVKGPUSwapchain; class CCVKGPUFramebuffer : public Object { public: @@ -177,23 +170,15 @@ class CCVKGPUQueue : public Object { }; struct CCVKGPUShaderStage { - CCVKGPUShaderStage(ShaderType t, String s, ShaderMacroList m) - : type(t), source(s), macros(m) { + CCVKGPUShaderStage(ShaderStageFlagBit t, String s) + : type(t), source(s) { } - ShaderType type; + ShaderStageFlagBit type; String source; - ShaderMacroList macros; VkShaderModule vkShader = VK_NULL_HANDLE; }; typedef vector CCVKGPUShaderStageList; -struct CCVKGPUPipelineLayout { - vector vkDescriptorSetLayouts; - vector vkDescriptorUpdateTemplates; - VkPipelineLayout vkPipelineLayout = VK_NULL_HANDLE; - vector> descriptorIndices; - vector descriptorCounts; -}; class CCVKGPUShader : public Object { public: String name; @@ -201,7 +186,6 @@ class CCVKGPUShader : public Object { UniformBlockList blocks; UniformSamplerList samplers; CCVKGPUShaderStageList gpuStages; - CCVKGPUPipelineLayout *pipelineLayout = nullptr; }; class CCVKGPUInputAssembler : public Object { @@ -214,34 +198,59 @@ class CCVKGPUInputAssembler : public Object { vector vertexBufferOffsets; }; -union CCVKGPUDescriptorInfo { +union CCVKDescriptorInfo { VkDescriptorImageInfo image; VkDescriptorBufferInfo buffer; VkBufferView texelBufferView; }; -class CCVKGPUBinding : public Object { -public: - CCVKGPUBuffer *buffer = nullptr; - CCVKGPUTextureView *texView = nullptr; - CCVKGPUSampler *sampler = nullptr; +struct CCVKGPUDescriptor { + DescriptorType type = DescriptorType::UNKNOWN; + CCVKGPUBufferView *gpuBufferView = nullptr; + CCVKGPUTextureView *gpuTextureView = nullptr; + CCVKGPUSampler *gpuSampler = nullptr; }; -class CCVKGPUBindingLayout : public Object { +typedef vector CCVKGPUDescriptorList; + +class CCVKGPUDescriptorSet : public Object { public: - vector> gpuBindings; - // contiguous across different sets - vector descriptorInfos; + CCVKGPUDescriptorList gpuDescriptors; + + vector descriptorInfos; vector descriptorUpdateEntries; +}; - vector descriptorSets; +class CCVKGPUDescriptorSetLayout : public Object { +public: + DescriptorSetLayoutBindingList bindings; + vector dynamicBindings; - // external references - const vector> *descriptorIndices = nullptr; + vector vkBindings; + VkDescriptorSetLayout vkDescriptorSetLayout = VK_NULL_HANDLE; + vector descriptorIndices; + uint descriptorCount = 0u; +}; +typedef vector CCVKGPUDescriptorSetLayoutList; + +class CCVKGPUPipelineLayout : public Object { +public: + CCVKGPUDescriptorSetLayoutList setLayouts; + vector dynamicOffsetOffsets; + uint dynamicOffsetCount; + + VkPipelineLayout vkPipelineLayout = VK_NULL_HANDLE; + vector vkDescriptorUpdateTemplates; + + // helper storage + vector descriptorSetLayouts; + vector descriptorSets; + vector dynamicOffsets; }; class CCVKGPUPipelineState : public Object { public: PrimitiveMode primitive = PrimitiveMode::TRIANGLE_LIST; CCVKGPUShader *gpuShader = nullptr; + CCVKGPUPipelineLayout *gpuPipelineLayout = nullptr; InputState inputState; RasterizerState rs; DepthStencilState dss; @@ -257,6 +266,22 @@ class CCVKGPUFence : public Object { VkFence vkFence; }; +class CCVKGPUDevice : public Object { +public: + VkDevice vkDevice = VK_NULL_HANDLE; + vector layers; + vector extensions; + VmaAllocator memoryAllocator = VK_NULL_HANDLE; + + bool useDescriptorUpdateTemplate = false; + bool useMultiDrawIndirect = false; + + CCVKGPUBuffer defaultBuffer; + CCVKGPUSampler defaultSampler; + CCVKGPUTexture defaultTexture; + CCVKGPUTextureView defaultTextureView; +}; + /** * A simple pool for reusing fences. */ @@ -367,7 +392,7 @@ class CCVKGPUDescriptorSetPool : public Object { _counts.clear(); } - void alloc(VkDescriptorSetLayout *layouts, VkDescriptorSet *output, uint count) { + void alloc(const VkDescriptorSetLayout *layouts, VkDescriptorSet *output, uint count) { VkDescriptorSetAllocateInfo info{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; info.pSetLayouts = layouts; info.descriptorSetCount = count; @@ -567,51 +592,6 @@ class CCVKGPUStagingBufferPool : public Object { vector _pool; }; -/** - * Pipeline layout pool, reuse if the hash matches. - * Is more useful when compiling lots of shader variants with the same descriptor set layouts. - */ -class CCVKGPUPipelineLayoutPool : public Object { -public: - CCVKGPUPipelineLayoutPool(CCVKGPUDevice *device) - : _device(device) { - } - - ~CCVKGPUPipelineLayoutPool() { - for (PipelineLayoutPool::iterator it = _pool.begin(); it != _pool.end(); it++) { - CCVKGPUPipelineLayout &pipelineLayout = it->second; - for (uint i = 0u; i < pipelineLayout.vkDescriptorUpdateTemplates.size(); i++) { - if (pipelineLayout.vkDescriptorUpdateTemplates[i] != VK_NULL_HANDLE) { - vkDestroyDescriptorUpdateTemplateKHR(_device->vkDevice, pipelineLayout.vkDescriptorUpdateTemplates[i], nullptr); - } - } - pipelineLayout.vkDescriptorUpdateTemplates.clear(); - - if (pipelineLayout.vkPipelineLayout != VK_NULL_HANDLE) { - vkDestroyPipelineLayout(_device->vkDevice, pipelineLayout.vkPipelineLayout, nullptr); - pipelineLayout.vkPipelineLayout = VK_NULL_HANDLE; - } - - for (uint i = 0u; i < pipelineLayout.vkDescriptorSetLayouts.size(); i++) { - if (pipelineLayout.vkDescriptorSetLayouts[i] != VK_NULL_HANDLE) { - vkDestroyDescriptorSetLayout(_device->vkDevice, pipelineLayout.vkDescriptorSetLayouts[i], nullptr); - } - } - pipelineLayout.vkDescriptorSetLayouts.clear(); - } - _pool.clear(); - } - - void request(CCVKGPUShader *gpuShader); - -private: - typedef map PipelineLayoutPool; - typedef PipelineLayoutPool::iterator PipelineLayoutPoolIt; - - CCVKGPUDevice *_device; - PipelineLayoutPool _pool; -}; - /** * Descriptor data maintenance hub, events like buffer/texture resizing, * descriptor set binding change, etc. should all request an update operation here. @@ -623,8 +603,8 @@ class CCVKGPUDescriptorHub : public Object { } #define DEFINE_DESCRIPTOR_HUB_FN(name) \ - CC_INLINE void name(const CCVKGPUBuffer *buffer) { name(_buffers, buffer, (VkDescriptorBufferInfo *)nullptr); } \ - CC_INLINE void name(const CCVKGPUBuffer *buffer, VkDescriptorBufferInfo *descriptor) { name(_buffers, buffer, descriptor); } \ + CC_INLINE void name(const CCVKGPUBufferView *buffer) { name(_buffers, buffer, (VkDescriptorBufferInfo *)nullptr); } \ + CC_INLINE void name(const CCVKGPUBufferView *buffer, VkDescriptorBufferInfo *descriptor) { name(_buffers, buffer, descriptor); } \ CC_INLINE void name(const CCVKGPUTextureView *texture) { name(_textures, texture, (VkDescriptorImageInfo *)nullptr); } \ CC_INLINE void name(const CCVKGPUTextureView *texture, VkDescriptorImageInfo *descriptor) { name(_textures, texture, descriptor); } \ CC_INLINE void name(const CCVKGPUSampler *sampler) { name(_samplers, sampler, (VkDescriptorImageInfo *)nullptr); } \ @@ -640,10 +620,10 @@ class CCVKGPUDescriptorHub : public Object { map[name].push(descriptor); } - CC_INLINE void _doUpdate(const CCVKGPUBuffer *buffer, VkDescriptorBufferInfo *descriptor) { - descriptor->buffer = buffer->vkBuffer; - descriptor->offset = buffer->startOffset; - descriptor->range = buffer->size; + CC_INLINE void _doUpdate(const CCVKGPUBufferView *buffer, VkDescriptorBufferInfo *descriptor) { + descriptor->buffer = buffer->gpuBuffer->vkBuffer; + descriptor->offset = buffer->gpuBuffer->startOffset + buffer->offset; + descriptor->range = buffer->range; } CC_INLINE void _doUpdate(const CCVKGPUTextureView *texture, VkDescriptorImageInfo *descriptor) { @@ -686,7 +666,7 @@ class CCVKGPUDescriptorHub : public Object { } CCVKGPUDevice *_device = nullptr; - map> _buffers; + map> _buffers; map> _textures; map> _samplers; }; // namespace gfx @@ -711,19 +691,35 @@ class CCVKGPURecycleBin : public Object { res.type = typeValue; \ expr; \ } - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUBuffer, ObjectType::BUFFER, (res.buffer = {gpuRes->vkBuffer, gpuRes->vmaAllocation})) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUTexture, ObjectType::TEXTURE, (res.image = {gpuRes->vkImage, gpuRes->vmaAllocation})) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUTextureView, ObjectType::TEXTURE_VIEW, res.vkImageView = gpuRes->vkImageView) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPURenderPass, ObjectType::RENDER_PASS, res.gpuRenderPass = gpuRes) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUFramebuffer, ObjectType::FRAMEBUFFER, res.gpuFramebuffer = gpuRes) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUSampler, ObjectType::SAMPLER, res.gpuSampler = gpuRes) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUShader, ObjectType::SHADER, res.gpuShader = gpuRes) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUPipelineState, ObjectType::PIPELINE_STATE, res.gpuPipelineState = gpuRes) - DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUFence, ObjectType::FENCE, res.gpuFence = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUBuffer, RecycledType::BUFFER, (res.buffer = {gpuRes->vkBuffer, gpuRes->vmaAllocation})) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUTexture, RecycledType::TEXTURE, (res.image = {gpuRes->vkImage, gpuRes->vmaAllocation})) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUTextureView, RecycledType::TEXTURE_VIEW, res.vkImageView = gpuRes->vkImageView) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPURenderPass, RecycledType::RENDER_PASS, res.gpuRenderPass = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUFramebuffer, RecycledType::FRAMEBUFFER, res.gpuFramebuffer = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUSampler, RecycledType::SAMPLER, res.gpuSampler = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUShader, RecycledType::SHADER, res.gpuShader = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUDescriptorSetLayout, RecycledType::DESCRIPTOR_SET_LAYOUT, res.gpuDescriptorSetLayout = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUPipelineLayout, RecycledType::PIPELINE_LAYOUT, res.gpuPipelineLayout = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUPipelineState, RecycledType::PIPELINE_STATE, res.gpuPipelineState = gpuRes) + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUFence, RecycledType::FENCE, res.gpuFence = gpuRes) void clear(); private: + enum class RecycledType : uint8_t { + UNKNOWN, + BUFFER, + TEXTURE, + TEXTURE_VIEW, + RENDER_PASS, + FRAMEBUFFER, + SAMPLER, + SHADER, + DESCRIPTOR_SET_LAYOUT, + PIPELINE_LAYOUT, + PIPELINE_STATE, + FENCE, + }; struct Buffer { VkBuffer vkBuffer; VmaAllocation vmaAllocation; @@ -733,7 +729,8 @@ class CCVKGPURecycleBin : public Object { VmaAllocation vmaAllocation; }; struct Resource { - ObjectType type = ObjectType::UNKNOWN; + RecycledType type = RecycledType::UNKNOWN; + bool isView = false; union { // resizable resources, cannot take over directly // or descriptor sets won't work @@ -745,6 +742,8 @@ class CCVKGPURecycleBin : public Object { CCVKGPUFramebuffer *gpuFramebuffer; CCVKGPUSampler *gpuSampler; CCVKGPUShader *gpuShader; + CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout; + CCVKGPUPipelineLayout *gpuPipelineLayout; CCVKGPUPipelineState *gpuPipelineState; CCVKGPUFence *gpuFence; }; diff --git a/cocos/renderer/gfx-vulkan/VKPipelineLayout.cc b/cocos/renderer/gfx-vulkan/VKPipelineLayout.cc new file mode 100644 index 00000000000..a934df0ebf7 --- /dev/null +++ b/cocos/renderer/gfx-vulkan/VKPipelineLayout.cc @@ -0,0 +1,55 @@ +#include "VKStd.h" + +#include "VKCommands.h" +#include "VKDescriptorSetLayout.h" +#include "VKDevice.h" +#include "VKPipelineLayout.h" + +namespace cc { +namespace gfx { + +CCVKPipelineLayout::CCVKPipelineLayout(Device *device) +: PipelineLayout(device) { +} + +CCVKPipelineLayout::~CCVKPipelineLayout() { +} + +bool CCVKPipelineLayout::initialize(const PipelineLayoutInfo &info) { + + _setLayouts = info.setLayouts; + + _gpuPipelineLayout = CC_NEW(CCVKGPUPipelineLayout); + + int offset = 0u; + for (uint i = 0u; i < _setLayouts.size(); i++) { + DescriptorSetLayout *setLayout = _setLayouts[i]; + CCVKGPUDescriptorSetLayout *gpuSetLayout = ((CCVKDescriptorSetLayout *)setLayout)->gpuDescriptorSetLayout(); + size_t dynamicCount = gpuSetLayout->dynamicBindings.size(); + _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); + _gpuPipelineLayout->setLayouts.push_back(gpuSetLayout); + offset += dynamicCount; + } + _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); + _gpuPipelineLayout->dynamicOffsetCount = offset; + _gpuPipelineLayout->dynamicOffsets.resize(offset); + + CCVKCmdFuncCreatePipelineLayout((CCVKDevice *)_device, _gpuPipelineLayout); + + _status = Status::SUCCESS; + + return true; +} + +void CCVKPipelineLayout::destroy() { + + if (_gpuPipelineLayout) { + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuPipelineLayout); + _gpuPipelineLayout = nullptr; + } + + _status = Status::UNREADY; +} + +} // namespace gfx +} // namespace cc diff --git a/cocos/renderer/gfx-vulkan/VKPipelineLayout.h b/cocos/renderer/gfx-vulkan/VKPipelineLayout.h new file mode 100644 index 00000000000..674d4cbf283 --- /dev/null +++ b/cocos/renderer/gfx-vulkan/VKPipelineLayout.h @@ -0,0 +1,27 @@ +#ifndef CC_GFXVULKAN_CCVK_PIPELINE_LAYOUT_H_ +#define CC_GFXVULKAN_CCVK_PIPELINE_LAYOUT_H_ + +namespace cc { +namespace gfx { + +class CCVKGPUPipelineLayout; + +class CC_VULKAN_API CCVKPipelineLayout : public PipelineLayout { +public: + CCVKPipelineLayout(Device *device); + ~CCVKPipelineLayout(); + +public: + virtual bool initialize(const PipelineLayoutInfo &info) override; + virtual void destroy() override; + + CC_INLINE CCVKGPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } + +private: + CCVKGPUPipelineLayout *_gpuPipelineLayout = nullptr; +}; + +} // namespace gfx +} // namespace cc + +#endif // CC_GFXVULKAN_CCVK_PIPELINE_LAYOUT_H_ diff --git a/cocos/renderer/gfx-vulkan/VKPipelineState.cc b/cocos/renderer/gfx-vulkan/VKPipelineState.cc index 74205ee7173..acc12d44586 100644 --- a/cocos/renderer/gfx-vulkan/VKPipelineState.cc +++ b/cocos/renderer/gfx-vulkan/VKPipelineState.cc @@ -2,6 +2,7 @@ #include "VKCommands.h" #include "VKDevice.h" +#include "VKPipelineLayout.h" #include "VKPipelineState.h" #include "VKRenderPass.h" #include "VKShader.h" @@ -25,6 +26,7 @@ bool CCVKPipelineState::initialize(const PipelineStateInfo &info) { _blendState = info.blendState; _dynamicStates = info.dynamicStates; _renderPass = info.renderPass; + _pipelineLayout = info.pipelineLayout; _gpuPipelineState = CC_NEW(CCVKGPUPipelineState); _gpuPipelineState->primitive = _primitive; @@ -34,6 +36,7 @@ bool CCVKPipelineState::initialize(const PipelineStateInfo &info) { _gpuPipelineState->dss = _depthStencilState; _gpuPipelineState->bs = _blendState; _gpuPipelineState->gpuRenderPass = ((CCVKRenderPass *)_renderPass)->gpuRenderPass(); + _gpuPipelineState->gpuPipelineLayout = ((CCVKPipelineLayout *)_pipelineLayout)->gpuPipelineLayout(); for (uint i = 0; i < 31; i++) { if ((uint)_dynamicStates & (1 << i)) { diff --git a/cocos/renderer/gfx-vulkan/VKSPIRV.h b/cocos/renderer/gfx-vulkan/VKSPIRV.h index d5e6a41253f..9929e8be627 100644 --- a/cocos/renderer/gfx-vulkan/VKSPIRV.h +++ b/cocos/renderer/gfx-vulkan/VKSPIRV.h @@ -9,16 +9,16 @@ namespace cc { namespace gfx { namespace { -EShLanguage getShaderStage(ShaderType type) { +EShLanguage getShaderStage(ShaderStageFlagBit type) { switch (type) { - case ShaderType::VERTEX: return EShLangVertex; - case ShaderType::CONTROL: return EShLangTessControl; - case ShaderType::EVALUATION: return EShLangTessEvaluation; - case ShaderType::GEOMETRY: return EShLangGeometry; - case ShaderType::FRAGMENT: return EShLangFragment; - case ShaderType::COMPUTE: return EShLangCompute; + case ShaderStageFlagBit::VERTEX: return EShLangVertex; + case ShaderStageFlagBit::CONTROL: return EShLangTessControl; + case ShaderStageFlagBit::EVALUATION: return EShLangTessEvaluation; + case ShaderStageFlagBit::GEOMETRY: return EShLangGeometry; + case ShaderStageFlagBit::FRAGMENT: return EShLangFragment; + case ShaderStageFlagBit::COMPUTE: return EShLangCompute; default: { - CCASSERT(false, "Unsupported ShaderType, convert to EShLanguage failed."); + CCASSERT(false, "Unsupported ShaderStageFlagBit, convert to EShLanguage failed."); return EShLangVertex; } } @@ -50,7 +50,7 @@ glslang::EShTargetLanguageVersion getTargetVersion(int vulkanMinorVersion) { bool glslangInitialized = false; -const vector GLSL2SPIRV(ShaderType type, const String &source, int vulkanMinorVersion = 0) { +const vector GLSL2SPIRV(ShaderStageFlagBit type, const String &source, int vulkanMinorVersion = 0) { if (!glslangInitialized) { glslang::InitializeProcess(); glslangInitialized = true; diff --git a/cocos/renderer/gfx-vulkan/VKShader.cc b/cocos/renderer/gfx-vulkan/VKShader.cc index 95997db3141..e6fd2c51c13 100644 --- a/cocos/renderer/gfx-vulkan/VKShader.cc +++ b/cocos/renderer/gfx-vulkan/VKShader.cc @@ -27,7 +27,7 @@ bool CCVKShader::initialize(const ShaderInfo &info) { _gpuShader->blocks = _blocks; _gpuShader->samplers = _samplers; for (ShaderStage &stage : _stages) { - _gpuShader->gpuStages.push_back({stage.type, stage.source, stage.macros}); + _gpuShader->gpuStages.push_back({stage.stage, stage.source}); } CCVKCmdFuncCreateShader((CCVKDevice *)_device, _gpuShader); diff --git a/cocos/renderer/gfx-vulkan/VKTexture.cc b/cocos/renderer/gfx-vulkan/VKTexture.cc index dcb6ab12c97..d0ff216ddfa 100644 --- a/cocos/renderer/gfx-vulkan/VKTexture.cc +++ b/cocos/renderer/gfx-vulkan/VKTexture.cc @@ -91,7 +91,7 @@ bool CCVKTexture::initialize(const TextureInfo &info) { } bool CCVKTexture::initialize(const TextureViewInfo &info) { - _Type = ObjectType::TEXTURE_VIEW; + _isTextureView = true; if (!info.texture) { _status = Status::FAILED; @@ -140,9 +140,11 @@ void CCVKTexture::destroy() { } if (_gpuTexture) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture); - _device->getMemoryStatus().textureSize -= _size; - CC_DELETE(_gpuTexture); + if (!_isTextureView) { + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture); + _device->getMemoryStatus().textureSize -= _size; + CC_DELETE(_gpuTexture); + } _gpuTexture = nullptr; } @@ -155,6 +157,8 @@ void CCVKTexture::destroy() { } void CCVKTexture::resize(uint width, uint height) { + CCASSERT(!_isTextureView, "Cannot resize texture views"); + uint size = FormatSize(_format, width, height, _depth); if (_size != size) { const uint old_size = _size; diff --git a/cocos/renderer/gfx-vulkan/VKUtils.h b/cocos/renderer/gfx-vulkan/VKUtils.h index 7a949be0514..398712238e1 100644 --- a/cocos/renderer/gfx-vulkan/VKUtils.h +++ b/cocos/renderer/gfx-vulkan/VKUtils.h @@ -375,13 +375,15 @@ VkCommandBufferLevel MapVkCommandBufferLevel(CommandBufferType type) { } } -VkDescriptorType MapVkDescriptorType(BindingType type) { +VkDescriptorType MapVkDescriptorType(DescriptorType type) { switch (type) { - case BindingType::UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - case BindingType::SAMPLER: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - case BindingType::STORAGE_BUFFER: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + case DescriptorType::DYNAMIC_UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; + case DescriptorType::UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + case DescriptorType::DYNAMIC_STORAGE_BUFFER: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; + case DescriptorType::STORAGE_BUFFER: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + case DescriptorType::SAMPLER: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; default: { - CCASSERT(false, "Unsupported BindingType, convert to VkDescriptorType failed."); + CCASSERT(false, "Unsupported DescriptorType, convert to VkDescriptorType failed."); return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; } } @@ -397,29 +399,29 @@ VkColorComponentFlags MapVkColorComponentFlags(ColorMask colorMask) { return (VkColorComponentFlags)flags; } -VkShaderStageFlagBits MapVkShaderStageFlagBits(ShaderType stage) { +VkShaderStageFlagBits MapVkShaderStageFlagBits(ShaderStageFlagBit stage) { switch (stage) { - case ShaderType::VERTEX: return VK_SHADER_STAGE_VERTEX_BIT; - case ShaderType::CONTROL: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; - case ShaderType::EVALUATION: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; - case ShaderType::GEOMETRY: return VK_SHADER_STAGE_GEOMETRY_BIT; - case ShaderType::FRAGMENT: return VK_SHADER_STAGE_FRAGMENT_BIT; - case ShaderType::COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT; + case ShaderStageFlagBit::VERTEX: return VK_SHADER_STAGE_VERTEX_BIT; + case ShaderStageFlagBit::CONTROL: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + case ShaderStageFlagBit::EVALUATION: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + case ShaderStageFlagBit::GEOMETRY: return VK_SHADER_STAGE_GEOMETRY_BIT; + case ShaderStageFlagBit::FRAGMENT: return VK_SHADER_STAGE_FRAGMENT_BIT; + case ShaderStageFlagBit::COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT; default: { - CCASSERT(false, "Unsupported ShaderType, convert to VkShaderStageFlagBits failed."); + CCASSERT(false, "Unsupported ShaderStageFlagBit, convert to VkShaderStageFlagBits failed."); return VK_SHADER_STAGE_VERTEX_BIT; } } } -VkShaderStageFlags MapVkShaderStageFlags(ShaderType stages) { +VkShaderStageFlags MapVkShaderStageFlags(ShaderStageFlagBit stages) { uint flags = 0u; - if (stages & ShaderType::VERTEX) flags |= VK_SHADER_STAGE_VERTEX_BIT; - if (stages & ShaderType::CONTROL) flags |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; - if (stages & ShaderType::EVALUATION) flags |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; - if (stages & ShaderType::GEOMETRY) flags |= VK_SHADER_STAGE_GEOMETRY_BIT; - if (stages & ShaderType::FRAGMENT) flags |= VK_SHADER_STAGE_FRAGMENT_BIT; - if (stages & ShaderType::COMPUTE) flags |= VK_SHADER_STAGE_COMPUTE_BIT; + if (stages & ShaderStageFlagBit::VERTEX) flags |= VK_SHADER_STAGE_VERTEX_BIT; + if (stages & ShaderStageFlagBit::CONTROL) flags |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + if (stages & ShaderStageFlagBit::EVALUATION) flags |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + if (stages & ShaderStageFlagBit::GEOMETRY) flags |= VK_SHADER_STAGE_GEOMETRY_BIT; + if (stages & ShaderStageFlagBit::FRAGMENT) flags |= VK_SHADER_STAGE_FRAGMENT_BIT; + if (stages & ShaderStageFlagBit::COMPUTE) flags |= VK_SHADER_STAGE_COMPUTE_BIT; return (VkShaderStageFlags)flags; } diff --git a/cocos/renderer/pipeline/BatchedBuffer.cpp b/cocos/renderer/pipeline/BatchedBuffer.cpp index c00e4f7e253..773ebf06a27 100644 --- a/cocos/renderer/pipeline/BatchedBuffer.cpp +++ b/cocos/renderer/pipeline/BatchedBuffer.cpp @@ -1,5 +1,5 @@ #include "BatchedBuffer.h" -#include "gfx/GFXBindingLayout.h" +#include "gfx/GFXDescriptorSet.h" #include "gfx/GFXBuffer.h" #include "gfx/GFXInputAssembler.h" #include "helper/SharedMemory.h" diff --git a/cocos/renderer/pipeline/Define.h b/cocos/renderer/pipeline/Define.h index 04ac787b529..7f1428904cf 100644 --- a/cocos/renderer/pipeline/Define.h +++ b/cocos/renderer/pipeline/Define.h @@ -81,7 +81,7 @@ enum class CC_DLL RenderPassStage { }; struct CC_DLL InternalBindingDesc { - gfx::BindingType type; + gfx::DescriptorType type; gfx::UniformBlock blockInfo; gfx::UniformSampler samplerInfo; Value defaultValue; diff --git a/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp index 690995f58e1..4c04f12e196 100644 --- a/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp @@ -2189,6 +2189,34 @@ static bool js_gfx_DeviceInfo_set_sharedCtx(se::State& s) } SE_BIND_PROP_SET(js_gfx_DeviceInfo_set_sharedCtx) +static bool js_gfx_DeviceInfo_get_bindingMappingInfo(se::State& s) +{ + cc::gfx::DeviceInfo* cobj = (cc::gfx::DeviceInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DeviceInfo_get_bindingMappingInfo : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= native_ptr_to_seval(cobj->bindingMappingInfo, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_DeviceInfo_get_bindingMappingInfo) + +static bool js_gfx_DeviceInfo_set_bindingMappingInfo(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::DeviceInfo* cobj = (cc::gfx::DeviceInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DeviceInfo_set_bindingMappingInfo : Invalid Native Object"); + + CC_UNUSED bool ok = true; + cc::gfx::BindingMappingInfo* arg0 = nullptr; + ok &= seval_to_reference(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DeviceInfo_set_bindingMappingInfo : Error processing new value"); + cobj->bindingMappingInfo = *arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_DeviceInfo_set_bindingMappingInfo) + SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_DeviceInfo_finalize) static bool js_gfx_DeviceInfo_constructor(se::State& s) @@ -2246,6 +2274,12 @@ static bool js_gfx_DeviceInfo_constructor(se::State& s) ok &= seval_to_native_ptr(field, &arg5); cobj->sharedCtx = arg5; } + cc::gfx::BindingMappingInfo* arg6 = nullptr; + json->getProperty("bindingMappingInfo", &field); + if(!field.isUndefined()) { + ok &= seval_to_reference(field, &arg6); + cobj->bindingMappingInfo = *arg6; + } if(!ok) { JSB_FREE(cobj); @@ -2257,7 +2291,7 @@ static bool js_gfx_DeviceInfo_constructor(se::State& s) se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; } - else if(argc == 6) + else if(argc == 7) { cc::gfx::DeviceInfo* cobj = JSB_ALLOC(cc::gfx::DeviceInfo); uintptr_t arg0 = 0; @@ -2290,6 +2324,11 @@ static bool js_gfx_DeviceInfo_constructor(se::State& s) ok &= seval_to_native_ptr(args[5], &arg5); cobj->sharedCtx = arg5; } + cc::gfx::BindingMappingInfo* arg6 = nullptr; + if (!args[6].isUndefined()) { + ok &= seval_to_reference(args[6], &arg6); + cobj->bindingMappingInfo = *arg6; + } if(!ok) { JSB_FREE(cobj); @@ -2333,6 +2372,7 @@ bool js_register_gfx_DeviceInfo(se::Object* obj) cls->defineProperty("nativeWidth", _SE(js_gfx_DeviceInfo_get_nativeWidth), _SE(js_gfx_DeviceInfo_set_nativeWidth)); cls->defineProperty("nativeHeight", _SE(js_gfx_DeviceInfo_get_nativeHeight), _SE(js_gfx_DeviceInfo_set_nativeHeight)); cls->defineProperty("sharedCtx", _SE(js_gfx_DeviceInfo_get_sharedCtx), _SE(js_gfx_DeviceInfo_set_sharedCtx)); + cls->defineProperty("bindingMappingInfo", _SE(js_gfx_DeviceInfo_get_bindingMappingInfo), _SE(js_gfx_DeviceInfo_set_bindingMappingInfo)); cls->defineFinalizeFunction(_SE(js_cc_gfx_DeviceInfo_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -2836,6 +2876,212 @@ bool js_register_gfx_BufferInfo(se::Object* obj) return true; } +se::Object* __jsb_cc_gfx_BufferViewInfo_proto = nullptr; +se::Class* __jsb_cc_gfx_BufferViewInfo_class = nullptr; + +static bool js_gfx_BufferViewInfo_get_buffer(se::State& s) +{ + cc::gfx::BufferViewInfo* cobj = (cc::gfx::BufferViewInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_BufferViewInfo_get_buffer : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= native_ptr_to_seval(cobj->buffer, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_BufferViewInfo_get_buffer) + +static bool js_gfx_BufferViewInfo_set_buffer(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::BufferViewInfo* cobj = (cc::gfx::BufferViewInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_BufferViewInfo_set_buffer : Invalid Native Object"); + + CC_UNUSED bool ok = true; + cc::gfx::Buffer* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_BufferViewInfo_set_buffer : Error processing new value"); + cobj->buffer = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_BufferViewInfo_set_buffer) + +static bool js_gfx_BufferViewInfo_get_offset(se::State& s) +{ + cc::gfx::BufferViewInfo* cobj = (cc::gfx::BufferViewInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_BufferViewInfo_get_offset : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= uint32_to_seval((unsigned int)cobj->offset, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_BufferViewInfo_get_offset) + +static bool js_gfx_BufferViewInfo_set_offset(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::BufferViewInfo* cobj = (cc::gfx::BufferViewInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_BufferViewInfo_set_offset : Invalid Native Object"); + + CC_UNUSED bool ok = true; + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_BufferViewInfo_set_offset : Error processing new value"); + cobj->offset = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_BufferViewInfo_set_offset) + +static bool js_gfx_BufferViewInfo_get_range(se::State& s) +{ + cc::gfx::BufferViewInfo* cobj = (cc::gfx::BufferViewInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_BufferViewInfo_get_range : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= uint32_to_seval((unsigned int)cobj->range, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_BufferViewInfo_get_range) + +static bool js_gfx_BufferViewInfo_set_range(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::BufferViewInfo* cobj = (cc::gfx::BufferViewInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_BufferViewInfo_set_range : Invalid Native Object"); + + CC_UNUSED bool ok = true; + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_BufferViewInfo_set_range : Error processing new value"); + cobj->range = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_BufferViewInfo_set_range) + +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_BufferViewInfo_finalize) + +static bool js_gfx_BufferViewInfo_constructor(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + + if(argc == 0) + { + cc::gfx::BufferViewInfo* cobj = JSB_ALLOC(cc::gfx::BufferViewInfo); + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + else if(argc == 1 && args[0].isObject()) + { + se::Object *json = args[0].toObject(); + se::Value field; + + cc::gfx::BufferViewInfo* cobj = JSB_ALLOC(cc::gfx::BufferViewInfo); + cc::gfx::Buffer* arg0 = nullptr; + json->getProperty("buffer", &field); + if(!field.isUndefined()) { + ok &= seval_to_native_ptr(field, &arg0); + cobj->buffer = arg0; + } + unsigned int arg1 = 0; + json->getProperty("offset", &field); + if(!field.isUndefined()) { + ok &= seval_to_uint32(field, (uint32_t*)&arg1); + cobj->offset = arg1; + } + unsigned int arg2 = 0; + json->getProperty("range", &field); + if(!field.isUndefined()) { + ok &= seval_to_uint32(field, (uint32_t*)&arg2); + cobj->range = arg2; + } + + if(!ok) { + JSB_FREE(cobj); + SE_REPORT_ERROR("argument convertion error"); + return false; + } + + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + else if(argc == 3) + { + cc::gfx::BufferViewInfo* cobj = JSB_ALLOC(cc::gfx::BufferViewInfo); + cc::gfx::Buffer* arg0 = nullptr; + if (!args[0].isUndefined()) { + ok &= seval_to_native_ptr(args[0], &arg0); + cobj->buffer = arg0; + } + unsigned int arg1 = 0; + if (!args[1].isUndefined()) { + ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); + cobj->offset = arg1; + } + unsigned int arg2 = 0; + if (!args[2].isUndefined()) { + ok &= seval_to_uint32(args[2], (uint32_t*)&arg2); + cobj->range = arg2; + } + + if(!ok) { + JSB_FREE(cobj); + SE_REPORT_ERROR("Argument convertion error"); + return false; + } + + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_CTOR(js_gfx_BufferViewInfo_constructor, __jsb_cc_gfx_BufferViewInfo_class, js_cc_gfx_BufferViewInfo_finalize) + + + + +static bool js_cc_gfx_BufferViewInfo_finalize(se::State& s) +{ + auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) + { + se::NonRefNativePtrCreatedByCtorMap::erase(iter); + cc::gfx::BufferViewInfo* cobj = (cc::gfx::BufferViewInfo*)s.nativeThisObject(); + JSB_FREE(cobj); + } + return true; +} +SE_BIND_FINALIZE_FUNC(js_cc_gfx_BufferViewInfo_finalize) + +bool js_register_gfx_BufferViewInfo(se::Object* obj) +{ + auto cls = se::Class::create("BufferViewInfo", obj, nullptr, _SE(js_gfx_BufferViewInfo_constructor)); + + cls->defineProperty("buffer", _SE(js_gfx_BufferViewInfo_get_buffer), _SE(js_gfx_BufferViewInfo_set_buffer)); + cls->defineProperty("offset", _SE(js_gfx_BufferViewInfo_get_offset), _SE(js_gfx_BufferViewInfo_set_offset)); + cls->defineProperty("range", _SE(js_gfx_BufferViewInfo_get_range), _SE(js_gfx_BufferViewInfo_set_range)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_BufferViewInfo_finalize)); + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_gfx_BufferViewInfo_proto = cls->getProto(); + __jsb_cc_gfx_BufferViewInfo_class = cls; + + se::ScriptEngine::getInstance()->clearException(); + return true; +} + se::Object* __jsb_cc_gfx_DrawInfo_proto = nullptr; se::Class* __jsb_cc_gfx_DrawInfo_class = nullptr; @@ -5138,33 +5384,33 @@ bool js_register_gfx_Uniform(se::Object* obj) se::Object* __jsb_cc_gfx_UniformBlock_proto = nullptr; se::Class* __jsb_cc_gfx_UniformBlock_class = nullptr; -static bool js_gfx_UniformBlock_get_shaderStages(se::State& s) +static bool js_gfx_UniformBlock_get_set(se::State& s) { cc::gfx::UniformBlock* cobj = (cc::gfx::UniformBlock*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_get_shaderStages : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_get_set : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= int32_to_seval((int)cobj->shaderStages, &jsret); + ok &= uint32_to_seval((unsigned int)cobj->set, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_UniformBlock_get_shaderStages) +SE_BIND_PROP_GET(js_gfx_UniformBlock_get_set) -static bool js_gfx_UniformBlock_set_shaderStages(se::State& s) +static bool js_gfx_UniformBlock_set_set(se::State& s) { const auto& args = s.args(); cc::gfx::UniformBlock* cobj = (cc::gfx::UniformBlock*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_set_shaderStages : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_set_set : Invalid Native Object"); CC_UNUSED bool ok = true; - cc::gfx::ShaderType arg0; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - SE_PRECONDITION2(ok, false, "js_gfx_UniformBlock_set_shaderStages : Error processing new value"); - cobj->shaderStages = arg0; + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_UniformBlock_set_set : Error processing new value"); + cobj->set = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_UniformBlock_set_shaderStages) +SE_BIND_PROP_SET(js_gfx_UniformBlock_set_set) static bool js_gfx_UniformBlock_get_binding(se::State& s) { @@ -5222,33 +5468,61 @@ static bool js_gfx_UniformBlock_set_name(se::State& s) } SE_BIND_PROP_SET(js_gfx_UniformBlock_set_name) -static bool js_gfx_UniformBlock_get_uniforms(se::State& s) +static bool js_gfx_UniformBlock_get_members(se::State& s) { cc::gfx::UniformBlock* cobj = (cc::gfx::UniformBlock*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_get_uniforms : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_get_members : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= std_vector_to_seval(cobj->uniforms, &jsret); + ok &= std_vector_to_seval(cobj->members, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_UniformBlock_get_uniforms) +SE_BIND_PROP_GET(js_gfx_UniformBlock_get_members) -static bool js_gfx_UniformBlock_set_uniforms(se::State& s) +static bool js_gfx_UniformBlock_set_members(se::State& s) { const auto& args = s.args(); cc::gfx::UniformBlock* cobj = (cc::gfx::UniformBlock*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_set_uniforms : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_set_members : Invalid Native Object"); CC_UNUSED bool ok = true; std::vector arg0; ok &= seval_to_std_vector(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_UniformBlock_set_uniforms : Error processing new value"); - cobj->uniforms = arg0; + SE_PRECONDITION2(ok, false, "js_gfx_UniformBlock_set_members : Error processing new value"); + cobj->members = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_UniformBlock_set_members) + +static bool js_gfx_UniformBlock_get_count(se::State& s) +{ + cc::gfx::UniformBlock* cobj = (cc::gfx::UniformBlock*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_get_count : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= uint32_to_seval((unsigned int)cobj->count, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_UniformBlock_get_count) + +static bool js_gfx_UniformBlock_set_count(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::UniformBlock* cobj = (cc::gfx::UniformBlock*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformBlock_set_count : Invalid Native Object"); + + CC_UNUSED bool ok = true; + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_UniformBlock_set_count : Error processing new value"); + cobj->count = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_UniformBlock_set_uniforms) +SE_BIND_PROP_SET(js_gfx_UniformBlock_set_count) SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_UniformBlock_finalize) @@ -5271,11 +5545,11 @@ static bool js_gfx_UniformBlock_constructor(se::State& s) se::Value field; cc::gfx::UniformBlock* cobj = JSB_ALLOC(cc::gfx::UniformBlock); - cc::gfx::ShaderType arg0; - json->getProperty("shaderStages", &field); + unsigned int arg0 = 0; + json->getProperty("set", &field); if(!field.isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->shaderStages = arg0; + ok &= seval_to_uint32(field, (uint32_t*)&arg0); + cobj->set = arg0; } unsigned int arg1 = 0; json->getProperty("binding", &field); @@ -5290,10 +5564,16 @@ static bool js_gfx_UniformBlock_constructor(se::State& s) cobj->name = arg2; } std::vector arg3; - json->getProperty("uniforms", &field); + json->getProperty("members", &field); if(!field.isUndefined()) { ok &= seval_to_std_vector(field, &arg3); - cobj->uniforms = arg3; + cobj->members = arg3; + } + unsigned int arg4 = 0; + json->getProperty("count", &field); + if(!field.isUndefined()) { + ok &= seval_to_uint32(field, (uint32_t*)&arg4); + cobj->count = arg4; } if(!ok) { @@ -5306,13 +5586,13 @@ static bool js_gfx_UniformBlock_constructor(se::State& s) se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; } - else if(argc == 4) + else if(argc == 5) { cc::gfx::UniformBlock* cobj = JSB_ALLOC(cc::gfx::UniformBlock); - cc::gfx::ShaderType arg0; + unsigned int arg0 = 0; if (!args[0].isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->shaderStages = arg0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + cobj->set = arg0; } unsigned int arg1 = 0; if (!args[1].isUndefined()) { @@ -5327,7 +5607,12 @@ static bool js_gfx_UniformBlock_constructor(se::State& s) std::vector arg3; if (!args[3].isUndefined()) { ok &= seval_to_std_vector(args[3], &arg3); - cobj->uniforms = arg3; + cobj->members = arg3; + } + unsigned int arg4 = 0; + if (!args[4].isUndefined()) { + ok &= seval_to_uint32(args[4], (uint32_t*)&arg4); + cobj->count = arg4; } if(!ok) { @@ -5366,10 +5651,11 @@ bool js_register_gfx_UniformBlock(se::Object* obj) { auto cls = se::Class::create("UniformBlock", obj, nullptr, _SE(js_gfx_UniformBlock_constructor)); - cls->defineProperty("shaderStages", _SE(js_gfx_UniformBlock_get_shaderStages), _SE(js_gfx_UniformBlock_set_shaderStages)); + cls->defineProperty("set", _SE(js_gfx_UniformBlock_get_set), _SE(js_gfx_UniformBlock_set_set)); cls->defineProperty("binding", _SE(js_gfx_UniformBlock_get_binding), _SE(js_gfx_UniformBlock_set_binding)); cls->defineProperty("name", _SE(js_gfx_UniformBlock_get_name), _SE(js_gfx_UniformBlock_set_name)); - cls->defineProperty("uniforms", _SE(js_gfx_UniformBlock_get_uniforms), _SE(js_gfx_UniformBlock_set_uniforms)); + cls->defineProperty("members", _SE(js_gfx_UniformBlock_get_members), _SE(js_gfx_UniformBlock_set_members)); + cls->defineProperty("count", _SE(js_gfx_UniformBlock_get_count), _SE(js_gfx_UniformBlock_set_count)); cls->defineFinalizeFunction(_SE(js_cc_gfx_UniformBlock_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -5384,33 +5670,33 @@ bool js_register_gfx_UniformBlock(se::Object* obj) se::Object* __jsb_cc_gfx_UniformSampler_proto = nullptr; se::Class* __jsb_cc_gfx_UniformSampler_class = nullptr; -static bool js_gfx_UniformSampler_get_shaderStages(se::State& s) +static bool js_gfx_UniformSampler_get_set(se::State& s) { cc::gfx::UniformSampler* cobj = (cc::gfx::UniformSampler*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_UniformSampler_get_shaderStages : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformSampler_get_set : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= int32_to_seval((int)cobj->shaderStages, &jsret); + ok &= uint32_to_seval((unsigned int)cobj->set, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_UniformSampler_get_shaderStages) +SE_BIND_PROP_GET(js_gfx_UniformSampler_get_set) -static bool js_gfx_UniformSampler_set_shaderStages(se::State& s) +static bool js_gfx_UniformSampler_set_set(se::State& s) { const auto& args = s.args(); cc::gfx::UniformSampler* cobj = (cc::gfx::UniformSampler*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_UniformSampler_set_shaderStages : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_UniformSampler_set_set : Invalid Native Object"); CC_UNUSED bool ok = true; - cc::gfx::ShaderType arg0; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - SE_PRECONDITION2(ok, false, "js_gfx_UniformSampler_set_shaderStages : Error processing new value"); - cobj->shaderStages = arg0; + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_UniformSampler_set_set : Error processing new value"); + cobj->set = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_UniformSampler_set_shaderStages) +SE_BIND_PROP_SET(js_gfx_UniformSampler_set_set) static bool js_gfx_UniformSampler_get_binding(se::State& s) { @@ -5545,11 +5831,11 @@ static bool js_gfx_UniformSampler_constructor(se::State& s) se::Value field; cc::gfx::UniformSampler* cobj = JSB_ALLOC(cc::gfx::UniformSampler); - cc::gfx::ShaderType arg0; - json->getProperty("shaderStages", &field); + unsigned int arg0 = 0; + json->getProperty("set", &field); if(!field.isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->shaderStages = arg0; + ok &= seval_to_uint32(field, (uint32_t*)&arg0); + cobj->set = arg0; } unsigned int arg1 = 0; json->getProperty("binding", &field); @@ -5589,10 +5875,10 @@ static bool js_gfx_UniformSampler_constructor(se::State& s) else if(argc == 5) { cc::gfx::UniformSampler* cobj = JSB_ALLOC(cc::gfx::UniformSampler); - cc::gfx::ShaderType arg0; + unsigned int arg0 = 0; if (!args[0].isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->shaderStages = arg0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + cobj->set = arg0; } unsigned int arg1 = 0; if (!args[1].isUndefined()) { @@ -5651,7 +5937,7 @@ bool js_register_gfx_UniformSampler(se::Object* obj) { auto cls = se::Class::create("UniformSampler", obj, nullptr, _SE(js_gfx_UniformSampler_constructor)); - cls->defineProperty("shaderStages", _SE(js_gfx_UniformSampler_get_shaderStages), _SE(js_gfx_UniformSampler_set_shaderStages)); + cls->defineProperty("set", _SE(js_gfx_UniformSampler_get_set), _SE(js_gfx_UniformSampler_set_set)); cls->defineProperty("binding", _SE(js_gfx_UniformSampler_get_binding), _SE(js_gfx_UniformSampler_set_binding)); cls->defineProperty("name", _SE(js_gfx_UniformSampler_get_name), _SE(js_gfx_UniformSampler_set_name)); cls->defineProperty("type", _SE(js_gfx_UniformSampler_get_type), _SE(js_gfx_UniformSampler_set_type)); @@ -5670,33 +5956,33 @@ bool js_register_gfx_UniformSampler(se::Object* obj) se::Object* __jsb_cc_gfx_ShaderStage_proto = nullptr; se::Class* __jsb_cc_gfx_ShaderStage_class = nullptr; -static bool js_gfx_ShaderStage_get_type(se::State& s) +static bool js_gfx_ShaderStage_get_stage(se::State& s) { cc::gfx::ShaderStage* cobj = (cc::gfx::ShaderStage*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_ShaderStage_get_type : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_ShaderStage_get_stage : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= int32_to_seval((int)cobj->type, &jsret); + ok &= int32_to_seval((int)cobj->stage, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_ShaderStage_get_type) +SE_BIND_PROP_GET(js_gfx_ShaderStage_get_stage) -static bool js_gfx_ShaderStage_set_type(se::State& s) +static bool js_gfx_ShaderStage_set_stage(se::State& s) { const auto& args = s.args(); cc::gfx::ShaderStage* cobj = (cc::gfx::ShaderStage*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_ShaderStage_set_type : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_ShaderStage_set_stage : Invalid Native Object"); CC_UNUSED bool ok = true; - cc::gfx::ShaderType arg0; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - SE_PRECONDITION2(ok, false, "js_gfx_ShaderStage_set_type : Error processing new value"); - cobj->type = arg0; + cc::gfx::ShaderStageFlagBit arg0; + do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderStageFlagBit)tmp; } while(false); + SE_PRECONDITION2(ok, false, "js_gfx_ShaderStage_set_stage : Error processing new value"); + cobj->stage = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_ShaderStage_set_type) +SE_BIND_PROP_SET(js_gfx_ShaderStage_set_stage) static bool js_gfx_ShaderStage_get_source(se::State& s) { @@ -5726,34 +6012,6 @@ static bool js_gfx_ShaderStage_set_source(se::State& s) } SE_BIND_PROP_SET(js_gfx_ShaderStage_set_source) -static bool js_gfx_ShaderStage_get_macros(se::State& s) -{ - cc::gfx::ShaderStage* cobj = (cc::gfx::ShaderStage*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_ShaderStage_get_macros : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= std_vector_to_seval(cobj->macros, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_ShaderStage_get_macros) - -static bool js_gfx_ShaderStage_set_macros(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::ShaderStage* cobj = (cc::gfx::ShaderStage*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_ShaderStage_set_macros : Invalid Native Object"); - - CC_UNUSED bool ok = true; - std::vector arg0; - ok &= seval_to_std_vector(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_ShaderStage_set_macros : Error processing new value"); - cobj->macros = arg0; - return true; -} -SE_BIND_PROP_SET(js_gfx_ShaderStage_set_macros) - SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_ShaderStage_finalize) static bool js_gfx_ShaderStage_constructor(se::State& s) @@ -5775,11 +6033,11 @@ static bool js_gfx_ShaderStage_constructor(se::State& s) se::Value field; cc::gfx::ShaderStage* cobj = JSB_ALLOC(cc::gfx::ShaderStage); - cc::gfx::ShaderType arg0; - json->getProperty("type", &field); + cc::gfx::ShaderStageFlagBit arg0; + json->getProperty("stage", &field); if(!field.isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->type = arg0; + do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::ShaderStageFlagBit)tmp; } while(false); + cobj->stage = arg0; } cc::String arg1; json->getProperty("source", &field); @@ -5787,12 +6045,6 @@ static bool js_gfx_ShaderStage_constructor(se::State& s) arg1 = field.toStringForce().c_str(); cobj->source = arg1; } - std::vector arg2; - json->getProperty("macros", &field); - if(!field.isUndefined()) { - ok &= seval_to_std_vector(field, &arg2); - cobj->macros = arg2; - } if(!ok) { JSB_FREE(cobj); @@ -5804,24 +6056,19 @@ static bool js_gfx_ShaderStage_constructor(se::State& s) se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; } - else if(argc == 3) + else if(argc == 2) { cc::gfx::ShaderStage* cobj = JSB_ALLOC(cc::gfx::ShaderStage); - cc::gfx::ShaderType arg0; + cc::gfx::ShaderStageFlagBit arg0; if (!args[0].isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->type = arg0; + do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderStageFlagBit)tmp; } while(false); + cobj->stage = arg0; } cc::String arg1; if (!args[1].isUndefined()) { arg1 = args[1].toStringForce().c_str(); cobj->source = arg1; } - std::vector arg2; - if (!args[2].isUndefined()) { - ok &= seval_to_std_vector(args[2], &arg2); - cobj->macros = arg2; - } if(!ok) { JSB_FREE(cobj); @@ -5859,9 +6106,8 @@ bool js_register_gfx_ShaderStage(se::Object* obj) { auto cls = se::Class::create("ShaderStage", obj, nullptr, _SE(js_gfx_ShaderStage_constructor)); - cls->defineProperty("type", _SE(js_gfx_ShaderStage_get_type), _SE(js_gfx_ShaderStage_set_type)); + cls->defineProperty("stage", _SE(js_gfx_ShaderStage_get_stage), _SE(js_gfx_ShaderStage_set_stage)); cls->defineProperty("source", _SE(js_gfx_ShaderStage_get_source), _SE(js_gfx_ShaderStage_set_source)); - cls->defineProperty("macros", _SE(js_gfx_ShaderStage_get_macros), _SE(js_gfx_ShaderStage_set_macros)); cls->defineFinalizeFunction(_SE(js_cc_gfx_ShaderStage_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -7763,7 +8009,7 @@ static bool js_gfx_FramebufferInfo_get_depthStencilMipmapLevel(se::State& s) CC_UNUSED bool ok = true; se::Value jsret; - ok &= int32_to_seval((int)cobj->depthStencilMipmapLevel, &jsret); + ok &= uint32_to_seval((unsigned int)cobj->depthStencilMipmapLevel, &jsret); s.rval() = jsret; return true; } @@ -7776,8 +8022,8 @@ static bool js_gfx_FramebufferInfo_set_depthStencilMipmapLevel(se::State& s) SE_PRECONDITION2(cobj, false, "js_gfx_FramebufferInfo_set_depthStencilMipmapLevel : Invalid Native Object"); CC_UNUSED bool ok = true; - int arg0 = 0; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false); + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); SE_PRECONDITION2(ok, false, "js_gfx_FramebufferInfo_set_depthStencilMipmapLevel : Error processing new value"); cobj->depthStencilMipmapLevel = arg0; return true; @@ -7823,10 +8069,10 @@ static bool js_gfx_FramebufferInfo_constructor(se::State& s) ok &= seval_to_native_ptr(field, &arg2); cobj->depthStencilTexture = arg2; } - int arg3 = 0; + unsigned int arg3 = 0; json->getProperty("depthStencilMipmapLevel", &field); if(!field.isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg3 = (int)tmp; } while(false); + ok &= seval_to_uint32(field, (uint32_t*)&arg3); cobj->depthStencilMipmapLevel = arg3; } @@ -7858,9 +8104,9 @@ static bool js_gfx_FramebufferInfo_constructor(se::State& s) ok &= seval_to_native_ptr(args[2], &arg2); cobj->depthStencilTexture = arg2; } - int arg3 = 0; + unsigned int arg3 = 0; if (!args[3].isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(args[3], &tmp); arg3 = (int)tmp; } while(false); + ok &= seval_to_uint32(args[3], (uint32_t*)&arg3); cobj->depthStencilMipmapLevel = arg3; } @@ -7915,228 +8161,41 @@ bool js_register_gfx_FramebufferInfo(se::Object* obj) return true; } -se::Object* __jsb_cc_gfx_BindingLayoutInfo_proto = nullptr; -se::Class* __jsb_cc_gfx_BindingLayoutInfo_class = nullptr; +se::Object* __jsb_cc_gfx_DescriptorSetLayoutBinding_proto = nullptr; +se::Class* __jsb_cc_gfx_DescriptorSetLayoutBinding_class = nullptr; -static bool js_gfx_BindingLayoutInfo_get_shader(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_get_descriptorType(se::State& s) { - cc::gfx::BindingLayoutInfo* cobj = (cc::gfx::BindingLayoutInfo*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayoutInfo_get_shader : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_get_descriptorType : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= native_ptr_to_seval(cobj->shader, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_BindingLayoutInfo_get_shader) - -static bool js_gfx_BindingLayoutInfo_set_shader(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::BindingLayoutInfo* cobj = (cc::gfx::BindingLayoutInfo*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayoutInfo_set_shader : Invalid Native Object"); - - CC_UNUSED bool ok = true; - cc::gfx::Shader* arg0 = nullptr; - ok &= seval_to_native_ptr(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayoutInfo_set_shader : Error processing new value"); - cobj->shader = arg0; - return true; -} -SE_BIND_PROP_SET(js_gfx_BindingLayoutInfo_set_shader) - -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_BindingLayoutInfo_finalize) - -static bool js_gfx_BindingLayoutInfo_constructor(se::State& s) -{ - CC_UNUSED bool ok = true; - const auto& args = s.args(); - size_t argc = args.size(); - - if(argc == 0) - { - cc::gfx::BindingLayoutInfo* cobj = JSB_ALLOC(cc::gfx::BindingLayoutInfo); - s.thisObject()->setPrivateData(cobj); - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; - } - else if(argc == 1) - { - cc::gfx::BindingLayoutInfo* cobj = JSB_ALLOC(cc::gfx::BindingLayoutInfo); - cc::gfx::Shader* arg0 = nullptr; - if (!args[0].isUndefined()) { - ok &= seval_to_native_ptr(args[0], &arg0); - cobj->shader = arg0; - } - - if(!ok) { - JSB_FREE(cobj); - SE_REPORT_ERROR("Argument convertion error"); - return false; - } - - s.thisObject()->setPrivateData(cobj); - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; - } - - SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); - return false; -} -SE_BIND_CTOR(js_gfx_BindingLayoutInfo_constructor, __jsb_cc_gfx_BindingLayoutInfo_class, js_cc_gfx_BindingLayoutInfo_finalize) - - - - -static bool js_cc_gfx_BindingLayoutInfo_finalize(se::State& s) -{ - auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); - if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) - { - se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::BindingLayoutInfo* cobj = (cc::gfx::BindingLayoutInfo*)s.nativeThisObject(); - JSB_FREE(cobj); - } - return true; -} -SE_BIND_FINALIZE_FUNC(js_cc_gfx_BindingLayoutInfo_finalize) - -bool js_register_gfx_BindingLayoutInfo(se::Object* obj) -{ - auto cls = se::Class::create("BindingLayoutInfo", obj, nullptr, _SE(js_gfx_BindingLayoutInfo_constructor)); - - cls->defineProperty("shader", _SE(js_gfx_BindingLayoutInfo_get_shader), _SE(js_gfx_BindingLayoutInfo_set_shader)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_BindingLayoutInfo_finalize)); - cls->install(); - JSBClassType::registerClass(cls); - - __jsb_cc_gfx_BindingLayoutInfo_proto = cls->getProto(); - __jsb_cc_gfx_BindingLayoutInfo_class = cls; - - se::ScriptEngine::getInstance()->clearException(); - return true; -} - -se::Object* __jsb_cc_gfx_BindingUnit_proto = nullptr; -se::Class* __jsb_cc_gfx_BindingUnit_class = nullptr; - -static bool js_gfx_BindingUnit_get_shaderStages(se::State& s) -{ - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_shaderStages : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= int32_to_seval((int)cobj->shaderStages, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_shaderStages) - -static bool js_gfx_BindingUnit_set_shaderStages(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_shaderStages : Invalid Native Object"); - - CC_UNUSED bool ok = true; - cc::gfx::ShaderType arg0; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_shaderStages : Error processing new value"); - cobj->shaderStages = arg0; - return true; -} -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_shaderStages) - -static bool js_gfx_BindingUnit_get_binding(se::State& s) -{ - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_binding : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= uint32_to_seval((unsigned int)cobj->binding, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_binding) - -static bool js_gfx_BindingUnit_set_binding(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_binding : Invalid Native Object"); - - CC_UNUSED bool ok = true; - unsigned int arg0 = 0; - ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_binding : Error processing new value"); - cobj->binding = arg0; - return true; -} -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_binding) - -static bool js_gfx_BindingUnit_get_type(se::State& s) -{ - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_type : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= int32_to_seval((int)cobj->type, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_type) - -static bool js_gfx_BindingUnit_set_type(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_type : Invalid Native Object"); - - CC_UNUSED bool ok = true; - cc::gfx::BindingType arg0; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::BindingType)tmp; } while(false); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_type : Error processing new value"); - cobj->type = arg0; - return true; -} -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_type) - -static bool js_gfx_BindingUnit_get_name(se::State& s) -{ - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_name : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - jsret.setString(cobj->name); + ok &= int32_to_seval((int)cobj->descriptorType, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_name) +SE_BIND_PROP_GET(js_gfx_DescriptorSetLayoutBinding_get_descriptorType) -static bool js_gfx_BindingUnit_set_name(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_set_descriptorType(se::State& s) { const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_name : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_set_descriptorType : Invalid Native Object"); CC_UNUSED bool ok = true; - cc::String arg0; - arg0 = args[0].toStringForce().c_str(); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_name : Error processing new value"); - cobj->name = arg0; + cc::gfx::DescriptorType arg0; + do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::DescriptorType)tmp; } while(false); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayoutBinding_set_descriptorType : Error processing new value"); + cobj->descriptorType = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_name) +SE_BIND_PROP_SET(js_gfx_DescriptorSetLayoutBinding_set_descriptorType) -static bool js_gfx_BindingUnit_get_count(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_get_count(se::State& s) { - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_count : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_get_count : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; @@ -8144,110 +8203,82 @@ static bool js_gfx_BindingUnit_get_count(se::State& s) s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_count) +SE_BIND_PROP_GET(js_gfx_DescriptorSetLayoutBinding_get_count) -static bool js_gfx_BindingUnit_set_count(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_set_count(se::State& s) { const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_count : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_set_count : Invalid Native Object"); CC_UNUSED bool ok = true; unsigned int arg0 = 0; ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_count : Error processing new value"); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayoutBinding_set_count : Error processing new value"); cobj->count = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_count) - -static bool js_gfx_BindingUnit_get_buffer(se::State& s) -{ - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_buffer : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= native_ptr_to_seval(cobj->buffer, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_buffer) - -static bool js_gfx_BindingUnit_set_buffer(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_buffer : Invalid Native Object"); - - CC_UNUSED bool ok = true; - cc::gfx::Buffer* arg0 = nullptr; - ok &= seval_to_native_ptr(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_buffer : Error processing new value"); - cobj->buffer = arg0; - return true; -} -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_buffer) +SE_BIND_PROP_SET(js_gfx_DescriptorSetLayoutBinding_set_count) -static bool js_gfx_BindingUnit_get_texture(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_get_stageFlags(se::State& s) { - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_texture : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_get_stageFlags : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= native_ptr_to_seval(cobj->texture, &jsret); + ok &= int32_to_seval((int)cobj->stageFlags, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_texture) +SE_BIND_PROP_GET(js_gfx_DescriptorSetLayoutBinding_get_stageFlags) -static bool js_gfx_BindingUnit_set_texture(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_set_stageFlags(se::State& s) { const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_texture : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_set_stageFlags : Invalid Native Object"); CC_UNUSED bool ok = true; - cc::gfx::Texture* arg0 = nullptr; - ok &= seval_to_native_ptr(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_texture : Error processing new value"); - cobj->texture = arg0; + cc::gfx::ShaderStageFlagBit arg0; + do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderStageFlagBit)tmp; } while(false); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayoutBinding_set_stageFlags : Error processing new value"); + cobj->stageFlags = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_texture) +SE_BIND_PROP_SET(js_gfx_DescriptorSetLayoutBinding_set_stageFlags) -static bool js_gfx_BindingUnit_get_sampler(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_get_immutableSamplers(se::State& s) { - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_get_sampler : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_get_immutableSamplers : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= native_ptr_to_seval(cobj->sampler, &jsret); + ok &= std_vector_to_seval(cobj->immutableSamplers, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_BindingUnit_get_sampler) +SE_BIND_PROP_GET(js_gfx_DescriptorSetLayoutBinding_get_immutableSamplers) -static bool js_gfx_BindingUnit_set_sampler(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_set_immutableSamplers(se::State& s) { const auto& args = s.args(); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingUnit_set_sampler : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutBinding_set_immutableSamplers : Invalid Native Object"); CC_UNUSED bool ok = true; - cc::gfx::Sampler* arg0 = nullptr; - ok &= seval_to_native_ptr(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_BindingUnit_set_sampler : Error processing new value"); - cobj->sampler = arg0; + std::vector arg0; + ok &= seval_to_std_vector(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayoutBinding_set_immutableSamplers : Error processing new value"); + cobj->immutableSamplers = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_BindingUnit_set_sampler) +SE_BIND_PROP_SET(js_gfx_DescriptorSetLayoutBinding_set_immutableSamplers) -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_BindingUnit_finalize) +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_DescriptorSetLayoutBinding_finalize) -static bool js_gfx_BindingUnit_constructor(se::State& s) +static bool js_gfx_DescriptorSetLayoutBinding_constructor(se::State& s) { CC_UNUSED bool ok = true; const auto& args = s.args(); @@ -8255,7 +8286,7 @@ static bool js_gfx_BindingUnit_constructor(se::State& s) if(argc == 0) { - cc::gfx::BindingUnit* cobj = JSB_ALLOC(cc::gfx::BindingUnit); + cc::gfx::DescriptorSetLayoutBinding* cobj = JSB_ALLOC(cc::gfx::DescriptorSetLayoutBinding); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; @@ -8265,54 +8296,30 @@ static bool js_gfx_BindingUnit_constructor(se::State& s) se::Object *json = args[0].toObject(); se::Value field; - cc::gfx::BindingUnit* cobj = JSB_ALLOC(cc::gfx::BindingUnit); - cc::gfx::ShaderType arg0; - json->getProperty("shaderStages", &field); + cc::gfx::DescriptorSetLayoutBinding* cobj = JSB_ALLOC(cc::gfx::DescriptorSetLayoutBinding); + cc::gfx::DescriptorType arg0; + json->getProperty("descriptorType", &field); if(!field.isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->shaderStages = arg0; + do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::DescriptorType)tmp; } while(false); + cobj->descriptorType = arg0; } unsigned int arg1 = 0; - json->getProperty("binding", &field); - if(!field.isUndefined()) { - ok &= seval_to_uint32(field, (uint32_t*)&arg1); - cobj->binding = arg1; - } - cc::gfx::BindingType arg2; - json->getProperty("type", &field); - if(!field.isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg2 = (cc::gfx::BindingType)tmp; } while(false); - cobj->type = arg2; - } - cc::String arg3; - json->getProperty("name", &field); - if(!field.isUndefined()) { - arg3 = field.toStringForce().c_str(); - cobj->name = arg3; - } - unsigned int arg4 = 0; json->getProperty("count", &field); if(!field.isUndefined()) { - ok &= seval_to_uint32(field, (uint32_t*)&arg4); - cobj->count = arg4; - } - cc::gfx::Buffer* arg5 = nullptr; - json->getProperty("buffer", &field); - if(!field.isUndefined()) { - ok &= seval_to_native_ptr(field, &arg5); - cobj->buffer = arg5; + ok &= seval_to_uint32(field, (uint32_t*)&arg1); + cobj->count = arg1; } - cc::gfx::Texture* arg6 = nullptr; - json->getProperty("texture", &field); + cc::gfx::ShaderStageFlagBit arg2; + json->getProperty("stageFlags", &field); if(!field.isUndefined()) { - ok &= seval_to_native_ptr(field, &arg6); - cobj->texture = arg6; + do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg2 = (cc::gfx::ShaderStageFlagBit)tmp; } while(false); + cobj->stageFlags = arg2; } - cc::gfx::Sampler* arg7 = nullptr; - json->getProperty("sampler", &field); + std::vector arg3; + json->getProperty("immutableSamplers", &field); if(!field.isUndefined()) { - ok &= seval_to_native_ptr(field, &arg7); - cobj->sampler = arg7; + ok &= seval_to_std_vector(field, &arg3); + cobj->immutableSamplers = arg3; } if(!ok) { @@ -8325,48 +8332,28 @@ static bool js_gfx_BindingUnit_constructor(se::State& s) se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; } - else if(argc == 8) + else if(argc == 4) { - cc::gfx::BindingUnit* cobj = JSB_ALLOC(cc::gfx::BindingUnit); - cc::gfx::ShaderType arg0; + cc::gfx::DescriptorSetLayoutBinding* cobj = JSB_ALLOC(cc::gfx::DescriptorSetLayoutBinding); + cc::gfx::DescriptorType arg0; if (!args[0].isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::ShaderType)tmp; } while(false); - cobj->shaderStages = arg0; + do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::DescriptorType)tmp; } while(false); + cobj->descriptorType = arg0; } unsigned int arg1 = 0; if (!args[1].isUndefined()) { ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); - cobj->binding = arg1; + cobj->count = arg1; } - cc::gfx::BindingType arg2; + cc::gfx::ShaderStageFlagBit arg2; if (!args[2].isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(args[2], &tmp); arg2 = (cc::gfx::BindingType)tmp; } while(false); - cobj->type = arg2; + do { int32_t tmp = 0; ok &= seval_to_int32(args[2], &tmp); arg2 = (cc::gfx::ShaderStageFlagBit)tmp; } while(false); + cobj->stageFlags = arg2; } - cc::String arg3; + std::vector arg3; if (!args[3].isUndefined()) { - arg3 = args[3].toStringForce().c_str(); - cobj->name = arg3; - } - unsigned int arg4 = 0; - if (!args[4].isUndefined()) { - ok &= seval_to_uint32(args[4], (uint32_t*)&arg4); - cobj->count = arg4; - } - cc::gfx::Buffer* arg5 = nullptr; - if (!args[5].isUndefined()) { - ok &= seval_to_native_ptr(args[5], &arg5); - cobj->buffer = arg5; - } - cc::gfx::Texture* arg6 = nullptr; - if (!args[6].isUndefined()) { - ok &= seval_to_native_ptr(args[6], &arg6); - cobj->texture = arg6; - } - cc::gfx::Sampler* arg7 = nullptr; - if (!args[7].isUndefined()) { - ok &= seval_to_native_ptr(args[7], &arg7); - cobj->sampler = arg7; + ok &= seval_to_std_vector(args[3], &arg3); + cobj->immutableSamplers = arg3; } if(!ok) { @@ -8383,81 +8370,77 @@ static bool js_gfx_BindingUnit_constructor(se::State& s) SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; } -SE_BIND_CTOR(js_gfx_BindingUnit_constructor, __jsb_cc_gfx_BindingUnit_class, js_cc_gfx_BindingUnit_finalize) +SE_BIND_CTOR(js_gfx_DescriptorSetLayoutBinding_constructor, __jsb_cc_gfx_DescriptorSetLayoutBinding_class, js_cc_gfx_DescriptorSetLayoutBinding_finalize) -static bool js_cc_gfx_BindingUnit_finalize(se::State& s) +static bool js_cc_gfx_DescriptorSetLayoutBinding_finalize(se::State& s) { auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::BindingUnit* cobj = (cc::gfx::BindingUnit*)s.nativeThisObject(); + cc::gfx::DescriptorSetLayoutBinding* cobj = (cc::gfx::DescriptorSetLayoutBinding*)s.nativeThisObject(); JSB_FREE(cobj); } return true; } -SE_BIND_FINALIZE_FUNC(js_cc_gfx_BindingUnit_finalize) +SE_BIND_FINALIZE_FUNC(js_cc_gfx_DescriptorSetLayoutBinding_finalize) -bool js_register_gfx_BindingUnit(se::Object* obj) +bool js_register_gfx_DescriptorSetLayoutBinding(se::Object* obj) { - auto cls = se::Class::create("BindingUnit", obj, nullptr, _SE(js_gfx_BindingUnit_constructor)); + auto cls = se::Class::create("DescriptorSetLayoutBinding", obj, nullptr, _SE(js_gfx_DescriptorSetLayoutBinding_constructor)); - cls->defineProperty("shaderStages", _SE(js_gfx_BindingUnit_get_shaderStages), _SE(js_gfx_BindingUnit_set_shaderStages)); - cls->defineProperty("binding", _SE(js_gfx_BindingUnit_get_binding), _SE(js_gfx_BindingUnit_set_binding)); - cls->defineProperty("type", _SE(js_gfx_BindingUnit_get_type), _SE(js_gfx_BindingUnit_set_type)); - cls->defineProperty("name", _SE(js_gfx_BindingUnit_get_name), _SE(js_gfx_BindingUnit_set_name)); - cls->defineProperty("count", _SE(js_gfx_BindingUnit_get_count), _SE(js_gfx_BindingUnit_set_count)); - cls->defineProperty("buffer", _SE(js_gfx_BindingUnit_get_buffer), _SE(js_gfx_BindingUnit_set_buffer)); - cls->defineProperty("texture", _SE(js_gfx_BindingUnit_get_texture), _SE(js_gfx_BindingUnit_set_texture)); - cls->defineProperty("sampler", _SE(js_gfx_BindingUnit_get_sampler), _SE(js_gfx_BindingUnit_set_sampler)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_BindingUnit_finalize)); + cls->defineProperty("descriptorType", _SE(js_gfx_DescriptorSetLayoutBinding_get_descriptorType), _SE(js_gfx_DescriptorSetLayoutBinding_set_descriptorType)); + cls->defineProperty("count", _SE(js_gfx_DescriptorSetLayoutBinding_get_count), _SE(js_gfx_DescriptorSetLayoutBinding_set_count)); + cls->defineProperty("stageFlags", _SE(js_gfx_DescriptorSetLayoutBinding_get_stageFlags), _SE(js_gfx_DescriptorSetLayoutBinding_set_stageFlags)); + cls->defineProperty("immutableSamplers", _SE(js_gfx_DescriptorSetLayoutBinding_get_immutableSamplers), _SE(js_gfx_DescriptorSetLayoutBinding_set_immutableSamplers)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_DescriptorSetLayoutBinding_finalize)); cls->install(); - JSBClassType::registerClass(cls); + JSBClassType::registerClass(cls); - __jsb_cc_gfx_BindingUnit_proto = cls->getProto(); - __jsb_cc_gfx_BindingUnit_class = cls; + __jsb_cc_gfx_DescriptorSetLayoutBinding_proto = cls->getProto(); + __jsb_cc_gfx_DescriptorSetLayoutBinding_class = cls; se::ScriptEngine::getInstance()->clearException(); return true; } -se::Object* __jsb_cc_gfx_InputState_proto = nullptr; -se::Class* __jsb_cc_gfx_InputState_class = nullptr; +se::Object* __jsb_cc_gfx_DescriptorSetLayoutInfo_proto = nullptr; +se::Class* __jsb_cc_gfx_DescriptorSetLayoutInfo_class = nullptr; -static bool js_gfx_InputState_get_attributes(se::State& s) +static bool js_gfx_DescriptorSetLayoutInfo_get_bindings(se::State& s) { - cc::gfx::InputState* cobj = (cc::gfx::InputState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_InputState_get_attributes : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutInfo* cobj = (cc::gfx::DescriptorSetLayoutInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutInfo_get_bindings : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= std_vector_to_seval(cobj->attributes, &jsret); + ok &= std_vector_to_seval(cobj->bindings, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_InputState_get_attributes) +SE_BIND_PROP_GET(js_gfx_DescriptorSetLayoutInfo_get_bindings) -static bool js_gfx_InputState_set_attributes(se::State& s) +static bool js_gfx_DescriptorSetLayoutInfo_set_bindings(se::State& s) { const auto& args = s.args(); - cc::gfx::InputState* cobj = (cc::gfx::InputState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_InputState_set_attributes : Invalid Native Object"); + cc::gfx::DescriptorSetLayoutInfo* cobj = (cc::gfx::DescriptorSetLayoutInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayoutInfo_set_bindings : Invalid Native Object"); CC_UNUSED bool ok = true; - std::vector arg0; + std::vector arg0; ok &= seval_to_std_vector(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_InputState_set_attributes : Error processing new value"); - cobj->attributes = arg0; + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayoutInfo_set_bindings : Error processing new value"); + cobj->bindings = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_InputState_set_attributes) +SE_BIND_PROP_SET(js_gfx_DescriptorSetLayoutInfo_set_bindings) -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_InputState_finalize) +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_DescriptorSetLayoutInfo_finalize) -static bool js_gfx_InputState_constructor(se::State& s) +static bool js_gfx_DescriptorSetLayoutInfo_constructor(se::State& s) { CC_UNUSED bool ok = true; const auto& args = s.args(); @@ -8465,18 +8448,18 @@ static bool js_gfx_InputState_constructor(se::State& s) if(argc == 0) { - cc::gfx::InputState* cobj = JSB_ALLOC(cc::gfx::InputState); + cc::gfx::DescriptorSetLayoutInfo* cobj = JSB_ALLOC(cc::gfx::DescriptorSetLayoutInfo); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; } else if(argc == 1) { - cc::gfx::InputState* cobj = JSB_ALLOC(cc::gfx::InputState); - std::vector arg0; + cc::gfx::DescriptorSetLayoutInfo* cobj = JSB_ALLOC(cc::gfx::DescriptorSetLayoutInfo); + std::vector arg0; if (!args[0].isUndefined()) { ok &= seval_to_std_vector(args[0], &arg0); - cobj->attributes = arg0; + cobj->bindings = arg0; } if(!ok) { @@ -8493,88 +8476,397 @@ static bool js_gfx_InputState_constructor(se::State& s) SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; } -SE_BIND_CTOR(js_gfx_InputState_constructor, __jsb_cc_gfx_InputState_class, js_cc_gfx_InputState_finalize) +SE_BIND_CTOR(js_gfx_DescriptorSetLayoutInfo_constructor, __jsb_cc_gfx_DescriptorSetLayoutInfo_class, js_cc_gfx_DescriptorSetLayoutInfo_finalize) -static bool js_cc_gfx_InputState_finalize(se::State& s) +static bool js_cc_gfx_DescriptorSetLayoutInfo_finalize(se::State& s) { auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::InputState* cobj = (cc::gfx::InputState*)s.nativeThisObject(); + cc::gfx::DescriptorSetLayoutInfo* cobj = (cc::gfx::DescriptorSetLayoutInfo*)s.nativeThisObject(); JSB_FREE(cobj); } return true; } -SE_BIND_FINALIZE_FUNC(js_cc_gfx_InputState_finalize) +SE_BIND_FINALIZE_FUNC(js_cc_gfx_DescriptorSetLayoutInfo_finalize) -bool js_register_gfx_InputState(se::Object* obj) +bool js_register_gfx_DescriptorSetLayoutInfo(se::Object* obj) { - auto cls = se::Class::create("InputState", obj, nullptr, _SE(js_gfx_InputState_constructor)); + auto cls = se::Class::create("DescriptorSetLayoutInfo", obj, nullptr, _SE(js_gfx_DescriptorSetLayoutInfo_constructor)); - cls->defineProperty("attributes", _SE(js_gfx_InputState_get_attributes), _SE(js_gfx_InputState_set_attributes)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_InputState_finalize)); + cls->defineProperty("bindings", _SE(js_gfx_DescriptorSetLayoutInfo_get_bindings), _SE(js_gfx_DescriptorSetLayoutInfo_set_bindings)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_DescriptorSetLayoutInfo_finalize)); cls->install(); - JSBClassType::registerClass(cls); + JSBClassType::registerClass(cls); - __jsb_cc_gfx_InputState_proto = cls->getProto(); - __jsb_cc_gfx_InputState_class = cls; + __jsb_cc_gfx_DescriptorSetLayoutInfo_proto = cls->getProto(); + __jsb_cc_gfx_DescriptorSetLayoutInfo_class = cls; se::ScriptEngine::getInstance()->clearException(); return true; } -se::Object* __jsb_cc_gfx_RasterizerState_proto = nullptr; -se::Class* __jsb_cc_gfx_RasterizerState_class = nullptr; +se::Object* __jsb_cc_gfx_DescriptorSetInfo_proto = nullptr; +se::Class* __jsb_cc_gfx_DescriptorSetInfo_class = nullptr; -static bool js_gfx_RasterizerState_get_isDiscard(se::State& s) +static bool js_gfx_DescriptorSetInfo_get_layout(se::State& s) { - cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_RasterizerState_get_isDiscard : Invalid Native Object"); + cc::gfx::DescriptorSetInfo* cobj = (cc::gfx::DescriptorSetInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetInfo_get_layout : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= boolean_to_seval(cobj->isDiscard, &jsret); + ok &= native_ptr_to_seval(cobj->layout, &jsret); s.rval() = jsret; return true; } -SE_BIND_PROP_GET(js_gfx_RasterizerState_get_isDiscard) +SE_BIND_PROP_GET(js_gfx_DescriptorSetInfo_get_layout) -static bool js_gfx_RasterizerState_set_isDiscard(se::State& s) +static bool js_gfx_DescriptorSetInfo_set_layout(se::State& s) { const auto& args = s.args(); - cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_RasterizerState_set_isDiscard : Invalid Native Object"); + cc::gfx::DescriptorSetInfo* cobj = (cc::gfx::DescriptorSetInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetInfo_set_layout : Invalid Native Object"); CC_UNUSED bool ok = true; - bool arg0; - ok &= seval_to_boolean(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_RasterizerState_set_isDiscard : Error processing new value"); - cobj->isDiscard = arg0; + cc::gfx::DescriptorSetLayout* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetInfo_set_layout : Error processing new value"); + cobj->layout = arg0; return true; } -SE_BIND_PROP_SET(js_gfx_RasterizerState_set_isDiscard) - -static bool js_gfx_RasterizerState_get_polygonMode(se::State& s) -{ - cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_RasterizerState_get_polygonMode : Invalid Native Object"); +SE_BIND_PROP_SET(js_gfx_DescriptorSetInfo_set_layout) - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= int32_to_seval((int)cobj->polygonMode, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_RasterizerState_get_polygonMode) +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_DescriptorSetInfo_finalize) -static bool js_gfx_RasterizerState_set_polygonMode(se::State& s) +static bool js_gfx_DescriptorSetInfo_constructor(se::State& s) { + CC_UNUSED bool ok = true; const auto& args = s.args(); - cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); + size_t argc = args.size(); + + if(argc == 0) + { + cc::gfx::DescriptorSetInfo* cobj = JSB_ALLOC(cc::gfx::DescriptorSetInfo); + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + else if(argc == 1) + { + cc::gfx::DescriptorSetInfo* cobj = JSB_ALLOC(cc::gfx::DescriptorSetInfo); + cc::gfx::DescriptorSetLayout* arg0 = nullptr; + if (!args[0].isUndefined()) { + ok &= seval_to_native_ptr(args[0], &arg0); + cobj->layout = arg0; + } + + if(!ok) { + JSB_FREE(cobj); + SE_REPORT_ERROR("Argument convertion error"); + return false; + } + + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_CTOR(js_gfx_DescriptorSetInfo_constructor, __jsb_cc_gfx_DescriptorSetInfo_class, js_cc_gfx_DescriptorSetInfo_finalize) + + + + +static bool js_cc_gfx_DescriptorSetInfo_finalize(se::State& s) +{ + auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) + { + se::NonRefNativePtrCreatedByCtorMap::erase(iter); + cc::gfx::DescriptorSetInfo* cobj = (cc::gfx::DescriptorSetInfo*)s.nativeThisObject(); + JSB_FREE(cobj); + } + return true; +} +SE_BIND_FINALIZE_FUNC(js_cc_gfx_DescriptorSetInfo_finalize) + +bool js_register_gfx_DescriptorSetInfo(se::Object* obj) +{ + auto cls = se::Class::create("DescriptorSetInfo", obj, nullptr, _SE(js_gfx_DescriptorSetInfo_constructor)); + + cls->defineProperty("layout", _SE(js_gfx_DescriptorSetInfo_get_layout), _SE(js_gfx_DescriptorSetInfo_set_layout)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_DescriptorSetInfo_finalize)); + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_gfx_DescriptorSetInfo_proto = cls->getProto(); + __jsb_cc_gfx_DescriptorSetInfo_class = cls; + + se::ScriptEngine::getInstance()->clearException(); + return true; +} + +se::Object* __jsb_cc_gfx_PipelineLayoutInfo_proto = nullptr; +se::Class* __jsb_cc_gfx_PipelineLayoutInfo_class = nullptr; + +static bool js_gfx_PipelineLayoutInfo_get_setLayouts(se::State& s) +{ + cc::gfx::PipelineLayoutInfo* cobj = (cc::gfx::PipelineLayoutInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineLayoutInfo_get_setLayouts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= std_vector_to_seval(cobj->setLayouts, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_PipelineLayoutInfo_get_setLayouts) + +static bool js_gfx_PipelineLayoutInfo_set_setLayouts(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::PipelineLayoutInfo* cobj = (cc::gfx::PipelineLayoutInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineLayoutInfo_set_setLayouts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + std::vector arg0; + ok &= seval_to_std_vector(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineLayoutInfo_set_setLayouts : Error processing new value"); + cobj->setLayouts = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_PipelineLayoutInfo_set_setLayouts) + +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_PipelineLayoutInfo_finalize) + +static bool js_gfx_PipelineLayoutInfo_constructor(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + + if(argc == 0) + { + cc::gfx::PipelineLayoutInfo* cobj = JSB_ALLOC(cc::gfx::PipelineLayoutInfo); + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + else if(argc == 1) + { + cc::gfx::PipelineLayoutInfo* cobj = JSB_ALLOC(cc::gfx::PipelineLayoutInfo); + std::vector arg0; + if (!args[0].isUndefined()) { + ok &= seval_to_std_vector(args[0], &arg0); + cobj->setLayouts = arg0; + } + + if(!ok) { + JSB_FREE(cobj); + SE_REPORT_ERROR("Argument convertion error"); + return false; + } + + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_CTOR(js_gfx_PipelineLayoutInfo_constructor, __jsb_cc_gfx_PipelineLayoutInfo_class, js_cc_gfx_PipelineLayoutInfo_finalize) + + + + +static bool js_cc_gfx_PipelineLayoutInfo_finalize(se::State& s) +{ + auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) + { + se::NonRefNativePtrCreatedByCtorMap::erase(iter); + cc::gfx::PipelineLayoutInfo* cobj = (cc::gfx::PipelineLayoutInfo*)s.nativeThisObject(); + JSB_FREE(cobj); + } + return true; +} +SE_BIND_FINALIZE_FUNC(js_cc_gfx_PipelineLayoutInfo_finalize) + +bool js_register_gfx_PipelineLayoutInfo(se::Object* obj) +{ + auto cls = se::Class::create("PipelineLayoutInfo", obj, nullptr, _SE(js_gfx_PipelineLayoutInfo_constructor)); + + cls->defineProperty("setLayouts", _SE(js_gfx_PipelineLayoutInfo_get_setLayouts), _SE(js_gfx_PipelineLayoutInfo_set_setLayouts)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_PipelineLayoutInfo_finalize)); + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_gfx_PipelineLayoutInfo_proto = cls->getProto(); + __jsb_cc_gfx_PipelineLayoutInfo_class = cls; + + se::ScriptEngine::getInstance()->clearException(); + return true; +} + +se::Object* __jsb_cc_gfx_InputState_proto = nullptr; +se::Class* __jsb_cc_gfx_InputState_class = nullptr; + +static bool js_gfx_InputState_get_attributes(se::State& s) +{ + cc::gfx::InputState* cobj = (cc::gfx::InputState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_InputState_get_attributes : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= std_vector_to_seval(cobj->attributes, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_InputState_get_attributes) + +static bool js_gfx_InputState_set_attributes(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::InputState* cobj = (cc::gfx::InputState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_InputState_set_attributes : Invalid Native Object"); + + CC_UNUSED bool ok = true; + std::vector arg0; + ok &= seval_to_std_vector(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_InputState_set_attributes : Error processing new value"); + cobj->attributes = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_InputState_set_attributes) + +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_InputState_finalize) + +static bool js_gfx_InputState_constructor(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + + if(argc == 0) + { + cc::gfx::InputState* cobj = JSB_ALLOC(cc::gfx::InputState); + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + else if(argc == 1) + { + cc::gfx::InputState* cobj = JSB_ALLOC(cc::gfx::InputState); + std::vector arg0; + if (!args[0].isUndefined()) { + ok &= seval_to_std_vector(args[0], &arg0); + cobj->attributes = arg0; + } + + if(!ok) { + JSB_FREE(cobj); + SE_REPORT_ERROR("Argument convertion error"); + return false; + } + + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_CTOR(js_gfx_InputState_constructor, __jsb_cc_gfx_InputState_class, js_cc_gfx_InputState_finalize) + + + + +static bool js_cc_gfx_InputState_finalize(se::State& s) +{ + auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) + { + se::NonRefNativePtrCreatedByCtorMap::erase(iter); + cc::gfx::InputState* cobj = (cc::gfx::InputState*)s.nativeThisObject(); + JSB_FREE(cobj); + } + return true; +} +SE_BIND_FINALIZE_FUNC(js_cc_gfx_InputState_finalize) + +bool js_register_gfx_InputState(se::Object* obj) +{ + auto cls = se::Class::create("InputState", obj, nullptr, _SE(js_gfx_InputState_constructor)); + + cls->defineProperty("attributes", _SE(js_gfx_InputState_get_attributes), _SE(js_gfx_InputState_set_attributes)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_InputState_finalize)); + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_gfx_InputState_proto = cls->getProto(); + __jsb_cc_gfx_InputState_class = cls; + + se::ScriptEngine::getInstance()->clearException(); + return true; +} + +se::Object* __jsb_cc_gfx_RasterizerState_proto = nullptr; +se::Class* __jsb_cc_gfx_RasterizerState_class = nullptr; + +static bool js_gfx_RasterizerState_get_isDiscard(se::State& s) +{ + cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_RasterizerState_get_isDiscard : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= boolean_to_seval(cobj->isDiscard, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_RasterizerState_get_isDiscard) + +static bool js_gfx_RasterizerState_set_isDiscard(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_RasterizerState_set_isDiscard : Invalid Native Object"); + + CC_UNUSED bool ok = true; + bool arg0; + ok &= seval_to_boolean(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_RasterizerState_set_isDiscard : Error processing new value"); + cobj->isDiscard = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_RasterizerState_set_isDiscard) + +static bool js_gfx_RasterizerState_get_polygonMode(se::State& s) +{ + cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_RasterizerState_get_polygonMode : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= int32_to_seval((int)cobj->polygonMode, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_RasterizerState_get_polygonMode) + +static bool js_gfx_RasterizerState_set_polygonMode(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::RasterizerState* cobj = (cc::gfx::RasterizerState*)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_RasterizerState_set_polygonMode : Invalid Native Object"); CC_UNUSED bool ok = true; @@ -10789,6 +11081,34 @@ static bool js_gfx_PipelineStateInfo_set_renderPass(se::State& s) } SE_BIND_PROP_SET(js_gfx_PipelineStateInfo_set_renderPass) +static bool js_gfx_PipelineStateInfo_get_pipelineLayout(se::State& s) +{ + cc::gfx::PipelineStateInfo* cobj = (cc::gfx::PipelineStateInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineStateInfo_get_pipelineLayout : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= native_ptr_to_seval(cobj->pipelineLayout, &jsret); + s.rval() = jsret; + return true; +} +SE_BIND_PROP_GET(js_gfx_PipelineStateInfo_get_pipelineLayout) + +static bool js_gfx_PipelineStateInfo_set_pipelineLayout(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::PipelineStateInfo* cobj = (cc::gfx::PipelineStateInfo*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineStateInfo_set_pipelineLayout : Invalid Native Object"); + + CC_UNUSED bool ok = true; + cc::gfx::PipelineLayout* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineStateInfo_set_pipelineLayout : Error processing new value"); + cobj->pipelineLayout = arg0; + return true; +} +SE_BIND_PROP_SET(js_gfx_PipelineStateInfo_set_pipelineLayout) + SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_PipelineStateInfo_finalize) static bool js_gfx_PipelineStateInfo_constructor(se::State& s) @@ -10858,6 +11178,12 @@ static bool js_gfx_PipelineStateInfo_constructor(se::State& s) ok &= seval_to_native_ptr(field, &arg7); cobj->renderPass = arg7; } + cc::gfx::PipelineLayout* arg8 = nullptr; + json->getProperty("pipelineLayout", &field); + if(!field.isUndefined()) { + ok &= seval_to_native_ptr(field, &arg8); + cobj->pipelineLayout = arg8; + } if(!ok) { JSB_FREE(cobj); @@ -10869,7 +11195,7 @@ static bool js_gfx_PipelineStateInfo_constructor(se::State& s) se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; } - else if(argc == 8) + else if(argc == 9) { cc::gfx::PipelineStateInfo* cobj = JSB_ALLOC(cc::gfx::PipelineStateInfo); cc::gfx::PrimitiveMode arg0; @@ -10912,6 +11238,11 @@ static bool js_gfx_PipelineStateInfo_constructor(se::State& s) ok &= seval_to_native_ptr(args[7], &arg7); cobj->renderPass = arg7; } + cc::gfx::PipelineLayout* arg8 = nullptr; + if (!args[8].isUndefined()) { + ok &= seval_to_native_ptr(args[8], &arg8); + cobj->pipelineLayout = arg8; + } if(!ok) { JSB_FREE(cobj); @@ -10957,6 +11288,7 @@ bool js_register_gfx_PipelineStateInfo(se::Object* obj) cls->defineProperty("blendState", _SE(js_gfx_PipelineStateInfo_get_blendState), _SE(js_gfx_PipelineStateInfo_set_blendState)); cls->defineProperty("dynamicStates", _SE(js_gfx_PipelineStateInfo_get_dynamicStates), _SE(js_gfx_PipelineStateInfo_set_dynamicStates)); cls->defineProperty("renderPass", _SE(js_gfx_PipelineStateInfo_get_renderPass), _SE(js_gfx_PipelineStateInfo_set_renderPass)); + cls->defineProperty("pipelineLayout", _SE(js_gfx_PipelineStateInfo_get_pipelineLayout), _SE(js_gfx_PipelineStateInfo_set_pipelineLayout)); cls->defineFinalizeFunction(_SE(js_cc_gfx_PipelineStateInfo_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -11900,6 +12232,24 @@ bool js_register_gfx_GFXObject(se::Object* obj) se::Object* __jsb_cc_gfx_Device_proto = nullptr; se::Class* __jsb_cc_gfx_Device_class = nullptr; +static bool js_gfx_Device_getMaxUniformBlockSize(se::State& s) +{ + cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_getMaxUniformBlockSize : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + int result = cobj->getMaxUniformBlockSize(); + ok &= int32_to_seval((int)result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_getMaxUniformBlockSize : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_Device_getMaxUniformBlockSize) + static bool js_gfx_Device_getMaxVertexTextureUnits(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); @@ -12086,6 +12436,27 @@ static bool js_gfx_Device_getQueue(se::State& s) } SE_BIND_PROP_GET(js_gfx_Device_getQueue) +static bool js_gfx_Device_createDescriptorSetLayout(se::State& s) +{ + cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_createDescriptorSetLayout : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 1) { + cc::gfx::DescriptorSetLayoutInfo* arg0 = nullptr; + ok &= seval_to_reference(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createDescriptorSetLayout : Error processing arguments"); + cc::gfx::DescriptorSetLayout* result = cobj->createDescriptorSetLayout(*arg0); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createDescriptorSetLayout : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(js_gfx_Device_createDescriptorSetLayout) + static bool js_gfx_Device_getMaxVertexAttributes(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); @@ -12230,23 +12601,26 @@ static bool js_gfx_Device_getHeight(se::State& s) } SE_BIND_PROP_GET(js_gfx_Device_getHeight) -static bool js_gfx_Device_getMaxFragmentUniformVectors(se::State& s) +static bool js_gfx_Device_createCommandBuffer(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_getMaxFragmentUniformVectors : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_createCommandBuffer : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 0) { - int result = cobj->getMaxFragmentUniformVectors(); - ok &= int32_to_seval((int)result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_getMaxFragmentUniformVectors : Error processing arguments"); + if (argc == 1) { + cc::gfx::CommandBufferInfo* arg0 = nullptr; + ok &= seval_to_reference(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createCommandBuffer : Error processing arguments"); + cc::gfx::CommandBuffer* result = cobj->createCommandBuffer(*arg0); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createCommandBuffer : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_PROP_GET(js_gfx_Device_getMaxFragmentUniformVectors) +SE_BIND_FUNC(js_gfx_Device_createCommandBuffer) static bool js_gfx_Device_createPipelineState(se::State& s) { @@ -12269,26 +12643,26 @@ static bool js_gfx_Device_createPipelineState(se::State& s) } SE_BIND_FUNC(js_gfx_Device_createPipelineState) -static bool js_gfx_Device_createCommandBuffer(se::State& s) +static bool js_gfx_Device_createDescriptorSet(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_createCommandBuffer : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_createDescriptorSet : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - cc::gfx::CommandBufferInfo* arg0 = nullptr; + cc::gfx::DescriptorSetInfo* arg0 = nullptr; ok &= seval_to_reference(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_Device_createCommandBuffer : Error processing arguments"); - cc::gfx::CommandBuffer* result = cobj->createCommandBuffer(*arg0); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createDescriptorSet : Error processing arguments"); + cc::gfx::DescriptorSet* result = cobj->createDescriptorSet(*arg0); ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_createCommandBuffer : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createDescriptorSet : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_FUNC(js_gfx_Device_createCommandBuffer) +SE_BIND_FUNC(js_gfx_Device_createDescriptorSet) static bool js_gfx_Device_present(se::State& s) { @@ -12398,23 +12772,26 @@ static bool js_gfx_Device_createRenderPass(se::State& s) } SE_BIND_FUNC(js_gfx_Device_createRenderPass) -static bool js_gfx_Device_getMaxUniformBlockSize(se::State& s) +static bool js_gfx_Device_createPipelineLayout(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_getMaxUniformBlockSize : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_createPipelineLayout : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 0) { - int result = cobj->getMaxUniformBlockSize(); - ok &= int32_to_seval((int)result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_getMaxUniformBlockSize : Error processing arguments"); + if (argc == 1) { + cc::gfx::PipelineLayoutInfo* arg0 = nullptr; + ok &= seval_to_reference(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createPipelineLayout : Error processing arguments"); + cc::gfx::PipelineLayout* result = cobj->createPipelineLayout(*arg0); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createPipelineLayout : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_PROP_GET(js_gfx_Device_getMaxUniformBlockSize) +SE_BIND_FUNC(js_gfx_Device_createPipelineLayout) static bool js_gfx_Device_acquire(se::State& s) { @@ -12569,27 +12946,6 @@ static bool js_gfx_Device_createSampler(se::State& s) } SE_BIND_FUNC(js_gfx_Device_createSampler) -static bool js_gfx_Device_createBuffer(se::State& s) -{ - cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_createBuffer : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 1) { - cc::gfx::BufferInfo* arg0 = nullptr; - ok &= seval_to_reference(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_Device_createBuffer : Error processing arguments"); - cc::gfx::Buffer* result = cobj->createBuffer(*arg0); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_createBuffer : Error processing arguments"); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); - return false; -} -SE_BIND_FUNC(js_gfx_Device_createBuffer) - static bool js_gfx_Device_getNativeHeight(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); @@ -12687,25 +13043,43 @@ static bool js_gfx_Device_getDepthBits(se::State& s) SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_Device_getDepthBits) +SE_BIND_PROP_GET(js_gfx_Device_getDepthBits) + +static bool js_gfx_Device_getMemoryStatus(se::State& s) +{ + cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_getMemoryStatus : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + cc::gfx::MemoryStatus& result = cobj->getMemoryStatus(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_getMemoryStatus : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_Device_getMemoryStatus) -static bool js_gfx_Device_getMemoryStatus(se::State& s) +static bool js_gfx_Device_getMaxFragmentUniformVectors(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_getMemoryStatus : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_getMaxFragmentUniformVectors : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - cc::gfx::MemoryStatus& result = cobj->getMemoryStatus(); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_getMemoryStatus : Error processing arguments"); + int result = cobj->getMaxFragmentUniformVectors(); + ok &= int32_to_seval((int)result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_getMaxFragmentUniformVectors : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_Device_getMemoryStatus) +SE_BIND_PROP_GET(js_gfx_Device_getMaxFragmentUniformVectors) static bool js_gfx_Device_getMaxTextureUnits(se::State& s) { @@ -12743,23 +13117,23 @@ static bool js_gfx_Device_getClipSpaceMinZ(se::State& s) } SE_BIND_PROP_GET(js_gfx_Device_getClipSpaceMinZ) -static bool js_gfx_Device_getNumDrawCalls(se::State& s) +static bool js_gfx_Device_getUboOffsetAlignment(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_getNumDrawCalls : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_getUboOffsetAlignment : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - unsigned int result = cobj->getNumDrawCalls(); - ok &= uint32_to_seval((unsigned int)result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_getNumDrawCalls : Error processing arguments"); + int result = cobj->getUboOffsetAlignment(); + ok &= int32_to_seval((int)result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_getUboOffsetAlignment : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_Device_getNumDrawCalls) +SE_BIND_PROP_GET(js_gfx_Device_getUboOffsetAlignment) static bool js_gfx_Device_getUVSpaceSignY(se::State& s) { @@ -12797,26 +13171,23 @@ static bool js_gfx_Device_getNativeWidth(se::State& s) } SE_BIND_PROP_GET(js_gfx_Device_getNativeWidth) -static bool js_gfx_Device_createBindingLayout(se::State& s) +static bool js_gfx_Device_getNumDrawCalls(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_createBindingLayout : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_getNumDrawCalls : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 1) { - cc::gfx::BindingLayoutInfo* arg0 = nullptr; - ok &= seval_to_reference(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_Device_createBindingLayout : Error processing arguments"); - cc::gfx::BindingLayout* result = cobj->createBindingLayout(*arg0); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_createBindingLayout : Error processing arguments"); + if (argc == 0) { + unsigned int result = cobj->getNumDrawCalls(); + ok &= uint32_to_seval((unsigned int)result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_getNumDrawCalls : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_FUNC(js_gfx_Device_createBindingLayout) +SE_BIND_PROP_GET(js_gfx_Device_getNumDrawCalls) @@ -12836,6 +13207,7 @@ bool js_register_gfx_Device(se::Object* obj) cls->defineProperty("UVSpaceSignY", _SE(js_gfx_Device_getUVSpaceSignY), nullptr); cls->defineProperty("vendor", _SE(js_gfx_Device_getVendor), nullptr); cls->defineProperty("depthBits", _SE(js_gfx_Device_getDepthBits), nullptr); + cls->defineProperty("uboOffsetAlignment", _SE(js_gfx_Device_getUboOffsetAlignment), nullptr); cls->defineProperty("maxFragmentUniformVectors", _SE(js_gfx_Device_getMaxFragmentUniformVectors), nullptr); cls->defineProperty("maxVertexAttributes", _SE(js_gfx_Device_getMaxVertexAttributes), nullptr); cls->defineProperty("width", _SE(js_gfx_Device_getWidth), nullptr); @@ -12858,22 +13230,23 @@ bool js_register_gfx_Device(se::Object* obj) cls->defineProperty("colorFormat", _SE(js_gfx_Device_getColorFormat), nullptr); cls->defineFunction("hasFeature", _SE(js_gfx_Device_hasFeature)); cls->defineFunction("createFence", _SE(js_gfx_Device_createFence)); - cls->defineFunction("createPipelineState", _SE(js_gfx_Device_createPipelineState)); + cls->defineFunction("createDescriptorSetLayout", _SE(js_gfx_Device_createDescriptorSetLayout)); cls->defineFunction("createCommandBuffer", _SE(js_gfx_Device_createCommandBuffer)); + cls->defineFunction("createPipelineState", _SE(js_gfx_Device_createPipelineState)); + cls->defineFunction("createDescriptorSet", _SE(js_gfx_Device_createDescriptorSet)); cls->defineFunction("present", _SE(js_gfx_Device_present)); cls->defineFunction("destroy", _SE(js_gfx_Device_destroy)); cls->defineFunction("createFramebuffer", _SE(js_gfx_Device_createFramebuffer)); cls->defineFunction("createRenderPass", _SE(js_gfx_Device_createRenderPass)); + cls->defineFunction("createPipelineLayout", _SE(js_gfx_Device_createPipelineLayout)); cls->defineFunction("acquire", _SE(js_gfx_Device_acquire)); cls->defineFunction("createShader", _SE(js_gfx_Device_createShader)); cls->defineFunction("createInputAssembler", _SE(js_gfx_Device_createInputAssembler)); cls->defineFunction("defineMacro", _SE(js_gfx_Device_defineMacro)); cls->defineFunction("createSampler", _SE(js_gfx_Device_createSampler)); - cls->defineFunction("createBuffer", _SE(js_gfx_Device_createBuffer)); cls->defineFunction("initialize", _SE(js_gfx_Device_initialize)); cls->defineFunction("resize", _SE(js_gfx_Device_resize)); cls->defineFunction("createQueue", _SE(js_gfx_Device_createQueue)); - cls->defineFunction("createBindingLayout", _SE(js_gfx_Device_createBindingLayout)); cls->install(); JSBClassType::registerClass(cls); @@ -12887,59 +13260,59 @@ bool js_register_gfx_Device(se::Object* obj) se::Object* __jsb_cc_gfx_Buffer_proto = nullptr; se::Class* __jsb_cc_gfx_Buffer_class = nullptr; -static bool js_gfx_Buffer_getBufferView(se::State& s) +static bool js_gfx_Buffer_getUsage(se::State& s) { cc::gfx::Buffer* cobj = (cc::gfx::Buffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_getBufferView : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_getUsage : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - unsigned char* result = cobj->getBufferView(); - #pragma warning NO CONVERSION FROM NATIVE FOR unsigned char*; - SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getBufferView : Error processing arguments"); + int result = (int)cobj->getUsage(); + ok &= int32_to_seval((int)result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getUsage : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_Buffer_getBufferView) +SE_BIND_PROP_GET(js_gfx_Buffer_getUsage) -static bool js_gfx_Buffer_getUsage(se::State& s) +static bool js_gfx_Buffer_getMemUsage(se::State& s) { cc::gfx::Buffer* cobj = (cc::gfx::Buffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_getUsage : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_getMemUsage : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getUsage(); + int result = (int)cobj->getMemUsage(); ok &= int32_to_seval((int)result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getUsage : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getMemUsage : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_Buffer_getUsage) +SE_BIND_PROP_GET(js_gfx_Buffer_getMemUsage) -static bool js_gfx_Buffer_getMemUsage(se::State& s) +static bool js_gfx_Buffer_getBackupBuffer(se::State& s) { cc::gfx::Buffer* cobj = (cc::gfx::Buffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_getMemUsage : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_getBackupBuffer : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getMemUsage(); - ok &= int32_to_seval((int)result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getMemUsage : Error processing arguments"); + unsigned char* result = cobj->getBackupBuffer(); + #pragma warning NO CONVERSION FROM NATIVE FOR unsigned char*; + SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getBackupBuffer : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_Buffer_getMemUsage) +SE_BIND_PROP_GET(js_gfx_Buffer_getBackupBuffer) static bool js_gfx_Buffer_getSize(se::State& s) { @@ -12977,26 +13350,23 @@ static bool js_gfx_Buffer_getCount(se::State& s) } SE_BIND_PROP_GET(js_gfx_Buffer_getCount) -static bool js_gfx_Buffer_initialize(se::State& s) +static bool js_gfx_Buffer_isBufferView(se::State& s) { cc::gfx::Buffer* cobj = (cc::gfx::Buffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_initialize : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_isBufferView : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 1) { - cc::gfx::BufferInfo* arg0 = nullptr; - ok &= seval_to_reference(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_Buffer_initialize : Error processing arguments"); - bool result = cobj->initialize(*arg0); + if (argc == 0) { + bool result = cobj->isBufferView(); ok &= boolean_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Buffer_initialize : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_Buffer_isBufferView : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_FUNC(js_gfx_Buffer_initialize) +SE_BIND_FUNC(js_gfx_Buffer_isBufferView) static bool js_gfx_Buffer_destroy(se::State& s) { @@ -13120,12 +13490,12 @@ bool js_register_gfx_Buffer(se::Object* obj) cls->defineProperty("count", _SE(js_gfx_Buffer_getCount), nullptr); cls->defineProperty("memUsage", _SE(js_gfx_Buffer_getMemUsage), nullptr); cls->defineProperty("stride", _SE(js_gfx_Buffer_getStride), nullptr); - cls->defineProperty("bufferView", _SE(js_gfx_Buffer_getBufferView), nullptr); cls->defineProperty("usage", _SE(js_gfx_Buffer_getUsage), nullptr); cls->defineProperty("flags", _SE(js_gfx_Buffer_getFlags), nullptr); cls->defineProperty("device", _SE(js_gfx_Buffer_getDevice), nullptr); + cls->defineProperty("backupBuffer", _SE(js_gfx_Buffer_getBackupBuffer), nullptr); cls->defineProperty("size", _SE(js_gfx_Buffer_getSize), nullptr); - cls->defineFunction("initialize", _SE(js_gfx_Buffer_initialize)); + cls->defineFunction("isBufferView", _SE(js_gfx_Buffer_isBufferView)); cls->defineFunction("destroy", _SE(js_gfx_Buffer_destroy)); cls->defineFunction("resize", _SE(js_gfx_Buffer_resize)); cls->defineFinalizeFunction(_SE(js_cc_gfx_Buffer_finalize)); @@ -13394,6 +13764,24 @@ static bool js_gfx_Texture_resize(se::State& s) } SE_BIND_FUNC(js_gfx_Texture_resize) +static bool js_gfx_Texture_isTextureView(se::State& s) +{ + cc::gfx::Texture* cobj = (cc::gfx::Texture*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Texture_isTextureView : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + bool result = cobj->isTextureView(); + ok &= boolean_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Texture_isTextureView : 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_gfx_Texture_isTextureView) + SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_Texture_finalize) static bool js_gfx_Texture_constructor(se::State& s) @@ -13439,6 +13827,7 @@ bool js_register_gfx_Texture(se::Object* obj) cls->defineProperty("size", _SE(js_gfx_Texture_getSize), nullptr); cls->defineFunction("destroy", _SE(js_gfx_Texture_destroy)); cls->defineFunction("resize", _SE(js_gfx_Texture_resize)); + cls->defineFunction("isTextureView", _SE(js_gfx_Texture_isTextureView)); cls->defineFinalizeFunction(_SE(js_cc_gfx_Texture_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -14765,180 +15154,452 @@ static bool js_gfx_Framebuffer_getDevice(se::State& s) SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_Framebuffer_getDevice) +SE_BIND_PROP_GET(js_gfx_Framebuffer_getDevice) + +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_Framebuffer_finalize) + +static bool js_gfx_Framebuffer_constructor(se::State& s) +{ + //#3 cc::gfx::Framebuffer: is_skip_construtor True + se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::Framebuffer constructor is skipped\")"); + return false; +} +SE_BIND_CTOR(js_gfx_Framebuffer_constructor, __jsb_cc_gfx_Framebuffer_class, js_cc_gfx_Framebuffer_finalize) + + + +extern se::Object* __jsb_cc_gfx_GFXObject_proto; + +static bool js_cc_gfx_Framebuffer_finalize(se::State& s) +{ + auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) + { + se::NonRefNativePtrCreatedByCtorMap::erase(iter); + cc::gfx::Framebuffer* cobj = (cc::gfx::Framebuffer*)s.nativeThisObject(); + JSB_FREE(cobj); + } + return true; +} +SE_BIND_FINALIZE_FUNC(js_cc_gfx_Framebuffer_finalize) + +bool js_register_gfx_Framebuffer(se::Object* obj) +{ + auto cls = se::Class::create("Framebuffer", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_Framebuffer_constructor)); + + cls->defineProperty("device", _SE(js_gfx_Framebuffer_getDevice), nullptr); + cls->defineProperty("renderPass", _SE(js_gfx_Framebuffer_getRenderPass), nullptr); + cls->defineProperty("colorTextures", _SE(js_gfx_Framebuffer_getColorTextures), nullptr); + cls->defineProperty("depthStencilTexture", _SE(js_gfx_Framebuffer_getDepthStencilTexture), nullptr); + cls->defineFunction("initialize", _SE(js_gfx_Framebuffer_initialize)); + cls->defineFunction("destroy", _SE(js_gfx_Framebuffer_destroy)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_Framebuffer_finalize)); + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_gfx_Framebuffer_proto = cls->getProto(); + __jsb_cc_gfx_Framebuffer_class = cls; + + se::ScriptEngine::getInstance()->clearException(); + return true; +} + +se::Object* __jsb_cc_gfx_DescriptorSetLayout_proto = nullptr; +se::Class* __jsb_cc_gfx_DescriptorSetLayout_class = nullptr; + +static bool js_gfx_DescriptorSetLayout_initialize(se::State& s) +{ + cc::gfx::DescriptorSetLayout* cobj = (cc::gfx::DescriptorSetLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayout_initialize : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 1) { + cc::gfx::DescriptorSetLayoutInfo* arg0 = nullptr; + ok &= seval_to_reference(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayout_initialize : Error processing arguments"); + bool result = cobj->initialize(*arg0); + ok &= boolean_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayout_initialize : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(js_gfx_DescriptorSetLayout_initialize) + +static bool js_gfx_DescriptorSetLayout_destroy(se::State& s) +{ + cc::gfx::DescriptorSetLayout* cobj = (cc::gfx::DescriptorSetLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayout_destroy : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + if (argc == 0) { + cobj->destroy(); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_gfx_DescriptorSetLayout_destroy) + +static bool js_gfx_DescriptorSetLayout_getDevice(se::State& s) +{ + cc::gfx::DescriptorSetLayout* cobj = (cc::gfx::DescriptorSetLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayout_getDevice : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + cc::gfx::Device* result = cobj->getDevice(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayout_getDevice : 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_gfx_DescriptorSetLayout_getDevice) + +static bool js_gfx_DescriptorSetLayout_getBindings(se::State& s) +{ + cc::gfx::DescriptorSetLayout* cobj = (cc::gfx::DescriptorSetLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSetLayout_getBindings : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const std::vector& result = cobj->getBindings(); + ok &= std_vector_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayout_getBindings : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_DescriptorSetLayout_getBindings) + +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_DescriptorSetLayout_finalize) + +static bool js_gfx_DescriptorSetLayout_constructor(se::State& s) +{ + //#3 cc::gfx::DescriptorSetLayout: is_skip_construtor True + se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::DescriptorSetLayout constructor is skipped\")"); + return false; +} +SE_BIND_CTOR(js_gfx_DescriptorSetLayout_constructor, __jsb_cc_gfx_DescriptorSetLayout_class, js_cc_gfx_DescriptorSetLayout_finalize) + + + +extern se::Object* __jsb_cc_gfx_GFXObject_proto; + +static bool js_cc_gfx_DescriptorSetLayout_finalize(se::State& s) +{ + auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) + { + se::NonRefNativePtrCreatedByCtorMap::erase(iter); + cc::gfx::DescriptorSetLayout* cobj = (cc::gfx::DescriptorSetLayout*)s.nativeThisObject(); + JSB_FREE(cobj); + } + return true; +} +SE_BIND_FINALIZE_FUNC(js_cc_gfx_DescriptorSetLayout_finalize) + +bool js_register_gfx_DescriptorSetLayout(se::Object* obj) +{ + auto cls = se::Class::create("DescriptorSetLayout", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_DescriptorSetLayout_constructor)); + + cls->defineProperty("bindings", _SE(js_gfx_DescriptorSetLayout_getBindings), nullptr); + cls->defineFunction("initialize", _SE(js_gfx_DescriptorSetLayout_initialize)); + cls->defineFunction("destroy", _SE(js_gfx_DescriptorSetLayout_destroy)); + cls->defineFunction("getDevice", _SE(js_gfx_DescriptorSetLayout_getDevice)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_DescriptorSetLayout_finalize)); + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_gfx_DescriptorSetLayout_proto = cls->getProto(); + __jsb_cc_gfx_DescriptorSetLayout_class = cls; + + se::ScriptEngine::getInstance()->clearException(); + return true; +} + +se::Object* __jsb_cc_gfx_PipelineLayout_proto = nullptr; +se::Class* __jsb_cc_gfx_PipelineLayout_class = nullptr; + +static bool js_gfx_PipelineLayout_initialize(se::State& s) +{ + cc::gfx::PipelineLayout* cobj = (cc::gfx::PipelineLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineLayout_initialize : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 1) { + cc::gfx::PipelineLayoutInfo* arg0 = nullptr; + ok &= seval_to_reference(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineLayout_initialize : Error processing arguments"); + bool result = cobj->initialize(*arg0); + ok &= boolean_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineLayout_initialize : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(js_gfx_PipelineLayout_initialize) + +static bool js_gfx_PipelineLayout_destroy(se::State& s) +{ + cc::gfx::PipelineLayout* cobj = (cc::gfx::PipelineLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineLayout_destroy : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + if (argc == 0) { + cobj->destroy(); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_gfx_PipelineLayout_destroy) + +static bool js_gfx_PipelineLayout_getDevice(se::State& s) +{ + cc::gfx::PipelineLayout* cobj = (cc::gfx::PipelineLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineLayout_getDevice : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + cc::gfx::Device* result = cobj->getDevice(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineLayout_getDevice : 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_gfx_PipelineLayout_getDevice) + +static bool js_gfx_PipelineLayout_getSetLayouts(se::State& s) +{ + cc::gfx::PipelineLayout* cobj = (cc::gfx::PipelineLayout*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineLayout_getSetLayouts : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const std::vector& result = cobj->getSetLayouts(); + ok &= std_vector_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineLayout_getSetLayouts : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_PipelineLayout_getSetLayouts) -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_Framebuffer_finalize) +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_PipelineLayout_finalize) -static bool js_gfx_Framebuffer_constructor(se::State& s) +static bool js_gfx_PipelineLayout_constructor(se::State& s) { - //#3 cc::gfx::Framebuffer: is_skip_construtor True - se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::Framebuffer constructor is skipped\")"); + //#3 cc::gfx::PipelineLayout: is_skip_construtor True + se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::PipelineLayout constructor is skipped\")"); return false; } -SE_BIND_CTOR(js_gfx_Framebuffer_constructor, __jsb_cc_gfx_Framebuffer_class, js_cc_gfx_Framebuffer_finalize) +SE_BIND_CTOR(js_gfx_PipelineLayout_constructor, __jsb_cc_gfx_PipelineLayout_class, js_cc_gfx_PipelineLayout_finalize) extern se::Object* __jsb_cc_gfx_GFXObject_proto; -static bool js_cc_gfx_Framebuffer_finalize(se::State& s) +static bool js_cc_gfx_PipelineLayout_finalize(se::State& s) { auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::Framebuffer* cobj = (cc::gfx::Framebuffer*)s.nativeThisObject(); + cc::gfx::PipelineLayout* cobj = (cc::gfx::PipelineLayout*)s.nativeThisObject(); JSB_FREE(cobj); } return true; } -SE_BIND_FINALIZE_FUNC(js_cc_gfx_Framebuffer_finalize) +SE_BIND_FINALIZE_FUNC(js_cc_gfx_PipelineLayout_finalize) -bool js_register_gfx_Framebuffer(se::Object* obj) +bool js_register_gfx_PipelineLayout(se::Object* obj) { - auto cls = se::Class::create("Framebuffer", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_Framebuffer_constructor)); + auto cls = se::Class::create("PipelineLayout", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_PipelineLayout_constructor)); - cls->defineProperty("device", _SE(js_gfx_Framebuffer_getDevice), nullptr); - cls->defineProperty("renderPass", _SE(js_gfx_Framebuffer_getRenderPass), nullptr); - cls->defineProperty("colorTextures", _SE(js_gfx_Framebuffer_getColorTextures), nullptr); - cls->defineProperty("depthStencilTexture", _SE(js_gfx_Framebuffer_getDepthStencilTexture), nullptr); - cls->defineFunction("initialize", _SE(js_gfx_Framebuffer_initialize)); - cls->defineFunction("destroy", _SE(js_gfx_Framebuffer_destroy)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_Framebuffer_finalize)); + cls->defineProperty("setLayouts", _SE(js_gfx_PipelineLayout_getSetLayouts), nullptr); + cls->defineFunction("initialize", _SE(js_gfx_PipelineLayout_initialize)); + cls->defineFunction("destroy", _SE(js_gfx_PipelineLayout_destroy)); + cls->defineFunction("getDevice", _SE(js_gfx_PipelineLayout_getDevice)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_PipelineLayout_finalize)); cls->install(); - JSBClassType::registerClass(cls); + JSBClassType::registerClass(cls); - __jsb_cc_gfx_Framebuffer_proto = cls->getProto(); - __jsb_cc_gfx_Framebuffer_class = cls; + __jsb_cc_gfx_PipelineLayout_proto = cls->getProto(); + __jsb_cc_gfx_PipelineLayout_class = cls; se::ScriptEngine::getInstance()->clearException(); return true; } -se::Object* __jsb_cc_gfx_BindingLayout_proto = nullptr; -se::Class* __jsb_cc_gfx_BindingLayout_class = nullptr; +se::Object* __jsb_cc_gfx_PipelineState_proto = nullptr; +se::Class* __jsb_cc_gfx_PipelineState_class = nullptr; -static bool js_gfx_BindingLayout_getBindingUnits(se::State& s) +static bool js_gfx_PipelineState_getRasterizerState(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_getBindingUnits : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getRasterizerState : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - const std::vector& result = cobj->getBindingUnits(); - ok &= std_vector_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayout_getBindingUnits : Error processing arguments"); + const cc::gfx::RasterizerState& result = cobj->getRasterizerState(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getRasterizerState : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_BindingLayout_getBindingUnits) +SE_BIND_PROP_GET(js_gfx_PipelineState_getRasterizerState) -static bool js_gfx_BindingLayout_bindBuffer(se::State& s) +static bool js_gfx_PipelineState_getShader(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_bindBuffer : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getShader : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 2) { - unsigned int arg0 = 0; - cc::gfx::Buffer* arg1 = nullptr; - ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); - ok &= seval_to_native_ptr(args[1], &arg1); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayout_bindBuffer : Error processing arguments"); - cobj->bindBuffer(arg0, arg1); + if (argc == 0) { + cc::gfx::Shader* result = cobj->getShader(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getShader : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_FUNC(js_gfx_BindingLayout_bindBuffer) +SE_BIND_PROP_GET(js_gfx_PipelineState_getShader) -static bool js_gfx_BindingLayout_bindSampler(se::State& s) +static bool js_gfx_PipelineState_getInputState(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_bindSampler : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getInputState : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 2) { - unsigned int arg0 = 0; - cc::gfx::Sampler* arg1 = nullptr; - ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); - ok &= seval_to_native_ptr(args[1], &arg1); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayout_bindSampler : Error processing arguments"); - cobj->bindSampler(arg0, arg1); + if (argc == 0) { + const cc::gfx::InputState& result = cobj->getInputState(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getInputState : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_FUNC(js_gfx_BindingLayout_bindSampler) +SE_BIND_PROP_GET(js_gfx_PipelineState_getInputState) -static bool js_gfx_BindingLayout_update(se::State& s) +static bool js_gfx_PipelineState_getPrimitive(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_update : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getPrimitive : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); + CC_UNUSED bool ok = true; if (argc == 0) { - cobj->update(); + int result = (int)cobj->getPrimitive(); + ok &= int32_to_seval((int)result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getPrimitive : 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_gfx_BindingLayout_update) +SE_BIND_PROP_GET(js_gfx_PipelineState_getPrimitive) -static bool js_gfx_BindingLayout_bindTexture(se::State& s) +static bool js_gfx_PipelineState_getDepthStencilState(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_bindTexture : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getDepthStencilState : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 2) { - unsigned int arg0 = 0; - cc::gfx::Texture* arg1 = nullptr; - ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); - ok &= seval_to_native_ptr(args[1], &arg1); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayout_bindTexture : Error processing arguments"); - cobj->bindTexture(arg0, arg1); + if (argc == 0) { + const cc::gfx::DepthStencilState& result = cobj->getDepthStencilState(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getDepthStencilState : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_PipelineState_getDepthStencilState) + +static bool js_gfx_PipelineState_getBlendState(se::State& s) +{ + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getBlendState : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const cc::gfx::BlendState& result = cobj->getBlendState(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getBlendState : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_PipelineState_getBlendState) + +static bool js_gfx_PipelineState_getPipelineLayout(se::State& s) +{ + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getPipelineLayout : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const cc::gfx::PipelineLayout* result = cobj->getPipelineLayout(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getPipelineLayout : 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_gfx_BindingLayout_bindTexture) +SE_BIND_FUNC(js_gfx_PipelineState_getPipelineLayout) -static bool js_gfx_BindingLayout_initialize(se::State& s) +static bool js_gfx_PipelineState_initialize(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_initialize : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_initialize : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - cc::gfx::BindingLayoutInfo* arg0 = nullptr; + cc::gfx::PipelineStateInfo* arg0 = nullptr; ok &= seval_to_reference(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayout_initialize : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_initialize : Error processing arguments"); bool result = cobj->initialize(*arg0); ok &= boolean_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayout_initialize : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_initialize : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_FUNC(js_gfx_BindingLayout_initialize) +SE_BIND_FUNC(js_gfx_PipelineState_initialize) -static bool js_gfx_BindingLayout_destroy(se::State& s) +static bool js_gfx_PipelineState_destroy(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_destroy : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_destroy : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); if (argc == 0) { @@ -14948,325 +15609,361 @@ static bool js_gfx_BindingLayout_destroy(se::State& s) SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_FUNC(js_gfx_BindingLayout_destroy) +SE_BIND_FUNC(js_gfx_PipelineState_destroy) + +static bool js_gfx_PipelineState_getRenderPass(se::State& s) +{ + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getRenderPass : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const cc::gfx::RenderPass* result = cobj->getRenderPass(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getRenderPass : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_PipelineState_getRenderPass) -static bool js_gfx_BindingLayout_getDevice(se::State& s) +static bool js_gfx_PipelineState_getDevice(se::State& s) { - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingLayout_getDevice : Invalid Native Object"); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getDevice : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { cc::gfx::Device* result = cobj->getDevice(); ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_BindingLayout_getDevice : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getDevice : Error processing arguments"); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_PROP_GET(js_gfx_PipelineState_getDevice) + +static bool js_gfx_PipelineState_getDynamicStates(se::State& s) +{ + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getDynamicStates : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + int result = (int)cobj->getDynamicStates(); + ok &= int32_to_seval((int)result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getDynamicStates : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_BindingLayout_getDevice) +SE_BIND_FUNC(js_gfx_PipelineState_getDynamicStates) -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_BindingLayout_finalize) +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_PipelineState_finalize) -static bool js_gfx_BindingLayout_constructor(se::State& s) +static bool js_gfx_PipelineState_constructor(se::State& s) { - //#3 cc::gfx::BindingLayout: is_skip_construtor True - se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::BindingLayout constructor is skipped\")"); + //#3 cc::gfx::PipelineState: is_skip_construtor True + se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::PipelineState constructor is skipped\")"); return false; } -SE_BIND_CTOR(js_gfx_BindingLayout_constructor, __jsb_cc_gfx_BindingLayout_class, js_cc_gfx_BindingLayout_finalize) +SE_BIND_CTOR(js_gfx_PipelineState_constructor, __jsb_cc_gfx_PipelineState_class, js_cc_gfx_PipelineState_finalize) extern se::Object* __jsb_cc_gfx_GFXObject_proto; -static bool js_cc_gfx_BindingLayout_finalize(se::State& s) +static bool js_cc_gfx_PipelineState_finalize(se::State& s) { auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::BindingLayout* cobj = (cc::gfx::BindingLayout*)s.nativeThisObject(); + cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); JSB_FREE(cobj); } return true; } -SE_BIND_FINALIZE_FUNC(js_cc_gfx_BindingLayout_finalize) +SE_BIND_FINALIZE_FUNC(js_cc_gfx_PipelineState_finalize) -bool js_register_gfx_BindingLayout(se::Object* obj) +bool js_register_gfx_PipelineState(se::Object* obj) { - auto cls = se::Class::create("BindingLayout", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_BindingLayout_constructor)); + auto cls = se::Class::create("PipelineState", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_PipelineState_constructor)); - cls->defineProperty("device", _SE(js_gfx_BindingLayout_getDevice), nullptr); - cls->defineProperty("bindingUnits", _SE(js_gfx_BindingLayout_getBindingUnits), nullptr); - cls->defineFunction("bindBuffer", _SE(js_gfx_BindingLayout_bindBuffer)); - cls->defineFunction("bindSampler", _SE(js_gfx_BindingLayout_bindSampler)); - cls->defineFunction("update", _SE(js_gfx_BindingLayout_update)); - cls->defineFunction("bindTexture", _SE(js_gfx_BindingLayout_bindTexture)); - cls->defineFunction("initialize", _SE(js_gfx_BindingLayout_initialize)); - cls->defineFunction("destroy", _SE(js_gfx_BindingLayout_destroy)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_BindingLayout_finalize)); + cls->defineProperty("primitive", _SE(js_gfx_PipelineState_getPrimitive), nullptr); + cls->defineProperty("rasterizerState", _SE(js_gfx_PipelineState_getRasterizerState), nullptr); + cls->defineProperty("shader", _SE(js_gfx_PipelineState_getShader), nullptr); + cls->defineProperty("blendState", _SE(js_gfx_PipelineState_getBlendState), nullptr); + cls->defineProperty("renderPass", _SE(js_gfx_PipelineState_getRenderPass), nullptr); + cls->defineProperty("device", _SE(js_gfx_PipelineState_getDevice), nullptr); + cls->defineProperty("inputState", _SE(js_gfx_PipelineState_getInputState), nullptr); + cls->defineProperty("depthStencilState", _SE(js_gfx_PipelineState_getDepthStencilState), nullptr); + cls->defineFunction("getPipelineLayout", _SE(js_gfx_PipelineState_getPipelineLayout)); + cls->defineFunction("initialize", _SE(js_gfx_PipelineState_initialize)); + cls->defineFunction("destroy", _SE(js_gfx_PipelineState_destroy)); + cls->defineFunction("getDynamicStates", _SE(js_gfx_PipelineState_getDynamicStates)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_PipelineState_finalize)); cls->install(); - JSBClassType::registerClass(cls); + JSBClassType::registerClass(cls); - __jsb_cc_gfx_BindingLayout_proto = cls->getProto(); - __jsb_cc_gfx_BindingLayout_class = cls; + __jsb_cc_gfx_PipelineState_proto = cls->getProto(); + __jsb_cc_gfx_PipelineState_class = cls; se::ScriptEngine::getInstance()->clearException(); return true; } -se::Object* __jsb_cc_gfx_PipelineState_proto = nullptr; -se::Class* __jsb_cc_gfx_PipelineState_class = nullptr; +se::Object* __jsb_cc_gfx_DescriptorSet_proto = nullptr; +se::Class* __jsb_cc_gfx_DescriptorSet_class = nullptr; -static bool js_gfx_PipelineState_getRasterizerState(se::State& s) +static bool js_gfx_DescriptorSet_getBuffer(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getRasterizerState : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_getBuffer : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 0) { - const cc::gfx::RasterizerState& result = cobj->getRasterizerState(); + if (argc == 1) { + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_getBuffer : Error processing arguments"); + const cc::gfx::Buffer* result = cobj->getBuffer(arg0); ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getRasterizerState : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_getBuffer : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_PROP_GET(js_gfx_PipelineState_getRasterizerState) +SE_BIND_FUNC(js_gfx_DescriptorSet_getBuffer) -static bool js_gfx_PipelineState_getShader(se::State& s) +static bool js_gfx_DescriptorSet_bindBuffer(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getShader : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_bindBuffer : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 0) { - cc::gfx::Shader* result = cobj->getShader(); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getShader : Error processing arguments"); + if (argc == 2) { + unsigned int arg0 = 0; + cc::gfx::Buffer* arg1 = nullptr; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + ok &= seval_to_native_ptr(args[1], &arg1); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_bindBuffer : Error processing arguments"); + cobj->bindBuffer(arg0, arg1); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); return false; } -SE_BIND_PROP_GET(js_gfx_PipelineState_getShader) +SE_BIND_FUNC(js_gfx_DescriptorSet_bindBuffer) -static bool js_gfx_PipelineState_getInputState(se::State& s) +static bool js_gfx_DescriptorSet_getTexture(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getInputState : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_getTexture : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 0) { - const cc::gfx::InputState& result = cobj->getInputState(); + if (argc == 1) { + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_getTexture : Error processing arguments"); + const cc::gfx::Texture* result = cobj->getTexture(arg0); ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getInputState : Error processing arguments"); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_PROP_GET(js_gfx_PipelineState_getInputState) - -static bool js_gfx_PipelineState_getPrimitive(se::State& s) -{ - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getPrimitive : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - int result = (int)cobj->getPrimitive(); - ok &= int32_to_seval((int)result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getPrimitive : Error processing arguments"); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_getTexture : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_PROP_GET(js_gfx_PipelineState_getPrimitive) +SE_BIND_FUNC(js_gfx_DescriptorSet_getTexture) -static bool js_gfx_PipelineState_getDepthStencilState(se::State& s) +static bool js_gfx_DescriptorSet_bindSampler(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getDepthStencilState : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_bindSampler : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 0) { - const cc::gfx::DepthStencilState& result = cobj->getDepthStencilState(); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getDepthStencilState : Error processing arguments"); + if (argc == 2) { + unsigned int arg0 = 0; + cc::gfx::Sampler* arg1 = nullptr; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + ok &= seval_to_native_ptr(args[1], &arg1); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_bindSampler : Error processing arguments"); + cobj->bindSampler(arg0, arg1); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); return false; } -SE_BIND_PROP_GET(js_gfx_PipelineState_getDepthStencilState) +SE_BIND_FUNC(js_gfx_DescriptorSet_bindSampler) -static bool js_gfx_PipelineState_getBlendState(se::State& s) +static bool js_gfx_DescriptorSet_update(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getBlendState : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_update : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); - CC_UNUSED bool ok = true; if (argc == 0) { - const cc::gfx::BlendState& result = cobj->getBlendState(); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getBlendState : Error processing arguments"); + cobj->update(); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_PipelineState_getBlendState) +SE_BIND_FUNC(js_gfx_DescriptorSet_update) -static bool js_gfx_PipelineState_initialize(se::State& s) +static bool js_gfx_DescriptorSet_getSampler(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_initialize : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_getSampler : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - cc::gfx::PipelineStateInfo* arg0 = nullptr; - ok &= seval_to_reference(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_initialize : Error processing arguments"); - bool result = cobj->initialize(*arg0); - ok &= boolean_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_initialize : Error processing arguments"); + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_getSampler : Error processing arguments"); + const cc::gfx::Sampler* result = cobj->getSampler(arg0); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_getSampler : Error processing arguments"); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_FUNC(js_gfx_PipelineState_initialize) +SE_BIND_FUNC(js_gfx_DescriptorSet_getSampler) -static bool js_gfx_PipelineState_destroy(se::State& s) +static bool js_gfx_DescriptorSet_bindTexture(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_destroy : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_bindTexture : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); - if (argc == 0) { - cobj->destroy(); + CC_UNUSED bool ok = true; + if (argc == 2) { + unsigned int arg0 = 0; + cc::gfx::Texture* arg1 = nullptr; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + ok &= seval_to_native_ptr(args[1], &arg1); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_bindTexture : Error processing arguments"); + cobj->bindTexture(arg0, arg1); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); return false; } -SE_BIND_FUNC(js_gfx_PipelineState_destroy) +SE_BIND_FUNC(js_gfx_DescriptorSet_bindTexture) -static bool js_gfx_PipelineState_getRenderPass(se::State& s) +static bool js_gfx_DescriptorSet_initialize(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getRenderPass : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_initialize : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc == 0) { - const cc::gfx::RenderPass* result = cobj->getRenderPass(); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getRenderPass : Error processing arguments"); + if (argc == 1) { + cc::gfx::DescriptorSetInfo* arg0 = nullptr; + ok &= seval_to_reference(args[0], &arg0); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_initialize : Error processing arguments"); + bool result = cobj->initialize(*arg0); + ok &= boolean_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_initialize : Error processing arguments"); return true; } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); return false; } -SE_BIND_PROP_GET(js_gfx_PipelineState_getRenderPass) +SE_BIND_FUNC(js_gfx_DescriptorSet_initialize) -static bool js_gfx_PipelineState_getDevice(se::State& s) +static bool js_gfx_DescriptorSet_destroy(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getDevice : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_destroy : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); - CC_UNUSED bool ok = true; if (argc == 0) { - cc::gfx::Device* result = cobj->getDevice(); - ok &= native_ptr_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getDevice : Error processing arguments"); + cobj->destroy(); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); return false; } -SE_BIND_PROP_GET(js_gfx_PipelineState_getDevice) +SE_BIND_FUNC(js_gfx_DescriptorSet_destroy) -static bool js_gfx_PipelineState_getDynamicStates(se::State& s) +static bool js_gfx_DescriptorSet_getDevice(se::State& s) { - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_PipelineState_getDynamicStates : Invalid Native Object"); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_DescriptorSet_getDevice : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - int result = (int)cobj->getDynamicStates(); - ok &= int32_to_seval((int)result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_getDynamicStates : Error processing arguments"); + cc::gfx::Device* result = cobj->getDevice(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_getDevice : 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_gfx_PipelineState_getDynamicStates) +SE_BIND_FUNC(js_gfx_DescriptorSet_getDevice) -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_PipelineState_finalize) +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_DescriptorSet_finalize) -static bool js_gfx_PipelineState_constructor(se::State& s) +static bool js_gfx_DescriptorSet_constructor(se::State& s) { - //#3 cc::gfx::PipelineState: is_skip_construtor True - se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::PipelineState constructor is skipped\")"); + //#3 cc::gfx::DescriptorSet: is_skip_construtor True + se::ScriptEngine::getInstance()->evalString("throw new Error(\"cc::gfx::DescriptorSet constructor is skipped\")"); return false; } -SE_BIND_CTOR(js_gfx_PipelineState_constructor, __jsb_cc_gfx_PipelineState_class, js_cc_gfx_PipelineState_finalize) +SE_BIND_CTOR(js_gfx_DescriptorSet_constructor, __jsb_cc_gfx_DescriptorSet_class, js_cc_gfx_DescriptorSet_finalize) extern se::Object* __jsb_cc_gfx_GFXObject_proto; -static bool js_cc_gfx_PipelineState_finalize(se::State& s) +static bool js_cc_gfx_DescriptorSet_finalize(se::State& s) { auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::PipelineState* cobj = (cc::gfx::PipelineState*)s.nativeThisObject(); + cc::gfx::DescriptorSet* cobj = (cc::gfx::DescriptorSet*)s.nativeThisObject(); JSB_FREE(cobj); } return true; } -SE_BIND_FINALIZE_FUNC(js_cc_gfx_PipelineState_finalize) +SE_BIND_FINALIZE_FUNC(js_cc_gfx_DescriptorSet_finalize) -bool js_register_gfx_PipelineState(se::Object* obj) +bool js_register_gfx_DescriptorSet(se::Object* obj) { - auto cls = se::Class::create("PipelineState", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_PipelineState_constructor)); + auto cls = se::Class::create("DescriptorSet", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_DescriptorSet_constructor)); - cls->defineProperty("primitive", _SE(js_gfx_PipelineState_getPrimitive), nullptr); - cls->defineProperty("rasterizerState", _SE(js_gfx_PipelineState_getRasterizerState), nullptr); - cls->defineProperty("shader", _SE(js_gfx_PipelineState_getShader), nullptr); - cls->defineProperty("blendState", _SE(js_gfx_PipelineState_getBlendState), nullptr); - cls->defineProperty("renderPass", _SE(js_gfx_PipelineState_getRenderPass), nullptr); - cls->defineProperty("device", _SE(js_gfx_PipelineState_getDevice), nullptr); - cls->defineProperty("inputState", _SE(js_gfx_PipelineState_getInputState), nullptr); - cls->defineProperty("depthStencilState", _SE(js_gfx_PipelineState_getDepthStencilState), nullptr); - cls->defineFunction("initialize", _SE(js_gfx_PipelineState_initialize)); - cls->defineFunction("destroy", _SE(js_gfx_PipelineState_destroy)); - cls->defineFunction("getDynamicStates", _SE(js_gfx_PipelineState_getDynamicStates)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_PipelineState_finalize)); + cls->defineFunction("getBuffer", _SE(js_gfx_DescriptorSet_getBuffer)); + cls->defineFunction("bindBuffer", _SE(js_gfx_DescriptorSet_bindBuffer)); + cls->defineFunction("getTexture", _SE(js_gfx_DescriptorSet_getTexture)); + cls->defineFunction("bindSampler", _SE(js_gfx_DescriptorSet_bindSampler)); + cls->defineFunction("update", _SE(js_gfx_DescriptorSet_update)); + cls->defineFunction("getSampler", _SE(js_gfx_DescriptorSet_getSampler)); + cls->defineFunction("bindTexture", _SE(js_gfx_DescriptorSet_bindTexture)); + cls->defineFunction("initialize", _SE(js_gfx_DescriptorSet_initialize)); + cls->defineFunction("destroy", _SE(js_gfx_DescriptorSet_destroy)); + cls->defineFunction("getDevice", _SE(js_gfx_DescriptorSet_getDevice)); + cls->defineFinalizeFunction(_SE(js_cc_gfx_DescriptorSet_finalize)); cls->install(); - JSBClassType::registerClass(cls); + JSBClassType::registerClass(cls); - __jsb_cc_gfx_PipelineState_proto = cls->getProto(); - __jsb_cc_gfx_PipelineState_class = cls; + __jsb_cc_gfx_DescriptorSet_proto = cls->getProto(); + __jsb_cc_gfx_DescriptorSet_class = cls; se::ScriptEngine::getInstance()->clearException(); return true; @@ -15617,43 +16314,58 @@ SE_BIND_FUNC(js_gfx_CommandBuffer_setDepthBias) static bool js_gfx_CommandBuffer_begin(se::State& s) { + CC_UNUSED bool ok = true; cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_begin : Invalid Native Object"); + SE_PRECONDITION2( cobj, false, "js_gfx_CommandBuffer_begin : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - cobj->begin(); - return true; - } - if (argc == 1) { - cc::gfx::RenderPass* arg0 = nullptr; - ok &= seval_to_native_ptr(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_begin : Error processing arguments"); - cobj->begin(arg0); - return true; - } - if (argc == 2) { - cc::gfx::RenderPass* arg0 = nullptr; - unsigned int arg1 = 0; - ok &= seval_to_native_ptr(args[0], &arg0); - ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); - SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_begin : Error processing arguments"); - cobj->begin(arg0, arg1); - return true; - } - if (argc == 3) { - cc::gfx::RenderPass* arg0 = nullptr; - unsigned int arg1 = 0; - cc::gfx::Framebuffer* arg2 = nullptr; - ok &= seval_to_native_ptr(args[0], &arg0); - ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); - ok &= seval_to_native_ptr(args[2], &arg2); - SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_begin : Error processing arguments"); - cobj->begin(arg0, arg1, arg2); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3); + do { + if (argc == 0) { + cobj->begin(); + return true; + } + } while(false); + + do { + if (argc == 3) { + cc::gfx::RenderPass* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + if (!ok) { ok = true; break; } + unsigned int arg1 = 0; + ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); + if (!ok) { ok = true; break; } + cc::gfx::Framebuffer* arg2 = nullptr; + ok &= seval_to_native_ptr(args[2], &arg2); + if (!ok) { ok = true; break; } + cobj->begin(arg0, arg1, arg2); + return true; + } + } while(false); + + do { + if (argc == 1) { + cc::gfx::RenderPass* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + if (!ok) { ok = true; break; } + cobj->begin(arg0); + return true; + } + } while(false); + + do { + if (argc == 2) { + cc::gfx::RenderPass* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + if (!ok) { ok = true; break; } + unsigned int arg1 = 0; + ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); + if (!ok) { ok = true; break; } + cobj->begin(arg0, arg1); + return true; + } + } while(false); + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; } SE_BIND_FUNC(js_gfx_CommandBuffer_begin) @@ -15676,24 +16388,66 @@ static bool js_gfx_CommandBuffer_getType(se::State& s) } SE_BIND_FUNC(js_gfx_CommandBuffer_getType) -static bool js_gfx_CommandBuffer_bindBindingLayout(se::State& s) +static bool js_gfx_CommandBuffer_bindDescriptorSet(se::State& s) { + CC_UNUSED bool ok = true; cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_bindBindingLayout : Invalid Native Object"); + SE_PRECONDITION2( cobj, false, "js_gfx_CommandBuffer_bindDescriptorSet : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 1) { - cc::gfx::BindingLayout* arg0 = nullptr; - ok &= seval_to_native_ptr(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_bindBindingLayout : Error processing arguments"); - cobj->bindBindingLayout(arg0); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + do { + if (argc == 2) { + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + if (!ok) { ok = true; break; } + cc::gfx::DescriptorSet* arg1 = nullptr; + ok &= seval_to_native_ptr(args[1], &arg1); + if (!ok) { ok = true; break; } + cobj->bindDescriptorSet(arg0, arg1); + return true; + } + } while(false); + + do { + if (argc == 4) { + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + if (!ok) { ok = true; break; } + cc::gfx::DescriptorSet* arg1 = nullptr; + ok &= seval_to_native_ptr(args[1], &arg1); + if (!ok) { ok = true; break; } + unsigned int arg2 = 0; + ok &= seval_to_uint32(args[2], (uint32_t*)&arg2); + if (!ok) { ok = true; break; } + const unsigned int* arg3 = 0; + #pragma warning NO CONVERSION TO NATIVE FOR unsigned int* + ok = false; + if (!ok) { ok = true; break; } + cobj->bindDescriptorSet(arg0, arg1, arg2, arg3); + return true; + } + } while(false); + + do { + if (argc == 3) { + unsigned int arg0 = 0; + ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); + if (!ok) { ok = true; break; } + cc::gfx::DescriptorSet* arg1 = nullptr; + ok &= seval_to_native_ptr(args[1], &arg1); + if (!ok) { ok = true; break; } + std::vector arg2; + ok &= seval_to_std_vector(args[2], &arg2); + if (!ok) { ok = true; break; } + cobj->bindDescriptorSet(arg0, arg1, arg2); + return true; + } + } while(false); + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; } -SE_BIND_FUNC(js_gfx_CommandBuffer_bindBindingLayout) +SE_BIND_FUNC(js_gfx_CommandBuffer_bindDescriptorSet) static bool js_gfx_CommandBuffer_endRenderPass(se::State& s) { @@ -15752,29 +16506,62 @@ SE_BIND_FUNC(js_gfx_CommandBuffer_setScissor) static bool js_gfx_CommandBuffer_beginRenderPass(se::State& s) { + CC_UNUSED bool ok = true; cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_beginRenderPass : Invalid Native Object"); + SE_PRECONDITION2( cobj, false, "js_gfx_CommandBuffer_beginRenderPass : Invalid Native Object"); const auto& args = s.args(); size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 6) { - cc::gfx::RenderPass* arg0 = nullptr; - cc::gfx::Framebuffer* arg1 = nullptr; - cc::gfx::Rect* arg2 = nullptr; - std::vector arg3; - float arg4 = 0; - int arg5 = 0; - ok &= seval_to_native_ptr(args[0], &arg0); - ok &= seval_to_native_ptr(args[1], &arg1); - ok &= seval_to_reference(args[2], &arg2); - ok &= seval_to_std_vector(args[3], &arg3); - ok &= seval_to_float(args[4], &arg4); - do { int32_t tmp = 0; ok &= seval_to_int32(args[5], &tmp); arg5 = (int)tmp; } while(false); - SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_beginRenderPass : Error processing arguments"); - cobj->beginRenderPass(arg0, arg1, *arg2, arg3, arg4, arg5); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 6); + do { + if (argc == 6) { + cc::gfx::RenderPass* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + if (!ok) { ok = true; break; } + cc::gfx::Framebuffer* arg1 = nullptr; + ok &= seval_to_native_ptr(args[1], &arg1); + if (!ok) { ok = true; break; } + cc::gfx::Rect arg2; + ok &= seval_to_reference(args[2], &arg2); + if (!ok) { ok = true; break; } + std::vector arg3; + ok &= seval_to_std_vector(args[3], &arg3); + if (!ok) { ok = true; break; } + float arg4 = 0; + ok &= seval_to_float(args[4], &arg4); + if (!ok) { ok = true; break; } + int arg5 = 0; + do { int32_t tmp = 0; ok &= seval_to_int32(args[5], &tmp); arg5 = (int)tmp; } while(false); + if (!ok) { ok = true; break; } + cobj->beginRenderPass(arg0, arg1, arg2, arg3, arg4, arg5); + return true; + } + } while(false); + + do { + if (argc == 6) { + cc::gfx::RenderPass* arg0 = nullptr; + ok &= seval_to_native_ptr(args[0], &arg0); + if (!ok) { ok = true; break; } + cc::gfx::Framebuffer* arg1 = nullptr; + ok &= seval_to_native_ptr(args[1], &arg1); + if (!ok) { ok = true; break; } + cc::gfx::Rect arg2; + ok &= seval_to_reference(args[2], &arg2); + if (!ok) { ok = true; break; } + const cc::gfx::Color* arg3 = nullptr; + ok &= seval_to_native_ptr(args[3], &arg3); + if (!ok) { ok = true; break; } + float arg4 = 0; + ok &= seval_to_float(args[4], &arg4); + if (!ok) { ok = true; break; } + int arg5 = 0; + do { int32_t tmp = 0; ok &= seval_to_int32(args[5], &tmp); arg5 = (int)tmp; } while(false); + if (!ok) { ok = true; break; } + cobj->beginRenderPass(arg0, arg1, arg2, arg3, arg4, arg5); + return true; + } + } while(false); + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; } SE_BIND_FUNC(js_gfx_CommandBuffer_beginRenderPass) @@ -15847,7 +16634,7 @@ bool js_register_gfx_CommandBuffer(se::Object* obj) cls->defineFunction("setDepthBias", _SE(js_gfx_CommandBuffer_setDepthBias)); cls->defineFunction("begin", _SE(js_gfx_CommandBuffer_begin)); cls->defineFunction("getType", _SE(js_gfx_CommandBuffer_getType)); - cls->defineFunction("bindBindingLayout", _SE(js_gfx_CommandBuffer_bindBindingLayout)); + cls->defineFunction("bindDescriptorSet", _SE(js_gfx_CommandBuffer_bindDescriptorSet)); cls->defineFunction("endRenderPass", _SE(js_gfx_CommandBuffer_endRenderPass)); cls->defineFunction("initialize", _SE(js_gfx_CommandBuffer_initialize)); cls->defineFunction("setScissor", _SE(js_gfx_CommandBuffer_setScissor)); @@ -16172,14 +16959,16 @@ bool register_all_gfx(se::Object* obj) js_register_gfx_ContextInfo(ns); js_register_gfx_Texture(ns); js_register_gfx_Uniform(ns); + js_register_gfx_DescriptorSet(ns); js_register_gfx_BlendTarget(ns); + js_register_gfx_DescriptorSetLayoutBinding(ns); + js_register_gfx_PipelineLayout(ns); js_register_gfx_Sampler(ns); js_register_gfx_InputAssembler(ns); js_register_gfx_RenderPass(ns); js_register_gfx_BufferInfo(ns); js_register_gfx_SamplerInfo(ns); js_register_gfx_QueueInfo(ns); - js_register_gfx_BindingUnit(ns); js_register_gfx_BufferTextureCopy(ns); js_register_gfx_ShaderMacro(ns); js_register_gfx_FormatInfo(ns); @@ -16193,18 +16982,21 @@ bool register_all_gfx(se::Object* obj) js_register_gfx_Device(ns); js_register_gfx_Framebuffer(ns); js_register_gfx_Viewport(ns); - js_register_gfx_BindingLayout(ns); + js_register_gfx_BufferViewInfo(ns); js_register_gfx_UniformSampler(ns); js_register_gfx_ShaderInfo(ns); js_register_gfx_PipelineStateInfo(ns); js_register_gfx_Shader(ns); js_register_gfx_BlendState(ns); - js_register_gfx_Queue(ns); + js_register_gfx_DescriptorSetInfo(ns); + js_register_gfx_DescriptorSetLayoutInfo(ns); js_register_gfx_DrawInfo(ns); js_register_gfx_CommandBufferInfo(ns); js_register_gfx_UniformBlock(ns); js_register_gfx_DepthStencilAttachment(ns); + js_register_gfx_PipelineLayoutInfo(ns); js_register_gfx_TextureViewInfo(ns); + js_register_gfx_Queue(ns); js_register_gfx_ColorAttachment(ns); js_register_gfx_RasterizerState(ns); js_register_gfx_Fence(ns); @@ -16215,10 +17007,10 @@ bool register_all_gfx(se::Object* obj) js_register_gfx_DepthStencilState(ns); js_register_gfx_Buffer(ns); js_register_gfx_FramebufferInfo(ns); - js_register_gfx_BindingLayoutInfo(ns); js_register_gfx_Rect(ns); js_register_gfx_ShaderStage(ns); js_register_gfx_InputState(ns); + js_register_gfx_DescriptorSetLayout(ns); js_register_gfx_TextureCopy(ns); js_register_gfx_IndirectBuffer(ns); return true; diff --git a/cocos/scripting/js-bindings/auto/jsb_gfx_auto.h b/cocos/scripting/js-bindings/auto/jsb_gfx_auto.h index c56cfd86574..9b95a3cf9c9 100644 --- a/cocos/scripting/js-bindings/auto/jsb_gfx_auto.h +++ b/cocos/scripting/js-bindings/auto/jsb_gfx_auto.h @@ -69,6 +69,12 @@ extern se::Class* __jsb_cc_gfx_BufferInfo_class; bool js_register_cc_gfx_BufferInfo(se::Object* obj); bool register_all_gfx(se::Object* obj); +extern se::Object* __jsb_cc_gfx_BufferViewInfo_proto; +extern se::Class* __jsb_cc_gfx_BufferViewInfo_class; + +bool js_register_cc_gfx_BufferViewInfo(se::Object* obj); +bool register_all_gfx(se::Object* obj); + extern se::Object* __jsb_cc_gfx_DrawInfo_proto; extern se::Class* __jsb_cc_gfx_DrawInfo_class; @@ -171,16 +177,28 @@ extern se::Class* __jsb_cc_gfx_FramebufferInfo_class; bool js_register_cc_gfx_FramebufferInfo(se::Object* obj); bool register_all_gfx(se::Object* obj); -extern se::Object* __jsb_cc_gfx_BindingLayoutInfo_proto; -extern se::Class* __jsb_cc_gfx_BindingLayoutInfo_class; +extern se::Object* __jsb_cc_gfx_DescriptorSetLayoutBinding_proto; +extern se::Class* __jsb_cc_gfx_DescriptorSetLayoutBinding_class; + +bool js_register_cc_gfx_DescriptorSetLayoutBinding(se::Object* obj); +bool register_all_gfx(se::Object* obj); + +extern se::Object* __jsb_cc_gfx_DescriptorSetLayoutInfo_proto; +extern se::Class* __jsb_cc_gfx_DescriptorSetLayoutInfo_class; + +bool js_register_cc_gfx_DescriptorSetLayoutInfo(se::Object* obj); +bool register_all_gfx(se::Object* obj); + +extern se::Object* __jsb_cc_gfx_DescriptorSetInfo_proto; +extern se::Class* __jsb_cc_gfx_DescriptorSetInfo_class; -bool js_register_cc_gfx_BindingLayoutInfo(se::Object* obj); +bool js_register_cc_gfx_DescriptorSetInfo(se::Object* obj); bool register_all_gfx(se::Object* obj); -extern se::Object* __jsb_cc_gfx_BindingUnit_proto; -extern se::Class* __jsb_cc_gfx_BindingUnit_class; +extern se::Object* __jsb_cc_gfx_PipelineLayoutInfo_proto; +extern se::Class* __jsb_cc_gfx_PipelineLayoutInfo_class; -bool js_register_cc_gfx_BindingUnit(se::Object* obj); +bool js_register_cc_gfx_PipelineLayoutInfo(se::Object* obj); bool register_all_gfx(se::Object* obj); extern se::Object* __jsb_cc_gfx_InputState_proto; @@ -257,29 +275,30 @@ bool js_register_cc_gfx_Device(se::Object* obj); bool register_all_gfx(se::Object* obj); SE_DECLARE_FUNC(js_gfx_Device_hasFeature); SE_DECLARE_FUNC(js_gfx_Device_createFence); -SE_DECLARE_FUNC(js_gfx_Device_createPipelineState); +SE_DECLARE_FUNC(js_gfx_Device_createDescriptorSetLayout); SE_DECLARE_FUNC(js_gfx_Device_createCommandBuffer); +SE_DECLARE_FUNC(js_gfx_Device_createPipelineState); +SE_DECLARE_FUNC(js_gfx_Device_createDescriptorSet); SE_DECLARE_FUNC(js_gfx_Device_present); SE_DECLARE_FUNC(js_gfx_Device_destroy); SE_DECLARE_FUNC(js_gfx_Device_createFramebuffer); SE_DECLARE_FUNC(js_gfx_Device_createRenderPass); +SE_DECLARE_FUNC(js_gfx_Device_createPipelineLayout); SE_DECLARE_FUNC(js_gfx_Device_acquire); SE_DECLARE_FUNC(js_gfx_Device_createShader); SE_DECLARE_FUNC(js_gfx_Device_createInputAssembler); SE_DECLARE_FUNC(js_gfx_Device_defineMacro); SE_DECLARE_FUNC(js_gfx_Device_createSampler); -SE_DECLARE_FUNC(js_gfx_Device_createBuffer); SE_DECLARE_FUNC(js_gfx_Device_initialize); SE_DECLARE_FUNC(js_gfx_Device_resize); SE_DECLARE_FUNC(js_gfx_Device_createQueue); -SE_DECLARE_FUNC(js_gfx_Device_createBindingLayout); extern se::Object* __jsb_cc_gfx_Buffer_proto; extern se::Class* __jsb_cc_gfx_Buffer_class; bool js_register_cc_gfx_Buffer(se::Object* obj); bool register_all_gfx(se::Object* obj); -SE_DECLARE_FUNC(js_gfx_Buffer_initialize); +SE_DECLARE_FUNC(js_gfx_Buffer_isBufferView); SE_DECLARE_FUNC(js_gfx_Buffer_destroy); SE_DECLARE_FUNC(js_gfx_Buffer_resize); SE_DECLARE_FUNC(js_gfx_Buffer_Buffer); @@ -291,6 +310,7 @@ bool js_register_cc_gfx_Texture(se::Object* obj); bool register_all_gfx(se::Object* obj); SE_DECLARE_FUNC(js_gfx_Texture_destroy); SE_DECLARE_FUNC(js_gfx_Texture_resize); +SE_DECLARE_FUNC(js_gfx_Texture_isTextureView); SE_DECLARE_FUNC(js_gfx_Texture_Texture); extern se::Object* __jsb_cc_gfx_Sampler_proto; @@ -338,29 +358,54 @@ SE_DECLARE_FUNC(js_gfx_Framebuffer_initialize); SE_DECLARE_FUNC(js_gfx_Framebuffer_destroy); SE_DECLARE_FUNC(js_gfx_Framebuffer_Framebuffer); -extern se::Object* __jsb_cc_gfx_BindingLayout_proto; -extern se::Class* __jsb_cc_gfx_BindingLayout_class; +extern se::Object* __jsb_cc_gfx_DescriptorSetLayout_proto; +extern se::Class* __jsb_cc_gfx_DescriptorSetLayout_class; + +bool js_register_cc_gfx_DescriptorSetLayout(se::Object* obj); +bool register_all_gfx(se::Object* obj); +SE_DECLARE_FUNC(js_gfx_DescriptorSetLayout_initialize); +SE_DECLARE_FUNC(js_gfx_DescriptorSetLayout_destroy); +SE_DECLARE_FUNC(js_gfx_DescriptorSetLayout_getDevice); +SE_DECLARE_FUNC(js_gfx_DescriptorSetLayout_DescriptorSetLayout); + +extern se::Object* __jsb_cc_gfx_PipelineLayout_proto; +extern se::Class* __jsb_cc_gfx_PipelineLayout_class; -bool js_register_cc_gfx_BindingLayout(se::Object* obj); +bool js_register_cc_gfx_PipelineLayout(se::Object* obj); bool register_all_gfx(se::Object* obj); -SE_DECLARE_FUNC(js_gfx_BindingLayout_bindBuffer); -SE_DECLARE_FUNC(js_gfx_BindingLayout_bindSampler); -SE_DECLARE_FUNC(js_gfx_BindingLayout_update); -SE_DECLARE_FUNC(js_gfx_BindingLayout_bindTexture); -SE_DECLARE_FUNC(js_gfx_BindingLayout_initialize); -SE_DECLARE_FUNC(js_gfx_BindingLayout_destroy); -SE_DECLARE_FUNC(js_gfx_BindingLayout_BindingLayout); +SE_DECLARE_FUNC(js_gfx_PipelineLayout_initialize); +SE_DECLARE_FUNC(js_gfx_PipelineLayout_destroy); +SE_DECLARE_FUNC(js_gfx_PipelineLayout_getDevice); +SE_DECLARE_FUNC(js_gfx_PipelineLayout_PipelineLayout); extern se::Object* __jsb_cc_gfx_PipelineState_proto; extern se::Class* __jsb_cc_gfx_PipelineState_class; bool js_register_cc_gfx_PipelineState(se::Object* obj); bool register_all_gfx(se::Object* obj); +SE_DECLARE_FUNC(js_gfx_PipelineState_getPipelineLayout); SE_DECLARE_FUNC(js_gfx_PipelineState_initialize); SE_DECLARE_FUNC(js_gfx_PipelineState_destroy); SE_DECLARE_FUNC(js_gfx_PipelineState_getDynamicStates); SE_DECLARE_FUNC(js_gfx_PipelineState_PipelineState); +extern se::Object* __jsb_cc_gfx_DescriptorSet_proto; +extern se::Class* __jsb_cc_gfx_DescriptorSet_class; + +bool js_register_cc_gfx_DescriptorSet(se::Object* obj); +bool register_all_gfx(se::Object* obj); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_getBuffer); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_bindBuffer); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_getTexture); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_bindSampler); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_update); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_getSampler); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_bindTexture); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_initialize); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_destroy); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_getDevice); +SE_DECLARE_FUNC(js_gfx_DescriptorSet_DescriptorSet); + extern se::Object* __jsb_cc_gfx_CommandBuffer_proto; extern se::Class* __jsb_cc_gfx_CommandBuffer_class; @@ -385,7 +430,7 @@ SE_DECLARE_FUNC(js_gfx_CommandBuffer_setViewport); SE_DECLARE_FUNC(js_gfx_CommandBuffer_setDepthBias); SE_DECLARE_FUNC(js_gfx_CommandBuffer_begin); SE_DECLARE_FUNC(js_gfx_CommandBuffer_getType); -SE_DECLARE_FUNC(js_gfx_CommandBuffer_bindBindingLayout); +SE_DECLARE_FUNC(js_gfx_CommandBuffer_bindDescriptorSet); SE_DECLARE_FUNC(js_gfx_CommandBuffer_endRenderPass); SE_DECLARE_FUNC(js_gfx_CommandBuffer_initialize); SE_DECLARE_FUNC(js_gfx_CommandBuffer_setScissor); diff --git a/cocos/scripting/js-bindings/auto/jsb_gles2_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_gles2_auto.cpp index feff5d89390..c291c6740ea 100644 --- a/cocos/scripting/js-bindings/auto/jsb_gles2_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_gles2_auto.cpp @@ -34,6 +34,24 @@ static bool js_gles2_GLES2Device_checkExtension(se::State& s) } SE_BIND_FUNC(js_gles2_GLES2Device_checkExtension) +static bool js_gles2_GLES2Device_bindingMappingInfo(se::State& s) +{ + cc::gfx::GLES2Device* cobj = (cc::gfx::GLES2Device*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gles2_GLES2Device_bindingMappingInfo : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const cc::gfx::BindingMappingInfo& result = cobj->bindingMappingInfo(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gles2_GLES2Device_bindingMappingInfo : 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_gles2_GLES2Device_bindingMappingInfo) + SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_GLES2Device_finalize) static bool js_gles2_GLES2Device_constructor(se::State& s) @@ -67,6 +85,7 @@ bool js_register_gles2_GLES2Device(se::Object* obj) auto cls = se::Class::create("GLES2Device", obj, __jsb_cc_gfx_Device_proto, _SE(js_gles2_GLES2Device_constructor)); cls->defineFunction("checkExtension", _SE(js_gles2_GLES2Device_checkExtension)); + cls->defineFunction("bindingMappingInfo", _SE(js_gles2_GLES2Device_bindingMappingInfo)); cls->defineFinalizeFunction(_SE(js_cc_gfx_GLES2Device_finalize)); cls->install(); JSBClassType::registerClass(cls); diff --git a/cocos/scripting/js-bindings/auto/jsb_gles2_auto.h b/cocos/scripting/js-bindings/auto/jsb_gles2_auto.h index 62eb16f7f48..e31849b4f26 100644 --- a/cocos/scripting/js-bindings/auto/jsb_gles2_auto.h +++ b/cocos/scripting/js-bindings/auto/jsb_gles2_auto.h @@ -9,5 +9,6 @@ extern se::Class* __jsb_cc_gfx_GLES2Device_class; bool js_register_cc_gfx_GLES2Device(se::Object* obj); bool register_all_gles2(se::Object* obj); SE_DECLARE_FUNC(js_gles2_GLES2Device_checkExtension); +SE_DECLARE_FUNC(js_gles2_GLES2Device_bindingMappingInfo); SE_DECLARE_FUNC(js_gles2_GLES2Device_GLES2Device); diff --git a/cocos/scripting/js-bindings/auto/jsb_gles3_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_gles3_auto.cpp index 9bc060a9180..258b5dc539e 100644 --- a/cocos/scripting/js-bindings/auto/jsb_gles3_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_gles3_auto.cpp @@ -13,6 +13,24 @@ se::Object* __jsb_cc_gfx_GLES3Device_proto = nullptr; se::Class* __jsb_cc_gfx_GLES3Device_class = nullptr; +static bool js_gles3_GLES3Device_bindingMappingInfo(se::State& s) +{ + cc::gfx::GLES3Device* cobj = (cc::gfx::GLES3Device*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gles3_GLES3Device_bindingMappingInfo : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const cc::gfx::BindingMappingInfo& result = cobj->bindingMappingInfo(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gles3_GLES3Device_bindingMappingInfo : 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_gles3_GLES3Device_bindingMappingInfo) + static bool js_gles3_GLES3Device_checkExtension(se::State& s) { cc::gfx::GLES3Device* cobj = (cc::gfx::GLES3Device*)s.nativeThisObject(); @@ -66,6 +84,7 @@ bool js_register_gles3_GLES3Device(se::Object* obj) { auto cls = se::Class::create("GLES3Device", obj, __jsb_cc_gfx_Device_proto, _SE(js_gles3_GLES3Device_constructor)); + cls->defineFunction("bindingMappingInfo", _SE(js_gles3_GLES3Device_bindingMappingInfo)); cls->defineFunction("checkExtension", _SE(js_gles3_GLES3Device_checkExtension)); cls->defineFinalizeFunction(_SE(js_cc_gfx_GLES3Device_finalize)); cls->install(); diff --git a/cocos/scripting/js-bindings/auto/jsb_gles3_auto.h b/cocos/scripting/js-bindings/auto/jsb_gles3_auto.h index e5e67573369..a059439b8c3 100644 --- a/cocos/scripting/js-bindings/auto/jsb_gles3_auto.h +++ b/cocos/scripting/js-bindings/auto/jsb_gles3_auto.h @@ -8,6 +8,7 @@ extern se::Class* __jsb_cc_gfx_GLES3Device_class; bool js_register_cc_gfx_GLES3Device(se::Object* obj); bool register_all_gles3(se::Object* obj); +SE_DECLARE_FUNC(js_gles3_GLES3Device_bindingMappingInfo); SE_DECLARE_FUNC(js_gles3_GLES3Device_checkExtension); SE_DECLARE_FUNC(js_gles3_GLES3Device_GLES3Device); diff --git a/cocos/scripting/js-bindings/auto/jsb_vk_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_vk_auto.cpp index ac1725c9ea2..2ef428eff23 100644 --- a/cocos/scripting/js-bindings/auto/jsb_vk_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_vk_auto.cpp @@ -34,6 +34,24 @@ static bool js_vk_CCVKDevice_checkExtension(se::State& s) } SE_BIND_FUNC(js_vk_CCVKDevice_checkExtension) +static bool js_vk_CCVKDevice_bindingMappingInfo(se::State& s) +{ + cc::gfx::CCVKDevice* cobj = (cc::gfx::CCVKDevice*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_vk_CCVKDevice_bindingMappingInfo : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + const cc::gfx::BindingMappingInfo& result = cobj->bindingMappingInfo(); + ok &= native_ptr_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_vk_CCVKDevice_bindingMappingInfo : 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_vk_CCVKDevice_bindingMappingInfo) + SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_CCVKDevice_finalize) static bool js_vk_CCVKDevice_constructor(se::State& s) @@ -67,6 +85,7 @@ bool js_register_vk_CCVKDevice(se::Object* obj) auto cls = se::Class::create("CCVKDevice", obj, __jsb_cc_gfx_Device_proto, _SE(js_vk_CCVKDevice_constructor)); cls->defineFunction("checkExtension", _SE(js_vk_CCVKDevice_checkExtension)); + cls->defineFunction("bindingMappingInfo", _SE(js_vk_CCVKDevice_bindingMappingInfo)); cls->defineFinalizeFunction(_SE(js_cc_gfx_CCVKDevice_finalize)); cls->install(); JSBClassType::registerClass(cls); diff --git a/cocos/scripting/js-bindings/auto/jsb_vk_auto.h b/cocos/scripting/js-bindings/auto/jsb_vk_auto.h index 1b633398548..e2cac10eb65 100644 --- a/cocos/scripting/js-bindings/auto/jsb_vk_auto.h +++ b/cocos/scripting/js-bindings/auto/jsb_vk_auto.h @@ -9,5 +9,6 @@ extern se::Class* __jsb_cc_gfx_CCVKDevice_class; bool js_register_cc_gfx_CCVKDevice(se::Object* obj); bool register_all_vk(se::Object* obj); SE_DECLARE_FUNC(js_vk_CCVKDevice_checkExtension); +SE_DECLARE_FUNC(js_vk_CCVKDevice_bindingMappingInfo); SE_DECLARE_FUNC(js_vk_CCVKDevice_CCVKDevice); diff --git a/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp b/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp index ec39556271b..1cef1ab31b0 100644 --- a/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp @@ -48,6 +48,79 @@ #define GFX_INVALID_BINDING ((uint8_t)-1) #define GFX_INVALID_HANDLE ((uint)-1) +se::Object *__jsb_cc_gfx_BindingMappingInfo_proto = nullptr; +se::Class *__jsb_cc_gfx_BindingMappingInfo_class = nullptr; + +SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_BindingMappingInfo_finalize) + +static bool js_gfx_BindingMappingInfo_constructor(se::State &s) { + CC_UNUSED bool ok = true; + const auto &args = s.args(); + size_t argc = args.size(); + + if (argc == 0) { + cc::gfx::BindingMappingInfo *cobj = JSB_ALLOC(cc::gfx::BindingMappingInfo); + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + return true; + } else if (argc == 1 && args[0].isObject()) { + + se::Object *json = args[0].toObject(); + se::Value field; + + cc::gfx::BindingMappingInfo *cobj = JSB_ALLOC(cc::gfx::BindingMappingInfo); + s.thisObject()->setPrivateData(cobj); + se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); + + json->getProperty("bufferOffsets", &field); + if (!field.isUndefined()) { + ok &= seval_to_std_vector(field, &cobj->bufferOffsets); + } + + json->getProperty("samplerOffsets", &field); + if (!field.isUndefined()) { + ok &= seval_to_std_vector(field, &cobj->samplerOffsets); + } + + if (!ok) { + JSB_FREE(cobj); + SE_REPORT_ERROR("Argument convertion error"); + return false; + } + + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_CTOR(js_gfx_BindingMappingInfo_constructor, __jsb_cc_gfx_BindingMappingInfo_class, js_cc_gfx_BindingMappingInfo_finalize) + +static bool js_cc_gfx_BindingMappingInfo_finalize(se::State &s) { + auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { + se::NonRefNativePtrCreatedByCtorMap::erase(iter); + cc::gfx::BindingMappingInfo *cobj = (cc::gfx::BindingMappingInfo *)s.nativeThisObject(); + JSB_FREE(cobj); + } + return true; +} +SE_BIND_FINALIZE_FUNC(js_cc_gfx_BindingMappingInfo_finalize) + +bool js_register_gfx_BindingMappingInfo(se::Object *obj) { + auto cls = se::Class::create("BindingMappingInfo", obj, nullptr, _SE(js_gfx_BindingMappingInfo_constructor)); + + cls->defineFinalizeFunction(_SE(js_cc_gfx_BindingMappingInfo_finalize)); + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_gfx_BindingMappingInfo_proto = cls->getProto(); + __jsb_cc_gfx_BindingMappingInfo_class = cls; + + se::ScriptEngine::getInstance()->clearException(); + return true; +} + bool js_gfx_Device_copyBuffersToTexture(se::State &s) { cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_Device_copyBuffersToTexture : Invalid Native Object"); @@ -138,6 +211,36 @@ bool js_gfx_Device_copyTexImagesToTexture(se::State &s) { } SE_BIND_FUNC(js_gfx_Device_copyTexImagesToTexture) +static bool js_gfx_Device_createBuffer(se::State &s) { + cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_createBuffer : Invalid Native Object"); + const auto &args = s.args(); + size_t argc = args.size(); + + if (argc == 2) { + cc::gfx::Buffer *buffer = nullptr; + + bool createBufferView = false; + seval_to_boolean(args[1], &createBufferView); + + if (createBufferView) { + auto bufferViewInfo = (cc::gfx::BufferViewInfo *)(args[0].toObject()->getPrivateData()); + buffer = cobj->createBuffer(*bufferViewInfo); + } else { + auto bufferInfo = (cc::gfx::BufferInfo *)(args[0].toObject()->getPrivateData()); + buffer = cobj->createBuffer(*bufferInfo); + } + + CC_UNUSED bool ok = native_ptr_to_seval(buffer, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_createBuffer : Error processing arguments"); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_FUNC(js_gfx_Device_createBuffer) + static bool js_gfx_Device_createTexture(se::State &s) { cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_Device_createTexture : Invalid Native Object"); @@ -168,6 +271,35 @@ static bool js_gfx_Device_createTexture(se::State &s) { } SE_BIND_FUNC(js_gfx_Device_createTexture) +static bool js_gfx_Buffer_initialize(se::State &s) { + CC_UNUSED bool ok = true; + cc::gfx::Buffer *cobj = (cc::gfx::Buffer *)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_initialize : Invalid Native Object"); + const auto &args = s.args(); + size_t argc = args.size(); + + if (argc == 2) { + bool initWithBufferViewInfo = false; + seval_to_boolean(args[1], &initWithBufferViewInfo); + + if (initWithBufferViewInfo) { + auto bufferViewInfo = (cc::gfx::BufferViewInfo *)(args[0].toObject()->getPrivateData()); + ok &= cobj->initialize(*bufferViewInfo); + } else { + auto bufferInfo = (cc::gfx::BufferInfo *)(args[0].toObject()->getPrivateData()); + ok &= cobj->initialize(*bufferInfo); + } + + ok &= boolean_to_seval(ok, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Buffer_initialize : Error processing arguments"); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_FUNC(js_gfx_Buffer_initialize) + static bool js_gfx_Texture_initialize(se::State &s) { CC_UNUSED bool ok = true; cc::gfx::Texture *cobj = (cc::gfx::Texture *)s.nativeThisObject(); @@ -416,7 +548,7 @@ static bool js_gfx_SubPass_constructor(se::State &s) { size_t argc = args.size(); if (argc == 0) { - cc::gfx::SubPass *cobj = new (std::nothrow) cc::gfx::SubPass(); + cc::gfx::SubPass *cobj = JSB_ALLOC(cc::gfx::SubPass); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; @@ -424,7 +556,7 @@ static bool js_gfx_SubPass_constructor(se::State &s) { se::Object *json = args[0].toObject(); se::Value field; - cc::gfx::SubPass *cobj = new (std::nothrow) cc::gfx::SubPass(); + cc::gfx::SubPass *cobj = JSB_ALLOC(cc::gfx::SubPass); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); @@ -483,7 +615,7 @@ static bool js_gfx_SubPass_constructor(se::State &s) { return true; } else if (argc == 6) { - cc::gfx::SubPass *cobj = new (std::nothrow) cc::gfx::SubPass(); + cc::gfx::SubPass *cobj = JSB_ALLOC(cc::gfx::SubPass); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); @@ -719,6 +851,8 @@ SE_BIND_FUNC(js_gfx_InputAssembler_extractDrawInfo) bool register_all_gfx_manual(se::Object *obj) { __jsb_cc_gfx_Device_proto->defineFunction("copyBuffersToTexture", _SE(js_gfx_Device_copyBuffersToTexture)); __jsb_cc_gfx_Device_proto->defineFunction("copyTexImagesToTexture", _SE(js_gfx_Device_copyTexImagesToTexture)); + + __jsb_cc_gfx_Device_proto->defineFunction("createBuffer", _SE(js_gfx_Device_createBuffer)); __jsb_cc_gfx_Device_proto->defineFunction("createTexture", _SE(js_gfx_Device_createTexture)); __jsb_cc_gfx_Buffer_proto->defineFunction("update", _SE(js_gfx_GFXBuffer_update)); @@ -730,9 +864,20 @@ bool register_all_gfx_manual(se::Object *obj) { __jsb_cc_gfx_InputAssembler_proto->defineFunction("extractDrawInfo", _SE(js_gfx_InputAssembler_extractDrawInfo)); + __jsb_cc_gfx_Buffer_proto->defineFunction("initialize", _SE(js_gfx_Buffer_initialize)); __jsb_cc_gfx_Texture_proto->defineFunction("initialize", _SE(js_gfx_Texture_initialize)); - js_register_gfx_SubPass(obj); + // Get the ns + se::Value nsVal; + if (!obj->getProperty("gfx", &nsVal)) { + se::HandleObject jsobj(se::Object::createPlainObject()); + nsVal.setObject(jsobj); + obj->setProperty("gfx", nsVal); + } + se::Object *ns = nsVal.toObject(); + + js_register_gfx_BindingMappingInfo(ns); + js_register_gfx_SubPass(ns); #if defined USE_VULKAN register_all_vk(obj); diff --git a/tools/tojs/gfx.ini b/tools/tojs/gfx.ini index fffbbf02c2d..9439f68f35b 100644 --- a/tools/tojs/gfx.ini +++ b/tools/tojs/gfx.ini @@ -33,7 +33,7 @@ replace_headers = # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu.*$". -classes = GFXObject Device BindingLayout Buffer CommandBuffer Framebuffer InputAssembler PipelineState Fence Queue RenderPass Sampler Shader Texture API Feature Format FormatType Type BufferUsageBit BufferFlagBit BufferAccessBit TextureUsageBit TextureFlagBit ShaderType TextureLayout QueueType CommandBufferType Offset Rect Extent TextureSubres TextureCopy BufferTextureCopy Viewport Color DeviceInfo ContextInfo BufferInfo DrawInfo IndirectBuffer TextureInfo TextureViewInfo SamplerInfo ShaderMacro Uniform UniformBlock UniformSampler ShaderStage ShaderInfo Attribute InputAssemblerInfo ColorAttachment DepthStencilAttachment RenderPassInfo FramebufferInfo Binding BindingLayoutInfo BindingUnit PushConstantRange InputState RasterizerState DepthStencilState BlendTarget BlendState PipelineStateInfo CommandBufferInfo QueueInfo FormatInfo MemoryStatus +classes = GFXObject Device Buffer CommandBuffer Framebuffer InputAssembler DescriptorSet DescriptorSetLayout PipelineLayout PipelineState Fence Queue RenderPass Sampler Shader Texture API Feature Format FormatType Type BufferUsageBit BufferFlagBit BufferAccessBit TextureUsageBit TextureFlagBit ShaderType TextureLayout QueueType CommandBufferType Offset Rect Extent TextureSubres TextureCopy BufferTextureCopy Viewport Color DeviceInfo ContextInfo BufferInfo BufferViewInfo DrawInfo IndirectBuffer TextureInfo TextureViewInfo SamplerInfo ShaderMacro Uniform UniformBlock UniformSampler ShaderStage ShaderInfo Attribute InputAssemblerInfo ColorAttachment DepthStencilAttachment RenderPassInfo FramebufferInfo DescriptorSetLayoutBinding DescriptorSetInfo DescriptorSetLayoutInfo PipelineLayoutInfo PushConstantRange InputState RasterizerState DepthStencilState BlendTarget BlendState PipelineStateInfo CommandBufferInfo QueueInfo FormatInfo MemoryStatus classes_need_extend = @@ -44,11 +44,13 @@ classes_need_extend = # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = BindingLayout::[BindingLayout], - Buffer::[Buffer update], +skip = Buffer::[Buffer initialize update], CommandBuffer::[CommandBuffer execute copyBuffersToTexture], Framebuffer::[Framebuffer], InputAssembler::[InputAssembler extractDrawInfo], + DescriptorSet::[DescriptorSet], + DescriptorSetLayout::[DescriptorSetLayout], + PipelineLayout::[PipelineLayout], PipelineState::[PipelineState], Fence::[Fence], Queue::[Queue], @@ -56,21 +58,23 @@ skip = BindingLayout::[BindingLayout], Sampler::[Sampler], Shader::[Shader], Texture::[Texture initialize], - Device::[copyBuffersToTexture createTexture getInstance], + Device::[copyBuffersToTexture createBuffer createTexture getInstance], BlendState::[targets] -getter_setter = Device::[gfxAPI deviceName width height nativeWidth nativeHeight memoryStatus context queue renderer vendor numDrawCalls numInstances numTris maxVertexAttributes maxVertexUniformVectors maxFragmentUniformVectors maxTextureUnits maxVertexTextureUnits maxUniformBufferBindings maxUniformBlockSize maxTextureSize maxCubeMapTextureSize depthBits stencilBits shaderIdGen colorFormat depthStencilFormat clipSpaceMinZ screenSpaceSignY UVSpaceSignY], +getter_setter = Device::[gfxAPI deviceName width height nativeWidth nativeHeight memoryStatus context queue renderer vendor numDrawCalls numInstances numTris maxVertexAttributes maxVertexUniformVectors maxFragmentUniformVectors maxTextureUnits maxVertexTextureUnits maxUniformBufferBindings maxUniformBlockSize maxTextureSize maxCubeMapTextureSize uboOffsetAlignment depthBits stencilBits shaderIdGen colorFormat depthStencilFormat clipSpaceMinZ screenSpaceSignY UVSpaceSignY], Shader::[device name hash stages attributes blocks samplers], Texture::[type usage format width height depth layerCount levelCount size samples flags buffer], BindingLayout::[device bindingUnits], Queue::[device type], RenderPass::[device colorAttachments depthStencilAttachment subPasses hash], + DescriptorSetLayout::[bindings], + PipelineLayout::[setLayouts], PipelineState::[device shader primitive inputState rasterizerState depthStencilState blendState renderPass], InputAssembler::[device vertexBuffers attributes indexBuffer indirectBuffer vertexCount firstVertex indexCount firstIndex vertexOffset instanceCount firstInstance attributesHash], Commanduffer::[device type queue numDrawCalls numInstances numTris], Context::[device sharedContext/sharedContext vsyncMode colorFormat depthStencilFormat], Framebuffer::[device renderPass colorTextures depthStencilTexture], - Buffer::[device usage memUsage stride count size flags bufferView], + Buffer::[device usage memUsage stride count size flags backupBuffer], Sampler::[device name minFilter magFilter mipFilter addressU addressV addressW maxAnisotropy cmpFunc borderColor minLOD maxLOD mipLODBias], GFXObject::[status gfxType/getType]