Merge changes Id72fbf3b,Ic59d23a2 into main

* changes:
  sharpyuv: add SharpYuvGetCPUInfo
  cpu.c,cosmetics: fix a typo
This commit is contained in:
James Zern 2022-10-26 20:56:42 +00:00 committed by Gerrit Code Review
commit 9ba800a745
12 changed files with 74 additions and 30 deletions

View File

@ -35,6 +35,7 @@ endif
sharpyuv_srcs := \ sharpyuv_srcs := \
sharpyuv/sharpyuv.c \ sharpyuv/sharpyuv.c \
sharpyuv/sharpyuv_cpu.c \
sharpyuv/sharpyuv_csp.c \ sharpyuv/sharpyuv_csp.c \
sharpyuv/sharpyuv_dsp.c \ sharpyuv/sharpyuv_dsp.c \
sharpyuv/sharpyuv_gamma.c \ sharpyuv/sharpyuv_gamma.c \

View File

@ -87,6 +87,7 @@ if(WEBP_BUILD_WEBP_JS)
endif() endif()
set(SHARPYUV_DEP_LIBRARIES) set(SHARPYUV_DEP_LIBRARIES)
set(SHARPYUV_DEP_INCLUDE_DIRS)
set(WEBP_DEP_LIBRARIES) set(WEBP_DEP_LIBRARIES)
set(WEBP_DEP_INCLUDE_DIRS) set(WEBP_DEP_INCLUDE_DIRS)
@ -151,9 +152,12 @@ if(ANDROID)
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c) ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
list(APPEND INSTALLED_LIBRARIES cpufeatures-webp) list(APPEND INSTALLED_LIBRARIES cpufeatures-webp)
target_link_libraries(cpufeatures-webp dl) target_link_libraries(cpufeatures-webp dl)
set(SHARPYUV_DEP_LIBRARIES ${SHARPYUV_DEP_LIBRARIES} cpufeatures-webp)
set(WEBP_DEP_LIBRARIES ${WEBP_DEP_LIBRARIES} cpufeatures-webp) set(WEBP_DEP_LIBRARIES ${WEBP_DEP_LIBRARIES} cpufeatures-webp)
set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS} set(cpufeatures_include_dir ${ANDROID_NDK}/sources/android/cpufeatures)
${ANDROID_NDK}/sources/android/cpufeatures) set(SHARPYUV_DEP_INCLUDE_DIRS ${SHARPYUV_DEP_INCLUDE_DIRS}
${cpufeatures_include_dir})
set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS} ${cpufeatures_include_dir})
add_definitions(-DHAVE_CPU_FEATURES_H=1) add_definitions(-DHAVE_CPU_FEATURES_H=1)
set(HAVE_CPU_FEATURES_H 1) set(HAVE_CPU_FEATURES_H 1)
else() else()

View File

@ -180,6 +180,7 @@ CFLAGS = $(CFLAGS) /D_UNICODE /DUNICODE
SHARPYUV_OBJS = \ SHARPYUV_OBJS = \
$(DIROBJ)\sharpyuv\sharpyuv.obj \ $(DIROBJ)\sharpyuv\sharpyuv.obj \
$(DIROBJ)\sharpyuv\sharpyuv_cpu.obj \
$(DIROBJ)\sharpyuv\sharpyuv_csp.obj \ $(DIROBJ)\sharpyuv\sharpyuv_csp.obj \
$(DIROBJ)\sharpyuv\sharpyuv_dsp.obj \ $(DIROBJ)\sharpyuv\sharpyuv_dsp.obj \
$(DIROBJ)\sharpyuv\sharpyuv_gamma.obj \ $(DIROBJ)\sharpyuv\sharpyuv_gamma.obj \

View File

