d3d12: Port to d3dshader library

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6434>
This commit is contained in:
Seungha Yang 2024-03-24 21:11:08 +09:00
parent cab1f3e547
commit 2649d2ae62
21 changed files with 166 additions and 2011 deletions

View file

@ -44,10 +44,7 @@
#include <queue>
#include <string.h>
#include <wrl.h>
#include "PSMain_checker_luma.h"
#include "PSMain_checker_rgb.h"
#include "PSMain_checker_vuya.h"
#include "VSMain_pos.h"
#include <gst/d3dshader/gstd3dshader.h>
GST_DEBUG_CATEGORY_STATIC (gst_d3d12_compositor_debug);
#define GST_CAT_DEFAULT gst_d3d12_compositor_debug
@ -368,20 +365,34 @@ struct BackgroundRender
input_desc.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
input_desc.InstanceDataStepRate = 0;
GstD3DShaderByteCode vs_code;
if (!gst_d3d_plugin_shader_get_vs_blob (GST_D3D_PLUGIN_VS_POS,
GST_D3D_SM_5_0, &vs_code)) {
GST_ERROR_OBJECT (device, "Couldn't get vs bytecode");
return;
}
GstD3DShaderByteCode ps_code;
GstD3DPluginPS ps_type;
if (GST_VIDEO_INFO_IS_RGB (&info))
ps_type = GST_D3D_PLUGIN_PS_CHECKER_RGB;
else if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_VUYA)
ps_type = GST_D3D_PLUGIN_PS_CHECKER_VUYA;
else
ps_type = GST_D3D_PLUGIN_PS_CHECKER_LUMA;
if (!gst_d3d_plugin_shader_get_ps_blob (ps_type,
GST_D3D_SM_5_0, &ps_code)) {
GST_ERROR_OBJECT (device, "Couldn't get ps bytecode");
return;
}
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { };
pso_desc.pRootSignature = rs.Get ();
pso_desc.VS.BytecodeLength = sizeof (g_VSMain_pos);
pso_desc.VS.pShaderBytecode = g_VSMain_pos;
if (GST_VIDEO_INFO_IS_RGB (&info)) {
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_checker_rgb);
pso_desc.PS.pShaderBytecode = g_PSMain_checker_rgb;
} else if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_VUYA) {
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_checker_vuya);
pso_desc.PS.pShaderBytecode = g_PSMain_checker_vuya;
} else {
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_checker_luma);
pso_desc.PS.pShaderBytecode = g_PSMain_checker_luma;
}
pso_desc.VS.BytecodeLength = vs_code.byte_code_len;
pso_desc.VS.pShaderBytecode = vs_code.byte_code;
pso_desc.PS.BytecodeLength = ps_code.byte_code_len;
pso_desc.PS.pShaderBytecode = ps_code.byte_code;
pso_desc.BlendState = CD3DX12_BLEND_DESC (D3D12_DEFAULT);
pso_desc.SampleMask = UINT_MAX;
pso_desc.RasterizerState = CD3DX12_RASTERIZER_DESC (D3D12_DEFAULT);

View file

