glsl: Implement more attribute getters and setters
This commit is contained in:
parent
8bb8bbf4ae
commit
3f31a547e0
@ -239,6 +239,7 @@ bool UsesTyplessImage(const Info& info) {
|
|||||||
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
||||||
const RuntimeInfo& runtime_info_)
|
const RuntimeInfo& runtime_info_)
|
||||||
: info{program.info}, profile{profile_}, runtime_info{runtime_info_} {
|
: info{program.info}, profile{profile_}, runtime_info{runtime_info_} {
|
||||||
|
header += "#pragma optionNV(fastmath off)\n";
|
||||||
SetupExtensions(header);
|
SetupExtensions(header);
|
||||||
stage = program.stage;
|
stage = program.stage;
|
||||||
switch (program.stage) {
|
switch (program.stage) {
|
||||||
@ -351,6 +352,9 @@ void EmitContext::SetupExtensions(std::string&) {
|
|||||||
if (info.uses_sparse_residency) {
|
if (info.uses_sparse_residency) {
|
||||||
header += "#extension GL_ARB_sparse_texture2 : enable\n";
|
header += "#extension GL_ARB_sparse_texture2 : enable\n";
|
||||||
}
|
}
|
||||||
|
if (info.stores_viewport_mask && profile.support_viewport_mask) {
|
||||||
|
header += "#extension GL_NV_viewport_array2 : enable\n";
|
||||||
|
}
|
||||||
if (UsesTyplessImage(info)) {
|
if (UsesTyplessImage(info)) {
|
||||||
header += "#extension GL_EXT_shader_image_load_formatted : enable\n";
|
header += "#extension GL_EXT_shader_image_load_formatted : enable\n";
|
||||||
}
|
}
|
||||||
|
@ -203,6 +203,9 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
|
case IR::Attribute::PrimitiveId:
|
||||||
|
ctx.AddF32("{}=itof(gl_PrimitiveID);", inst);
|
||||||
|
break;
|
||||||
case IR::Attribute::PositionX:
|
case IR::Attribute::PositionX:
|
||||||
case IR::Attribute::PositionY:
|
case IR::Attribute::PositionY:
|
||||||
case IR::Attribute::PositionZ:
|
case IR::Attribute::PositionZ:
|
||||||
@ -212,10 +215,20 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
|||||||
ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle);
|
ctx.AddF32("{}={}{}.{};", inst, input_decorator, ctx.position_name, swizzle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case IR::Attribute::ColorFrontDiffuseR:
|
||||||
|
case IR::Attribute::ColorFrontDiffuseG:
|
||||||
|
case IR::Attribute::ColorFrontDiffuseB:
|
||||||
|
case IR::Attribute::ColorFrontDiffuseA:
|
||||||
|
ctx.AddF32("{}=gl_FrontMaterial.diffuse.{};", inst, swizzle);
|
||||||
|
break;
|
||||||
case IR::Attribute::PointSpriteS:
|
case IR::Attribute::PointSpriteS:
|
||||||
case IR::Attribute::PointSpriteT:
|
case IR::Attribute::PointSpriteT:
|
||||||
ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle);
|
ctx.AddF32("{}=gl_PointCoord.{};", inst, swizzle);
|
||||||
break;
|
break;
|
||||||
|
case IR::Attribute::TessellationEvaluationPointU:
|
||||||
|
case IR::Attribute::TessellationEvaluationPointV:
|
||||||
|
ctx.AddF32("{}=gl_TessCoord.{};", inst, swizzle);
|
||||||
|
break;
|
||||||
case IR::Attribute::InstanceId:
|
case IR::Attribute::InstanceId:
|
||||||
ctx.AddF32("{}=itof(gl_InstanceID);", inst);
|
ctx.AddF32("{}=itof(gl_InstanceID);", inst);
|
||||||
break;
|
break;
|
||||||
@ -225,10 +238,6 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
|
|||||||
case IR::Attribute::FrontFace:
|
case IR::Attribute::FrontFace:
|
||||||
ctx.AddF32("{}=itof(gl_FrontFacing?-1:0);", inst);
|
ctx.AddF32("{}=itof(gl_FrontFacing?-1:0);", inst);
|
||||||
break;
|
break;
|
||||||
case IR::Attribute::TessellationEvaluationPointU:
|
|
||||||
case IR::Attribute::TessellationEvaluationPointV:
|
|
||||||
ctx.AddF32("{}=gl_TessCoord.{};", inst, swizzle);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
fmt::print("Get attribute {}", attr);
|
fmt::print("Get attribute {}", attr);
|
||||||
throw NotImplementedException("Get attribute {}", attr);
|
throw NotImplementedException("Get attribute {}", attr);
|
||||||
@ -262,6 +271,23 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val
|
|||||||
}
|
}
|
||||||
ctx.Add("gl_Layer=ftoi({});", value);
|
ctx.Add("gl_Layer=ftoi({});", value);
|
||||||
break;
|
break;
|
||||||
|
case IR::Attribute::ViewportIndex:
|
||||||
|
if (ctx.stage != Stage::Geometry &&
|
||||||
|
!ctx.profile.support_viewport_index_layer_non_geometry) {
|
||||||
|
// LOG_WARNING(..., "Shader stores viewport index but device does not support viewport
|
||||||
|
// layer extension");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ctx.Add("gl_ViewportIndex=ftoi({});", value);
|
||||||
|
break;
|
||||||
|
case IR::Attribute::ViewportMask:
|
||||||
|
if (ctx.stage != Stage::Geometry && !ctx.profile.support_viewport_mask) {
|
||||||
|
// LOG_WARNING(..., "Shader stores viewport mask but device does not support viewport
|
||||||
|
// mask extension");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ctx.Add("gl_ViewportMask[0]=ftoi({});", value);
|
||||||
|
break;
|
||||||
case IR::Attribute::PointSize:
|
case IR::Attribute::PointSize:
|
||||||
ctx.Add("gl_PointSize={};", value);
|
ctx.Add("gl_PointSize={};", value);
|
||||||
break;
|
break;
|
||||||
@ -271,14 +297,32 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view val
|
|||||||
case IR::Attribute::PositionW:
|
case IR::Attribute::PositionW:
|
||||||
ctx.Add("gl_Position.{}={};", swizzle, value);
|
ctx.Add("gl_Position.{}={};", swizzle, value);
|
||||||
break;
|
break;
|
||||||
case IR::Attribute::ViewportIndex:
|
case IR::Attribute::ColorFrontDiffuseR:
|
||||||
if (ctx.stage != Stage::Geometry &&
|
case IR::Attribute::ColorFrontDiffuseG:
|
||||||
!ctx.profile.support_viewport_index_layer_non_geometry) {
|
case IR::Attribute::ColorFrontDiffuseB:
|
||||||
// LOG_WARNING(..., "Shader stores viewport index but device does not support viewport
|
case IR::Attribute::ColorFrontDiffuseA:
|
||||||
// layer extension");
|
ctx.Add("gl_FrontMaterial.diffuse.{}={};", swizzle, value);
|
||||||
break;
|
break;
|
||||||
}
|
case IR::Attribute::ColorFrontSpecularR:
|
||||||
ctx.Add("gl_ViewportIndex=ftoi({});", value);
|
case IR::Attribute::ColorFrontSpecularG:
|
||||||
|
case IR::Attribute::ColorFrontSpecularB:
|
||||||
|
case IR::Attribute::ColorFrontSpecularA:
|
||||||
|
ctx.Add("gl_FrontMaterial.specular.{}={};", swizzle, value);
|
||||||
|
break;
|
||||||
|
case IR::Attribute::ColorBackDiffuseR:
|
||||||
|
case IR::Attribute::ColorBackDiffuseG:
|
||||||
|
case IR::Attribute::ColorBackDiffuseB:
|
||||||
|
case IR::Attribute::ColorBackDiffuseA:
|
||||||
|
ctx.Add("gl_BackMaterial.diffuse.{}={};", swizzle, value);
|
||||||
|
break;
|
||||||
|
case IR::Attribute::ColorBackSpecularR:
|
||||||
|
case IR::Attribute::ColorBackSpecularG:
|
||||||
|
case IR::Attribute::ColorBackSpecularB:
|
||||||
|
case IR::Attribute::ColorBackSpecularA:
|
||||||
|
ctx.Add("gl_BackMaterial.specular.{}={};", swizzle, value);
|
||||||
|
break;
|
||||||
|
case IR::Attribute::FogCoordinate:
|
||||||
|
ctx.Add("gl_FragCoord.x={};", value);
|
||||||
break;
|
break;
|
||||||
case IR::Attribute::ClipDistance0:
|
case IR::Attribute::ClipDistance0:
|
||||||
case IR::Attribute::ClipDistance1:
|
case IR::Attribute::ClipDistance1:
|
||||||
|
Loading…
Reference in New Issue
Block a user