@ -107,6 +107,7 @@ model {
source { source {
srcDir "sharpyuv" srcDir "sharpyuv"
include "sharpyuv.c" include "sharpyuv.c"
include "sharpyuv_cpu.c"
include "sharpyuv_csp.c" include "sharpyuv_csp.c"
include "sharpyuv_dsp.c" include "sharpyuv_dsp.c"
include "sharpyuv_gamma.c" include "sharpyuv_gamma.c"

View File

@ -128,6 +128,7 @@ ANIM_UTIL_OBJS = \
SHARPYUV_OBJS = \ SHARPYUV_OBJS = \
sharpyuv/sharpyuv.o \ sharpyuv/sharpyuv.o \
sharpyuv/sharpyuv_cpu.o \
sharpyuv/sharpyuv_csp.o \ sharpyuv/sharpyuv_csp.o \
sharpyuv/sharpyuv_dsp.o \ sharpyuv/sharpyuv_dsp.o \
sharpyuv/sharpyuv_gamma.o \ sharpyuv/sharpyuv_gamma.o \
@ -308,7 +309,8 @@ HDRS_INSTALLED = \
SHARPYUV_HDRS_INSTALLED = \ SHARPYUV_HDRS_INSTALLED = \
sharpyuv/sharpyuv.h \ sharpyuv/sharpyuv.h \
sharpyuv/sharpyuv_csp.h sharpyuv/sharpyuv_cpu.h \
sharpyuv/sharpyuv_csp.h \
HDRS = \ HDRS = \
src/dec/alphai_dec.h \ src/dec/alphai_dec.h \

View File

@ -11,6 +11,7 @@ libsharpyuvinclude_HEADERS =
libsharpyuvinclude_HEADERS += sharpyuv.h libsharpyuvinclude_HEADERS += sharpyuv.h
libsharpyuvinclude_HEADERS += sharpyuv_csp.h libsharpyuvinclude_HEADERS += sharpyuv_csp.h
noinst_HEADERS = noinst_HEADERS =
noinst_HEADERS += ../src/dsp/cpu.c
noinst_HEADERS += ../src/dsp/cpu.h noinst_HEADERS += ../src/dsp/cpu.h
noinst_HEADERS += ../src/webp/types.h noinst_HEADERS += ../src/webp/types.h
@ -25,6 +26,7 @@ libsharpyuv_neon_la_CPPFLAGS = $(libsharpyuv_la_CPPFLAGS)
libsharpyuv_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_FLAGS) libsharpyuv_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_FLAGS)
libsharpyuv_la_SOURCES = libsharpyuv_la_SOURCES =
libsharpyuv_la_SOURCES += sharpyuv_cpu.c sharpyuv_cpu.h
libsharpyuv_la_SOURCES += sharpyuv_csp.c sharpyuv_csp.h libsharpyuv_la_SOURCES += sharpyuv_csp.c sharpyuv_csp.h
libsharpyuv_la_SOURCES += sharpyuv_dsp.c sharpyuv_dsp.h libsharpyuv_la_SOURCES += sharpyuv_dsp.c sharpyuv_dsp.h
libsharpyuv_la_SOURCES += sharpyuv_gamma.c sharpyuv_gamma.h libsharpyuv_la_SOURCES += sharpyuv_gamma.c sharpyuv_gamma.h

View File

@ -20,7 +20,7 @@
#include <string.h> #include <string.h>
#include "src/webp/types.h" #include "src/webp/types.h"
#include "src/dsp/cpu.h" #include "sharpyuv/sharpyuv_cpu.h"
#include "sharpyuv/sharpyuv_dsp.h" #include "sharpyuv/sharpyuv_dsp.h"
#include "sharpyuv/sharpyuv_gamma.h" #include "sharpyuv/sharpyuv_gamma.h"
@ -431,26 +431,23 @@ static int DoSharpArgbToYuv(const uint8_t* r_ptr, const uint8_t* g_ptr,
#endif // defined(WEBP_USE_THREAD) && !defined(_WIN32) #endif // defined(WEBP_USE_THREAD) && !defined(_WIN32)
// Hidden exported init function. // Hidden exported init function.
// By default SharpYuvConvert calls it with NULL. If needed, users can declare // By default SharpYuvConvert calls it with SharpYuvGetCPUInfo. If needed,
// it as extern and call it with a VP8CPUInfo function. // users can declare it as extern and call it with an alternate VP8CPUInfo
// function.
SHARPYUV_EXTERN void SharpYuvInit(VP8CPUInfo cpu_info_func); SHARPYUV_EXTERN void SharpYuvInit(VP8CPUInfo cpu_info_func);
void SharpYuvInit(VP8CPUInfo cpu_info_func) { void SharpYuvInit(VP8CPUInfo cpu_info_func) {
static volatile VP8CPUInfo sharpyuv_last_cpuinfo_used = static volatile VP8CPUInfo sharpyuv_last_cpuinfo_used =
(VP8CPUInfo)&sharpyuv_last_cpuinfo_used; (VP8CPUInfo)&sharpyuv_last_cpuinfo_used;
LOCK_ACCESS; LOCK_ACCESS;
{ SharpYuvGetCPUInfo = cpu_info_func;
const int initialized = if (sharpyuv_last_cpuinfo_used == SharpYuvGetCPUInfo) {
(sharpyuv_last_cpuinfo_used != (VP8CPUInfo)&sharpyuv_last_cpuinfo_used); UNLOCK_ACCESS_AND_RETURN;
if (cpu_info_func == NULL && initialized) UNLOCK_ACCESS_AND_RETURN; }
if (sharpyuv_last_cpuinfo_used == cpu_info_func) UNLOCK_ACCESS_AND_RETURN;
SharpYuvInitDsp(cpu_info_func); SharpYuvInitDsp();
if (!initialized) {
SharpYuvInitGammaTables(); SharpYuvInitGammaTables();
}
sharpyuv_last_cpuinfo_used = cpu_info_func; sharpyuv_last_cpuinfo_used = SharpYuvGetCPUInfo;
}
UNLOCK_ACCESS_AND_RETURN; UNLOCK_ACCESS_AND_RETURN;
} }
@ -487,7 +484,7 @@ int SharpYuvConvert(const void* r_ptr, const void* g_ptr,
// Stride should be even for uint16_t buffers. // Stride should be even for uint16_t buffers.
return 0; return 0;
} }
SharpYuvInit(NULL); SharpYuvInit(SharpYuvGetCPUInfo);
// Add scaling factor to go from rgb_bit_depth to yuv_bit_depth, to the // Add scaling factor to go from rgb_bit_depth to yuv_bit_depth, to the
// rgb->yuv conversion matrix. // rgb->yuv conversion matrix.

14
sharpyuv/sharpyuv_cpu.c Normal file
View File

@ -0,0 +1,14 @@
// Copyright 2022 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
#include "sharpyuv/sharpyuv_cpu.h"
// Include src/dsp/cpu.c to create SharpYuvGetCPUInfo from VP8GetCPUInfo. The
// function pointer is renamed in sharpyuv_cpu.h.
#include "src/dsp/cpu.c"

22
sharpyuv/sharpyuv_cpu.h Normal file
View File

@ -0,0 +1,22 @@
// Copyright 2022 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
#ifndef WEBP_SHARPYUV_SHARPYUV_CPU_H_
#define WEBP_SHARPYUV_SHARPYUV_CPU_H_
#include "sharpyuv/sharpyuv.h"
// Avoid exporting SharpYuvGetCPUInfo in shared object / DLL builds.
// SharpYuvInit() replaces the use of the function pointer.
#undef WEBP_EXTERN
#define WEBP_EXTERN extern
#define VP8GetCPUInfo SharpYuvGetCPUInfo
#include "src/dsp/cpu.h"
#endif // WEBP_SHARPYUV_SHARPYUV_CPU_H_

View File

@ -16,7 +16,7 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include "src/dsp/cpu.h" #include "sharpyuv/sharpyuv_cpu.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -75,23 +75,24 @@ void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,
extern void InitSharpYuvSSE2(void); extern void InitSharpYuvSSE2(void);
extern void InitSharpYuvNEON(void); extern void InitSharpYuvNEON(void);
void SharpYuvInitDsp(VP8CPUInfo cpu_info_func) { void SharpYuvInitDsp(void) {
(void)cpu_info_func;
#if !WEBP_NEON_OMIT_C_CODE #if !WEBP_NEON_OMIT_C_CODE
SharpYuvUpdateY = SharpYuvUpdateY_C; SharpYuvUpdateY = SharpYuvUpdateY_C;
SharpYuvUpdateRGB = SharpYuvUpdateRGB_C; SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;
SharpYuvFilterRow = SharpYuvFilterRow_C; SharpYuvFilterRow = SharpYuvFilterRow_C;
#endif #endif
if (SharpYuvGetCPUInfo != NULL) {
#if defined(WEBP_HAVE_SSE2) #if defined(WEBP_HAVE_SSE2)
if (cpu_info_func == NULL || cpu_info_func(kSSE2)) { if (SharpYuvGetCPUInfo(kSSE2)) {
InitSharpYuvSSE2(); InitSharpYuvSSE2();
} }
#endif // WEBP_HAVE_SSE2 #endif // WEBP_HAVE_SSE2
}
#if defined(WEBP_HAVE_NEON) #if defined(WEBP_HAVE_NEON)
if (WEBP_NEON_OMIT_C_CODE || cpu_info_func == NULL || cpu_info_func(kNEON)) { if (WEBP_NEON_OMIT_C_CODE ||
(SharpYuvGetCPUInfo != NULL && SharpYuvGetCPUInfo(kNEON))) {
InitSharpYuvNEON(); InitSharpYuvNEON();
} }
#endif // WEBP_HAVE_NEON #endif // WEBP_HAVE_NEON

View File

@ -12,7 +12,6 @@
#ifndef WEBP_SHARPYUV_SHARPYUV_DSP_H_ #ifndef WEBP_SHARPYUV_SHARPYUV_DSP_H_
#define WEBP_SHARPYUV_SHARPYUV_DSP_H_ #define WEBP_SHARPYUV_SHARPYUV_DSP_H_
#include "src/dsp/cpu.h"
#include "src/webp/types.h" #include "src/webp/types.h"
extern uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref, extern uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref,
@ -23,6 +22,6 @@ extern void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len,
const uint16_t* best_y, uint16_t* out, const uint16_t* best_y, uint16_t* out,
int bit_depth); int bit_depth);
void SharpYuvInitDsp(VP8CPUInfo cpu_info_func); void SharpYuvInitDsp(void);
#endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_ #endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_

View File

@ -212,7 +212,7 @@ VP8CPUInfo VP8GetCPUInfo = wasmCPUInfo;
#elif defined(WEBP_HAVE_NEON) #elif defined(WEBP_HAVE_NEON)
// In most cases this function doesn't check for NEON support (it's assumed by // In most cases this function doesn't check for NEON support (it's assumed by
// the configuration), but enables turning off NEON at runtime, for testing // the configuration), but enables turning off NEON at runtime, for testing
// purposes, by setting VP8DecGetCPUInfo = NULL. // purposes, by setting VP8GetCPUInfo = NULL.
static int armCPUInfo(CPUFeature feature) { static int armCPUInfo(CPUFeature feature) {
if (feature != kNEON) return 0; if (feature != kNEON) return 0;
#if defined(__linux__) && defined(WEBP_HAVE_NEON_RTCD) #if defined(__linux__) && defined(WEBP_HAVE_NEON_RTCD)