@ -23,345 +23,80 @@
#include "gstd3d12.h"
#include "gstd3d12converter-builder.h"
#include <gst/d3dshader/gstd3dshader.h>
#include <directx/d3dx12.h>
#include <map>
#include <mutex>
#include <string>
#include <utility>
#include <memory>
#include "PSMainConverter.h"
#include "VSMain_converter.h"
GST_DEBUG_CATEGORY_EXTERN (gst_d3d12_converter_debug);
#define GST_CAT_DEFAULT gst_d3d12_converter_debug
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
enum class PS_OUTPUT
{
PACKED,
LUMA,
CHROMA,
CHROMA_PLANAR,
PLANAR,
PLANAR_FULL,
};
static const std::string
ps_output_to_string (PS_OUTPUT output)
{
switch (output) {
case PS_OUTPUT::PACKED:
return "PS_OUTPUT_PACKED";
case PS_OUTPUT::LUMA:
return "PS_OUTPUT_LUMA";
case PS_OUTPUT::CHROMA:
return "PS_OUTPUT_CHROMA";
case PS_OUTPUT::CHROMA_PLANAR:
return "PS_OUTPUT_CHROMA_PLANAR";
case PS_OUTPUT::PLANAR:
return "PS_OUTPUT_PLANAR";
case PS_OUTPUT::PLANAR_FULL:
return "PS_OUTPUT_PLANAR_FULL";
default:
g_assert_not_reached ();
break;
}
return "";
}
static guint
ps_output_get_num_rtv (PS_OUTPUT output)
{
switch (output) {
case PS_OUTPUT::PACKED:
case PS_OUTPUT::LUMA:
case PS_OUTPUT::CHROMA:
return 1;
case PS_OUTPUT::CHROMA_PLANAR:
return 2;
case PS_OUTPUT::PLANAR:
return 3;
case PS_OUTPUT::PLANAR_FULL:
return 4;
default:
g_assert_not_reached ();
break;
}
return 0;
}
static std::string
make_input (GstVideoFormat format, gboolean premul)
{
switch (format) {
case GST_VIDEO_FORMAT_RGBA:
case GST_VIDEO_FORMAT_RGBA64_LE:
case GST_VIDEO_FORMAT_RGB10A2_LE:
case GST_VIDEO_FORMAT_BGRA:
if (premul)
return "RGBAPremul";
return "RGBA";
case GST_VIDEO_FORMAT_RGBx:
case GST_VIDEO_FORMAT_BGRx:
return "RGBx";
case GST_VIDEO_FORMAT_ARGB:
return "ARGB";
case GST_VIDEO_FORMAT_xRGB:
return "xRGB";
case GST_VIDEO_FORMAT_ABGR:
return "ABGR";
case GST_VIDEO_FORMAT_xBGR:
return "xBGR";
case GST_VIDEO_FORMAT_VUYA:
return "VUYA";
case GST_VIDEO_FORMAT_AYUV:
case GST_VIDEO_FORMAT_AYUV64:
return "AYUV";
case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_P010_10LE:
case GST_VIDEO_FORMAT_P012_LE:
case GST_VIDEO_FORMAT_P016_LE:
return "NV12";
case GST_VIDEO_FORMAT_NV21:
return "NV21";
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_Y42B:
case GST_VIDEO_FORMAT_Y444:
case GST_VIDEO_FORMAT_Y444_16LE:
return "I420";
case GST_VIDEO_FORMAT_YV12:
return "YV12";
case GST_VIDEO_FORMAT_I420_10LE:
case GST_VIDEO_FORMAT_I422_10LE:
case GST_VIDEO_FORMAT_Y444_10LE:
return "I420_10";
case GST_VIDEO_FORMAT_I420_12LE:
case GST_VIDEO_FORMAT_I422_12LE:
case GST_VIDEO_FORMAT_Y444_12LE:
return "I420_12";
case GST_VIDEO_FORMAT_Y410:
return "Y410";
case GST_VIDEO_FORMAT_GRAY8:
case GST_VIDEO_FORMAT_GRAY16_LE:
return "GRAY";
case GST_VIDEO_FORMAT_RGBP:
return "RGBP";
case GST_VIDEO_FORMAT_BGRP:
return "BGRP";
case GST_VIDEO_FORMAT_GBR:
case GST_VIDEO_FORMAT_GBR_16LE:
return "GBR";
case GST_VIDEO_FORMAT_GBR_10LE:
return "GBR_10";
case GST_VIDEO_FORMAT_GBR_12LE:
return "GBR_12";
case GST_VIDEO_FORMAT_GBRA:
return "GBRA";
case GST_VIDEO_FORMAT_GBRA_10LE:
return "GBRA_10";
case GST_VIDEO_FORMAT_GBRA_12LE:
return "GBRA_12";
case GST_VIDEO_FORMAT_Y412_LE:
return "Y412";
case GST_VIDEO_FORMAT_BGR10A2_LE:
return "BGR10A2";
case GST_VIDEO_FORMAT_BGRA64_LE:
return "BGRA64";
case GST_VIDEO_FORMAT_RBGA:
return "RBGA";
default:
g_assert_not_reached ();
break;
}
return "";
}
static std::vector<std::pair<PS_OUTPUT, std::string>>
make_output (GstVideoFormat format, gboolean premul)
{
std::vector<std::pair<PS_OUTPUT, std::string>> ret;
switch (format) {
case GST_VIDEO_FORMAT_RGBA:
case GST_VIDEO_FORMAT_RGBA64_LE:
case GST_VIDEO_FORMAT_RGB10A2_LE:
case GST_VIDEO_FORMAT_BGRA:
if (premul)
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "RGBAPremul"));
else
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "RGBA"));
break;
case GST_VIDEO_FORMAT_RGBx:
case GST_VIDEO_FORMAT_BGRx:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "RGBx"));
break;
case GST_VIDEO_FORMAT_ARGB:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "ARGB"));
break;
case GST_VIDEO_FORMAT_xRGB:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "xRGB"));
break;
case GST_VIDEO_FORMAT_ABGR:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "ABGR"));
break;
case GST_VIDEO_FORMAT_xBGR:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "xBGR"));
break;
case GST_VIDEO_FORMAT_VUYA:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "VUYA"));
break;
case GST_VIDEO_FORMAT_AYUV:
case GST_VIDEO_FORMAT_AYUV64:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "AYUV"));
break;
case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_P010_10LE:
case GST_VIDEO_FORMAT_P012_LE:
case GST_VIDEO_FORMAT_P016_LE:
ret.push_back(std::make_pair(PS_OUTPUT::LUMA, "Luma"));
ret.push_back(std::make_pair(PS_OUTPUT::CHROMA, "ChromaNV12"));
break;
case GST_VIDEO_FORMAT_NV21:
ret.push_back(std::make_pair(PS_OUTPUT::LUMA, "Luma"));
ret.push_back(std::make_pair(PS_OUTPUT::CHROMA, "ChromaNV21"));
break;
case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_Y42B:
ret.push_back(std::make_pair(PS_OUTPUT::LUMA, "Luma"));
ret.push_back(std::make_pair(PS_OUTPUT::CHROMA_PLANAR, "ChromaI420"));
break;
case GST_VIDEO_FORMAT_Y444:
case GST_VIDEO_FORMAT_Y444_16LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "Y444"));
break;
case GST_VIDEO_FORMAT_YV12:
ret.push_back(std::make_pair(PS_OUTPUT::LUMA, "Luma"));
ret.push_back(std::make_pair(PS_OUTPUT::CHROMA_PLANAR, "ChromaYV12"));
break;
case GST_VIDEO_FORMAT_I420_10LE:
case GST_VIDEO_FORMAT_I422_10LE:
ret.push_back(std::make_pair(PS_OUTPUT::LUMA, "Luma_10"));
ret.push_back(std::make_pair(PS_OUTPUT::CHROMA_PLANAR, "ChromaI420_10"));
break;
case GST_VIDEO_FORMAT_Y444_10LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "Y444_10"));
break;
case GST_VIDEO_FORMAT_I420_12LE:
case GST_VIDEO_FORMAT_I422_12LE:
ret.push_back(std::make_pair(PS_OUTPUT::LUMA, "Luma_12"));
ret.push_back(std::make_pair(PS_OUTPUT::CHROMA_PLANAR, "ChromaI420_12"));
break;
case GST_VIDEO_FORMAT_Y444_12LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "Y444_12"));
break;
case GST_VIDEO_FORMAT_GRAY8:
case GST_VIDEO_FORMAT_GRAY16_LE:
ret.push_back(std::make_pair(PS_OUTPUT::LUMA, "Luma"));
break;
case GST_VIDEO_FORMAT_RGBP:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "RGBP"));
break;
case GST_VIDEO_FORMAT_BGRP:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "BGRP"));
break;
case GST_VIDEO_FORMAT_GBR:
case GST_VIDEO_FORMAT_GBR_16LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "GBR"));
break;
case GST_VIDEO_FORMAT_GBR_10LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "GBR_10"));
break;
case GST_VIDEO_FORMAT_GBR_12LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR, "GBR_12"));
break;
case GST_VIDEO_FORMAT_GBRA:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR_FULL, "GBRA"));
break;
case GST_VIDEO_FORMAT_GBRA_10LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR_FULL, "GBRA_10"));
break;
case GST_VIDEO_FORMAT_GBRA_12LE:
ret.push_back(std::make_pair(PS_OUTPUT::PLANAR_FULL, "GBRA_12"));
break;
case GST_VIDEO_FORMAT_RBGA:
ret.push_back(std::make_pair(PS_OUTPUT::PACKED, "RBGA"));
break;
default:
g_assert_not_reached ();
break;
}
return ret;
}
/* *INDENT-ON* */
PixelShaderBlobList
gst_d3d12_get_converter_pixel_shader_blob (GstVideoFormat in_format,
GstVideoFormat out_format, gboolean in_premul, gboolean out_premul,
CONVERT_TYPE type)
{
auto input = make_input (in_format, in_premul);
auto output = make_output (out_format, out_premul);
std::string conv_type;
GstD3DConverterType conv_type;
PixelShaderBlobList ret;
static std::mutex cache_lock;
static std::map<std::string, std::shared_ptr<PixelShaderBlob>> ps_cache;
switch (type) {
case CONVERT_TYPE::IDENTITY:
conv_type = "Identity";
conv_type = GST_D3D_CONVERTER_IDENTITY;
break;
case CONVERT_TYPE::SIMPLE:
conv_type = "Simple";
conv_type = GST_D3D_CONVERTER_SIMPLE;
break;
case CONVERT_TYPE::RANGE:
conv_type = "Range";
conv_type = GST_D3D_CONVERTER_RANGE;
break;
case CONVERT_TYPE::GAMMA:
conv_type = "Gamma";
conv_type = GST_D3D_CONVERTER_GAMMA;
break;
case CONVERT_TYPE::PRIMARY:
conv_type = "Primary";
conv_type = GST_D3D_CONVERTER_PRIMARY;
break;
default:
g_assert_not_reached ();
return ret;
}
for (const auto & it : output) {
std::string entry_point = "PSMain_" + input + "_" + conv_type + "_" +
it.second;
std::shared_ptr<PixelShaderBlob> source;
std::lock_guard<std::mutex> lk (cache_lock);
auto cached = ps_cache.find(entry_point);
if (cached != ps_cache.end()) {
source = cached->second;
} else {
auto precompiled = precompiled_bytecode.find (entry_point);
if (precompiled == precompiled_bytecode.end ()) {
GST_ERROR ("Couldn't find precompiled %s", entry_point.c_str ());
ret.clear ();
return ret;
}
source = std::make_shared<PixelShaderBlob> ();
source->bytecode.pShaderBytecode = precompiled->second.first;
source->bytecode.BytecodeLength = precompiled->second.second;
source->num_rtv = ps_output_get_num_rtv (it.first);
ps_cache[entry_point] = source;
}
GstD3DConverterPSByteCode blobs[4];
auto num_blobs = gst_d3d_converter_shader_get_ps_blob (in_format, out_format,
in_premul, out_premul, conv_type, GST_D3D_SM_5_0, blobs);
ret.push_back (*source);
if (!num_blobs) {
GST_ERROR ("Couldn't get compiled bytecode");
return ret;
}
for (guint i = 0; i < num_blobs; i++) {
auto blob = &blobs[i];
PixelShaderBlob ps;
ps.bytecode.pShaderBytecode = blob->byte_code.byte_code;
ps.bytecode.BytecodeLength = blob->byte_code.byte_code_len;
ps.num_rtv = blob->num_rtv;
ret.push_back (ps);
}
return ret;
}
/* *INDENT-ON* */
HRESULT
gst_d3d12_get_converter_vertex_shader_blob (D3D12_SHADER_BYTECODE * vs,
D3D12_INPUT_ELEMENT_DESC input_desc[2])
{
GstD3DShaderByteCode bytecode = { };
if (!gst_d3d_converter_shader_get_vs_blob (GST_D3D_SM_5_0, &bytecode)) {
GST_ERROR ("Couldn't get compiled bytecode");
return E_FAIL;
}
input_desc[0].SemanticName = "POSITION";
input_desc[0].SemanticIndex = 0;
input_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
@ -378,8 +113,8 @@ gst_d3d12_get_converter_vertex_shader_blob (D3D12_SHADER_BYTECODE * vs,
input_desc[1].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
input_desc[1].InstanceDataStepRate = 0;
vs->BytecodeLength = sizeof (g_VSMain_converter);
vs->pShaderBytecode = g_VSMain_converter;
vs->BytecodeLength = bytecode.byte_code_len;
vs->pShaderBytecode = bytecode.byte_code;
return S_OK;
}

View file

@ -55,8 +55,7 @@
#include <memory>
#include <future>
#include <wrl.h>
#include "PSMain_sample.h"
#include "VSMain_coord.h"
#include <gst/d3dshader/gstd3dshader.h>
#define _XM_NO_INTRINSICS_
#include <DirectXMath.h>
@ -953,12 +952,26 @@ gst_d3d12_dxgi_capture_open (GstD3D12DxgiCapture * self,
input_desc[1].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
input_desc[1].InstanceDataStepRate = 0;
GstD3DShaderByteCode vs_code;
GstD3DShaderByteCode ps_code;
if (!gst_d3d_plugin_shader_get_vs_blob (GST_D3D_PLUGIN_VS_COORD,
GST_D3D_SM_5_0, &vs_code)) {
GST_ERROR_OBJECT (self, "Couldn't get vs bytecode");
return FALSE;
}
if (!gst_d3d_plugin_shader_get_ps_blob (GST_D3D_PLUGIN_PS_SAMPLE,
GST_D3D_SM_5_0, &ps_code)) {
GST_ERROR_OBJECT (self, "Couldn't get ps bytecode");
return FALSE;
}
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { };
pso_desc.pRootSignature = priv->rs.Get ();
pso_desc.VS.BytecodeLength = sizeof (g_VSMain_coord);
pso_desc.VS.pShaderBytecode = g_VSMain_coord;
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_sample);
pso_desc.PS.pShaderBytecode = g_PSMain_sample;
pso_desc.VS.BytecodeLength = vs_code.byte_code_len;
pso_desc.VS.pShaderBytecode = vs_code.byte_code;
pso_desc.PS.BytecodeLength = ps_code.byte_code_len;
pso_desc.PS.pShaderBytecode = ps_code.byte_code;
pso_desc.BlendState = CD3DX12_BLEND_DESC (D3D12_DEFAULT);
pso_desc.SampleMask = UINT_MAX;
pso_desc.RasterizerState = CD3DX12_RASTERIZER_DESC (D3D12_DEFAULT);

View file

@ -27,9 +27,7 @@
#include <memory>
#include <vector>
#include <algorithm>
#include "PSMain_sample.h"
#include "PSMain_sample_premul.h"
#include "VSMain_coord.h"
#include <gst/d3dshader/gstd3dshader.h>
GST_DEBUG_CATEGORY_STATIC (gst_d3d12_overlay_compositor_debug);
#define GST_CAT_DEFAULT gst_d3d12_overlay_compositor_debug
@ -430,6 +428,27 @@ gst_d3d12_overlay_compositor_setup_shader (GstD3D12OverlayCompositor * self)
gst_d3d12_device_get_format (self->device, GST_VIDEO_INFO_FORMAT (info),
&device_format);
GstD3DShaderByteCode vs_code;
GstD3DShaderByteCode ps_sample_code;
GstD3DShaderByteCode ps_sample_premul_code;
if (!gst_d3d_plugin_shader_get_vs_blob (GST_D3D_PLUGIN_VS_COORD,
GST_D3D_SM_5_0, &vs_code)) {
GST_ERROR_OBJECT (self, "Couldn't get vs bytecode");
return FALSE;
}
if (!gst_d3d_plugin_shader_get_ps_blob (GST_D3D_PLUGIN_PS_SAMPLE,
GST_D3D_SM_5_0, &ps_sample_code)) {
GST_ERROR_OBJECT (self, "Couldn't get ps bytecode");
return FALSE;
}
if (!gst_d3d_plugin_shader_get_ps_blob (GST_D3D_PLUGIN_PS_SAMPLE_PREMULT,
GST_D3D_SM_5_0, &ps_sample_premul_code)) {
GST_ERROR_OBJECT (self, "Couldn't get ps bytecode");
return FALSE;
}
auto device = gst_d3d12_device_get_device_handle (self->device);
ComPtr < ID3D12RootSignature > rs;
device->CreateRootSignature (0, rs_blob->GetBufferPointer (),
@ -455,10 +474,10 @@ gst_d3d12_overlay_compositor_setup_shader (GstD3D12OverlayCompositor * self)
auto & pso_desc = priv->pso_desc;
pso_desc.pRootSignature = rs.Get ();
pso_desc.VS.BytecodeLength = sizeof (g_VSMain_coord);
pso_desc.VS.pShaderBytecode = g_VSMain_coord;
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_sample);
pso_desc.PS.pShaderBytecode = g_PSMain_sample;
pso_desc.VS.BytecodeLength = vs_code.byte_code_len;
pso_desc.VS.pShaderBytecode = vs_code.byte_code;
pso_desc.PS.BytecodeLength = ps_sample_code.byte_code_len;
pso_desc.PS.pShaderBytecode = ps_sample_code.byte_code;
pso_desc.BlendState = CD3DX12_BLEND_DESC (D3D12_DEFAULT);
pso_desc.BlendState.RenderTarget[0].BlendEnable = TRUE;
pso_desc.BlendState.RenderTarget[0].LogicOpEnable = FALSE;
@ -494,8 +513,8 @@ gst_d3d12_overlay_compositor_setup_shader (GstD3D12OverlayCompositor * self)
ComPtr < ID3D12PipelineState > pso_premul;
auto & pso_premul_desc = priv->pso_premul_desc;
pso_premul_desc = priv->pso_desc;
pso_premul_desc.PS.BytecodeLength = sizeof (g_PSMain_sample_premul);
pso_premul_desc.PS.pShaderBytecode = g_PSMain_sample_premul;
pso_premul_desc.PS.BytecodeLength = ps_sample_premul_code.byte_code_len;
pso_premul_desc.PS.pShaderBytecode = ps_sample_premul_code.byte_code;
hr = device->CreateGraphicsPipelineState (&pso_premul_desc,
IID_PPV_ARGS (&pso_premul));
if (!gst_d3d12_result (hr, self->device)) {

View file

@ -46,11 +46,7 @@
#include <memory>
#include <vector>
#include <queue>
#include "PSMain_checker.h"
#include "PSMain_color.h"
#include "PSMain_snow.h"
#include "VSMain_color.h"
#include "VSMain_coord.h"
#include <gst/d3dshader/gstd3dshader.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
@ -417,6 +413,20 @@ setup_snow_render (GstD3D12TestSrc * self, RenderContext * ctx,
return FALSE;
}
GstD3DShaderByteCode vs_code;
GstD3DShaderByteCode ps_code;
if (!gst_d3d_plugin_shader_get_vs_blob (GST_D3D_PLUGIN_VS_COORD,
GST_D3D_SM_5_0, &vs_code)) {
GST_ERROR_OBJECT (self, "Couldn't get vs bytecode");
return FALSE;
}
if (!gst_d3d_plugin_shader_get_ps_blob (GST_D3D_PLUGIN_PS_SNOW,
GST_D3D_SM_5_0, &ps_code)) {
GST_ERROR_OBJECT (self, "Couldn't get ps bytecode");
return FALSE;
}
D3D12_INPUT_ELEMENT_DESC input_desc[2];
input_desc[0].SemanticName = "POSITION";
input_desc[0].SemanticIndex = 0;
@ -436,10 +446,10 @@ setup_snow_render (GstD3D12TestSrc * self, RenderContext * ctx,
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { };
pso_desc.pRootSignature = rs.Get ();
pso_desc.VS.BytecodeLength = sizeof (g_VSMain_coord);
pso_desc.VS.pShaderBytecode = g_VSMain_coord;
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_snow);
pso_desc.PS.pShaderBytecode = g_PSMain_snow;
pso_desc.VS.BytecodeLength = vs_code.byte_code_len;
pso_desc.VS.pShaderBytecode = vs_code.byte_code;
pso_desc.PS.BytecodeLength = ps_code.byte_code_len;
pso_desc.PS.pShaderBytecode = ps_code.byte_code;
pso_desc.BlendState = CD3DX12_BLEND_DESC (D3D12_DEFAULT);
pso_desc.SampleMask = UINT_MAX;
pso_desc.RasterizerState = CD3DX12_RASTERIZER_DESC (D3D12_DEFAULT);
@ -627,6 +637,20 @@ setup_smpte_render (GstD3D12TestSrc * self, RenderContext * ctx)
return FALSE;
}
GstD3DShaderByteCode vs_code;
GstD3DShaderByteCode ps_code;
if (!gst_d3d_plugin_shader_get_vs_blob (GST_D3D_PLUGIN_VS_COLOR,
GST_D3D_SM_5_0, &vs_code)) {
GST_ERROR_OBJECT (self, "Couldn't get vs bytecode");
return FALSE;
}
if (!gst_d3d_plugin_shader_get_ps_blob (GST_D3D_PLUGIN_PS_COLOR,
GST_D3D_SM_5_0, &ps_code)) {
GST_ERROR_OBJECT (self, "Couldn't get ps bytecode");
return FALSE;
}
D3D12_INPUT_ELEMENT_DESC input_desc[2];
input_desc[0].SemanticName = "POSITION";
input_desc[0].SemanticIndex = 0;
@ -646,10 +670,10 @@ setup_smpte_render (GstD3D12TestSrc * self, RenderContext * ctx)
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { };
pso_desc.pRootSignature = rs.Get ();
pso_desc.VS.BytecodeLength = sizeof (g_VSMain_color);
pso_desc.VS.pShaderBytecode = g_VSMain_color;
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_color);
pso_desc.PS.pShaderBytecode = g_PSMain_color;
pso_desc.VS.BytecodeLength = vs_code.byte_code_len;
pso_desc.VS.pShaderBytecode = vs_code.byte_code;
pso_desc.PS.BytecodeLength = ps_code.byte_code_len;
pso_desc.PS.pShaderBytecode = ps_code.byte_code;
pso_desc.BlendState = CD3DX12_BLEND_DESC (D3D12_DEFAULT);
pso_desc.SampleMask = UINT_MAX;
pso_desc.RasterizerState = CD3DX12_RASTERIZER_DESC (D3D12_DEFAULT);
@ -1004,6 +1028,20 @@ setup_checker_render (GstD3D12TestSrc * self, RenderContext * ctx,
return FALSE;
}
GstD3DShaderByteCode vs_code;
GstD3DShaderByteCode ps_code;
if (!gst_d3d_plugin_shader_get_vs_blob (GST_D3D_PLUGIN_VS_COORD,
GST_D3D_SM_5_0, &vs_code)) {
GST_ERROR_OBJECT (self, "Couldn't get vs bytecode");
return FALSE;
}
if (!gst_d3d_plugin_shader_get_ps_blob (GST_D3D_PLUGIN_PS_CHECKER,
GST_D3D_SM_5_0, &ps_code)) {
GST_ERROR_OBJECT (self, "Couldn't get ps bytecode");
return FALSE;
}
D3D12_INPUT_ELEMENT_DESC input_desc[2];
input_desc[0].SemanticName = "POSITION";
input_desc[0].SemanticIndex = 0;
@ -1023,10 +1061,10 @@ setup_checker_render (GstD3D12TestSrc * self, RenderContext * ctx,
D3D12_GRAPHICS_PIPELINE_STATE_DESC pso_desc = { };
pso_desc.pRootSignature = rs.Get ();
pso_desc.VS.BytecodeLength = sizeof (g_VSMain_coord);
pso_desc.VS.pShaderBytecode = g_VSMain_coord;
pso_desc.PS.BytecodeLength = sizeof (g_PSMain_checker);
pso_desc.PS.pShaderBytecode = g_PSMain_checker;
pso_desc.VS.BytecodeLength = vs_code.byte_code_len;
pso_desc.VS.pShaderBytecode = vs_code.byte_code;
pso_desc.PS.BytecodeLength = ps_code.byte_code_len;
pso_desc.PS.pShaderBytecode = ps_code.byte_code;
pso_desc.BlendState = CD3DX12_BLEND_DESC (D3D12_DEFAULT);
pso_desc.SampleMask = UINT_MAX;
pso_desc.RasterizerState = CD3DX12_RASTERIZER_DESC (D3D12_DEFAULT);

View file

@ -1,44 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
cbuffer CheckerConstBuffer : register(b0)
{
float width;
float height;
float checker_size;
float alpha;
};
struct PS_INPUT
{
float4 Position: SV_POSITION;
float2 Texture: TEXCOORD;
};
float4 PSMain_checker (PS_INPUT input) : SV_Target
{
float4 output;
float2 xy_mod = floor (0.5 * input.Texture * float2 (width, height) / checker_size);
float result = fmod (xy_mod.x + xy_mod.y, 2.0);
output.r = step (result, 0.5);
output.g = 1.0 - output.r;
output.b = 0;
output.a = alpha;
return output;
}

View file

@ -1,49 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
static const float blocksize = 8.0;
static const float4 high = float4 (0.667, 0.0, 0.0, 1.0);
static const float4 low = float4 (0.333, 0.0, 0.0, 1.0);
struct PS_INPUT
{
float4 Position : SV_POSITION;
};
struct PS_OUTPUT
{
float4 Plane : SV_TARGET;
};
PS_OUTPUT PSMain_checker_luma (PS_INPUT input)
{
PS_OUTPUT output;
if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {
if ((input.Position.y % (blocksize * 2.0)) >= blocksize)
output.Plane = low;
else
output.Plane = high;
} else {
if ((input.Position.y % (blocksize * 2.0)) < blocksize)
output.Plane = low;
else
output.Plane = high;
}
return output;
}

View file

@ -1,49 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
static const float blocksize = 8.0;
static const float4 high = float4 (0.667, 0.667, 0.667, 1.0);
static const float4 low = float4 (0.333, 0.333, 0.333, 1.0);
struct PS_INPUT
{
float4 Position : SV_POSITION;
};
struct PS_OUTPUT
{
float4 Plane : SV_TARGET;
};
PS_OUTPUT PSMain_checker_rgb (PS_INPUT input)
{
PS_OUTPUT output;
if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {
if ((input.Position.y % (blocksize * 2.0)) >= blocksize)
output.Plane = low;
else
output.Plane = high;
} else {
if ((input.Position.y % (blocksize * 2.0)) < blocksize)
output.Plane = low;
else
output.Plane = high;
}
return output;
}

View file

@ -1,49 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
static const float blocksize = 8.0;
static const float4 high = float4 (0.5, 0.5, 0.667, 1.0);
static const float4 low = float4 (0.5, 0.5, 0.333, 1.0);
struct PS_INPUT
{
float4 Position : SV_POSITION;
};
struct PS_OUTPUT
{
float4 Plane : SV_TARGET;
};
PS_OUTPUT PSMain_checker_vuya (PS_INPUT input)
{
PS_OUTPUT output;
if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {
if ((input.Position.y % (blocksize * 2.0)) >= blocksize)
output.Plane = low;
else
output.Plane = high;
} else {
if ((input.Position.y % (blocksize * 2.0)) < blocksize)
output.Plane = low;
else
output.Plane = high;
}
return output;
}

View file

@ -1,29 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
struct PS_INPUT
{
float4 Position: SV_POSITION;
float4 Color: COLOR;
};
float4 PSMain_color (PS_INPUT input) : SV_TARGET
{
return input.Color;
}

View file

@ -1,939 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
cbuffer PsAlphaFactor : register(b1)
{
float alphaFactor;
};
struct PSColorSpace
{
float3 CoeffX;
float3 CoeffY;
float3 CoeffZ;
float3 Offset;
float3 Min;
float3 Max;
float padding;
};
cbuffer PsConstBuffer : register(b2)
{
PSColorSpace preCoeff;
PSColorSpace postCoeff;
PSColorSpace primariesCoeff;
};
Texture2D shaderTexture_0 : register(t0);
Texture2D shaderTexture_1 : register(t1);
Texture2D shaderTexture_2 : register(t2);
Texture2D shaderTexture_3 : register(t3);
Texture1D<float> gammaDecLUT : register(t4);
Texture1D<float> gammaEncLUT : register(t5);
SamplerState samplerState : register(s0);
SamplerState lutSamplerState : register(s1);
struct PS_INPUT
{
float4 Position: SV_POSITION;
float2 Texture: TEXCOORD;
};
struct PS_OUTPUT_PACKED
{
float4 Plane0: SV_TARGET0;
};
struct PS_OUTPUT_LUMA
{
float4 Plane0: SV_TARGET0;
};
struct PS_OUTPUT_CHROMA
{
float4 Plane0: SV_TARGET0;
};
struct PS_OUTPUT_CHROMA_PLANAR
{
float4 Plane0: SV_TARGET0;
float4 Plane1: SV_TARGET1;
};
struct PS_OUTPUT_PLANAR
{
float4 Plane0: SV_TARGET0;
float4 Plane1: SV_TARGET1;
float4 Plane2: SV_TARGET2;
};
struct PS_OUTPUT_PLANAR_FULL
{
float4 Plane0: SV_TARGET0;
float4 Plane1: SV_TARGET1;
float4 Plane2: SV_TARGET2;
float4 Plane3: SV_TARGET3;
};
float4 DoAlphaPremul (float4 sample)
{
float4 premul_tex;
premul_tex.rgb = sample.rgb * sample.a;
premul_tex.a = sample.a;
return premul_tex;
}
float4 DoAlphaUnpremul (float4 sample)
{
float4 unpremul_tex;
if (sample.a == 0 || sample.a == 1)
return sample;
unpremul_tex.rgb = saturate (sample.rgb / sample.a);
unpremul_tex.a = sample.a;
return unpremul_tex;
}
interface ISampler
{
float4 Execute (float2 uv);
};
class SamplerRGBA : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv);
}
};
class SamplerRGBAPremul : ISampler
{
float4 Execute (float2 uv)
{
return DoAlphaUnpremul (shaderTexture_0.Sample(samplerState, uv));
}
};
class SamplerRBGA : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv).rbga;
}
};
class SamplerVUYA : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv).zyxw;
}
};
class SamplerY410 : ISampler
{
float4 Execute (float2 uv)
{
return float4 (shaderTexture_0.Sample(samplerState, uv).yxz, 1.0);
}
};
class SamplerY412 : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv).grba;
}
};
class SamplerAYUV : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv).yzwx;
}
};
class SamplerRGBx : ISampler
{
float4 Execute (float2 uv)
{
return float4 (shaderTexture_0.Sample(samplerState, uv).rgb, 1.0);
}
};
class SamplerxRGB : ISampler
{
float4 Execute (float2 uv)
{
return float4 (shaderTexture_0.Sample(samplerState, uv).gba, 1.0);
}
};
class SamplerARGB : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv).gbar;
}
};
class SamplerxBGR : ISampler
{
float4 Execute (float2 uv)
{
return float4 (shaderTexture_0.Sample(samplerState, uv).abg, 1.0);
}
};
class SamplerABGR : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv).abgr;
}
};
class SamplerBGR10A2 : ISampler
{
float4 Execute (float2 uv)
{
return float4 (shaderTexture_0.Sample(samplerState, uv).zyx, 1.0);
}
};
class SamplerBGRA64 : ISampler
{
float4 Execute (float2 uv)
{
return shaderTexture_0.Sample(samplerState, uv).bgra;
}
};
class SamplerGRAY : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.x = shaderTexture_0.Sample(samplerState, uv).x;
sample.y = 0.5;
sample.z = 0.5;
sample.a = 1.0;
return sample;
}
};
class SamplerNV12 : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.x = shaderTexture_0.Sample(samplerState, uv).x;
sample.yz = shaderTexture_1.Sample(samplerState, uv).xy;
sample.a = 1.0;
return sample;
}
};
class SamplerNV21 : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.x = shaderTexture_0.Sample(samplerState, uv).x;
sample.yz = shaderTexture_1.Sample(samplerState, uv).yx;
sample.a = 1.0;
return sample;
}
};
class SamplerI420 : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.x = shaderTexture_0.Sample(samplerState, uv).x;
sample.y = shaderTexture_1.Sample(samplerState, uv).x;
sample.z = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = 1.0;
return sample;
}
};
class SamplerYV12 : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.x = shaderTexture_0.Sample(samplerState, uv).x;
sample.z = shaderTexture_1.Sample(samplerState, uv).x;
sample.y = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = 1.0;
return sample;
}
};
class SamplerI420_10 : ISampler
{
float4 Execute (float2 uv)
{
float3 sample;
sample.x = shaderTexture_0.Sample(samplerState, uv).x;
sample.y = shaderTexture_1.Sample(samplerState, uv).x;
sample.z = shaderTexture_2.Sample(samplerState, uv).x;
return float4 (saturate (sample * 64.0), 1.0);
}
};
class SamplerI420_12 : ISampler
{
float4 Execute (float2 uv)
{
float3 sample;
sample.x = shaderTexture_0.Sample(samplerState, uv).x;
sample.y = shaderTexture_1.Sample(samplerState, uv).x;
sample.z = shaderTexture_2.Sample(samplerState, uv).x;
return float4 (saturate (sample * 16.0), 1.0);
}
};
class SamplerGBR : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.g = shaderTexture_0.Sample(samplerState, uv).x;
sample.b = shaderTexture_1.Sample(samplerState, uv).x;
sample.r = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = 1.0;
return sample;
}
};
class SamplerGBR_10 : ISampler
{
float4 Execute (float2 uv)
{
float3 sample;
sample.g = shaderTexture_0.Sample(samplerState, uv).x;
sample.b = shaderTexture_1.Sample(samplerState, uv).x;
sample.r = shaderTexture_2.Sample(samplerState, uv).x;
return float4 (saturate (sample * 64.0), 1.0);
}
};
class SamplerGBR_12 : ISampler
{
float4 Execute (float2 uv)
{
float3 sample;
sample.g = shaderTexture_0.Sample(samplerState, uv).x;
sample.b = shaderTexture_1.Sample(samplerState, uv).x;
sample.r = shaderTexture_2.Sample(samplerState, uv).x;
return float4 (saturate (sample * 16.0), 1.0);
}
};
class SamplerRGBP : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.r = shaderTexture_0.Sample(samplerState, uv).x;
sample.g = shaderTexture_1.Sample(samplerState, uv).x;
sample.b = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = 1.0;
return sample;
}
};
class SamplerBGRP : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.b = shaderTexture_0.Sample(samplerState, uv).x;
sample.g = shaderTexture_1.Sample(samplerState, uv).x;
sample.r = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = 1.0;
return sample;
}
};
class SamplerGBRA : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.g = shaderTexture_0.Sample(samplerState, uv).x;
sample.b = shaderTexture_1.Sample(samplerState, uv).x;
sample.r = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = shaderTexture_3.Sample(samplerState, uv).x;
return sample;
}
};
class SamplerGBRA_10 : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.g = shaderTexture_0.Sample(samplerState, uv).x;
sample.b = shaderTexture_1.Sample(samplerState, uv).x;
sample.r = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = shaderTexture_3.Sample(samplerState, uv).x;
return saturate (sample * 64.0);
}
};
class SamplerGBRA_12 : ISampler
{
float4 Execute (float2 uv)
{
float4 sample;
sample.g = shaderTexture_0.Sample(samplerState, uv).x;
sample.b = shaderTexture_1.Sample(samplerState, uv).x;
sample.r = shaderTexture_2.Sample(samplerState, uv).x;
sample.a = shaderTexture_3.Sample(samplerState, uv).x;
return saturate (sample * 16.0);
}
};
interface IConverter
{
float4 Execute (float4 sample);
};
class ConverterIdentity : IConverter
{
float4 Execute (float4 sample)
{
return sample;
}
};
class ConverterRange : IConverter
{
float4 Execute (float4 sample)
{
float3 out_space;
out_space.x = postCoeff.CoeffX.x * sample.x;
out_space.y = postCoeff.CoeffY.y * sample.y;
out_space.z = postCoeff.CoeffZ.z * sample.z;
out_space += postCoeff.Offset;
return float4 (clamp (out_space, postCoeff.Min, postCoeff.Max), sample.a);
}
};
class ConverterSimple : IConverter
{
float4 Execute (float4 sample)
{
float3 out_space;
out_space.x = dot (postCoeff.CoeffX, sample.xyz);
out_space.y = dot (postCoeff.CoeffY, sample.xyz);
out_space.z = dot (postCoeff.CoeffZ, sample.xyz);
out_space += postCoeff.Offset;
return float4 (clamp (out_space, postCoeff.Min, postCoeff.Max), sample.a);
}
};
class ConverterGamma : IConverter
{
float4 Execute (float4 sample)
{
float3 out_space;
out_space.x = dot (preCoeff.CoeffX, sample.xyz);
out_space.y = dot (preCoeff.CoeffY, sample.xyz);
out_space.z = dot (preCoeff.CoeffZ, sample.xyz);
out_space += preCoeff.Offset;
out_space = clamp (out_space, preCoeff.Min, preCoeff.Max);
out_space.x = gammaDecLUT.Sample (lutSamplerState, out_space.x);
out_space.y = gammaDecLUT.Sample (lutSamplerState, out_space.y);
out_space.z = gammaDecLUT.Sample (lutSamplerState, out_space.z);
out_space.x = gammaEncLUT.Sample (lutSamplerState, out_space.x);
out_space.y = gammaEncLUT.Sample (lutSamplerState, out_space.y);
out_space.z = gammaEncLUT.Sample (lutSamplerState, out_space.z);
out_space.x = dot (postCoeff.CoeffX, out_space);
out_space.y = dot (postCoeff.CoeffY, out_space);
out_space.z = dot (postCoeff.CoeffZ, out_space);
out_space += postCoeff.Offset;
return float4 (clamp (out_space, postCoeff.Min, postCoeff.Max), sample.a);
}
};
class ConverterPrimary : IConverter
{
float4 Execute (float4 sample)
{
float3 out_space;
float3 tmp;
out_space.x = dot (preCoeff.CoeffX, sample.xyz);
out_space.y = dot (preCoeff.CoeffY, sample.xyz);
out_space.z = dot (preCoeff.CoeffZ, sample.xyz);
out_space += preCoeff.Offset;
out_space = clamp (out_space, preCoeff.Min, preCoeff.Max);
out_space.x = gammaDecLUT.Sample (lutSamplerState, out_space.x);
out_space.y = gammaDecLUT.Sample (lutSamplerState, out_space.y);
out_space.z = gammaDecLUT.Sample (lutSamplerState, out_space.z);
tmp.x = dot (primariesCoeff.CoeffX, out_space);
tmp.y = dot (primariesCoeff.CoeffY, out_space);
tmp.z = dot (primariesCoeff.CoeffZ, out_space);
out_space.x = gammaEncLUT.Sample (lutSamplerState, tmp.x);
out_space.y = gammaEncLUT.Sample (lutSamplerState, tmp.y);
out_space.z = gammaEncLUT.Sample (lutSamplerState, tmp.z);
out_space.x = dot (postCoeff.CoeffX, out_space);
out_space.y = dot (postCoeff.CoeffY, out_space);
out_space.z = dot (postCoeff.CoeffZ, out_space);
out_space += postCoeff.Offset;
return float4 (clamp (out_space, postCoeff.Min, postCoeff.Max), sample.a);
}
};
float UnormTo10bit (float sample)
{
return sample * 1023.0 / 65535.0;
}
float2 UnormTo10bit (float2 sample)
{
return sample * 1023.0 / 65535.0;
}
float3 UnormTo10bit (float3 sample)
{
return sample * 1023.0 / 65535.0;
}
float4 UnormTo10bit (float4 sample)
{
return sample * 1023.0 / 65535.0;
}
float UnormTo12bit (float sample)
{
return sample * 4095.0 / 65535.0;
}
float2 UnormTo12bit (float2 sample)
{
return sample * 4095.0 / 65535.0;
}
float3 UnormTo12bit (float3 sample)
{
return sample * 4095.0 / 65535.0;
}
float4 UnormTo12bit (float4 sample)
{
return sample * 4095.0 / 65535.0;
}
interface IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample);
};
class OutputRGBA : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
output.Plane0 = float4 (sample.rgb, sample.a * alphaFactor);
return output;
}
};
class OutputRGBAPremul : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
sample.a *= alphaFactor;
output.Plane0 = DoAlphaPremul (sample);
return output;
}
};
class OutputRGBx : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
output.Plane0 = float4 (sample.rgb, 1.0);
return output;
}
};
class OutputxRGB : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
output.Plane0 = float4 (0.0, sample.rgb);
return output;
}
};
class OutputARGB : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
output.Plane0 = sample.argb;
return output;
}
};
class OutputxBGR : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
output.Plane0 = float4 (0.0, sample.bgr);
return output;
}
};
class OutputABGR : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
output.Plane0 = sample.abgr;
return output;
}
};
class OutputVUYA : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
sample.a *= alphaFactor;
output.Plane0 = sample.zyxw;
return output;
}
};
class OutputAYUV : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
sample.a *= alphaFactor;
output.Plane0 = sample.wxyz;
return output;
}
};
class OutputRBGA : IOutputPacked
{
PS_OUTPUT_PACKED Build (float4 sample)
{
PS_OUTPUT_PACKED output;
sample.a *= alphaFactor;
output.Plane0 = sample.rbga;
return output;
}
};
interface IOutputLuma
{
PS_OUTPUT_LUMA Build (float4 sample);
};
class OutputLuma : IOutputLuma
{
PS_OUTPUT_LUMA Build (float4 sample)
{
PS_OUTPUT_LUMA output;
output.Plane0 = float4 (sample.x, 0, 0, 0);
return output;
}
};
class OutputLuma_10 : IOutputLuma
{
PS_OUTPUT_LUMA Build (float4 sample)
{
PS_OUTPUT_LUMA output;
output.Plane0 = float4 (UnormTo10bit (sample.x), 0, 0, 0);
return output;
}
};
class OutputLuma_12 : IOutputLuma
{
PS_OUTPUT_LUMA Build (float4 sample)
{
PS_OUTPUT_LUMA output;
output.Plane0 = float4 (UnormTo12bit (sample.x), 0, 0, 0);
return output;
}
};
interface IOutputChroma
{
PS_OUTPUT_CHROMA Build (float4 sample);
};
class OutputChromaNV12 : IOutputChroma
{
PS_OUTPUT_CHROMA Build (float4 sample)
{
PS_OUTPUT_CHROMA output;
output.Plane0 = float4 (sample.yz, 0, 0);
return output;
}
};
class OutputChromaNV21 : IOutputChroma
{
PS_OUTPUT_CHROMA Build (float4 sample)
{
PS_OUTPUT_CHROMA output;
output.Plane0 = float4 (sample.zy, 0, 0);
return output;
}
};
interface IOutputChromaPlanar
{
PS_OUTPUT_CHROMA_PLANAR Build (float4 sample);
};
class OutputChromaI420 : IOutputChromaPlanar
{
PS_OUTPUT_CHROMA_PLANAR Build (float4 sample)
{
PS_OUTPUT_CHROMA_PLANAR output;
output.Plane0 = float4 (sample.y, 0, 0, 0);
output.Plane1 = float4 (sample.z, 0, 0, 0);
return output;
}
};
class OutputChromaYV12 : IOutputChromaPlanar
{
PS_OUTPUT_CHROMA_PLANAR Build (float4 sample)
{
PS_OUTPUT_CHROMA_PLANAR output;
output.Plane0 = float4 (sample.z, 0, 0, 0);
output.Plane1 = float4 (sample.y, 0, 0, 0);
return output;
}
};
class OutputChromaI420_10 : IOutputChromaPlanar
{
PS_OUTPUT_CHROMA_PLANAR Build (float4 sample)
{
PS_OUTPUT_CHROMA_PLANAR output;
float2 scaled = UnormTo10bit (sample.yz);
output.Plane0 = float4 (scaled.x, 0, 0, 0);
output.Plane1 = float4 (scaled.y, 0, 0, 0);
return output;
}
};
class OutputChromaI420_12 : IOutputChromaPlanar
{
PS_OUTPUT_CHROMA_PLANAR Build (float4 sample)
{
PS_OUTPUT_CHROMA_PLANAR output;
float2 scaled = UnormTo12bit (sample.yz);
output.Plane0 = float4 (scaled.x, 0, 0, 0);
output.Plane1 = float4 (scaled.y, 0, 0, 0);
return output;
}
};
interface IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample);
};
class OutputY444 : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
output.Plane0 = float4 (sample.x, 0, 0, 0);
output.Plane1 = float4 (sample.y, 0, 0, 0);
output.Plane2 = float4 (sample.z, 0, 0, 0);
return output;
}
};
class OutputY444_10 : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
float3 scaled = UnormTo10bit (sample.xyz);
output.Plane0 = float4 (scaled.x, 0, 0, 0);
output.Plane1 = float4 (scaled.y, 0, 0, 0);
output.Plane2 = float4 (scaled.z, 0, 0, 0);
return output;
}
};
class OutputY444_12 : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
float3 scaled = UnormTo12bit (sample.xyz);
output.Plane0 = float4 (scaled.x, 0, 0, 0);
output.Plane1 = float4 (scaled.y, 0, 0, 0);
output.Plane2 = float4 (scaled.z, 0, 0, 0);
return output;
}
};
class OutputGBR : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
output.Plane0 = float4 (sample.g, 0, 0, 0);
output.Plane1 = float4 (sample.b, 0, 0, 0);
output.Plane2 = float4 (sample.r, 0, 0, 0);
return output;
}
};
class OutputGBR_10 : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
float3 scaled = UnormTo10bit (sample.rgb);
output.Plane0 = float4 (scaled.g, 0, 0, 0);
output.Plane1 = float4 (scaled.b, 0, 0, 0);
output.Plane2 = float4 (scaled.r, 0, 0, 0);
return output;
}
};
class OutputGBR_12 : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
float3 scaled = UnormTo12bit (sample.rgb);
output.Plane0 = float4 (scaled.g, 0, 0, 0);
output.Plane1 = float4 (scaled.b, 0, 0, 0);
output.Plane2 = float4 (scaled.r, 0, 0, 0);
return output;
}
};
class OutputRGBP : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
output.Plane0 = float4 (sample.r, 0, 0, 0);
output.Plane1 = float4 (sample.g, 0, 0, 0);
output.Plane2 = float4 (sample.b, 0, 0, 0);
return output;
}
};
class OutputBGRP : IOutputPlanar
{
PS_OUTPUT_PLANAR Build (float4 sample)
{
PS_OUTPUT_PLANAR output;
output.Plane0 = float4 (sample.b, 0, 0, 0);
output.Plane1 = float4 (sample.g, 0, 0, 0);
output.Plane2 = float4 (sample.r, 0, 0, 0);
return output;
}
};
interface IOutputPlanarFull
{
PS_OUTPUT_PLANAR_FULL Build (float4 sample);
};
class OutputGBRA : IOutputPlanarFull
{
PS_OUTPUT_PLANAR_FULL Build (float4 sample)
{
PS_OUTPUT_PLANAR_FULL output;
output.Plane0 = float4 (sample.g, 0, 0, 0);
output.Plane1 = float4 (sample.b, 0, 0, 0);
output.Plane2 = float4 (sample.r, 0, 0, 0);
output.Plane3 = float4 (sample.a * alphaFactor, 0, 0, 0);
return output;
}
};
class OutputGBRA_10 : IOutputPlanarFull
{
PS_OUTPUT_PLANAR_FULL Build (float4 sample)
{
PS_OUTPUT_PLANAR_FULL output;
float4 scaled;
sample.a *= alphaFactor;
scaled = UnormTo10bit (sample);
output.Plane0 = float4 (scaled.g, 0, 0, 0);
output.Plane1 = float4 (scaled.b, 0, 0, 0);
output.Plane2 = float4 (scaled.r, 0, 0, 0);
output.Plane3 = float4 (scaled.a, 0, 0, 0);
return output;
}
};
class OutputGBRA_12 : IOutputPlanarFull
{
PS_OUTPUT_PLANAR_FULL Build (float4 sample)
{
PS_OUTPUT_PLANAR_FULL output;
float4 scaled;
sample.a *= alphaFactor;
scaled = UnormTo12bit (sample);
output.Plane0 = float4 (scaled.g, 0, 0, 0);
output.Plane1 = float4 (scaled.b, 0, 0, 0);
output.Plane2 = float4 (scaled.r, 0, 0, 0);
output.Plane3 = float4 (scaled.a, 0, 0, 0);
return output;
}
};
OUTPUT_TYPE ENTRY_POINT (PS_INPUT input)
{
SAMPLER g_sampler;
CONVERTER g_converter;
OUTPUT_BUILDER g_builder;
return g_builder.Build (g_converter.Execute (g_sampler.Execute (input.Texture)));
}

