Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Metal backend的 BufferMTL有一个函数是不是实现的有问题? #20583

Open
breakerrorchen opened this issue Sep 16, 2020 · 6 comments
Open

Comments

@breakerrorchen
Copy link

void BufferMTL::updateSubData(void* data, std::size_t offset, std::size_t size)
{
assert(offset + size <= _size);
updateIndex();
memcpy((uint8_t*)_mtlBuffer.contents + offset, data, size);
}

这个函数在GL的backend里面是更新局部数据,没有更新的部分保留上一次提交的数据,但是在Metal的backend里面如果 updataIndex成功后拿到一个新的buffer,但是只是修改了offset后面的一部分数据。这样如果使用,就会出现GL的Buffer和Metal的Buffer数据不一致的问题

@breakerrorchen
Copy link
Author

比如 第一帧的时候 我对一个Buffer做了UpdateData操作,在第二帧里面我调用 UpdateSubData 函数, 这样这个Buffer就和我期待的数据不一致了

@Mee-gu
Copy link
Contributor

Mee-gu commented Sep 16, 2020

之所以使用 triple buffering,就是为了防止下一帧的数据覆盖当前帧 buffer 里的内容,导致 GPU 在绘制时,出现 write-after-read 的情况

@breakerrorchen
Copy link
Author

@Mee-gu 我能理解这块,但是我第一帧 updateData后设置一些数据,第二帧只修改了部分数据,我的期望是修改的部分是新的数据,没有修改的数据是旧的数据。

现在的Cocos的设计用来三缓冲,也是相邻的两帧不可以使用同样的buffer。但是第二帧我只更新了部分数据,我期待没有修改的数据和第一帧的时候buffer的数据是一样的。

但是实际上并不是这样。不是么?

@breakerrorchen
Copy link
Author

@minggo 指导一下呗

@Mee-gu
Copy link
Contributor

Mee-gu commented Sep 17, 2020

修复了:cocos2d-x/pull/20585

@breakerrorchen
Copy link
Author

@Mee-gu 点赞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants