graphicsdriver/metal: Bug fix: Use correct pixel format for the screen

This commit is contained in:
Hajime Hoshi 2019-09-08 03:52:29 +09:00
parent ef91fb739f
commit 3fb9c02e2f

View File

@ -280,6 +280,7 @@ type rpsKey struct {
filter driver.Filter filter driver.Filter
address driver.Address address driver.Address
compositeMode driver.CompositeMode compositeMode driver.CompositeMode
screen bool
} }
type Driver struct { type Driver struct {
@ -511,46 +512,54 @@ func (d *Driver) Reset() error {
} }
} }
for _, cm := range []bool{false, true} { for _, screen := range []bool{false, true} {
for _, a := range []driver.Address{ for _, cm := range []bool{false, true} {
driver.AddressClampToZero, for _, a := range []driver.Address{
driver.AddressRepeat, driver.AddressClampToZero,
} { driver.AddressRepeat,
for _, f := range []driver.Filter{
driver.FilterNearest,
driver.FilterLinear,
} { } {
for c := driver.CompositeModeSourceOver; c <= driver.CompositeModeMax; c++ { for _, f := range []driver.Filter{
cmi := 0 driver.FilterNearest,
if cm { driver.FilterLinear,
cmi = 1 } {
} for c := driver.CompositeModeSourceOver; c <= driver.CompositeModeMax; c++ {
fs, err := lib.MakeFunction(fmt.Sprintf("FragmentShader_%d_%d_%d", cmi, f, a)) cmi := 0
if err != nil { if cm {
return err cmi = 1
} }
rpld := mtl.RenderPipelineDescriptor{ fs, err := lib.MakeFunction(fmt.Sprintf("FragmentShader_%d_%d_%d", cmi, f, a))
VertexFunction: vs, if err != nil {
FragmentFunction: fs, return err
} }
rpld.ColorAttachments[0].PixelFormat = mtl.PixelFormatRGBA8UNorm rpld := mtl.RenderPipelineDescriptor{
rpld.ColorAttachments[0].BlendingEnabled = true VertexFunction: vs,
FragmentFunction: fs,
}
src, dst := c.Operations() pix := mtl.PixelFormatRGBA8UNorm
rpld.ColorAttachments[0].DestinationAlphaBlendFactor = conv(dst) if screen {
rpld.ColorAttachments[0].DestinationRGBBlendFactor = conv(dst) pix = d.view.colorPixelFormat()
rpld.ColorAttachments[0].SourceAlphaBlendFactor = conv(src) }
rpld.ColorAttachments[0].SourceRGBBlendFactor = conv(src) rpld.ColorAttachments[0].PixelFormat = pix
rps, err := d.view.getMTLDevice().MakeRenderPipelineState(rpld) rpld.ColorAttachments[0].BlendingEnabled = true
if err != nil {
return err src, dst := c.Operations()
rpld.ColorAttachments[0].DestinationAlphaBlendFactor = conv(dst)
rpld.ColorAttachments[0].DestinationRGBBlendFactor = conv(dst)
rpld.ColorAttachments[0].SourceAlphaBlendFactor = conv(src)
rpld.ColorAttachments[0].SourceRGBBlendFactor = conv(src)
rps, err := d.view.getMTLDevice().MakeRenderPipelineState(rpld)
if err != nil {
return err
}
d.rpss[rpsKey{
screen: screen,
useColorM: cm,
filter: f,
address: a,
compositeMode: c,
}] = rps
} }
d.rpss[rpsKey{
useColorM: cm,
filter: f,
address: a,
compositeMode: c,
}] = rps
} }
} }
} }
@ -604,6 +613,7 @@ func (d *Driver) Draw(indexLen int, indexOffset int, mode driver.CompositeMode,
rce.SetRenderPipelineState(d.screenRPS) rce.SetRenderPipelineState(d.screenRPS)
} else { } else {
rce.SetRenderPipelineState(d.rpss[rpsKey{ rce.SetRenderPipelineState(d.rpss[rpsKey{
screen: d.dst.screen,
useColorM: colorM != nil, useColorM: colorM != nil,
filter: filter, filter: filter,
address: address, address: address,