View file

@ -1,32 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
Texture2D shaderTexture : register(t0);
SamplerState samplerState : register(s0);
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 Texture : TEXCOORD;
};
float4 PSMain_sample (PS_INPUT input): SV_TARGET
{
return shaderTexture.Sample (samplerState, input.Texture);
}

View file

@ -1,38 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
Texture2D shaderTexture : register(t0);
SamplerState samplerState : register(s0);
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 Texture : TEXCOORD;
};
float4 PSMain_sample_premul (PS_INPUT input): SV_TARGET
{
float4 sample = shaderTexture.Sample (samplerState, input.Texture);
float4 premul_sample;
premul_sample.r = saturate (sample.r * sample.a);
premul_sample.g = saturate (sample.g * sample.a);
premul_sample.b = saturate (sample.b * sample.a);
premul_sample.a = sample.a;
return premul_sample;
}

View file

@ -1,45 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
cbuffer SnowConstBuffer : register(b0)
{
float time;
float alpha;
};
struct PS_INPUT
{
float4 Position : SV_POSITION;
float2 Texture : TEXCOORD;
};
float get_rand (float2 uv)
{
return frac (sin (dot (uv, float2 (12.9898,78.233))) * 43758.5453);
}
float4 PSMain_snow (PS_INPUT input) : SV_Target
{
float4 output;
float val = get_rand (time * input.Texture);
output.rgb = float3(val, val, val);
output.a = alpha;
return output;
}

