mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Improvement] (All): Better assertion.
This commit is contained in:
@@ -17,9 +17,11 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void BufferObject::UploadData(DataPtr data, SizeT atOffset) {
|
||||
assert(atOffset + data.size <= m_size);
|
||||
assert(!m_isMapped);
|
||||
memcpy(m_dataPtr->data() + atOffset, data.data, data.size);
|
||||
MOBILEGL_ASSERT(atOffset + data.size <= m_size,
|
||||
"UploadData out of bounds: atOffset (%zu) + data.size (%zu) > m_size (%zu)", atOffset,
|
||||
data.size, m_size);
|
||||
MOBILEGL_ASSERT(!m_isMapped, "Cannot upload data while buffer is mapped.");
|
||||
Memcpy(m_dataPtr->data() + atOffset, data.data, data.size);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
|
||||
@@ -32,7 +34,7 @@ namespace MobileGL {
|
||||
|
||||
if (m_mappingAccess & BufferMappingAccessBit::Write) { // if we wrote to the buffer
|
||||
if (!(m_mappingAccess & BufferMappingAccessBit::FlushExplicit)) { // if we didn't flush explicitly
|
||||
memcpy(m_dataPtr->data() + m_mappedRange.start, m_stagingData.data(),
|
||||
Memcpy(m_dataPtr->data() + m_mappedRange.start, m_stagingData.data(),
|
||||
m_mappedRange.end - m_mappedRange.start);
|
||||
m_dirtyRange.UnionUpdate(m_mappedRange.start, m_mappedRange.end);
|
||||
}
|
||||
@@ -47,35 +49,44 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void BufferObject::FlushMemoryRange(SizeT offset, SizeT length) {
|
||||
assert(m_isMapped);
|
||||
assert((m_mappingAccess & BufferMappingAccessBit::FlushExplicit));
|
||||
assert((m_mappingAccess & BufferMappingAccessBit::Write));
|
||||
MOBILEGL_ASSERT(m_isMapped, "Buffer must be mapped to flush memory range.");
|
||||
MOBILEGL_ASSERT((m_mappingAccess & BufferMappingAccessBit::FlushExplicit),
|
||||
"Buffer must be mapped with FlushExplicit access to flush memory range.");
|
||||
MOBILEGL_ASSERT((m_mappingAccess & BufferMappingAccessBit::Write),
|
||||
"Buffer must be mapped with Write access to flush memory range.");
|
||||
|
||||
SizeT start = m_mappedRange.start + offset;
|
||||
SizeT end = start + length;
|
||||
assert(end <= m_mappedRange.end);
|
||||
MOBILEGL_ASSERT(end <= m_mappedRange.end,
|
||||
"Flush range out of bounds: mappedRange.end (%zu) < end (%zu)", m_mappedRange.end, end);
|
||||
|
||||
memcpy(m_dataPtr->data() + start, m_stagingData.data() + offset, length);
|
||||
Memcpy(m_dataPtr->data() + start, m_stagingData.data() + offset, length);
|
||||
m_dirtyRange.UnionUpdate(start, end);
|
||||
}
|
||||
|
||||
void BufferObject::UploadSubData(DataPtr data, SizeT atOffset) {
|
||||
assert(!m_isMapped);
|
||||
assert(atOffset + data.size <= m_size);
|
||||
MOBILEGL_ASSERT(!m_isMapped, "Cannot upload sub data while buffer is mapped.");
|
||||
MOBILEGL_ASSERT(atOffset + data.size <= m_size,
|
||||
"UploadSubData out of bounds: atOffset (%zu) + data.size (%zu) > m_size (%zu)",
|
||||
atOffset, data.size, m_size);
|
||||
|
||||
memcpy(m_dataPtr->data() + atOffset, data.data, data.size);
|
||||
Memcpy(m_dataPtr->data() + atOffset, data.data, data.size);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
|
||||
void BufferObject::CopyDataFrom(const SharedPtr<BufferObject>& src, SizeT srcOffset, SizeT dstOffset,
|
||||
SizeT size) {
|
||||
assert(!m_isMapped);
|
||||
assert(!src->IsMapped());
|
||||
assert(srcOffset + size <= src->GetSize());
|
||||
assert(dstOffset + size <= m_size);
|
||||
MOBILEGL_ASSERT(!m_isMapped, "Cannot copy data while buffer is mapped.");
|
||||
MOBILEGL_ASSERT(!src->IsMapped(), "Cannot copy data from a buffer that is mapped.");
|
||||
MOBILEGL_ASSERT(srcOffset + size <= src->GetSize(),
|
||||
"Source buffer copy out of bounds: srcOffset (%zu) + size (%zu) > src->GetSize() (%zu)",
|
||||
srcOffset, size, src->GetSize());
|
||||
MOBILEGL_ASSERT(dstOffset + size <= m_size,
|
||||
"Destination buffer copy out of bounds: dstOffset (%zu) + size (%zu) > m_size (%zu)",
|
||||
dstOffset, size, m_size);
|
||||
|
||||
const Uint8* srcData = src->m_dataPtr->data() + srcOffset;
|
||||
memcpy(m_dataPtr->data() + dstOffset, srcData, size);
|
||||
Memcpy(m_dataPtr->data() + dstOffset, srcData, size);
|
||||
m_dirtyRange.UnionUpdate(dstOffset, dstOffset + size);
|
||||
}
|
||||
|
||||
@@ -93,7 +104,7 @@ namespace MobileGL {
|
||||
|
||||
if (!(m_mappingAccess &
|
||||
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_dataPtr->data(), m_size);
|
||||
Memcpy(m_stagingData.data(), m_dataPtr->data(), m_size);
|
||||
}
|
||||
|
||||
return m_stagingData.data();
|
||||
@@ -104,7 +115,9 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void* BufferObject::AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access) {
|
||||
assert(range.end <= m_size && range.start <= range.end);
|
||||
MOBILEGL_ASSERT(range.end <= m_size && range.start <= range.end,
|
||||
"AcquireMemoryRange out of bounds: range (%zu, %zu) exceeds m_size (%zu)", range.start,
|
||||
range.end, m_size);
|
||||
m_isMapped = true;
|
||||
m_mappingAccess = access;
|
||||
m_mappedRange = range;
|
||||
@@ -115,7 +128,7 @@ namespace MobileGL {
|
||||
|
||||
if (!(access &
|
||||
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_dataPtr->data() + range.start, m_stagingData.size());
|
||||
Memcpy(m_stagingData.data(), m_dataPtr->data() + range.start, m_stagingData.size());
|
||||
}
|
||||
|
||||
return m_stagingData.data();
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace MobileGL {
|
||||
return m_bindingSlots[i];
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
MOBILEGL_ASSERT(false, "Invalid BufferTarget enum value: %d", static_cast<int>(target));
|
||||
return m_bindingSlots[0];
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ namespace MobileGL {
|
||||
return m_bufferObjects.find(index) != m_bufferObjects.end();
|
||||
}
|
||||
|
||||
BindingSlotRange1D<BufferObject> &
|
||||
BufferState::GetBindingPoint(BufferTarget target, Uint index) {
|
||||
BindingSlotRange1D<BufferObject>& BufferState::GetBindingPoint(BufferTarget target, Uint index) {
|
||||
for (SizeT i = 0; i < BufferBindPointTargets.size(); ++i) {
|
||||
if (BufferBindPointTargets[i] == target) {
|
||||
return m_bufferBindPointTargets[i][index];
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
MOBILEGL_ASSERT(false, "Invalid BufferTarget enum value for binding point: %d",
|
||||
static_cast<int>(target));
|
||||
return m_bufferBindPointTargets[0][index];
|
||||
}
|
||||
} // namespace GLState
|
||||
|
||||
@@ -53,13 +53,9 @@ namespace MobileGL {
|
||||
BindingSlot<BufferObject>& GLContext::GetBufferBindingSlot(BufferTarget target) {
|
||||
if (target == BufferTarget::Index) {
|
||||
const auto& vao = m_vertexArrayState.GetBoundVertexArray();
|
||||
if (vao) {
|
||||
return vao->GetIndexBufferBindingSlot();
|
||||
} else {
|
||||
assert(false);
|
||||
static BindingSlot<BufferObject> defaultSlot(BufferTarget::Index);
|
||||
return defaultSlot;
|
||||
}
|
||||
MOBILEGL_ASSERT(vao != nullptr,
|
||||
"No VAO is currently bound when accessing index buffer binding slot.");
|
||||
return vao->GetIndexBufferBindingSlot();
|
||||
}
|
||||
|
||||
return m_bufferState.GetBindingSlot(target);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace MobileGL {
|
||||
return m_bindingSlots[i];
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
MOBILEGL_ASSERT(false, "Invalid FramebufferTarget enum value: %d", static_cast<int>(target));
|
||||
return m_bindingSlots[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ namespace MobileGL {
|
||||
MGLOG_E("ProgramObject %u: GenerateBinary - last compiled shader src: \n%s", m_externalIndex,
|
||||
m_shaders[i]->GetShaderSource().c_str());
|
||||
}
|
||||
assert(res); // keep original assert but log first
|
||||
MOBILEGL_ASSERT(res, "CompileShader failed during binary generation");
|
||||
shaders[i] = res.value();
|
||||
MGLOG_D("ProgramObject %u: GenerateBinary - compiled shader[%zu] -> TShader ptr %p",
|
||||
m_externalIndex, i, shaders[i].get());
|
||||
@@ -385,7 +385,7 @@ namespace MobileGL {
|
||||
MGLOG_E("ProgramObject %u: GenerateBinary - LinkProgram failed during binary generation",
|
||||
m_externalIndex);
|
||||
}
|
||||
assert(programResult);
|
||||
MOBILEGL_ASSERT(programResult, "LinkProgram failed during binary generation");
|
||||
auto program = programResult.value();
|
||||
MGLOG_D("ProgramObject %u: GenerateBinary - got linked program object", m_externalIndex);
|
||||
|
||||
@@ -398,7 +398,7 @@ namespace MobileGL {
|
||||
if (!binaryResult) {
|
||||
MGLOG_E("ProgramObject %u: GenerateBinary - GetSpirvBinaryFromProgram failed", m_externalIndex);
|
||||
}
|
||||
assert(binaryResult);
|
||||
MOBILEGL_ASSERT(binaryResult, "GetSpirvBinaryFromProgram failed");
|
||||
m_generatedSpirv = Move(binaryResult.value());
|
||||
MGLOG_D("ProgramObject %u: GenerateBinary - generated %zu SPIR-V modules", m_externalIndex,
|
||||
m_generatedSpirv.size());
|
||||
|
||||
@@ -161,9 +161,7 @@ namespace MobileGL {
|
||||
m_unpackParameters.LSBFirst = value != 0;
|
||||
break;
|
||||
default:
|
||||
MGLOG_F("RenderState::SetPixelStoreParam: Invalid PixelStoreParam enum: %d",
|
||||
static_cast<int>(param));
|
||||
assert(false && "Invalid PixelStoreParam enum");
|
||||
MOBILEGL_ASSERT(false, "Invalid PixelStoreParam enum: %d", static_cast<int>(param));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -203,9 +201,7 @@ namespace MobileGL {
|
||||
case PixelStoreParam::UnpackLsbFirst:
|
||||
return m_unpackParameters.LSBFirst ? 1 : 0;
|
||||
default:
|
||||
MGLOG_F("RenderState::GetPixelStoreParam: Invalid PixelStoreParam enum: %d",
|
||||
static_cast<int>(param));
|
||||
assert(false && "Invalid PixelStoreParam enum");
|
||||
MOBILEGL_ASSERT(false, "Invalid PixelStoreParam enum: %d", static_cast<int>(param));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,7 @@ namespace MobileGL {
|
||||
|
||||
MipmapLevelInternal& TextureObjectBase::GetMipmap(Int index) {
|
||||
if (index >= m_mipmaps.size()) {
|
||||
MGLOG_F("TextureObjectBase::GetMipmap: Requested mipmap level %d exceeds available levels %zu",
|
||||
index, m_mipmaps.size());
|
||||
assert(false && "Requested mipmap level exceeds available levels");
|
||||
MOBILEGL_ASSERT(false, "GetMipmap: index %d out of bounds, returning last mipmap level", index);
|
||||
index = static_cast<Int>(m_mipmaps.size() - 1);
|
||||
}
|
||||
return m_mipmaps[index];
|
||||
@@ -100,9 +98,8 @@ namespace MobileGL {
|
||||
case TextureSwizzleParam::Alpha:
|
||||
return m_swizzleParams[3];
|
||||
default:
|
||||
MGLOG_F("TextureObjectBase::GetSwizzleParam: Invalid TextureSwizzleParam: %d",
|
||||
static_cast<Int>(param));
|
||||
assert(false && "Invalid TextureSwizzleParam");
|
||||
MOBILEGL_ASSERT(false, "TextureObjectBase::GetSwizzleParam: Invalid TextureSwizzleParam: %d",
|
||||
static_cast<Int>(param));
|
||||
return TextureSwizzleParam::Red;
|
||||
}
|
||||
}
|
||||
@@ -122,9 +119,8 @@ namespace MobileGL {
|
||||
m_swizzleParams[3] = value;
|
||||
break;
|
||||
default:
|
||||
MGLOG_F("TextureObjectBase::SetSwizzleParam: Invalid TextureSwizzleParam: %d",
|
||||
static_cast<Int>(param));
|
||||
assert(false && "Invalid TextureSwizzleParam");
|
||||
MOBILEGL_ASSERT(false, "TextureObjectBase::SetSwizzleParam: Invalid TextureSwizzleParam: %d",
|
||||
static_cast<Int>(param));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user