public void PrepareForReturn() { if (_config.Stage == ShaderStage.Fragment) { if (_config.OmapDepth) { Operand dest = Attribute(AttributeConsts.FragmentOutputDepth); Operand src = Register(_config.GetDepthRegister(), RegisterType.Gpr); this.Copy(dest, src); } int regIndex = 0; for (int attachment = 0; attachment < 8; attachment++) { OmapTarget target = _config.OmapTargets[attachment]; for (int component = 0; component < 4; component++) { if (target.ComponentEnabled(component)) { Operand dest = Attribute(AttributeConsts.FragmentOutputColorBase + attachment * 16 + component * 4); Operand src = Register(regIndex, RegisterType.Gpr); this.Copy(dest, src); regIndex++; } } } } }
public void PrepareForReturn() { if (Config.Stage == ShaderStage.Fragment) { if (Config.OmapDepth) { Operand dest = Attribute(AttributeConsts.FragmentOutputDepth); Operand src = Register(Config.GetDepthRegister(), RegisterType.Gpr); this.Copy(dest, src); } int regIndex = 0; for (int rtIndex = 0; rtIndex < 8; rtIndex++) { OmapTarget target = Config.OmapTargets[rtIndex]; for (int component = 0; component < 4; component++) { if (!target.ComponentEnabled(component)) { continue; } int fragmentOutputColorAttr = AttributeConsts.FragmentOutputColorBase + rtIndex * 16; Operand src = Register(regIndex, RegisterType.Gpr); // Perform B <-> R swap if needed, for BGRA formats (not supported on OpenGL). if (component == 0 || component == 2) { Operand isBgra = Attribute(AttributeConsts.FragmentOutputIsBgraBase + rtIndex * 4); Operand lblIsBgra = Label(); Operand lblEnd = Label(); this.BranchIfTrue(lblIsBgra, isBgra); this.Copy(Attribute(fragmentOutputColorAttr + component * 4), src); this.Branch(lblEnd); MarkLabel(lblIsBgra); this.Copy(Attribute(fragmentOutputColorAttr + (2 - component) * 4), src); MarkLabel(lblEnd); } else { this.Copy(Attribute(fragmentOutputColorAttr + component * 4), src); } regIndex++; } } } }
public ShaderHeader(IGpuAccessor gpuAccessor, ulong address) { int commonWord0 = gpuAccessor.MemoryRead <int>(address + 0); int commonWord1 = gpuAccessor.MemoryRead <int>(address + 4); int commonWord2 = gpuAccessor.MemoryRead <int>(address + 8); int commonWord3 = gpuAccessor.MemoryRead <int>(address + 12); int commonWord4 = gpuAccessor.MemoryRead <int>(address + 16); SphType = commonWord0.Extract(0, 5); Version = commonWord0.Extract(5, 5); Stage = (ShaderStage)commonWord0.Extract(10, 4); // Invalid. if (Stage == ShaderStage.Compute) { Stage = ShaderStage.Vertex; } MrtEnable = commonWord0.Extract(14); KillsPixels = commonWord0.Extract(15); DoesGlobalStore = commonWord0.Extract(16); SassVersion = commonWord0.Extract(17, 4); GpPassthrough = commonWord0.Extract(24); DoesLoadOrStore = commonWord0.Extract(26); DoesFp64 = commonWord0.Extract(27); StreamOutMask = commonWord0.Extract(28, 4); ShaderLocalMemoryLowSize = commonWord1.Extract(0, 24); PerPatchAttributeCount = commonWord1.Extract(24, 8); ShaderLocalMemoryHighSize = commonWord2.Extract(0, 24); ThreadsPerInputPrimitive = commonWord2.Extract(24, 8); ShaderLocalMemoryCrsSize = commonWord3.Extract(0, 24); OutputTopology = (OutputTopology)commonWord3.Extract(24, 4); MaxOutputVertexCount = commonWord4.Extract(0, 12); StoreReqStart = commonWord4.Extract(12, 8); StoreReqEnd = commonWord4.Extract(24, 8); ImapTypes = new ImapPixelType[32]; for (ulong i = 0; i < 32; i++) { byte imap = gpuAccessor.MemoryRead <byte>(address + 0x18 + i); ImapTypes[i] = new ImapPixelType( (PixelImap)((imap >> 0) & 3), (PixelImap)((imap >> 2) & 3), (PixelImap)((imap >> 4) & 3), (PixelImap)((imap >> 6) & 3)); } int type2OmapTarget = gpuAccessor.MemoryRead <int>(address + 0x48); int type2Omap = gpuAccessor.MemoryRead <int>(address + 0x4c); OmapTargets = new OmapTarget[8]; for (int offset = 0; offset < OmapTargets.Length * 4; offset += 4) { OmapTargets[offset >> 2] = new OmapTarget( type2OmapTarget.Extract(offset + 0), type2OmapTarget.Extract(offset + 1), type2OmapTarget.Extract(offset + 2), type2OmapTarget.Extract(offset + 3)); } OmapSampleMask = type2Omap.Extract(0); OmapDepth = type2Omap.Extract(1); }
public void PrepareForReturn() { if (Config.Stage == ShaderStage.Vertex && (Config.Flags & TranslationFlags.VertexA) == 0) { // Here we attempt to implement viewport swizzle on the vertex shader. // Perform permutation and negation of the output gl_Position components. // Note that per-viewport swizzling can't be supported using thhis approach. int swizzleX = Config.GpuAccessor.QueryViewportSwizzle(0); int swizzleY = Config.GpuAccessor.QueryViewportSwizzle(1); int swizzleZ = Config.GpuAccessor.QueryViewportSwizzle(2); int swizzleW = Config.GpuAccessor.QueryViewportSwizzle(3); bool nonStandardSwizzle = swizzleX != 0 || swizzleY != 2 || swizzleZ != 4 || swizzleW != 6; if (!Config.GpuAccessor.QuerySupportsViewportSwizzle() && nonStandardSwizzle) { Operand[] temp = new Operand[4]; temp[0] = this.Copy(Attribute(AttributeConsts.PositionX)); temp[1] = this.Copy(Attribute(AttributeConsts.PositionY)); temp[2] = this.Copy(Attribute(AttributeConsts.PositionZ)); temp[3] = this.Copy(Attribute(AttributeConsts.PositionW)); this.Copy(Attribute(AttributeConsts.PositionX), this.FPNegate(temp[(swizzleX >> 1) & 3], (swizzleX & 1) != 0)); this.Copy(Attribute(AttributeConsts.PositionY), this.FPNegate(temp[(swizzleY >> 1) & 3], (swizzleY & 1) != 0)); this.Copy(Attribute(AttributeConsts.PositionZ), this.FPNegate(temp[(swizzleZ >> 1) & 3], (swizzleZ & 1) != 0)); this.Copy(Attribute(AttributeConsts.PositionW), this.FPNegate(temp[(swizzleW >> 1) & 3], (swizzleW & 1) != 0)); } } else if (Config.Stage == ShaderStage.Fragment) { if (Config.OmapDepth) { Operand dest = Attribute(AttributeConsts.FragmentOutputDepth); Operand src = Register(Config.GetDepthRegister(), RegisterType.Gpr); this.Copy(dest, src); } int regIndex = 0; for (int attachment = 0; attachment < 8; attachment++) { OmapTarget target = Config.OmapTargets[attachment]; for (int component = 0; component < 4; component++) { if (target.ComponentEnabled(component)) { Operand dest = Attribute(AttributeConsts.FragmentOutputColorBase + attachment * 16 + component * 4); Operand src = Register(regIndex, RegisterType.Gpr); this.Copy(dest, src); regIndex++; } } } } }
public void PrepareForReturn() { if (Config.Stage == ShaderStage.Vertex && (Config.Flags & TranslationFlags.VertexA) == 0) { // Here we attempt to implement viewport swizzle on the vertex shader. // Perform permutation and negation of the output gl_Position components. // Note that per-viewport swizzling can't be supported using this approach. int swizzleX = Config.GpuAccessor.QueryViewportSwizzle(0); int swizzleY = Config.GpuAccessor.QueryViewportSwizzle(1); int swizzleZ = Config.GpuAccessor.QueryViewportSwizzle(2); int swizzleW = Config.GpuAccessor.QueryViewportSwizzle(3); bool nonStandardSwizzle = swizzleX != 0 || swizzleY != 2 || swizzleZ != 4 || swizzleW != 6; if (!Config.GpuAccessor.QuerySupportsViewportSwizzle() && nonStandardSwizzle) { Operand[] temp = new Operand[4]; temp[0] = this.Copy(Attribute(AttributeConsts.PositionX)); temp[1] = this.Copy(Attribute(AttributeConsts.PositionY)); temp[2] = this.Copy(Attribute(AttributeConsts.PositionZ)); temp[3] = this.Copy(Attribute(AttributeConsts.PositionW)); this.Copy(Attribute(AttributeConsts.PositionX), this.FPNegate(temp[(swizzleX >> 1) & 3], (swizzleX & 1) != 0)); this.Copy(Attribute(AttributeConsts.PositionY), this.FPNegate(temp[(swizzleY >> 1) & 3], (swizzleY & 1) != 0)); this.Copy(Attribute(AttributeConsts.PositionZ), this.FPNegate(temp[(swizzleZ >> 1) & 3], (swizzleZ & 1) != 0)); this.Copy(Attribute(AttributeConsts.PositionW), this.FPNegate(temp[(swizzleW >> 1) & 3], (swizzleW & 1) != 0)); } } else if (Config.Stage == ShaderStage.Fragment) { if (Config.OmapDepth) { Operand dest = Attribute(AttributeConsts.FragmentOutputDepth); Operand src = Register(Config.GetDepthRegister(), RegisterType.Gpr); this.Copy(dest, src); } int regIndex = 0; for (int rtIndex = 0; rtIndex < 8; rtIndex++) { OmapTarget target = Config.OmapTargets[rtIndex]; for (int component = 0; component < 4; component++) { if (!target.ComponentEnabled(component)) { continue; } int fragmentOutputColorAttr = AttributeConsts.FragmentOutputColorBase + rtIndex * 16; Operand src = Register(regIndex, RegisterType.Gpr); // Perform B <-> R swap if needed, for BGRA formats (not supported on OpenGL). if (component == 0 || component == 2) { Operand isBgra = Attribute(AttributeConsts.FragmentOutputIsBgraBase + rtIndex * 4); Operand lblIsBgra = Label(); Operand lblEnd = Label(); this.BranchIfTrue(lblIsBgra, isBgra); this.Copy(Attribute(fragmentOutputColorAttr + component * 4), src); this.Branch(lblEnd); MarkLabel(lblIsBgra); this.Copy(Attribute(fragmentOutputColorAttr + (2 - component) * 4), src); MarkLabel(lblEnd); } else { this.Copy(Attribute(fragmentOutputColorAttr + component * 4), src); } regIndex++; } } } }
public ShaderHeader(IGpuAccessor gpuAccessor, ulong address) { ReadOnlySpan <int> header = MemoryMarshal.Cast <ulong, int>(gpuAccessor.GetCode(address, 0x50)); int commonWord0 = header[0]; int commonWord1 = header[1]; int commonWord2 = header[2]; int commonWord3 = header[3]; int commonWord4 = header[4]; SphType = commonWord0.Extract(0, 5); Version = commonWord0.Extract(5, 5); Stage = (ShaderStage)commonWord0.Extract(10, 4); // Invalid. if (Stage == ShaderStage.Compute) { Stage = ShaderStage.Vertex; } MrtEnable = commonWord0.Extract(14); KillsPixels = commonWord0.Extract(15); DoesGlobalStore = commonWord0.Extract(16); SassVersion = commonWord0.Extract(17, 4); GpPassthrough = commonWord0.Extract(24); DoesLoadOrStore = commonWord0.Extract(26); DoesFp64 = commonWord0.Extract(27); StreamOutMask = commonWord0.Extract(28, 4); ShaderLocalMemoryLowSize = commonWord1.Extract(0, 24); PerPatchAttributeCount = commonWord1.Extract(24, 8); ShaderLocalMemoryHighSize = commonWord2.Extract(0, 24); ThreadsPerInputPrimitive = commonWord2.Extract(24, 8); ShaderLocalMemoryCrsSize = commonWord3.Extract(0, 24); OutputTopology = (OutputTopology)commonWord3.Extract(24, 4); MaxOutputVertexCount = commonWord4.Extract(0, 12); StoreReqStart = commonWord4.Extract(12, 8); StoreReqEnd = commonWord4.Extract(24, 8); ImapTypes = new ImapPixelType[32]; for (int i = 0; i < 32; i++) { byte imap = (byte)(header[6 + (i >> 2)] >> ((i & 3) * 8)); ImapTypes[i] = new ImapPixelType( (PixelImap)((imap >> 0) & 3), (PixelImap)((imap >> 2) & 3), (PixelImap)((imap >> 4) & 3), (PixelImap)((imap >> 6) & 3)); } int type2OmapTarget = header[18]; int type2Omap = header[19]; OmapTargets = new OmapTarget[8]; for (int offset = 0; offset < OmapTargets.Length * 4; offset += 4) { OmapTargets[offset >> 2] = new OmapTarget( type2OmapTarget.Extract(offset + 0), type2OmapTarget.Extract(offset + 1), type2OmapTarget.Extract(offset + 2), type2OmapTarget.Extract(offset + 3)); } OmapSampleMask = type2Omap.Extract(0); OmapDepth = type2Omap.Extract(1); }