View file

@ -1,35 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
struct VS_INPUT
{
float4 Position : POSITION;
float4 Color : COLOR;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float4 Color : COLOR;
};
VS_OUTPUT VSMain_color (VS_INPUT input)
{
return input;
}

View file

@ -1,45 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
cbuffer VsConstBuffer : register(b0)
{
matrix Transform;
};
struct VS_INPUT
{
float4 Position : POSITION;
float2 Texture : TEXCOORD;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float2 Texture : TEXCOORD;
};
VS_OUTPUT VSMain_converter (VS_INPUT input)
{
VS_OUTPUT output;
output.Position = mul (Transform, input.Position);
output.Texture = input.Texture;
return output;
}

View file

@ -1,35 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
struct VS_INPUT
{
float4 Position : POSITION;
float2 Texture : TEXCOORD;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
float2 Texture : TEXCOORD;
};
VS_OUTPUT VSMain_coord (VS_INPUT input)
{
return input;
}

View file

@ -1,33 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
struct VS_INPUT
{
float4 Position : POSITION;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION;
};
VS_OUTPUT VSMain_pos (VS_INPUT input)
{
return input;
}

View file

@ -1,64 +0,0 @@
#!/usr/bin/env python3
# GStreamer
# Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
import sys
import os
import argparse
start_header = """/*
* This file is autogenerated by collect_hlsl_header.py
*/
#pragma once
"""
start_map = """
#define MAKE_BYTECODE(name) { G_STRINGIFY (name), { g_##name, sizeof (g_##name)} }
static const std::map<std::string, std::pair<const BYTE *, SIZE_T>> precompiled_bytecode = {
"""
end_map = """};
#undef MAKE_BYTECODE
"""
def main(args):
parser = argparse.ArgumentParser(description='Read precompiled HLSL headers from directory and make single header')
parser.add_argument("--input", help="the precompiled HLSL header directory")
parser.add_argument("--output", help="output header file location")
parser.add_argument("--prefix", help="HLSL header filename prefix")
args = parser.parse_args(args)
# Scan precompiled PSMain_*.h headers in build directory
# and generate single header
hlsl_headers = [os.path.basename(file) for file in os.listdir(args.input) if file.startswith(args.prefix) and file.endswith(".h") ]
with open(args.output, 'w', newline='\n', encoding='utf8') as f:
f.write(start_header)
for file in hlsl_headers:
f.write("#include \"")
f.write(file)
f.write("\"\n")
f.write(start_map)
for file in hlsl_headers:
f.write(" MAKE_BYTECODE ({}),\n".format(os.path.splitext(file)[0]))
f.write(end_map)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

