Integrate GPU conversion and update capture pipeline
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
project(gvfg_convert LANGUAGES CXX)
|
||||
|
||||
add_library(gvfg_convert SHARED
|
||||
include/gvfg_convert.h
|
||||
src/gvfg_convert.cpp
|
||||
)
|
||||
|
||||
set_target_properties(gvfg_convert PROPERTIES
|
||||
AUTOMOC OFF
|
||||
AUTOUIC OFF
|
||||
AUTORCC OFF
|
||||
)
|
||||
|
||||
target_include_directories(gvfg_convert
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg_convert PRIVATE
|
||||
GVFG_CONVERT_BUILD
|
||||
)
|
||||
|
||||
target_link_libraries(gvfg_convert PUBLIC
|
||||
gvfg
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(gvfg_convert PRIVATE /utf-8 /EHsc)
|
||||
endif()
|
||||
|
||||
install(TARGETS gvfg_convert
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
||||
|
||||
install(FILES include/gvfg_convert.h
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
@@ -1,70 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Optional GVFG frame conversion helper.
|
||||
*
|
||||
* Link this helper only when the application needs snapshot/export-friendly
|
||||
* buffers. Core capture frames from gvfg.dll remain native hardware buffers.
|
||||
*/
|
||||
|
||||
#include <gvfg_capture.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef GVFG_CONVERT_BUILD
|
||||
#define GVFG_CONVERT_API __declspec(dllexport)
|
||||
#else
|
||||
#define GVFG_CONVERT_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define GVFG_CONVERT_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_CONVERT_FMT_BGRA8 = 1, /* 8-bit BGRA, alpha 255. */
|
||||
GVFG_CONVERT_FMT_RGB48 = 2, /* 16-bit RGB container, useful for 10-bit snapshots. */
|
||||
GVFG_CONVERT_FMT_RGBA64 = 3 /* 16-bit RGBA container, alpha 65535. */
|
||||
} gvfg_convert_format_t;
|
||||
|
||||
typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width; /* Frame width in pixels. Use 0 to size from source during conversion. */
|
||||
int height; /* Frame height in pixels. Use 0 to size from source during conversion. */
|
||||
int pixel_format; /* gvfg_convert_format_t destination format. */
|
||||
int row_bytes; /* Destination row stride in bytes. Use 0 for helper default. */
|
||||
uint64_t data_size; /* Output buffer size in bytes, filled after create/convert. */
|
||||
} gvfg_convert_frame_desc_t;
|
||||
|
||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_create_frame(
|
||||
_In_ const gvfg_convert_frame_desc_t *desc,
|
||||
_Outptr_ gvfg_convert_frame *out_frame);
|
||||
|
||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_destroy_frame(
|
||||
_In_opt_ gvfg_convert_frame frame);
|
||||
|
||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_frame_from_capture(
|
||||
_In_ const gvfg_frame_t *src,
|
||||
_In_ gvfg_convert_frame dst_frame);
|
||||
|
||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_frame_desc(
|
||||
_In_ gvfg_convert_frame frame,
|
||||
_Out_ gvfg_convert_frame_desc_t *out_desc);
|
||||
|
||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_buffer(
|
||||
_In_ gvfg_convert_frame frame,
|
||||
_Out_ const void **out_data,
|
||||
_Out_ uint64_t *out_size);
|
||||
|
||||
GVFG_CONVERT_API const char *gvfg_convert_strerror(
|
||||
_In_ gvfg_status_t status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,428 +0,0 @@
|
||||
#include "gvfg_convert.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool checked_mul_u64(uint64_t a, uint64_t b, uint64_t &out)
|
||||
{
|
||||
if (a != 0 && b > UINT64_MAX / a)
|
||||
return false;
|
||||
out = a * b;
|
||||
return true;
|
||||
}
|
||||
|
||||
int convert_format_bytes_per_pixel(int fmt)
|
||||
{
|
||||
switch (fmt)
|
||||
{
|
||||
case GVFG_CONVERT_FMT_BGRA8:
|
||||
return 4;
|
||||
case GVFG_CONVERT_FMT_RGB48:
|
||||
return 6;
|
||||
case GVFG_CONVERT_FMT_RGBA64:
|
||||
return 8;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t clamp_u8(double v)
|
||||
{
|
||||
if (v <= 0.0)
|
||||
return 0;
|
||||
if (v >= 255.0)
|
||||
return 255;
|
||||
return static_cast<uint8_t>(v + 0.5);
|
||||
}
|
||||
|
||||
uint16_t clamp_u16(double v)
|
||||
{
|
||||
if (v <= 0.0)
|
||||
return 0;
|
||||
if (v >= 65535.0)
|
||||
return 65535;
|
||||
return static_cast<uint16_t>(v + 0.5);
|
||||
}
|
||||
|
||||
void yuv709_limited_to_rgb01(double y01,
|
||||
double u01,
|
||||
double v01,
|
||||
double &r,
|
||||
double &g,
|
||||
double &b)
|
||||
{
|
||||
const double y = y01 * 255.0;
|
||||
const double u = (u01 - 0.5) * 255.0;
|
||||
const double v = (v01 - 0.5) * 255.0;
|
||||
const double c = y - 16.0;
|
||||
r = (1.164383 * c + 1.792741 * v) / 255.0;
|
||||
g = (1.164383 * c - 0.213249 * u - 0.532909 * v) / 255.0;
|
||||
b = (1.164383 * c + 2.112402 * u) / 255.0;
|
||||
}
|
||||
|
||||
void store_converted_pixel(uint8_t *dst,
|
||||
int dstFormat,
|
||||
double r,
|
||||
double g,
|
||||
double b)
|
||||
{
|
||||
switch (dstFormat)
|
||||
{
|
||||
case GVFG_CONVERT_FMT_BGRA8:
|
||||
dst[0] = clamp_u8(b * 255.0);
|
||||
dst[1] = clamp_u8(g * 255.0);
|
||||
dst[2] = clamp_u8(r * 255.0);
|
||||
dst[3] = 255;
|
||||
break;
|
||||
case GVFG_CONVERT_FMT_RGB48:
|
||||
{
|
||||
auto *out = reinterpret_cast<uint16_t *>(dst);
|
||||
out[0] = clamp_u16(r * 65535.0);
|
||||
out[1] = clamp_u16(g * 65535.0);
|
||||
out[2] = clamp_u16(b * 65535.0);
|
||||
break;
|
||||
}
|
||||
case GVFG_CONVERT_FMT_RGBA64:
|
||||
{
|
||||
auto *out = reinterpret_cast<uint16_t *>(dst);
|
||||
out[0] = clamp_u16(r * 65535.0);
|
||||
out[1] = clamp_u16(g * 65535.0);
|
||||
out[2] = clamp_u16(b * 65535.0);
|
||||
out[3] = 65535;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t y210_word_to_10bit(uint16_t value)
|
||||
{
|
||||
return static_cast<uint16_t>((value >> 6) & 0x03ffu);
|
||||
}
|
||||
}
|
||||
|
||||
struct gvfg_convert_frame_t
|
||||
{
|
||||
gvfg_convert_frame_desc_t request{};
|
||||
gvfg_convert_frame_desc_t desc{};
|
||||
std::vector<uint8_t> buffer;
|
||||
|
||||
gvfg_status_t configure(int width, int height, int pixelFormat, int rowBytes)
|
||||
{
|
||||
if (width <= 0 || height <= 0 || convert_format_bytes_per_pixel(pixelFormat) <= 0)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
const int bytesPerPixel = convert_format_bytes_per_pixel(pixelFormat);
|
||||
uint64_t minStride64 = 0;
|
||||
if (!checked_mul_u64(static_cast<uint64_t>(width),
|
||||
static_cast<uint64_t>(bytesPerPixel),
|
||||
minStride64) ||
|
||||
minStride64 > static_cast<uint64_t>(INT_MAX))
|
||||
return GVFG_EINVAL;
|
||||
|
||||
const int minStride = static_cast<int>(minStride64);
|
||||
const int actualStride = rowBytes > 0 ? rowBytes : minStride;
|
||||
if (actualStride < minStride)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
uint64_t size = 0;
|
||||
if (!checked_mul_u64(static_cast<uint64_t>(actualStride),
|
||||
static_cast<uint64_t>(height),
|
||||
size) ||
|
||||
size > static_cast<uint64_t>((std::numeric_limits<size_t>::max)()))
|
||||
return GVFG_EINVAL;
|
||||
|
||||
desc = request;
|
||||
desc.width = width;
|
||||
desc.height = height;
|
||||
desc.pixel_format = pixelFormat;
|
||||
desc.row_bytes = actualStride;
|
||||
desc.data_size = size;
|
||||
|
||||
try
|
||||
{
|
||||
buffer.resize(static_cast<size_t>(size));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
buffer.clear();
|
||||
desc.data_size = 0;
|
||||
return GVFG_EIO;
|
||||
}
|
||||
|
||||
return GVFG_OK;
|
||||
}
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
gvfg_status_t create_or_reconfigure_frame(const gvfg_frame_t &src,
|
||||
gvfg_convert_frame_t &dst)
|
||||
{
|
||||
const int requestedWidth = dst.request.width;
|
||||
const int requestedHeight = dst.request.height;
|
||||
const int targetWidth = requestedWidth > 0 ? requestedWidth : src.width;
|
||||
const int targetHeight = requestedHeight > 0 ? requestedHeight : src.height;
|
||||
|
||||
if (targetWidth != src.width || targetHeight != src.height)
|
||||
return GVFG_ENOTSUP;
|
||||
|
||||
if (!dst.buffer.empty() &&
|
||||
dst.desc.width == targetWidth &&
|
||||
dst.desc.height == targetHeight &&
|
||||
dst.desc.pixel_format == dst.request.pixel_format &&
|
||||
dst.desc.row_bytes > 0)
|
||||
return GVFG_OK;
|
||||
|
||||
return dst.configure(targetWidth, targetHeight, dst.request.pixel_format, dst.request.row_bytes);
|
||||
}
|
||||
|
||||
gvfg_status_t convert_yuy2_to_frame(const gvfg_frame_t &src,
|
||||
gvfg_convert_frame_t &dst)
|
||||
{
|
||||
if (!src.data || src.row_stride_bytes < src.width * 2)
|
||||
return GVFG_EINVAL;
|
||||
uint64_t requiredSize = 0;
|
||||
if (!checked_mul_u64(static_cast<uint64_t>(src.row_stride_bytes),
|
||||
static_cast<uint64_t>(src.height),
|
||||
requiredSize) ||
|
||||
requiredSize > src.data_size)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
const auto *srcBase = static_cast<const uint8_t *>(src.data);
|
||||
const int srcStride = src.row_stride_bytes;
|
||||
const int bytesPerPixel = convert_format_bytes_per_pixel(dst.desc.pixel_format);
|
||||
if (bytesPerPixel <= 0)
|
||||
return GVFG_ENOTSUP;
|
||||
|
||||
for (int y = 0; y < src.height; ++y)
|
||||
{
|
||||
const uint8_t *srcRow = srcBase + static_cast<size_t>(y) * static_cast<size_t>(srcStride);
|
||||
uint8_t *dstRow = dst.buffer.data() + static_cast<size_t>(y) * static_cast<size_t>(dst.desc.row_bytes);
|
||||
|
||||
for (int x = 0; x < src.width; x += 2)
|
||||
{
|
||||
const int sx = x * 2;
|
||||
const uint8_t y0 = srcRow[sx + 0];
|
||||
const uint8_t u = srcRow[sx + 1];
|
||||
const uint8_t y1 = (x + 1 < src.width) ? srcRow[sx + 2] : y0;
|
||||
const uint8_t v = (x + 1 < src.width) ? srcRow[sx + 3] : srcRow[sx + 1];
|
||||
|
||||
double r = 0.0, g = 0.0, b = 0.0;
|
||||
yuv709_limited_to_rgb01(static_cast<double>(y0) / 255.0,
|
||||
static_cast<double>(u) / 255.0,
|
||||
static_cast<double>(v) / 255.0,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
store_converted_pixel(dstRow + static_cast<size_t>(x) * static_cast<size_t>(bytesPerPixel),
|
||||
dst.desc.pixel_format,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
|
||||
if (x + 1 < src.width)
|
||||
{
|
||||
yuv709_limited_to_rgb01(static_cast<double>(y1) / 255.0,
|
||||
static_cast<double>(u) / 255.0,
|
||||
static_cast<double>(v) / 255.0,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
store_converted_pixel(dstRow + static_cast<size_t>(x + 1) * static_cast<size_t>(bytesPerPixel),
|
||||
dst.desc.pixel_format,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t convert_y210_to_frame(const gvfg_frame_t &src,
|
||||
gvfg_convert_frame_t &dst)
|
||||
{
|
||||
if (!src.data || src.row_stride_bytes < src.width * 4)
|
||||
return GVFG_EINVAL;
|
||||
uint64_t requiredSize = 0;
|
||||
if (!checked_mul_u64(static_cast<uint64_t>(src.row_stride_bytes),
|
||||
static_cast<uint64_t>(src.height),
|
||||
requiredSize) ||
|
||||
requiredSize > src.data_size)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
const auto *srcBase = static_cast<const uint8_t *>(src.data);
|
||||
const int srcStride = src.row_stride_bytes;
|
||||
const int bytesPerPixel = convert_format_bytes_per_pixel(dst.desc.pixel_format);
|
||||
if (bytesPerPixel <= 0)
|
||||
return GVFG_ENOTSUP;
|
||||
|
||||
for (int y = 0; y < src.height; ++y)
|
||||
{
|
||||
const auto *srcRow = reinterpret_cast<const uint16_t *>(srcBase + static_cast<size_t>(y) * static_cast<size_t>(srcStride));
|
||||
uint8_t *dstRow = dst.buffer.data() + static_cast<size_t>(y) * static_cast<size_t>(dst.desc.row_bytes);
|
||||
|
||||
for (int x = 0; x < src.width; x += 2)
|
||||
{
|
||||
const int sx = x * 2;
|
||||
// Standard Y210 is Y0, Cb(U), Y1, Cr(V). Normalize the
|
||||
// current FPGA DMA order Y0, Cr(V), Y1, Cb(U) before RGB
|
||||
// conversion so snapshots match the preview path.
|
||||
const uint16_t y0 = y210_word_to_10bit(srcRow[sx + 0]);
|
||||
const uint16_t v = y210_word_to_10bit(srcRow[sx + 1]);
|
||||
const uint16_t y1 = (x + 1 < src.width) ? y210_word_to_10bit(srcRow[sx + 2]) : y0;
|
||||
const uint16_t u = (x + 1 < src.width) ? y210_word_to_10bit(srcRow[sx + 3]) : v;
|
||||
|
||||
double r = 0.0, g = 0.0, b = 0.0;
|
||||
yuv709_limited_to_rgb01(static_cast<double>(y0) / 1023.0,
|
||||
static_cast<double>(u) / 1023.0,
|
||||
static_cast<double>(v) / 1023.0,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
store_converted_pixel(dstRow + static_cast<size_t>(x) * static_cast<size_t>(bytesPerPixel),
|
||||
dst.desc.pixel_format,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
|
||||
if (x + 1 < src.width)
|
||||
{
|
||||
yuv709_limited_to_rgb01(static_cast<double>(y1) / 1023.0,
|
||||
static_cast<double>(u) / 1023.0,
|
||||
static_cast<double>(v) / 1023.0,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
store_converted_pixel(dstRow + static_cast<size_t>(x + 1) * static_cast<size_t>(bytesPerPixel),
|
||||
dst.desc.pixel_format,
|
||||
r,
|
||||
g,
|
||||
b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GVFG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
gvfg_status_t gvfg_convert_create_frame(const gvfg_convert_frame_desc_t *desc,
|
||||
gvfg_convert_frame *out_frame)
|
||||
{
|
||||
if (!desc || !out_frame)
|
||||
return GVFG_EINVAL;
|
||||
*out_frame = nullptr;
|
||||
|
||||
if (convert_format_bytes_per_pixel(desc->pixel_format) <= 0)
|
||||
return GVFG_EINVAL;
|
||||
if (desc->width < 0 || desc->height < 0 || desc->row_bytes < 0)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
auto frame = std::make_unique<gvfg_convert_frame_t>();
|
||||
frame->request = {};
|
||||
frame->request.width = desc->width;
|
||||
frame->request.height = desc->height;
|
||||
frame->request.pixel_format = desc->pixel_format;
|
||||
frame->request.row_bytes = desc->row_bytes;
|
||||
frame->desc = frame->request;
|
||||
|
||||
if (desc->width > 0 || desc->height > 0 || desc->row_bytes > 0)
|
||||
{
|
||||
if (desc->width <= 0 || desc->height <= 0)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
const gvfg_status_t st = frame->configure(desc->width,
|
||||
desc->height,
|
||||
desc->pixel_format,
|
||||
desc->row_bytes);
|
||||
if (st != GVFG_OK)
|
||||
return st;
|
||||
}
|
||||
|
||||
*out_frame = frame.release();
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_convert_destroy_frame(gvfg_convert_frame frame)
|
||||
{
|
||||
delete frame;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_convert_frame_from_capture(const gvfg_frame_t *src,
|
||||
gvfg_convert_frame dst_frame)
|
||||
{
|
||||
if (!src || !dst_frame)
|
||||
return GVFG_EINVAL;
|
||||
|
||||
const gvfg_status_t cfg = create_or_reconfigure_frame(*src, *dst_frame);
|
||||
if (cfg != GVFG_OK)
|
||||
return cfg;
|
||||
|
||||
switch (src->pixel_format)
|
||||
{
|
||||
case GVFG_PIXFMT_YUY2:
|
||||
return convert_yuy2_to_frame(*src, *dst_frame);
|
||||
case GVFG_PIXFMT_Y210:
|
||||
return convert_y210_to_frame(*src, *dst_frame);
|
||||
default:
|
||||
return GVFG_ENOTSUP;
|
||||
}
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_convert_get_frame_desc(gvfg_convert_frame frame,
|
||||
gvfg_convert_frame_desc_t *out_desc)
|
||||
{
|
||||
if (!frame || !out_desc)
|
||||
return GVFG_EINVAL;
|
||||
*out_desc = frame->desc;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_convert_get_buffer(gvfg_convert_frame frame,
|
||||
const void **out_data,
|
||||
uint64_t *out_size)
|
||||
{
|
||||
if (!frame || !out_data || !out_size)
|
||||
return GVFG_EINVAL;
|
||||
*out_data = frame->buffer.empty() ? nullptr : frame->buffer.data();
|
||||
*out_size = static_cast<uint64_t>(frame->buffer.size());
|
||||
return frame->buffer.empty() ? GVFG_ESTATE : GVFG_OK;
|
||||
}
|
||||
|
||||
const char *gvfg_convert_strerror(gvfg_status_t status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case GVFG_OK:
|
||||
return "ok";
|
||||
case GVFG_EINVAL:
|
||||
return "invalid argument";
|
||||
case GVFG_ENODEV:
|
||||
return "device not found";
|
||||
case GVFG_ESTATE:
|
||||
return "invalid state";
|
||||
case GVFG_EIO:
|
||||
return "i/o error";
|
||||
case GVFG_ENOTSUP:
|
||||
return "not supported";
|
||||
case GVFG_ETIMEOUT:
|
||||
return "timeout";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ project(gvfg_preview LANGUAGES CXX)
|
||||
|
||||
add_library(gvfg_preview SHARED
|
||||
include/gvfg_preview.h
|
||||
src/d3d_preview_pipeline.cpp
|
||||
src/d3d_preview_pipeline.h
|
||||
../../sdk/gvfg/src/gpu/d3d_conversion_pipeline.cpp
|
||||
../../sdk/gvfg/src/gpu/d3d_conversion_pipeline.h
|
||||
src/gvfg_preview.cpp
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@ target_include_directories(gvfg_preview
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/gvfg/src/gpu
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg_preview PRIVATE
|
||||
|
||||
@@ -37,8 +37,8 @@ typedef struct gvfg_preview_handle_t *gvfg_preview_handle;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_PREVIEW_PIXFMT_YUY2 = 1,
|
||||
GVFG_PREVIEW_PIXFMT_Y210 = 2
|
||||
GVFG_PREVIEW_PIXFMT_Y210 = 2,
|
||||
GVFG_PREVIEW_PIXFMT_YVYU = 3
|
||||
} gvfg_preview_pixel_format_t;
|
||||
|
||||
typedef struct
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,114 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11_1.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <stdint.h>
|
||||
#include <wrl.h>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_FMT_YUY2,
|
||||
GVFG_RENDER_FMT_Y210
|
||||
} gvfg_render_pixfmt_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_8BIT = 0,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_10BIT = 1,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_AUTO = 2
|
||||
} gvfg_render_preview_bitdepth_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_PREVIEW_PRESENT_FAILED = 0,
|
||||
GVFG_PREVIEW_PRESENTED = 1,
|
||||
GVFG_PREVIEW_PRESENT_SKIPPED = 2
|
||||
} gvfg_preview_present_result_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *hwnd;
|
||||
int enable_preview;
|
||||
int swapchain_10bit;
|
||||
} gvfg_render_preview_desc_t;
|
||||
|
||||
class D3DPreviewPipeline
|
||||
{
|
||||
public:
|
||||
D3DPreviewPipeline() = default;
|
||||
~D3DPreviewPipeline() = default;
|
||||
|
||||
bool initialize(ID3D11Device *d3d,
|
||||
ID3D11DeviceContext *ctx);
|
||||
|
||||
bool configurePreview(const gvfg_render_preview_desc_t &desc);
|
||||
void set_source_bit_depth(int bits);
|
||||
void release_preview_swapchain();
|
||||
|
||||
bool create_shaders_and_states();
|
||||
bool ensure_rt_and_pipeline(int w, int h);
|
||||
bool ensure_preview_swapchain(int w, int h);
|
||||
bool preview_swapchain_10bit() const { return preview_swapchain_10bit_; }
|
||||
gvfg_preview_present_result_t present_preview(int src_w, int src_h);
|
||||
DXGI_FORMAT preview_backbuffer_format() const;
|
||||
DXGI_FORMAT scene_texture_format() const;
|
||||
DXGI_FORMAT linear_fp16_texture_format() const;
|
||||
bool blit_fp16_to_rgba8(int frame_w, int frame_h);
|
||||
bool upload_yuy2_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
||||
bool upload_y210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
||||
bool render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h);
|
||||
bool copy_fp16_to_scene();
|
||||
|
||||
ID3D11Device *d3d_ = nullptr;
|
||||
ID3D11DeviceContext *ctx_ = nullptr;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_scene_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_scene_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_scene_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_rgba8_to_preview_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_yuy2_packed_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_y210_packed_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_rgba_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> cs_params_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11VertexShader> vs_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_yuy2_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_y210_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_fp16_to_rgba8_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_fp16_to_preview_;
|
||||
Microsoft::WRL::ComPtr<ID3D11InputLayout> il_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> vb_;
|
||||
Microsoft::WRL::ComPtr<ID3D11SamplerState> samp_;
|
||||
|
||||
void *preview_hwnd_ = nullptr;
|
||||
bool preview_enabled_ = false;
|
||||
int preview_swapchain_mode_ = GVFG_RENDER_PREVIEW_BITDEPTH_10BIT;
|
||||
int preview_source_bit_depth_ = 0;
|
||||
bool preview_swapchain_10bit_ = false;
|
||||
DXGI_FORMAT preview_swapchain_format_ = DXGI_FORMAT_UNKNOWN;
|
||||
int preview_w_ = 0;
|
||||
int preview_h_ = 0;
|
||||
|
||||
int rt_w_ = 0;
|
||||
int rt_h_ = 0;
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGISwapChain1> preview_swapchain_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> preview_backbuf_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> preview_rtv_;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "gvfg_preview.h"
|
||||
|
||||
#include "d3d_preview_pipeline.h"
|
||||
#include "d3d_conversion_pipeline.h"
|
||||
|
||||
#include <d3d11_4.h>
|
||||
#include <dxgi1_2.h>
|
||||
@@ -61,15 +61,15 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
gvfg::internal::gvfg_render_pixfmt_t renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
gvfg::internal::gvfg_render_pixfmt_t renderFmt = gvfg::internal::GVFG_RENDER_FMT_YVYU;
|
||||
const uint8_t *base = static_cast<const uint8_t *>(frame.data);
|
||||
const int stride = frame.row_bytes;
|
||||
bool uploaded = false;
|
||||
|
||||
switch (frame.pixel_format)
|
||||
{
|
||||
case GVFG_PREVIEW_PIXFMT_YUY2:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
||||
case GVFG_PREVIEW_PIXFMT_YVYU:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_YVYU;
|
||||
break;
|
||||
case GVFG_PREVIEW_PIXFMT_Y210:
|
||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_Y210;
|
||||
@@ -80,8 +80,8 @@ public:
|
||||
|
||||
switch (frame.pixel_format)
|
||||
{
|
||||
case GVFG_PREVIEW_PIXFMT_YUY2:
|
||||
uploaded = pipeline_->upload_yuy2_frame(base, stride, frame.width, frame.height);
|
||||
case GVFG_PREVIEW_PIXFMT_YVYU:
|
||||
uploaded = pipeline_->upload_packed_422_frame(base, stride, frame.width, frame.height);
|
||||
break;
|
||||
case GVFG_PREVIEW_PIXFMT_Y210:
|
||||
uploaded = pipeline_->upload_y210_frame(base, stride, frame.width, frame.height);
|
||||
@@ -438,7 +438,7 @@ extern "C"
|
||||
uint64_t minimumRowBytes = 0;
|
||||
switch (frame->pixel_format)
|
||||
{
|
||||
case GVFG_PREVIEW_PIXFMT_YUY2:
|
||||
case GVFG_PREVIEW_PIXFMT_YVYU:
|
||||
minimumRowBytes = static_cast<uint64_t>(frame->width) * 2u;
|
||||
break;
|
||||
case GVFG_PREVIEW_PIXFMT_Y210:
|
||||
|
||||
Reference in New Issue
Block a user