Skip to content

Commit

Permalink
GFX Descriptor Set: Vulkan
Browse files Browse the repository at this point in the history
  • Loading branch information
YunHsiao committed Aug 20, 2020
1 parent c90c536 commit 17275ed
Show file tree
Hide file tree
Showing 37 changed files with 783 additions and 572 deletions.
11 changes: 7 additions & 4 deletions cocos/renderer/core/gfx/GFXBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ class CC_DLL Buffer : public GFXObject {
CC_INLINE uint getCount() const { return _count; }
CC_INLINE uint getSize() const { return _size; }
CC_INLINE BufferFlags getFlags() const { return _flags; }
CC_INLINE uint8_t *getBufferView() const { return _buffer; }
CC_INLINE uint8_t *getBackupBuffer() const { return _buffer; }
CC_INLINE bool isBufferView() const { return _isBufferView; }

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

} // namespace gfx
Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/core/gfx/GFXCommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CC_DLL CommandBuffer : public GFXObject {
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) = 0;
virtual void endRenderPass() = 0;
virtual void bindPipelineState(PipelineState *pso) = 0;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, uint *dynamicOffsets) = 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;
Expand Down
1 change: 0 additions & 1 deletion cocos/renderer/core/gfx/GFXDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ enum class ObjectType : uint8_t {
UNKNOWN,
BUFFER,
TEXTURE,
TEXTURE_VIEW,
RENDER_PASS,
FRAMEBUFFER,
SAMPLER,
Expand Down
2 changes: 2 additions & 0 deletions cocos/renderer/core/gfx/GFXTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions cocos/renderer/gfx-gles2/GLES2Buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,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;

Expand Down Expand Up @@ -60,6 +60,8 @@ bool GLES2Buffer::initialize(const BufferInfo &info) {

bool GLES2Buffer::initialize(const BufferViewInfo &info) {

_isBufferView = true;

GLES2Buffer *buffer = (GLES2Buffer *)info.buffer;

_usage = buffer->_usage;
Expand Down Expand Up @@ -96,7 +98,7 @@ void GLES2Buffer::destroy() {
}

void GLES2Buffer::resize(uint size) {
CCASSERT(!_gpuBufferView, "Cannot resize buffer views");
CCASSERT(!_isBufferView, "Cannot resize buffer views");

if (_size != size) {
const uint oldSize = _size;
Expand Down Expand Up @@ -129,7 +131,7 @@ void GLES2Buffer::resize(uint size) {
}

void GLES2Buffer::update(void *buffer, uint offset, uint size) {
CCASSERT(!_gpuBufferView, "Cannot update through buffer views");
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");

Expand Down
4 changes: 2 additions & 2 deletions cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ void GLES2CommandBuffer::bindPipelineState(PipelineState *pso) {
}
}

void GLES2CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, uint *dynamicOffsets) {
void GLES2CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) {
// these will break if using more sets than what's declared in DeviceInfo.bindingMappingInfo
CCASSERT(_curGPUDescriptorSets.size() > set, "");
CCASSERT(_curDynamicOffsets.size() > set, "");

GLES2GPUDescriptorSet *gpuDescriptorSet = ((GLES2DescriptorSet *)descriptorSet)->gpuBindingLayout();
GLES2GPUDescriptorSet *gpuDescriptorSet = ((GLES2DescriptorSet *)descriptorSet)->gpuDescriptorSet();
if (_curGPUDescriptorSets[set] != gpuDescriptorSet) {
_curGPUDescriptorSets[set] = gpuDescriptorSet;
_isStateInvalid = true;
Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/gfx-gles2/GLES2CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CC_GLES2_API GLES2CommandBuffer : public CommandBuffer {
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<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, uint *dynamicOffsets) 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;
Expand Down
2 changes: 2 additions & 0 deletions cocos/renderer/gfx-gles2/GLES2Commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,8 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
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) {
Expand Down
34 changes: 19 additions & 15 deletions cocos/renderer/gfx-gles2/GLES2DescriptorSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ bool GLES2DescriptorSet::initialize(const DescriptorSetInfo &info) {
_textures.resize(descriptorCount);
_samplers.resize(descriptorCount);

_gpuBindingLayout = CC_NEW(GLES2GPUDescriptorSet);
_gpuBindingLayout->gpuDescriptors.resize(descriptorCount);
_gpuDescriptorSet = CC_NEW(GLES2GPUDescriptorSet);
_gpuDescriptorSet->gpuDescriptors.resize(descriptorCount);
for (size_t i = 0u; i < descriptorCount; i++) {
_gpuBindingLayout->gpuDescriptors[i].type = bindings[i].descriptorType;
_gpuDescriptorSet->gpuDescriptors[i].type = bindings[i].descriptorType;
}

_status = Status::SUCCESS;
Expand All @@ -41,33 +41,37 @@ bool GLES2DescriptorSet::initialize(const DescriptorSetInfo &info) {
void GLES2DescriptorSet::destroy() {
_layout = nullptr;

if (_gpuBindingLayout) {
CC_DELETE(_gpuBindingLayout);
_gpuBindingLayout = nullptr;
if (_gpuDescriptorSet) {
CC_DELETE(_gpuDescriptorSet);
_gpuDescriptorSet = nullptr;
}

_status = Status::UNREADY;
}

void GLES2DescriptorSet::update() {
if (_isDirty && _gpuBindingLayout) {
const DescriptorSetLayoutBindingList &bindings = _layout->getBindings();
for (size_t i = 0; i < bindings.size(); i++) {
if ((uint)bindings[i].descriptorType & DESCRIPTOR_BUFFER_TYPE) {
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()) {
_gpuBindingLayout->gpuDescriptors[i].gpuBuffer = buffer->gpuBuffer();
binding.gpuBuffer = buffer->gpuBuffer();
} else if (buffer->gpuBufferView()) {
_gpuBindingLayout->gpuDescriptors[i].gpuBufferView = buffer->gpuBufferView();
binding.gpuBufferView = buffer->gpuBufferView();
}
}
} else if ((uint)bindings[i].descriptorType & DESCRIPTOR_SAMPLER_TYPE) {
}
else if ((uint)binding.type & DESCRIPTOR_SAMPLER_TYPE) {
if (_textures[i]) {
_gpuBindingLayout->gpuDescriptors[i].gpuTexture = ((GLES2Texture *)_textures[i])->gpuTexture();
binding.gpuTexture = ((GLES2Texture *)_textures[i])->gpuTexture();
}
if (_samplers[i]) {
_gpuBindingLayout->gpuDescriptors[i].gpuSampler = ((GLES2Sampler *)_samplers[i])->gpuSampler();
binding.gpuSampler = ((GLES2Sampler *)_samplers[i])->gpuSampler();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cocos/renderer/gfx-gles2/GLES2DescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class CC_GLES2_API GLES2DescriptorSet : public DescriptorSet {
virtual void destroy() override;
virtual void update() override;

CC_INLINE GLES2GPUDescriptorSet *gpuBindingLayout() const { return _gpuBindingLayout; }
CC_INLINE GLES2GPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; }

private:
GLES2GPUDescriptorSet *_gpuBindingLayout = nullptr;
GLES2GPUDescriptorSet *_gpuDescriptorSet = nullptr;
};

} // namespace gfx
Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/gfx-gles2/GLES2Texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions cocos/renderer/gfx-gles3/GLES3Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ class CC_GLES3_API GLES3Buffer : public Buffer {
virtual void update(void *buffer, uint offset, uint size) override;

CC_INLINE GLES3GPUBuffer *gpuBuffer() const { return _gpuBuffer; }
CC_INLINE bool isBufferView() const { return _isBufferView; }

private:
bool _isBufferView = false;
GLES3GPUBuffer *_gpuBuffer = nullptr;
};

Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void GLES3CommandBuffer::bindPipelineState(PipelineState *pso) {
}
}

void GLES3CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, uint *dynamicOffsets) {
void GLES3CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) {
// these will break if using more sets than what's declared in DeviceInfo.bindingMappingInfo
CCASSERT(_curGPUDescriptorSets.size() > set, "");
CCASSERT(_curDynamicOffsets.size() > set, "");
Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/gfx-gles3/GLES3CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer {
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<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, uint *dynamicOffsets) 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;
Expand Down
3 changes: 2 additions & 1 deletion cocos/renderer/gfx-gles3/GLES3Texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions cocos/renderer/gfx-vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 17275ed

Please sign in to comment.