mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
vk: async submission (#2647)
This commit is contained in:
@@ -31,8 +31,8 @@ public:
|
||||
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 copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) = 0;
|
||||
virtual void execute(const vector<CommandBuffer *> &cmd_buffs, uint32_t count) = 0;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) = 0;
|
||||
virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) = 0;
|
||||
|
||||
CC_INLINE Device *getDevice() const { return _device; }
|
||||
CC_INLINE Queue *getQueue() const { return _queue; }
|
||||
|
||||
@@ -40,11 +40,9 @@ enum class ObjectType : uint8_t {
|
||||
PIPELINE_STATE,
|
||||
BINDING_LAYOUT,
|
||||
INPUT_ASSEMBLER,
|
||||
COMMAND_ALLOCATOR,
|
||||
COMMAND_BUFFER,
|
||||
FENCE,
|
||||
QUEUE,
|
||||
WINDOW,
|
||||
};
|
||||
|
||||
enum class Status : uint8_t {
|
||||
@@ -610,10 +608,7 @@ struct BufferTextureCopy {
|
||||
TextureSubres texSubres;
|
||||
};
|
||||
typedef vector<BufferTextureCopy> BufferTextureCopyList;
|
||||
|
||||
struct DataArray {
|
||||
vector<uint8_t *> datas;
|
||||
};
|
||||
typedef vector<const uint8_t *> BufferDataList;
|
||||
|
||||
struct Viewport {
|
||||
int left = 0;
|
||||
@@ -709,11 +704,11 @@ struct TextureInfo {
|
||||
TextureType type = TextureType::TEX2D;
|
||||
TextureUsage usage = TextureUsageBit::NONE;
|
||||
Format format = Format::UNKNOWN;
|
||||
uint width = 0;
|
||||
uint height = 0;
|
||||
uint depth = 1;
|
||||
uint arrayLayer = 1;
|
||||
uint mipLevel = 1;
|
||||
uint width = 0u;
|
||||
uint height = 0u;
|
||||
uint depth = 1u;
|
||||
uint layerCount = 1u;
|
||||
uint levelCount = 1u;
|
||||
SampleCount samples = SampleCount::X1;
|
||||
TextureFlags flags = TextureFlagBit::NONE;
|
||||
};
|
||||
@@ -722,10 +717,10 @@ struct TextureViewInfo {
|
||||
Texture *texture = nullptr;
|
||||
TextureType type = TextureType::TEX2D;
|
||||
Format format = Format::UNKNOWN;
|
||||
uint baseLevel = 0;
|
||||
uint levelCount = 1;
|
||||
uint baseLayer = 0;
|
||||
uint layerCount = 1;
|
||||
uint baseLevel = 0u;
|
||||
uint levelCount = 1u;
|
||||
uint baseLayer = 0u;
|
||||
uint layerCount = 1u;
|
||||
};
|
||||
|
||||
struct SamplerInfo {
|
||||
@@ -966,10 +961,10 @@ struct CommandBufferInfo {
|
||||
Queue *queue = nullptr;
|
||||
CommandBufferType type = CommandBufferType::PRIMARY;
|
||||
};
|
||||
typedef vector<CommandBuffer *> CommandBufferList;
|
||||
|
||||
struct QueueInfo {
|
||||
QueueType type = QueueType::GRAPHICS;
|
||||
bool forceSync = false;
|
||||
};
|
||||
|
||||
struct FenceInfo {
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) = 0;
|
||||
virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) = 0;
|
||||
virtual PipelineState *createPipelineState(const PipelineStateInfo &info) = 0;
|
||||
virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) = 0;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) = 0;
|
||||
|
||||
CC_INLINE API getGfxAPI() const { return _API; }
|
||||
CC_INLINE const String &getDeviceName() const { return _deviceName; }
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
CC_INLINE bool hasFeature(Feature feature) const { return _features[static_cast<uint8_t>(feature)]; }
|
||||
CC_INLINE void defineMacro(const String ¯o, const String &value) { _macros[macro] = value; }
|
||||
CC_INLINE float getClipSpaceMinZ() const { return _clipSpaceMinZ; }
|
||||
CC_INLINE float getClipSpaceSignY() const { return _clipSpaceSignY; }
|
||||
CC_INLINE float getScreenSpaceSignY() const { return _screenSpaceSignY; }
|
||||
CC_INLINE float getUVSpaceSignY() const { return _UVSpaceSignY; }
|
||||
|
||||
protected:
|
||||
@@ -98,7 +98,7 @@ protected:
|
||||
uint _shaderIdGen = 0;
|
||||
unordered_map<String, String> _macros;
|
||||
float _clipSpaceMinZ = -1.0f;
|
||||
float _clipSpaceSignY = 1.0f;
|
||||
float _screenSpaceSignY = 1.0f;
|
||||
float _UVSpaceSignY = -1.0f;
|
||||
}; // namespace gfx
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
CC_INLINE uint getWidth() const { return _width; }
|
||||
CC_INLINE uint getHeight() const { return _height; }
|
||||
CC_INLINE uint getDepth() const { return _depth; }
|
||||
CC_INLINE uint getArrayLayer() const { return _arrayLayer; }
|
||||
CC_INLINE uint getMipLevel() const { return _mipLevel; }
|
||||
CC_INLINE uint getLayerCount() const { return _layerCount; }
|
||||
CC_INLINE uint getLevelCount() const { return _levelCount; }
|
||||
CC_INLINE uint getSize() const { return _size; }
|
||||
CC_INLINE SampleCount getSamples() const { return _samples; }
|
||||
CC_INLINE TextureFlags getFlags() const { return _flags; }
|
||||
@@ -35,12 +35,14 @@ protected:
|
||||
TextureType _type = TextureType::TEX2D;
|
||||
TextureUsage _usage = TextureUsageBit::NONE;
|
||||
Format _format = Format::UNKNOWN;
|
||||
uint _width = 0;
|
||||
uint _height = 0;
|
||||
uint _depth = 1;
|
||||
uint _arrayLayer = 1;
|
||||
uint _mipLevel = 1;
|
||||
uint _size = 0;
|
||||
uint _width = 0u;
|
||||
uint _height = 0u;
|
||||
uint _depth = 1u;
|
||||
uint _baseLevel = 0u;
|
||||
uint _levelCount = 1u;
|
||||
uint _baseLayer = 0u;
|
||||
uint _layerCount = 1u;
|
||||
uint _size = 0u;
|
||||
SampleCount _samples = SampleCount::X1;
|
||||
TextureFlags _flags = TextureFlagBit::NONE;
|
||||
uint8_t *_buffer = nullptr;
|
||||
|
||||
@@ -152,10 +152,10 @@ void GLES2CommandBuffer::setBlendConstants(const Color &constants) {
|
||||
}
|
||||
|
||||
void GLES2CommandBuffer::setDepthBound(float min_bounds, float max_bounds) {
|
||||
if (math::IsNotEqualF(_curDepthBounds.min_bounds, min_bounds) ||
|
||||
math::IsNotEqualF(_curDepthBounds.max_bounds, max_bounds)) {
|
||||
_curDepthBounds.min_bounds = min_bounds;
|
||||
_curDepthBounds.max_bounds = max_bounds;
|
||||
if (math::IsNotEqualF(_curDepthBounds.minBounds, min_bounds) ||
|
||||
math::IsNotEqualF(_curDepthBounds.maxBounds, max_bounds)) {
|
||||
_curDepthBounds.minBounds = min_bounds;
|
||||
_curDepthBounds.maxBounds = max_bounds;
|
||||
_isStateInvalid = true;
|
||||
}
|
||||
}
|
||||
@@ -172,10 +172,10 @@ void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) {
|
||||
void GLES2CommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint mask) {
|
||||
if ((_curStencilCompareMask.face != face) ||
|
||||
(_curStencilCompareMask.refrence != ref) ||
|
||||
(_curStencilCompareMask.compare_mask != mask)) {
|
||||
(_curStencilCompareMask.compareMask != mask)) {
|
||||
_curStencilCompareMask.face = face;
|
||||
_curStencilCompareMask.refrence = ref;
|
||||
_curStencilCompareMask.compare_mask = mask;
|
||||
_curStencilCompareMask.compareMask = mask;
|
||||
_isStateInvalid = true;
|
||||
}
|
||||
}
|
||||
@@ -237,18 +237,17 @@ void GLES2CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint
|
||||
}
|
||||
}
|
||||
|
||||
void GLES2CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) {
|
||||
void GLES2CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) {
|
||||
if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) ||
|
||||
(_type == CommandBufferType::SECONDARY)) {
|
||||
GLES2GPUBuffer *gpuBuffer = ((GLES2Buffer *)src)->gpuBuffer();
|
||||
GLES2GPUTexture *gpuTexture = ((GLES2Texture *)dst)->gpuTexture();
|
||||
if (gpuBuffer && gpuTexture) {
|
||||
GLES2GPUTexture *gpuTexture = ((GLES2Texture *)texture)->gpuTexture();
|
||||
if (gpuTexture) {
|
||||
GLES2CmdCopyBufferToTexture *cmd = _gles2Allocator->copyBufferToTextureCmdPool.alloc();
|
||||
cmd->gpuBuffer = gpuBuffer;
|
||||
cmd->gpuTexture = gpuTexture;
|
||||
cmd->dst_layout = layout;
|
||||
cmd->buffers.resize(buffers.size());
|
||||
cmd->regions.resize(regions.size());
|
||||
for (uint i = 0; i < static_cast<uint>(regions.size()); ++i) {
|
||||
cmd->buffers[i] = buffers[i];
|
||||
cmd->regions[i] = regions[i];
|
||||
}
|
||||
|
||||
@@ -256,11 +255,11 @@ void GLES2CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureL
|
||||
_cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE);
|
||||
}
|
||||
} else {
|
||||
CC_LOG_ERROR("Command 'copyBufferToTexture' must be recorded outside a render pass.");
|
||||
CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass.");
|
||||
}
|
||||
}
|
||||
|
||||
void GLES2CommandBuffer::execute(const vector<CommandBuffer *> &cmd_buffs, uint32_t count) {
|
||||
void GLES2CommandBuffer::execute(const CommandBufferList &cmd_buffs, uint32_t count) {
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
GLES2CommandBuffer *cmd_buff = (GLES2CommandBuffer *)cmd_buffs[i];
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ public:
|
||||
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 copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) override;
|
||||
virtual void execute(const vector<CommandBuffer *> &cmd_buffs, uint32_t count) override;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override;
|
||||
virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override;
|
||||
|
||||
private:
|
||||
void BindStates();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "GLES2Std.h"
|
||||
|
||||
#include "GLES2Commands.h"
|
||||
#include "GLES2Context.h"
|
||||
#include "GLES2Device.h"
|
||||
#include "GLES2StateCache.h"
|
||||
#include "GLES2Context.h"
|
||||
|
||||
#define BUFFER_OFFSET(idx) (static_cast<char *>(0) + (idx))
|
||||
|
||||
@@ -1999,43 +1999,43 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
|
||||
switch (cmd->stencilCompareMask.face) {
|
||||
case StencilFace::FRONT:
|
||||
if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask)) {
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask)) {
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncFront],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask;
|
||||
}
|
||||
break;
|
||||
case StencilFace::BACK:
|
||||
if ((cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) {
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) {
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncBack],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask;
|
||||
}
|
||||
break;
|
||||
case StencilFace::ALL:
|
||||
if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask) ||
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask) ||
|
||||
(cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) {
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) {
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncFront],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncBack],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask;
|
||||
cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2053,22 +2053,22 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
|
||||
if (gpuInputAssembler && gpuPipelineState) {
|
||||
if (!gpuInputAssembler->gpuIndirectBuffer) {
|
||||
|
||||
if (gpuInputAssembler->gpuIndexBuffer && cmd->draw_info.indexCount >= 0) {
|
||||
if (gpuInputAssembler->gpuIndexBuffer && cmd->drawInfo.indexCount >= 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += cmd->draw_info.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->draw_info.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->draw_info.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
offset += cmd->drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
if (device->useDrawInstanced()) {
|
||||
glDrawElementsInstancedEXT(glPrimitive, cmd->draw_info.indexCount, gpuInputAssembler->glIndexType, offset, cmd->draw_info.instanceCount);
|
||||
glDrawElementsInstancedEXT(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (cmd->draw_info.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount);
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount);
|
||||
} else {
|
||||
if (device->useDrawInstanced()) {
|
||||
glDrawArraysInstancedEXT(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount, cmd->draw_info.instanceCount);
|
||||
glDrawArraysInstancedEXT(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount, cmd->drawInfo.instanceCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2078,7 +2078,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
|
||||
if (gpuInputAssembler->gpuIndexBuffer && draw.indexCount >= 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->draw_info.instanceCount == 0) {
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
if (device->useDrawInstanced()) {
|
||||
@@ -2106,7 +2106,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
|
||||
}
|
||||
case GFXCmdType::COPY_BUFFER_TO_TEXTURE: {
|
||||
GLES2CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx];
|
||||
GLES2CmdFuncCopyBuffersToTexture(device, &cmd->gpuBuffer->buffer, cmd->gpuTexture, cmd->regions);
|
||||
GLES2CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2116,7 +2116,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
|
||||
}
|
||||
}
|
||||
|
||||
void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) {
|
||||
void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) {
|
||||
GLuint &glTexture = device->stateCache->glTextures[device->stateCache->texUint];
|
||||
if (glTexture != gpuTexture->glTexture) {
|
||||
glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture);
|
||||
@@ -2134,7 +2134,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe
|
||||
const BufferTextureCopy ®ion = regions[i];
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1);
|
||||
glCompressedTexSubImage2D(GL_TEXTURE_2D,
|
||||
@@ -2169,7 +2169,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe
|
||||
for (uint z = region.texSubres.baseArrayLayer; z < layerCount; ++z) {
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1);
|
||||
glCompressedTexSubImage3DOES(GL_TEXTURE_2D_ARRAY,
|
||||
@@ -2204,7 +2204,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
d = region.texExtent.depth;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, d + 1, 1);
|
||||
glCompressedTexSubImage3DOES(GL_TEXTURE_3D,
|
||||
@@ -2240,7 +2240,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe
|
||||
for (f = region.texSubres.baseArrayLayer; f < face_count; ++f) {
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1);
|
||||
glCompressedTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f,
|
||||
|
||||
@@ -15,8 +15,8 @@ struct GLES2DepthBias {
|
||||
};
|
||||
|
||||
struct GLES2DepthBounds {
|
||||
float min_bounds = 0.0f;
|
||||
float max_bounds = 0.0f;
|
||||
float minBounds = 0.0f;
|
||||
float maxBounds = 0.0f;
|
||||
};
|
||||
|
||||
struct GLES2StencilWriteMask {
|
||||
@@ -27,7 +27,7 @@ struct GLES2StencilWriteMask {
|
||||
struct GLES2StencilCompareMask {
|
||||
StencilFace face = StencilFace::FRONT;
|
||||
int refrence = 0;
|
||||
uint compare_mask = 0;
|
||||
uint compareMask = 0;
|
||||
};
|
||||
|
||||
struct GLES2TextureSubres {
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
GLES2GPUPipelineState *gpuPipelineState = nullptr;
|
||||
GLES2GPUBindingLayout *gpuBindingLayout = nullptr;
|
||||
GLES2GPUInputAssembler *gpuInputAssembler = nullptr;
|
||||
uint8_t state_flags[(int)GLES2State::COUNT] = {0};
|
||||
uint8_t stateFlags[(int)GLES2State::COUNT] = {0};
|
||||
Viewport viewport;
|
||||
Rect scissor;
|
||||
float lineWidth = 1.0f;
|
||||
@@ -98,13 +98,13 @@ public:
|
||||
gpuPipelineState = nullptr;
|
||||
gpuBindingLayout = nullptr;
|
||||
gpuInputAssembler = nullptr;
|
||||
memset(state_flags, 0, sizeof(state_flags));
|
||||
memset(stateFlags, 0, sizeof(stateFlags));
|
||||
}
|
||||
};
|
||||
|
||||
class GLES2CmdDraw : public GFXCmd {
|
||||
public:
|
||||
DrawInfo draw_info;
|
||||
DrawInfo drawInfo;
|
||||
|
||||
GLES2CmdDraw() : GFXCmd(GFXCmdType::DRAW) {}
|
||||
virtual void clear() override {}
|
||||
@@ -127,16 +127,15 @@ public:
|
||||
|
||||
class GLES2CmdCopyBufferToTexture : public GFXCmd {
|
||||
public:
|
||||
GLES2GPUBuffer *gpuBuffer = nullptr;
|
||||
GLES2GPUTexture *gpuTexture = nullptr;
|
||||
TextureLayout dst_layout;
|
||||
BufferDataList buffers;
|
||||
BufferTextureCopyList regions;
|
||||
|
||||
GLES2CmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {}
|
||||
|
||||
virtual void clear() override {
|
||||
gpuBuffer = nullptr;
|
||||
gpuTexture = nullptr;
|
||||
buffers.clear();
|
||||
regions.clear();
|
||||
}
|
||||
};
|
||||
@@ -167,7 +166,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, uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions);
|
||||
CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions);
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace cc
|
||||
|
||||
@@ -282,8 +282,8 @@ PipelineState *GLES2Device::createPipelineState(const PipelineStateInfo &info) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GLES2Device::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) {
|
||||
GLES2CmdFuncCopyBuffersToTexture(this, buffers.datas.data(), ((GLES2Texture *)dst)->gpuTexture(), regions);
|
||||
void GLES2Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) {
|
||||
GLES2CmdFuncCopyBuffersToTexture(this, buffers, ((GLES2Texture *)dst)->gpuTexture(), regions);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override;
|
||||
virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override;
|
||||
virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override;
|
||||
virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
|
||||
CC_INLINE bool useVAO() const { return _useVAO; }
|
||||
CC_INLINE bool useDrawInstanced() const { return _useDrawInstanced; }
|
||||
|
||||
@@ -56,13 +56,13 @@ void GLES2InputAssembler::destroy() {
|
||||
}
|
||||
|
||||
void GLES2InputAssembler::ExtractCmdDraw(GLES2CmdDraw *cmd) {
|
||||
cmd->draw_info.vertexCount = _vertexCount;
|
||||
cmd->draw_info.firstVertex = _firstVertex;
|
||||
cmd->draw_info.indexCount = _indexCount;
|
||||
cmd->draw_info.firstIndex = _firstIndex;
|
||||
cmd->draw_info.vertexOffset = _vertexOffset;
|
||||
cmd->draw_info.instanceCount = _instanceCount;
|
||||
cmd->draw_info.firstInstance = _firstInstance;
|
||||
cmd->drawInfo.vertexCount = _vertexCount;
|
||||
cmd->drawInfo.firstVertex = _firstVertex;
|
||||
cmd->drawInfo.indexCount = _indexCount;
|
||||
cmd->drawInfo.firstIndex = _firstIndex;
|
||||
cmd->drawInfo.vertexOffset = _vertexOffset;
|
||||
cmd->drawInfo.instanceCount = _instanceCount;
|
||||
cmd->drawInfo.firstInstance = _firstInstance;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -21,8 +21,8 @@ bool GLES2Texture::initialize(const TextureInfo &info) {
|
||||
_width = info.width;
|
||||
_height = info.height;
|
||||
_depth = info.depth;
|
||||
_arrayLayer = info.arrayLayer;
|
||||
_mipLevel = info.mipLevel;
|
||||
_layerCount = info.layerCount;
|
||||
_levelCount = info.levelCount;
|
||||
_samples = info.samples;
|
||||
_flags = info.flags;
|
||||
_size = FormatSize(_format, _width, _height, _depth);
|
||||
@@ -83,8 +83,8 @@ bool GLES2Texture::initialize(const TextureInfo &info) {
|
||||
_gpuTexture->height = _height;
|
||||
_gpuTexture->depth = _depth;
|
||||
_gpuTexture->size = _size;
|
||||
_gpuTexture->arrayLayer = _arrayLayer;
|
||||
_gpuTexture->mipLevel = _mipLevel;
|
||||
_gpuTexture->arrayLayer = _layerCount;
|
||||
_gpuTexture->mipLevel = _levelCount;
|
||||
_gpuTexture->samples = _samples;
|
||||
_gpuTexture->flags = _flags;
|
||||
_gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height);
|
||||
|
||||
@@ -156,11 +156,11 @@ void GLES3CommandBuffer::setBlendConstants(const Color &constants) {
|
||||
}
|
||||
|
||||
void GLES3CommandBuffer::setDepthBound(float min_bounds, float max_bounds) {
|
||||
if (math::IsNotEqualF(_curDepthBounds.min_bounds, min_bounds) ||
|
||||
math::IsNotEqualF(_curDepthBounds.max_bounds, max_bounds)) {
|
||||
if (math::IsNotEqualF(_curDepthBounds.minBounds, min_bounds) ||
|
||||
math::IsNotEqualF(_curDepthBounds.maxBounds, max_bounds)) {
|
||||
|
||||
_curDepthBounds.min_bounds = min_bounds;
|
||||
_curDepthBounds.max_bounds = max_bounds;
|
||||
_curDepthBounds.minBounds = min_bounds;
|
||||
_curDepthBounds.maxBounds = max_bounds;
|
||||
_isStateInvalid = true;
|
||||
}
|
||||
}
|
||||
@@ -178,11 +178,11 @@ void GLES3CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) {
|
||||
void GLES3CommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint mask) {
|
||||
if ((_curStencilCompareMask.face != face) ||
|
||||
(_curStencilCompareMask.refrence != ref) ||
|
||||
(_curStencilCompareMask.compare_mask != mask)) {
|
||||
(_curStencilCompareMask.compareMask != mask)) {
|
||||
|
||||
_curStencilCompareMask.face = face;
|
||||
_curStencilCompareMask.refrence = ref;
|
||||
_curStencilCompareMask.compare_mask = mask;
|
||||
_curStencilCompareMask.compareMask = mask;
|
||||
_isStateInvalid = true;
|
||||
}
|
||||
}
|
||||
@@ -242,19 +242,18 @@ void GLES3CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint
|
||||
}
|
||||
}
|
||||
|
||||
void GLES3CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) {
|
||||
void GLES3CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) {
|
||||
if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) ||
|
||||
(_type == CommandBufferType::SECONDARY)) {
|
||||
|
||||
GLES3GPUBuffer *gpuBuffer = ((GLES3Buffer *)src)->gpuBuffer();
|
||||
GLES3GPUTexture *gpuTexture = ((GLES3Texture *)dst)->gpuTexture();
|
||||
if (gpuBuffer && gpuTexture) {
|
||||
GLES3GPUTexture *gpuTexture = ((GLES3Texture *)texture)->gpuTexture();
|
||||
if (gpuTexture) {
|
||||
GLES3CmdCopyBufferToTexture *cmd = _gles3Allocator->copyBufferToTextureCmdPool.alloc();
|
||||
cmd->gpuBuffer = gpuBuffer;
|
||||
cmd->gpuTexture = gpuTexture;
|
||||
cmd->dst_layout = layout;
|
||||
cmd->buffers.resize(buffers.size());
|
||||
cmd->regions.resize(regions.size());
|
||||
for (uint i = 0; i < static_cast<uint>(regions.size()); ++i) {
|
||||
cmd->buffers[i] = buffers[i];
|
||||
cmd->regions[i] = regions[i];
|
||||
}
|
||||
|
||||
@@ -262,11 +261,11 @@ void GLES3CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureL
|
||||
_cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE);
|
||||
}
|
||||
} else {
|
||||
CC_LOG_ERROR("Command 'copyBufferToTexture' must be recorded outside a render pass.");
|
||||
CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass.");
|
||||
}
|
||||
}
|
||||
|
||||
void GLES3CommandBuffer::execute(const vector<CommandBuffer *> &cmd_buffs, uint32_t count) {
|
||||
void GLES3CommandBuffer::execute(const CommandBufferList &cmd_buffs, uint32_t count) {
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
GLES3CommandBuffer *cmd_buff = (GLES3CommandBuffer *)cmd_buffs[i];
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ public:
|
||||
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 copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) override;
|
||||
virtual void execute(const vector<CommandBuffer *> &cmd_buffs, uint32_t count) override;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override;
|
||||
virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override;
|
||||
|
||||
private:
|
||||
void BindStates();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "GLES3Std.h"
|
||||
|
||||
#include "GLES3Commands.h"
|
||||
#include "GLES3Context.h"
|
||||
#include "GLES3Device.h"
|
||||
#include "GLES3StateCache.h"
|
||||
#include "GLES3Context.h"
|
||||
|
||||
#define BUFFER_OFFSET(idx) (static_cast<char *>(0) + (idx))
|
||||
|
||||
@@ -1972,43 +1972,43 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
|
||||
switch (cmd->stencilCompareMask.face) {
|
||||
case StencilFace::FRONT:
|
||||
if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask)) {
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask)) {
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask;
|
||||
}
|
||||
break;
|
||||
case StencilFace::BACK:
|
||||
if ((cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) {
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) {
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask;
|
||||
}
|
||||
break;
|
||||
case StencilFace::ALL:
|
||||
if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask) ||
|
||||
(cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask) ||
|
||||
(cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) ||
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) {
|
||||
(cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) {
|
||||
glStencilFuncSeparate(GL_FRONT,
|
||||
GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
glStencilFuncSeparate(GL_BACK,
|
||||
GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack],
|
||||
cmd->stencilCompareMask.refrence,
|
||||
cmd->stencilCompareMask.compare_mask);
|
||||
cmd->stencilCompareMask.compareMask);
|
||||
cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask;
|
||||
cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask;
|
||||
cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2025,19 +2025,19 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
|
||||
GLES3CmdDraw *cmd = cmdPackage->drawCmds[cmdIdx];
|
||||
if (gpuInputAssembler && gpuPipelineState) {
|
||||
if (!gpuInputAssembler->gpuIndirectBuffer) {
|
||||
if (gpuInputAssembler->gpuIndexBuffer && cmd->draw_info.indexCount >= 0) {
|
||||
if (gpuInputAssembler->gpuIndexBuffer && cmd->drawInfo.indexCount >= 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += cmd->draw_info.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->draw_info.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->draw_info.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
offset += cmd->drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
glDrawElementsInstanced(glPrimitive, cmd->draw_info.indexCount, gpuInputAssembler->glIndexType, offset, cmd->draw_info.instanceCount);
|
||||
glDrawElementsInstanced(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount);
|
||||
}
|
||||
} else {
|
||||
if (cmd->draw_info.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount);
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount);
|
||||
} else {
|
||||
glDrawArraysInstanced(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount, cmd->draw_info.instanceCount);
|
||||
glDrawArraysInstanced(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount, cmd->drawInfo.instanceCount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -2070,7 +2070,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
|
||||
}
|
||||
case GFXCmdType::COPY_BUFFER_TO_TEXTURE: {
|
||||
GLES3CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx];
|
||||
GLES3CmdFuncCopyBuffersToTexture(device, &(cmd->gpuBuffer->buffer), cmd->gpuTexture, cmd->regions);
|
||||
GLES3CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2080,7 +2080,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
|
||||
}
|
||||
}
|
||||
|
||||
void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) {
|
||||
void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList &buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) {
|
||||
GLuint &glTexture = device->stateCache->glTextures[device->stateCache->texUint];
|
||||
if (glTexture != gpuTexture->glTexture) {
|
||||
glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture);
|
||||
@@ -2098,7 +2098,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe
|
||||
const BufferTextureCopy ®ion = regions[i];
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1);
|
||||
glCompressedTexSubImage2D(GL_TEXTURE_2D,
|
||||
@@ -2133,7 +2133,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe
|
||||
for (uint z = region.texSubres.baseArrayLayer; z < layerCount; ++z) {
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1);
|
||||
glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY,
|
||||
@@ -2169,7 +2169,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
d = region.texExtent.depth;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1);
|
||||
glCompressedTexSubImage3D(GL_TEXTURE_3D,
|
||||
@@ -2205,7 +2205,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe
|
||||
for (f = region.texSubres.baseArrayLayer; f < face_count; ++f) {
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
uint8_t *buff = buffers[n++];
|
||||
const uint8_t *buff = buffers[n++];
|
||||
if (isCompressed) {
|
||||
GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1);
|
||||
glCompressedTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f,
|
||||
|
||||
@@ -15,8 +15,8 @@ struct GLES3DepthBias {
|
||||
};
|
||||
|
||||
struct GLES3DepthBounds {
|
||||
float min_bounds = 0.0f;
|
||||
float max_bounds = 0.0f;
|
||||
float minBounds = 0.0f;
|
||||
float maxBounds = 0.0f;
|
||||
};
|
||||
|
||||
struct GLES3StencilWriteMask {
|
||||
@@ -27,7 +27,7 @@ struct GLES3StencilWriteMask {
|
||||
struct GLES3StencilCompareMask {
|
||||
StencilFace face = StencilFace::FRONT;
|
||||
int refrence = 0;
|
||||
uint compare_mask = 0;
|
||||
uint compareMask = 0;
|
||||
};
|
||||
|
||||
struct GLES3TextureSubres {
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
GLES3GPUPipelineState *gpuPipelineState = nullptr;
|
||||
GLES3GPUBindingLayout *gpuBindingLayout = nullptr;
|
||||
GLES3GPUInputAssembler *gpuInputAssembler = nullptr;
|
||||
uint8_t state_flags[(int)GLES3State::COUNT] = {0};
|
||||
uint8_t stateFlags[(int)GLES3State::COUNT] = {0};
|
||||
Viewport viewport;
|
||||
Rect scissor;
|
||||
float lineWidth = 1.0f;
|
||||
@@ -98,13 +98,13 @@ public:
|
||||
gpuPipelineState = nullptr;
|
||||
gpuBindingLayout = nullptr;
|
||||
gpuInputAssembler = nullptr;
|
||||
memset(state_flags, 0, sizeof(state_flags));
|
||||
memset(stateFlags, 0, sizeof(stateFlags));
|
||||
}
|
||||
};
|
||||
|
||||
class GLES3CmdDraw : public GFXCmd {
|
||||
public:
|
||||
DrawInfo draw_info;
|
||||
DrawInfo drawInfo;
|
||||
|
||||
GLES3CmdDraw() : GFXCmd(GFXCmdType::DRAW) {}
|
||||
virtual void clear() override {}
|
||||
@@ -127,16 +127,15 @@ public:
|
||||
|
||||
class GLES3CmdCopyBufferToTexture : public GFXCmd {
|
||||
public:
|
||||
GLES3GPUBuffer *gpuBuffer = nullptr;
|
||||
GLES3GPUTexture *gpuTexture = nullptr;
|
||||
TextureLayout dst_layout;
|
||||
BufferDataList buffers;
|
||||
BufferTextureCopyList regions;
|
||||
|
||||
GLES3CmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {}
|
||||
|
||||
virtual void clear() override {
|
||||
gpuBuffer = nullptr;
|
||||
gpuTexture = nullptr;
|
||||
buffers.clear();
|
||||
regions.clear();
|
||||
}
|
||||
};
|
||||
@@ -167,7 +166,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, uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions);
|
||||
CC_GLES3_API void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList &buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions);
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace cc
|
||||
|
||||
@@ -278,9 +278,8 @@ PipelineState *GLES3Device::createPipelineState(const PipelineStateInfo &info) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GLES3Device::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) {
|
||||
|
||||
GLES3CmdFuncCopyBuffersToTexture(this, buffers.datas.data(), ((GLES3Texture *)dst)->gpuTexture(), regions);
|
||||
void GLES3Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) {
|
||||
GLES3CmdFuncCopyBuffersToTexture(this, buffers, ((GLES3Texture *)dst)->gpuTexture(), regions);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override;
|
||||
virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override;
|
||||
virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override;
|
||||
virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
|
||||
CC_INLINE GLES3CommandAllocator *cmdAllocator() const { return _cmdAllocator; }
|
||||
|
||||
|
||||
@@ -56,13 +56,13 @@ void GLES3InputAssembler::destroy() {
|
||||
}
|
||||
|
||||
void GLES3InputAssembler::ExtractCmdDraw(GLES3CmdDraw *cmd) {
|
||||
cmd->draw_info.vertexCount = _vertexCount;
|
||||
cmd->draw_info.firstVertex = _firstVertex;
|
||||
cmd->draw_info.indexCount = _indexCount;
|
||||
cmd->draw_info.firstIndex = _firstIndex;
|
||||
cmd->draw_info.vertexOffset = _vertexOffset;
|
||||
cmd->draw_info.instanceCount = _instanceCount;
|
||||
cmd->draw_info.firstInstance = _firstInstance;
|
||||
cmd->drawInfo.vertexCount = _vertexCount;
|
||||
cmd->drawInfo.firstVertex = _firstVertex;
|
||||
cmd->drawInfo.indexCount = _indexCount;
|
||||
cmd->drawInfo.firstIndex = _firstIndex;
|
||||
cmd->drawInfo.vertexOffset = _vertexOffset;
|
||||
cmd->drawInfo.instanceCount = _instanceCount;
|
||||
cmd->drawInfo.firstInstance = _firstInstance;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -21,8 +21,8 @@ bool GLES3Texture::initialize(const TextureInfo &info) {
|
||||
_width = info.width;
|
||||
_height = info.height;
|
||||
_depth = info.depth;
|
||||
_arrayLayer = info.arrayLayer;
|
||||
_mipLevel = info.mipLevel;
|
||||
_layerCount = info.layerCount;
|
||||
_levelCount = info.levelCount;
|
||||
_samples = info.samples;
|
||||
_flags = info.flags;
|
||||
_size = FormatSize(_format, _width, _height, _depth);
|
||||
@@ -83,8 +83,8 @@ bool GLES3Texture::initialize(const TextureInfo &info) {
|
||||
_gpuTexture->height = _height;
|
||||
_gpuTexture->depth = _depth;
|
||||
_gpuTexture->size = _size;
|
||||
_gpuTexture->arrayLayer = _arrayLayer;
|
||||
_gpuTexture->mipLevel = _mipLevel;
|
||||
_gpuTexture->arrayLayer = _layerCount;
|
||||
_gpuTexture->mipLevel = _levelCount;
|
||||
_gpuTexture->samples = _samples;
|
||||
_gpuTexture->flags = _flags;
|
||||
_gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height);
|
||||
|
||||
@@ -39,8 +39,8 @@ public:
|
||||
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 copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) override;
|
||||
virtual void execute(const vector<CommandBuffer *> &cmd_buffs, uint32_t count) override;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override;
|
||||
virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override;
|
||||
|
||||
private:
|
||||
void bindStates();
|
||||
|
||||
@@ -288,21 +288,20 @@ void CCMTLCommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint
|
||||
}
|
||||
}
|
||||
|
||||
void CCMTLCommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) {
|
||||
void CCMTLCommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) {
|
||||
if ((_type == CommandBufferType::PRIMARY) ||
|
||||
(_type == CommandBufferType::SECONDARY)) {
|
||||
if (src && dst) {
|
||||
auto buffer = src->getBufferView();
|
||||
static_cast<CCMTLTexture *>(dst)->update(&buffer, regions);
|
||||
if (texture) {
|
||||
static_cast<CCMTLTexture *>(texture)->update(buffers.data(), regions);
|
||||
} else {
|
||||
CC_LOG_ERROR("CCMTLCommandBuffer::copyBufferToTexture: buffer 0x%p or texture 0x%p is nullptr", (void *)src, (void *)dst);
|
||||
CC_LOG_ERROR("CCMTLCommandBuffer::copyBufferToTexture: texture is nullptr");
|
||||
}
|
||||
} else {
|
||||
CC_LOG_ERROR("CCMTLCommandBuffer::copyBufferToTexture: invalid command buffer type %d.", _type);
|
||||
}
|
||||
}
|
||||
|
||||
void CCMTLCommandBuffer::execute(const vector<CommandBuffer *> &commandBuffs, uint32_t count) {
|
||||
void CCMTLCommandBuffer::execute(const CommandBufferList &commandBuffs, uint32_t count) {
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
auto commandBuffer = static_cast<CCMTLCommandBuffer *>(commandBuffs[i]);
|
||||
_numDrawCalls += commandBuffer->_numDrawCalls;
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override;
|
||||
virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override;
|
||||
virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override;
|
||||
virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
virtual void blitBuffer(void *srcBuffer, uint offset, uint size, void *dstBuffer);
|
||||
|
||||
CC_INLINE CCMTLStateCache *getStateCache() const { return _stateCache; }
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace gfx {
|
||||
|
||||
CCMTLDevice::CCMTLDevice() {
|
||||
_clipSpaceMinZ = 0.0f;
|
||||
_clipSpaceSignY = 1.0f;
|
||||
_screenSpaceSignY = 1.0f;
|
||||
_UVSpaceSignY = 1.0f;
|
||||
}
|
||||
|
||||
@@ -257,8 +257,8 @@ PipelineState *CCMTLDevice::createPipelineState(const PipelineStateInfo &info) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CCMTLDevice::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) {
|
||||
static_cast<CCMTLTexture *>(dst)->update(buffers.datas.data(), regions);
|
||||
void CCMTLDevice::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) {
|
||||
static_cast<CCMTLTexture *>(texture)->update(buffers.data(), regions);
|
||||
}
|
||||
|
||||
void CCMTLDevice::blitBuffer(void *srcData, uint offset, uint size, void *dstBuffer) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
CC_INLINE Format getConvertedFormat() const { return _convertedFormat; }
|
||||
|
||||
private:
|
||||
void update(uint8_t *const *datas, const BufferTextureCopyList ®ions);
|
||||
void update(const uint8_t *const *datas, const BufferTextureCopyList ®ions);
|
||||
bool createMTLTexture();
|
||||
void generateMipmaps();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace cc {
|
||||
namespace gfx {
|
||||
|
||||
namespace {
|
||||
uint8_t *convertData(uint8_t *source, uint length, Format type) {
|
||||
const uint8_t *convertData(const uint8_t *source, uint length, Format type) {
|
||||
switch (type) {
|
||||
case Format::RGB8: return mu::convertRGB8ToRGBA8(source, length);
|
||||
case Format::RGB32F: return mu::convertRGB32FToRGBA32F(source, length);
|
||||
@@ -27,8 +27,8 @@ bool CCMTLTexture::initialize(const TextureInfo &info) {
|
||||
_width = info.width;
|
||||
_height = info.height;
|
||||
_depth = info.depth;
|
||||
_arrayLayer = info.arrayLayer;
|
||||
_mipLevel = info.mipLevel;
|
||||
_layerCount = info.layerCount;
|
||||
_levelCount = info.levelCount;
|
||||
_samples = info.samples;
|
||||
_flags = info.flags;
|
||||
_size = FormatSize(_format, _width, _height, _depth);
|
||||
@@ -101,8 +101,8 @@ bool CCMTLTexture::initialize(const TextureViewInfo &info) {
|
||||
_width = info.texture->getWidth();
|
||||
_height = info.texture->getHeight();
|
||||
_depth = info.texture->getDepth();
|
||||
_arrayLayer = info.texture->getArrayLayer();
|
||||
_mipLevel = info.texture->getMipLevel();
|
||||
_layerCount = info.texture->getLayerCount();
|
||||
_levelCount = info.texture->getLevelCount();
|
||||
_samples = info.texture->getSamples();
|
||||
_flags = info.texture->getFlags();
|
||||
_size = info.texture->getSize();
|
||||
@@ -138,7 +138,7 @@ bool CCMTLTexture::createMTLTexture() {
|
||||
switch (mtlTextureType) {
|
||||
case MTLTextureType2D:
|
||||
case MTLTextureType2DArray:
|
||||
//No need to set mipmapped flag since mipmapLevelCount was explicty set via `_mipLevel`.
|
||||
//No need to set mipmapped flag since mipmapLevelCount was explicty set via `_levelCount`.
|
||||
descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:mtlFormat
|
||||
width:_width
|
||||
height:_height
|
||||
@@ -160,8 +160,8 @@ bool CCMTLTexture::createMTLTexture() {
|
||||
descriptor.usage = mu::toMTLTextureUsage(_usage);
|
||||
descriptor.textureType = mu::toMTLTextureType(_type);
|
||||
descriptor.sampleCount = mu::toMTLSampleCount(_samples);
|
||||
descriptor.mipmapLevelCount = _mipLevel;
|
||||
descriptor.arrayLength = _flags & TextureFlagBit::CUBEMAP ? 1 : _arrayLayer;
|
||||
descriptor.mipmapLevelCount = _levelCount;
|
||||
descriptor.arrayLength = _flags & TextureFlagBit::CUBEMAP ? 1 : _layerCount;
|
||||
|
||||
//FIXME: should change to MTLStorageModeManaged if texture usage is TextureFlags::BAKUP_BUFFER?
|
||||
if (_usage & TextureUsage::COLOR_ATTACHMENT ||
|
||||
@@ -237,7 +237,7 @@ void CCMTLTexture::resize(uint width, uint height) {
|
||||
_status = Status::SUCCESS;
|
||||
}
|
||||
|
||||
void CCMTLTexture::update(uint8_t *const *datas, const BufferTextureCopyList ®ions) {
|
||||
void CCMTLTexture::update(const uint8_t *const *datas, const BufferTextureCopyList ®ions) {
|
||||
if (!_mtlTexture)
|
||||
return;
|
||||
|
||||
@@ -252,8 +252,8 @@ void CCMTLTexture::update(uint8_t *const *datas, const BufferTextureCopyList &re
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
|
||||
uint8_t *buffer = datas[n];
|
||||
uint8_t *convertedData = convertData(buffer, w * h, _format);
|
||||
const uint8_t *buffer = datas[n];
|
||||
const uint8_t *convertedData = convertData(buffer, w * h, _format);
|
||||
MTLRegion mtlRegion = {{(uint)region.texOffset.x, (uint)region.texOffset.y, (uint)region.texOffset.z}, {w, h, 1}};
|
||||
[_mtlTexture replaceRegion:mtlRegion
|
||||
mipmapLevel:region.texSubres.mipLevel
|
||||
@@ -274,8 +274,8 @@ void CCMTLTexture::update(uint8_t *const *datas, const BufferTextureCopyList &re
|
||||
for (; layer < layerCount; layer++) {
|
||||
w = region.texExtent.width;
|
||||
h = region.texExtent.height;
|
||||
uint8_t *buffer = datas[n];
|
||||
uint8_t *convertedData = convertData(buffer, w * h, _format);
|
||||
const uint8_t *buffer = datas[n];
|
||||
const uint8_t *convertedData = convertData(buffer, w * h, _format);
|
||||
MTLRegion mtlRegion = {{(uint)region.texOffset.x, (uint)region.texOffset.y, (uint)region.texOffset.z}, {w, h, 1}};
|
||||
[_mtlTexture replaceRegion:mtlRegion
|
||||
mipmapLevel:region.texSubres.mipLevel
|
||||
|
||||
@@ -40,8 +40,8 @@ MTLSamplerBorderColor toMTLSamplerBorderColor(const Color &);
|
||||
MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(Filter);
|
||||
MTLSamplerMipFilter toMTLSamplerMipFilter(Filter);
|
||||
String compileGLSLShader2Msl(const String &src, ShaderType shaderType, Device* device, unordered_map<uint, uint> &samplerBindings);
|
||||
uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length);
|
||||
uint8_t *convertRGB32FToRGBA32F(uint8_t *source, uint length);
|
||||
const uint8_t *convertRGB8ToRGBA8(const uint8_t *source, uint length);
|
||||
const uint8_t *convertRGB32FToRGBA32F(const uint8_t *source, uint length);
|
||||
NSUInteger highestSupportedFeatureSet(id<MTLDevice> device);
|
||||
uint getGPUFamily(MTLFeatureSet featureSet);
|
||||
uint getMaxVertexAttributes(uint family);
|
||||
|
||||
@@ -591,7 +591,7 @@ String compileGLSLShader2Msl(const String &src,
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length) {
|
||||
const uint8_t *convertRGB8ToRGBA8(const uint8_t *source, uint length) {
|
||||
uint finalLength = length * 4;
|
||||
uint8 *out = (uint8 *)CC_MALLOC(finalLength);
|
||||
if (!out) {
|
||||
@@ -599,7 +599,7 @@ uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length) {
|
||||
return source;
|
||||
}
|
||||
|
||||
uint8_t *src = source;
|
||||
const uint8_t *src = source;
|
||||
uint8_t *dst = out;
|
||||
for (uint i = 0; i < length; ++i) {
|
||||
*dst++ = *src++;
|
||||
@@ -611,7 +611,7 @@ uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length) {
|
||||
return out;
|
||||
}
|
||||
|
||||
uint8_t *convertRGB32FToRGBA32F(uint8_t *source, uint length) {
|
||||
const uint8_t *convertRGB32FToRGBA32F(const uint8_t *source, uint length) {
|
||||
uint finalLength = length * sizeof(float) * 4;
|
||||
uint8 *out = (uint8 *)CC_MALLOC(finalLength);
|
||||
if (!out) {
|
||||
@@ -619,7 +619,7 @@ uint8_t *convertRGB32FToRGBA32F(uint8_t *source, uint length) {
|
||||
return source;
|
||||
}
|
||||
|
||||
float *src = reinterpret_cast<float *>(source);
|
||||
const float *src = reinterpret_cast<const float *>(source);
|
||||
float *dst = reinterpret_cast<float *>(out);
|
||||
for (uint i = 0; i < length; ++i) {
|
||||
*dst++ = *src++;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "VKStd.h"
|
||||
|
||||
#include "VKBuffer.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -50,7 +51,7 @@ bool CCVKBuffer::initialize(const BufferInfo &info) {
|
||||
|
||||
void CCVKBuffer::destroy() {
|
||||
if (_gpuBuffer) {
|
||||
CCVKCmdFuncDestroyBuffer((CCVKDevice *)_device, _gpuBuffer);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer);
|
||||
_device->getMemoryStatus().bufferSize -= _size;
|
||||
CC_DELETE(_gpuBuffer);
|
||||
_gpuBuffer = nullptr;
|
||||
@@ -74,7 +75,8 @@ void CCVKBuffer::resize(uint size) {
|
||||
MemoryStatus &status = _device->getMemoryStatus();
|
||||
_gpuBuffer->size = _size;
|
||||
_gpuBuffer->count = _count;
|
||||
CCVKCmdFuncResizeBuffer((CCVKDevice *)_device, _gpuBuffer);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer);
|
||||
CCVKCmdFuncCreateBuffer((CCVKDevice *)_device, _gpuBuffer);
|
||||
status.bufferSize -= oldSize;
|
||||
status.bufferSize += _size;
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ void CCVKCommandBuffer::draw(InputAssembler *ia) {
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::execute(const vector<CommandBuffer *> &cmdBuffs, uint count) {
|
||||
void CCVKCommandBuffer::execute(const CommandBufferList &cmdBuffs, uint count) {
|
||||
if (!count) {
|
||||
return;
|
||||
}
|
||||
@@ -431,7 +431,7 @@ void CCVKCommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint o
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) {
|
||||
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();
|
||||
@@ -439,7 +439,7 @@ void CCVKCommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLa
|
||||
//vkCmdCopyBufferToImage(_gpuCommandBuffer->vkCommandBuffer, gpuBuffer->vkBuffer, gpuTexture->vkImage, MapVkImageLayout(layout),
|
||||
// regions.size(), regions.data());
|
||||
} else {
|
||||
CC_LOG_ERROR("Command 'copyBufferToTexture' must be recorded outside a render pass.");
|
||||
CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
void setStencilCompareMask(StencilFace face, int reference, uint mask);
|
||||
void draw(InputAssembler *ia);
|
||||
void updateBuffer(Buffer *buff, void *data, uint size, uint offset);
|
||||
void copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions);
|
||||
void execute(const vector<CommandBuffer *> &cmd_buffs, uint count);
|
||||
void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions);
|
||||
void execute(const CommandBufferList &cmd_buffs, uint count);
|
||||
|
||||
CCVKGPUCommandBuffer *gpuCommandBuffer() const { return _gpuCommandBuffer; }
|
||||
|
||||
|
||||
@@ -36,126 +36,6 @@ void insertVkDynamicStates(vector<VkDynamicState> &out, const vector<DynamicStat
|
||||
}
|
||||
}
|
||||
|
||||
void beginOneTimeCommands(CCVKDevice *device, CCVKGPUCommandBuffer *cmdBuff) {
|
||||
cmdBuff->level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
cmdBuff->queueFamilyIndex = ((CCVKQueue *)device->getQueue())->gpuQueue()->queueFamilyIndex;
|
||||
device->gpuCommandBufferPool()->request(cmdBuff);
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
VK_CHECK(vkBeginCommandBuffer(cmdBuff->vkCommandBuffer, &beginInfo));
|
||||
}
|
||||
|
||||
void endOneTimeCommands(CCVKDevice *device, CCVKGPUCommandBuffer *cmdBuff) {
|
||||
VK_CHECK(vkEndCommandBuffer(cmdBuff->vkCommandBuffer));
|
||||
|
||||
VkFence fence = device->gpuFencePool()->alloc();
|
||||
const CCVKGPUQueue *queue = ((CCVKQueue *)device->getQueue())->gpuQueue();
|
||||
VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &cmdBuff->vkCommandBuffer;
|
||||
VK_CHECK(vkQueueSubmit(queue->vkQueue, 1, &submitInfo, fence));
|
||||
VK_CHECK(vkWaitForFences(device->gpuDevice()->vkDevice, 1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT));
|
||||
device->gpuCommandBufferPool()->yield(cmdBuff);
|
||||
}
|
||||
|
||||
void insertImageMemoryBarrior(
|
||||
VkCommandBuffer cmdBuffer,
|
||||
VkImage image,
|
||||
VkAccessFlags srcAccessMask,
|
||||
VkAccessFlags dstAccessMask,
|
||||
VkImageLayout oldImageLayout,
|
||||
VkImageLayout newImageLayout,
|
||||
VkPipelineStageFlags srcStageMask,
|
||||
VkPipelineStageFlags dstStageMask,
|
||||
VkImageSubresourceRange subresourceRange) {
|
||||
VkImageMemoryBarrier barrier{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
|
||||
barrier.image = image;
|
||||
barrier.srcAccessMask = srcAccessMask;
|
||||
barrier.dstAccessMask = dstAccessMask;
|
||||
barrier.oldLayout = oldImageLayout;
|
||||
barrier.newLayout = newImageLayout;
|
||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.subresourceRange = subresourceRange;
|
||||
|
||||
vkCmdPipelineBarrier(cmdBuffer,
|
||||
srcStageMask, dstStageMask, 0,
|
||||
0, nullptr,
|
||||
0, nullptr,
|
||||
1, &barrier);
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) {
|
||||
size_t colorAttachmentCount = gpuRenderPass->colorAttachments.size();
|
||||
vector<VkAttachmentDescription> attachmentDescriptions(colorAttachmentCount + 1);
|
||||
gpuRenderPass->clearValues.resize(colorAttachmentCount + 1);
|
||||
for (size_t i = 0u; i < colorAttachmentCount; i++) {
|
||||
const ColorAttachment &attachment = gpuRenderPass->colorAttachments[i];
|
||||
const VkImageLayout beginLayout = MapVkImageLayout(attachment.beginLayout);
|
||||
const VkImageLayout endLayout = MapVkImageLayout(attachment.endLayout);
|
||||
const VkAccessFlags beginAccessMask = MapVkAccessFlags(attachment.beginLayout);
|
||||
const VkAccessFlags endAccessMask = MapVkAccessFlags(attachment.endLayout);
|
||||
attachmentDescriptions[i].format = MapVkFormat(attachment.format);
|
||||
attachmentDescriptions[i].samples = MapVkSampleCount(attachment.sampleCount);
|
||||
attachmentDescriptions[i].loadOp = MapVkLoadOp(attachment.loadOp);
|
||||
attachmentDescriptions[i].storeOp = MapVkStoreOp(attachment.storeOp);
|
||||
attachmentDescriptions[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachmentDescriptions[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachmentDescriptions[i].initialLayout = beginLayout;
|
||||
attachmentDescriptions[i].finalLayout = endLayout;
|
||||
}
|
||||
const DepthStencilAttachment &depthStencilAttachment = gpuRenderPass->depthStencilAttachment;
|
||||
const VkImageLayout beginLayout = MapVkImageLayout(depthStencilAttachment.beginLayout);
|
||||
const VkImageLayout endLayout = MapVkImageLayout(depthStencilAttachment.endLayout);
|
||||
const VkAccessFlags beginAccessMask = MapVkAccessFlags(depthStencilAttachment.beginLayout);
|
||||
const VkAccessFlags endAccessMask = MapVkAccessFlags(depthStencilAttachment.endLayout);
|
||||
const VkImageAspectFlags aspectMask = GFX_FORMAT_INFOS[(uint)depthStencilAttachment.format].hasStencil ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
attachmentDescriptions[colorAttachmentCount].format = MapVkFormat(depthStencilAttachment.format);
|
||||
attachmentDescriptions[colorAttachmentCount].samples = MapVkSampleCount(depthStencilAttachment.sampleCount);
|
||||
attachmentDescriptions[colorAttachmentCount].loadOp = MapVkLoadOp(depthStencilAttachment.depthLoadOp);
|
||||
attachmentDescriptions[colorAttachmentCount].storeOp = MapVkStoreOp(depthStencilAttachment.depthStoreOp);
|
||||
attachmentDescriptions[colorAttachmentCount].stencilLoadOp = MapVkLoadOp(depthStencilAttachment.stencilLoadOp);
|
||||
attachmentDescriptions[colorAttachmentCount].stencilStoreOp = MapVkStoreOp(depthStencilAttachment.stencilStoreOp);
|
||||
attachmentDescriptions[colorAttachmentCount].initialLayout = beginLayout;
|
||||
attachmentDescriptions[colorAttachmentCount].finalLayout = endLayout;
|
||||
|
||||
size_t subpassCount = gpuRenderPass->subPasses.size();
|
||||
vector<VkSubpassDescription> subpassDescriptions(1, {VK_PIPELINE_BIND_POINT_GRAPHICS});
|
||||
vector<VkAttachmentReference> attachmentReferences;
|
||||
if (subpassCount) { // pass on user-specified subpasses
|
||||
subpassDescriptions.resize(subpassCount);
|
||||
for (size_t i = 0u; i < subpassCount; i++) {
|
||||
const SubPass &subpass = gpuRenderPass->subPasses[i];
|
||||
subpassDescriptions[i].pipelineBindPoint = MapVkPipelineBindPoint(subpass.bindPoint);
|
||||
// TODO
|
||||
}
|
||||
} else { // generate a default subpass from attachment info
|
||||
for (size_t i = 0u; i < colorAttachmentCount; i++) {
|
||||
attachmentReferences.push_back({(uint32_t)i, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL});
|
||||
}
|
||||
attachmentReferences.push_back({(uint32_t)colorAttachmentCount, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL});
|
||||
subpassDescriptions[0].colorAttachmentCount = attachmentReferences.size() - 1;
|
||||
subpassDescriptions[0].pColorAttachments = attachmentReferences.data();
|
||||
subpassDescriptions[0].pDepthStencilAttachment = &attachmentReferences.back();
|
||||
}
|
||||
|
||||
VkRenderPassCreateInfo renderPassCreateInfo{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO};
|
||||
renderPassCreateInfo.attachmentCount = attachmentDescriptions.size();
|
||||
renderPassCreateInfo.pAttachments = attachmentDescriptions.data();
|
||||
renderPassCreateInfo.subpassCount = subpassDescriptions.size();
|
||||
renderPassCreateInfo.pSubpasses = subpassDescriptions.data();
|
||||
|
||||
VK_CHECK(vkCreateRenderPass(device->gpuDevice()->vkDevice, &renderPassCreateInfo, nullptr, &gpuRenderPass->vkRenderPass));
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) {
|
||||
if (gpuRenderPass->vkRenderPass != VK_NULL_HANDLE) {
|
||||
vkDestroyRenderPass(device->gpuDevice()->vkDevice, gpuRenderPass->vkRenderPass, nullptr);
|
||||
gpuRenderPass->vkRenderPass = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) {
|
||||
uint queueType = 0u;
|
||||
VkBool32 needPresentable = VK_FALSE;
|
||||
@@ -212,77 +92,6 @@ void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) {
|
||||
gpuBuffer->startOffset = 0; // we are creating one VkBuffer each for now
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) {
|
||||
if (gpuBuffer->vmaAllocation) {
|
||||
vmaDestroyBuffer(device->gpuDevice()->memoryAllocator, gpuBuffer->vkBuffer, gpuBuffer->vmaAllocation);
|
||||
gpuBuffer->buffer = VK_NULL_HANDLE;
|
||||
gpuBuffer->vmaAllocation = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncResizeBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) {
|
||||
CCVKCmdFuncDestroyBuffer(device, gpuBuffer);
|
||||
CCVKCmdFuncCreateBuffer(device, gpuBuffer);
|
||||
}
|
||||
|
||||
void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size) {
|
||||
if (!gpuBuffer) return;
|
||||
|
||||
const void *dataToUpload = nullptr;
|
||||
size_t sizeToUpload = 0u;
|
||||
|
||||
if (gpuBuffer->usage & BufferUsageBit::INDIRECT) {
|
||||
size_t drawInfoCount = size / sizeof(DrawInfo);
|
||||
DrawInfo *drawInfo = static_cast<DrawInfo *>(buffer);
|
||||
if (drawInfoCount > 0) {
|
||||
if (drawInfo->indexCount) {
|
||||
for (size_t i = 0; i < drawInfoCount; i++) {
|
||||
gpuBuffer->indexedIndirectCmds[i].indexCount = drawInfo->indexCount;
|
||||
gpuBuffer->indexedIndirectCmds[i].instanceCount = std::max(drawInfo->instanceCount, 1u);
|
||||
gpuBuffer->indexedIndirectCmds[i].firstIndex = drawInfo->firstIndex;
|
||||
gpuBuffer->indexedIndirectCmds[i].vertexOffset = drawInfo->vertexOffset;
|
||||
gpuBuffer->indexedIndirectCmds[i].firstInstance = drawInfo->firstInstance;
|
||||
drawInfo++;
|
||||
}
|
||||
dataToUpload = gpuBuffer->indexedIndirectCmds.data();
|
||||
sizeToUpload = drawInfoCount * sizeof(VkDrawIndexedIndirectCommand);
|
||||
gpuBuffer->isDrawIndirectByIndex = true;
|
||||
} else {
|
||||
for (size_t i = 0; i < drawInfoCount; i++) {
|
||||
gpuBuffer->indirectCmds[i].vertexCount = drawInfo->vertexCount;
|
||||
gpuBuffer->indirectCmds[i].instanceCount = drawInfo->instanceCount;
|
||||
gpuBuffer->indirectCmds[i].firstVertex = drawInfo->firstVertex;
|
||||
gpuBuffer->indirectCmds[i].firstInstance = drawInfo->firstInstance;
|
||||
drawInfo++;
|
||||
}
|
||||
dataToUpload = gpuBuffer->indirectCmds.data();
|
||||
sizeToUpload = drawInfoCount * sizeof(VkDrawIndirectCommand);
|
||||
gpuBuffer->isDrawIndirectByIndex = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dataToUpload = buffer;
|
||||
sizeToUpload = size;
|
||||
}
|
||||
|
||||
if (gpuBuffer->mappedData) {
|
||||
memcpy(gpuBuffer->mappedData + offset, dataToUpload, sizeToUpload);
|
||||
} else {
|
||||
const CCVKGPUBuffer *stagingBuffer = device->stagingBuffer()->gpuBuffer();
|
||||
if (stagingBuffer->size < sizeToUpload) device->stagingBuffer()->resize(nextPowerOf2(sizeToUpload));
|
||||
|
||||
memcpy(stagingBuffer->mappedData, dataToUpload, sizeToUpload);
|
||||
|
||||
CCVKGPUCommandBuffer cmdBuff;
|
||||
beginOneTimeCommands(device, &cmdBuff);
|
||||
|
||||
VkBufferCopy region{0, gpuBuffer->startOffset + offset, sizeToUpload};
|
||||
vkCmdCopyBuffer(cmdBuff.vkCommandBuffer, stagingBuffer->vkBuffer, gpuBuffer->vkBuffer, 1, ®ion);
|
||||
|
||||
endOneTimeCommands(device, &cmdBuff);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) {
|
||||
if (!gpuTexture->size) return;
|
||||
|
||||
@@ -306,8 +115,8 @@ void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) {
|
||||
createInfo.imageType = MapVkImageType(gpuTexture->type);
|
||||
createInfo.format = format;
|
||||
createInfo.extent = {gpuTexture->width, gpuTexture->height, gpuTexture->depth};
|
||||
createInfo.mipLevels = gpuTexture->mipLevel;
|
||||
createInfo.arrayLayers = gpuTexture->arrayLayer;
|
||||
createInfo.mipLevels = gpuTexture->mipLevels;
|
||||
createInfo.arrayLayers = gpuTexture->arrayLayers;
|
||||
createInfo.samples = MapVkSampleCount(gpuTexture->samples);
|
||||
createInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
createInfo.usage = usageFlags;
|
||||
@@ -320,44 +129,10 @@ void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) {
|
||||
VK_CHECK(vmaCreateImage(device->gpuDevice()->memoryAllocator, &createInfo, &allocInfo, &gpuTexture->vkImage, &gpuTexture->vmaAllocation, &res));
|
||||
//CC_LOG_DEBUG("Allocated texture: %llu %llx %llx %llu %x", res.size, gpuTexture->vkImage, res.deviceMemory, res.offset, res.pMappedData);
|
||||
|
||||
gpuTexture->currentLayout = MapVkImageLayout(gpuTexture->usage, gpuTexture->format);
|
||||
gpuTexture->layout = MapVkImageLayout(gpuTexture->usage, gpuTexture->format);
|
||||
gpuTexture->accessMask = MapVkAccessFlags(gpuTexture->usage, gpuTexture->format);
|
||||
gpuTexture->aspectMask = MapVkImageAspectFlags(gpuTexture->format);
|
||||
gpuTexture->targetStage = MapVkPipelineStageFlags(gpuTexture->usage);
|
||||
|
||||
if (gpuTexture->currentLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
|
||||
CCVKGPUCommandBuffer cmfBuff;
|
||||
beginOneTimeCommands(device, &cmfBuff);
|
||||
|
||||
VkImageSubresourceRange subresourceRange{};
|
||||
subresourceRange.aspectMask = gpuTexture->aspectMask;
|
||||
subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||
subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
insertImageMemoryBarrior(cmfBuff.vkCommandBuffer,
|
||||
gpuTexture->vkImage,
|
||||
0,
|
||||
gpuTexture->accessMask,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
gpuTexture->currentLayout,
|
||||
VK_PIPELINE_STAGE_HOST_BIT,
|
||||
gpuTexture->targetStage,
|
||||
subresourceRange);
|
||||
|
||||
endOneTimeCommands(device, &cmfBuff);
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) {
|
||||
if (gpuTexture->vmaAllocation) {
|
||||
vmaDestroyImage(device->gpuDevice()->memoryAllocator, gpuTexture->vkImage, gpuTexture->vmaAllocation);
|
||||
gpuTexture->vkImage = VK_NULL_HANDLE;
|
||||
gpuTexture->vmaAllocation = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncResizeTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) {
|
||||
CCVKCmdFuncDestroyTexture(device, gpuTexture);
|
||||
CCVKCmdFuncCreateTexture(device, gpuTexture);
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView) {
|
||||
@@ -370,17 +145,77 @@ void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTex
|
||||
createInfo.subresourceRange.aspectMask = GFX_FORMAT_INFOS[(uint)gpuTextureView->format].hasDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
createInfo.subresourceRange.baseMipLevel = gpuTextureView->baseLevel;
|
||||
createInfo.subresourceRange.levelCount = gpuTextureView->levelCount;
|
||||
createInfo.subresourceRange.baseArrayLayer = 0;
|
||||
createInfo.subresourceRange.layerCount = gpuTextureView->gpuTexture->arrayLayer;
|
||||
createInfo.subresourceRange.baseArrayLayer = gpuTextureView->baseLayer;
|
||||
createInfo.subresourceRange.layerCount = gpuTextureView->layerCount;
|
||||
|
||||
VK_CHECK(vkCreateImageView(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuTextureView->vkImageView));
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView) {
|
||||
if (gpuTextureView->vkImageView != VK_NULL_HANDLE) {
|
||||
vkDestroyImageView(device->gpuDevice()->vkDevice, gpuTextureView->vkImageView, nullptr);
|
||||
gpuTextureView->vkImageView = VK_NULL_HANDLE;
|
||||
void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) {
|
||||
const size_t colorAttachmentCount = gpuRenderPass->colorAttachments.size();
|
||||
const size_t hasDepth = gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN ? 1 : 0;
|
||||
vector<VkAttachmentDescription> attachmentDescriptions(colorAttachmentCount + hasDepth);
|
||||
gpuRenderPass->clearValues.resize(colorAttachmentCount + hasDepth);
|
||||
for (size_t i = 0u; i < colorAttachmentCount; i++) {
|
||||
const ColorAttachment &attachment = gpuRenderPass->colorAttachments[i];
|
||||
const VkImageLayout beginLayout = MapVkImageLayout(attachment.beginLayout);
|
||||
const VkImageLayout endLayout = MapVkImageLayout(attachment.endLayout);
|
||||
const VkAccessFlags beginAccessMask = MapVkAccessFlags(attachment.beginLayout);
|
||||
const VkAccessFlags endAccessMask = MapVkAccessFlags(attachment.endLayout);
|
||||
attachmentDescriptions[i].format = MapVkFormat(attachment.format);
|
||||
attachmentDescriptions[i].samples = MapVkSampleCount(attachment.sampleCount);
|
||||
attachmentDescriptions[i].loadOp = MapVkLoadOp(attachment.loadOp);
|
||||
attachmentDescriptions[i].storeOp = MapVkStoreOp(attachment.storeOp);
|
||||
attachmentDescriptions[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
attachmentDescriptions[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
attachmentDescriptions[i].initialLayout = beginLayout;
|
||||
attachmentDescriptions[i].finalLayout = endLayout;
|
||||
}
|
||||
if (hasDepth) {
|
||||
const DepthStencilAttachment &depthStencilAttachment = gpuRenderPass->depthStencilAttachment;
|
||||
const VkImageLayout beginLayout = MapVkImageLayout(depthStencilAttachment.beginLayout);
|
||||
const VkImageLayout endLayout = MapVkImageLayout(depthStencilAttachment.endLayout);
|
||||
const VkAccessFlags beginAccessMask = MapVkAccessFlags(depthStencilAttachment.beginLayout);
|
||||
const VkAccessFlags endAccessMask = MapVkAccessFlags(depthStencilAttachment.endLayout);
|
||||
const bool hasStencil = GFX_FORMAT_INFOS[(uint)depthStencilAttachment.format].hasStencil;
|
||||
const VkImageAspectFlags aspectMask = hasStencil ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
attachmentDescriptions[colorAttachmentCount].format = MapVkFormat(depthStencilAttachment.format);
|
||||
attachmentDescriptions[colorAttachmentCount].samples = MapVkSampleCount(depthStencilAttachment.sampleCount);
|
||||
attachmentDescriptions[colorAttachmentCount].loadOp = MapVkLoadOp(depthStencilAttachment.depthLoadOp);
|
||||
attachmentDescriptions[colorAttachmentCount].storeOp = MapVkStoreOp(depthStencilAttachment.depthStoreOp);
|
||||
attachmentDescriptions[colorAttachmentCount].stencilLoadOp = MapVkLoadOp(depthStencilAttachment.stencilLoadOp);
|
||||
attachmentDescriptions[colorAttachmentCount].stencilStoreOp = MapVkStoreOp(depthStencilAttachment.stencilStoreOp);
|
||||
attachmentDescriptions[colorAttachmentCount].initialLayout = beginLayout;
|
||||
attachmentDescriptions[colorAttachmentCount].finalLayout = endLayout;
|
||||
}
|
||||
|
||||
const size_t subpassCount = gpuRenderPass->subPasses.size();
|
||||
vector<VkSubpassDescription> subpassDescriptions(1, {VK_PIPELINE_BIND_POINT_GRAPHICS});
|
||||
vector<VkAttachmentReference> attachmentReferences;
|
||||
if (subpassCount) { // pass on user-specified subpasses
|
||||
subpassDescriptions.resize(subpassCount);
|
||||
for (size_t i = 0u; i < subpassCount; i++) {
|
||||
const SubPass &subpass = gpuRenderPass->subPasses[i];
|
||||
subpassDescriptions[i].pipelineBindPoint = MapVkPipelineBindPoint(subpass.bindPoint);
|
||||
// TODO
|
||||
}
|
||||
} else { // generate a default subpass from attachment info
|
||||
for (size_t i = 0u; i < colorAttachmentCount; i++) {
|
||||
attachmentReferences.push_back({(uint32_t)i, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL});
|
||||
}
|
||||
attachmentReferences.push_back({(uint32_t)colorAttachmentCount, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL});
|
||||
subpassDescriptions[0].colorAttachmentCount = attachmentReferences.size() - 1;
|
||||
subpassDescriptions[0].pColorAttachments = attachmentReferences.data();
|
||||
subpassDescriptions[0].pDepthStencilAttachment = &attachmentReferences.back();
|
||||
}
|
||||
|
||||
VkRenderPassCreateInfo renderPassCreateInfo{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO};
|
||||
renderPassCreateInfo.attachmentCount = attachmentDescriptions.size();
|
||||
renderPassCreateInfo.pAttachments = attachmentDescriptions.data();
|
||||
renderPassCreateInfo.subpassCount = subpassDescriptions.size();
|
||||
renderPassCreateInfo.pSubpasses = subpassDescriptions.data();
|
||||
|
||||
VK_CHECK(vkCreateRenderPass(device->gpuDevice()->vkDevice, &renderPassCreateInfo, nullptr, &gpuRenderPass->vkRenderPass));
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) {
|
||||
@@ -404,13 +239,6 @@ void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) {
|
||||
VK_CHECK(vkCreateSampler(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuSampler->vkSampler));
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroySampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) {
|
||||
if (gpuSampler->vkSampler != VK_NULL_HANDLE) {
|
||||
vkDestroySampler(device->gpuDevice()->vkDevice, gpuSampler->vkSampler, nullptr);
|
||||
gpuSampler->vkSampler = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) {
|
||||
for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) {
|
||||
vector<unsigned int> spirv = GLSL2SPIRV(stage.type, "#version 450\n" + stage.source, ((CCVKContext *)device->getContext())->minorVersion());
|
||||
@@ -463,7 +291,7 @@ void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) {
|
||||
for (size_t i = 0u; i < bindingCount; i++) {
|
||||
entries[i].dstBinding = setBindings[i].binding;
|
||||
entries[i].dstArrayElement = 0;
|
||||
entries[i].descriptorCount = 1;
|
||||
entries[i].descriptorCount = setBindings[i].descriptorCount; // TODO: texture arrays
|
||||
entries[i].descriptorType = setBindings[i].descriptorType;
|
||||
entries[i].offset = sizeof(CCVKDescriptorInfo) * i;
|
||||
entries[i].stride = sizeof(CCVKDescriptorInfo);
|
||||
@@ -489,69 +317,30 @@ void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) {
|
||||
for (size_t i = 0u; i < bindingCount; i++) {
|
||||
entries[i].dstBinding = setBindings[i].binding;
|
||||
entries[i].dstArrayElement = 0;
|
||||
entries[i].descriptorCount = 1;
|
||||
entries[i].descriptorCount = setBindings[i].descriptorCount;
|
||||
entries[i].descriptorType = setBindings[i].descriptorType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyShader(CCVKDevice *device, CCVKGPUShader *gpuShader) {
|
||||
for (uint i = 0u; i < gpuShader->vkDescriptorUpdateTemplates.size(); i++) {
|
||||
if (gpuShader->vkDescriptorUpdateTemplates[i] != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorUpdateTemplateKHR(device->gpuDevice()->vkDevice, gpuShader->vkDescriptorUpdateTemplates[i], nullptr);
|
||||
}
|
||||
}
|
||||
gpuShader->vkDescriptorUpdateTemplates.clear();
|
||||
|
||||
if (gpuShader->vkPipelineLayout != VK_NULL_HANDLE) {
|
||||
vkDestroyPipelineLayout(device->gpuDevice()->vkDevice, gpuShader->vkPipelineLayout, nullptr);
|
||||
gpuShader->vkPipelineLayout = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
for (uint i = 0u; i < gpuShader->vkDescriptorSetLayouts.size(); i++) {
|
||||
if (gpuShader->vkDescriptorSetLayouts[i] != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorSetLayout(device->gpuDevice()->vkDevice, gpuShader->vkDescriptorSetLayouts[i], nullptr);
|
||||
}
|
||||
}
|
||||
gpuShader->vkDescriptorSetLayouts.clear();
|
||||
|
||||
for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) {
|
||||
vkDestroyShaderModule(device->gpuDevice()->vkDevice, stage.vkShader, nullptr);
|
||||
stage.vkShader = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreateInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler) {
|
||||
size_t vbCount = gpuInputAssembler->gpuVertexBuffers.size();
|
||||
gpuInputAssembler->vertexBuffers.resize(vbCount);
|
||||
gpuInputAssembler->vertexBufferOffsets.resize(vbCount);
|
||||
|
||||
for (size_t i = 0u; i < vbCount; i++) {
|
||||
gpuInputAssembler->vertexBuffers[i] = gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer;
|
||||
gpuInputAssembler->vertexBufferOffsets[i] = gpuInputAssembler->gpuVertexBuffers[i]->startOffset;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler) {
|
||||
gpuInputAssembler->vertexBuffers.clear();
|
||||
gpuInputAssembler->vertexBufferOffsets.clear();
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer) {
|
||||
size_t colorViewCount = gpuFramebuffer->gpuColorViews.size();
|
||||
bool depthSpecified = gpuFramebuffer->gpuDepthStencilView;
|
||||
bool hasDepth = gpuFramebuffer->gpuRenderPass->depthStencilAttachment.format == device->getDepthStencilFormat();
|
||||
vector<VkImageView> attachments(colorViewCount + (depthSpecified || hasDepth ? 1 : 0));
|
||||
uint swapchainImageIndices = 0;
|
||||
CCVKGPUTexture *gpuTexture = nullptr;
|
||||
for (size_t i = 0u; i < colorViewCount; i++) {
|
||||
CCVKGPUTextureView *texView = gpuFramebuffer->gpuColorViews[i];
|
||||
if (texView) {
|
||||
gpuTexture = gpuFramebuffer->gpuColorViews[i]->gpuTexture;
|
||||
attachments[i] = gpuFramebuffer->gpuColorViews[i]->vkImageView;
|
||||
} else {
|
||||
swapchainImageIndices |= (1 << i);
|
||||
}
|
||||
}
|
||||
if (depthSpecified) {
|
||||
gpuTexture = gpuFramebuffer->gpuDepthStencilView->gpuTexture;
|
||||
attachments[colorViewCount] = gpuFramebuffer->gpuDepthStencilView->vkImageView;
|
||||
} else if (hasDepth) {
|
||||
swapchainImageIndices |= (1 << colorViewCount);
|
||||
@@ -563,8 +352,8 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra
|
||||
createInfo.renderPass = gpuFramebuffer->gpuRenderPass->vkRenderPass;
|
||||
createInfo.attachmentCount = attachments.size();
|
||||
createInfo.pAttachments = attachments.data();
|
||||
createInfo.width = colorViewCount ? gpuFramebuffer->gpuColorViews[0]->gpuTexture->width : 1;
|
||||
createInfo.height = colorViewCount ? gpuFramebuffer->gpuColorViews[0]->gpuTexture->height : 1;
|
||||
createInfo.width = gpuTexture ? gpuTexture->width : 1;
|
||||
createInfo.height = gpuTexture ? gpuTexture->height : 1;
|
||||
createInfo.layers = 1;
|
||||
VK_CHECK(vkCreateFramebuffer(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuFramebuffer->vkFramebuffer));
|
||||
} else {
|
||||
@@ -604,25 +393,6 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer) {
|
||||
if (gpuFramebuffer->isOffscreen) {
|
||||
if (gpuFramebuffer->vkFramebuffer != VK_NULL_HANDLE) {
|
||||
vkDestroyFramebuffer(device->gpuDevice()->vkDevice, gpuFramebuffer->vkFramebuffer, nullptr);
|
||||
gpuFramebuffer->vkFramebuffer = VK_NULL_HANDLE;
|
||||
}
|
||||
} else {
|
||||
FramebufferListMap &fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap;
|
||||
FramebufferListMapIter fboListMapIter = fboListMap.find(gpuFramebuffer);
|
||||
if (fboListMapIter != fboListMap.end()) {
|
||||
for (size_t i = 0u; i < fboListMapIter->second.size(); i++) {
|
||||
vkDestroyFramebuffer(device->gpuDevice()->vkDevice, fboListMapIter->second[i], nullptr);
|
||||
}
|
||||
fboListMapIter->second.clear();
|
||||
fboListMap.erase(fboListMapIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) {
|
||||
VkGraphicsPipelineCreateInfo createInfo{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO};
|
||||
|
||||
@@ -816,150 +586,338 @@ void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gp
|
||||
1, &createInfo, nullptr, &gpuPipelineState->vkPipeline));
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) {
|
||||
void CCVKCmdFuncCreateFence(CCVKDevice *device, CCVKGPUFence *gpuFence) {
|
||||
VkFenceCreateInfo createInfo{VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
|
||||
VK_CHECK(vkCreateFence(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuFence->vkFence));
|
||||
}
|
||||
|
||||
void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size) {
|
||||
if (!gpuBuffer) return;
|
||||
|
||||
const void *dataToUpload = nullptr;
|
||||
size_t sizeToUpload = 0u;
|
||||
|
||||
if (gpuBuffer->usage & BufferUsageBit::INDIRECT) {
|
||||
size_t drawInfoCount = size / sizeof(DrawInfo);
|
||||
DrawInfo *drawInfo = static_cast<DrawInfo *>(buffer);
|
||||
if (drawInfoCount > 0) {
|
||||
if (drawInfo->indexCount) {
|
||||
for (size_t i = 0; i < drawInfoCount; i++) {
|
||||
gpuBuffer->indexedIndirectCmds[i].indexCount = drawInfo->indexCount;
|
||||
gpuBuffer->indexedIndirectCmds[i].instanceCount = std::max(drawInfo->instanceCount, 1u);
|
||||
gpuBuffer->indexedIndirectCmds[i].firstIndex = drawInfo->firstIndex;
|
||||
gpuBuffer->indexedIndirectCmds[i].vertexOffset = drawInfo->vertexOffset;
|
||||
gpuBuffer->indexedIndirectCmds[i].firstInstance = drawInfo->firstInstance;
|
||||
drawInfo++;
|
||||
}
|
||||
dataToUpload = gpuBuffer->indexedIndirectCmds.data();
|
||||
sizeToUpload = drawInfoCount * sizeof(VkDrawIndexedIndirectCommand);
|
||||
gpuBuffer->isDrawIndirectByIndex = true;
|
||||
} else {
|
||||
for (size_t i = 0; i < drawInfoCount; i++) {
|
||||
gpuBuffer->indirectCmds[i].vertexCount = drawInfo->vertexCount;
|
||||
gpuBuffer->indirectCmds[i].instanceCount = drawInfo->instanceCount;
|
||||
gpuBuffer->indirectCmds[i].firstVertex = drawInfo->firstVertex;
|
||||
gpuBuffer->indirectCmds[i].firstInstance = drawInfo->firstInstance;
|
||||
drawInfo++;
|
||||
}
|
||||
dataToUpload = gpuBuffer->indirectCmds.data();
|
||||
sizeToUpload = drawInfoCount * sizeof(VkDrawIndirectCommand);
|
||||
gpuBuffer->isDrawIndirectByIndex = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dataToUpload = buffer;
|
||||
sizeToUpload = size;
|
||||
}
|
||||
|
||||
if (gpuBuffer->mappedData) {
|
||||
device->gpuTransportHub()->checkIn(gpuBuffer->mappedData + offset, dataToUpload, sizeToUpload);
|
||||
} else {
|
||||
CCVKGPUBuffer stagingBuffer;
|
||||
stagingBuffer.size = sizeToUpload;
|
||||
device->gpuStagingBufferPool()->alloc(&stagingBuffer);
|
||||
memcpy(stagingBuffer.mappedData, dataToUpload, sizeToUpload);
|
||||
|
||||
VkBufferCopy region{stagingBuffer.startOffset, gpuBuffer->startOffset + offset, sizeToUpload};
|
||||
device->gpuTransportHub()->checkIn([&](VkCommandBuffer cmdBuff) {
|
||||
vkCmdCopyBuffer(cmdBuff, stagingBuffer.vkBuffer, gpuBuffer->vkBuffer, 1, ®ion);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const BufferDataList &buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions) {
|
||||
device->gpuTransportHub()->checkIn([&](VkCommandBuffer cmdBuff) {
|
||||
//bool isCompressed = GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed;
|
||||
|
||||
VkImageMemoryBarrier barriers[2]{};
|
||||
barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
barriers[0].image = gpuTexture->vkImage;
|
||||
barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barriers[0].subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||
barriers[0].subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
barriers[0].subresourceRange.aspectMask = gpuTexture->aspectMask;
|
||||
barriers[0].srcAccessMask = gpuTexture->accessMask;
|
||||
barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barriers[0].oldLayout = gpuTexture->currentLayout;
|
||||
barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
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<uint> regionSizes(regionCount);
|
||||
for (size_t i = 0u; i < regionCount; ++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;
|
||||
totalSize += regionSizes[i] = FormatSize(gpuTexture->format, w, h, region.texExtent.depth);
|
||||
}
|
||||
|
||||
CCVKGPUBuffer stagingBuffer;
|
||||
stagingBuffer.size = totalSize;
|
||||
device->gpuStagingBufferPool()->alloc(&stagingBuffer);
|
||||
|
||||
vector<VkBufferImageCopy> stagingRegions(regionCount);
|
||||
VkDeviceSize offset = 0;
|
||||
for (size_t i = 0u; i < regionCount; ++i) {
|
||||
const BufferTextureCopy ®ion = regions[i];
|
||||
VkBufferImageCopy &stagingRegion = stagingRegions[i];
|
||||
stagingRegion.bufferOffset = stagingBuffer.startOffset + offset;
|
||||
stagingRegion.bufferRowLength = region.buffStride;
|
||||
stagingRegion.bufferImageHeight = region.buffTexHeight;
|
||||
stagingRegion.imageSubresource = {gpuTexture->aspectMask, region.texSubres.mipLevel, region.texSubres.baseArrayLayer, region.texSubres.layerCount};
|
||||
stagingRegion.imageOffset = {region.texOffset.x, region.texOffset.y, region.texOffset.z};
|
||||
stagingRegion.imageExtent = {region.texExtent.width, region.texExtent.height, region.texExtent.depth};
|
||||
|
||||
memcpy(stagingBuffer.mappedData + offset, buffers[i], regionSizes[i]);
|
||||
offset += regionSizes[i];
|
||||
}
|
||||
|
||||
vkCmdCopyBufferToImage(cmdBuff, stagingBuffer.vkBuffer, gpuTexture->vkImage,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, stagingRegions.size(), stagingRegions.data());
|
||||
|
||||
bool layoutReady = false;
|
||||
if (gpuTexture->flags & TextureFlags::GEN_MIPMAP) {
|
||||
VkFormatProperties formatProperties;
|
||||
vkGetPhysicalDeviceFormatProperties(device->gpuContext()->physicalDevice, MapVkFormat(gpuTexture->format), &formatProperties);
|
||||
VkFormatFeatureFlags mipmapFeatures = VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
|
||||
if (formatProperties.optimalTilingFeatures & mipmapFeatures) {
|
||||
const int32_t width = gpuTexture->width;
|
||||
const int32_t height = gpuTexture->height;
|
||||
|
||||
VkImageBlit blitInfo{};
|
||||
blitInfo.srcSubresource.aspectMask = gpuTexture->aspectMask;
|
||||
blitInfo.srcSubresource.layerCount = gpuTexture->arrayLayers;
|
||||
blitInfo.dstSubresource.aspectMask = gpuTexture->aspectMask;
|
||||
blitInfo.dstSubresource.layerCount = gpuTexture->arrayLayers;
|
||||
blitInfo.srcOffsets[1] = {width, height, 1};
|
||||
blitInfo.dstOffsets[1] = {std::max(width >> 1, 1), std::max(height >> 1, 1), 1};
|
||||
barriers[0].subresourceRange.levelCount = 1;
|
||||
barriers[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
barriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
||||
|
||||
for (uint i = 1u; i < gpuTexture->mipLevels; i++) {
|
||||
barriers[0].subresourceRange.baseMipLevel = i - 1;
|
||||
vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, barriers);
|
||||
|
||||
blitInfo.srcSubresource.mipLevel = i - 1;
|
||||
blitInfo.dstSubresource.mipLevel = i;
|
||||
vkCmdBlitImage(cmdBuff, gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blitInfo, VK_FILTER_LINEAR);
|
||||
|
||||
const int32_t w = blitInfo.srcOffsets[1].x = blitInfo.dstOffsets[1].x;
|
||||
const int32_t h = blitInfo.srcOffsets[1].y = blitInfo.dstOffsets[1].y;
|
||||
blitInfo.dstOffsets[1].x = std::max(w >> 1, 1);
|
||||
blitInfo.dstOffsets[1].y = std::max(h >> 1, 1);
|
||||
}
|
||||
|
||||
barriers[0].subresourceRange.baseMipLevel = gpuTexture->mipLevels - 1;
|
||||
barriers[0].dstAccessMask = gpuTexture->accessMask;
|
||||
barriers[0].newLayout = gpuTexture->layout;
|
||||
|
||||
barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
barriers[1].image = gpuTexture->vkImage;
|
||||
barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barriers[1].subresourceRange.aspectMask = gpuTexture->aspectMask;
|
||||
barriers[1].subresourceRange.baseMipLevel = 0;
|
||||
barriers[1].subresourceRange.levelCount = gpuTexture->mipLevels - 1;
|
||||
barriers[1].subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
barriers[1].srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
barriers[1].dstAccessMask = gpuTexture->accessMask;
|
||||
barriers[1].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
||||
barriers[1].newLayout = gpuTexture->layout;
|
||||
|
||||
vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_TRANSFER_BIT, gpuTexture->targetStage,
|
||||
VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 2, barriers);
|
||||
layoutReady = true;
|
||||
} else {
|
||||
const char *formatName = GFX_FORMAT_INFOS[(uint)gpuTexture->format].name.c_str();
|
||||
CC_LOG_WARNING("CCVKCmdFuncCopyBuffersToTexture: generate mipmap for %s is not supported on this platform", formatName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!layoutReady) {
|
||||
barriers[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
barriers[0].dstAccessMask = gpuTexture->accessMask;
|
||||
barriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
barriers[0].newLayout = gpuTexture->layout;
|
||||
vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_TRANSFER_BIT, gpuTexture->targetStage,
|
||||
VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, barriers);
|
||||
}
|
||||
|
||||
gpuTexture->currentLayout = gpuTexture->layout;
|
||||
});
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyRenderPass(CCVKGPUDevice *gpuDevice, CCVKGPURenderPass *gpuRenderPass) {
|
||||
if (gpuRenderPass->vkRenderPass != VK_NULL_HANDLE) {
|
||||
vkDestroyRenderPass(gpuDevice->vkDevice, gpuRenderPass->vkRenderPass, nullptr);
|
||||
gpuRenderPass->vkRenderPass = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroySampler(CCVKGPUDevice *gpuDevice, CCVKGPUSampler *gpuSampler) {
|
||||
if (gpuSampler->vkSampler != VK_NULL_HANDLE) {
|
||||
vkDestroySampler(gpuDevice->vkDevice, gpuSampler->vkSampler, nullptr);
|
||||
gpuSampler->vkSampler = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyShader(CCVKGPUDevice *gpuDevice, CCVKGPUShader *gpuShader) {
|
||||
for (uint i = 0u; i < gpuShader->vkDescriptorUpdateTemplates.size(); i++) {
|
||||
if (gpuShader->vkDescriptorUpdateTemplates[i] != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, gpuShader->vkDescriptorUpdateTemplates[i], nullptr);
|
||||
}
|
||||
}
|
||||
gpuShader->vkDescriptorUpdateTemplates.clear();
|
||||
|
||||
if (gpuShader->vkPipelineLayout != VK_NULL_HANDLE) {
|
||||
vkDestroyPipelineLayout(gpuDevice->vkDevice, gpuShader->vkPipelineLayout, nullptr);
|
||||
gpuShader->vkPipelineLayout = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
for (uint i = 0u; i < gpuShader->vkDescriptorSetLayouts.size(); i++) {
|
||||
if (gpuShader->vkDescriptorSetLayouts[i] != VK_NULL_HANDLE) {
|
||||
vkDestroyDescriptorSetLayout(gpuDevice->vkDevice, gpuShader->vkDescriptorSetLayouts[i], nullptr);
|
||||
}
|
||||
}
|
||||
gpuShader->vkDescriptorSetLayouts.clear();
|
||||
|
||||
for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) {
|
||||
vkDestroyShaderModule(gpuDevice->vkDevice, stage.vkShader, nullptr);
|
||||
stage.vkShader = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer *gpuFramebuffer) {
|
||||
if (gpuFramebuffer->isOffscreen) {
|
||||
if (gpuFramebuffer->vkFramebuffer != VK_NULL_HANDLE) {
|
||||
vkDestroyFramebuffer(gpuDevice->vkDevice, gpuFramebuffer->vkFramebuffer, nullptr);
|
||||
gpuFramebuffer->vkFramebuffer = VK_NULL_HANDLE;
|
||||
}
|
||||
} else {
|
||||
FramebufferListMap &fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap;
|
||||
FramebufferListMapIter fboListMapIter = fboListMap.find(gpuFramebuffer);
|
||||
if (fboListMapIter != fboListMap.end()) {
|
||||
for (size_t i = 0u; i < fboListMapIter->second.size(); i++) {
|
||||
vkDestroyFramebuffer(gpuDevice->vkDevice, fboListMapIter->second[i], nullptr);
|
||||
}
|
||||
fboListMapIter->second.clear();
|
||||
fboListMap.erase(fboListMapIter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineState *gpuPipelineState) {
|
||||
if (gpuPipelineState->vkPipeline != VK_NULL_HANDLE) {
|
||||
vkDestroyPipeline(device->gpuDevice()->vkDevice, gpuPipelineState->vkPipeline, nullptr);
|
||||
vkDestroyPipeline(gpuDevice->vkDevice, gpuPipelineState->vkPipeline, nullptr);
|
||||
gpuPipelineState->vkPipeline = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions) {
|
||||
//bool isCompressed = GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed;
|
||||
CCVKGPUCommandBuffer cmdBuff;
|
||||
beginOneTimeCommands(device, &cmdBuff);
|
||||
|
||||
//transfer image layout to destination for later copy.
|
||||
VkImageSubresourceRange subresoureceRange{};
|
||||
subresoureceRange.aspectMask = gpuTexture->aspectMask;
|
||||
subresoureceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||
subresoureceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
insertImageMemoryBarrior(cmdBuff.vkCommandBuffer,
|
||||
gpuTexture->vkImage,
|
||||
gpuTexture->accessMask,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
gpuTexture->currentLayout,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
gpuTexture->targetStage,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
subresoureceRange);
|
||||
|
||||
uint regionCount = regions.size(), totalSize = 0u;
|
||||
vector<uint> regionSizes(regionCount);
|
||||
for (size_t i = 0u; i < regionCount; ++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;
|
||||
totalSize += regionSizes[i] = FormatSize(gpuTexture->format, w, h, region.texExtent.depth);
|
||||
void CCVKCmdFuncDestroyFence(CCVKGPUDevice *gpuDevice, CCVKGPUFence *gpuFence) {
|
||||
if (gpuFence->vkFence) {
|
||||
vkDestroyFence(gpuDevice->vkDevice, gpuFence->vkFence, nullptr);
|
||||
gpuFence->vkFence = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
CCVKGPUBuffer *stagingBuffer = device->stagingBuffer()->gpuBuffer();
|
||||
if (stagingBuffer->size < totalSize) device->stagingBuffer()->resize(nextPowerOf2(totalSize));
|
||||
|
||||
vector<VkBufferImageCopy> stagingRegions(regionCount);
|
||||
VkDeviceSize offset = stagingBuffer->startOffset;
|
||||
for (size_t i = 0u; i < regionCount; ++i) {
|
||||
const BufferTextureCopy ®ion = regions[i];
|
||||
VkBufferImageCopy &stagingRegion = stagingRegions[i];
|
||||
stagingRegion.bufferOffset = offset;
|
||||
stagingRegion.bufferRowLength = region.buffStride;
|
||||
stagingRegion.bufferImageHeight = region.buffTexHeight;
|
||||
stagingRegion.imageSubresource = {gpuTexture->aspectMask, region.texSubres.mipLevel, region.texSubres.baseArrayLayer, region.texSubres.layerCount};
|
||||
stagingRegion.imageOffset = {region.texOffset.x, region.texOffset.y, region.texOffset.z};
|
||||
stagingRegion.imageExtent = {region.texExtent.width, region.texExtent.height, region.texExtent.depth};
|
||||
|
||||
memcpy(stagingBuffer->mappedData + offset, buffers[i], regionSizes[i]);
|
||||
offset += regionSizes[i];
|
||||
}
|
||||
|
||||
vkCmdCopyBufferToImage(cmdBuff.vkCommandBuffer, stagingBuffer->vkBuffer, gpuTexture->vkImage,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, stagingRegions.size(), stagingRegions.data());
|
||||
|
||||
bool layoutReady = false;
|
||||
if (gpuTexture->flags & TextureFlags::GEN_MIPMAP) {
|
||||
VkFormatProperties formatProperties;
|
||||
vkGetPhysicalDeviceFormatProperties(device->gpuContext()->physicalDevice, MapVkFormat(gpuTexture->format), &formatProperties);
|
||||
VkFormatFeatureFlags mipmapFeatures = VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
|
||||
if (formatProperties.optimalTilingFeatures & mipmapFeatures) {
|
||||
VkImageSubresourceRange mipSubRange{};
|
||||
mipSubRange.aspectMask = gpuTexture->aspectMask;
|
||||
mipSubRange.levelCount = 1;
|
||||
mipSubRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||
|
||||
int32_t mipWidth = gpuTexture->width;
|
||||
int32_t mipHeight = gpuTexture->height;
|
||||
|
||||
for (uint i = 1u; i < gpuTexture->mipLevel; i++) {
|
||||
mipSubRange.baseMipLevel = i - 1;
|
||||
insertImageMemoryBarrior(cmdBuff.vkCommandBuffer,
|
||||
gpuTexture->vkImage,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_ACCESS_TRANSFER_READ_BIT,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
mipSubRange);
|
||||
|
||||
VkImageBlit blit{};
|
||||
blit.srcOffsets[1] = {mipWidth, mipHeight, 1};
|
||||
blit.srcSubresource.aspectMask = gpuTexture->aspectMask;
|
||||
blit.srcSubresource.mipLevel = i - 1;
|
||||
blit.srcSubresource.layerCount = gpuTexture->arrayLayer;
|
||||
blit.dstOffsets[1] = {mipWidth > 1 ? mipWidth >> 1 : 1, mipHeight > 1 ? mipHeight >> 1 : 1, 1};
|
||||
blit.dstSubresource.aspectMask = gpuTexture->aspectMask;
|
||||
blit.dstSubresource.mipLevel = i;
|
||||
blit.dstSubresource.layerCount = gpuTexture->arrayLayer;
|
||||
vkCmdBlitImage(cmdBuff.vkCommandBuffer,
|
||||
gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
1, &blit,
|
||||
VK_FILTER_LINEAR);
|
||||
|
||||
insertImageMemoryBarrior(cmdBuff.vkCommandBuffer,
|
||||
gpuTexture->vkImage,
|
||||
VK_ACCESS_TRANSFER_READ_BIT,
|
||||
gpuTexture->accessMask,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
gpuTexture->currentLayout,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
gpuTexture->targetStage,
|
||||
mipSubRange);
|
||||
|
||||
if (mipWidth > 1) mipWidth = mipWidth >> 1;
|
||||
if (mipHeight > 1) mipHeight = mipHeight >> 1;
|
||||
}
|
||||
|
||||
mipSubRange.baseMipLevel = gpuTexture->mipLevel - 1;
|
||||
insertImageMemoryBarrior(cmdBuff.vkCommandBuffer,
|
||||
gpuTexture->vkImage,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
gpuTexture->accessMask,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
gpuTexture->currentLayout,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
gpuTexture->targetStage,
|
||||
mipSubRange);
|
||||
layoutReady = true;
|
||||
} else {
|
||||
const char *formatName = GFX_FORMAT_INFOS[(uint)gpuTexture->format].name.c_str();
|
||||
CC_LOG_WARNING("CCVKCmdFuncCopyBuffersToTexture: generate mipmap for %s is not supported on this platform", formatName);
|
||||
void CCVKGPURecycleBin::clear() {
|
||||
for (uint i = 0u; i < _count; i++) {
|
||||
Resource &res = _resources[i];
|
||||
switch (res.type) {
|
||||
case ObjectType::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:
|
||||
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:
|
||||
if (res.vkImageView) {
|
||||
vkDestroyImageView(_device->vkDevice, res.vkImageView, nullptr);
|
||||
res.vkImageView = VK_NULL_HANDLE;
|
||||
}
|
||||
break;
|
||||
case ObjectType::RENDER_PASS:
|
||||
if (res.gpuRenderPass) {
|
||||
CCVKCmdFuncDestroyRenderPass(_device, res.gpuRenderPass);
|
||||
CC_DELETE(res.gpuRenderPass);
|
||||
res.gpuRenderPass = nullptr;
|
||||
}
|
||||
break;
|
||||
case ObjectType::FRAMEBUFFER:
|
||||
if (res.gpuFramebuffer) {
|
||||
CCVKCmdFuncDestroyFramebuffer(_device, res.gpuFramebuffer);
|
||||
CC_DELETE(res.gpuFramebuffer);
|
||||
res.gpuFramebuffer = nullptr;
|
||||
}
|
||||
break;
|
||||
case ObjectType::SAMPLER:
|
||||
if (res.gpuSampler) {
|
||||
CCVKCmdFuncDestroySampler(_device, res.gpuSampler);
|
||||
CC_DELETE(res.gpuSampler);
|
||||
res.gpuSampler = nullptr;
|
||||
}
|
||||
break;
|
||||
case ObjectType::SHADER:
|
||||
if (res.gpuShader) {
|
||||
CCVKCmdFuncDestroyShader(_device, res.gpuShader);
|
||||
CC_DELETE(res.gpuShader);
|
||||
res.gpuShader = nullptr;
|
||||
}
|
||||
break;
|
||||
case ObjectType::PIPELINE_STATE:
|
||||
if (res.gpuPipelineState) {
|
||||
CCVKCmdFuncDestroyPipelineState(_device, res.gpuPipelineState);
|
||||
CC_DELETE(res.gpuPipelineState);
|
||||
res.gpuPipelineState = nullptr;
|
||||
}
|
||||
break;
|
||||
case ObjectType::FENCE:
|
||||
if (res.gpuFence) {
|
||||
CCVKCmdFuncDestroyFence(_device, res.gpuFence);
|
||||
CC_DELETE(res.gpuFence);
|
||||
res.gpuFence = nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
res.type = ObjectType::UNKNOWN;
|
||||
}
|
||||
|
||||
if (!layoutReady) {
|
||||
insertImageMemoryBarrior(cmdBuff.vkCommandBuffer,
|
||||
gpuTexture->vkImage,
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
gpuTexture->accessMask,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
gpuTexture->currentLayout,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
gpuTexture->targetStage,
|
||||
subresoureceRange);
|
||||
}
|
||||
|
||||
endOneTimeCommands(device, &cmdBuff);
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -31,30 +31,26 @@ struct CCVKStencilCompareMask {
|
||||
};
|
||||
|
||||
CC_VULKAN_API void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass);
|
||||
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncResizeBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView);
|
||||
CC_VULKAN_API void CCVKCmdFuncResizeTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroySampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyShader(CCVKDevice *device, CCVKGPUShader *gpuShader);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState);
|
||||
CC_VULKAN_API void CCVKCmdFuncCreateFence(CCVKDevice *device, CCVKGPUFence *gpuFence);
|
||||
|
||||
CC_VULKAN_API void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions);
|
||||
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 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 CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *device, CCVKGPUPipelineState *gpuPipelineState);
|
||||
CC_VULKAN_API void CCVKCmdFuncDestroyFence(CCVKGPUDevice *device, CCVKGPUFence *gpuFence);
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace cc
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace gfx {
|
||||
|
||||
CCVKDevice::CCVKDevice() {
|
||||
_clipSpaceMinZ = 0.0f;
|
||||
_clipSpaceSignY = -1.0f;
|
||||
_screenSpaceSignY = -1.0f;
|
||||
_UVSpaceSignY = 1.0f;
|
||||
}
|
||||
|
||||
@@ -63,8 +63,7 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
//const VkPhysicalDeviceVulkan12Features &deviceVulkan12Features = gpuContext->physicalDeviceVulkan12Features;
|
||||
|
||||
// only enable the absolute essentials for now
|
||||
vector<const char *> requestedValidationLayers{
|
||||
};
|
||||
vector<const char *> requestedValidationLayers{};
|
||||
#if COCOS2D_DEBUG > 0
|
||||
requestedValidationLayers.push_back("VK_LAYER_KHRONOS_validation");
|
||||
#endif
|
||||
@@ -259,30 +258,28 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
|
||||
VK_CHECK(vmaCreateAllocator(&allocatorInfo, &_gpuDevice->memoryAllocator));
|
||||
|
||||
_gpuSemaphorePool = CC_NEW(CCVKGPUSemaphorePool(_gpuDevice));
|
||||
_gpuFencePool = CC_NEW(CCVKGPUFencePool(_gpuDevice));
|
||||
_gpuDescriptorSetPool = CC_NEW(CCVKGPUDescriptorSetPool(_gpuDevice));
|
||||
_gpuCommandBufferPool = CC_NEW(CCVKGPUCommandBufferPool(_gpuDevice));
|
||||
|
||||
BufferInfo stagingBufferInfo;
|
||||
stagingBufferInfo.usage = BufferUsage::TRANSFER_SRC;
|
||||
stagingBufferInfo.memUsage = MemoryUsage::HOST;
|
||||
stagingBufferInfo.stride = _defaultStagingBufferSize;
|
||||
stagingBufferInfo.size = _defaultStagingBufferSize;
|
||||
_stagingBuffer = (CCVKBuffer *)createBuffer(stagingBufferInfo);
|
||||
|
||||
QueueInfo queueInfo;
|
||||
queueInfo.type = QueueType::GRAPHICS;
|
||||
queueInfo.forceSync = true;
|
||||
//queueInfo.forceSync = true;
|
||||
_queue = createQueue(queueInfo);
|
||||
|
||||
_gpuFencePool = CC_NEW(CCVKGPUFencePool(_gpuDevice));
|
||||
_gpuRecycleBin = CC_NEW(CCVKGPURecycleBin(_gpuDevice));
|
||||
_gpuTransportHub = CC_NEW(CCVKGPUTransportHub(_gpuDevice));
|
||||
_gpuSemaphorePool = CC_NEW(CCVKGPUSemaphorePool(_gpuDevice));
|
||||
_gpuDescriptorSetPool = CC_NEW(CCVKGPUDescriptorSetPool(_gpuDevice));
|
||||
_gpuCommandBufferPool = CC_NEW(CCVKGPUCommandBufferPool(_gpuDevice));
|
||||
_gpuStagingBufferPool = CC_NEW(CCVKGPUStagingBufferPool(_gpuDevice));
|
||||
|
||||
_gpuTransportHub->link(((CCVKQueue *)_queue)->gpuQueue(), _gpuFencePool, _gpuCommandBufferPool);
|
||||
|
||||
for (uint i = 0u; i < gpuContext->swapchainCreateInfo.minImageCount; i++) {
|
||||
TextureInfo depthStencilTexInfo;
|
||||
depthStencilTexInfo.type = TextureType::TEX2D;
|
||||
depthStencilTexInfo.usage = TextureUsageBit::DEPTH_STENCIL_ATTACHMENT | TextureUsageBit::SAMPLED;
|
||||
depthStencilTexInfo.format = _context->getDepthStencilFormat();
|
||||
depthStencilTexInfo.width = 1;
|
||||
depthStencilTexInfo.height = 1;
|
||||
depthStencilTexInfo.width = _width;
|
||||
depthStencilTexInfo.height = _height;
|
||||
CCVKTexture *texture = (CCVKTexture *)createTexture(depthStencilTexInfo);
|
||||
_depthStencilTextures.push_back(texture);
|
||||
}
|
||||
@@ -328,6 +325,8 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
}
|
||||
|
||||
void CCVKDevice::destroy() {
|
||||
VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice));
|
||||
|
||||
if (_gpuSwapchain) {
|
||||
if (_gpuSwapchain->vkSwapchain != VK_NULL_HANDLE) {
|
||||
_gpuSwapchain->depthStencilImageViews.clear();
|
||||
@@ -352,21 +351,22 @@ void CCVKDevice::destroy() {
|
||||
vkDestroySwapchainKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, nullptr);
|
||||
_gpuSwapchain->vkSwapchain = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
CC_DELETE(_gpuSwapchain);
|
||||
_gpuSwapchain = nullptr;
|
||||
}
|
||||
|
||||
for (CCVKTexture *texture : _depthStencilTextures) {
|
||||
CC_SAFE_DESTROY(texture);
|
||||
}
|
||||
_depthStencilTextures.clear();
|
||||
_gpuRecycleBin->clear();
|
||||
|
||||
CC_SAFE_DESTROY(_stagingBuffer);
|
||||
CC_SAFE_DESTROY(_queue);
|
||||
CC_SAFE_DELETE(_gpuSwapchain);
|
||||
CC_SAFE_DELETE(_gpuStagingBufferPool);
|
||||
CC_SAFE_DELETE(_gpuCommandBufferPool);
|
||||
CC_SAFE_DELETE(_gpuDescriptorSetPool);
|
||||
CC_SAFE_DELETE(_gpuSemaphorePool);
|
||||
CC_SAFE_DELETE(_gpuTransportHub);
|
||||
CC_SAFE_DELETE(_gpuRecycleBin);
|
||||
CC_SAFE_DELETE(_gpuFencePool);
|
||||
|
||||
if (_gpuDevice) {
|
||||
@@ -482,18 +482,13 @@ void CCVKDevice::buildSwapchain() {
|
||||
void CCVKDevice::acquire() {
|
||||
if (!_swapchainReady) return;
|
||||
|
||||
VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice));
|
||||
_gpuSemaphorePool->reset();
|
||||
_gpuFencePool->reset();
|
||||
_gpuDescriptorSetPool->reset();
|
||||
_gpuCommandBufferPool->reset();
|
||||
|
||||
VkSemaphore acquireSemaphore = _gpuSemaphorePool->alloc();
|
||||
VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain,
|
||||
~0ull, acquireSemaphore, VK_NULL_HANDLE, &_gpuSwapchain->curImageIndex));
|
||||
|
||||
// Clear queue stats
|
||||
CCVKQueue *queue = (CCVKQueue *)_queue;
|
||||
// Clear queue stats
|
||||
queue->_numDrawCalls = 0;
|
||||
queue->_numInstances = 0;
|
||||
queue->_numTriangles = 0;
|
||||
@@ -517,6 +512,21 @@ void CCVKDevice::present() {
|
||||
presentInfo.pImageIndices = &_gpuSwapchain->curImageIndex;
|
||||
|
||||
VK_CHECK(vkQueuePresentKHR(queue->gpuQueue()->vkQueue, &presentInfo));
|
||||
|
||||
// TODO: these can be moved to acquire-time after pipeline refactoring,
|
||||
// which should guarantee that no transfer operation will be issued before acquiring
|
||||
|
||||
VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice));
|
||||
|
||||
queue->gpuQueue()->lastAutoFence = VK_NULL_HANDLE;
|
||||
// reset everything only when no pending commands
|
||||
if (_gpuTransportHub->empty()) {
|
||||
_gpuFencePool->reset();
|
||||
_gpuRecycleBin->clear();
|
||||
_gpuDescriptorSetPool->reset();
|
||||
_gpuCommandBufferPool->reset();
|
||||
_gpuStagingBufferPool->reset();
|
||||
}
|
||||
}
|
||||
|
||||
CommandBuffer *CCVKDevice::createCommandBuffer(const CommandBufferInfo &info) {
|
||||
@@ -636,8 +646,8 @@ PipelineState *CCVKDevice::createPipelineState(const PipelineStateInfo &info) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CCVKDevice::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) {
|
||||
CCVKCmdFuncCopyBuffersToTexture(this, buffers.datas.data(), ((CCVKTexture *)dst)->gpuTexture(), regions);
|
||||
void CCVKDevice::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) {
|
||||
CCVKCmdFuncCopyBuffersToTexture(this, buffers, ((CCVKTexture *)dst)->gpuTexture(), regions);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -4,16 +4,21 @@
|
||||
namespace cc {
|
||||
namespace gfx {
|
||||
|
||||
class CCVKGPUContext;
|
||||
class CCVKGPUDevice;
|
||||
class CCVKGPUSwapchain;
|
||||
class CCVKGPUSemaphorePool;
|
||||
class CCVKGPUFencePool;
|
||||
class CCVKGPUDescriptorSetPool;
|
||||
class CCVKGPUCommandBufferPool;
|
||||
class CCVKBuffer;
|
||||
class CCVKTexture;
|
||||
class CCVKRenderPass;
|
||||
class CCVKBuffer;
|
||||
|
||||
class CCVKGPUDevice;
|
||||
class CCVKGPUContext;
|
||||
class CCVKGPUSwapchain;
|
||||
|
||||
class CCVKGPUFencePool;
|
||||
class CCVKGPURecycleBin;
|
||||
class CCVKGPUTransportHub;
|
||||
class CCVKGPUSemaphorePool;
|
||||
class CCVKGPUDescriptorSetPool;
|
||||
class CCVKGPUCommandBufferPool;
|
||||
class CCVKGPUStagingBufferPool;
|
||||
|
||||
class CC_VULKAN_API CCVKDevice : public Device {
|
||||
public:
|
||||
@@ -39,7 +44,7 @@ public:
|
||||
virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override;
|
||||
virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override;
|
||||
virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override;
|
||||
virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override;
|
||||
|
||||
CC_INLINE bool checkExtension(const String &extension) const {
|
||||
return std::find_if(_extensions.begin(), _extensions.end(),
|
||||
@@ -51,11 +56,13 @@ public:
|
||||
CCVKGPUContext *gpuContext() const;
|
||||
CC_INLINE CCVKGPUDevice *gpuDevice() const { return _gpuDevice; }
|
||||
CC_INLINE CCVKGPUSwapchain *gpuSwapchain() { return _gpuSwapchain; }
|
||||
CC_INLINE CCVKGPUSemaphorePool *gpuSemaphorePool() { return _gpuSemaphorePool; }
|
||||
CC_INLINE CCVKGPUFencePool *gpuFencePool() { return _gpuFencePool; }
|
||||
CC_INLINE CCVKGPURecycleBin *gpuRecycleBin() { return _gpuRecycleBin; }
|
||||
CC_INLINE CCVKGPUTransportHub *gpuTransportHub() { return _gpuTransportHub; }
|
||||
CC_INLINE CCVKGPUSemaphorePool *gpuSemaphorePool() { return _gpuSemaphorePool; }
|
||||
CC_INLINE CCVKGPUDescriptorSetPool *gpuDescriptorSetPool() { return _gpuDescriptorSetPool; }
|
||||
CC_INLINE CCVKGPUCommandBufferPool *gpuCommandBufferPool() { return _gpuCommandBufferPool; }
|
||||
CC_INLINE CCVKBuffer *stagingBuffer() { return _stagingBuffer; }
|
||||
CC_INLINE CCVKGPUStagingBufferPool *gpuStagingBufferPool() { return _gpuStagingBufferPool; }
|
||||
CC_INLINE const vector<const char *> &getLayers() const { return _layers; }
|
||||
CC_INLINE const vector<const char *> &getExtensions() const { return _extensions; }
|
||||
CC_INLINE bool isSwapchainReady() const { return _swapchainReady; }
|
||||
@@ -68,15 +75,15 @@ private:
|
||||
void buildSwapchain();
|
||||
|
||||
CCVKGPUDevice *_gpuDevice = nullptr;
|
||||
CCVKGPUSemaphorePool *_gpuSemaphorePool = nullptr;
|
||||
CCVKGPUFencePool *_gpuFencePool = nullptr;
|
||||
CCVKGPURecycleBin *_gpuRecycleBin = nullptr;
|
||||
CCVKGPUTransportHub *_gpuTransportHub = nullptr;
|
||||
CCVKGPUSemaphorePool *_gpuSemaphorePool = nullptr;
|
||||
CCVKGPUDescriptorSetPool *_gpuDescriptorSetPool = nullptr;
|
||||
CCVKGPUCommandBufferPool *_gpuCommandBufferPool = nullptr;
|
||||
CCVKGPUStagingBufferPool *_gpuStagingBufferPool = nullptr;
|
||||
CCVKGPUSwapchain *_gpuSwapchain = nullptr;
|
||||
vector<CCVKTexture *> _depthStencilTextures;
|
||||
CCVKBuffer *_stagingBuffer = nullptr;
|
||||
|
||||
uint32_t _defaultStagingBufferSize = 1024;
|
||||
|
||||
vector<const char *> _layers;
|
||||
vector<const char *> _extensions;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "VKDevice.h"
|
||||
#include "VKFence.h"
|
||||
#include "VKGPUObjects.h"
|
||||
#include "VKCommands.h"
|
||||
|
||||
namespace cc {
|
||||
namespace gfx {
|
||||
@@ -17,12 +17,11 @@ CCVKFence::~CCVKFence() {
|
||||
bool CCVKFence::initialize(const FenceInfo &info) {
|
||||
_gpuFence = CC_NEW(CCVKGPUFence);
|
||||
if (!_gpuFence) {
|
||||
CC_LOG_ERROR("GLES2Fence: CC_NEW CCVKGPUFence failed.");
|
||||
CC_LOG_ERROR("CCVKFence: CC_NEW CCVKGPUFence failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
VkFenceCreateInfo createInfo{VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
|
||||
VK_CHECK(vkCreateFence(((CCVKDevice *)_device)->gpuDevice()->vkDevice, &createInfo, nullptr, &_gpuFence->vkFence));
|
||||
CCVKCmdFuncCreateFence((CCVKDevice *)_device, _gpuFence);
|
||||
|
||||
_status = Status::SUCCESS;
|
||||
return true;
|
||||
@@ -30,14 +29,13 @@ bool CCVKFence::initialize(const FenceInfo &info) {
|
||||
|
||||
void CCVKFence::destroy() {
|
||||
if (_gpuFence) {
|
||||
vkDestroyFence(((CCVKDevice *)_device)->gpuDevice()->vkDevice, _gpuFence->vkFence, nullptr);
|
||||
|
||||
CC_DELETE(_gpuFence);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuFence);
|
||||
_gpuFence = nullptr;
|
||||
}
|
||||
_status = Status::UNREADY;
|
||||
}
|
||||
|
||||
// TODO: move these two to device
|
||||
void CCVKFence::wait() {
|
||||
VK_CHECK(vkWaitForFences(((CCVKDevice *)_device)->gpuDevice()->vkDevice, 1, &_gpuFence->vkFence, VK_TRUE, DEFAULT_FENCE_TIMEOUT));
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ bool CCVKFramebuffer::initialize(const FramebufferInfo &info) {
|
||||
|
||||
void CCVKFramebuffer::destroy() {
|
||||
if (_gpuFBO) {
|
||||
CCVKCmdFuncDestroyFramebuffer((CCVKDevice *)_device, _gpuFBO);
|
||||
CC_DELETE(_gpuFBO);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuFBO);
|
||||
_gpuFBO = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,14 +55,15 @@ public:
|
||||
uint height = 0u;
|
||||
uint depth = 1u;
|
||||
uint size = 0u;
|
||||
uint arrayLayer = 1u;
|
||||
uint mipLevel = 1u;
|
||||
uint arrayLayers = 1u;
|
||||
uint mipLevels = 1u;
|
||||
SampleCount samples = SampleCount::X1;
|
||||
TextureFlags flags = TextureFlagBit::NONE;
|
||||
bool isPowerOf2 = false;
|
||||
|
||||
VkImage vkImage = VK_NULL_HANDLE;
|
||||
VmaAllocation vmaAllocation = VK_NULL_HANDLE;
|
||||
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
VkImageLayout currentLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
VkAccessFlags accessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
@@ -76,6 +77,8 @@ public:
|
||||
Format format = Format::UNKNOWN;
|
||||
uint baseLevel = 0u;
|
||||
uint levelCount = 1u;
|
||||
uint baseLayer = 0u;
|
||||
uint layerCount = 1u;
|
||||
VkImageView vkImageView = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
@@ -124,6 +127,7 @@ public:
|
||||
VkSemaphore nextSignalSemaphore = VK_NULL_HANDLE;
|
||||
VkPipelineStageFlags submitStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
CachedArray<VkCommandBuffer> commandBuffers;
|
||||
VkFence lastAutoFence = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
class CCVKGPUBuffer : public Object {
|
||||
@@ -239,48 +243,6 @@ public:
|
||||
VkFence vkFence;
|
||||
};
|
||||
|
||||
class CCVKGPUSemaphorePool : public Object {
|
||||
public:
|
||||
CCVKGPUSemaphorePool(CCVKGPUDevice *device)
|
||||
: _device(device) {
|
||||
}
|
||||
|
||||
~CCVKGPUSemaphorePool() {
|
||||
for (VkSemaphore semaphore : _semaphores) {
|
||||
vkDestroySemaphore(_device->vkDevice, semaphore, nullptr);
|
||||
}
|
||||
_semaphores.clear();
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
VkSemaphore alloc() {
|
||||
if (_count < _semaphores.size()) {
|
||||
return _semaphores[_count++];
|
||||
}
|
||||
|
||||
VkSemaphore semaphore = VK_NULL_HANDLE;
|
||||
VkSemaphoreCreateInfo createInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
|
||||
VK_CHECK(vkCreateSemaphore(_device->vkDevice, &createInfo, nullptr, &semaphore));
|
||||
_semaphores.push_back(semaphore);
|
||||
_count++;
|
||||
|
||||
return semaphore;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
uint size() {
|
||||
return _count;
|
||||
}
|
||||
|
||||
private:
|
||||
CCVKGPUDevice *_device;
|
||||
uint _count = 0;
|
||||
vector<VkSemaphore> _semaphores;
|
||||
};
|
||||
|
||||
class CCVKGPUFencePool : public Object {
|
||||
public:
|
||||
CCVKGPUFencePool(CCVKGPUDevice *device)
|
||||
@@ -322,10 +284,52 @@ public:
|
||||
|
||||
private:
|
||||
CCVKGPUDevice *_device;
|
||||
uint _count = 0;
|
||||
uint _count = 0u;
|
||||
vector<VkFence> _fences;
|
||||
};
|
||||
|
||||
class CCVKGPUSemaphorePool : public Object {
|
||||
public:
|
||||
CCVKGPUSemaphorePool(CCVKGPUDevice *device)
|
||||
: _device(device) {
|
||||
}
|
||||
|
||||
~CCVKGPUSemaphorePool() {
|
||||
for (VkSemaphore semaphore : _semaphores) {
|
||||
vkDestroySemaphore(_device->vkDevice, semaphore, nullptr);
|
||||
}
|
||||
_semaphores.clear();
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
VkSemaphore alloc() {
|
||||
if (_count < _semaphores.size()) {
|
||||
return _semaphores[_count++];
|
||||
}
|
||||
|
||||
VkSemaphore semaphore = VK_NULL_HANDLE;
|
||||
VkSemaphoreCreateInfo createInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
|
||||
VK_CHECK(vkCreateSemaphore(_device->vkDevice, &createInfo, nullptr, &semaphore));
|
||||
_semaphores.push_back(semaphore);
|
||||
_count++;
|
||||
|
||||
return semaphore;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
uint size() {
|
||||
return _count;
|
||||
}
|
||||
|
||||
private:
|
||||
CCVKGPUDevice *_device;
|
||||
uint _count = 0u;
|
||||
vector<VkSemaphore> _semaphores;
|
||||
};
|
||||
|
||||
class CCVKGPUDescriptorSetPool : public Object {
|
||||
public:
|
||||
CCVKGPUDescriptorSetPool(CCVKGPUDevice *device)
|
||||
@@ -395,12 +399,6 @@ private:
|
||||
|
||||
class CCVKGPUCommandBufferPool : public Object {
|
||||
public:
|
||||
struct CommandBufferPool {
|
||||
VkCommandPool vkCommandPool = VK_NULL_HANDLE;
|
||||
CachedArray<VkCommandBuffer> commandBuffers[2];
|
||||
CachedArray<VkCommandBuffer> usedCommandBuffers[2];
|
||||
};
|
||||
|
||||
CCVKGPUCommandBufferPool(CCVKGPUDevice *device)
|
||||
: _device(device) {
|
||||
}
|
||||
@@ -465,11 +463,229 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
struct CommandBufferPool {
|
||||
VkCommandPool vkCommandPool = VK_NULL_HANDLE;
|
||||
CachedArray<VkCommandBuffer> commandBuffers[2];
|
||||
CachedArray<VkCommandBuffer> usedCommandBuffers[2];
|
||||
};
|
||||
|
||||
CCVKGPUDevice *_device = nullptr;
|
||||
map<uint, CommandBufferPool> _pools;
|
||||
vector<uint> _counts;
|
||||
};
|
||||
|
||||
class CCVKGPUStagingBufferPool : public Object {
|
||||
public:
|
||||
CCVKGPUStagingBufferPool(CCVKGPUDevice *device)
|
||||
: _device(device) {
|
||||
}
|
||||
|
||||
~CCVKGPUStagingBufferPool() {
|
||||
for (Buffer &buffer : _pool) {
|
||||
vmaDestroyBuffer(_device->memoryAllocator, buffer.vkBuffer, buffer.vmaAllocation);
|
||||
}
|
||||
_pool.clear();
|
||||
}
|
||||
|
||||
void alloc(CCVKGPUBuffer *gpuBuffer) {
|
||||
size_t bufferCount = _pool.size();
|
||||
Buffer *buffer = nullptr;
|
||||
for (size_t idx = 0u; idx < bufferCount; idx++) {
|
||||
Buffer *cur = &_pool[idx];
|
||||
if (cur->size - cur->curOffset > gpuBuffer->size) {
|
||||
buffer = cur;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!buffer) {
|
||||
_pool.resize(bufferCount + 1);
|
||||
buffer = &_pool.back();
|
||||
VkBufferCreateInfo bufferInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
|
||||
bufferInfo.size = buffer->size;
|
||||
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
VmaAllocationCreateInfo allocInfo{};
|
||||
allocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT;
|
||||
allocInfo.usage = VMA_MEMORY_USAGE_CPU_ONLY;
|
||||
VmaAllocationInfo res;
|
||||
VK_CHECK(vmaCreateBuffer(_device->memoryAllocator, &bufferInfo, &allocInfo, &buffer->vkBuffer, &buffer->vmaAllocation, &res));
|
||||
buffer->mappedData = (uint8_t *)res.pMappedData;
|
||||
}
|
||||
gpuBuffer->vkBuffer = buffer->vkBuffer;
|
||||
gpuBuffer->startOffset = buffer->curOffset;
|
||||
gpuBuffer->mappedData = buffer->mappedData + buffer->curOffset;
|
||||
buffer->curOffset += gpuBuffer->size;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
for (Buffer &buffer : _pool) {
|
||||
buffer.curOffset = 0u;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
struct Buffer {
|
||||
VkBuffer vkBuffer = VK_NULL_HANDLE;
|
||||
VkDeviceSize size = 16 * 1024 * 1024; // 16M per block by default
|
||||
uint8_t *mappedData = nullptr;
|
||||
VmaAllocation vmaAllocation = VK_NULL_HANDLE;
|
||||
|
||||
VkDeviceSize curOffset = 0u;
|
||||
};
|
||||
|
||||
CCVKGPUDevice *_device = nullptr;
|
||||
vector<Buffer> _pool;
|
||||
};
|
||||
|
||||
class CCVKGPURecycleBin : public Object {
|
||||
public:
|
||||
CCVKGPURecycleBin(CCVKGPUDevice *device)
|
||||
: _device(device) {
|
||||
_resources.resize(16);
|
||||
}
|
||||
|
||||
#define DEFINE_COLLECT_FN(_type, typeValue, expr) \
|
||||
void collect(_type *gpuRes) { \
|
||||
if (_resources.size() <= _count) { \
|
||||
_resources.resize(_count * 2); \
|
||||
} \
|
||||
Resource &res = _resources[_count++]; \
|
||||
res.type = typeValue; \
|
||||
expr; \
|
||||
}
|
||||
DEFINE_COLLECT_FN(CCVKGPUBuffer, ObjectType::BUFFER, (res.buffer = {gpuRes->vkBuffer, gpuRes->vmaAllocation}))
|
||||
DEFINE_COLLECT_FN(CCVKGPUTexture, ObjectType::TEXTURE, (res.image = {gpuRes->vkImage, gpuRes->vmaAllocation}))
|
||||
DEFINE_COLLECT_FN(CCVKGPUTextureView, ObjectType::TEXTURE_VIEW, res.vkImageView = gpuRes->vkImageView)
|
||||
DEFINE_COLLECT_FN(CCVKGPURenderPass, ObjectType::RENDER_PASS, res.gpuRenderPass = gpuRes)
|
||||
DEFINE_COLLECT_FN(CCVKGPUFramebuffer, ObjectType::FRAMEBUFFER, res.gpuFramebuffer = gpuRes)
|
||||
DEFINE_COLLECT_FN(CCVKGPUSampler, ObjectType::SAMPLER, res.gpuSampler = gpuRes)
|
||||
DEFINE_COLLECT_FN(CCVKGPUShader, ObjectType::SHADER, res.gpuShader = gpuRes)
|
||||
DEFINE_COLLECT_FN(CCVKGPUPipelineState, ObjectType::PIPELINE_STATE, res.gpuPipelineState = gpuRes)
|
||||
DEFINE_COLLECT_FN(CCVKGPUFence, ObjectType::FENCE, res.gpuFence = gpuRes)
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
struct Buffer {
|
||||
VkBuffer vkBuffer;
|
||||
VmaAllocation vmaAllocation;
|
||||
};
|
||||
struct Image {
|
||||
VkImage vkImage;
|
||||
VmaAllocation vmaAllocation;
|
||||
};
|
||||
struct Resource {
|
||||
ObjectType type = ObjectType::UNKNOWN;
|
||||
union {
|
||||
// resizable resources, cannot take over directly
|
||||
// or descriptor sets won't work
|
||||
Buffer buffer;
|
||||
Image image;
|
||||
VkImageView vkImageView;
|
||||
|
||||
CCVKGPURenderPass *gpuRenderPass;
|
||||
CCVKGPUFramebuffer *gpuFramebuffer;
|
||||
CCVKGPUSampler *gpuSampler;
|
||||
CCVKGPUShader *gpuShader;
|
||||
CCVKGPUPipelineState *gpuPipelineState;
|
||||
CCVKGPUFence *gpuFence;
|
||||
};
|
||||
};
|
||||
CCVKGPUDevice *_device = nullptr;
|
||||
vector<Resource> _resources;
|
||||
uint _count = 0u;
|
||||
};
|
||||
|
||||
#define ASYNC_SUBMISSION
|
||||
class CCVKGPUTransportHub : public Object {
|
||||
public:
|
||||
CCVKGPUTransportHub(CCVKGPUDevice *device)
|
||||
: _device(device) {
|
||||
_transfers.resize(16);
|
||||
}
|
||||
|
||||
void link(CCVKGPUQueue *queue, CCVKGPUFencePool *fencePool, CCVKGPUCommandBufferPool *commandBufferPool) {
|
||||
_queue = queue;
|
||||
_fencePool = fencePool;
|
||||
_commandBufferPool = commandBufferPool;
|
||||
|
||||
_cmdBuff.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
_cmdBuff.queueFamilyIndex = _queue->queueFamilyIndex;
|
||||
}
|
||||
|
||||
CC_INLINE bool empty() {
|
||||
return !_cmdBuff.vkCommandBuffer && !_count;
|
||||
}
|
||||
|
||||
void checkIn(void *dst, const void *src, size_t size) {
|
||||
if (_transfers.size() <= _count) {
|
||||
_transfers.resize(_count * 2);
|
||||
}
|
||||
Transfer &transfer = _transfers[_count++];
|
||||
transfer.dst = dst;
|
||||
transfer.src = src;
|
||||
transfer.size = size;
|
||||
}
|
||||
|
||||
template <typename TFunc>
|
||||
void checkIn(const TFunc &record) {
|
||||
if (!_cmdBuff.vkCommandBuffer) {
|
||||
_commandBufferPool->request(&_cmdBuff);
|
||||
VkCommandBufferBeginInfo beginInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
VK_CHECK(vkBeginCommandBuffer(_cmdBuff.vkCommandBuffer, &beginInfo));
|
||||
}
|
||||
|
||||
record(_cmdBuff.vkCommandBuffer);
|
||||
|
||||
#ifndef ASYNC_SUBMISSION
|
||||
VK_CHECK(vkEndCommandBuffer(_cmdBuff.vkCommandBuffer));
|
||||
VkFence fence = _fencePool->alloc();
|
||||
VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &_cmdBuff.vkCommandBuffer;
|
||||
VK_CHECK(vkQueueSubmit(_queue->vkQueue, 1, &submitInfo, fence));
|
||||
VK_CHECK(vkWaitForFences(_device->vkDevice, 1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT));
|
||||
_commandBufferPool->yield(&_cmdBuff);
|
||||
#endif // ASYNC_SUBMISSION
|
||||
}
|
||||
|
||||
void depart() {
|
||||
if (_cmdBuff.vkCommandBuffer) {
|
||||
VK_CHECK(vkEndCommandBuffer(_cmdBuff.vkCommandBuffer));
|
||||
_queue->commandBuffers.push(_cmdBuff.vkCommandBuffer);
|
||||
_commandBufferPool->yield(&_cmdBuff);
|
||||
}
|
||||
|
||||
if (_count) {
|
||||
if (_queue->lastAutoFence) {
|
||||
vkWaitForFences(_device->vkDevice, 1, &_queue->lastAutoFence, VK_TRUE, DEFAULT_FENCE_TIMEOUT);
|
||||
_queue->lastAutoFence = VK_NULL_HANDLE;
|
||||
}
|
||||
for (const Transfer &transfer : _transfers) {
|
||||
memcpy(transfer.dst, transfer.src, transfer.size);
|
||||
}
|
||||
_count = 0u;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
struct Transfer {
|
||||
void *dst = nullptr;
|
||||
const void *src = nullptr;
|
||||
size_t size = 0u;
|
||||
};
|
||||
|
||||
CCVKGPUDevice *_device = nullptr;
|
||||
|
||||
CCVKGPUQueue *_queue = nullptr;
|
||||
CCVKGPUFencePool *_fencePool = nullptr;
|
||||
CCVKGPUCommandBufferPool *_commandBufferPool = nullptr;
|
||||
|
||||
CCVKGPUCommandBuffer _cmdBuff;
|
||||
vector<Transfer> _transfers;
|
||||
uint _count = 0u;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace cc
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "VKStd.h"
|
||||
|
||||
#include "VKBuffer.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKCommands.h"
|
||||
#include "VKInputAssembler.h"
|
||||
|
||||
@@ -19,18 +20,19 @@ bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) {
|
||||
_vertexBuffers = info.vertexBuffers;
|
||||
_indexBuffer = info.indexBuffer;
|
||||
_indirectBuffer = info.indirectBuffer;
|
||||
size_t vbCount = _vertexBuffers.size();
|
||||
|
||||
if (_indexBuffer) {
|
||||
_indexCount = _indexBuffer->getCount();
|
||||
} else if (_vertexBuffers.size()) {
|
||||
} else if (vbCount) {
|
||||
_vertexCount = _vertexBuffers[0]->getCount();
|
||||
}
|
||||
|
||||
_gpuInputAssembler = CC_NEW(CCVKGPUInputAssembler);
|
||||
_gpuInputAssembler->attributes = _attributes;
|
||||
_gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size());
|
||||
_gpuInputAssembler->gpuVertexBuffers.resize(vbCount);
|
||||
|
||||
for (size_t i = 0u; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) {
|
||||
for (size_t i = 0u; i < vbCount; ++i) {
|
||||
CCVKBuffer *vb = (CCVKBuffer *)_vertexBuffers[i];
|
||||
_gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer();
|
||||
}
|
||||
@@ -43,7 +45,14 @@ bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) {
|
||||
_gpuInputAssembler->gpuIndirectBuffer = static_cast<CCVKBuffer *>(info.indirectBuffer)->gpuBuffer();
|
||||
}
|
||||
|
||||
CCVKCmdFuncCreateInputAssembler((CCVKDevice *)_device, _gpuInputAssembler);
|
||||
_gpuInputAssembler->vertexBuffers.resize(vbCount);
|
||||
_gpuInputAssembler->vertexBufferOffsets.resize(vbCount);
|
||||
|
||||
for (size_t i = 0u; i < vbCount; i++) {
|
||||
_gpuInputAssembler->vertexBuffers[i] = _gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer;
|
||||
_gpuInputAssembler->vertexBufferOffsets[i] = _gpuInputAssembler->gpuVertexBuffers[i]->startOffset;
|
||||
}
|
||||
|
||||
_attributesHash = computeAttributesHash();
|
||||
_status = Status::SUCCESS;
|
||||
|
||||
@@ -52,7 +61,8 @@ bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) {
|
||||
|
||||
void CCVKInputAssembler::destroy() {
|
||||
if (_gpuInputAssembler) {
|
||||
CCVKCmdFuncDestroyInputAssembler((CCVKDevice *)_device, _gpuInputAssembler);
|
||||
_gpuInputAssembler->vertexBuffers.clear();
|
||||
_gpuInputAssembler->vertexBufferOffsets.clear();
|
||||
CC_DELETE(_gpuInputAssembler);
|
||||
_gpuInputAssembler = nullptr;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "VKStd.h"
|
||||
|
||||
#include "VKCommands.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKPipelineState.h"
|
||||
#include "VKRenderPass.h"
|
||||
#include "VKShader.h"
|
||||
@@ -44,8 +45,7 @@ bool CCVKPipelineState::initialize(const PipelineStateInfo &info) {
|
||||
|
||||
void CCVKPipelineState::destroy() {
|
||||
if (_gpuPipelineState) {
|
||||
CCVKCmdFuncDestroyPipelineState((CCVKDevice *)_device, _gpuPipelineState);
|
||||
CC_DELETE(_gpuPipelineState);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuPipelineState);
|
||||
_gpuPipelineState = nullptr;
|
||||
}
|
||||
_status = Status::UNREADY;
|
||||
|
||||
@@ -18,7 +18,7 @@ CCVKQueue::~CCVKQueue() {
|
||||
|
||||
bool CCVKQueue::initialize(const QueueInfo &info) {
|
||||
_type = info.type;
|
||||
_isAsync = !info.forceSync;
|
||||
_isAsync = true;
|
||||
|
||||
_gpuQueue = CC_NEW(CCVKGPUQueue);
|
||||
_gpuQueue->type = _type;
|
||||
@@ -39,8 +39,9 @@ void CCVKQueue::destroy() {
|
||||
|
||||
void CCVKQueue::submit(const vector<CommandBuffer *> &cmdBuffs, Fence *fence) {
|
||||
CCVKDevice *device = (CCVKDevice *)_device;
|
||||
|
||||
_gpuQueue->commandBuffers.clear();
|
||||
device->gpuTransportHub()->depart();
|
||||
|
||||
uint count = cmdBuffs.size();
|
||||
for (uint i = 0u; i < count; ++i) {
|
||||
CCVKCommandBuffer *cmdBuffer = (CCVKCommandBuffer *)cmdBuffs[i];
|
||||
@@ -54,23 +55,24 @@ void CCVKQueue::submit(const vector<CommandBuffer *> &cmdBuffs, Fence *fence) {
|
||||
}
|
||||
|
||||
VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
submitInfo.waitSemaphoreCount = 1;
|
||||
submitInfo.waitSemaphoreCount = _gpuQueue->nextWaitSemaphore ? 1 : 0;
|
||||
submitInfo.pWaitSemaphores = &_gpuQueue->nextWaitSemaphore;
|
||||
submitInfo.pWaitDstStageMask = &_gpuQueue->submitStageMask;
|
||||
submitInfo.commandBufferCount = count;
|
||||
submitInfo.commandBufferCount = _gpuQueue->commandBuffers.size();
|
||||
submitInfo.pCommandBuffers = &_gpuQueue->commandBuffers[0];
|
||||
submitInfo.signalSemaphoreCount = 1;
|
||||
submitInfo.signalSemaphoreCount = _gpuQueue->nextSignalSemaphore ? 1 : 0;
|
||||
submitInfo.pSignalSemaphores = &_gpuQueue->nextSignalSemaphore;
|
||||
|
||||
if (_isAsync) {
|
||||
VkFence vkFence = fence ? ((CCVKFence *)fence)->gpuFence()->vkFence : VK_NULL_HANDLE;
|
||||
VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, vkFence));
|
||||
VkFence vkFence = VK_NULL_HANDLE;
|
||||
if (fence) {
|
||||
vkFence = ((CCVKFence *)fence)->gpuFence()->vkFence;
|
||||
} else {
|
||||
VkFence vkFence = fence ? ((CCVKFence *)fence)->gpuFence()->vkFence : device->gpuFencePool()->alloc();
|
||||
VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, vkFence));
|
||||
VK_CHECK(vkWaitForFences(device->gpuDevice()->vkDevice, 1, &vkFence, VK_TRUE, DEFAULT_FENCE_TIMEOUT));
|
||||
vkFence = device->gpuFencePool()->alloc();
|
||||
_gpuQueue->lastAutoFence = vkFence;
|
||||
}
|
||||
|
||||
VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, vkFence));
|
||||
|
||||
_gpuQueue->nextWaitSemaphore = _gpuQueue->nextSignalSemaphore;
|
||||
_gpuQueue->nextSignalSemaphore = device->gpuSemaphorePool()->alloc();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "VKStd.h"
|
||||
|
||||
#include "VKCommands.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKRenderPass.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -32,8 +33,7 @@ bool CCVKRenderPass::initialize(const RenderPassInfo &info) {
|
||||
|
||||
void CCVKRenderPass::destroy() {
|
||||
if (_gpuRenderPass) {
|
||||
CCVKCmdFuncDestroyRenderPass((CCVKDevice *)_device, _gpuRenderPass);
|
||||
CC_DELETE(_gpuRenderPass);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuRenderPass);
|
||||
_gpuRenderPass = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "VKStd.h"
|
||||
|
||||
#include "VKCommands.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKSampler.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -51,8 +52,7 @@ bool CCVKSampler::initialize(const SamplerInfo &info) {
|
||||
|
||||
void CCVKSampler::destroy() {
|
||||
if (_gpuSampler) {
|
||||
CCVKCmdFuncDestroySampler((CCVKDevice *)_device, _gpuSampler);
|
||||
CC_DELETE(_gpuSampler);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuSampler);
|
||||
_gpuSampler = nullptr;
|
||||
}
|
||||
_status = Status::UNREADY;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "VKStd.h"
|
||||
|
||||
#include "VKCommands.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKShader.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -38,8 +39,7 @@ bool CCVKShader::initialize(const ShaderInfo &info) {
|
||||
|
||||
void CCVKShader::destroy() {
|
||||
if (_gpuShader) {
|
||||
CCVKCmdFuncDestroyShader((CCVKDevice *)_device, _gpuShader);
|
||||
CC_DELETE(_gpuShader);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuShader);
|
||||
_gpuShader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "VKStd.h"
|
||||
|
||||
#include "VKCommands.h"
|
||||
#include "VKDevice.h"
|
||||
#include "VKTexture.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -20,8 +21,8 @@ bool CCVKTexture::initialize(const TextureInfo &info) {
|
||||
_width = info.width;
|
||||
_height = info.height;
|
||||
_depth = info.depth;
|
||||
_arrayLayer = info.arrayLayer;
|
||||
_mipLevel = info.mipLevel;
|
||||
_layerCount = info.layerCount;
|
||||
_levelCount = info.levelCount;
|
||||
_samples = info.samples;
|
||||
_flags = info.flags;
|
||||
_size = FormatSize(_format, _width, _height, _depth);
|
||||
@@ -72,8 +73,8 @@ bool CCVKTexture::initialize(const TextureInfo &info) {
|
||||
_gpuTexture->height = _height;
|
||||
_gpuTexture->depth = _depth;
|
||||
_gpuTexture->size = _size;
|
||||
_gpuTexture->arrayLayer = _arrayLayer;
|
||||
_gpuTexture->mipLevel = _mipLevel;
|
||||
_gpuTexture->arrayLayers = _layerCount;
|
||||
_gpuTexture->mipLevels = _levelCount;
|
||||
_gpuTexture->samples = _samples;
|
||||
_gpuTexture->flags = _flags;
|
||||
_gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height);
|
||||
@@ -81,62 +82,61 @@ bool CCVKTexture::initialize(const TextureInfo &info) {
|
||||
CCVKCmdFuncCreateTexture((CCVKDevice *)_device, _gpuTexture);
|
||||
_device->getMemoryStatus().textureSize += _size;
|
||||
|
||||
TextureViewInfo textureViewInfo;
|
||||
textureViewInfo.texture = this;
|
||||
textureViewInfo.type = _type;
|
||||
textureViewInfo.format = _format;
|
||||
textureViewInfo.baseLevel = 0;
|
||||
textureViewInfo.levelCount = _mipLevel;
|
||||
textureViewInfo.baseLayer = 0;
|
||||
textureViewInfo.layerCount = _arrayLayer;
|
||||
createTextureView(textureViewInfo);
|
||||
_gpuTextureView = CC_NEW(CCVKGPUTextureView);
|
||||
createTextureView();
|
||||
|
||||
_status = Status::SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCVKTexture::initialize(const TextureViewInfo &info) {
|
||||
if (info.texture) {
|
||||
_type = info.texture->getType();
|
||||
_format = info.texture->getFormat();
|
||||
_arrayLayer = info.texture->getArrayLayer();
|
||||
_mipLevel = info.texture->getMipLevel();
|
||||
_usage = info.texture->getUsage();
|
||||
_width = info.texture->getWidth();
|
||||
_height = info.texture->getHeight();
|
||||
_depth = info.texture->getDepth();
|
||||
_samples = info.texture->getSamples();
|
||||
_flags = info.texture->getFlags();
|
||||
_size = FormatSize(_format, _width, _height, _depth);
|
||||
if (!info.texture) {
|
||||
_status = Status::FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
createTextureView(info);
|
||||
_type = info.texture->getType();
|
||||
_format = info.format;
|
||||
_baseLayer = info.baseLayer;
|
||||
_layerCount = info.layerCount;
|
||||
_baseLevel = info.baseLevel;
|
||||
_levelCount = info.levelCount;
|
||||
_usage = info.texture->getUsage();
|
||||
_width = info.texture->getWidth();
|
||||
_height = info.texture->getHeight();
|
||||
_depth = info.texture->getDepth();
|
||||
_samples = info.texture->getSamples();
|
||||
_flags = info.texture->getFlags();
|
||||
_size = FormatSize(_format, _width, _height, _depth);
|
||||
|
||||
_gpuTexture = ((CCVKTexture *)info.texture)->gpuTexture();
|
||||
_gpuTextureView = CC_NEW(CCVKGPUTextureView);
|
||||
createTextureView();
|
||||
|
||||
_status = Status::SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCVKTexture::createTextureView(const TextureViewInfo &info) {
|
||||
if (!_gpuTextureView) {
|
||||
_gpuTextureView = CC_NEW(CCVKGPUTextureView);
|
||||
}
|
||||
_gpuTextureView->gpuTexture = info.texture ? static_cast<CCVKTexture *>(info.texture)->gpuTexture() : nullptr;
|
||||
_gpuTextureView->type = info.type;
|
||||
_gpuTextureView->format = info.format;
|
||||
_gpuTextureView->baseLevel = info.baseLevel;
|
||||
_gpuTextureView->levelCount = info.levelCount;
|
||||
void CCVKTexture::createTextureView() {
|
||||
_gpuTextureView->gpuTexture = _gpuTexture;
|
||||
_gpuTextureView->type = _type;
|
||||
_gpuTextureView->format = _format;
|
||||
_gpuTextureView->baseLevel = _baseLevel;
|
||||
_gpuTextureView->levelCount = _levelCount;
|
||||
_gpuTextureView->baseLayer = _baseLayer;
|
||||
_gpuTextureView->layerCount = _layerCount;
|
||||
CCVKCmdFuncCreateTextureView((CCVKDevice *)_device, _gpuTextureView);
|
||||
}
|
||||
|
||||
void CCVKTexture::destroy() {
|
||||
if (_gpuTextureView) {
|
||||
CCVKCmdFuncDestroyTextureView((CCVKDevice *)_device, _gpuTextureView);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTextureView);
|
||||
CC_DELETE(_gpuTextureView);
|
||||
_gpuTextureView = nullptr;
|
||||
}
|
||||
|
||||
if (_gpuTexture) {
|
||||
CCVKCmdFuncDestroyTexture((CCVKDevice *)_device, _gpuTexture);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture);
|
||||
_device->getMemoryStatus().textureSize -= _size;
|
||||
CC_DELETE(_gpuTexture);
|
||||
_gpuTexture = nullptr;
|
||||
@@ -158,17 +158,18 @@ void CCVKTexture::resize(uint width, uint height) {
|
||||
_height = height;
|
||||
_size = size;
|
||||
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTextureView);
|
||||
((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture);
|
||||
|
||||
MemoryStatus &status = _device->getMemoryStatus();
|
||||
_gpuTexture->width = _width;
|
||||
_gpuTexture->height = _height;
|
||||
_gpuTexture->size = _size;
|
||||
CCVKCmdFuncResizeTexture((CCVKDevice *)_device, _gpuTexture);
|
||||
|
||||
CCVKCmdFuncCreateTexture((CCVKDevice *)_device, _gpuTexture);
|
||||
status.bufferSize -= old_size;
|
||||
status.bufferSize += _size;
|
||||
|
||||
CCVKCmdFuncDestroyTextureView((CCVKDevice *)_device, _gpuTextureView);
|
||||
|
||||
_gpuTextureView->gpuTexture = _gpuTexture;
|
||||
CCVKCmdFuncCreateTextureView((CCVKDevice *)_device, _gpuTextureView);
|
||||
|
||||
if (_buffer) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
CC_INLINE CCVKGPUTextureView *gpuTextureView() const { return _gpuTextureView; }
|
||||
|
||||
private:
|
||||
void createTextureView(const TextureViewInfo &info);
|
||||
void createTextureView();
|
||||
|
||||
CCVKGPUTexture *_gpuTexture = nullptr;
|
||||
CCVKGPUTextureView *_gpuTextureView = nullptr;
|
||||
|
||||
@@ -3483,7 +3483,7 @@ static bool js_gfx_TextureInfo_get_arrayLayer(se::State& s)
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::Value jsret;
|
||||
ok &= uint32_to_seval((unsigned int)cobj->arrayLayer, &jsret);
|
||||
ok &= uint32_to_seval((unsigned int)cobj->layerCount, &jsret);
|
||||
s.rval() = jsret;
|
||||
return true;
|
||||
}
|
||||
@@ -3499,7 +3499,7 @@ static bool js_gfx_TextureInfo_set_arrayLayer(se::State& s)
|
||||
unsigned int arg0 = 0;
|
||||
ok &= seval_to_uint32(args[0], (uint32_t*)&arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_TextureInfo_set_arrayLayer : Error processing new value");
|
||||
cobj->arrayLayer = arg0;
|
||||
cobj->layerCount = arg0;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_gfx_TextureInfo_set_arrayLayer)
|
||||
@@ -3511,7 +3511,7 @@ static bool js_gfx_TextureInfo_get_mipLevel(se::State& s)
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::Value jsret;
|
||||
ok &= uint32_to_seval((unsigned int)cobj->mipLevel, &jsret);
|
||||
ok &= uint32_to_seval((unsigned int)cobj->levelCount, &jsret);
|
||||
s.rval() = jsret;
|
||||
return true;
|
||||
}
|
||||
@@ -3527,7 +3527,7 @@ static bool js_gfx_TextureInfo_set_mipLevel(se::State& s)
|
||||
unsigned int arg0 = 0;
|
||||
ok &= seval_to_uint32(args[0], (uint32_t*)&arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_TextureInfo_set_mipLevel : Error processing new value");
|
||||
cobj->mipLevel = arg0;
|
||||
cobj->levelCount = arg0;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_gfx_TextureInfo_set_mipLevel)
|
||||
@@ -3649,13 +3649,13 @@ static bool js_gfx_TextureInfo_constructor(se::State& s)
|
||||
json->getProperty("arrayLayer", &field);
|
||||
if(!field.isUndefined()) {
|
||||
ok &= seval_to_uint32(field, (uint32_t*)&arg6);
|
||||
cobj->arrayLayer = arg6;
|
||||
cobj->layerCount = arg6;
|
||||
}
|
||||
unsigned int arg7 = 0;
|
||||
json->getProperty("mipLevel", &field);
|
||||
if(!field.isUndefined()) {
|
||||
ok &= seval_to_uint32(field, (uint32_t*)&arg7);
|
||||
cobj->mipLevel = arg7;
|
||||
cobj->levelCount = arg7;
|
||||
}
|
||||
cc::gfx::SampleCount arg8;
|
||||
json->getProperty("samples", &field);
|
||||
@@ -3716,12 +3716,12 @@ static bool js_gfx_TextureInfo_constructor(se::State& s)
|
||||
unsigned int arg6 = 0;
|
||||
if (!args[6].isUndefined()) {
|
||||
ok &= seval_to_uint32(args[6], (uint32_t*)&arg6);
|
||||
cobj->arrayLayer = arg6;
|
||||
cobj->layerCount = arg6;
|
||||
}
|
||||
unsigned int arg7 = 0;
|
||||
if (!args[7].isUndefined()) {
|
||||
ok &= seval_to_uint32(args[7], (uint32_t*)&arg7);
|
||||
cobj->mipLevel = arg7;
|
||||
cobj->levelCount = arg7;
|
||||
}
|
||||
cc::gfx::SampleCount arg8;
|
||||
if (!args[8].isUndefined()) {
|
||||
@@ -11165,34 +11165,6 @@ static bool js_gfx_QueueInfo_set_type(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_SET(js_gfx_QueueInfo_set_type)
|
||||
|
||||
static bool js_gfx_QueueInfo_get_forceSync(se::State& s)
|
||||
{
|
||||
cc::gfx::QueueInfo* cobj = (cc::gfx::QueueInfo*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_gfx_QueueInfo_get_forceSync : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::Value jsret;
|
||||
ok &= boolean_to_seval(cobj->forceSync, &jsret);
|
||||
s.rval() = jsret;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_QueueInfo_get_forceSync)
|
||||
|
||||
static bool js_gfx_QueueInfo_set_forceSync(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
cc::gfx::QueueInfo* cobj = (cc::gfx::QueueInfo*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_gfx_QueueInfo_set_forceSync : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_QueueInfo_set_forceSync : Error processing new value");
|
||||
cobj->forceSync = arg0;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_gfx_QueueInfo_set_forceSync)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_QueueInfo_finalize)
|
||||
|
||||
static bool js_gfx_QueueInfo_constructor(se::State& s)
|
||||
@@ -11208,36 +11180,7 @@ static bool js_gfx_QueueInfo_constructor(se::State& s)
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
else if(argc == 1 && args[0].isObject())
|
||||
{
|
||||
se::Object *json = args[0].toObject();
|
||||
se::Value field;
|
||||
|
||||
cc::gfx::QueueInfo* cobj = JSB_ALLOC(cc::gfx::QueueInfo);
|
||||
cc::gfx::QueueType arg0;
|
||||
json->getProperty("type", &field);
|
||||
if(!field.isUndefined()) {
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::QueueType)tmp; } while(false);
|
||||
cobj->type = arg0;
|
||||
}
|
||||
bool arg1;
|
||||
json->getProperty("forceSync", &field);
|
||||
if(!field.isUndefined()) {
|
||||
ok &= seval_to_boolean(field, &arg1);
|
||||
cobj->forceSync = arg1;
|
||||
}
|
||||
|
||||
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 == 2)
|
||||
else if(argc == 1)
|
||||
{
|
||||
cc::gfx::QueueInfo* cobj = JSB_ALLOC(cc::gfx::QueueInfo);
|
||||
cc::gfx::QueueType arg0;
|
||||
@@ -11245,11 +11188,6 @@ static bool js_gfx_QueueInfo_constructor(se::State& s)
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::QueueType)tmp; } while(false);
|
||||
cobj->type = arg0;
|
||||
}
|
||||
bool arg1;
|
||||
if (!args[1].isUndefined()) {
|
||||
ok &= seval_to_boolean(args[1], &arg1);
|
||||
cobj->forceSync = arg1;
|
||||
}
|
||||
|
||||
if(!ok) {
|
||||
JSB_FREE(cobj);
|
||||
@@ -11288,7 +11226,6 @@ bool js_register_gfx_QueueInfo(se::Object* obj)
|
||||
auto cls = se::Class::create("QueueInfo", obj, nullptr, _SE(js_gfx_QueueInfo_constructor));
|
||||
|
||||
cls->defineProperty("type", _SE(js_gfx_QueueInfo_get_type), _SE(js_gfx_QueueInfo_set_type));
|
||||
cls->defineProperty("forceSync", _SE(js_gfx_QueueInfo_get_forceSync), _SE(js_gfx_QueueInfo_set_forceSync));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_QueueInfo_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cc::gfx::QueueInfo>(cls);
|
||||
@@ -12113,6 +12050,24 @@ static bool js_gfx_Device_getWidth(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Device_getWidth)
|
||||
|
||||
static bool js_gfx_Device_getScreenSpaceSignY(se::State& s)
|
||||
{
|
||||
cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_gfx_Device_getScreenSpaceSignY : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
float result = cobj->getScreenSpaceSignY();
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_Device_getScreenSpaceSignY : 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_getScreenSpaceSignY)
|
||||
|
||||
static bool js_gfx_Device_getQueue(se::State& s)
|
||||
{
|
||||
cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject();
|
||||
@@ -12752,24 +12707,6 @@ static bool js_gfx_Device_getMemoryStatus(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Device_getMemoryStatus)
|
||||
|
||||
static bool js_gfx_Device_getClipSpaceSignY(se::State& s)
|
||||
{
|
||||
cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_gfx_Device_getClipSpaceSignY : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
float result = cobj->getClipSpaceSignY();
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_Device_getClipSpaceSignY : 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_getClipSpaceSignY)
|
||||
|
||||
static bool js_gfx_Device_getMaxTextureUnits(se::State& s)
|
||||
{
|
||||
cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject();
|
||||
@@ -12912,9 +12849,9 @@ bool js_register_gfx_Device(se::Object* obj)
|
||||
cls->defineProperty("maxUniformBlockSize", _SE(js_gfx_Device_getMaxUniformBlockSize), nullptr);
|
||||
cls->defineProperty("maxTextureSize", _SE(js_gfx_Device_getMaxTextureSize), nullptr);
|
||||
cls->defineProperty("nativeHeight", _SE(js_gfx_Device_getNativeHeight), nullptr);
|
||||
cls->defineProperty("clipSpaceSignY", _SE(js_gfx_Device_getClipSpaceSignY), nullptr);
|
||||
cls->defineProperty("depthStencilFormat", _SE(js_gfx_Device_getDepthStencilFormat), nullptr);
|
||||
cls->defineProperty("numTris", _SE(js_gfx_Device_getNumTris), nullptr);
|
||||
cls->defineProperty("screenSpaceSignY", _SE(js_gfx_Device_getScreenSpaceSignY), nullptr);
|
||||
cls->defineProperty("stencilBits", _SE(js_gfx_Device_getStencilBits), nullptr);
|
||||
cls->defineProperty("queue", _SE(js_gfx_Device_getQueue), nullptr);
|
||||
cls->defineProperty("context", _SE(js_gfx_Device_getContext), nullptr);
|
||||
@@ -13321,7 +13258,7 @@ static bool js_gfx_Texture_getMipLevel(se::State& s)
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
unsigned int result = cobj->getMipLevel();
|
||||
unsigned int result = cobj->getLevelCount();
|
||||
ok &= uint32_to_seval((unsigned int)result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_Texture_getMipLevel : Error processing arguments");
|
||||
return true;
|
||||
@@ -13339,7 +13276,7 @@ static bool js_gfx_Texture_getArrayLayer(se::State& s)
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
unsigned int result = cobj->getArrayLayer();
|
||||
unsigned int result = cobj->getLayerCount();
|
||||
ok &= uint32_to_seval((unsigned int)result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_Texture_getArrayLayer : Error processing arguments");
|
||||
return true;
|
||||
@@ -15397,31 +15334,6 @@ static bool js_gfx_CommandBuffer_setDepthBound(se::State& s)
|
||||
}
|
||||
SE_BIND_FUNC(js_gfx_CommandBuffer_setDepthBound)
|
||||
|
||||
static bool js_gfx_CommandBuffer_copyBufferToTexture(se::State& s)
|
||||
{
|
||||
cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_copyBufferToTexture : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 4) {
|
||||
cc::gfx::Buffer* arg0 = nullptr;
|
||||
cc::gfx::Texture* arg1 = nullptr;
|
||||
cc::gfx::TextureLayout arg2;
|
||||
std::vector<cc::gfx::BufferTextureCopy> arg3;
|
||||
ok &= seval_to_native_ptr(args[0], &arg0);
|
||||
ok &= seval_to_native_ptr(args[1], &arg1);
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[2], &tmp); arg2 = (cc::gfx::TextureLayout)tmp; } while(false);
|
||||
ok &= seval_to_std_vector(args[3], &arg3);
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_copyBufferToTexture : Error processing arguments");
|
||||
cobj->copyBufferToTexture(arg0, arg1, arg2, arg3);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 4);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_gfx_CommandBuffer_copyBufferToTexture)
|
||||
|
||||
static bool js_gfx_CommandBuffer_getQueue(se::State& s)
|
||||
{
|
||||
cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject();
|
||||
@@ -15919,7 +15831,6 @@ bool js_register_gfx_CommandBuffer(se::Object* obj)
|
||||
cls->defineFunction("draw", _SE(js_gfx_CommandBuffer_draw));
|
||||
cls->defineFunction("setBlendConstants", _SE(js_gfx_CommandBuffer_setBlendConstants));
|
||||
cls->defineFunction("setDepthBound", _SE(js_gfx_CommandBuffer_setDepthBound));
|
||||
cls->defineFunction("copyBufferToTexture", _SE(js_gfx_CommandBuffer_copyBufferToTexture));
|
||||
cls->defineFunction("getQueue", _SE(js_gfx_CommandBuffer_getQueue));
|
||||
cls->defineFunction("setLineWidth", _SE(js_gfx_CommandBuffer_setLineWidth));
|
||||
cls->defineFunction("updateBuffer", _SE(js_gfx_CommandBuffer_updateBuffer));
|
||||
|
||||
@@ -369,7 +369,6 @@ bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_CommandBuffer_draw);
|
||||
SE_DECLARE_FUNC(js_gfx_CommandBuffer_setBlendConstants);
|
||||
SE_DECLARE_FUNC(js_gfx_CommandBuffer_setDepthBound);
|
||||
SE_DECLARE_FUNC(js_gfx_CommandBuffer_copyBufferToTexture);
|
||||
SE_DECLARE_FUNC(js_gfx_CommandBuffer_getQueue);
|
||||
SE_DECLARE_FUNC(js_gfx_CommandBuffer_setLineWidth);
|
||||
SE_DECLARE_FUNC(js_gfx_CommandBuffer_updateBuffer);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"version": "v3d-gfx-20",
|
||||
"version": "v3d-gfx-22",
|
||||
"from": {
|
||||
"type": "github",
|
||||
"owner": "cocos-creator",
|
||||
"name": "cocos2d-x-lite-external",
|
||||
"checkout": "v3d-gfx-20"
|
||||
"checkout": "v3d-gfx-22"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ classes_need_extend =
|
||||
|
||||
skip = BindingLayout::[BindingLayout],
|
||||
Buffer::[Buffer update],
|
||||
CommandBuffer::[CommandBuffer execute],
|
||||
CommandBuffer::[CommandBuffer execute copyBuffersToTexture],
|
||||
Framebuffer::[Framebuffer],
|
||||
InputAssembler::[InputAssembler extractDrawInfo],
|
||||
PipelineState::[PipelineState],
|
||||
@@ -59,9 +59,9 @@ skip = BindingLayout::[BindingLayout],
|
||||
Device::[copyBuffersToTexture createTexture],
|
||||
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 clipSpaceSignY 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 depthBits stencilBits shaderIdGen colorFormat depthStencilFormat clipSpaceMinZ screenSpaceSignY UVSpaceSignY],
|
||||
Shader::[device name hash stages attributes blocks samplers],
|
||||
Texture::[type usage format width height depth arrayLayer mipLevel size samples flags buffer],
|
||||
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],
|
||||
|
||||
@@ -44,7 +44,7 @@ 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 = CCVKDevice::[copyBuffersToTexture gpuContext gpuDevice gpuSwapchain gpuSemaphorePool gpuFencePool gpuDescriptorSetPool gpuCommandBufferPool stagingBuffer getLayers getExtensions isSwapchainReady isDescriptorUpdateTemplateSupported isPushDescriptorSetSupported isMultiDrawIndirectSupported]
|
||||
skip = CCVKDevice::[copyBuffersToTexture gpuContext gpuDevice gpuSwapchain gpuFencePool gpuRecycleBin gpuTransportHub gpuSemaphorePool gpuDescriptorSetPool gpuCommandBufferPool gpuStagingBufferPool getLayers getExtensions isSwapchainReady isDescriptorUpdateTemplateSupported isPushDescriptorSetSupported isMultiDrawIndirectSupported]
|
||||
|
||||
getter_setter =
|
||||
|
||||
|
||||
Reference in New Issue
Block a user