View file

@ -1,169 +0,0 @@
hlsl_conv_ps_source = files('PSMain_converter.hlsl')
hlsl_conv_ps_input_formats = [
['NV12', false, 2],
['NV21', false, 2],
['I420', false, 3],
['YV12', false, 3],
['I420_10', false, 3],
['I420_12', false, 3],
['VUYA', false, 1],
['Y410', false, 1],
['AYUV', false, 1],
['Y412', false, 1],
['RGBA', true, 1],
['RGBAPremul', true, 1],
['RGBx', true, 1],
['GBR', true, 3],
['GBR_10', true, 3],
['GBR_12', true, 3],
['GBRA', true, 4],
['GBRA_10', true, 4],
['GBRA_12', true, 4],
['RGBP', true, 3],
['BGRP', true, 3],
['xRGB', true, 1],
['ARGB', true, 1],
['xBGR', true, 1],
['ABGR', true, 1],
['BGR10A2', true, 1],
['BGRA64', true, 1],
['RBGA', true, 1],
['GRAY', false, 1],
]
hlsl_conv_ps_output_formats = [
['PS_OUTPUT_LUMA', 'Luma', false],
['PS_OUTPUT_LUMA', 'Luma_10', false],
['PS_OUTPUT_LUMA', 'Luma_12', false],
['PS_OUTPUT_CHROMA', 'ChromaNV12', false],
['PS_OUTPUT_CHROMA', 'ChromaNV21', false],
['PS_OUTPUT_CHROMA_PLANAR', 'ChromaI420', false],
['PS_OUTPUT_CHROMA_PLANAR', 'ChromaYV12', false],
['PS_OUTPUT_CHROMA_PLANAR', 'ChromaI420_10', false],
['PS_OUTPUT_CHROMA_PLANAR', 'ChromaI420_12', false],
['PS_OUTPUT_PLANAR', 'Y444', false],
['PS_OUTPUT_PLANAR', 'Y444_10', false],
['PS_OUTPUT_PLANAR', 'Y444_12', false],
['PS_OUTPUT_PLANAR', 'GBR', true],
['PS_OUTPUT_PLANAR', 'GBR_10', true],
['PS_OUTPUT_PLANAR', 'GBR_12', true],
['PS_OUTPUT_PLANAR', 'RGBP', true],
['PS_OUTPUT_PLANAR', 'BGRP', true],
['PS_OUTPUT_PLANAR_FULL', 'GBRA', true],
['PS_OUTPUT_PLANAR_FULL', 'GBRA_10', true],
['PS_OUTPUT_PLANAR_FULL', 'GBRA_12', true],
['PS_OUTPUT_PACKED', 'RGBA', true],
['PS_OUTPUT_PACKED', 'RGBAPremul', true],
['PS_OUTPUT_PACKED', 'RBGA', true],
['PS_OUTPUT_PACKED', 'RGBx', true],
['PS_OUTPUT_PACKED', 'VUYA', false],
['PS_OUTPUT_PACKED', 'AYUV', false],
['PS_OUTPUT_PACKED', 'xRGB', true],
['PS_OUTPUT_PACKED', 'ARGB', true],
['PS_OUTPUT_PACKED', 'xBGR', true],
['PS_OUTPUT_PACKED', 'ABGR', true],
]
extra_converters = [
'Gamma',
'Primary',
]
header_collector = find_program('collect_hlsl_header.py')
foreach input_format : hlsl_conv_ps_input_formats
in_format = input_format.get(0)
num_srv = input_format.get(2)
foreach output_format : hlsl_conv_ps_output_formats
converters = []
if input_format.get(1) != output_format.get(2)
converters += ['Simple']
else
converters += ['Identity', 'Range']
endif
output_type = output_format.get(0)
output_builder = output_format.get(1)
foreach conv : converters
entry_point = 'PSMain_@0@_@1@_@2@'.format(in_format, conv, output_builder)
header = '@0@.h'.format(entry_point)
compiled_shader = custom_target(header,
input : hlsl_conv_ps_source,
output : header,
command : [fxc, '/Fh', '@OUTPUT@',
'/E', entry_point,
'/T', 'ps_5_0',
'/D', 'OUTPUT_TYPE=@0@'.format(output_type),
'/D', 'ENTRY_POINT=@0@'.format(entry_point),
'/D', 'SAMPLER=Sampler@0@'.format(in_format),
'/D', 'CONVERTER=Converter@0@'.format(conv),
'/D', 'OUTPUT_BUILDER=Output@0@'.format(output_builder),
'/nologo',
'@INPUT@'])
hlsl_precompiled += [compiled_shader]
endforeach
foreach conv : extra_converters
entry_point = 'PSMain_@0@_@1@_@2@'.format(in_format, conv, output_builder)
header = '@0@.h'.format(entry_point)
compiled_shader = custom_target(header,
input : hlsl_conv_ps_source,
output : header,
command : [fxc, '/Fh', '@OUTPUT@',
'/E', entry_point,
'/T', 'ps_5_0',
'/D', 'OUTPUT_TYPE=@0@'.format(output_type),
'/D', 'ENTRY_POINT=@0@'.format(entry_point),
'/D', 'SAMPLER=Sampler@0@'.format(in_format),
'/D', 'CONVERTER=Converter@0@'.format(conv),
'/D', 'OUTPUT_BUILDER=Output@0@'.format(output_builder),
'/nologo',
'@INPUT@'])
hlsl_precompiled += [compiled_shader]
endforeach
endforeach
endforeach
header_collection = 'PSMainConverter.h'
generated_collection = custom_target(header_collection,
input : hlsl_precompiled,
output : header_collection,
command : [header_collector,
'--input', meson.current_build_dir(),
'--prefix', 'PSMain_',
'--output', '@OUTPUT@'
])
hlsl_precompiled += generated_collection
hlsl_sources = [
['VSMain_converter', 'vs_5_0'],
['PSMain_sample', 'ps_5_0'],
['PSMain_sample_premul', 'ps_5_0'],
['VSMain_coord', 'vs_5_0'],
['PSMain_color', 'ps_5_0'],
['VSMain_color', 'vs_5_0'],
['PSMain_snow', 'ps_5_0'],
['PSMain_checker', 'ps_5_0'],
['PSMain_checker_luma', 'ps_5_0'],
['PSMain_checker_rgb', 'ps_5_0'],
['PSMain_checker_vuya', 'ps_5_0'],
['VSMain_pos', 'vs_5_0'],
]
foreach shader : hlsl_sources
entry_point = shader.get(0)
source = files('@0@.hlsl'.format(entry_point))
header = '@0@.h'.format(entry_point)
compiled_shader = custom_target(header,
input : source,
output : header,
command : [fxc, '/Fh', '@OUTPUT@',
'/E', entry_point,
'/T', shader.get(1),
'/nologo',
'@INPUT@'])
hlsl_precompiled += [compiled_shader]
endforeach

