summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2023-04-12 13:52:11 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-04-12 13:52:11 +0000
commit26eb19870a70b762ade90ec7fe42efa5105cb1a2 (patch)
tree7b1f3225d9c7118c947bf8f2ba9c2eb66b9a420b
parentecd5d511ec9d3c61f199564a7d7b0a0ca7e74e47 (diff)
parentcc89e956c088ef279a3a3192e689a86175be0f31 (diff)
Merge "minui: Add SPR support for drm" into u-keystone-qcom-dev
-rw-r--r--minui/graphics_drm.cpp117
-rw-r--r--minui/graphics_drm.h137
2 files changed, 253 insertions, 1 deletions
diff --git a/minui/graphics_drm.cpp b/minui/graphics_drm.cpp
index c17cef95..a8cd5a95 100644
--- a/minui/graphics_drm.cpp
+++ b/minui/graphics_drm.cpp
@@ -54,6 +54,7 @@
#include <memory>
#include <android-base/macros.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <string>
@@ -189,6 +190,98 @@ static int atomic_add_prop_to_plane(Plane *plane_res, drmModeAtomicReq *req,
return 0;
}
+static int SetupSprBlobV1(int fd, uint32_t* blob_id) {
+ SPRPackType pack_type = SPRPackType::kPentile;
+ SPRFilterType filter_type = SPRFilterType::kFourTap;
+ SPRAdaptiveModeType adpative_mode = SPRAdaptiveModeType::kYYGM;
+
+ drm_msm_spr_init_cfg spr_init_cfg;
+ spr_init_cfg.cfg0 = 1;
+ spr_init_cfg.cfg1 = 1;
+ spr_init_cfg.cfg2 = 1;
+ spr_init_cfg.cfg3 = 0;
+ spr_init_cfg.flags = 0;
+ spr_init_cfg.cfg4 = (pack_type == SPRPackType::kRGBW);
+ spr_init_cfg.cfg5 = kDefaultColorPhaseIncrement.at(pack_type);
+ spr_init_cfg.cfg6 = kDefaultColorPhaseRepeat.at(pack_type);
+ spr_init_cfg.cfg7 = static_cast<uint16_t>(filter_type);
+ spr_init_cfg.cfg8 = static_cast<uint16_t>(adpative_mode);
+ if (pack_type == SPRPackType::kRGBW) {
+ spr_init_cfg.cfg9 = 512;
+ std::copy(kDefaultRGBWGains.begin(), kDefaultRGBWGains.end(), spr_init_cfg.cfg11);
+ }
+ spr_init_cfg.cfg10 = 0;
+ std::copy(kDecimationRatioMap.at(pack_type).begin(), kDecimationRatioMap.at(pack_type).end(),
+ spr_init_cfg.cfg11);
+ std::copy(kDefaultOPRGains.begin(), kDefaultOPRGains.end(), spr_init_cfg.cfg13);
+ std::copy(kDefaultAdaptiveStrengths.begin(), kDefaultAdaptiveStrengths.end(), spr_init_cfg.cfg14);
+ std::copy(kDefaultOPROffsets.begin(), kDefaultOPROffsets.end(), spr_init_cfg.cfg15);
+ std::copy(kDefaultFilterCoeffsMap.at(filter_type).begin(),
+ kDefaultFilterCoeffsMap.at(filter_type).end(), spr_init_cfg.cfg16);
+ std::copy(kDefaultColorPhaseMap.at(pack_type).begin(), kDefaultColorPhaseMap.at(pack_type).end(),
+ spr_init_cfg.cfg17);
+
+ if (drmModeCreatePropertyBlob(fd, &spr_init_cfg, sizeof(drm_msm_spr_init_cfg), blob_id)) {
+ printf("failed to create spr blob\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int SetupSprBlobV2(int fd, uint32_t* blob_id) {
+ SPRPackType pack_type = SPRPackType::kPentile;
+ SPRFilterType filter_type = SPRFilterType::kFourTap;
+ SPRAdaptiveModeType adpative_mode = SPRAdaptiveModeType::kYYGM;
+
+ drm_msm_spr_init_cfg_v2 spr_init_cfg_v2;
+ spr_init_cfg_v2.cfg0 = 1;
+ spr_init_cfg_v2.cfg1 = 1;
+ spr_init_cfg_v2.cfg2 = 1;
+ spr_init_cfg_v2.cfg3 = 0;
+ spr_init_cfg_v2.flags = 0;
+ spr_init_cfg_v2.cfg4 = (pack_type == SPRPackType::kRGBW);
+ spr_init_cfg_v2.cfg5 = kDefaultColorPhaseIncrement.at(pack_type);
+ spr_init_cfg_v2.cfg6 = kDefaultColorPhaseRepeat.at(pack_type);
+ spr_init_cfg_v2.cfg7 = static_cast<uint16_t>(filter_type);
+ spr_init_cfg_v2.cfg8 = static_cast<uint16_t>(adpative_mode);
+ if (pack_type == SPRPackType::kRGBW) {
+ spr_init_cfg_v2.cfg9 = 512;
+ std::copy(kDefaultRGBWGains.begin(), kDefaultRGBWGains.end(), spr_init_cfg_v2.cfg11);
+ }
+ spr_init_cfg_v2.cfg10 = 0;
+ std::copy(kDecimationRatioMap.at(pack_type).begin(), kDecimationRatioMap.at(pack_type).end(),
+ spr_init_cfg_v2.cfg11);
+ std::copy(kDefaultOPRGains.begin(), kDefaultOPRGains.end(), spr_init_cfg_v2.cfg13);
+ std::copy(kDefaultAdaptiveStrengths.begin(), kDefaultAdaptiveStrengths.end(),
+ spr_init_cfg_v2.cfg14);
+ std::copy(kDefaultOPROffsets.begin(), kDefaultOPROffsets.end(), spr_init_cfg_v2.cfg15);
+ std::copy(kDefaultFilterCoeffsMap.at(filter_type).begin(),
+ kDefaultFilterCoeffsMap.at(filter_type).end(), spr_init_cfg_v2.cfg16);
+ std::copy(kDefaultColorPhaseMap.at(pack_type).begin(), kDefaultColorPhaseMap.at(pack_type).end(),
+ spr_init_cfg_v2.cfg17);
+
+ if (drmModeCreatePropertyBlob(fd, &spr_init_cfg_v2, sizeof(drm_msm_spr_init_cfg_v2), blob_id)) {
+ printf("failed to create spr blob\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int SetupSprBlob(int fd, const std::string& prop_name, uint32_t* blob_id) {
+ int ret = 0;
+ if (prop_name == "SDE_SPR_INIT_CFG_V1") {
+ ret = SetupSprBlobV1(fd, blob_id);
+ } else if (prop_name == "SDE_SPR_INIT_CFG_V2") {
+ ret = SetupSprBlobV2(fd, blob_id);
+ } else {
+ ret = -ENOENT;
+ }
+
+ return ret;
+}
+
int MinuiBackendDrm::AtomicPopulatePlane(int plane, drmModeAtomicReqPtr atomic_req, DrmConnector index) {
uint32_t src_x, src_y, src_w, src_h;
uint32_t crtc_x, crtc_y, crtc_w, crtc_h;
@@ -265,6 +358,10 @@ int MinuiBackendDrm::TeardownPipeline(drmModeAtomicReqPtr atomic_req, DrmConnect
add_prop(&conn_res, connector, Connector, drm[index].monitor_connector->connector_id, "CRTC_ID", 0, index);
add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "MODE_ID", 0, index);
add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "ACTIVE", 0, index);
+ if (spr_enabled) {
+ add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, spr_prop_name.c_str(), 0,
+ index);
+ }
for(i = 0; i < number_of_lms; i++) {
ret = atomic_add_prop_to_plane(plane_res, atomic_req,
@@ -292,6 +389,10 @@ int MinuiBackendDrm::SetupPipeline(drmModeAtomicReqPtr atomic_req, DrmConnector
"CRTC_ID", drm[index].monitor_crtc->crtc_id, index);
add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "MODE_ID", crtc_res.mode_blob_id, index);
add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "ACTIVE", 1, index);
+ if (spr_enabled) {
+ add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, spr_prop_name.c_str(),
+ crtc_res.spr_blob_id, index);
+ }
}
/* Setup planes */
@@ -652,6 +753,7 @@ GRSurface* MinuiBackendDrm::Init() {
drmModeRes* res = nullptr;
drm_fd = -1;
+ spr_enabled = android::base::GetIntProperty("vendor.display.enable_spr", 0);
number_of_lms = DEFAULT_NUM_LMS;
/* Consider DRM devices in order. */
for (int i = 0; i < DRM_MAX_MINOR; i++) {
@@ -743,9 +845,15 @@ GRSurface* MinuiBackendDrm::Init() {
if (!crtc_res.props_info)
return NULL;
else
- for (int j = 0; j < (int)crtc_res.props->count_props; ++j)
+ for (int j = 0; j < (int)crtc_res.props->count_props; ++j) {
crtc_res.props_info[j] = drmModeGetProperty(drm_fd,
crtc_res.props->props[j]);
+ /* Get spr property name */
+ if (!strcmp(crtc_res.props_info[j]->name, "SDE_SPR_INIT_CFG_V1") ||
+ !strcmp(crtc_res.props_info[j]->name, "SDE_SPR_INIT_CFG_V2")) {
+ spr_prop_name = crtc_res.props_info[j]->name;
+ }
+ }
/* Set connector resources */
conn_res.props = drmModeObjectGetProperties(drm_fd,
@@ -800,6 +908,13 @@ GRSurface* MinuiBackendDrm::Init() {
drmModeFreePlaneResources(plane_options);
plane_options = NULL;
+ /* Setup spr blob id if enabled */
+ if (spr_enabled) {
+ if (SetupSprBlob(drm_fd, spr_prop_name, &crtc_res.spr_blob_id)) {
+ return NULL;
+ }
+ }
+
/* Setup pipe and blob_id */
if (drmModeCreatePropertyBlob(drm_fd, &drm[DRM_MAIN].monitor_crtc->mode, sizeof(drmModeModeInfo),
&crtc_res.mode_blob_id)) {
diff --git a/minui/graphics_drm.h b/minui/graphics_drm.h
index 5124dbe9..a883e84d 100644
--- a/minui/graphics_drm.h
+++ b/minui/graphics_drm.h
@@ -19,6 +19,8 @@
#include <stddef.h>
#include <stdint.h>
+#include <array>
+#include <map>
#include <memory>
#include <xf86drmMode.h>
@@ -30,10 +32,97 @@
#define NUM_PLANES 4
#define DEFAULT_NUM_LMS 2
+#define SPR_INIT_PARAM_SIZE_1 4
+#define SPR_INIT_PARAM_SIZE_2 5
+#define SPR_INIT_PARAM_SIZE_3 16
+#define SPR_INIT_PARAM_SIZE_4 24
+#define SPR_INIT_PARAM_SIZE_5 32
+#define SPR_INIT_PARAM_SIZE_6 7
+
+enum class SPRPackType {
+ kPentile,
+ kRGBW,
+ kYYGW,
+ kYYGM,
+ kDelta3,
+ kMax = 0xFF,
+};
+
+enum class SPRFilterType {
+ kPixelDrop,
+ kBilinear,
+ kFourTap,
+ kAdaptive,
+ k2DAvg,
+ kMax = 0xFF,
+};
+
+enum class SPRAdaptiveModeType {
+ kYYGM,
+ kYYGW,
+ kMax = 0xFF,
+};
+
+static const std::map<SPRPackType, uint32_t> kDefaultColorPhaseIncrement = {
+ { { { SPRPackType::kPentile }, { 8 } },
+ { { SPRPackType::kYYGM }, { 6 } },
+ { { SPRPackType::kYYGW }, { 6 } },
+ { { SPRPackType::kDelta3 }, { 6 } },
+ { { SPRPackType::kRGBW }, { 8 } } }
+};
+static const std::map<SPRPackType, uint32_t> kDefaultColorPhaseRepeat = {
+ { { { SPRPackType::kPentile }, { 2 } },
+ { { SPRPackType::kYYGM }, { 2 } },
+ { { SPRPackType::kYYGW }, { 2 } },
+ { { SPRPackType::kDelta3 }, { 2 } },
+ { { SPRPackType::kRGBW }, { 2 } } }
+};
+static const std::map<SPRPackType, std::array<uint16_t, SPR_INIT_PARAM_SIZE_1>> kDecimationRatioMap{
+ {
+ { { SPRPackType::kPentile }, { 1, 0, 1, 0 } },
+ { { SPRPackType::kYYGM }, { 2, 2, 2, 0 } },
+ { { SPRPackType::kYYGW }, { 2, 2, 2, 0 } },
+ { { SPRPackType::kRGBW }, { 1, 1, 1, 1 } },
+ }
+};
+static const std::map<SPRFilterType, std::array<int16_t, SPR_INIT_PARAM_SIZE_3>>
+ kDefaultFilterCoeffsMap{
+ { { { SPRFilterType::kPixelDrop }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { SPRFilterType::kBilinear },
+ { 0, 512, 0, 0, -33, 443, 110, -8, -23, 279, 279, -23, -8, 110, 443, -33 } },
+ { { SPRFilterType::kFourTap },
+ { 128, 256, 128, 0, 86, 241, 164, 21, 52, 204, 204, 52, 21, 164, 241, 86 } },
+ { { SPRFilterType::kAdaptive },
+ { 0, 256, 256, 0, 0, 256, 256, 0, 0, 256, 256, 0, 0, 256, 256, 0 } } }
+ };
+static const std::map<SPRPackType, std::array<int16_t, SPR_INIT_PARAM_SIZE_4>>
+ kDefaultColorPhaseMap{
+ { { { SPRPackType::kPentile },
+ { -2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { SPRPackType::kYYGM },
+ { -3, 0, 0, 0, 0, 0, -1, 2, 1, 1, 0, 0, 1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { SPRPackType::kYYGW },
+ { -4, 2, 0, 0, 0, -1, 2, 2, 0, -1, -1, -1, 2, 2, -1, -1, -1, 2, 0, 0, 0, 0, 0, 0 } },
+ { { SPRPackType::kDelta3 },
+ { -3, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { SPRPackType::kRGBW },
+ { -4, 0, 0, 0, 0, 0, -2, 2, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 2, -2, 0, 0, 0, 0 } } }
+ };
+static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_1> kDefaultRGBWGains = { 1024, 1024, 1024,
+ 341 };
+static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_1> kDefaultOPRGains = { 341, 341, 341, 0 };
+static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_2> kDefaultAdaptiveStrengths = { 0, 4, 8, 12,
+ 16 };
+static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_5> kDefaultOPROffsets = {
+ 0, 132, 264, 396, 529, 661, 793, 925, 1057, 1189, 1321, 1453, 1586, 1718, 1850, 1982,
+ 2114, 2246, 2378, 2510, 2643, 2775, 2907, 3039, 3171, 3303, 3435, 3567, 3700, 3832, 3964, 4095
+};
+
struct Crtc {
drmModeObjectProperties *props;
drmModePropertyRes **props_info;
uint32_t mode_blob_id;
+ uint32_t spr_blob_id;
};
struct Connector {
@@ -47,6 +136,52 @@ struct Plane {
drmModePropertyRes ** props_info;
};
+struct drm_msm_spr_init_cfg {
+ __u64 flags;
+ __u16 cfg0;
+ __u16 cfg1;
+ __u16 cfg2;
+ __u16 cfg3;
+ __u16 cfg4;
+ __u16 cfg5;
+ __u16 cfg6;
+ __u16 cfg7;
+ __u16 cfg8;
+ __u16 cfg9;
+ __u32 cfg10;
+ __u16 cfg11[SPR_INIT_PARAM_SIZE_1];
+ __u16 cfg12[SPR_INIT_PARAM_SIZE_1];
+ __u16 cfg13[SPR_INIT_PARAM_SIZE_1];
+ __u16 cfg14[SPR_INIT_PARAM_SIZE_2];
+ __u16 cfg15[SPR_INIT_PARAM_SIZE_5];
+ int cfg16[SPR_INIT_PARAM_SIZE_3];
+ int cfg17[SPR_INIT_PARAM_SIZE_4];
+};
+
+struct drm_msm_spr_init_cfg_v2 {
+ __u64 flags;
+ __u16 cfg0;
+ __u16 cfg1;
+ __u16 cfg2;
+ __u16 cfg3;
+ __u16 cfg4;
+ __u16 cfg5;
+ __u16 cfg6;
+ __u16 cfg7;
+ __u16 cfg8;
+ __u16 cfg9;
+ __u32 cfg10;
+ __u16 cfg11[SPR_INIT_PARAM_SIZE_1];
+ __u16 cfg12[SPR_INIT_PARAM_SIZE_1];
+ __u16 cfg13[SPR_INIT_PARAM_SIZE_1];
+ __u16 cfg14[SPR_INIT_PARAM_SIZE_2];
+ __u16 cfg15[SPR_INIT_PARAM_SIZE_5];
+ int cfg16[SPR_INIT_PARAM_SIZE_3];
+ int cfg17[SPR_INIT_PARAM_SIZE_4];
+ __u16 cfg18_en;
+ __u8 cfg18[SPR_INIT_PARAM_SIZE_6];
+};
+
class GRSurfaceDrm : public GRSurface {
public:
~GRSurfaceDrm() override;
@@ -111,4 +246,6 @@ class MinuiBackendDrm : public MinuiBackend {
struct Connector conn_res;
struct Plane plane_res[NUM_PLANES];
uint32_t number_of_lms;
+ uint32_t spr_enabled;
+ std::string spr_prop_name;
};