clang/gcc: enable a bunch more warnings (#91)

* clang/gcc: enable -pedantic warnings

* suppress a GCC-specific warning in stb_image

* And some clang-specific warnings

* -Wconversion (clang) -Wold-style-cast (clang+gcc)

and fix a few warnings that show up with these (and a few more with
-Wconversion on gcc, even though that's not enabled by default)

* bunch more warnings

* fixes

* remove merge error
This commit is contained in:
Kai Ninomiya
2017-07-21 17:00:22 -07:00
committed by GitHub
parent 159bade5f5
commit 78c8b837ea
29 changed files with 85 additions and 52 deletions

View File

@@ -186,7 +186,8 @@ namespace backend {
// Make sure we have space for current allocation, plus end of block and alignment padding
// for the first id.
if (!GetNewBlock(nextPtr - currentPtr + sizeof(uint32_t) + alignof(uint32_t))) {
ASSERT(nextPtr > currentPtr);
if (!GetNewBlock(static_cast<size_t>(nextPtr - currentPtr) + sizeof(uint32_t) + alignof(uint32_t))) {
return nullptr;
}
return Allocate(commandId, commandSize, commandAlignment);

View File

@@ -88,7 +88,7 @@ namespace backend {
}
uint32_t ComputeDefaultRowPitch(TextureBase* texture, uint32_t width) {
uint32_t texelSize = static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat()));
uint32_t texelSize = TextureFormatPixelSize(texture->GetFormat());
return texelSize * width;
}
@@ -98,7 +98,7 @@ namespace backend {
return false;
}
uint32_t texelSize = static_cast<uint32_t>(TextureFormatPixelSize(location.texture.Get()->GetFormat()));
uint32_t texelSize = TextureFormatPixelSize(location.texture.Get()->GetFormat());
if (rowPitch < location.width * texelSize) {
builder->HandleError("Row pitch must not be less than the number of bytes per row");
return false;

View File

@@ -200,7 +200,7 @@ namespace backend {
aspects.set(VALIDATION_ASPECT_RENDER_SUBPASS);
return true;
};
}
bool CommandBufferStateTracker::EndSubpass() {
if (!aspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
@@ -233,7 +233,7 @@ namespace backend {
aspects.reset(VALIDATION_ASPECT_RENDER_SUBPASS);
UnsetPipeline();
return true;
};
}
bool CommandBufferStateTracker::BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer) {
if (aspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
@@ -402,7 +402,7 @@ namespace backend {
}
auto it = mostRecentBufferUsages.find(buffer);
return it != mostRecentBufferUsages.end() && (it->second & usage);
};
}
bool CommandBufferStateTracker::TextureHasGuaranteedUsageBit(TextureBase* texture, nxt::TextureUsageBit usage) const {
ASSERT(usage != nxt::TextureUsageBit::None && nxt::HasZeroOrOneBits(usage));
@@ -411,7 +411,7 @@ namespace backend {
}
auto it = mostRecentTextureUsages.find(texture);
return it != mostRecentTextureUsages.end() && (it->second & usage);
};
}
bool CommandBufferStateTracker::IsInternalTextureTransitionPossible(TextureBase* texture, nxt::TextureUsageBit usage) const {
ASSERT(usage != nxt::TextureUsageBit::None && nxt::HasZeroOrOneBits(usage));
@@ -419,7 +419,7 @@ namespace backend {
return false;
}
return texture->IsTransitionPossible(usage);
};
}
bool CommandBufferStateTracker::IsExplicitTextureTransitionPossible(TextureBase* texture, nxt::TextureUsageBit usage) const {
const nxt::TextureUsageBit attachmentUsages =
@@ -519,7 +519,7 @@ namespace backend {
}
}
return true;
};
}
bool CommandBufferStateTracker::RevalidateCanDraw() {
if (!aspects[VALIDATION_ASPECT_RENDER_PIPELINE]) {

View File

@@ -36,7 +36,7 @@ namespace backend {
info->mask = moduleInfo.mask;
for (uint32_t i = 0; i < moduleInfo.names.size(); i++) {
unsigned int size = moduleInfo.sizes[i];
uint32_t size = moduleInfo.sizes[i];
if (size == 0) {
continue;
}

View File

@@ -96,7 +96,7 @@ namespace backend {
// Fill in bindingInfo with the SPIRV bindings
auto ExtractResourcesBinding = [this](const std::vector<spirv_cross::Resource>& resources,
const spirv_cross::Compiler& compiler, nxt::BindingType type) {
const spirv_cross::Compiler& compiler, nxt::BindingType bindingType) {
constexpr uint64_t requiredBindingDecorationMask = (1ull << spv::DecorationBinding) | (1ull << spv::DecorationDescriptorSet);
for (const auto& resource : resources) {
@@ -113,7 +113,7 @@ namespace backend {
info.used = true;
info.id = resource.id;
info.base_type_id = resource.base_type_id;
info.type = type;
info.type = bindingType;
}
};

View File

@@ -42,7 +42,7 @@ namespace backend {
std::bitset<kMaxPushConstants> mask;
std::array<std::string, kMaxPushConstants> names;
std::array<int, kMaxPushConstants> sizes;
std::array<uint32_t, kMaxPushConstants> sizes;
std::array<PushConstantType, kMaxPushConstants> types;
};

View File

@@ -19,7 +19,7 @@
namespace backend {
size_t TextureFormatPixelSize(nxt::TextureFormat format) {
uint32_t TextureFormatPixelSize(nxt::TextureFormat format) {
switch (format) {
case nxt::TextureFormat::R8G8B8A8Unorm:
return 4;

View File

@@ -23,7 +23,7 @@
namespace backend {
size_t TextureFormatPixelSize(nxt::TextureFormat format);
uint32_t TextureFormatPixelSize(nxt::TextureFormat format);
bool TextureFormatHasDepth(nxt::TextureFormat format);
bool TextureFormatHasStencil(nxt::TextureFormat format);

View File

@@ -48,7 +48,7 @@ namespace metal {
mtlVertexDescriptor = [MTLVertexDescriptor new];
const auto& attributesSetMask = GetAttributesSetMask();
for (size_t i = 0; i < attributesSetMask.size(); ++i) {
for (uint32_t i = 0; i < attributesSetMask.size(); ++i) {
if (!attributesSetMask[i]) {
continue;
}
@@ -63,7 +63,7 @@ namespace metal {
}
const auto& inputsSetMask = GetInputsSetMask();
for (size_t i = 0; i < inputsSetMask.size(); ++i) {
for (uint32_t i = 0; i < inputsSetMask.size(); ++i) {
if (!inputsSetMask[i]) {
continue;
}

View File

@@ -181,7 +181,7 @@ namespace opengl {
glBindTexture(target, texture->GetHandle());
ASSERT(texture->GetDimension() == nxt::TextureDimension::e2D);
glPixelStorei(GL_UNPACK_ROW_LENGTH, copy->rowPitch / static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat())));
glPixelStorei(GL_UNPACK_ROW_LENGTH, copy->rowPitch / TextureFormatPixelSize(texture->GetFormat()));
glTexSubImage2D(target, dst.level, dst.x, dst.y, dst.width, dst.height,
format.format, format.type,
reinterpret_cast<void*>(static_cast<uintptr_t>(src.offset)));
@@ -212,7 +212,7 @@ namespace opengl {
texture->GetHandle(), src.level);
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer->GetHandle());
glPixelStorei(GL_PACK_ROW_LENGTH, copy->rowPitch / static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat())));
glPixelStorei(GL_PACK_ROW_LENGTH, copy->rowPitch / TextureFormatPixelSize(texture->GetFormat()));
ASSERT(src.depth == 1 && src.z == 0);
void* offset = reinterpret_cast<void*>(static_cast<uintptr_t>(dst.offset));
glReadPixels(src.x, src.y, src.width, src.height, format.format, format.type, offset);

View File

@@ -192,12 +192,12 @@ namespace opengl {
}
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForSampler(GLuint index) const {
ASSERT(index >= 0 && index < unitsForSamplers.size());
ASSERT(index < unitsForSamplers.size());
return unitsForSamplers[index];
}
const std::vector<GLuint>& PipelineGL::GetTextureUnitsForTexture(GLuint index) const {
ASSERT(index >= 0 && index < unitsForSamplers.size());
ASSERT(index < unitsForSamplers.size());
return unitsForTextures[index];
}