View file

@ -46,8 +46,6 @@ d3d12_sources = [
'plugin.cpp',
]
hlsl_precompiled = []
extra_args = [
'-DGST_USE_UNSTABLE_API',
# Disable this warning error. Otherwise d3dx12.h will break build
@ -75,10 +73,9 @@ dx_headers_dep = dependency('DirectX-Headers',
version: '>= 1.611',
allow_fallback: true,
required: d3d12_option)
fxc = find_program('fxc', required : d3d12_option)
if not gstdxva_dep.found() or not d3d12_lib.found() or not dxgi_lib.found() \
or not dx_headers_dep.found() or not fxc.found() or not d2d_dep.found() \
or not dx_headers_dep.found() or not gstd3dshader_dep.found() or not d2d_dep.found() \
or not dwmapi_lib.found()
if d3d12_option.enabled()
error('The d3d12 was enabled explicitly, but required dependencies were not found.')
@ -134,9 +131,6 @@ if not have_d3d12_headers
subdir_done()
endif
hlsl_precompiled = []
subdir('hlsl')
# https://learn.microsoft.com/en-us/windows/win32/dxmath/pg-xnamath-internals#windows-sse-versus-sse2
# x86 with Windows 7 or older may not support SSE2
if host_machine.cpu_family() != 'x86'
@ -144,13 +138,13 @@ if host_machine.cpu_family() != 'x86'
endif
gstd3d12 = library('gstd3d12',
d3d12_sources + hlsl_precompiled,
d3d12_sources,
c_args : gst_plugins_bad_args + extra_args,
cpp_args: gst_plugins_bad_args + extra_args,
include_directories : [configinc],
dependencies : [gstbase_dep, gstvideo_dep, gstcodecs_dep, gmodule_dep,
gstdxva_dep, d3d12_lib, d3d11_lib, d2d_dep, dxgi_lib,
dx_headers_dep, dwmapi_lib],
gstd3dshader_dep, dx_headers_dep, dwmapi_lib],
install : true,
install_dir : plugins_install_dir,
)