update binding mapping info (#2777)

This commit is contained in:
Yun Hsiao Wu
2020-09-11 11:12:32 +08:00
committed by GitHub
parent 59d567bcbb
commit 577e3375e2
12 changed files with 73 additions and 45 deletions
+8 -3
View File
@@ -1088,12 +1088,17 @@ if(CC_USE_VULKAN)
else()
target_compile_definitions(cocos2d PUBLIC VK_USE_PLATFORM_XCB_KHR)
endif()
endif()
elseif(CC_USE_METAL)
if(CC_USE_METAL)
target_compile_definitions(cocos2d PUBLIC CC_USE_METAL)
elseif(CC_USE_GLES3)
endif()
if(CC_USE_GLES3)
target_compile_definitions(cocos2d PUBLIC CC_USE_GLES3)
elseif(CC_USE_GLES2)
endif()
if(CC_USE_GLES2)
target_compile_definitions(cocos2d PUBLIC CC_USE_GLES2)
endif()
@@ -72,6 +72,11 @@ static bool js_gfx_BindingMappingInfo_constructor(se::State &s) {
ok &= seval_to_std_vector(field, &cobj->samplerOffsets);
}
json->getProperty("flexibleSet", &field);
if (!field.isUndefined()) {
ok &= seval_to_uint32(field, &cobj->flexibleSet);
}
if (!ok) {
JSB_FREE(cobj);
SE_REPORT_ERROR("Argument convertion error");
+2 -5
View File
@@ -23,10 +23,7 @@ class Queue;
class Window;
class Context;
#define GFX_MAX_VERTEX_ATTRIBUTES 16
#define GFX_MAX_TEXTURE_UNITS 16
#define GFX_MAX_ATTACHMENTS 4
#define GFX_MAX_BUFFER_BINDINGS 24
#define GFX_INVALID_BINDING ((uint8_t)-1)
#define GFX_INVALID_HANDLE ((uint)-1)
#define MAX_INFLIGHT_BUFFER 3
@@ -666,8 +663,8 @@ typedef vector<Color> ColorList;
* exact offsets for each descriptor type in each set.
*/
struct BindingMappingInfo {
vector<uint> bufferOffsets;
vector<uint> samplerOffsets;
vector<int> bufferOffsets;
vector<int> samplerOffsets;
uint flexibleSet = 0u;
};
+1 -1
View File
@@ -101,7 +101,7 @@ protected:
uint _maxFragmentUniformVectors = 0u;
uint _maxTextureUnits = 0u;
uint _maxVertexTextureUnits = 0u;
uint _maxUniformBufferBindings = GFX_MAX_BUFFER_BINDINGS;
uint _maxUniformBufferBindings = 0u;
uint _maxUniformBlockSize = 0u;
uint _maxTextureSize = 0u;
uint _maxCubeMapTextureSize = 0u;
@@ -1049,7 +1049,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) {
for (uint i = 0u; i < gpuShader->samplers.size(); i++) {
const UniformSampler &sampler = gpuShader->samplers[i];
uint glLoc = glGetUniformLocation(gpuShader->glProgram, sampler.name.c_str());
GLint glLoc = glGetUniformLocation(gpuShader->glProgram, sampler.name.c_str());
if (glLoc >= 0) {
glActiveSamplers.push_back(gpuShader->glSamplers[i]);
glActiveSamplerLocations.push_back(glLoc);
@@ -1063,7 +1063,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) {
}
if (glActiveSamplers.size()) {
bool usedTexUnits[GFX_MAX_TEXTURE_UNITS]{};
vector<bool> usedTexUnits(device->getMaxTextureUnits(), false);
// try to reuse existing mappings first
for (uint i = 0u; i < glActiveSamplers.size(); i++) {
GLES2GPUUniformSampler &glSampler = glActiveSamplers[i];
@@ -1147,7 +1147,7 @@ void GLES2CmdFuncCreateInputAssembler(GLES2Device *device, GLES2GPUInputAssemble
}
}
uint streamOffsets[GFX_MAX_VERTEX_ATTRIBUTES] = {0};
vector<uint> streamOffsets(device->getMaxVertexAttributes(), 0u);
gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size());
for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) {
@@ -1965,7 +1965,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
cache->glVAO = glVAO;
}
} else {
for (uint a = 0; a < GFX_MAX_VERTEX_ATTRIBUTES; ++a) {
for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) {
cache->glCurrentAttribLocs[a] = false;
}
@@ -2003,7 +2003,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
}
}
for (uint a = 0; a < GFX_MAX_VERTEX_ATTRIBUTES; ++a) {
for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) {
if (cache->glEnabledAttribLocs[a] != cache->glCurrentAttribLocs[a]) {
glDisableVertexAttribArray(a);
cache->glEnabledAttribLocs[a] = false;
@@ -143,6 +143,8 @@ bool GLES2Device::initialize(const DeviceInfo &info) {
glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_stencilBits);
_uboOffsetAlignment = 1u;
stateCache->initialize(_maxTextureUnits, _maxVertexAttributes);
return true;
}
@@ -11,14 +11,12 @@ public:
GLuint glArrayBuffer = 0;
GLuint glElementArrayBuffer = 0;
GLuint glUniformBuffer = 0;
GLuint glBindUBOs[GFX_MAX_BUFFER_BINDINGS] = {0};
GLuint glVAO = 0;
uint texUint = 0;
GLuint glTextures[GFX_MAX_TEXTURE_UNITS] = {0};
GLuint glSamplers[GFX_MAX_TEXTURE_UNITS] = {0};
vector<GLuint> glTextures;
GLuint glProgram = 0;
bool glEnabledAttribLocs[GFX_MAX_VERTEX_ATTRIBUTES] = {false};
bool glCurrentAttribLocs[GFX_MAX_VERTEX_ATTRIBUTES] = {false};
vector<bool> glEnabledAttribLocs;
vector<bool> glCurrentAttribLocs;
GLuint glFramebuffer = 0;
GLuint glReadFBO = 0;
Viewport viewport;
@@ -30,7 +28,11 @@ public:
bool isStencilTestEnabled = false;
map<String, uint> texUnitCacheMap;
GLES2StateCache() {}
void initialize(size_t texUnits, size_t vertexAttributes) {
glTextures.resize(texUnits, 0u);
glEnabledAttribLocs.resize(vertexAttributes, false);
glCurrentAttribLocs.resize(vertexAttributes, false);
}
};
} // namespace gfx
@@ -574,8 +574,8 @@ void GLES3CmdFuncDestroyBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) {
device->stateCache->glElementArrayBuffer = 0;
}
} else if (gpuBuffer->usage & BufferUsageBit::UNIFORM) {
GLuint *ubo = device->stateCache->glBindUBOs;
for (auto i = 0; i < GFX_MAX_BUFFER_BINDINGS; i++) {
vector<GLuint> &ubo = device->stateCache->glBindUBOs;
for (size_t i = 0; i < ubo.size(); i++) {
if (ubo[i] == gpuBuffer->glBuffer) {
glBindBufferBase(GL_UNIFORM_BUFFER, i, 0);
device->stateCache->glUniformBuffer = 0;
@@ -1146,7 +1146,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) {
for (uint i = 0u; i < gpuShader->samplers.size(); i++) {
const UniformSampler &sampler = gpuShader->samplers[i];
uint glLoc = glGetUniformLocation(gpuShader->glProgram, sampler.name.c_str());
GLint glLoc = glGetUniformLocation(gpuShader->glProgram, sampler.name.c_str());
if (glLoc >= 0) {
glActiveSamplers.push_back(gpuShader->glSamplers[i]);
glActiveSamplerLocations.push_back(glLoc);
@@ -1160,7 +1160,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) {
}
if (glActiveSamplers.size()) {
bool usedTexUnits[GFX_MAX_TEXTURE_UNITS]{};
vector<bool> usedTexUnits(device->getMaxTextureUnits(), false);
// try to reuse existing mappings first
for (uint i = 0u; i < glActiveSamplers.size(); i++) {
GLES3GPUUniformSampler &glSampler = glActiveSamplers[i];
@@ -1168,10 +1168,12 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) {
if (texUnitCacheMap.count(glSampler.name)) {
uint cachedUnit = texUnitCacheMap[glSampler.name];
glSampler.glLoc = glActiveSamplerLocations[i];
for (uint t = 0u, offset = 0u; t < glSampler.count; t++) {
while (usedTexUnits[cachedUnit + t + offset]) offset++;
glSampler.units.push_back(cachedUnit + t + offset);
usedTexUnits[cachedUnit + t + offset] = true;
for (uint t = 0u; t < glSampler.count; t++) {
while (usedTexUnits[cachedUnit]) {
cachedUnit = (cachedUnit + 1) % device->getMaxTextureUnits();
}
glSampler.units.push_back(cachedUnit);
usedTexUnits[cachedUnit] = true;
}
}
}
@@ -1183,12 +1185,14 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) {
if (glSampler.glLoc < 0) {
glSampler.glLoc = glActiveSamplerLocations[i];
for (uint t = 0u; t < glSampler.count; t++) {
while (usedTexUnits[unitIdx + t]) unitIdx++;
glSampler.units.push_back(unitIdx + t);
usedTexUnits[unitIdx + t] = true;
}
if (!texUnitCacheMap.count(glSampler.name)) {
texUnitCacheMap[glSampler.name] = unitIdx;
while (usedTexUnits[unitIdx]) {
unitIdx = (unitIdx + 1) % device->getMaxTextureUnits();
}
if (!texUnitCacheMap.count(glSampler.name)) {
texUnitCacheMap[glSampler.name] = unitIdx;
}
glSampler.units.push_back(unitIdx);
usedTexUnits[unitIdx] = true;
}
}
}
@@ -1236,7 +1240,7 @@ void GLES3CmdFuncCreateInputAssembler(GLES3Device *device, GLES3GPUInputAssemble
}
}
uint streamOffsets[GFX_MAX_VERTEX_ATTRIBUTES] = {0};
vector<uint> streamOffsets(device->getMaxVertexAttributes(), 0u);
gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size());
for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) {
@@ -1915,7 +1919,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
cache->glVAO = glVAO;
}
} else {
for (uint a = 0; a < GFX_MAX_VERTEX_ATTRIBUTES; ++a) {
for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) {
cache->glCurrentAttribLocs[a] = false;
}
@@ -1950,7 +1954,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
}
}
for (uint a = 0; a < GFX_MAX_VERTEX_ATTRIBUTES; ++a) {
for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) {
if (cache->glEnabledAttribLocs[a] != cache->glCurrentAttribLocs[a]) {
glDisableVertexAttribArray(a);
cache->glEnabledAttribLocs[a] = false;
@@ -139,6 +139,8 @@ bool GLES3Device::initialize(const DeviceInfo &info) {
glGetIntegerv(GL_DEPTH_BITS, (GLint *)&_depthBits);
glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_stencilBits);
stateCache->initialize(_maxTextureUnits, _maxUniformBufferBindings, _maxVertexAttributes);
return true;
}
@@ -11,15 +11,15 @@ public:
GLuint glArrayBuffer = 0;
GLuint glElementArrayBuffer = 0;
GLuint glUniformBuffer = 0;
GLuint glBindUBOs[GFX_MAX_BUFFER_BINDINGS] = {0};
GLuint glBindUBOOffsets[GFX_MAX_BUFFER_BINDINGS] = {0};
vector<GLuint> glBindUBOs;
vector<GLuint> glBindUBOOffsets;
GLuint glVAO = 0;
uint texUint = 0;
GLuint glTextures[GFX_MAX_TEXTURE_UNITS] = {0};
GLuint glSamplers[GFX_MAX_TEXTURE_UNITS] = {0};
vector<GLuint> glTextures;
vector<GLuint> glSamplers;
GLuint glProgram = 0;
bool glEnabledAttribLocs[GFX_MAX_VERTEX_ATTRIBUTES] = {false};
bool glCurrentAttribLocs[GFX_MAX_VERTEX_ATTRIBUTES] = {false};
vector<bool> glEnabledAttribLocs;
vector<bool> glCurrentAttribLocs;
GLuint glFramebuffer = 0;
GLuint glReadFBO = 0;
Viewport viewport;
@@ -31,7 +31,14 @@ public:
bool isStencilTestEnabled = false;
map<String, uint> texUnitCacheMap;
GLES3StateCache() {}
void initialize(size_t texUnits, size_t bufferBindings, size_t vertexAttributes) {
glBindUBOs.resize(bufferBindings, 0u);
glBindUBOOffsets.resize(bufferBindings, 0u);
glTextures.resize(texUnits, 0u);
glSamplers.resize(texUnits, 0u);
glEnabledAttribLocs.resize(vertexAttributes, false);
glCurrentAttribLocs.resize(vertexAttributes, false);
}
};
} // namespace gfx
@@ -144,7 +144,7 @@ void CCMTLPipelineState::setVertexDescriptor(MTLRenderPipelineDescriptor *descri
vector<std::tuple<int /**vertexBufferBindingIndex*/, uint /**stream*/>> layouts;
unordered_map<int /**vertexBufferBindingIndex*/, std::tuple<uint /**stride*/, bool /**isInstanced*/>> map;
uint streamOffsets[GFX_MAX_VERTEX_ATTRIBUTES] = {0};
vector<uint> streamOffsets(_device->getMaxVertexAttributes(), 0u);
bool attributeFound = false;
for (const auto &activeAttribute : activeAttributes) {
attributeFound = false;
@@ -29,6 +29,10 @@ android {
jniLibs.srcDirs "../libs", 'libs'
manifest.srcFile "AndroidManifest.xml"
assets.srcDir "assets"
jniLibs {
// Vulkan validation layer
// srcDir "${android.ndkDirectory}/sources/third_party/vulkan/src/build-android/jniLibs"
}
}
externalNativeBuild {