예제 #1
0
int main(void) {
    ss varying(4) x;
    ss varying(4) y;
    //x.a = 42;
    //x.b = 42;
    //y = x;
    return 0;
}
예제 #2
0
/* plot_line
 *
 * Plot a line defined by two points in window coordinates. Use Bresenham's
 * Algorithm for this. Don't forget to interpolate the normals and texture
 * coordinates as well.
 */
void canvashdl::plot_line(vec3f v1, vector<float> v1_varying, vec3f v2, vector<float> v2_varying)
{
	vec3i s1 = (vec3i)v1;
	vec3i s2 = (vec3i)v2;

	int b = (abs(s2[1] - s1[1]) > abs(s2[0] - s1[0]));

	vec2i dv = (vec2i)s2 - (vec2i)s1;

	vec2i step((int)(dv[0] > 0) - (int)(dv[0] < 0),
			   (int)(dv[1] > 0) - (int)(dv[1] < 0));
	dv[0] *= step[0];
	dv[1] *= step[1];

	int D = 2*dv[1-b] - dv[b];

	vector<float> varying(v1_varying.size());

	if (shade_model == flat)
		for (int i = 0; i < (int)v1_varying.size(); i++)
			varying[i] = (v1_varying[i] + v2_varying[i])/2.0f;
	else
		varying = v1_varying;

	plot(s1, varying);

	vec3i p = s1;
	float increment = (float)step[b]/(float)(s2[b] - s1[b]);
	float interpolate = 0.0f;
	float zdiff = v2[2] - v1[2];
	p[b]+=step[b];
	while (step[b]*p[b] < step[b]*s2[b])
	{
		if (D > 0)
		{
			p[1-b] += step[1-b];
			D += 2*(dv[1-b] - dv[b]);
		}
		else
			D += 2*dv[1-b];

		p[2] = (int)(zdiff*interpolate) + s1[2];

		if (shade_model != flat)
			for (int i = 0; i < (int)v1_varying.size(); i++)
				varying[i] = (v2_varying[i] - v1_varying[i])*interpolate + v1_varying[i];

		plot(p, varying);
		p[b] += step[b];
		interpolate += increment;
	}
}
void Vc4Shader::Emit_Prologue_PS()
{
    assert(this->uShaderType == D3D10_SB_PIXEL_SHADER);
    
    for (uint8_t i = 0, iRegUsed = 0; iRegUsed < this->cInput; i++)
    {
        Vc4Register raX = this->InputRegister[i / 4][i % 4];

        if (raX.GetFlags().valid)
        {
            assert(raX.GetMux() == VC4_QPU_ALU_REG_A || raX.GetMux() == VC4_QPU_ALU_REG_B);

            Vc4Register r0(VC4_QPU_ALU_R0, VC4_QPU_WADDR_ACC0);

            // Issue mul inputs (from varying) with ra15 (W).
            {
                Vc4Instruction Vc4Inst;
                Vc4Register varying(VC4_QPU_ALU_REG_B, VC4_QPU_RADDR_VERYING);
                Vc4Register ra15(VC4_QPU_ALU_REG_A, 15);
                Vc4Inst.Vc4_m_FMUL(r0, varying, ra15);
                Vc4Inst.Emit(CurrentStorage);
            }

            // Issue add r5 to each input data to complete interpolation.
            {
                Vc4Instruction Vc4Inst;
                Vc4Register r5(VC4_QPU_ALU_R5);
                Vc4Inst.Vc4_a_FADD(raX, r0, r5);
                Vc4Inst.Emit(CurrentStorage);
            }

            iRegUsed++;
        }
    }

    { // Emit a NOP with 'sbwait'
        Vc4Instruction Vc4Inst;
        Vc4Inst.Vc4_Sig(VC4_QPU_SIG_WAIT_FOR_SCOREBOARD);
        Vc4Inst.Emit(CurrentStorage);
    }
}
        void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
            const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
            GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
            GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
            GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
            GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;

            // emit attributes
            varyingHandler->emitAttributes(gp);

            // Setup pass through color
            if (gp.hasVertexColor()) {
                GrGLSLVarying varying(kHalf4_GrSLType);
                varyingHandler->addVarying("color", &varying);

                // There are several optional steps to process the color. Start with the attribute:
                vertBuilder->codeAppendf("half4 color = %s;", gp.inColor()->fName);

                // Linearize
                if (gp.linearizeColor()) {
                    SkString srgbFuncName;
                    static const GrShaderVar gSrgbArgs[] = {
                        GrShaderVar("x", kHalf_GrSLType),
                    };
                    vertBuilder->emitFunction(kHalf_GrSLType,
                                              "srgb_to_linear",
                                              SK_ARRAY_COUNT(gSrgbArgs),
                                              gSrgbArgs,
                                              "return (x <= 0.04045) ? (x / 12.92) "
                                              ": pow((x + 0.055) / 1.055, 2.4);",
                                              &srgbFuncName);
                    vertBuilder->codeAppendf("color = half4(%s(%s.r), %s(%s.g), %s(%s.b), %s.a);",
                                             srgbFuncName.c_str(), gp.inColor()->fName,
                                             srgbFuncName.c_str(), gp.inColor()->fName,
                                             srgbFuncName.c_str(), gp.inColor()->fName,
                                             gp.inColor()->fName);
                }

                // For SkColor, do a red/blue swap and premul
                if (gp.fFlags & kColorAttributeIsSkColor_GPFlag) {
                    vertBuilder->codeAppend("color = half4(color.a * color.bgr, color.a);");
                }

                // Do color-correction to destination gamut
                if (gp.linearizeColor()) {
                    fColorSpaceHelper.emitCode(uniformHandler, gp.fColorSpaceXform.get(),
                                               kVertex_GrShaderFlag);
                    if (fColorSpaceHelper.isValid()) {
                        SkString xformedColor;
                        vertBuilder->appendColorGamutXform(&xformedColor, "color",
                                                           &fColorSpaceHelper);
                        vertBuilder->codeAppendf("color = %s;", xformedColor.c_str());
                    }
                }
                vertBuilder->codeAppendf("%s = color;\n", varying.vsOut());
                fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
            } else {
                this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
                                        &fColorUniform);
            }

            // Setup position
            this->writeOutputPosition(vertBuilder,
                                      uniformHandler,
                                      gpArgs,
                                      gp.inPosition()->fName,
                                      gp.viewMatrix(),
                                      &fViewMatrixUniform);

            if (gp.hasExplicitLocalCoords()) {
                // emit transforms with explicit local coords
                this->emitTransforms(vertBuilder,
                                     varyingHandler,
                                     uniformHandler,
                                     gp.inLocalCoords()->asShaderVar(),
                                     gp.localMatrix(),
                                     args.fFPCoordTransformHandler);
            } else {
                // emit transforms with position
                this->emitTransforms(vertBuilder,
                                     varyingHandler,
                                     uniformHandler,
                                     gp.inPosition()->asShaderVar(),
                                     gp.localMatrix(),
                                     args.fFPCoordTransformHandler);
            }

            // Setup coverage as pass through
            if (gp.hasVertexCoverage()) {
                fragBuilder->codeAppendf("half alpha = 1.0;");
                varyingHandler->addPassThroughAttribute(gp.inCoverage(), "alpha");
                fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage);
            } else if (gp.coverage() == 0xff) {
                fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
            } else {
                const char* fragCoverage;
                fCoverageUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
                                                              kHalf_GrSLType,
                                                              "Coverage",
                                                              &fragCoverage);
                fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, fragCoverage);
            }
        }