Vulkan: Assume all 1D texture sampling is actually sampling a 2D texture.
This commit is contained in:
parent
fdef1e098d
commit
42533d39eb
|
@ -189,9 +189,6 @@ void SpirvShaderTranslator::StartTranslation() {
|
||||||
push_consts_ = b.createVariable(spv::StorageClass::StorageClassPushConstant,
|
push_consts_ = b.createVariable(spv::StorageClass::StorageClassPushConstant,
|
||||||
push_constants_type, "push_consts");
|
push_constants_type, "push_consts");
|
||||||
|
|
||||||
image_1d_type_ =
|
|
||||||
b.makeImageType(float_type_, spv::Dim::Dim1D, false, false, false, 1,
|
|
||||||
spv::ImageFormat::ImageFormatUnknown);
|
|
||||||
image_2d_type_ =
|
image_2d_type_ =
|
||||||
b.makeImageType(float_type_, spv::Dim::Dim2D, false, false, false, 1,
|
b.makeImageType(float_type_, spv::Dim::Dim2D, false, false, false, 1,
|
||||||
spv::ImageFormat::ImageFormatUnknown);
|
spv::ImageFormat::ImageFormatUnknown);
|
||||||
|
@ -203,21 +200,19 @@ void SpirvShaderTranslator::StartTranslation() {
|
||||||
spv::ImageFormat::ImageFormatUnknown);
|
spv::ImageFormat::ImageFormatUnknown);
|
||||||
|
|
||||||
// Texture bindings
|
// Texture bindings
|
||||||
Id tex_t[] = {b.makeSampledImageType(image_1d_type_),
|
Id tex_t[] = {b.makeSampledImageType(image_2d_type_),
|
||||||
b.makeSampledImageType(image_2d_type_),
|
|
||||||
b.makeSampledImageType(image_3d_type_),
|
b.makeSampledImageType(image_3d_type_),
|
||||||
b.makeSampledImageType(image_cube_type_)};
|
b.makeSampledImageType(image_cube_type_)};
|
||||||
|
|
||||||
Id tex_a_t[] = {b.makeArrayType(tex_t[0], b.makeUintConstant(32), 0),
|
Id tex_a_t[] = {b.makeArrayType(tex_t[0], b.makeUintConstant(32), 0),
|
||||||
b.makeArrayType(tex_t[1], b.makeUintConstant(32), 0),
|
b.makeArrayType(tex_t[1], b.makeUintConstant(32), 0),
|
||||||
b.makeArrayType(tex_t[2], b.makeUintConstant(32), 0),
|
b.makeArrayType(tex_t[2], b.makeUintConstant(32), 0)};
|
||||||
b.makeArrayType(tex_t[3], b.makeUintConstant(32), 0)};
|
|
||||||
|
|
||||||
// Create 4 texture types, all aliased on the same binding
|
// Create 3 texture types, all aliased on the same binding
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
tex_[i] = b.createVariable(spv::StorageClass::StorageClassUniformConstant,
|
tex_[i] = b.createVariable(spv::StorageClass::StorageClassUniformConstant,
|
||||||
tex_a_t[i],
|
tex_a_t[i],
|
||||||
xe::format_string("textures%dD", i + 1).c_str());
|
xe::format_string("textures%dD", i + 2).c_str());
|
||||||
b.addDecoration(tex_[i], spv::Decoration::DecorationDescriptorSet, 1);
|
b.addDecoration(tex_[i], spv::Decoration::DecorationDescriptorSet, 1);
|
||||||
b.addDecoration(tex_[i], spv::Decoration::DecorationBinding, 0);
|
b.addDecoration(tex_[i], spv::Decoration::DecorationBinding, 0);
|
||||||
}
|
}
|
||||||
|
@ -1296,17 +1291,15 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
|
||||||
|
|
||||||
uint32_t dim_idx = 0;
|
uint32_t dim_idx = 0;
|
||||||
switch (instr.dimension) {
|
switch (instr.dimension) {
|
||||||
case TextureDimension::k1D: {
|
case TextureDimension::k1D:
|
||||||
|
case TextureDimension::k2D: {
|
||||||
dim_idx = 0;
|
dim_idx = 0;
|
||||||
} break;
|
} break;
|
||||||
case TextureDimension::k2D: {
|
case TextureDimension::k3D: {
|
||||||
dim_idx = 1;
|
dim_idx = 1;
|
||||||
} break;
|
} break;
|
||||||
case TextureDimension::k3D: {
|
|
||||||
dim_idx = 2;
|
|
||||||
} break;
|
|
||||||
case TextureDimension::kCube: {
|
case TextureDimension::kCube: {
|
||||||
dim_idx = 3;
|
dim_idx = 2;
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
assert_unhandled_case(instr.dimension);
|
assert_unhandled_case(instr.dimension);
|
||||||
|
@ -1332,22 +1325,30 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
|
||||||
size = b.createTextureQueryCall(spv::Op::OpImageQuerySizeLod, params);
|
size = b.createTextureQueryCall(spv::Op::OpImageQuerySizeLod, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instr.dimension == TextureDimension::k1D &&
|
if (instr.dimension == TextureDimension::k1D) {
|
||||||
(instr.attributes.offset_x)) {
|
if (instr.attributes.offset_x) {
|
||||||
auto offset = b.makeFloatConstant(instr.attributes.offset_x + 0.5f);
|
auto offset = b.makeFloatConstant(instr.attributes.offset_x + 0.5f);
|
||||||
offset = b.createBinOp(spv::Op::OpFDiv, float_type_, offset, size);
|
offset = b.createBinOp(spv::Op::OpFDiv, float_type_, offset, size);
|
||||||
|
src = b.createBinOp(spv::Op::OpFAdd, float_type_, src, offset);
|
||||||
src = b.createBinOp(spv::Op::OpFAdd, float_type_, src, offset);
|
}
|
||||||
} else if (instr.dimension == TextureDimension::k2D &&
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb944006.aspx
|
||||||
(instr.attributes.offset_x || instr.attributes.offset_y)) {
|
// "Because the runtime does not support 1D textures, the compiler will
|
||||||
auto offset = b.makeCompositeConstant(
|
// use a 2D texture with the knowledge that the y-coordinate is
|
||||||
|
// unimportant."
|
||||||
|
src = b.createCompositeConstruct(
|
||||||
vec2_float_type_,
|
vec2_float_type_,
|
||||||
std::vector<Id>(
|
std::vector<Id>({src, b.makeFloatConstant(0.0f)}));
|
||||||
{b.makeFloatConstant(instr.attributes.offset_x + 0.5f),
|
} else if (instr.dimension == TextureDimension::k2D) {
|
||||||
b.makeFloatConstant(instr.attributes.offset_y + 0.5f)}));
|
if (instr.attributes.offset_x || instr.attributes.offset_y) {
|
||||||
|
auto offset = b.makeCompositeConstant(
|
||||||
offset = b.createBinOp(spv::Op::OpFDiv, vec2_float_type_, offset, size);
|
vec2_float_type_,
|
||||||
src = b.createBinOp(spv::Op::OpFAdd, vec2_float_type_, src, offset);
|
std::vector<Id>(
|
||||||
|
{b.makeFloatConstant(instr.attributes.offset_x + 0.5f),
|
||||||
|
b.makeFloatConstant(instr.attributes.offset_y + 0.5f)}));
|
||||||
|
offset =
|
||||||
|
b.createBinOp(spv::Op::OpFDiv, vec2_float_type_, offset, size);
|
||||||
|
src = b.createBinOp(spv::Op::OpFAdd, vec2_float_type_, src, offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spv::Builder::TextureParameters params = {0};
|
spv::Builder::TextureParameters params = {0};
|
||||||
|
@ -1367,23 +1368,7 @@ void SpirvShaderTranslator::ProcessTextureFetchInstruction(
|
||||||
b.createUnaryOp(spv::OpImage, b.getImageType(texture), texture);
|
b.createUnaryOp(spv::OpImage, b.getImageType(texture), texture);
|
||||||
|
|
||||||
switch (instr.dimension) {
|
switch (instr.dimension) {
|
||||||
case TextureDimension::k1D: {
|
case TextureDimension::k1D:
|
||||||
spv::Builder::TextureParameters params;
|
|
||||||
std::memset(¶ms, 0, sizeof(params));
|
|
||||||
params.sampler = image;
|
|
||||||
params.lod = b.makeIntConstant(0);
|
|
||||||
auto size =
|
|
||||||
b.createTextureQueryCall(spv::Op::OpImageQuerySizeLod, params);
|
|
||||||
size = b.createUnaryOp(spv::Op::OpConvertUToF, float_type_, size);
|
|
||||||
|
|
||||||
auto weight = b.createBinOp(spv::Op::OpFMul, float_type_, size, src);
|
|
||||||
weight = CreateGlslStd450InstructionCall(
|
|
||||||
spv::NoPrecision, float_type_, spv::GLSLstd450::kFract, {weight});
|
|
||||||
|
|
||||||
dest = b.createOp(spv::Op::OpVectorShuffle, vec4_float_type_,
|
|
||||||
{weight, vec4_float_zero_, 0, 1, 1, 1});
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case TextureDimension::k2D: {
|
case TextureDimension::k2D: {
|
||||||
spv::Builder::TextureParameters params;
|
spv::Builder::TextureParameters params;
|
||||||
std::memset(¶ms, 0, sizeof(params));
|
std::memset(¶ms, 0, sizeof(params));
|
||||||
|
|
|
@ -137,8 +137,7 @@ class SpirvShaderTranslator : public ShaderTranslator {
|
||||||
spv::Id vec2_float_type_ = 0, vec3_float_type_ = 0, vec4_float_type_ = 0;
|
spv::Id vec2_float_type_ = 0, vec3_float_type_ = 0, vec4_float_type_ = 0;
|
||||||
spv::Id vec4_int_type_ = 0, vec4_uint_type_ = 0;
|
spv::Id vec4_int_type_ = 0, vec4_uint_type_ = 0;
|
||||||
spv::Id vec2_bool_type_ = 0, vec3_bool_type_ = 0, vec4_bool_type_ = 0;
|
spv::Id vec2_bool_type_ = 0, vec3_bool_type_ = 0, vec4_bool_type_ = 0;
|
||||||
spv::Id image_1d_type_ = 0, image_2d_type_ = 0, image_3d_type_ = 0,
|
spv::Id image_2d_type_ = 0, image_3d_type_ = 0, image_cube_type_ = 0;
|
||||||
image_cube_type_ = 0;
|
|
||||||
|
|
||||||
// Constants.
|
// Constants.
|
||||||
spv::Id vec4_float_zero_ = 0, vec4_float_one_ = 0;
|
spv::Id vec4_float_zero_ = 0, vec4_float_one_ = 0;
|
||||||
|
@ -157,7 +156,7 @@ class SpirvShaderTranslator : public ShaderTranslator {
|
||||||
spv::Id vertex_idx_ = 0;
|
spv::Id vertex_idx_ = 0;
|
||||||
spv::Id frag_outputs_ = 0, frag_depth_ = 0;
|
spv::Id frag_outputs_ = 0, frag_depth_ = 0;
|
||||||
spv::Id samplers_ = 0;
|
spv::Id samplers_ = 0;
|
||||||
spv::Id tex_[4] = {0}; // Images {1D, 2D, 3D, Cube}
|
spv::Id tex_[3] = {0}; // Images {2D, 3D, Cube}
|
||||||
|
|
||||||
// SPIR-V IDs that are part of the in/out interface.
|
// SPIR-V IDs that are part of the in/out interface.
|
||||||
std::vector<spv::Id> interface_ids_;
|
std::vector<spv::Id> interface_ids_;
|
||||||
|
|
Loading…
Reference in New Issue