Pack shading rate in position variable
This commit is contained in:
@@ -36,9 +36,8 @@ struct stream_defoveator::vertex
|
||||
{
|
||||
// output image position
|
||||
alignas(8) glm::vec2 position;
|
||||
// input texture coordinates
|
||||
alignas(8) glm::vec2 uv;
|
||||
int32_t shading_rate;
|
||||
// input texture coordinates + shading rate in the first 4 bits of x
|
||||
alignas(8) glm::uvec2 uv;
|
||||
};
|
||||
|
||||
struct vert_pc
|
||||
@@ -184,15 +183,9 @@ FIXME: SGSR
|
||||
{
|
||||
.location = 1,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.format = vk::Format::eR32G32Uint,
|
||||
.offset = offsetof(vertex, uv),
|
||||
},
|
||||
{
|
||||
.location = 2,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32Sint,
|
||||
.offset = offsetof(vertex, shading_rate),
|
||||
},
|
||||
},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
@@ -260,7 +253,7 @@ FIXME: SGSR
|
||||
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
|
||||
{
|
||||
if (fragment_sizes[x][y] == 0)
|
||||
fragment_sizes[x][y] = flags;
|
||||
fragment_sizes[x][y] = flags << 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,7 +367,7 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
int32_t stream_defoveator::shading_rate(int pixels_x, int pixels_y)
|
||||
uint32_t stream_defoveator::shading_rate(int pixels_x, int pixels_y)
|
||||
{
|
||||
int x = 0;
|
||||
if (pixels_x >= 2)
|
||||
@@ -408,7 +401,8 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
const int n_ratio_y = (py.size() - 1) / 2;
|
||||
const int n_ratio_x = (px.size() - 1) / 2;
|
||||
|
||||
glm::vec2 in(0), out(0); // pixel coordinates
|
||||
glm::uvec2 in(0);
|
||||
glm::vec2 out(0); // pixel coordinates
|
||||
glm::vec2 out_pixel_size(2. / output_extent.width,
|
||||
2. / output_extent.height);
|
||||
for (auto [iy, n_out_y]: utils::enumerate_range(py))
|
||||
@@ -420,15 +414,14 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
glm::uvec2 rate = glm::uvec2(shading_rate(ratio_x, ratio_y), 0);
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in,
|
||||
.shading_rate = shading_rate(ratio_x, ratio_y),
|
||||
.uv = in | rate,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
|
||||
.uv = (in + glm::vec2(0, n_out_y)),
|
||||
.shading_rate = shading_rate(ratio_x, ratio_y),
|
||||
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
|
||||
};
|
||||
in.x += n_out_x;
|
||||
out.x += n_out_x * ratio_x;
|
||||
|
||||
@@ -54,7 +54,7 @@ class stream_defoveator
|
||||
// 0 is 1 pixel
|
||||
// 1 is 2 or 3 pixels
|
||||
// 2 is 4 pixels or more
|
||||
int32_t fragment_sizes[3][3] = {};
|
||||
uint32_t fragment_sizes[3][3] = {};
|
||||
|
||||
// Destination images
|
||||
std::vector<vk::Image> output_images;
|
||||
@@ -65,7 +65,7 @@ class stream_defoveator
|
||||
void ensure_vertices(size_t num_vertices);
|
||||
vertex * get_vertices(size_t view);
|
||||
|
||||
int32_t shading_rate(int pixels_x, int pixels_y);
|
||||
uint32_t shading_rate(int pixels_x, int pixels_y);
|
||||
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
|
||||
|
||||
public:
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
|
||||
|
||||
layout (location = 0) in vec2 vPosition;
|
||||
layout (location = 1) in vec2 vUV;
|
||||
layout (location = 2) in int vShadingRate;
|
||||
layout (location = 1) in uvec2 vUV;
|
||||
|
||||
layout(location = 0) out vec4 outUV;
|
||||
|
||||
@@ -39,11 +38,14 @@ layout(push_constant) uniform pc
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(vPosition, 0.0, 1.0);
|
||||
outUV.xy = (vUV + rgb_rect.xy) / rgb_rect.zw;
|
||||
outUV.zw = (vUV + a_rect.xy) / a_rect.zw;
|
||||
#if VSR
|
||||
gl_PrimitiveShadingRateEXT = vShadingRate;
|
||||
gl_PrimitiveShadingRateEXT = int(bitfieldExtract(vUV.x, 28, 4));
|
||||
vec2 uv = bitfieldInsert(vUV, uvec2(0), 28, 4);
|
||||
#else
|
||||
vec2 uv = vUV;
|
||||
#endif
|
||||
outUV.xy = (uv + rgb_rect.xy) / rgb_rect.zw;
|
||||
outUV.zw = (uv + a_rect.xy) / a_rect.zw;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user