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

Add -Wconversion and fix the related conversion issues #7

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions common/include/crcgenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
#ifndef _CRC_GENERATOR_INCLUDED
#define _CRC_GENERATOR_INCLUDED

extern unsigned long Crc32Table[256];
void getCRC(uint32_t *checksum, const uint8_t *inputBytes, size_t length, unsigned long crcTable[]);
extern uint32_t Crc32Table[256];
void getCRC(uint32_t *checksum, const uint8_t *inputBytes, size_t length, uint32_t crcTable[]);
#endif //_CRC_GENERATOR_INCLUDED
2 changes: 1 addition & 1 deletion common/libs/VkCodecUtils/FrameProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class FrameProcessor : public VkVideoRefCountBase {
if (timeDiffNanoseconds) {
*timeDiffNanoseconds = diffNanoseconds;
}
fps = (float)((double)(m_profileFramesCount * 1000000000) / diffNanoseconds);
fps = (float)((double)(m_profileFramesCount * 1000000000) / (double)diffNanoseconds);
m_profileFramesCount = 0;
displayTimeNow = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion common/libs/VkCodecUtils/ProgramConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ struct ProgramConfig {
std::string token;
while (std::getline(stream, token, ',')) {
char* endPtr = NULL;
uint32_t initValue = strtoul(token.c_str(), &endPtr, 16);
uint32_t initValue = static_cast<uint32_t>(strtoul(token.c_str(), &endPtr, 16));
if ((endPtr == NULL) || (*endPtr != 0)) {
std::cerr << "Failed to parse the following initial CRC value:"
<< token << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions common/libs/VkCodecUtils/VulkanFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool VulkanFrame<FrameDataType>::OnFrame( int32_t renderIndex,

if (gfxRendererIsEnabled == false) {

m_frameDataIndex = (m_frameDataIndex + 1) % m_frameData.size();
m_frameDataIndex = (uint32_t)((m_frameDataIndex + 1) % m_frameData.size());
dabrain34 marked this conversation as resolved.
Show resolved Hide resolved
return continueLoop;
}

Expand Down Expand Up @@ -670,7 +670,7 @@ VkResult VulkanFrame<FrameDataType>::DrawFrame( int32_t renderIndex,
close(fd);
#endif

m_frameDataIndex = (m_frameDataIndex + 1) % m_frameData.size();
m_frameDataIndex = ((m_frameDataIndex + 1) % (uint32_t)m_frameData.size());

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion common/libs/VkCodecUtils/VulkanFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class VulkanFrame : public FrameProcessor {
std::vector<VkMemoryPropertyFlags> m_memFlags;

std::vector<FrameDataType> m_frameData;
int m_frameDataIndex;
uint32_t m_frameDataIndex;

VkExtent2D m_extent;
VkViewport m_viewport;
Expand Down
4 changes: 2 additions & 2 deletions common/libs/VkCodecUtils/VulkanShaderCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static shaderc_shader_kind getShadercShaderType(VkShaderStageFlagBits type)
default:
std::cerr << "VulkanShaderCompiler: " << "invalid VKShaderStageFlagBits" << "type = " << type;
}
return static_cast<shaderc_shader_kind>(-1);
return shaderc_glsl_infer_from_source;
}

VulkanShaderCompiler::VulkanShaderCompiler()
Expand Down Expand Up @@ -108,7 +108,7 @@ VkShaderModule VulkanShaderCompiler::BuildShaderFromFile(const char *fileName,

if (is.is_open()) {

size_t size = is.tellg();
size_t size = (size_t)is.tellg();
is.seekg(0, std::ios::beg);
char* shaderCode = new char[size];
is.read(shaderCode, size);
Expand Down
4 changes: 2 additions & 2 deletions common/libs/VkCodecUtils/VulkanVideoUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,11 @@ VkResult VulkanPerDrawContext::RecordCommandBuffer(VkCommandBuffer cmdBuffer,
vk::TransformPushConstants constants;
if (scaleInput) {
if (displayWidth && (displayWidth != inputImageToDrawFrom->imageWidth)) {
constants.texMatrix[0] = vk::Vec2((float)displayWidth / inputImageToDrawFrom->imageWidth, 0.0f);
constants.texMatrix[0] = vk::Vec2((float)(double)displayWidth / (float)(double)inputImageToDrawFrom->imageWidth, 0.0f);
}

if (displayHeight && (displayHeight != inputImageToDrawFrom->imageHeight)) {
constants.texMatrix[1] = vk::Vec2(.0f, (float)displayHeight /inputImageToDrawFrom->imageHeight);
constants.texMatrix[1] = vk::Vec2(.0f, (float)(double)displayHeight / (float)(double)inputImageToDrawFrom->imageHeight);
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/libs/VkCodecUtils/crcgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "crcgenerator.h"

unsigned long Crc32Table[256] = {
uint32_t Crc32Table[256] = {
// CRC32 lookup table
// Generated by the following routine
// int i, j;
Expand Down Expand Up @@ -97,7 +97,7 @@ unsigned long Crc32Table[256] = {
0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d
};

void getCRC(uint32_t *checksum, const uint8_t *inputBytes, size_t length, unsigned long crcTable[])
void getCRC(uint32_t *checksum, const uint8_t *inputBytes, size_t length, uint32_t crcTable[])
{
for (size_t i = 0; i < length; i += 1) {
*checksum = crcTable[inputBytes[i] ^ (*checksum & 0xff)] ^ (*checksum >> 8);
Expand Down
4 changes: 2 additions & 2 deletions common/libs/VkShell/ShellXcb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace {

xcb_intern_atom_cookie_t intern_atom_cookie(xcb_connection_t *c, const std::string &s) {
return xcb_intern_atom(c, false, s.size(), s.c_str());
return xcb_intern_atom(c, false, static_cast<uint16_t>(s.size()), s.c_str());
}

xcb_atom_t intern_atom(xcb_connection_t *c, xcb_intern_atom_cookie_t cookie) {
Expand Down Expand Up @@ -118,7 +118,7 @@ void ShellXcb::CreateWindow() {
xcb_atom_t utf8_string = intern_atom(m_connection, utf8_string_cookie);
xcb_atom_t _net_wm_name = intern_atom(m_connection, _net_wm_name_cookie);
xcb_change_property(m_connection, XCB_PROP_MODE_REPLACE, m_window, _net_wm_name, utf8_string, 8,
m_settings.m_windowName.size(), m_settings.m_windowName.c_str());
static_cast<uint32_t>(m_settings.m_windowName.size()), m_settings.m_windowName.c_str());

// advertise WM_DELETE_WINDOW
m_wm_protocols = intern_atom(m_connection, wm_protocols_cookie);
Expand Down
2 changes: 1 addition & 1 deletion vk_video_decoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ set(SCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../scripts")
include_directories("${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/../common/include")

if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
# set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion -Wno-sign-conversion -Wno-conversion -Wno-sign-compare")
set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wconversion")
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")

# These flags are not supported on Windows and some older version of GCC
Expand Down
10 changes: 5 additions & 5 deletions vk_video_decoder/include/vkvideo_parser/VulkanVideoParserIf.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ typedef struct VkParserHevcPictureData {
uint8_t seq_parameter_set_id; // SPS ID
uint8_t vps_video_parameter_set_id; // VPS ID

uint8_t IrapPicFlag;
uint8_t IdrPicFlag;
uint8_t short_term_ref_pic_set_sps_flag;
uint32_t IrapPicFlag : 1;
uint32_t IdrPicFlag : 1;
uint32_t short_term_ref_pic_set_sps_flag : 1;

// RefPicSets
int32_t NumBitsForShortTermRPSInSlice;
Expand Down Expand Up @@ -440,7 +440,7 @@ typedef struct VkParserSequenceInfo {
VkVideoCodecOperationFlagBitsKHR eCodec; // Compression Standard
bool isSVC; // h.264 SVC
FrameRate frameRate; // Frame Rate stored in the bitstream
int32_t bProgSeq; // Progressive Sequence
bool bProgSeq; // Progressive Sequence
int32_t nDisplayWidth; // Displayed Horizontal Size
int32_t nDisplayHeight; // Displayed Vertical Size
int32_t nCodedWidth; // Coded Picture Width
Expand All @@ -453,7 +453,7 @@ typedef struct VkParserSequenceInfo {
uint8_t uVideoFullRange; // 0=16-235, 1=0-255
int32_t lBitrate; // Video bitrate (bps)
int32_t lDARWidth,
lDARHeight; // Display Aspect Ratio = lDARWidth : lDARHeight
lDARHeight; // Display Aspect Ratio = lDARWidth : lDARHeight
int32_t lVideoFormat; // Video Format (VideoFormatXXX)
int32_t lColorPrimaries; // Colour Primaries (ColorPrimariesXXX)
int32_t lTransferCharacteristics; // Transfer Characteristics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class VulkanAV1Decoder : public VulkanVideoDecoder {
size_t le(int n) {
size_t t = 0;
for (int i = 0; i < n; i++) {
uint8_t byte = u(8);
uint8_t byte = (uint8_t)u(8);
t += (byte << (i * 8));
}
return t;
Expand Down
38 changes: 19 additions & 19 deletions vk_video_decoder/libs/NvVideoParser/include/VulkanH264Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "VulkanH26xDecoder.h"
#include "nvVulkanh264ScalingList.h"

#define VK_H264_SPS_VUI_FIELD(pStdVui, nvSpsIn, name) pStdVui->name = nvSpsIn->vui.name
#define VK_H264_SPS_VUI_FIELD(pStdVui, nvSpsIn, name) pStdVui->name = (uint8_t)(nvSpsIn->vui.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. Not all SPS_VUI fields are uint8_t. This will create a big issue on truncating types.

#define SET_VK_H264_SPS_VUI_FIELD(pStdVui, name, value) pStdVui->name = value
#define VK_H264_SPS_VUI_FLAG(pStdVui, nvSpsIn, name) pStdVui->flags.name = nvSpsIn->vui.name

Expand Down Expand Up @@ -76,19 +76,19 @@ struct vui_parameters_s

struct seq_parameter_set_svc_extension_s
{
int inter_layer_deblocking_filter_control_present_flag;
int extended_spatial_scalability_idc;
int chroma_phase_x_plus1_flag;
int chroma_phase_y_plus1;
int seq_ref_layer_chroma_phase_x_plus1_flag;
int seq_ref_layer_chroma_phase_y_plus1;
int seq_scaled_ref_layer_left_offset;
int seq_scaled_ref_layer_top_offset;
int seq_scaled_ref_layer_right_offset;
int seq_scaled_ref_layer_bottom_offset;
int seq_tcoeff_level_prediction_flag;
int adaptive_tcoeff_level_prediction_flag;
int slice_header_restriction_flag;
uint32_t inter_layer_deblocking_filter_control_present_flag;
uint32_t extended_spatial_scalability_idc;
uint32_t chroma_phase_x_plus1_flag;
uint32_t chroma_phase_y_plus1;
uint32_t seq_ref_layer_chroma_phase_x_plus1_flag;
uint32_t seq_ref_layer_chroma_phase_y_plus1;
uint32_t seq_scaled_ref_layer_left_offset;
uint32_t seq_scaled_ref_layer_top_offset;
uint32_t seq_scaled_ref_layer_right_offset;
uint32_t seq_scaled_ref_layer_bottom_offset;
uint32_t seq_tcoeff_level_prediction_flag;
uint32_t adaptive_tcoeff_level_prediction_flag;
uint32_t slice_header_restriction_flag;
};

struct seq_parameter_set_s : public StdVideoPictureParametersSet, public StdVideoH264SequenceParameterSet
Expand Down Expand Up @@ -233,8 +233,8 @@ struct seq_parameter_set_s : public StdVideoPictureParametersSet, public StdVide

// StdVideoH264HrdParameters hrd_parameters);
pStdHrdParameters->cpb_cnt_minus1 = pSps->vui.nal_hrd.cpb_cnt_minus1;
pStdHrdParameters->bit_rate_scale = pSps->vui.nal_hrd.bit_rate;
pStdHrdParameters->cpb_size_scale = pSps->vui.nal_hrd.cbp_size;
pStdHrdParameters->bit_rate_scale = (uint8_t)(pSps->vui.nal_hrd.bit_rate);
pStdHrdParameters->cpb_size_scale =(uint8_t)(pSps->vui.nal_hrd.cbp_size);
// stdVui.pHrdParameters->bit_rate_value_minus1[32];
// stdVui.pHrdParameters->cpb_size_value_minus1[32];
// stdVui.pHrdParameters->cbr_flag[32];
Expand Down Expand Up @@ -544,7 +544,7 @@ struct slice_header_s
int first_mb_in_slice;
int slice_type_raw;
int slice_type;
int pic_parameter_set_id;
uint8_t pic_parameter_set_id;
int colour_plane_id;
int frame_num;
int idr_pic_id;
Expand Down Expand Up @@ -737,8 +737,8 @@ typedef bool (*PFNSORTCHECK)(int, int *, const DPBPicNum *, const VkParserPictur
class VulkanH264Decoder: public VulkanVideoDecoder
{
public:
enum { MAX_NUM_SPS = 32 };
enum { MAX_NUM_PPS = 256 };
enum { MAX_NUM_SPS = 31 };
dabrain34 marked this conversation as resolved.
Show resolved Hide resolved
enum { MAX_NUM_PPS = 255 };

public:
VulkanH264Decoder(VkVideoCodecOperationFlagBitsKHR std);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,14 @@ struct hevc_video_param_s : public StdVideoPictureParametersSet, public StdVideo
uint8_t layer_id_included_flag[MAX_VPS_LAYER_SETS][MAX_NUM_LAYER_IDS];
uint32_t num_layers_in_id_list[MAX_VPS_LAYER_SETS];
uint8_t layer_set_layer_id_list[MAX_VPS_LAYER_SETS][MAX_NUM_LAYER_IDS];
uint32_t vps_num_hrd_parameters;
uint32_t vps_num_hrd_parameters;
// hrdParameters_t hrdParameters[MAX_VPS_LAYER_SETS]; // CMOD variable
uint32_t hrd_layer_set_idx[MAX_VPS_LAYER_SETS];
uint8_t cprms_present_flag[MAX_VPS_LAYER_SETS];

/* VPS Extension */
uint8_t scalability_mask_flag[MAX_NUM_SCALABILITY_TYPES];
uint32_t numScalabilityTypes;
uint32_t numScalabilityTypes;
uint8_t dimension_id_len[MAX_NUM_SCALABILITY_TYPES];

uint8_t layer_id_in_nuh[MAX_NUM_LAYER_IDS];
Expand Down Expand Up @@ -651,10 +651,10 @@ typedef struct _hevc_slice_header_s
uint32_t slice_segment_address;

uint8_t colour_plane_id;
uint8_t short_term_ref_pic_set_sps_flag;
uint32_t short_term_ref_pic_set_sps_flag : 1;
uint8_t short_term_ref_pic_set_idx;
uint8_t num_long_term_sps;

uint16_t pic_order_cnt_lsb;
uint8_t num_long_term_pics;
uint8_t reserved1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ enum NvScalingListTypeH264 {

struct NvScalingListH264
{
int32_t scaling_matrix_present_flag:1;
uint8_t scaling_list_type[8]; // scaling_list_type_e
uint8_t ScalingList4x4[6][16];
uint8_t ScalingList8x8[2][64];
uint32_t scaling_matrix_present_flag:1;
uint8_t scaling_list_type[8]; // scaling_list_type_e
uint8_t ScalingList4x4[6][16];
uint8_t ScalingList8x8[2][64];
};

NVPARSER_EXPORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ size_t VulkanVideoDecoder::next_start_code<SIMD_ISA::AVX2>(const uint8_t *pdatai
{
const __m256i v1 = _mm256_set1_epi8(1);
__m256i vdata = _mm256_loadu_si256((const __m256i*)pdatain);
__m256i vBfr = _mm256_set1_epi16(((m_BitBfr << 8) & 0xFF00) | ((m_BitBfr >> 8) & 0xFF));
__m256i vBfr = _mm256_set1_epi16((((int16_t)m_BitBfr << 8) & 0xFF00) | (((short)m_BitBfr >> 8) & 0xFF));
__m256i vdata_alignr16b_init = _mm256_permute2f128_si256(vBfr, vdata, 1 | (2<<4));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short -> int16_t

__m256i vdata_prev1 = _mm256_alignr_epi8(vdata, vdata_alignr16b_init, 15);
__m256i vdata_prev2 = _mm256_alignr_epi8(vdata, vdata_alignr16b_init, 14);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ size_t VulkanVideoDecoder::next_start_code<SIMD_ISA::AVX512>(const uint8_t *pdat
const __m512i v1 = _mm512_set1_epi8(1);
const __m512i v254 = _mm512_set1_epi8(-2);
__m512i vdata = _mm512_loadu_si512((const void*)pdatain);
__m512i vBfr = _mm512_set1_epi16(((m_BitBfr << 8) & 0xFF00) | ((m_BitBfr >> 8) & 0xFF));
__m512i vBfr = _mm512_set1_epi16((((int16_t)m_BitBfr << 8) & 0xFF00) | (((short)m_BitBfr >> 8) & 0xFF));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short -> int16_t

__m512i vdata_alignr48b_init = _mm512_alignr_epi32(vdata, vBfr, 12);
__m512i vdata_prev1 = _mm512_alignr_epi8(vdata, vdata_alignr48b_init, 15);
__m512i vdata_prev2 = _mm512_alignr_epi8(vdata, vdata_alignr48b_init, 14);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ size_t VulkanVideoDecoder::next_start_code<SIMD_ISA::SSSE3>(const uint8_t *pdata
{
const __m128i v1 = _mm_set1_epi8(1);
__m128i vdata = _mm_loadu_si128((const __m128i*)pdatain);
__m128i vBfr = _mm_set1_epi16(((m_BitBfr << 8) & 0xFF00) | ((m_BitBfr >> 8) & 0xFF));
__m128i vBfr = _mm_set1_epi16((((int16_t)m_BitBfr << 8) & 0xFF00) | (((short)m_BitBfr >> 8) & 0xFF));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short -> int16_t

__m128i vdata_prev1 = _mm_alignr_epi8(vdata, vBfr, 15);
__m128i vdata_prev2 = _mm_alignr_epi8(vdata, vBfr, 14);
for ( ; i < datasize32 - 32; i += 32)
Expand Down
Loading